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

Commit 8edbc941 authored by Brint E. Kriebel's avatar Brint E. Kriebel Committed by Zhao Wei Liew
Browse files

development: Add setting for updating recovery

When enabled, the recovery of the device will be updated with the
version of the installed system.

This squashes the following commits from cm-13.0:
c5a41263 development: Add setting for updating recovery
4a78446c DevelopmentSettings: Add an opt-out for recovery updater

Change-Id: I519905341b9cba9c2ab09f5d9c6e88f4025a73a7
parent 969dd16e
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -442,4 +442,10 @@
    <!-- Launch music player when headset is connected -->
    <string name="headset_connect_player_title">Launch music player</string>
    <string name="headset_connect_player_summary">Launch the default music player when a headset is connected</string>

    <!-- Update recovery -->
    <string name="update_recovery_title">Update recovery</string>
    <string name="update_recovery_summary">Update the built-in recovery with system updates</string>
    <string name="update_recovery_on_warning">NOTICE: When this feature is enabled, your installed recovery will be replaced by one included with the current version of the running OS.\n\nYour recovery will be updated along with upgrades to your system, helping to ensure compatibility with future versions.\n\nWould you like to enable this feature?</string>
    <string name="update_recovery_off_warning">WARNING: When this feature is disabled, your installed recovery will not be updated with OS upgrades.\n\nFuture OS updates may not install with outdated or custom recovery versions.\n\nDo you really want to disable this feature?</string>
</resources>
+3 −0
Original line number Diff line number Diff line
@@ -100,4 +100,7 @@
         3 = right side
    -->
    <integer name="config_fingerprintSensorLocation">0</integer>

    <!-- Does the device allow updating the recovery. -->
    <bool name="config_enableRecoveryUpdater">true</bool>
</resources>
+5 −0
Original line number Diff line number Diff line
@@ -126,6 +126,11 @@
        android:title="@string/root_appops_title"
        android:summary="@string/root_appops_summary" />

    <SwitchPreference
        android:key="update_recovery"
        android:title="@string/update_recovery_title"
        android:summary="@string/update_recovery_summary" />

    <PreferenceCategory android:key="debug_debugging_category"
            android:title="@string/debug_debugging_category">

+65 −0
Original line number Diff line number Diff line
@@ -215,6 +215,8 @@ public class DevelopmentSettings extends RestrictedSettingsFragment

    private static final String ROOT_APPOPS_KEY = "root_appops";

    private static final String UPDATE_RECOVERY_PROPERTY = "persist.sys.recovery_update";

    private static final String IMMEDIATELY_DESTROY_ACTIVITIES_KEY
            = "immediately_destroy_activities";
    private static final String APP_PROCESS_LIMIT_KEY = "app_process_limit";
@@ -330,6 +332,8 @@ public class DevelopmentSettings extends RestrictedSettingsFragment

    private SwitchPreference mColorTemperaturePreference;

    private SwitchPreference mUpdateRecoveryPreference;

    private ListPreference mRootAccess;
    private Object mSelectedRootValue;
    private PreferenceScreen mDevelopmentTools;
@@ -349,6 +353,7 @@ public class DevelopmentSettings extends RestrictedSettingsFragment
    private Dialog mAdbKeysDialog;
    private boolean mUnavailable;
    private Dialog mRootDialog;
    private Dialog mUpdateRecoveryDialog;

    private boolean mLogpersistCleared;
    private Dialog mLogpersistClearDialog;
@@ -428,6 +433,7 @@ public class DevelopmentSettings extends RestrictedSettingsFragment
            disableForUser(mClearAdbKeys);
            disableForUser(mEnableTerminal);
            disableForUser(mPassword);
            disableForUser(mUpdateRecoveryPreference);
        }

        mDebugAppPref = findPreference(DEBUG_APP_KEY);
@@ -566,6 +572,16 @@ public class DevelopmentSettings extends RestrictedSettingsFragment
            mAllPrefs.add(mRootAppops);
        }

        mUpdateRecoveryPreference = findAndInitSwitchPref("update_recovery");
        if (!getResources().getBoolean(R.bool.config_enableRecoveryUpdater)) {
            removePreference(mUpdateRecoveryPreference);
            mUpdateRecoveryPreference = null;
            if (SystemProperties.getBoolean(UPDATE_RECOVERY_PROPERTY, false)) {
                SystemProperties.set(UPDATE_RECOVERY_PROPERTY, "false");
                pokeSystemProperties();
            }
        }

        mDevelopmentTools = (PreferenceScreen) findPreference(DEVELOPMENT_TOOLS);
        mAllPrefs.add(mDevelopmentTools);
    }
