Loading core/java/android/util/RotationUtils.java +20 −0 Original line number Diff line number Diff line Loading @@ -27,6 +27,7 @@ import android.graphics.Matrix; import android.graphics.Point; import android.graphics.PointF; import android.graphics.Rect; import android.view.Surface; import android.view.Surface.Rotation; import android.view.SurfaceControl; Loading Loading @@ -245,4 +246,23 @@ public class RotationUtils { throw new IllegalArgumentException("Unknown rotation: " + rotation); } } /** * Reverses the rotation direction around the Z axis. Note that this method assumes all * rotations are relative to {@link Surface.ROTATION_0}. * * @param rotation the original rotation. * @return the new rotation that should be applied. */ @Surface.Rotation public static int reverseRotationDirectionAroundZAxis(@Surface.Rotation int rotation) { // Flipping 270 and 90 has the same effect as changing the direction which rotation is // applied. if (rotation == Surface.ROTATION_90) { rotation = Surface.ROTATION_270; } else if (rotation == Surface.ROTATION_270) { rotation = Surface.ROTATION_90; } return rotation; } } core/res/res/values/config.xml +7 −0 Original line number Diff line number Diff line Loading @@ -983,6 +983,13 @@ <integer-array name="config_deviceStatesToReverseDefaultDisplayRotationAroundZAxis"> </integer-array> <!-- Boolean indicating whether secondary built-in displays should have their orientation match the active default display. This config assumes that the secondary display only requires swapping ROTATION_90 and ROTATION_270. TODO(b/265991392): This should eventually be configured and parsed in display_settings.xml --> <bool name="config_matchSecondaryInternalDisplaysOrientationToReverseDefaultDisplay">true</bool> <!-- Indicate available ColorDisplayManager.COLOR_MODE_xxx. --> <integer-array name="config_availableColorModes"> <!-- Example: Loading core/res/res/values/symbols.xml +7 −0 Original line number Diff line number Diff line Loading @@ -3404,6 +3404,13 @@ TODO(b/265312193): Remove this workaround when this bug is fixed.--> <java-symbol type="array" name="config_deviceStatesToReverseDefaultDisplayRotationAroundZAxis" /> <!-- Boolean indicating whether secondary built-in displays should have their orientation match the active default display. This config assumes that the secondary display only requires swapping ROTATION_90 and ROTATION_270. TODO(b/265991392): This should eventually be configured and parsed in display_settings.xml --> <java-symbol type="bool" name="config_matchSecondaryInternalDisplaysOrientationToReverseDefaultDisplay" /> <!-- Default user restrictions for the SYSTEM user --> <java-symbol type="array" name="config_defaultFirstUserRestrictions" /> Loading services/core/java/com/android/server/wm/DeviceStateController.java +23 −9 Original line number Diff line number Diff line Loading @@ -24,6 +24,7 @@ import android.os.Handler; import android.os.HandlerExecutor; import com.android.internal.R; import com.android.internal.annotations.GuardedBy; import com.android.internal.util.ArrayUtils; import java.util.ArrayList; Loading @@ -48,9 +49,12 @@ final class DeviceStateController implements DeviceStateManager.DeviceStateCallb private final int[] mRearDisplayDeviceStates; @NonNull private final int[] mReverseRotationAroundZAxisStates; @GuardedBy("this") @NonNull private final List<Consumer<DeviceState>> mDeviceStateCallbacks = new ArrayList<>(); private final boolean mMatchBuiltInDisplayOrientationToDefaultDisplay; @Nullable private DeviceState mLastDeviceState; private int mCurrentState; Loading @@ -72,21 +76,20 @@ final class DeviceStateController implements DeviceStateManager.DeviceStateCallb .getIntArray(R.array.config_rearDisplayDeviceStates); mReverseRotationAroundZAxisStates = context.getResources() .getIntArray(R.array.config_deviceStatesToReverseDefaultDisplayRotationAroundZAxis); mMatchBuiltInDisplayOrientationToDefaultDisplay = context.getResources() .getBoolean(R.bool .config_matchSecondaryInternalDisplaysOrientationToReverseDefaultDisplay); if (mDeviceStateManager != null) { mDeviceStateManager.registerCallback(new HandlerExecutor(handler), this); } } void unregisterFromDeviceStateManager() { if (mDeviceStateManager != null) { mDeviceStateManager.unregisterCallback(this); } } void registerDeviceStateCallback(@NonNull Consumer<DeviceState> callback) { synchronized (this) { mDeviceStateCallbacks.add(callback); } } /** * @return true if the rotation direction on the Z axis should be reversed. Loading @@ -95,6 +98,15 @@ final class DeviceStateController implements DeviceStateManager.DeviceStateCallb return ArrayUtils.contains(mReverseRotationAroundZAxisStates, mCurrentState); } /** * @return true if non-default built-in displays should match the default display's rotation. */ boolean shouldMatchBuiltInDisplayOrientationToReverseDefaultDisplay() { // TODO(b/265991392): This should come from display_settings.xml once it's easier to // extend with complex configurations. return mMatchBuiltInDisplayOrientationToDefaultDisplay; } @Override public void onStateChanged(int state) { mCurrentState = state; Loading @@ -115,9 +127,11 @@ final class DeviceStateController implements DeviceStateManager.DeviceStateCallb if (mLastDeviceState == null || !mLastDeviceState.equals(deviceState)) { mLastDeviceState = deviceState; synchronized (this) { for (Consumer<DeviceState> callback : mDeviceStateCallbacks) { callback.accept(mLastDeviceState); } } } } } services/core/java/com/android/server/wm/DisplayContent.java +7 −5 Original line number Diff line number Diff line Loading @@ -595,7 +595,8 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp final FixedRotationTransitionListener mFixedRotationTransitionListener = new FixedRotationTransitionListener(); private final DeviceStateController mDeviceStateController; @VisibleForTesting final DeviceStateController mDeviceStateController; private final PhysicalDisplaySwitchTransitionLauncher mDisplaySwitchTransitionLauncher; final RemoteDisplayChangeController mRemoteDisplayChangeController; Loading Loading @@ -1091,7 +1092,8 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp * @param display May not be null. * @param root {@link RootWindowContainer} */ DisplayContent(Display display, RootWindowContainer root) { DisplayContent(Display display, RootWindowContainer root, @NonNull DeviceStateController deviceStateController) { super(root.mWindowManager, "DisplayContent", FEATURE_ROOT); if (mWmService.mRoot.getDisplayContent(display.getDisplayId()) != null) { throw new IllegalArgumentException("Display with ID=" + display.getDisplayId() Loading Loading @@ -1151,11 +1153,11 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp mWmService.mAtmService.getRecentTasks().getInputListener()); } mDeviceStateController = new DeviceStateController(mWmService.mContext, mWmService.mH); mDeviceStateController = deviceStateController; mDisplayPolicy = new DisplayPolicy(mWmService, this); mDisplayRotation = new DisplayRotation(mWmService, this, mDisplayInfo.address, mDeviceStateController); mDeviceStateController, root.getDisplayRotationCoordinator()); final Consumer<DeviceStateController.DeviceState> deviceStateConsumer = (@NonNull DeviceStateController.DeviceState newFoldState) -> { Loading Loading @@ -3326,7 +3328,7 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp mTransitionController.unregisterLegacyListener(mFixedRotationTransitionListener); handleAnimatingStoppedAndTransition(); mWmService.stopFreezingDisplayLocked(); mDeviceStateController.unregisterFromDeviceStateManager(); mDisplayRotation.removeDefaultDisplayRotationChangedCallback(); super.removeImmediately(); if (DEBUG_DISPLAY) Slog.v(TAG_WM, "Removing display=" + this); mPointerEventDispatcher.dispose(); Loading Loading
core/java/android/util/RotationUtils.java +20 −0 Original line number Diff line number Diff line Loading @@ -27,6 +27,7 @@ import android.graphics.Matrix; import android.graphics.Point; import android.graphics.PointF; import android.graphics.Rect; import android.view.Surface; import android.view.Surface.Rotation; import android.view.SurfaceControl; Loading Loading @@ -245,4 +246,23 @@ public class RotationUtils { throw new IllegalArgumentException("Unknown rotation: " + rotation); } } /** * Reverses the rotation direction around the Z axis. Note that this method assumes all * rotations are relative to {@link Surface.ROTATION_0}. * * @param rotation the original rotation. * @return the new rotation that should be applied. */ @Surface.Rotation public static int reverseRotationDirectionAroundZAxis(@Surface.Rotation int rotation) { // Flipping 270 and 90 has the same effect as changing the direction which rotation is // applied. if (rotation == Surface.ROTATION_90) { rotation = Surface.ROTATION_270; } else if (rotation == Surface.ROTATION_270) { rotation = Surface.ROTATION_90; } return rotation; } }
core/res/res/values/config.xml +7 −0 Original line number Diff line number Diff line Loading @@ -983,6 +983,13 @@ <integer-array name="config_deviceStatesToReverseDefaultDisplayRotationAroundZAxis"> </integer-array> <!-- Boolean indicating whether secondary built-in displays should have their orientation match the active default display. This config assumes that the secondary display only requires swapping ROTATION_90 and ROTATION_270. TODO(b/265991392): This should eventually be configured and parsed in display_settings.xml --> <bool name="config_matchSecondaryInternalDisplaysOrientationToReverseDefaultDisplay">true</bool> <!-- Indicate available ColorDisplayManager.COLOR_MODE_xxx. --> <integer-array name="config_availableColorModes"> <!-- Example: Loading
core/res/res/values/symbols.xml +7 −0 Original line number Diff line number Diff line Loading @@ -3404,6 +3404,13 @@ TODO(b/265312193): Remove this workaround when this bug is fixed.--> <java-symbol type="array" name="config_deviceStatesToReverseDefaultDisplayRotationAroundZAxis" /> <!-- Boolean indicating whether secondary built-in displays should have their orientation match the active default display. This config assumes that the secondary display only requires swapping ROTATION_90 and ROTATION_270. TODO(b/265991392): This should eventually be configured and parsed in display_settings.xml --> <java-symbol type="bool" name="config_matchSecondaryInternalDisplaysOrientationToReverseDefaultDisplay" /> <!-- Default user restrictions for the SYSTEM user --> <java-symbol type="array" name="config_defaultFirstUserRestrictions" /> Loading
services/core/java/com/android/server/wm/DeviceStateController.java +23 −9 Original line number Diff line number Diff line Loading @@ -24,6 +24,7 @@ import android.os.Handler; import android.os.HandlerExecutor; import com.android.internal.R; import com.android.internal.annotations.GuardedBy; import com.android.internal.util.ArrayUtils; import java.util.ArrayList; Loading @@ -48,9 +49,12 @@ final class DeviceStateController implements DeviceStateManager.DeviceStateCallb private final int[] mRearDisplayDeviceStates; @NonNull private final int[] mReverseRotationAroundZAxisStates; @GuardedBy("this") @NonNull private final List<Consumer<DeviceState>> mDeviceStateCallbacks = new ArrayList<>(); private final boolean mMatchBuiltInDisplayOrientationToDefaultDisplay; @Nullable private DeviceState mLastDeviceState; private int mCurrentState; Loading @@ -72,21 +76,20 @@ final class DeviceStateController implements DeviceStateManager.DeviceStateCallb .getIntArray(R.array.config_rearDisplayDeviceStates); mReverseRotationAroundZAxisStates = context.getResources() .getIntArray(R.array.config_deviceStatesToReverseDefaultDisplayRotationAroundZAxis); mMatchBuiltInDisplayOrientationToDefaultDisplay = context.getResources() .getBoolean(R.bool .config_matchSecondaryInternalDisplaysOrientationToReverseDefaultDisplay); if (mDeviceStateManager != null) { mDeviceStateManager.registerCallback(new HandlerExecutor(handler), this); } } void unregisterFromDeviceStateManager() { if (mDeviceStateManager != null) { mDeviceStateManager.unregisterCallback(this); } } void registerDeviceStateCallback(@NonNull Consumer<DeviceState> callback) { synchronized (this) { mDeviceStateCallbacks.add(callback); } } /** * @return true if the rotation direction on the Z axis should be reversed. Loading @@ -95,6 +98,15 @@ final class DeviceStateController implements DeviceStateManager.DeviceStateCallb return ArrayUtils.contains(mReverseRotationAroundZAxisStates, mCurrentState); } /** * @return true if non-default built-in displays should match the default display's rotation. */ boolean shouldMatchBuiltInDisplayOrientationToReverseDefaultDisplay() { // TODO(b/265991392): This should come from display_settings.xml once it's easier to // extend with complex configurations. return mMatchBuiltInDisplayOrientationToDefaultDisplay; } @Override public void onStateChanged(int state) { mCurrentState = state; Loading @@ -115,9 +127,11 @@ final class DeviceStateController implements DeviceStateManager.DeviceStateCallb if (mLastDeviceState == null || !mLastDeviceState.equals(deviceState)) { mLastDeviceState = deviceState; synchronized (this) { for (Consumer<DeviceState> callback : mDeviceStateCallbacks) { callback.accept(mLastDeviceState); } } } } }
services/core/java/com/android/server/wm/DisplayContent.java +7 −5 Original line number Diff line number Diff line Loading @@ -595,7 +595,8 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp final FixedRotationTransitionListener mFixedRotationTransitionListener = new FixedRotationTransitionListener(); private final DeviceStateController mDeviceStateController; @VisibleForTesting final DeviceStateController mDeviceStateController; private final PhysicalDisplaySwitchTransitionLauncher mDisplaySwitchTransitionLauncher; final RemoteDisplayChangeController mRemoteDisplayChangeController; Loading Loading @@ -1091,7 +1092,8 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp * @param display May not be null. * @param root {@link RootWindowContainer} */ DisplayContent(Display display, RootWindowContainer root) { DisplayContent(Display display, RootWindowContainer root, @NonNull DeviceStateController deviceStateController) { super(root.mWindowManager, "DisplayContent", FEATURE_ROOT); if (mWmService.mRoot.getDisplayContent(display.getDisplayId()) != null) { throw new IllegalArgumentException("Display with ID=" + display.getDisplayId() Loading Loading @@ -1151,11 +1153,11 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp mWmService.mAtmService.getRecentTasks().getInputListener()); } mDeviceStateController = new DeviceStateController(mWmService.mContext, mWmService.mH); mDeviceStateController = deviceStateController; mDisplayPolicy = new DisplayPolicy(mWmService, this); mDisplayRotation = new DisplayRotation(mWmService, this, mDisplayInfo.address, mDeviceStateController); mDeviceStateController, root.getDisplayRotationCoordinator()); final Consumer<DeviceStateController.DeviceState> deviceStateConsumer = (@NonNull DeviceStateController.DeviceState newFoldState) -> { Loading Loading @@ -3326,7 +3328,7 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp mTransitionController.unregisterLegacyListener(mFixedRotationTransitionListener); handleAnimatingStoppedAndTransition(); mWmService.stopFreezingDisplayLocked(); mDeviceStateController.unregisterFromDeviceStateManager(); mDisplayRotation.removeDefaultDisplayRotationChangedCallback(); super.removeImmediately(); if (DEBUG_DISPLAY) Slog.v(TAG_WM, "Removing display=" + this); mPointerEventDispatcher.dispose(); Loading