From 91c8c9ea8f304abebdd516e1e64dc88ac62006a5 Mon Sep 17 00:00:00 2001 From: Alex Florescu Date: Fri, 25 Jun 2021 11:31:47 +0100 Subject: [PATCH] Introduce separate rotation lock settings per device state. This will be flagged with config_perDeviceStateRotationLock. If true, a distinct rotation lock settings can be maintained for each device state. Some device states won't need their own rotation lock setting and in those cases, the setting of the previous device state will be used. The existing global setting "Settings.System.ACCELEROMETER_ROTATION" still works the same and reflects the setting for the currently active state. Test: atest SystemUiTests:RotationLockControllerImplTest Test: atest SystemUiTests:DeviceStateRotationLockSettingControllerTest Bug: 183001527 Change-Id: I1cbcfae7db7c01745ea7ad665432f8651d8f1546 --- core/java/android/provider/Settings.java | 55 ++++ core/res/res/values/config.xml | 11 + core/res/res/values/symbols.xml | 2 + .../validators/SecureSettingsValidators.java | 29 +++ ...iceStateRotationLockSettingController.java | 239 ++++++++++++++++++ .../policy/RotationLockControllerImpl.java | 55 ++-- .../policy/dagger/StatusBarPolicyModule.java | 17 ++ .../systemui/util/dagger/UtilModule.java | 5 +- .../util/wrapper/RotationPolicyWrapper.kt | 67 +++++ .../util/wrapper/UtilWrapperModule.kt | 29 +++ ...tateRotationLockSettingControllerTest.java | 239 ++++++++++++++++++ .../RotationLockControllerImplTest.java | 113 +++++++++ 12 files changed, 843 insertions(+), 18 deletions(-) create mode 100644 packages/SystemUI/src/com/android/systemui/statusbar/policy/DeviceStateRotationLockSettingController.java create mode 100644 packages/SystemUI/src/com/android/systemui/util/wrapper/RotationPolicyWrapper.kt create mode 100644 packages/SystemUI/src/com/android/systemui/util/wrapper/UtilWrapperModule.kt create mode 100644 packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/DeviceStateRotationLockSettingControllerTest.java create mode 100644 packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/RotationLockControllerImplTest.java diff --git a/core/java/android/provider/Settings.java b/core/java/android/provider/Settings.java index 589ecc0a4de50..dc4a74766ed92 100644 --- a/core/java/android/provider/Settings.java +++ b/core/java/android/provider/Settings.java @@ -10119,6 +10119,61 @@ public final class Settings { @Readable public static final String GAME_DASHBOARD_ALWAYS_ON = "game_dashboard_always_on"; + + /** + * For this device state, no specific auto-rotation lock setting should be applied. + * If the user toggles the auto-rotate lock in this state, the setting will apply to the + * previously valid device state. + * @hide + */ + public static final int DEVICE_STATE_ROTATION_LOCK_IGNORED = 0; + /** + * For this device state, the setting for auto-rotation is locked. + * @hide + */ + public static final int DEVICE_STATE_ROTATION_LOCK_LOCKED = 1; + /** + * For this device state, the setting for auto-rotation is unlocked. + * @hide + */ + public static final int DEVICE_STATE_ROTATION_LOCK_UNLOCKED = 2; + + /** + * The different settings that can be used as values with + * {@link #DEVICE_STATE_ROTATION_LOCK}. + * @hide + */ + @IntDef(prefix = {"DEVICE_STATE_ROTATION_LOCK_"}, value = { + DEVICE_STATE_ROTATION_LOCK_IGNORED, + DEVICE_STATE_ROTATION_LOCK_LOCKED, + DEVICE_STATE_ROTATION_LOCK_UNLOCKED, + }) + @Retention(RetentionPolicy.SOURCE) + @interface DeviceStateRotationLockSetting { + } + + /** + * Rotation lock setting keyed on device state. + * + * This holds a serialized map using int keys that represent Device States and value of + * {@link DeviceStateRotationLockSetting} representing the rotation lock setting for that + * device state. + * + * Serialized as key0:value0:key1:value1:...:keyN:valueN. + * + * Example: "0:1:1:2:2:1" + * This example represents a map of: + * + * + * @hide + */ + public static final String DEVICE_STATE_ROTATION_LOCK = + "device_state_rotation_lock"; + /** * These entries are considered common between the personal and the managed profile, * since the managed profile doesn't get to change them. diff --git a/core/res/res/values/config.xml b/core/res/res/values/config.xml index ef8e938cbca76..a0f5ba1196b3e 100644 --- a/core/res/res/values/config.xml +++ b/core/res/res/values/config.xml @@ -666,6 +666,17 @@ display is powered on at the same time. --> true + + + +