Loading services/core/java/com/android/server/wm/AppCompatOrientationOverrides.java +11 −0 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ package com.android.server.wm; import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN; import static android.content.pm.ActivityInfo.OVERRIDE_ANY_ORIENTATION; import static android.content.pm.ActivityInfo.OVERRIDE_ENABLE_COMPAT_IGNORE_ORIENTATION_REQUEST_WHEN_LOOP_DETECTED; import static android.content.pm.ActivityInfo.OVERRIDE_ENABLE_COMPAT_IGNORE_REQUESTED_ORIENTATION; Loading Loading @@ -106,6 +107,16 @@ class AppCompatOrientationOverrides { return isChangeEnabled(mActivityRecord, OVERRIDE_RESPECT_REQUESTED_ORIENTATION); } boolean shouldRespectRequestedOrientationDueToOverride() { // Checking TaskFragment rather than ActivityRecord to ensure that transition // between fullscreen and PiP would work well. Checking TaskFragment rather than // Task to ensure that Activity Embedding is excluded. return mActivityRecord.isVisibleRequested() && mActivityRecord.getTaskFragment() != null && mActivityRecord.getTaskFragment().getWindowingMode() == WINDOWING_MODE_FULLSCREEN && mActivityRecord.mAppCompatController.getAppCompatOrientationOverrides() .isOverrideRespectRequestedOrientationEnabled(); } /** * Whether an app is calling {@link android.app.Activity#setRequestedOrientation} * in a loop and orientation request should be ignored. Loading services/core/java/com/android/server/wm/DisplayArea.java +8 −10 Original line number Diff line number Diff line Loading @@ -16,7 +16,6 @@ package com.android.server.wm; import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN; import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_BEHIND; import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSET; import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; Loading Loading @@ -260,15 +259,14 @@ public class DisplayArea<T extends WindowContainer> extends WindowContainer<T> { if (mDisplayContent == null) { return false; } ActivityRecord activity = mDisplayContent.topRunningActivity( /* considerKeyguardState= */ true); return activity != null && activity.getTaskFragment() != null // Checking TaskFragment rather than ActivityRecord to ensure that transition // between fullscreen and PiP would work well. Checking TaskFragment rather than // Task to ensure that Activity Embedding is excluded. && activity.getTaskFragment().getWindowingMode() == WINDOWING_MODE_FULLSCREEN && activity.mAppCompatController.getAppCompatOrientationOverrides() .isOverrideRespectRequestedOrientationEnabled(); // Top running activity can be freeform and ignore orientation request from bottom activity // that should be respected, Check all activities in display to make sure any eligible // activity should be respected. final ActivityRecord activity = mDisplayContent.getActivity((r) -> r.mAppCompatController.getAppCompatOrientationOverrides() .shouldRespectRequestedOrientationDueToOverride()); return activity != null; } boolean getIgnoreOrientationRequest() { Loading services/tests/wmtests/src/com/android/server/wm/AppCompatOrientationOverridesTest.java +38 −0 Original line number Diff line number Diff line Loading @@ -17,11 +17,13 @@ package com.android.server.wm; import static android.content.pm.ActivityInfo.OVERRIDE_ENABLE_COMPAT_IGNORE_ORIENTATION_REQUEST_WHEN_LOOP_DETECTED; import static android.content.pm.ActivityInfo.OVERRIDE_USE_DISPLAY_LANDSCAPE_NATURAL_ORIENTATION; import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE; import static android.content.res.Configuration.ORIENTATION_LANDSCAPE; import static android.content.res.Configuration.ORIENTATION_PORTRAIT; import static android.view.WindowManager.PROPERTY_COMPAT_ALLOW_DISPLAY_ORIENTATION_OVERRIDE; import static android.view.WindowManager.PROPERTY_COMPAT_ALLOW_IGNORING_ORIENTATION_REQUEST_WHEN_LOOP_DETECTED; import static com.android.dx.mockito.inline.extended.ExtendedMockito.doReturn; import static com.android.dx.mockito.inline.extended.ExtendedMockito.spyOn; import static com.android.server.wm.AppCompatOrientationOverrides.OrientationOverridesState.MIN_COUNT_TO_IGNORE_REQUEST_IN_LOOP; import static com.android.server.wm.AppCompatOrientationOverrides.OrientationOverridesState.SET_ORIENTATION_REQUEST_COUNTER_TIMEOUT_MS; Loading @@ -31,6 +33,7 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import android.compat.testing.PlatformCompatChangeRule; import android.content.pm.ActivityInfo.ScreenOrientation; import android.platform.test.annotations.Presubmit; import androidx.annotation.NonNull; Loading Loading @@ -228,6 +231,25 @@ public class AppCompatOrientationOverridesTest extends WindowTestsBase { }); } @Test public void testOverrideRespectRequestedOrientationIsEnabled_bottomOrientationIsRespected() { runTestScenario((robot) -> { robot.applyOnActivity((a) -> { a.setIgnoreOrientationRequest(true); a.createActivityWithComponentInNewTask(); robot.setOverrideRespectRequestedOrientationEnabled(true); a.configureUnresizableTopActivity(SCREEN_ORIENTATION_LANDSCAPE); robot.checkDisplayShouldIgnoreOrientationRequest(SCREEN_ORIENTATION_LANDSCAPE, /* expected */ false); a.createActivityWithComponentInNewTask(); a.setTopActivityInFreeformWindowingMode(true); }); robot.checkDisplayShouldIgnoreOrientationRequest(SCREEN_ORIENTATION_LANDSCAPE, /* expected */ false); }); } /** * Runs a test scenario providing a Robot. */ Loading Loading @@ -291,6 +313,22 @@ public class AppCompatOrientationOverridesTest extends WindowTestsBase { } } void setOverrideRespectRequestedOrientationEnabled(boolean override) { spyOn(getTopOrientationOverrides()); doReturn(override).when(getTopOrientationOverrides()) .isOverrideRespectRequestedOrientationEnabled(); } void checkDisplayShouldIgnoreOrientationRequest(@ScreenOrientation int candidate, boolean expected) { assertEquals(expected, activity().displayContent() .shouldIgnoreOrientationRequest(candidate)); } void checkExpectedDisplayOrientation(@ScreenOrientation int expected) { assertEquals(expected, activity().displayContent().getOrientation()); } void checkShouldUseDisplayLandscapeNaturalOrientation(boolean expected) { assertEquals(expected, getTopOrientationOverrides().shouldUseDisplayLandscapeNaturalOrientation()); Loading Loading
services/core/java/com/android/server/wm/AppCompatOrientationOverrides.java +11 −0 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ package com.android.server.wm; import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN; import static android.content.pm.ActivityInfo.OVERRIDE_ANY_ORIENTATION; import static android.content.pm.ActivityInfo.OVERRIDE_ENABLE_COMPAT_IGNORE_ORIENTATION_REQUEST_WHEN_LOOP_DETECTED; import static android.content.pm.ActivityInfo.OVERRIDE_ENABLE_COMPAT_IGNORE_REQUESTED_ORIENTATION; Loading Loading @@ -106,6 +107,16 @@ class AppCompatOrientationOverrides { return isChangeEnabled(mActivityRecord, OVERRIDE_RESPECT_REQUESTED_ORIENTATION); } boolean shouldRespectRequestedOrientationDueToOverride() { // Checking TaskFragment rather than ActivityRecord to ensure that transition // between fullscreen and PiP would work well. Checking TaskFragment rather than // Task to ensure that Activity Embedding is excluded. return mActivityRecord.isVisibleRequested() && mActivityRecord.getTaskFragment() != null && mActivityRecord.getTaskFragment().getWindowingMode() == WINDOWING_MODE_FULLSCREEN && mActivityRecord.mAppCompatController.getAppCompatOrientationOverrides() .isOverrideRespectRequestedOrientationEnabled(); } /** * Whether an app is calling {@link android.app.Activity#setRequestedOrientation} * in a loop and orientation request should be ignored. Loading
services/core/java/com/android/server/wm/DisplayArea.java +8 −10 Original line number Diff line number Diff line Loading @@ -16,7 +16,6 @@ package com.android.server.wm; import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN; import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_BEHIND; import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSET; import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; Loading Loading @@ -260,15 +259,14 @@ public class DisplayArea<T extends WindowContainer> extends WindowContainer<T> { if (mDisplayContent == null) { return false; } ActivityRecord activity = mDisplayContent.topRunningActivity( /* considerKeyguardState= */ true); return activity != null && activity.getTaskFragment() != null // Checking TaskFragment rather than ActivityRecord to ensure that transition // between fullscreen and PiP would work well. Checking TaskFragment rather than // Task to ensure that Activity Embedding is excluded. && activity.getTaskFragment().getWindowingMode() == WINDOWING_MODE_FULLSCREEN && activity.mAppCompatController.getAppCompatOrientationOverrides() .isOverrideRespectRequestedOrientationEnabled(); // Top running activity can be freeform and ignore orientation request from bottom activity // that should be respected, Check all activities in display to make sure any eligible // activity should be respected. final ActivityRecord activity = mDisplayContent.getActivity((r) -> r.mAppCompatController.getAppCompatOrientationOverrides() .shouldRespectRequestedOrientationDueToOverride()); return activity != null; } boolean getIgnoreOrientationRequest() { Loading
services/tests/wmtests/src/com/android/server/wm/AppCompatOrientationOverridesTest.java +38 −0 Original line number Diff line number Diff line Loading @@ -17,11 +17,13 @@ package com.android.server.wm; import static android.content.pm.ActivityInfo.OVERRIDE_ENABLE_COMPAT_IGNORE_ORIENTATION_REQUEST_WHEN_LOOP_DETECTED; import static android.content.pm.ActivityInfo.OVERRIDE_USE_DISPLAY_LANDSCAPE_NATURAL_ORIENTATION; import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE; import static android.content.res.Configuration.ORIENTATION_LANDSCAPE; import static android.content.res.Configuration.ORIENTATION_PORTRAIT; import static android.view.WindowManager.PROPERTY_COMPAT_ALLOW_DISPLAY_ORIENTATION_OVERRIDE; import static android.view.WindowManager.PROPERTY_COMPAT_ALLOW_IGNORING_ORIENTATION_REQUEST_WHEN_LOOP_DETECTED; import static com.android.dx.mockito.inline.extended.ExtendedMockito.doReturn; import static com.android.dx.mockito.inline.extended.ExtendedMockito.spyOn; import static com.android.server.wm.AppCompatOrientationOverrides.OrientationOverridesState.MIN_COUNT_TO_IGNORE_REQUEST_IN_LOOP; import static com.android.server.wm.AppCompatOrientationOverrides.OrientationOverridesState.SET_ORIENTATION_REQUEST_COUNTER_TIMEOUT_MS; Loading @@ -31,6 +33,7 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import android.compat.testing.PlatformCompatChangeRule; import android.content.pm.ActivityInfo.ScreenOrientation; import android.platform.test.annotations.Presubmit; import androidx.annotation.NonNull; Loading Loading @@ -228,6 +231,25 @@ public class AppCompatOrientationOverridesTest extends WindowTestsBase { }); } @Test public void testOverrideRespectRequestedOrientationIsEnabled_bottomOrientationIsRespected() { runTestScenario((robot) -> { robot.applyOnActivity((a) -> { a.setIgnoreOrientationRequest(true); a.createActivityWithComponentInNewTask(); robot.setOverrideRespectRequestedOrientationEnabled(true); a.configureUnresizableTopActivity(SCREEN_ORIENTATION_LANDSCAPE); robot.checkDisplayShouldIgnoreOrientationRequest(SCREEN_ORIENTATION_LANDSCAPE, /* expected */ false); a.createActivityWithComponentInNewTask(); a.setTopActivityInFreeformWindowingMode(true); }); robot.checkDisplayShouldIgnoreOrientationRequest(SCREEN_ORIENTATION_LANDSCAPE, /* expected */ false); }); } /** * Runs a test scenario providing a Robot. */ Loading Loading @@ -291,6 +313,22 @@ public class AppCompatOrientationOverridesTest extends WindowTestsBase { } } void setOverrideRespectRequestedOrientationEnabled(boolean override) { spyOn(getTopOrientationOverrides()); doReturn(override).when(getTopOrientationOverrides()) .isOverrideRespectRequestedOrientationEnabled(); } void checkDisplayShouldIgnoreOrientationRequest(@ScreenOrientation int candidate, boolean expected) { assertEquals(expected, activity().displayContent() .shouldIgnoreOrientationRequest(candidate)); } void checkExpectedDisplayOrientation(@ScreenOrientation int expected) { assertEquals(expected, activity().displayContent().getOrientation()); } void checkShouldUseDisplayLandscapeNaturalOrientation(boolean expected) { assertEquals(expected, getTopOrientationOverrides().shouldUseDisplayLandscapeNaturalOrientation()); Loading