Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 435f835d authored by Christian Göllner's avatar Christian Göllner Committed by Christian Göllner
Browse files

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
Merged-In: I3f28027d5e24796ceb01fc1eb164aac8814a1753
parent d0b406dd
Loading
Loading
Loading
Loading
+10 −9
Original line number Diff line number Diff line
@@ -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();
    }

+15 −0
Original line number Diff line number Diff line
@@ -113,6 +113,21 @@ public class DeviceStateRotationLockSettingsManagerTest {
        assertThat(mNumSettingsChanges).isEqualTo(3);
    }

    @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(