@@ -797,6 +813,7 @@ public class DevelopmentSettings extends RestrictedSettingsFragment
        updateBluetoothDisableAbsVolumeOptions();
        updateRootAccessOptions();
        updateAdbOverNetwork();
        updateUpdateRecoveryOptions();
    }

    private void updateAdbOverNetwork() {
@@ -2014,6 +2031,21 @@ public class DevelopmentSettings extends RestrictedSettingsFragment
                .show();
    }

    private void updateUpdateRecoveryOptions() {
        if (mUpdateRecoveryPreference == null) {
            return;
        }

        updateSwitchPreference(mUpdateRecoveryPreference,
                SystemProperties.getBoolean(UPDATE_RECOVERY_PROPERTY, false));
    }

    private void writeUpdateRecoveryOptions() {
        SystemProperties.set(UPDATE_RECOVERY_PROPERTY,
                mUpdateRecoveryPreference.isChecked() ? "true" : "false");
        pokeSystemProperties();
    }

    @Override
    public void onSwitchChanged(Switch switchView, boolean isChecked) {
        if (switchView != mSwitchBar.getSwitch()) {
@@ -2234,6 +2266,28 @@ public class DevelopmentSettings extends RestrictedSettingsFragment
            writeWebViewMultiprocessOptions();
        } else if (SHORTCUT_MANAGER_RESET_KEY.equals(preference.getKey())) {
            resetShortcutManagerThrottling();
        } else if (preference == mUpdateRecoveryPreference) {
            if (mSwitchBar.isChecked()) {
                if (mUpdateRecoveryDialog != null) {
                    dismissDialogs();
                }
                if (mUpdateRecoveryPreference.isChecked()) {
                    mUpdateRecoveryDialog = new AlertDialog.Builder(getActivity()).setMessage(
                            getResources().getString(R.string.update_recovery_on_warning))
                            .setTitle(R.string.update_recovery_title)
                            .setPositiveButton(android.R.string.yes, this)
                            .setNegativeButton(android.R.string.no, this)
                            .show();
                } else {
                    mUpdateRecoveryDialog = new AlertDialog.Builder(getActivity()).setMessage(
                            getResources().getString(R.string.update_recovery_off_warning))
                            .setTitle(R.string.update_recovery_title)
                            .setPositiveButton(android.R.string.yes, this)
                            .setNegativeButton(android.R.string.no, this)
                            .show();
                }
                mUpdateRecoveryDialog.setOnDismissListener(this);
            }
        } else {
            return super.onPreferenceTreeClick(preference);
        }
@@ -2363,6 +2417,10 @@ public class DevelopmentSettings extends RestrictedSettingsFragment
            mAdbTcpDialog.dismiss();
            mAdbTcpDialog = null;
        }
        if (mUpdateRecoveryDialog != null) {
            mUpdateRecoveryDialog.dismiss();
            mUpdateRecoveryDialog = null;
        }
    }

    public void onClick(DialogInterface dialog, int which) {
@@ -2424,6 +2482,10 @@ public class DevelopmentSettings extends RestrictedSettingsFragment
                CMSettings.Secure.putInt(getActivity().getContentResolver(),
                        CMSettings.Secure.ADB_PORT, 5555);
            }
        } else if (dialog == mUpdateRecoveryDialog) {
            if (which == DialogInterface.BUTTON_POSITIVE) {
                writeUpdateRecoveryOptions();
            }
        }
    }

@@ -2447,6 +2509,9 @@ public class DevelopmentSettings extends RestrictedSettingsFragment
        } else if (dialog == mAdbTcpDialog) {
            updateAdbOverNetwork();
            mAdbTcpDialog = null;
        } else if (dialog == mUpdateRecoveryDialog) {
            updateUpdateRecoveryOptions();
            mUpdateRecoveryDialog = null;
        }
    }