diff options
| author | 2023-03-23 14:09:11 +0000 | |
|---|---|---|
| committer | 2023-03-23 14:09:11 +0000 | |
| commit | dad0c5569b145f89bfcd053ce9db0532ca0dfb77 (patch) | |
| tree | 4fbae1bf2ad3da9a4889219e366bb1ab85ae3abb | |
| parent | aee5c18251fa23b016b82ce65a034f132986f8d4 (diff) | |
| parent | 1d480ca06e53c3c01354e51139c365718b77acc6 (diff) | |
Merge "Add a delay to rotation updates to help avoid fold state race" into tm-qpr-dev am: d094fe2516 am: 1d480ca06e
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/22122422
Change-Id: Ic4020fa21c634520d79ab641bf38fc967192d601
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
| -rw-r--r-- | services/core/java/com/android/server/wm/DisplayRotation.java | 12 | ||||
| -rw-r--r-- | services/tests/wmtests/src/com/android/server/wm/DisplayRotationTests.java | 4 |
2 files changed, 9 insertions, 7 deletions
diff --git a/services/core/java/com/android/server/wm/DisplayRotation.java b/services/core/java/com/android/server/wm/DisplayRotation.java index 6af1c7c9d656..72263ffc7de2 100644 --- a/services/core/java/com/android/server/wm/DisplayRotation.java +++ b/services/core/java/com/android/server/wm/DisplayRotation.java @@ -87,6 +87,8 @@ import java.util.Set; */ public class DisplayRotation { private static final String TAG = TAG_WITH_CLASS_NAME ? "DisplayRotation" : TAG_WM; + // Delay to avoid race between fold update and orientation update. + private static final int ORIENTATION_UPDATE_DELAY_MS = 800; // Delay in milliseconds when updating config due to folding events. This prevents // config changes and unexpected jumps while folding the device to closed state. @@ -1787,15 +1789,15 @@ public class DisplayRotation { mDeviceState = newState; // Now mFoldState is set to HALF_FOLDED, the overrideFrozenRotation function will // return true, so rotation is unlocked. - mService.updateRotation(false /* alwaysSendConfiguration */, - false /* forceRelayout */); } else { mInHalfFoldTransition = true; mDeviceState = newState; - // Tell the device to update its orientation. - mService.updateRotation(false /* alwaysSendConfiguration */, - false /* forceRelayout */); } + UiThread.getHandler().postDelayed( + () -> { + mService.updateRotation(false /* alwaysSendConfiguration */, + false /* forceRelayout */); + }, ORIENTATION_UPDATE_DELAY_MS); // Alert the activity of possible new bounds. UiThread.getHandler().removeCallbacks(mActivityBoundsUpdateCallback); UiThread.getHandler().postDelayed(mActivityBoundsUpdateCallback, diff --git a/services/tests/wmtests/src/com/android/server/wm/DisplayRotationTests.java b/services/tests/wmtests/src/com/android/server/wm/DisplayRotationTests.java index 146ed34204f5..226ecf421928 100644 --- a/services/tests/wmtests/src/com/android/server/wm/DisplayRotationTests.java +++ b/services/tests/wmtests/src/com/android/server/wm/DisplayRotationTests.java @@ -792,7 +792,7 @@ public class DisplayRotationTests { // ... until half-fold mTarget.foldStateChanged(DeviceStateController.DeviceState.HALF_FOLDED); assertTrue(waitForUiHandler()); - verify(sMockWm).updateRotation(false, false); + verify(sMockWm).updateRotation(anyBoolean(), anyBoolean()); assertTrue(waitForUiHandler()); assertEquals(Surface.ROTATION_0, mTarget.rotationForOrientation( SCREEN_ORIENTATION_UNSPECIFIED, Surface.ROTATION_0)); @@ -800,7 +800,7 @@ public class DisplayRotationTests { // ... then transition back to flat mTarget.foldStateChanged(DeviceStateController.DeviceState.OPEN); assertTrue(waitForUiHandler()); - verify(sMockWm, atLeast(1)).updateRotation(false, false); + verify(sMockWm, atLeast(1)).updateRotation(anyBoolean(), anyBoolean()); assertTrue(waitForUiHandler()); assertEquals(Surface.ROTATION_270, mTarget.rotationForOrientation( SCREEN_ORIENTATION_UNSPECIFIED, Surface.ROTATION_0)); |