From d06b33076755c8978d3359dd2fa24bdf91dabee7 Mon Sep 17 00:00:00 2001 From: Shu Chen Date: Mon, 24 Feb 2020 22:53:59 +0800 Subject: [PATCH] Makes sure the magnifier source bounds doesn't beyond the surface. Test: locally verified. Bug: 150122887 Change-Id: I3df94f0f073197f4a321faac24fa222f9dbb1674 --- core/java/android/widget/Magnifier.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/core/java/android/widget/Magnifier.java b/core/java/android/widget/Magnifier.java index a299b0185433d..8ea824d3ce82e 100644 --- a/core/java/android/widget/Magnifier.java +++ b/core/java/android/widget/Magnifier.java @@ -353,8 +353,9 @@ public final class Magnifier { // Gets the startX for new style, which should be bounded by the horizontal bounds. // Also calculates the left/right cut width for pixel copy. - leftBound += mViewCoordinatesInSurface[0]; - rightBound += mViewCoordinatesInSurface[0]; + leftBound = Math.max(leftBound + mViewCoordinatesInSurface[0], 0); + rightBound = Math.min( + rightBound + mViewCoordinatesInSurface[0], mContentCopySurface.mWidth); mLeftCutWidth = Math.max(0, leftBound - startX); mRightCutWidth = Math.max(0, startX + mSourceWidth - rightBound); startX = Math.max(startX, leftBound);