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

Commit a0a6de5e authored by Roman Birg's avatar Roman Birg
Browse files

Settings: fix button back light restore logic



Only persist backlight data if it's modified by the user, otherwise we
can just restore the default framework value when enabling.

Always restore a backlight value setting, either the framework default,
or user saved value.

Change-Id: I2d6e95a48bc4ac4dbe6d639d87dc93ec1799c290
Signed-off-by: default avatarRoman Birg <roman@cyngn.com>
parent 010a5395
Loading
Loading
Loading
Loading
+13 −14
Original line number Diff line number Diff line
@@ -613,25 +613,14 @@ public class ButtonSettings extends SettingsPreferenceFragment implements
        cmHardwareManager.set(CmHardwareManager.FEATURE_KEY_DISABLE, enabled);

        /* Save/restore button timeouts to disable them in softkey mode */
        Editor editor = prefs.edit();

        if (enabled) {
            int currentBrightness = Settings.Secure.getInt(context.getContentResolver(),
                    Settings.Secure.BUTTON_BRIGHTNESS, defaultBrightness);
            if (!prefs.contains("pre_navbar_button_backlight")) {
                editor.putInt("pre_navbar_button_backlight", currentBrightness);
            }
            Settings.Secure.putInt(context.getContentResolver(),
                    Settings.Secure.BUTTON_BRIGHTNESS, 0);
        } else {
            int oldBright = prefs.getInt("pre_navbar_button_backlight", -1);
            if (oldBright != -1) {
            int oldBright = prefs.getInt("pre_navbar_button_backlight", defaultBrightness);
            Settings.Secure.putInt(context.getContentResolver(),
                    Settings.Secure.BUTTON_BRIGHTNESS, oldBright);
                editor.remove("pre_navbar_button_backlight");
            }
        }
        editor.commit();
    }

    private void updateDisableNavkeysOption() {
@@ -709,6 +698,16 @@ public class ButtonSettings extends SettingsPreferenceFragment implements
        } else if (preference == mDisableNavigationKeys) {
            mDisableNavigationKeys.setEnabled(false);
            mNavigationPreferencesCat.setEnabled(false);

            if (mDisableNavigationKeys.isChecked()) {
                // enabling virtual nav keys, back it up lights setting
                final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(
                        getActivity());
                int currentBrightness = Settings.Secure.getInt(getActivity().getContentResolver(),
                        Settings.Secure.BUTTON_BRIGHTNESS, -1);
                prefs.edit().putInt("pre_navbar_button_backlight", currentBrightness).apply();
            }

            writeDisableNavkeysOption(getActivity(), mDisableNavigationKeys.isChecked());
            updateDisableNavkeysOption();
            updateDisableNavkeysCategories(true);