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

Commit 96626c2f authored by Bruno Martins's avatar Bruno Martins
Browse files

Updater: Add setting for updating recovery

When enabled, the recovery of the device will be updated with the
version of the installed system. This is only applicable to devices
with a dedicated recovery partition and not A/B.

Change-Id: I4c1701b09c000b4cdb044069fa9ba857500f9cb1
parent 1f8b7d56
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -52,4 +52,12 @@
        android:layout_marginBottom="16dp"
        android:text="@string/menu_ab_perf_mode"
        android:textSize="16sp" />

    <Switch
        android:id="@+id/preferences_update_recovery"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="16dp"
        android:text="@string/menu_update_recovery"
        android:textSize="16sp" />
</LinearLayout>

res/values/config.xml

0 → 100644
+19 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
     Copyright (C) 2020 The LineageOS Project

     Licensed under the Apache License, Version 2.0 (the "License");
     you may not use this file except in compliance with the License.
     You may obtain a copy of the License at

          http://www.apache.org/licenses/LICENSE-2.0

     Unless required by applicable law or agreed to in writing, software
     distributed under the License is distributed on an "AS IS" BASIS,
     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     See the License for the specific language governing permissions and
     limitations under the License.
-->
<resources>
    <bool name="config_hideRecoveryUpdate">false</bool>
</resources>
+3 −1
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
     Copyright (C) 2017 The LineageOS Project
     Copyright (C) 2017-2020 The LineageOS Project

     Licensed under the Apache License, Version 2.0 (the "License");
     you may not use this file except in compliance with the License.
@@ -77,6 +77,8 @@
    <string name="menu_show_changelog">Show changelog</string>
    <string name="menu_changelog_url" translatable="false">https://download.lineageos.org/<xliff:g id="device_name">%1$s</xliff:g>/changes</string>
    <string name="menu_ab_perf_mode">Prioritize update process</string>
    <string name="menu_update_recovery">Update recovery</string>
    <string name="toast_forced_update_recovery">You cannot disable the update of Lineage Recovery on this device.</string>

    <string name="snack_updates_found">New updates found</string>
    <string name="snack_no_updates_found">No new updates found</string>

res/values/symbols.xml

0 → 100644
+19 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
     Copyright (C) 2020 The LineageOS Project

     Licensed under the Apache License, Version 2.0 (the "License");
     you may not use this file except in compliance with the License.
     You may obtain a copy of the License at

          http://www.apache.org/licenses/LICENSE-2.0

     Unless required by applicable law or agreed to in writing, software
     distributed under the License is distributed on an "AS IS" BASIS,
     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     See the License for the specific language governing permissions and
     limitations under the License.
-->
<resources>
    <java-symbol type="bool" name="config_hideRecoveryUpdate" />
</resources>
+39 −1
Original line number Diff line number Diff line
/*
 * Copyright (C) 2017 The LineageOS Project
 * Copyright (C) 2017-2020 The LineageOS Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
@@ -27,10 +27,12 @@ import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.IBinder;
import android.os.SystemProperties;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.LinearInterpolator;
@@ -38,6 +40,7 @@ import android.view.animation.RotateAnimation;
import android.widget.Spinner;
import android.widget.Switch;
import android.widget.TextView;
import android.widget.Toast;

import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.widget.Toolbar;
@@ -414,6 +417,7 @@ public class UpdatesActivity extends UpdatesListActivity {
        Switch autoDelete = view.findViewById(R.id.preferences_auto_delete_updates);
        Switch dataWarning = view.findViewById(R.id.preferences_mobile_data_warning);
        Switch abPerfMode = view.findViewById(R.id.preferences_ab_perf_mode);
        Switch updateRecovery = view.findViewById(R.id.preferences_update_recovery);

        if (!Utils.isABDevice()) {
            abPerfMode.setVisibility(View.GONE);
@@ -425,6 +429,33 @@ public class UpdatesActivity extends UpdatesListActivity {
        dataWarning.setChecked(prefs.getBoolean(Constants.PREF_MOBILE_DATA_WARNING, true));
        abPerfMode.setChecked(prefs.getBoolean(Constants.PREF_AB_PERF_MODE, false));

        if (getResources().getBoolean(R.bool.config_hideRecoveryUpdate)) {
            // Hide the update feature if explicitely requested.
            // Might be the case of A-only devices using prebuilt vendor images.
            updateRecovery.setVisibility(View.GONE);
        } else if (Utils.isRecoveryUpdateExecPresent()) {
            updateRecovery.setChecked(prefs.getBoolean(Constants.PREF_UPDATE_RECOVERY, false));
        } else {
            // There is no recovery updater script in the device, so the feature is considered
            // forcefully enabled, just to avoid users to be confused and complain that
            // recovery gets overwritten. That's the case of A/B and recovery-in-boot devices.
            updateRecovery.setChecked(true);
            updateRecovery.setOnTouchListener(new View.OnTouchListener() {
                private Toast forcedUpdateToast = null;

                @Override
                public boolean onTouch(View v, MotionEvent event) {
                    if (forcedUpdateToast != null) {
                        forcedUpdateToast.cancel();
                    }
                    forcedUpdateToast = Toast.makeText(getApplicationContext(),
                            getString(R.string.toast_forced_update_recovery), Toast.LENGTH_SHORT);
                    forcedUpdateToast.show();
                    return true;
                }
            });
        }

        new AlertDialog.Builder(this)
                .setTitle(R.string.menu_preferences)
                .setView(view)
@@ -438,6 +469,8 @@ public class UpdatesActivity extends UpdatesListActivity {
                                    dataWarning.isChecked())
                            .putBoolean(Constants.PREF_AB_PERF_MODE,
                                    abPerfMode.isChecked())
                            .putBoolean(Constants.PREF_UPDATE_RECOVERY,
                                    updateRecovery.isChecked())
                            .apply();

                    if (Utils.isUpdateCheckEnabled(this)) {
@@ -451,6 +484,11 @@ public class UpdatesActivity extends UpdatesListActivity {
                        boolean enableABPerfMode = abPerfMode.isChecked();
                        mUpdaterService.getUpdaterController().setPerformanceMode(enableABPerfMode);
                    }
                    if (Utils.isRecoveryUpdateExecPresent()) {
                        boolean enableRecoveryUpdate = updateRecovery.isChecked();
                        SystemProperties.set(Constants.UPDATE_RECOVERY_PROPERTY,
                                String.valueOf(enableRecoveryUpdate));
                    }
                })
                .show();
    }
Loading