Loading core/java/android/view/IWindowManager.aidl +5 −0 Original line number Diff line number Diff line Loading @@ -387,6 +387,11 @@ interface IWindowManager */ boolean isRotationFrozen(); /** * Sets display rotation to {@link rotation} if auto-rotate is OFF. */ void setRotationAtAngleIfLocked(int rotation, String caller); /** * Lock the display orientation to the specified rotation, or to the current * rotation if -1. Sensor input will be ignored until thawRotation() is called. Loading core/java/com/android/internal/view/RotationPolicy.java +20 −0 Original line number Diff line number Diff line Loading @@ -16,6 +16,8 @@ package com.android.internal.view; import static android.provider.Settings.System.ACCELEROMETER_ROTATION; import android.content.Context; import android.content.pm.PackageManager; import android.content.res.Configuration; Loading Loading @@ -138,6 +140,24 @@ public final class RotationPolicy { setRotationLock(enabled, rotation, caller); } /** * Sets screen rotation to {@link rotation} if the value of {@link ACCELEROMETER_ROTATION} is * false. */ public static void setRotationAtAngleIfLocked(final int rotation, String caller) { AsyncTask.execute(new Runnable() { @Override public void run() { try { IWindowManager wm = WindowManagerGlobal.getWindowManagerService(); wm.setRotationAtAngleIfLocked(rotation, caller); } catch (RemoteException exc) { Log.w(TAG, "Unable to set rotation to:" + rotation); } } }); } /** * Enables or disables natural rotation lock from Accessibility settings. * Loading packages/SystemUI/shared/src/com/android/systemui/shared/rotation/RotationButtonController.java +15 −3 Original line number Diff line number Diff line Loading @@ -67,6 +67,7 @@ import com.android.systemui.shared.rotation.RotationButton.RotationButtonUpdates import com.android.systemui.shared.system.ActivityManagerWrapper; import com.android.systemui.shared.system.TaskStackChangeListener; import com.android.systemui.shared.system.TaskStackChangeListeners; import com.android.window.flags.Flags; import java.io.PrintWriter; import java.util.Optional; Loading Loading @@ -286,12 +287,23 @@ public class RotationButtonController { TaskStackChangeListeners.getInstance().unregisterTaskStackListener(mTaskStackListener); } public void setRotationLockedAtAngle( /** * Sets device rotation to {@code rotationSuggestion} if {@code isLocked} is true and * {@link Flags#enableDeviceStateAutoRotateSettingRefactor()} is disabled. * <p> When {@link Flags#enableDeviceStateAutoRotateSettingRefactor()} is enabled, the rotation * change in system server is conditional on auto-rotate still being OFF. */ public void setRotationAtAngle( @Nullable Boolean isLocked, int rotationSuggestion, String caller) { if (isLocked == null) { // Ignore if we can't read the setting for the current user return; } if (Flags.enableDeviceStateAutoRotateSettingRefactor()) { RotationPolicy.setRotationAtAngleIfLocked(rotationSuggestion, caller); return; } RotationPolicy.setRotationLockAtAngle(mContext, /* enabled= */ isLocked, /* rotation= */ rotationSuggestion, caller); } Loading Loading @@ -476,7 +488,7 @@ public class RotationButtonController { if (isRotationLocked || mRotationButton.isVisible()) { // Do not allow a change in rotation to set user rotation when docked. if (shouldOverrideUserLockPrefs(rotation) && isRotationLocked && !mDocked) { setRotationLockedAtAngle(true, rotation, /* caller= */ setRotationAtAngle(true, rotation, /* caller= */ "RotationButtonController#onRotationWatcherChanged"); } setRotateSuggestionButtonState(false /* visible */, true /* forced */); Loading Loading @@ -581,7 +593,7 @@ public class RotationButtonController { private void onRotateSuggestionClick(View v) { mUiEventLogger.log(RotationButtonEvent.ROTATION_SUGGESTION_ACCEPTED); incrementNumAcceptedRotationSuggestionsIfNeeded(); setRotationLockedAtAngle( setRotationAtAngle( RotationPolicyUtil.isRotationLocked(mContext), mLastRotationSuggestion, /* caller= */ "RotationButtonController#onRotateSuggestionClick"); Log.i(TAG, "onRotateSuggestionClick() mLastRotationSuggestion=" + mLastRotationSuggestion); Loading packages/SystemUI/src/com/android/systemui/navigationbar/views/NavigationBar.java +1 −1 Original line number Diff line number Diff line Loading @@ -847,7 +847,7 @@ public class NavigationBar extends ViewController<NavigationBarView> implements // mode. This will automatically happen when switching from auto-rotate to locked mode. @Nullable Boolean isRotationLocked = RotationPolicyUtil.isRotationLocked(mContext); if (display != null && isRotationLocked) { rotationButtonController.setRotationLockedAtAngle(isRotationLocked, rotationButtonController.setRotationAtAngle(isRotationLocked, display.getRotation(), /* caller= */ "NavigationBar#onViewAttached"); } } else { Loading packages/SystemUI/src/com/android/systemui/util/wrapper/RotationPolicyWrapper.kt +10 −0 Original line number Diff line number Diff line Loading @@ -30,6 +30,7 @@ import javax.inject.Inject interface RotationPolicyWrapper { fun setRotationLock(enabled: Boolean, caller: String) fun setRotationLockAtAngle(enabled: Boolean, rotation: Int, caller: String) fun setRotationAtAngleIfLocked(rotation: Int, caller: String) fun getRotationLockOrientation(): Int fun isRotationLockToggleVisible(): Boolean fun isRotationLocked(): Boolean Loading @@ -54,6 +55,15 @@ class RotationPolicyWrapperImpl @Inject constructor( RotationPolicy.setRotationLockAtAngle(context, enabled, rotation, caller) } /** * Sets screen rotation to [rotation] if the value of [ACCELEROMETER_ROTATION] is false. */ override fun setRotationAtAngleIfLocked(rotation: Int, caller: String) { traceSection("RotationPolicyWrapperImpl#setRotationAtAngleIfLocked") { RotationPolicy.setRotationAtAngleIfLocked(rotation, caller) } } override fun getRotationLockOrientation(): Int = RotationPolicy.getRotationLockOrientation(context) Loading Loading
core/java/android/view/IWindowManager.aidl +5 −0 Original line number Diff line number Diff line Loading @@ -387,6 +387,11 @@ interface IWindowManager */ boolean isRotationFrozen(); /** * Sets display rotation to {@link rotation} if auto-rotate is OFF. */ void setRotationAtAngleIfLocked(int rotation, String caller); /** * Lock the display orientation to the specified rotation, or to the current * rotation if -1. Sensor input will be ignored until thawRotation() is called. Loading
core/java/com/android/internal/view/RotationPolicy.java +20 −0 Original line number Diff line number Diff line Loading @@ -16,6 +16,8 @@ package com.android.internal.view; import static android.provider.Settings.System.ACCELEROMETER_ROTATION; import android.content.Context; import android.content.pm.PackageManager; import android.content.res.Configuration; Loading Loading @@ -138,6 +140,24 @@ public final class RotationPolicy { setRotationLock(enabled, rotation, caller); } /** * Sets screen rotation to {@link rotation} if the value of {@link ACCELEROMETER_ROTATION} is * false. */ public static void setRotationAtAngleIfLocked(final int rotation, String caller) { AsyncTask.execute(new Runnable() { @Override public void run() { try { IWindowManager wm = WindowManagerGlobal.getWindowManagerService(); wm.setRotationAtAngleIfLocked(rotation, caller); } catch (RemoteException exc) { Log.w(TAG, "Unable to set rotation to:" + rotation); } } }); } /** * Enables or disables natural rotation lock from Accessibility settings. * Loading
packages/SystemUI/shared/src/com/android/systemui/shared/rotation/RotationButtonController.java +15 −3 Original line number Diff line number Diff line Loading @@ -67,6 +67,7 @@ import com.android.systemui.shared.rotation.RotationButton.RotationButtonUpdates import com.android.systemui.shared.system.ActivityManagerWrapper; import com.android.systemui.shared.system.TaskStackChangeListener; import com.android.systemui.shared.system.TaskStackChangeListeners; import com.android.window.flags.Flags; import java.io.PrintWriter; import java.util.Optional; Loading Loading @@ -286,12 +287,23 @@ public class RotationButtonController { TaskStackChangeListeners.getInstance().unregisterTaskStackListener(mTaskStackListener); } public void setRotationLockedAtAngle( /** * Sets device rotation to {@code rotationSuggestion} if {@code isLocked} is true and * {@link Flags#enableDeviceStateAutoRotateSettingRefactor()} is disabled. * <p> When {@link Flags#enableDeviceStateAutoRotateSettingRefactor()} is enabled, the rotation * change in system server is conditional on auto-rotate still being OFF. */ public void setRotationAtAngle( @Nullable Boolean isLocked, int rotationSuggestion, String caller) { if (isLocked == null) { // Ignore if we can't read the setting for the current user return; } if (Flags.enableDeviceStateAutoRotateSettingRefactor()) { RotationPolicy.setRotationAtAngleIfLocked(rotationSuggestion, caller); return; } RotationPolicy.setRotationLockAtAngle(mContext, /* enabled= */ isLocked, /* rotation= */ rotationSuggestion, caller); } Loading Loading @@ -476,7 +488,7 @@ public class RotationButtonController { if (isRotationLocked || mRotationButton.isVisible()) { // Do not allow a change in rotation to set user rotation when docked. if (shouldOverrideUserLockPrefs(rotation) && isRotationLocked && !mDocked) { setRotationLockedAtAngle(true, rotation, /* caller= */ setRotationAtAngle(true, rotation, /* caller= */ "RotationButtonController#onRotationWatcherChanged"); } setRotateSuggestionButtonState(false /* visible */, true /* forced */); Loading Loading @@ -581,7 +593,7 @@ public class RotationButtonController { private void onRotateSuggestionClick(View v) { mUiEventLogger.log(RotationButtonEvent.ROTATION_SUGGESTION_ACCEPTED); incrementNumAcceptedRotationSuggestionsIfNeeded(); setRotationLockedAtAngle( setRotationAtAngle( RotationPolicyUtil.isRotationLocked(mContext), mLastRotationSuggestion, /* caller= */ "RotationButtonController#onRotateSuggestionClick"); Log.i(TAG, "onRotateSuggestionClick() mLastRotationSuggestion=" + mLastRotationSuggestion); Loading
packages/SystemUI/src/com/android/systemui/navigationbar/views/NavigationBar.java +1 −1 Original line number Diff line number Diff line Loading @@ -847,7 +847,7 @@ public class NavigationBar extends ViewController<NavigationBarView> implements // mode. This will automatically happen when switching from auto-rotate to locked mode. @Nullable Boolean isRotationLocked = RotationPolicyUtil.isRotationLocked(mContext); if (display != null && isRotationLocked) { rotationButtonController.setRotationLockedAtAngle(isRotationLocked, rotationButtonController.setRotationAtAngle(isRotationLocked, display.getRotation(), /* caller= */ "NavigationBar#onViewAttached"); } } else { Loading
packages/SystemUI/src/com/android/systemui/util/wrapper/RotationPolicyWrapper.kt +10 −0 Original line number Diff line number Diff line Loading @@ -30,6 +30,7 @@ import javax.inject.Inject interface RotationPolicyWrapper { fun setRotationLock(enabled: Boolean, caller: String) fun setRotationLockAtAngle(enabled: Boolean, rotation: Int, caller: String) fun setRotationAtAngleIfLocked(rotation: Int, caller: String) fun getRotationLockOrientation(): Int fun isRotationLockToggleVisible(): Boolean fun isRotationLocked(): Boolean Loading @@ -54,6 +55,15 @@ class RotationPolicyWrapperImpl @Inject constructor( RotationPolicy.setRotationLockAtAngle(context, enabled, rotation, caller) } /** * Sets screen rotation to [rotation] if the value of [ACCELEROMETER_ROTATION] is false. */ override fun setRotationAtAngleIfLocked(rotation: Int, caller: String) { traceSection("RotationPolicyWrapperImpl#setRotationAtAngleIfLocked") { RotationPolicy.setRotationAtAngleIfLocked(rotation, caller) } } override fun getRotationLockOrientation(): Int = RotationPolicy.getRotationLockOrientation(context) Loading