summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Oleg Blinnikov <olb@google.com> 2024-04-12 10:42:16 +0000
committer Oleg Blinnikov <olb@google.com> 2024-04-20 01:38:41 +0000
commit059ce8f4fbb99e52dcee91c862c36de37c438d0d (patch)
treec9e8cf5aae3693e785887b371b38bd8ccc01c706
parent01d88d2bef47f084a42177e44868ed3793dbd2c1 (diff)
Virtual Display demo rotation
Previously virtual displays, such as chromecast was not possible to permanently rotate for demo purposes. This will make virtual displays to appear rotated. Change-Id: I433313ab53bdb69e26355997913024bab4e6351d Test: adb shell setprop persist.demo.userrotation 1 && adb shell setprop persist.demo.userrotation.package_name com.google.android.gms Bug: 329442350 Bug: 302326003
-rw-r--r--services/core/java/com/android/server/wm/DisplayRotation.java25
-rw-r--r--services/tests/wmtests/src/com/android/server/wm/DisplayRotationTests.java76
2 files changed, 97 insertions, 4 deletions
diff --git a/services/core/java/com/android/server/wm/DisplayRotation.java b/services/core/java/com/android/server/wm/DisplayRotation.java
index 4a97128c27b6..afcf364d4729 100644
--- a/services/core/java/com/android/server/wm/DisplayRotation.java
+++ b/services/core/java/com/android/server/wm/DisplayRotation.java
@@ -21,6 +21,7 @@ import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSET;
import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
import static android.view.Display.TYPE_EXTERNAL;
import static android.view.Display.TYPE_OVERLAY;
+import static android.view.Display.TYPE_VIRTUAL;
import static android.view.WindowManager.LayoutParams.ROTATION_ANIMATION_CROSSFADE;
import static android.view.WindowManager.LayoutParams.ROTATION_ANIMATION_JUMPCUT;
import static android.view.WindowManager.LayoutParams.ROTATION_ANIMATION_ROTATE;
@@ -1794,20 +1795,36 @@ public class DisplayRotation {
}
}
+ @VisibleForTesting
+ int getDemoUserRotationOverride() {
+ return SystemProperties.getInt("persist.demo.userrotation", Surface.ROTATION_0);
+ }
+
+ @VisibleForTesting
+ @NonNull
+ String getDemoUserRotationPackage() {
+ return SystemProperties.get("persist.demo.userrotation.package_name");
+ }
+
@Surface.Rotation
private int getUserRotationOverride() {
- final int userRotationOverride = SystemProperties.getInt("persist.demo.userrotation",
- Surface.ROTATION_0);
+ final int userRotationOverride = getDemoUserRotationOverride();
if (userRotationOverride == Surface.ROTATION_0) {
return userRotationOverride;
}
- final var display = mDisplayContent.mDisplay;
+ final var display = mDisplayContent.getDisplay();
if (display.getType() == TYPE_EXTERNAL || display.getType() == TYPE_OVERLAY) {
- // TODO b/329442350 add chromecast virtual displays here
return userRotationOverride;
}
+ if (display.getType() == TYPE_VIRTUAL) {
+ final var packageName = getDemoUserRotationPackage();
+ if (!packageName.isEmpty() && packageName.equals(display.getOwnerPackageName())) {
+ return userRotationOverride;
+ }
+ }
+
return Surface.ROTATION_0;
}
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 e14568d281c0..e3a85424554d 100644
--- a/services/tests/wmtests/src/com/android/server/wm/DisplayRotationTests.java
+++ b/services/tests/wmtests/src/com/android/server/wm/DisplayRotationTests.java
@@ -38,6 +38,7 @@ import static com.android.dx.mockito.inline.extended.ExtendedMockito.eq;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.mock;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.reset;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.same;
+import static com.android.dx.mockito.inline.extended.ExtendedMockito.spyOn;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.times;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.verify;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.when;
@@ -66,6 +67,7 @@ import android.os.PowerManagerInternal;
import android.os.SystemClock;
import android.platform.test.annotations.Presubmit;
import android.provider.Settings;
+import android.view.Display;
import android.view.DisplayAddress;
import android.view.IRotationWatcher;
import android.view.Surface;
@@ -217,6 +219,79 @@ public class DisplayRotationTests {
}
@Test
+ public void testUserRotationSystemProperty_NonDefault_InternalDisplay() throws Exception {
+ mBuilder.setIsDefaultDisplay(false).build();
+ when(mMockDisplayContent.getDisplay().getType()).thenReturn(Display.TYPE_INTERNAL);
+ spyOn(mTarget);
+ when(mTarget.getDemoUserRotationOverride()).thenReturn(Surface.ROTATION_90);
+
+ mTarget.restoreSettings(WindowManagerPolicy.USER_ROTATION_FREE, Surface.ROTATION_270,
+ /*fixedToUserRotation=*/ 0);
+
+ assertEquals(Surface.ROTATION_270, mTarget.getUserRotation());
+ assertEquals(WindowManagerPolicy.USER_ROTATION_FREE, mTarget.getUserRotationMode());
+ assertEquals(0, mTarget.getFixedToUserRotationMode());
+ }
+
+ @Test
+ public void testUserRotationSystemProperty_NonDefault_ExternalDisplay() throws Exception {
+ mBuilder.setIsDefaultDisplay(false).build();
+ when(mMockDisplayContent.getDisplay().getType()).thenReturn(Display.TYPE_EXTERNAL);
+ spyOn(mTarget);
+ when(mTarget.getDemoUserRotationOverride()).thenReturn(Surface.ROTATION_90);
+
+ mTarget.restoreSettings(WindowManagerPolicy.USER_ROTATION_FREE, Surface.ROTATION_270,
+ /*fixedToUserRotation=*/ 0);
+
+ assertEquals(WindowManagerPolicy.USER_ROTATION_LOCKED, mTarget.getUserRotationMode());
+ assertEquals(Surface.ROTATION_90, mTarget.getUserRotation());
+ assertEquals(0, mTarget.getFixedToUserRotationMode());
+ }
+
+ @Test
+ public void testUserRotationSystemProperty_NonDefault_OverlayDisplay() throws Exception {
+ mBuilder.setIsDefaultDisplay(false).build();
+ when(mMockDisplayContent.getDisplay().getType()).thenReturn(Display.TYPE_OVERLAY);
+ spyOn(mTarget);
+ when(mTarget.getDemoUserRotationOverride()).thenReturn(Surface.ROTATION_90);
+
+ mTarget.restoreSettings(WindowManagerPolicy.USER_ROTATION_FREE, Surface.ROTATION_270,
+ /*fixedToUserRotation=*/ 0);
+
+ assertEquals(WindowManagerPolicy.USER_ROTATION_LOCKED, mTarget.getUserRotationMode());
+ assertEquals(Surface.ROTATION_90, mTarget.getUserRotation());
+ assertEquals(0, mTarget.getFixedToUserRotationMode());
+ }
+
+ @Test
+ public void testUserRotationSystemProperty_NonDefault_VirtualDisplay() throws Exception {
+ mBuilder.setIsDefaultDisplay(false).build();
+ when(mMockDisplayContent.getDisplay().getType()).thenReturn(Display.TYPE_VIRTUAL);
+ final var packageName = "abc";
+ when(mMockDisplayContent.getDisplay().getOwnerPackageName()).thenReturn(packageName);
+ spyOn(mTarget);
+ when(mTarget.getDemoUserRotationOverride()).thenReturn(Surface.ROTATION_90);
+
+ // Without package name
+ when(mTarget.getDemoUserRotationPackage()).thenReturn("");
+ mTarget.restoreSettings(WindowManagerPolicy.USER_ROTATION_FREE, Surface.ROTATION_270,
+ /*fixedToUserRotation=*/ 0);
+
+ assertEquals(WindowManagerPolicy.USER_ROTATION_FREE, mTarget.getUserRotationMode());
+ assertEquals(Surface.ROTATION_270, mTarget.getUserRotation());
+ assertEquals(0, mTarget.getFixedToUserRotationMode());
+
+ // Use package name
+ when(mTarget.getDemoUserRotationPackage()).thenReturn(packageName);
+ mTarget.restoreSettings(WindowManagerPolicy.USER_ROTATION_FREE, Surface.ROTATION_270,
+ /*fixedToUserRotation=*/ 0);
+
+ assertEquals(WindowManagerPolicy.USER_ROTATION_LOCKED, mTarget.getUserRotation());
+ assertEquals(Surface.ROTATION_90, mTarget.getUserRotationMode());
+ assertEquals(0, mTarget.getFixedToUserRotationMode());
+ }
+
+ @Test
public void testPersistUserRotation_UnlockRotation_DefaultDisplay() throws Exception {
mBuilder.build();
@@ -1450,6 +1525,7 @@ public class DisplayRotationTests {
mMockContext = mock(Context.class);
mMockDisplayContent = mock(DisplayContent.class);
+ when(mMockDisplayContent.getDisplay()).thenReturn(mock(Display.class));
mMockDisplayContent.isDefaultDisplay = mIsDefaultDisplay;
when(mMockDisplayContent.calculateDisplayCutoutForRotation(anyInt()))
.thenReturn(NO_CUTOUT);