From a9b435df01a4af87ee0f3d0b67a05357dd296e00 Mon Sep 17 00:00:00 2001 From: Roy Chou Date: Fri, 14 Jul 2023 07:50:13 +0000 Subject: [PATCH] fix(#Magnification): flaky presubmit error on FullScreenMagnificationGestureHandlerTest The test case testTransitToPanningState_scaleDifferenceOverThreshold_startDetecting is flaky. The main reason is that the exact persisted scale after setScale+persistScale is not expected, then it causes the ratio not passing the threshold so the flag is not set to true. Therefore, in test case we directly update the persisted scale by Settings api to ensure it's expected. In this test case our main target is to check whether the flag is set under given scale and persisted scale, so we think directly set the persisted scale is fine, and the update persisted scale logic is already verified by other test cases. Bug: 289268089 Test: atest FullScreenMagnificationGestureHandlerTest via abtd presubmit Change-Id: I5ec46ec84d1693f01b20c07f3e617b22c465da21 --- ...ScreenMagnificationGestureHandlerTest.java | 31 +++++++++++++------ 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/services/tests/servicestests/src/com/android/server/accessibility/magnification/FullScreenMagnificationGestureHandlerTest.java b/services/tests/servicestests/src/com/android/server/accessibility/magnification/FullScreenMagnificationGestureHandlerTest.java index 2d4bf144155c1..32d0c98d44815 100644 --- a/services/tests/servicestests/src/com/android/server/accessibility/magnification/FullScreenMagnificationGestureHandlerTest.java +++ b/services/tests/servicestests/src/com/android/server/accessibility/magnification/FullScreenMagnificationGestureHandlerTest.java @@ -44,8 +44,10 @@ import android.annotation.NonNull; import android.graphics.PointF; import android.os.Handler; import android.os.Message; +import android.os.UserHandle; import android.os.VibrationEffect; import android.os.Vibrator; +import android.provider.Settings; import android.testing.TestableContext; import android.util.DebugUtils; import android.view.InputDevice; @@ -140,8 +142,6 @@ public class FullScreenMagnificationGestureHandlerTest { @Mock WindowMagnificationPromptController mWindowMagnificationPromptController; @Mock - AccessibilityManagerService mMockAccessibilityManagerService; - @Mock AccessibilityTraceManager mMockTraceManager; @Rule @@ -153,6 +153,8 @@ public class FullScreenMagnificationGestureHandlerTest { private long mLastDownTime = Integer.MIN_VALUE; + private float mOriginalMagnificationPersistedScale; + @Before public void setUp() { MockitoAnnotations.initMocks(this); @@ -166,6 +168,13 @@ public class FullScreenMagnificationGestureHandlerTest { when(mockController.newValueAnimator()).thenReturn(new ValueAnimator()); when(mockController.getAnimationDuration()).thenReturn(1000L); when(mockWindowManager.setMagnificationCallbacks(eq(DISPLAY_0), any())).thenReturn(true); + mOriginalMagnificationPersistedScale = Settings.Secure.getFloatForUser( + mContext.getContentResolver(), + Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_SCALE, 2.0f, + UserHandle.USER_SYSTEM); + Settings.Secure.putFloatForUser(mContext.getContentResolver(), + Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_SCALE, 2.0f, + UserHandle.USER_SYSTEM); mFullScreenMagnificationController = new FullScreenMagnificationController( mockController, new Object(), @@ -192,6 +201,10 @@ public class FullScreenMagnificationGestureHandlerTest { mMgh.onDestroy(); mFullScreenMagnificationController.unregister(DISPLAY_0); verify(mWindowMagnificationPromptController).onDestroy(); + Settings.Secure.putFloatForUser(mContext.getContentResolver(), + Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_SCALE, + mOriginalMagnificationPersistedScale, + UserHandle.USER_SYSTEM); } @NonNull @@ -525,10 +538,9 @@ public class FullScreenMagnificationGestureHandlerTest { final float threshold = FullScreenMagnificationGestureHandler.PanningScalingState .CHECK_DETECTING_PASS_PERSISTED_SCALE_THRESHOLD; final float persistedScale = (1.0f + threshold) * scale + 1.0f; - mFullScreenMagnificationController.setScale(DISPLAY_0, persistedScale, DEFAULT_X, - DEFAULT_Y, /* animate= */ false, - AccessibilityManagerService.MAGNIFICATION_GESTURE_HANDLER_ID); - mFullScreenMagnificationController.persistScale(DISPLAY_0); + Settings.Secure.putFloatForUser(mContext.getContentResolver(), + Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_SCALE, persistedScale, + UserHandle.USER_SYSTEM); mFullScreenMagnificationController.setScale(DISPLAY_0, scale, DEFAULT_X, DEFAULT_Y, /* animate= */ false, AccessibilityManagerService.MAGNIFICATION_GESTURE_HANDLER_ID); @@ -547,10 +559,9 @@ public class FullScreenMagnificationGestureHandlerTest { final float threshold = FullScreenMagnificationGestureHandler.PanningScalingState .CHECK_DETECTING_PASS_PERSISTED_SCALE_THRESHOLD; final float persistedScale = (1.0f + threshold) * scale - 0.1f; - mFullScreenMagnificationController.setScale(DISPLAY_0, persistedScale, DEFAULT_X, - DEFAULT_Y, /* animate= */ false, - AccessibilityManagerService.MAGNIFICATION_GESTURE_HANDLER_ID); - mFullScreenMagnificationController.persistScale(DISPLAY_0); + Settings.Secure.putFloatForUser(mContext.getContentResolver(), + Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_SCALE, persistedScale, + UserHandle.USER_SYSTEM); mFullScreenMagnificationController.setScale(DISPLAY_0, scale, DEFAULT_X, DEFAULT_Y, /* animate= */ false, AccessibilityManagerService.MAGNIFICATION_GESTURE_HANDLER_ID);