Loading services/core/java/com/android/server/wm/DisplayContent.java +10 −12 Original line number Diff line number Diff line Loading @@ -33,14 +33,11 @@ import static android.view.Display.DEFAULT_DISPLAY; import static android.view.Display.FLAG_PRIVATE; import static android.view.Display.INVALID_DISPLAY; import static android.view.InsetsState.TYPE_IME; import static android.view.InsetsState.TYPE_NAVIGATION_BAR; import static android.view.InsetsState.TYPE_TOP_BAR; import static android.view.Surface.ROTATION_0; import static android.view.Surface.ROTATION_180; import static android.view.Surface.ROTATION_270; import static android.view.Surface.ROTATION_90; import static android.view.View.GONE; import static android.view.ViewRootImpl.NEW_INSETS_MODE_FULL; import static android.view.WindowManager.DOCKED_BOTTOM; import static android.view.WindowManager.DOCKED_INVALID; import static android.view.WindowManager.DOCKED_TOP; Loading Loading @@ -175,7 +172,6 @@ import android.view.SurfaceControl; import android.view.SurfaceControl.Transaction; import android.view.SurfaceSession; import android.view.View; import android.view.ViewRootImpl; import android.view.WindowManager; import android.view.WindowManagerPolicyConstants.PointerEventListener; Loading Loading @@ -1162,14 +1158,12 @@ class DisplayContent extends WindowContainer<DisplayContent.DisplayChildWindowCo @Override boolean onDescendantOrientationChanged(IBinder freezeDisplayToken, ConfigurationContainer requestingContainer) { final int previousRotation = mRotation; final Configuration config = updateOrientationFromAppTokens( getRequestedOverrideConfiguration(), freezeDisplayToken, false); // This event is considered handled iff a configuration propagation is triggered, because // that's the only place lower level containers check if they need to do something to this // request. The only guaranteed signal is that the display is rotated to a different // orientation (i.e. rotating 180 degrees doesn't count). final boolean handled = (mRotation - previousRotation) % 2 != 0; // If display rotation class tells us that it doesn't consider app requested orientation, // this display won't rotate just because of an app changes its requested orientation. Thus // it indicates that this display chooses not to handle this request. final boolean handled = getDisplayRotation().respectAppRequestedOrientation(); if (config == null) { return handled; } Loading @@ -1191,6 +1185,11 @@ class DisplayContent extends WindowContainer<DisplayContent.DisplayChildWindowCo return handled; } @Override boolean handlesOrientationChangeFromDescendant() { return getDisplayRotation().respectAppRequestedOrientation(); } /** * Determine the new desired orientation of this display. * Loading Loading @@ -1371,8 +1370,7 @@ class DisplayContent extends WindowContainer<DisplayContent.DisplayChildWindowCo if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Display id=" + mDisplayId + " selected orientation " + lastOrientation + ", got rotation " + rotation + " which has " + " metrics"); + ", got rotation " + rotation); if (oldRotation == rotation) { // No change. Loading services/core/java/com/android/server/wm/DisplayRotation.java +9 −0 Original line number Diff line number Diff line Loading @@ -329,6 +329,15 @@ public class DisplayRotation { return mFixedToUserRotation; } /** * Returns {@code true} if this display rotation takes app requested orientation into * consideration; {@code false} otherwise. For the time being the only case where this is {@code * false} is when {@link #isFixedToUserRotation()} is {@code true}. */ boolean respectAppRequestedOrientation() { return !mFixedToUserRotation; } public int getLandscapeRotation() { return mLandscapeRotation; } Loading services/core/java/com/android/server/wm/TaskRecord.java +5 −1 Original line number Diff line number Diff line Loading @@ -2197,11 +2197,15 @@ class TaskRecord extends ConfigurationContainer { // In FULLSCREEN mode, always start with empty bounds to indicate "fill parent" outOverrideBounds.setEmpty(); final boolean parentHandlesOrientationChange = mTask != null && mTask.getParent() != null && mTask.getParent().handlesOrientationChangeFromDescendant(); // If the task or its top activity requires a different orientation, make it fit the // available bounds by scaling down its bounds. int forcedOrientation = getTopActivityRequestedOrientation(); if (forcedOrientation != ORIENTATION_UNDEFINED && forcedOrientation != newParentConfig.orientation) { && forcedOrientation != newParentConfig.orientation && !parentHandlesOrientationChange) { final Rect parentBounds = newParentConfig.windowConfiguration.getBounds(); final int parentWidth = parentBounds.width(); final int parentHeight = parentBounds.height(); Loading services/core/java/com/android/server/wm/WindowContainer.java +15 −0 Original line number Diff line number Diff line Loading @@ -714,6 +714,21 @@ class WindowContainer<E extends WindowContainer> extends ConfigurationContainer< requestingContainer); } /** * Check if this container or its parent will handle orientation changes from descendants. It's * different from the return value of {@link #onDescendantOrientationChanged(IBinder, * ConfigurationContainer)} in the sense that the return value of this method tells if this * container or its parent will handle the request eventually, while the return value of the * other method is if it handled the request synchronously. * * @return {@code true} if it handles or will handle orientation change in the future; {@code * false} if it won't handle the change at anytime. */ boolean handlesOrientationChangeFromDescendant() { final WindowContainer parent = getParent(); return parent != null && parent.handlesOrientationChangeFromDescendant(); } /** * Calls {@link #setOrientation(int, IBinder, ActivityRecord)} with {@code null} to the last 2 * parameters. Loading services/tests/wmtests/src/com/android/server/wm/DisplayContentTests.java +11 −15 Original line number Diff line number Diff line Loading @@ -59,7 +59,6 @@ import android.os.SystemClock; import android.platform.test.annotations.Presubmit; import android.util.DisplayMetrics; import android.view.DisplayCutout; import android.view.DisplayInfo; import android.view.Gravity; import android.view.MotionEvent; import android.view.Surface; Loading Loading @@ -585,17 +584,15 @@ public class DisplayContentTests extends WindowTestsBase { @Test public void testOnDescendantOrientationRequestChanged() { final DisplayInfo info = new DisplayInfo(); info.logicalWidth = 1080; info.logicalHeight = 1920; info.logicalDensityDpi = 240; final DisplayContent dc = createNewDisplay(info); dc.configureDisplayPolicy(); final DisplayContent dc = createNewDisplay(); mWm.mAtmService.mRootActivityContainer = mock(RootActivityContainer.class); final int newOrientation = dc.getLastOrientation() == SCREEN_ORIENTATION_LANDSCAPE ? SCREEN_ORIENTATION_PORTRAIT : SCREEN_ORIENTATION_LANDSCAPE; final WindowState window = createWindow(null /* parent */, TYPE_BASE_APPLICATION, dc, "w"); window.getTask().mTaskRecord = mock(TaskRecord.class, ExtendedMockito.RETURNS_DEEP_STUBS); window.mAppToken.mOrientation = SCREEN_ORIENTATION_LANDSCAPE; window.mAppToken.setOrientation(newOrientation); ActivityRecord activityRecord = mock(ActivityRecord.class); Loading @@ -606,22 +603,21 @@ public class DisplayContentTests extends WindowTestsBase { verify(mWm.mAtmService).updateDisplayOverrideConfigurationLocked(captor.capture(), same(activityRecord), anyBoolean(), eq(dc.getDisplayId())); final Configuration newDisplayConfig = captor.getValue(); assertEquals(Configuration.ORIENTATION_LANDSCAPE, newDisplayConfig.orientation); assertEquals(Configuration.ORIENTATION_PORTRAIT, newDisplayConfig.orientation); } @Test public void testOnDescendantOrientationRequestChanged_FrozenToUserRotation() { final DisplayInfo info = new DisplayInfo(); info.logicalWidth = 1080; info.logicalHeight = 1920; info.logicalDensityDpi = 240; final DisplayContent dc = createNewDisplay(info); final DisplayContent dc = createNewDisplay(); dc.getDisplayRotation().setFixedToUserRotation(true); mWm.mAtmService.mRootActivityContainer = mock(RootActivityContainer.class); final int newOrientation = dc.getLastOrientation() == SCREEN_ORIENTATION_LANDSCAPE ? SCREEN_ORIENTATION_PORTRAIT : SCREEN_ORIENTATION_LANDSCAPE; final WindowState window = createWindow(null /* parent */, TYPE_BASE_APPLICATION, dc, "w"); window.getTask().mTaskRecord = mock(TaskRecord.class, ExtendedMockito.RETURNS_DEEP_STUBS); window.mAppToken.mOrientation = SCREEN_ORIENTATION_LANDSCAPE; window.mAppToken.setOrientation(newOrientation); ActivityRecord activityRecord = mock(ActivityRecord.class); Loading Loading
services/core/java/com/android/server/wm/DisplayContent.java +10 −12 Original line number Diff line number Diff line Loading @@ -33,14 +33,11 @@ import static android.view.Display.DEFAULT_DISPLAY; import static android.view.Display.FLAG_PRIVATE; import static android.view.Display.INVALID_DISPLAY; import static android.view.InsetsState.TYPE_IME; import static android.view.InsetsState.TYPE_NAVIGATION_BAR; import static android.view.InsetsState.TYPE_TOP_BAR; import static android.view.Surface.ROTATION_0; import static android.view.Surface.ROTATION_180; import static android.view.Surface.ROTATION_270; import static android.view.Surface.ROTATION_90; import static android.view.View.GONE; import static android.view.ViewRootImpl.NEW_INSETS_MODE_FULL; import static android.view.WindowManager.DOCKED_BOTTOM; import static android.view.WindowManager.DOCKED_INVALID; import static android.view.WindowManager.DOCKED_TOP; Loading Loading @@ -175,7 +172,6 @@ import android.view.SurfaceControl; import android.view.SurfaceControl.Transaction; import android.view.SurfaceSession; import android.view.View; import android.view.ViewRootImpl; import android.view.WindowManager; import android.view.WindowManagerPolicyConstants.PointerEventListener; Loading Loading @@ -1162,14 +1158,12 @@ class DisplayContent extends WindowContainer<DisplayContent.DisplayChildWindowCo @Override boolean onDescendantOrientationChanged(IBinder freezeDisplayToken, ConfigurationContainer requestingContainer) { final int previousRotation = mRotation; final Configuration config = updateOrientationFromAppTokens( getRequestedOverrideConfiguration(), freezeDisplayToken, false); // This event is considered handled iff a configuration propagation is triggered, because // that's the only place lower level containers check if they need to do something to this // request. The only guaranteed signal is that the display is rotated to a different // orientation (i.e. rotating 180 degrees doesn't count). final boolean handled = (mRotation - previousRotation) % 2 != 0; // If display rotation class tells us that it doesn't consider app requested orientation, // this display won't rotate just because of an app changes its requested orientation. Thus // it indicates that this display chooses not to handle this request. final boolean handled = getDisplayRotation().respectAppRequestedOrientation(); if (config == null) { return handled; } Loading @@ -1191,6 +1185,11 @@ class DisplayContent extends WindowContainer<DisplayContent.DisplayChildWindowCo return handled; } @Override boolean handlesOrientationChangeFromDescendant() { return getDisplayRotation().respectAppRequestedOrientation(); } /** * Determine the new desired orientation of this display. * Loading Loading @@ -1371,8 +1370,7 @@ class DisplayContent extends WindowContainer<DisplayContent.DisplayChildWindowCo if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Display id=" + mDisplayId + " selected orientation " + lastOrientation + ", got rotation " + rotation + " which has " + " metrics"); + ", got rotation " + rotation); if (oldRotation == rotation) { // No change. Loading
services/core/java/com/android/server/wm/DisplayRotation.java +9 −0 Original line number Diff line number Diff line Loading @@ -329,6 +329,15 @@ public class DisplayRotation { return mFixedToUserRotation; } /** * Returns {@code true} if this display rotation takes app requested orientation into * consideration; {@code false} otherwise. For the time being the only case where this is {@code * false} is when {@link #isFixedToUserRotation()} is {@code true}. */ boolean respectAppRequestedOrientation() { return !mFixedToUserRotation; } public int getLandscapeRotation() { return mLandscapeRotation; } Loading
services/core/java/com/android/server/wm/TaskRecord.java +5 −1 Original line number Diff line number Diff line Loading @@ -2197,11 +2197,15 @@ class TaskRecord extends ConfigurationContainer { // In FULLSCREEN mode, always start with empty bounds to indicate "fill parent" outOverrideBounds.setEmpty(); final boolean parentHandlesOrientationChange = mTask != null && mTask.getParent() != null && mTask.getParent().handlesOrientationChangeFromDescendant(); // If the task or its top activity requires a different orientation, make it fit the // available bounds by scaling down its bounds. int forcedOrientation = getTopActivityRequestedOrientation(); if (forcedOrientation != ORIENTATION_UNDEFINED && forcedOrientation != newParentConfig.orientation) { && forcedOrientation != newParentConfig.orientation && !parentHandlesOrientationChange) { final Rect parentBounds = newParentConfig.windowConfiguration.getBounds(); final int parentWidth = parentBounds.width(); final int parentHeight = parentBounds.height(); Loading
services/core/java/com/android/server/wm/WindowContainer.java +15 −0 Original line number Diff line number Diff line Loading @@ -714,6 +714,21 @@ class WindowContainer<E extends WindowContainer> extends ConfigurationContainer< requestingContainer); } /** * Check if this container or its parent will handle orientation changes from descendants. It's * different from the return value of {@link #onDescendantOrientationChanged(IBinder, * ConfigurationContainer)} in the sense that the return value of this method tells if this * container or its parent will handle the request eventually, while the return value of the * other method is if it handled the request synchronously. * * @return {@code true} if it handles or will handle orientation change in the future; {@code * false} if it won't handle the change at anytime. */ boolean handlesOrientationChangeFromDescendant() { final WindowContainer parent = getParent(); return parent != null && parent.handlesOrientationChangeFromDescendant(); } /** * Calls {@link #setOrientation(int, IBinder, ActivityRecord)} with {@code null} to the last 2 * parameters. Loading
services/tests/wmtests/src/com/android/server/wm/DisplayContentTests.java +11 −15 Original line number Diff line number Diff line Loading @@ -59,7 +59,6 @@ import android.os.SystemClock; import android.platform.test.annotations.Presubmit; import android.util.DisplayMetrics; import android.view.DisplayCutout; import android.view.DisplayInfo; import android.view.Gravity; import android.view.MotionEvent; import android.view.Surface; Loading Loading @@ -585,17 +584,15 @@ public class DisplayContentTests extends WindowTestsBase { @Test public void testOnDescendantOrientationRequestChanged() { final DisplayInfo info = new DisplayInfo(); info.logicalWidth = 1080; info.logicalHeight = 1920; info.logicalDensityDpi = 240; final DisplayContent dc = createNewDisplay(info); dc.configureDisplayPolicy(); final DisplayContent dc = createNewDisplay(); mWm.mAtmService.mRootActivityContainer = mock(RootActivityContainer.class); final int newOrientation = dc.getLastOrientation() == SCREEN_ORIENTATION_LANDSCAPE ? SCREEN_ORIENTATION_PORTRAIT : SCREEN_ORIENTATION_LANDSCAPE; final WindowState window = createWindow(null /* parent */, TYPE_BASE_APPLICATION, dc, "w"); window.getTask().mTaskRecord = mock(TaskRecord.class, ExtendedMockito.RETURNS_DEEP_STUBS); window.mAppToken.mOrientation = SCREEN_ORIENTATION_LANDSCAPE; window.mAppToken.setOrientation(newOrientation); ActivityRecord activityRecord = mock(ActivityRecord.class); Loading @@ -606,22 +603,21 @@ public class DisplayContentTests extends WindowTestsBase { verify(mWm.mAtmService).updateDisplayOverrideConfigurationLocked(captor.capture(), same(activityRecord), anyBoolean(), eq(dc.getDisplayId())); final Configuration newDisplayConfig = captor.getValue(); assertEquals(Configuration.ORIENTATION_LANDSCAPE, newDisplayConfig.orientation); assertEquals(Configuration.ORIENTATION_PORTRAIT, newDisplayConfig.orientation); } @Test public void testOnDescendantOrientationRequestChanged_FrozenToUserRotation() { final DisplayInfo info = new DisplayInfo(); info.logicalWidth = 1080; info.logicalHeight = 1920; info.logicalDensityDpi = 240; final DisplayContent dc = createNewDisplay(info); final DisplayContent dc = createNewDisplay(); dc.getDisplayRotation().setFixedToUserRotation(true); mWm.mAtmService.mRootActivityContainer = mock(RootActivityContainer.class); final int newOrientation = dc.getLastOrientation() == SCREEN_ORIENTATION_LANDSCAPE ? SCREEN_ORIENTATION_PORTRAIT : SCREEN_ORIENTATION_LANDSCAPE; final WindowState window = createWindow(null /* parent */, TYPE_BASE_APPLICATION, dc, "w"); window.getTask().mTaskRecord = mock(TaskRecord.class, ExtendedMockito.RETURNS_DEEP_STUBS); window.mAppToken.mOrientation = SCREEN_ORIENTATION_LANDSCAPE; window.mAppToken.setOrientation(newOrientation); ActivityRecord activityRecord = mock(ActivityRecord.class); Loading