From cf951a027696295a23ba4a643de921cb4bd9f9e1 Mon Sep 17 00:00:00 2001 From: Riddle Hsu Date: Fri, 30 Apr 2021 01:27:35 +0800 Subject: [PATCH] Apply rotation animation when canceling fixed rotation ... if the activity requested the same orientation as display. The launching activity may not declare fixed orientation, so when launching it in a different orientation, the fixed rotation will be applied. But if the activity requested to use previous orientation before the transition is done, it suddenly redraws that causes flickering. Fix: 186759371 Test: ActivityRecordTests#testActivityOnCancelFixedRotationTransform Change-Id: I839dc1b563e9e3c150fbad8c33596dbc2bf0677b --- .../java/com/android/server/wm/ActivityRecord.java | 12 +++++++++--- .../com/android/server/wm/ActivityRecordTests.java | 9 +++++++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/services/core/java/com/android/server/wm/ActivityRecord.java b/services/core/java/com/android/server/wm/ActivityRecord.java index 3e8bc5d31af0f..5014bf645492f 100644 --- a/services/core/java/com/android/server/wm/ActivityRecord.java +++ b/services/core/java/com/android/server/wm/ActivityRecord.java @@ -6598,9 +6598,15 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A @Override void onCancelFixedRotationTransform(int originalDisplayRotation) { - if (this != mDisplayContent.getLastOrientationSource() - || getRequestedConfigurationOrientation() != ORIENTATION_UNDEFINED) { - // Only need to handle the activity that should be rotated with display. + if (this != mDisplayContent.getLastOrientationSource()) { + // This activity doesn't affect display rotation. + return; + } + final int requestedOrientation = getRequestedConfigurationOrientation(); + if (requestedOrientation != ORIENTATION_UNDEFINED + && requestedOrientation != mDisplayContent.getConfiguration().orientation) { + // Only need to handle the activity that can be rotated with display or the activity + // has requested the same orientation. return; } diff --git a/services/tests/wmtests/src/com/android/server/wm/ActivityRecordTests.java b/services/tests/wmtests/src/com/android/server/wm/ActivityRecordTests.java index bd143f8a5c35a..06542bd01ba4e 100644 --- a/services/tests/wmtests/src/com/android/server/wm/ActivityRecordTests.java +++ b/services/tests/wmtests/src/com/android/server/wm/ActivityRecordTests.java @@ -1723,6 +1723,15 @@ public class ActivityRecordTests extends WindowTestsBase { assertFalse(display.hasTopFixedRotationLaunchingApp()); assertFalse(activity.hasFixedRotationTransform()); + + // Simulate that the activity requests the same orientation as display. + activity.setOrientation(display.getConfiguration().orientation); + // Skip the real freezing. + activity.mVisibleRequested = false; + clearInvocations(activity); + activity.onCancelFixedRotationTransform(originalRotation); + // The implementation of cancellation must be executed. + verify(activity).startFreezingScreen(originalRotation); } @Test