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

Commit 2403204f authored by Brint E. Kriebel's avatar Brint E. Kriebel Committed by Steve Kondik
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.

Change-Id: I519905341b9cba9c2ab09f5d9c6e88f4025a73a7
parent dc07bc85
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -279,6 +279,12 @@
    <!-- CM Updater -->
    <string name="cmupdate_settings_title">CyanogenMod updates</string>

    <!-- Settings switch for updating Cyanogen recovery -->
    <string name="update_recovery_title">Update Cyanogen recovery</string>
    <string name="update_recovery_summary">Update 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>

    <!-- About phone screen, CyanogenMod version -->
    <string name="mod_version">CyanogenMod version</string>
    <string name="mod_version_default">Unknown</string>
+5 −0
Original line number Diff line number Diff line
@@ -88,6 +88,11 @@
        android:entries="@array/root_access_entries"
        android:entryValues="@array/root_access_values" />

    <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">

+60 −0
Original line number Diff line number Diff line
@@ -114,6 +114,7 @@ public class DevelopmentSettings extends SettingsPreferenceFragment
    private static final String BUGREPORT = "bugreport";
    private static final String BUGREPORT_IN_POWER_KEY = "bugreport_in_power";
    private static final String OPENGL_TRACES_PROPERTY = "debug.egl.trace";
    private static final String UPDATE_RECOVERY_PROPERTY = "persist.sys.recovery_update";

    private static final String DEBUG_APP_KEY = "debug_app";
    private static final String WAIT_FOR_DEBUGGER_KEY = "wait_for_debugger";
@@ -151,6 +152,7 @@ public class DevelopmentSettings extends SettingsPreferenceFragment
    private static final String SELECT_LOGD_SIZE_KEY = "select_logd_size";
    private static final String SELECT_LOGD_SIZE_PROPERTY = "persist.logd.size";
    private static final String SELECT_LOGD_DEFAULT_SIZE_PROPERTY = "ro.logd.size";
    private static final String UPDATE_RECOVERY_KEY = "update_recovery";

    private static final String OPENGL_TRACES_KEY = "enable_opengl_traces";

@@ -263,6 +265,8 @@ public class DevelopmentSettings extends SettingsPreferenceFragment

    private SwitchPreference mAdvancedReboot;

    private SwitchPreference mUpdateRecovery;

    private SwitchPreference mDevelopmentShortcut;

    private final ArrayList<Preference> mAllPrefs = new ArrayList<Preference>();
@@ -279,6 +283,7 @@ public class DevelopmentSettings extends SettingsPreferenceFragment
    private Dialog mAdbKeysDialog;
    private boolean mUnavailable;
    private Dialog mRootDialog;
    private Dialog mUpdateRecoveryDialog;

    @Override
    public void onCreate(Bundle icicle) {
@@ -338,6 +343,7 @@ public class DevelopmentSettings extends SettingsPreferenceFragment
        mPassword = (PreferenceScreen) findPreference(LOCAL_BACKUP_PASSWORD);
        mAllPrefs.add(mPassword);
        mAdvancedReboot = findAndInitSwitchPref(ADVANCED_REBOOT_KEY);
        mUpdateRecovery = findAndInitSwitchPref(UPDATE_RECOVERY_KEY);
        mDevelopmentShortcut = findAndInitSwitchPref(DEVELOPMENT_SHORTCUT_KEY);


@@ -347,6 +353,7 @@ public class DevelopmentSettings extends SettingsPreferenceFragment
            disableForUser(mEnableTerminal);
            disableForUser(mPassword);
            disableForUser(mAdvancedReboot);
            disableForUser(mUpdateRecovery);
            disableForUser(mDevelopmentShortcut);
            disableForUser(mQuickBoot);
        }
@@ -631,6 +638,7 @@ public class DevelopmentSettings extends SettingsPreferenceFragment
        updateRootAccessOptions();
        updateAdvancedRebootOptions();
        updateDevelopmentShortcutOptions();
        updateUpdateRecoveryOptions();
    }

    private void writeAdvancedRebootOptions() {
@@ -703,6 +711,7 @@ public class DevelopmentSettings extends SettingsPreferenceFragment
        resetAdbNotifyOptions();
        resetVerifyAppsOverUsbOptions();
        resetDevelopmentShortcutOptions();
        resetUpdateRecoveryOptions();
        writeAnimationScaleOption(0, mWindowAnimationScale, null);
        writeAnimationScaleOption(1, mTransitionAnimationScale, null);
        writeAnimationScaleOption(2, mAnimatorDurationScale, null);
@@ -1503,6 +1512,24 @@ public class DevelopmentSettings extends SettingsPreferenceFragment
                .show();
    }

    private void updateUpdateRecoveryOptions() {
        updateSwitch(mUpdateRecovery, SystemProperties.getBoolean(UPDATE_RECOVERY_PROPERTY,
                false));
    }

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

    private void resetUpdateRecoveryOptions() {
        // User builds should update recovery by default
        if ("user".equals(Build.TYPE)) {
            SystemProperties.set(UPDATE_RECOVERY_PROPERTY, "true");
        }
    }

    @Override
    public void onSwitchChanged(Switch switchView, boolean isChecked) {
        if (switchView != mSwitchBar.getSwitch()) {
@@ -1699,6 +1726,28 @@ public class DevelopmentSettings extends SettingsPreferenceFragment
            writeDevelopmentShortcutOptions();
        } else if (preference == mKillAppLongpressBack) {
            writeKillAppLongpressBackOptions();
        } else if (preference == mUpdateRecovery) {
            if (mSwitchBar.isChecked()) {
                if (mUpdateRecoveryDialog != null) {
                    dismissDialogs();
                }
                if (mUpdateRecovery.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(preferenceScreen, preference);
        }
@@ -1796,6 +1845,10 @@ public class DevelopmentSettings extends SettingsPreferenceFragment
            mRootDialog.dismiss();
            mRootDialog = null;
        }
        if (mUpdateRecoveryDialog != null) {
            mUpdateRecoveryDialog.dismiss();
            mUpdateRecoveryDialog = null;
        }
    }

    public void onClick(DialogInterface dialog, int which) {
@@ -1845,6 +1898,10 @@ public class DevelopmentSettings extends SettingsPreferenceFragment
                // Reset the option
                writeRootAccessOptions("0");
            }
        } else if (dialog == mUpdateRecoveryDialog) {
            if (which == DialogInterface.BUTTON_POSITIVE) {
                writeUpdateRecoveryOptions();
            }
        }
    }

@@ -1863,6 +1920,9 @@ public class DevelopmentSettings extends SettingsPreferenceFragment
                mSwitchBar.setChecked(false);
            }
            mEnableDialog = null;
        } else if (dialog == mUpdateRecoveryDialog) {
            updateUpdateRecoveryOptions();
            mUpdateRecoveryDialog = null;
        }
    }