summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--services/core/java/com/android/server/wm/DisplayContent.java15
-rw-r--r--services/core/java/com/android/server/wm/DisplayRotation.java9
-rw-r--r--services/tests/wmtests/src/com/android/server/wm/DisplayContentTests.java22
3 files changed, 43 insertions, 3 deletions
diff --git a/services/core/java/com/android/server/wm/DisplayContent.java b/services/core/java/com/android/server/wm/DisplayContent.java
index d55883968b56..c24c1e466133 100644
--- a/services/core/java/com/android/server/wm/DisplayContent.java
+++ b/services/core/java/com/android/server/wm/DisplayContent.java
@@ -32,6 +32,7 @@ import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSET;
import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_USER;
import static android.content.res.Configuration.ORIENTATION_LANDSCAPE;
import static android.content.res.Configuration.ORIENTATION_PORTRAIT;
+import static android.content.res.Configuration.ORIENTATION_UNDEFINED;
import static android.os.Build.VERSION_CODES.N;
import static android.os.Trace.TRACE_TAG_WINDOW_MANAGER;
import static android.util.DisplayMetrics.DENSITY_DEFAULT;
@@ -1526,12 +1527,12 @@ class DisplayContent extends WindowContainer<DisplayContent.DisplayChildWindowCo
}
/**
- * Sets the provided record to {@link mFixedRotationLaunchingApp} if possible to apply fixed
+ * Sets the provided record to {@link #mFixedRotationLaunchingApp} if possible to apply fixed
* rotation transform to it and indicate that the display may be rotated after it is launched.
*/
void setFixedRotationLaunchingApp(@NonNull ActivityRecord r, @Surface.Rotation int rotation) {
final WindowToken prevRotatedLaunchingApp = mFixedRotationLaunchingApp;
- if (prevRotatedLaunchingApp != null && prevRotatedLaunchingApp == r
+ if (prevRotatedLaunchingApp == r
&& r.getWindowConfiguration().getRotation() == rotation) {
// The given launching app and target rotation are the same as the existing ones.
return;
@@ -5659,6 +5660,16 @@ class DisplayContent extends WindowContainer<DisplayContent.DisplayChildWindowCo
}
}
+ /**
+ * Return {@code true} if there is an ongoing animation to the "Recents" activity and this
+ * activity as a fixed orientation so shouldn't be rotated.
+ */
+ boolean isFixedOrientationRecentsAnimating() {
+ return mAnimatingRecents != null
+ && mAnimatingRecents.getRequestedConfigurationOrientation()
+ != ORIENTATION_UNDEFINED;
+ }
+
@Override
public void onAppTransitionFinishedLocked(IBinder token) {
final ActivityRecord r = getActivityRecord(token);
diff --git a/services/core/java/com/android/server/wm/DisplayRotation.java b/services/core/java/com/android/server/wm/DisplayRotation.java
index 831491dd145e..f093fd34bcc0 100644
--- a/services/core/java/com/android/server/wm/DisplayRotation.java
+++ b/services/core/java/com/android/server/wm/DisplayRotation.java
@@ -430,6 +430,15 @@ public class DisplayRotation {
"Deferring rotation, still finishing previous rotation");
return false;
}
+
+ if (mDisplayContent.mFixedRotationTransitionListener
+ .isFixedOrientationRecentsAnimating()) {
+ // During the recents animation, the closing app might still be considered on top.
+ // In order to ignore its requested orientation to avoid a sensor led rotation (e.g
+ // user rotating the device while the recents animation is running), we ignore
+ // rotation update while the animation is running.
+ return false;
+ }
}
if (!mService.mDisplayEnabled) {
diff --git a/services/tests/wmtests/src/com/android/server/wm/DisplayContentTests.java b/services/tests/wmtests/src/com/android/server/wm/DisplayContentTests.java
index 5a952b3e238f..8cf850736cb2 100644
--- a/services/tests/wmtests/src/com/android/server/wm/DisplayContentTests.java
+++ b/services/tests/wmtests/src/com/android/server/wm/DisplayContentTests.java
@@ -16,6 +16,7 @@
package com.android.server.wm;
+import static android.app.WindowConfiguration.ACTIVITY_TYPE_RECENTS;
import static android.app.WindowConfiguration.ACTIVITY_TYPE_STANDARD;
import static android.app.WindowConfiguration.WINDOWING_MODE_FREEFORM;
import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN;
@@ -79,6 +80,7 @@ import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.atLeastOnce;
import static org.mockito.Mockito.clearInvocations;
import static org.mockito.Mockito.doAnswer;
+import static org.mockito.Mockito.doCallRealMethod;
import android.annotation.SuppressLint;
import android.app.ActivityTaskManager;
@@ -1231,11 +1233,29 @@ public class DisplayContentTests extends WindowTestsBase {
}
@Test
+ public void testRecentsNotRotatingWithFixedRotation() {
+ final DisplayRotation displayRotation = mDisplayContent.getDisplayRotation();
+ doCallRealMethod().when(displayRotation).updateRotationUnchecked(anyBoolean());
+ doCallRealMethod().when(displayRotation).updateOrientation(anyInt(), anyBoolean());
+
+ final ActivityRecord recentsActivity = createActivityRecord(mDisplayContent,
+ WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_RECENTS);
+ recentsActivity.setRequestedOrientation(SCREEN_ORIENTATION_PORTRAIT);
+
+ mDisplayContent.mFixedRotationTransitionListener.onStartRecentsAnimation(recentsActivity);
+ displayRotation.setRotation((displayRotation.getRotation() + 1) % 4);
+ assertFalse(displayRotation.updateRotationUnchecked(false));
+
+ mDisplayContent.mFixedRotationTransitionListener.onFinishRecentsAnimation(false);
+ assertTrue(displayRotation.updateRotationUnchecked(false));
+ }
+
+ @Test
public void testRemoteRotation() {
DisplayContent dc = createNewDisplay();
final DisplayRotation dr = dc.getDisplayRotation();
- Mockito.doCallRealMethod().when(dr).updateRotationUnchecked(anyBoolean());
+ doCallRealMethod().when(dr).updateRotationUnchecked(anyBoolean());
Mockito.doReturn(ROTATION_90).when(dr).rotationForOrientation(anyInt(), anyInt());
final boolean[] continued = new boolean[1];
// TODO(display-merge): Remove cast