summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Christian Göllner <chrisgollner@google.com> 2023-04-26 11:31:07 +0200
committer Christian Göllner <chrisgollner@google.com> 2023-04-26 14:12:06 +0000
commit470c64f7ecedb8fe2164325d2113c6b8fb50f5fb (patch)
treed83dc1e347fa5dafcda22098b4dc08d138c752f8
parent3a2bda18c40dd4701cc0f0487930af9053a41419 (diff)
Fixes foldable autorotation setting being out of sync in QS and Settings
Both QS (SystemUI) and Settings, were using the same class to update foldable auto-rotation settings. Since both are in different processes, they have different internal memory state. There was a bug where the internal state for the persisted setting was only changed in the process that changed the setting. When then trying to change the setting in the other process, it didn't work as it thought that the setting was the same as before. Test: DeviceStateRotationLockSettingsManagerTest.java Test: Manually - Change settings in both QS and Settings and read logs. Fixes: 279603743 Change-Id: I3f28027d5e24796ceb01fc1eb164aac8814a1753
-rw-r--r--packages/SettingsLib/DeviceStateRotationLock/src/com.android.settingslib.devicestate/DeviceStateRotationLockSettingsManager.java19
-rw-r--r--packages/SettingsLib/tests/integ/src/com/android/settingslib/devicestate/DeviceStateRotationLockSettingsManagerTest.java15
2 files changed, 25 insertions, 9 deletions
diff --git a/packages/SettingsLib/DeviceStateRotationLock/src/com.android.settingslib.devicestate/DeviceStateRotationLockSettingsManager.java b/packages/SettingsLib/DeviceStateRotationLock/src/com.android.settingslib.devicestate/DeviceStateRotationLockSettingsManager.java
index 76e1df1459e3..ea4ac2c928ce 100644
--- a/packages/SettingsLib/DeviceStateRotationLock/src/com.android.settingslib.devicestate/DeviceStateRotationLockSettingsManager.java
+++ b/packages/SettingsLib/DeviceStateRotationLock/src/com.android.settingslib.devicestate/DeviceStateRotationLockSettingsManager.java
@@ -62,7 +62,6 @@ public final class DeviceStateRotationLockSettingsManager {
private SparseIntArray mPostureRotationLockSettings;
private SparseIntArray mPostureDefaultRotationLockSettings;
private SparseIntArray mPostureRotationLockFallbackSettings;
- private String mLastSettingValue;
private List<SettableDeviceState> mSettableDeviceStates;
@VisibleForTesting
@@ -209,10 +208,7 @@ public final class DeviceStateRotationLockSettingsManager {
}
private void initializeInMemoryMap() {
- String serializedSetting =
- mSecureSettings.getStringForUser(
- Settings.Secure.DEVICE_STATE_ROTATION_LOCK,
- UserHandle.USER_CURRENT);
+ String serializedSetting = getPersistedSettingValue();
if (TextUtils.isEmpty(serializedSetting)) {
// No settings saved, we should load the defaults and persist them.
fallbackOnDefaults();
@@ -290,19 +286,25 @@ public final class DeviceStateRotationLockSettingsManager {
}
private void persistSettingIfChanged(String newSettingValue) {
+ String lastSettingValue = getPersistedSettingValue();
Log.v(TAG, "persistSettingIfChanged: "
- + "last=" + mLastSettingValue + ", "
+ + "last=" + lastSettingValue + ", "
+ "new=" + newSettingValue);
- if (TextUtils.equals(mLastSettingValue, newSettingValue)) {
+ if (TextUtils.equals(lastSettingValue, newSettingValue)) {
return;
}
- mLastSettingValue = newSettingValue;
mSecureSettings.putStringForUser(
Settings.Secure.DEVICE_STATE_ROTATION_LOCK,
/* value= */ newSettingValue,
UserHandle.USER_CURRENT);
}
+ private String getPersistedSettingValue() {
+ return mSecureSettings.getStringForUser(
+ Settings.Secure.DEVICE_STATE_ROTATION_LOCK,
+ UserHandle.USER_CURRENT);
+ }
+
private void loadDefaults() {
mSettableDeviceStates = new ArrayList<>(mPostureRotationLockDefaults.length);
mPostureDefaultRotationLockSettings = new SparseIntArray(
@@ -351,7 +353,6 @@ public final class DeviceStateRotationLockSettingsManager {
pw.println("mDeviceStateRotationLockSettings: " + mPostureRotationLockSettings);
pw.println("mPostureRotationLockFallbackSettings: " + mPostureRotationLockFallbackSettings);
pw.println("mSettableDeviceStates: " + mSettableDeviceStates);
- pw.println("mLastSettingValue: " + mLastSettingValue);
pw.decreaseIndent();
}
diff --git a/packages/SettingsLib/tests/integ/src/com/android/settingslib/devicestate/DeviceStateRotationLockSettingsManagerTest.java b/packages/SettingsLib/tests/integ/src/com/android/settingslib/devicestate/DeviceStateRotationLockSettingsManagerTest.java
index fdefcde3a170..52c2a87cc961 100644
--- a/packages/SettingsLib/tests/integ/src/com/android/settingslib/devicestate/DeviceStateRotationLockSettingsManagerTest.java
+++ b/packages/SettingsLib/tests/integ/src/com/android/settingslib/devicestate/DeviceStateRotationLockSettingsManagerTest.java
@@ -114,6 +114,21 @@ public class DeviceStateRotationLockSettingsManagerTest {
}
@Test
+ public void updateSetting_twiceWithSameValue_persistedValueDifferent_persistsAgain() {
+ mManager.updateSetting(/* deviceState= */ 1, /* rotationLocked= */ true);
+ // This persists a different setting than what was set above. It simulates the persisted
+ // setting being changed from a different process.
+ persistSettings("0:1:1:2:2:2");
+ mNumSettingsChanges = 0;
+
+ // Updating again with the same value as in the first line of the test should persist the
+ // setting, as it is different to what is actually persisted.
+ mManager.updateSetting(/* deviceState= */ 1, /* rotationLocked= */ true);
+
+ assertThat(mNumSettingsChanges).isEqualTo(1);
+ }
+
+ @Test
public void getSettableDeviceStates_returnsExpectedValuesInOriginalOrder() {
when(mMockResources.getStringArray(
R.array.config_perDeviceStateRotationLockDefaults)).thenReturn(