Loading packages/SettingsLib/DeviceStateRotationLock/src/com/android/settingslib/devicestate/DeviceStateAutoRotateSettingManager.java +4 −1 Original line number Diff line number Diff line Loading @@ -68,11 +68,14 @@ public interface DeviceStateAutoRotateSettingManager extends Dumpable { * * @param proposedSetting Settings maps desired to be written into persisted setting. * @param currentSetting Current settings map * @return Resolved proposedSetting map */ @Discouraged(message = "This method is exclusively for internal use. The designated API for " + "updating settings is #updateSetting(int, boolean) in com.android.settingslib" + ".devicestate.DeviceStateAutoRotateSettingManager. Please use that method.") void updateSetting(SparseIntArray proposedSetting, SparseIntArray currentSetting); @NonNull SparseIntArray updateSetting(@NonNull SparseIntArray proposedSetting, @NonNull SparseIntArray currentSetting); /** * Get {@link DEVICE_STATE_ROTATION_LOCK} setting value for {@code deviceState}. Loading packages/SettingsLib/DeviceStateRotationLock/src/com/android/settingslib/devicestate/DeviceStateAutoRotateSettingManagerImpl.java +6 −1 Original line number Diff line number Diff line Loading @@ -162,8 +162,10 @@ public class DeviceStateAutoRotateSettingManagerImpl implements RotationPolicy.requestDeviceStateAutoRotateSettingChange(deviceState, !rotationLock); } @NonNull @Override public void updateSetting(SparseIntArray proposedSetting, SparseIntArray currentSetting) { public SparseIntArray updateSetting(@NonNull SparseIntArray proposedSetting, @NonNull SparseIntArray currentSetting) { if (!areAllDefaultsPresent(proposedSetting) || !areAllDefaultsPresent(currentSetting)) { // Either the postures in proposed setting or current setting map do not match with // device postures defined in the default in configuration. We should still go ahead Loading Loading @@ -221,6 +223,9 @@ public class DeviceStateAutoRotateSettingManagerImpl implements convertIntArrayToSerializedSetting(proposedSetting); mSecureSettings.putStringForUser(DEVICE_STATE_ROTATION_LOCK, serializedDeviceStateAutoRotateSetting, UserHandle.USER_CURRENT); resolveIgnoredAutoRotateStates(proposedSetting); return proposedSetting; } @Override Loading packages/SettingsLib/DeviceStateRotationLock/src/com/android/settingslib/devicestate/DeviceStateRotationLockSettingsManager.java +3 −2 Original line number Diff line number Diff line Loading @@ -140,8 +140,9 @@ public final class DeviceStateRotationLockSettingsManager implements } @Override public void updateSetting(SparseIntArray proposedSetting, SparseIntArray currentSetting) { @NonNull public SparseIntArray updateSetting(@NonNull SparseIntArray proposedSetting, @NonNull SparseIntArray currentSetting) { // This method is not supported in this implementation. Use updateSetting(int, boolean) // instead. This overload is intended for a refactored settings manager. throw new UnsupportedOperationException( Loading packages/SettingsLib/tests/integ/src/com/android/settingslib/devicestate/DeviceStateAutoRotateSettingManagerImplTest.kt +83 −4 Original line number Diff line number Diff line Loading @@ -66,7 +66,7 @@ class DeviceStateAutoRotateSettingManagerImplTest { "$DEVICE_STATE_ROTATION_KEY_UNFOLDED", "$DEVICE_STATE_ROTATION_KEY_REAR_DISPLAY:" + "$DEVICE_STATE_ROTATION_LOCK_IGNORED:" + "$DEVICE_STATE_ROTATION_KEY_UNFOLDED", "$DEVICE_STATE_ROTATION_KEY_FOLDED", "$DEVICE_STATE_ROTATION_KEY_UNFOLDED:$DEVICE_STATE_ROTATION_LOCK_UNLOCKED", "$DEVICE_STATE_ROTATION_KEY_FOLDED:$DEVICE_STATE_ROTATION_LOCK_LOCKED", ) Loading Loading @@ -299,7 +299,7 @@ class DeviceStateAutoRotateSettingManagerImplTest { expectedPairs[DEVICE_STATE_ROTATION_KEY_HALF_FOLDED] = DEVICE_STATE_ROTATION_LOCK_LOCKED expectedPairs[DEVICE_STATE_ROTATION_KEY_REAR_DISPLAY] = DEVICE_STATE_ROTATION_LOCK_LOCKED DEVICE_STATE_ROTATION_LOCK_UNLOCKED val deviceStateAutoRotateSetting = settingManager.getRotationLockSetting() Loading Loading @@ -435,6 +435,72 @@ class DeviceStateAutoRotateSettingManagerImplTest { assertThat(persistedSetting).isEqualTo(expectedPairs) } @Test fun updateSettingMap_sendsMapsWithOneUpdatedSetting_returnsResolvedMap() { val currentSettingMap = getDefaultResolvedMap() val proposedSettingMap = getDefaultResolvedMap() proposedSettingMap[DEVICE_STATE_ROTATION_KEY_FOLDED] = DEVICE_STATE_ROTATION_LOCK_UNLOCKED val expectedSettingIntArray = convertMapToSparseIntArray(proposedSettingMap) expectedSettingIntArray.put( DEVICE_STATE_ROTATION_KEY_REAR_DISPLAY, DEVICE_STATE_ROTATION_LOCK_UNLOCKED ) val actualProposedSettingIntArray = settingManager.updateSetting( convertMapToSparseIntArray(proposedSettingMap), convertMapToSparseIntArray(currentSettingMap) ) assertIntArrayEqual(expectedSettingIntArray, actualProposedSettingIntArray) } @Test fun updateSettingMap_sendsMapsWithTwoUpdatedSettings_returnsResolvedMap() { val currentSettingMap = getDefaultResolvedMap() val proposedSettingMap = getDefaultResolvedMap() proposedSettingMap[DEVICE_STATE_ROTATION_KEY_FOLDED] = DEVICE_STATE_ROTATION_LOCK_UNLOCKED proposedSettingMap[DEVICE_STATE_ROTATION_KEY_UNFOLDED] = DEVICE_STATE_ROTATION_LOCK_LOCKED val expectedSettingIntArray = convertMapToSparseIntArray(proposedSettingMap) expectedSettingIntArray.put( DEVICE_STATE_ROTATION_KEY_REAR_DISPLAY, DEVICE_STATE_ROTATION_LOCK_UNLOCKED ) expectedSettingIntArray.put( DEVICE_STATE_ROTATION_KEY_HALF_FOLDED, DEVICE_STATE_ROTATION_LOCK_LOCKED ) val actualProposedSettingIntArray = settingManager.updateSetting( convertMapToSparseIntArray(proposedSettingMap), convertMapToSparseIntArray(currentSettingMap) ) assertIntArrayEqual(expectedSettingIntArray, actualProposedSettingIntArray) } @Test fun updateSettingMap_settingValueForIgnoredChanged_returnsResolvedMap() { val currentSettingMap = getDefaultResolvedMap() val proposedSettingMap = getDefaultResolvedMap() proposedSettingMap[DEVICE_STATE_ROTATION_KEY_HALF_FOLDED] = DEVICE_STATE_ROTATION_LOCK_LOCKED val expectedSettingIntArray = convertMapToSparseIntArray(proposedSettingMap) expectedSettingIntArray.put( DEVICE_STATE_ROTATION_KEY_UNFOLDED, DEVICE_STATE_ROTATION_LOCK_LOCKED ) val actualProposedSettingIntArray = settingManager.updateSetting( convertMapToSparseIntArray(proposedSettingMap), convertMapToSparseIntArray(currentSettingMap) ) assertIntArrayEqual(expectedSettingIntArray, actualProposedSettingIntArray) } @Test fun updateSettingMap_currentSettingMissingValueForFallbackPosture_throwsIllegalStateException() { val currentSettingMap = getDefaultResolvedMap() Loading Loading @@ -577,7 +643,7 @@ class DeviceStateAutoRotateSettingManagerImplTest { defaultSettingMap[DEVICE_STATE_ROTATION_KEY_HALF_FOLDED] = DEVICE_STATE_ROTATION_LOCK_UNLOCKED defaultSettingMap[DEVICE_STATE_ROTATION_KEY_REAR_DISPLAY] = DEVICE_STATE_ROTATION_LOCK_UNLOCKED DEVICE_STATE_ROTATION_LOCK_LOCKED return defaultSettingMap } Loading Loading @@ -643,6 +709,19 @@ class DeviceStateAutoRotateSettingManagerImplTest { ).thenReturn(DEVICE_STATE_REAR_DISPLAY) } private fun assertIntArrayEqual( expectedIntArray: SparseIntArray, actualIntArray: SparseIntArray ) { assertThat(expectedIntArray.size()).isEqualTo(actualIntArray.size()) for (i in 0 until expectedIntArray.size()) { val expectedKey = expectedIntArray.keyAt(i) val expectedValue = expectedIntArray.valueAt(i) assertThat(actualIntArray.indexOfKey(expectedKey)).isGreaterThan(-1) assertThat(actualIntArray[expectedKey]).isEqualTo(expectedValue) } } private companion object { const val DEVICE_STATE_FOLDED = 0 const val DEVICE_STATE_HALF_FOLDED = 1 Loading @@ -654,7 +733,7 @@ class DeviceStateAutoRotateSettingManagerImplTest { const val FOLDED_LOCKED_OPEN_UNLOCKED_SETTING_UNRESOLVED: String = "0:1:1:0:2:2:3:0" const val FOLDED_LOCKED_OPEN_LOCKED_SETTING_UNRESOLVED: String = "0:1:1:0:2:1:3:0" const val FOLDED_UNLOCKED_OPEN_LOCKED_SETTING_UNRESOLVED: String = "0:2:1:0:2:1:3:0" const val FOLDED_UNLOCKED_OPEN_UNLOCKED_SETTING_RESOLVED: String = "0:1:1:2:2:2:3:0" const val FOLDED_UNLOCKED_OPEN_UNLOCKED_SETTING_RESOLVED: String = "0:2:1:2:2:2:3:2" const val INVALID_AUTO_ROTATE_VALUE_FOR_FOLDED_SETTING: String = "0:4:1:0:2:2:3:0" const val MISSING_FOLDED_KEY_AND_VALUE_SETTING: String = "1:0:2:2:3:0" const val MISSING_VALUE_FOR_FOLDED_SETTING: String = "0:1:0:2:2:3:0" Loading services/core/java/com/android/server/wm/DeviceStateAutoRotateSettingController.java +5 −3 Original line number Diff line number Diff line Loading @@ -331,7 +331,7 @@ public class DeviceStateAutoRotateSettingController { } if (!equals(mDeviceStateAutoRotateSetting, persistedDeviceStateAutoRotateSetting)) { mDeviceStateAutoRotateSettingManager.updateSetting( mDeviceStateAutoRotateSetting = mDeviceStateAutoRotateSettingManager.updateSetting( mDeviceStateAutoRotateSetting.clone(), persistedDeviceStateAutoRotateSetting == null ? getDefaultDeviceStateAutoRotateSetting() Loading Loading @@ -437,7 +437,8 @@ public class DeviceStateAutoRotateSettingController { * setting(DEVICE_STATE_ROTATION_LOCK) for a specific device posture. */ static final class UpdateDeviceStateAutoRotateSetting extends Event { @DeviceStateRotationLockKey final int mDevicePosture; @DeviceStateRotationLockKey final int mDevicePosture; final boolean mAutoRotate; /** Loading @@ -455,7 +456,8 @@ public class DeviceStateAutoRotateSettingController { * Event sent when the device posture changes. */ static final class UpdateDevicePosture extends Event { @DeviceStateRotationLockKey final int mDevicePosture; @DeviceStateRotationLockKey final int mDevicePosture; /** * @param devicePosture New device posture. Loading Loading
packages/SettingsLib/DeviceStateRotationLock/src/com/android/settingslib/devicestate/DeviceStateAutoRotateSettingManager.java +4 −1 Original line number Diff line number Diff line Loading @@ -68,11 +68,14 @@ public interface DeviceStateAutoRotateSettingManager extends Dumpable { * * @param proposedSetting Settings maps desired to be written into persisted setting. * @param currentSetting Current settings map * @return Resolved proposedSetting map */ @Discouraged(message = "This method is exclusively for internal use. The designated API for " + "updating settings is #updateSetting(int, boolean) in com.android.settingslib" + ".devicestate.DeviceStateAutoRotateSettingManager. Please use that method.") void updateSetting(SparseIntArray proposedSetting, SparseIntArray currentSetting); @NonNull SparseIntArray updateSetting(@NonNull SparseIntArray proposedSetting, @NonNull SparseIntArray currentSetting); /** * Get {@link DEVICE_STATE_ROTATION_LOCK} setting value for {@code deviceState}. Loading
packages/SettingsLib/DeviceStateRotationLock/src/com/android/settingslib/devicestate/DeviceStateAutoRotateSettingManagerImpl.java +6 −1 Original line number Diff line number Diff line Loading @@ -162,8 +162,10 @@ public class DeviceStateAutoRotateSettingManagerImpl implements RotationPolicy.requestDeviceStateAutoRotateSettingChange(deviceState, !rotationLock); } @NonNull @Override public void updateSetting(SparseIntArray proposedSetting, SparseIntArray currentSetting) { public SparseIntArray updateSetting(@NonNull SparseIntArray proposedSetting, @NonNull SparseIntArray currentSetting) { if (!areAllDefaultsPresent(proposedSetting) || !areAllDefaultsPresent(currentSetting)) { // Either the postures in proposed setting or current setting map do not match with // device postures defined in the default in configuration. We should still go ahead Loading Loading @@ -221,6 +223,9 @@ public class DeviceStateAutoRotateSettingManagerImpl implements convertIntArrayToSerializedSetting(proposedSetting); mSecureSettings.putStringForUser(DEVICE_STATE_ROTATION_LOCK, serializedDeviceStateAutoRotateSetting, UserHandle.USER_CURRENT); resolveIgnoredAutoRotateStates(proposedSetting); return proposedSetting; } @Override Loading
packages/SettingsLib/DeviceStateRotationLock/src/com/android/settingslib/devicestate/DeviceStateRotationLockSettingsManager.java +3 −2 Original line number Diff line number Diff line Loading @@ -140,8 +140,9 @@ public final class DeviceStateRotationLockSettingsManager implements } @Override public void updateSetting(SparseIntArray proposedSetting, SparseIntArray currentSetting) { @NonNull public SparseIntArray updateSetting(@NonNull SparseIntArray proposedSetting, @NonNull SparseIntArray currentSetting) { // This method is not supported in this implementation. Use updateSetting(int, boolean) // instead. This overload is intended for a refactored settings manager. throw new UnsupportedOperationException( Loading
packages/SettingsLib/tests/integ/src/com/android/settingslib/devicestate/DeviceStateAutoRotateSettingManagerImplTest.kt +83 −4 Original line number Diff line number Diff line Loading @@ -66,7 +66,7 @@ class DeviceStateAutoRotateSettingManagerImplTest { "$DEVICE_STATE_ROTATION_KEY_UNFOLDED", "$DEVICE_STATE_ROTATION_KEY_REAR_DISPLAY:" + "$DEVICE_STATE_ROTATION_LOCK_IGNORED:" + "$DEVICE_STATE_ROTATION_KEY_UNFOLDED", "$DEVICE_STATE_ROTATION_KEY_FOLDED", "$DEVICE_STATE_ROTATION_KEY_UNFOLDED:$DEVICE_STATE_ROTATION_LOCK_UNLOCKED", "$DEVICE_STATE_ROTATION_KEY_FOLDED:$DEVICE_STATE_ROTATION_LOCK_LOCKED", ) Loading Loading @@ -299,7 +299,7 @@ class DeviceStateAutoRotateSettingManagerImplTest { expectedPairs[DEVICE_STATE_ROTATION_KEY_HALF_FOLDED] = DEVICE_STATE_ROTATION_LOCK_LOCKED expectedPairs[DEVICE_STATE_ROTATION_KEY_REAR_DISPLAY] = DEVICE_STATE_ROTATION_LOCK_LOCKED DEVICE_STATE_ROTATION_LOCK_UNLOCKED val deviceStateAutoRotateSetting = settingManager.getRotationLockSetting() Loading Loading @@ -435,6 +435,72 @@ class DeviceStateAutoRotateSettingManagerImplTest { assertThat(persistedSetting).isEqualTo(expectedPairs) } @Test fun updateSettingMap_sendsMapsWithOneUpdatedSetting_returnsResolvedMap() { val currentSettingMap = getDefaultResolvedMap() val proposedSettingMap = getDefaultResolvedMap() proposedSettingMap[DEVICE_STATE_ROTATION_KEY_FOLDED] = DEVICE_STATE_ROTATION_LOCK_UNLOCKED val expectedSettingIntArray = convertMapToSparseIntArray(proposedSettingMap) expectedSettingIntArray.put( DEVICE_STATE_ROTATION_KEY_REAR_DISPLAY, DEVICE_STATE_ROTATION_LOCK_UNLOCKED ) val actualProposedSettingIntArray = settingManager.updateSetting( convertMapToSparseIntArray(proposedSettingMap), convertMapToSparseIntArray(currentSettingMap) ) assertIntArrayEqual(expectedSettingIntArray, actualProposedSettingIntArray) } @Test fun updateSettingMap_sendsMapsWithTwoUpdatedSettings_returnsResolvedMap() { val currentSettingMap = getDefaultResolvedMap() val proposedSettingMap = getDefaultResolvedMap() proposedSettingMap[DEVICE_STATE_ROTATION_KEY_FOLDED] = DEVICE_STATE_ROTATION_LOCK_UNLOCKED proposedSettingMap[DEVICE_STATE_ROTATION_KEY_UNFOLDED] = DEVICE_STATE_ROTATION_LOCK_LOCKED val expectedSettingIntArray = convertMapToSparseIntArray(proposedSettingMap) expectedSettingIntArray.put( DEVICE_STATE_ROTATION_KEY_REAR_DISPLAY, DEVICE_STATE_ROTATION_LOCK_UNLOCKED ) expectedSettingIntArray.put( DEVICE_STATE_ROTATION_KEY_HALF_FOLDED, DEVICE_STATE_ROTATION_LOCK_LOCKED ) val actualProposedSettingIntArray = settingManager.updateSetting( convertMapToSparseIntArray(proposedSettingMap), convertMapToSparseIntArray(currentSettingMap) ) assertIntArrayEqual(expectedSettingIntArray, actualProposedSettingIntArray) } @Test fun updateSettingMap_settingValueForIgnoredChanged_returnsResolvedMap() { val currentSettingMap = getDefaultResolvedMap() val proposedSettingMap = getDefaultResolvedMap() proposedSettingMap[DEVICE_STATE_ROTATION_KEY_HALF_FOLDED] = DEVICE_STATE_ROTATION_LOCK_LOCKED val expectedSettingIntArray = convertMapToSparseIntArray(proposedSettingMap) expectedSettingIntArray.put( DEVICE_STATE_ROTATION_KEY_UNFOLDED, DEVICE_STATE_ROTATION_LOCK_LOCKED ) val actualProposedSettingIntArray = settingManager.updateSetting( convertMapToSparseIntArray(proposedSettingMap), convertMapToSparseIntArray(currentSettingMap) ) assertIntArrayEqual(expectedSettingIntArray, actualProposedSettingIntArray) } @Test fun updateSettingMap_currentSettingMissingValueForFallbackPosture_throwsIllegalStateException() { val currentSettingMap = getDefaultResolvedMap() Loading Loading @@ -577,7 +643,7 @@ class DeviceStateAutoRotateSettingManagerImplTest { defaultSettingMap[DEVICE_STATE_ROTATION_KEY_HALF_FOLDED] = DEVICE_STATE_ROTATION_LOCK_UNLOCKED defaultSettingMap[DEVICE_STATE_ROTATION_KEY_REAR_DISPLAY] = DEVICE_STATE_ROTATION_LOCK_UNLOCKED DEVICE_STATE_ROTATION_LOCK_LOCKED return defaultSettingMap } Loading Loading @@ -643,6 +709,19 @@ class DeviceStateAutoRotateSettingManagerImplTest { ).thenReturn(DEVICE_STATE_REAR_DISPLAY) } private fun assertIntArrayEqual( expectedIntArray: SparseIntArray, actualIntArray: SparseIntArray ) { assertThat(expectedIntArray.size()).isEqualTo(actualIntArray.size()) for (i in 0 until expectedIntArray.size()) { val expectedKey = expectedIntArray.keyAt(i) val expectedValue = expectedIntArray.valueAt(i) assertThat(actualIntArray.indexOfKey(expectedKey)).isGreaterThan(-1) assertThat(actualIntArray[expectedKey]).isEqualTo(expectedValue) } } private companion object { const val DEVICE_STATE_FOLDED = 0 const val DEVICE_STATE_HALF_FOLDED = 1 Loading @@ -654,7 +733,7 @@ class DeviceStateAutoRotateSettingManagerImplTest { const val FOLDED_LOCKED_OPEN_UNLOCKED_SETTING_UNRESOLVED: String = "0:1:1:0:2:2:3:0" const val FOLDED_LOCKED_OPEN_LOCKED_SETTING_UNRESOLVED: String = "0:1:1:0:2:1:3:0" const val FOLDED_UNLOCKED_OPEN_LOCKED_SETTING_UNRESOLVED: String = "0:2:1:0:2:1:3:0" const val FOLDED_UNLOCKED_OPEN_UNLOCKED_SETTING_RESOLVED: String = "0:1:1:2:2:2:3:0" const val FOLDED_UNLOCKED_OPEN_UNLOCKED_SETTING_RESOLVED: String = "0:2:1:2:2:2:3:2" const val INVALID_AUTO_ROTATE_VALUE_FOR_FOLDED_SETTING: String = "0:4:1:0:2:2:3:0" const val MISSING_FOLDED_KEY_AND_VALUE_SETTING: String = "1:0:2:2:3:0" const val MISSING_VALUE_FOR_FOLDED_SETTING: String = "0:1:0:2:2:3:0" Loading
services/core/java/com/android/server/wm/DeviceStateAutoRotateSettingController.java +5 −3 Original line number Diff line number Diff line Loading @@ -331,7 +331,7 @@ public class DeviceStateAutoRotateSettingController { } if (!equals(mDeviceStateAutoRotateSetting, persistedDeviceStateAutoRotateSetting)) { mDeviceStateAutoRotateSettingManager.updateSetting( mDeviceStateAutoRotateSetting = mDeviceStateAutoRotateSettingManager.updateSetting( mDeviceStateAutoRotateSetting.clone(), persistedDeviceStateAutoRotateSetting == null ? getDefaultDeviceStateAutoRotateSetting() Loading Loading @@ -437,7 +437,8 @@ public class DeviceStateAutoRotateSettingController { * setting(DEVICE_STATE_ROTATION_LOCK) for a specific device posture. */ static final class UpdateDeviceStateAutoRotateSetting extends Event { @DeviceStateRotationLockKey final int mDevicePosture; @DeviceStateRotationLockKey final int mDevicePosture; final boolean mAutoRotate; /** Loading @@ -455,7 +456,8 @@ public class DeviceStateAutoRotateSettingController { * Event sent when the device posture changes. */ static final class UpdateDevicePosture extends Event { @DeviceStateRotationLockKey final int mDevicePosture; @DeviceStateRotationLockKey final int mDevicePosture; /** * @param devicePosture New device posture. Loading