From d93e0e1bbd858672ad543aa89787209c43da237c Mon Sep 17 00:00:00 2001 From: Alessandro Astone Date: Fri, 13 Nov 2020 01:03:12 +0100 Subject: [PATCH] SetupWizard: Add activity to toggle recovery updates Change-Id: I8157d812c1b616b10dd4204d12cc8fb21d4eee50 --- AndroidManifest.xml | 12 +++ res/drawable/ic_system_update.xml | 25 +++++ res/layout/update_recovery_page.xml | 101 ++++++++++++++++++ res/raw/lineage_wizard_script.xml | 4 + res/raw/wizard_script.xml | 5 +- res/values/strings.xml | 6 ++ .../setupwizard/UpdateRecoveryActivity.java | 91 ++++++++++++++++ .../setupwizard/util/SetupWizardUtils.java | 23 ++++ 8 files changed, 266 insertions(+), 1 deletion(-) create mode 100644 res/drawable/ic_system_update.xml create mode 100644 res/layout/update_recovery_page.xml create mode 100644 src/org/lineageos/setupwizard/UpdateRecoveryActivity.java diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 491ea8d6..43d0881d 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -223,6 +223,18 @@ + + + + + + + + + + + diff --git a/res/layout/update_recovery_page.xml b/res/layout/update_recovery_page.xml new file mode 100644 index 00000000..59e3c629 --- /dev/null +++ b/res/layout/update_recovery_page.xml @@ -0,0 +1,101 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/res/raw/lineage_wizard_script.xml b/res/raw/lineage_wizard_script.xml index 2a0fbf19..d502649b 100644 --- a/res/raw/lineage_wizard_script.xml +++ b/res/raw/lineage_wizard_script.xml @@ -54,6 +54,10 @@ + + + + diff --git a/res/raw/wizard_script.xml b/res/raw/wizard_script.xml index f82ab401..8ff58f6e 100644 --- a/res/raw/wizard_script.xml +++ b/res/raw/wizard_script.xml @@ -98,7 +98,10 @@ - + + + + diff --git a/res/values/strings.xml b/res/values/strings.xml index cacc01d6..0b1831cf 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -106,4 +106,10 @@ If you have a backup from your last LineageOS tablet, you can restore it here. If you have a backup from your last LineageOS phone, you can restore it here. Restore from backup + + + Update Lineage Recovery + Updates Lineage Recovery on first boot subsequent to every update. + Recovery will be updated as soon as you proceed to the next step. If you wish to keep it intact, disable this feature. + Update Lineage Recovery alongside the OS diff --git a/src/org/lineageos/setupwizard/UpdateRecoveryActivity.java b/src/org/lineageos/setupwizard/UpdateRecoveryActivity.java new file mode 100644 index 00000000..6474d12b --- /dev/null +++ b/src/org/lineageos/setupwizard/UpdateRecoveryActivity.java @@ -0,0 +1,91 @@ +/* + * Copyright (C) 2019-2020 The Calyx Institute + * + * 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 + */ + +package org.lineageos.setupwizard; + +import android.app.Activity; +import android.content.Intent; +import android.os.Bundle; +import android.os.SystemProperties; +import android.util.Log; +import android.view.View; +import android.widget.CheckBox; + +import com.google.android.setupcompat.util.WizardManagerHelper; +import org.lineageos.setupwizard.util.SetupWizardUtils; + + +public class UpdateRecoveryActivity extends BaseSetupWizardActivity { + + private static final String UPDATE_RECOVERY_PROP = "persist.vendor.recovery_update"; + + private CheckBox mRecoveryUpdateCheckbox; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + if (!SetupWizardUtils.hasRecoveryUpdater(this)) { + Log.v(TAG, "No recovery updater, skipping UpdateRecoveryActivity"); + + Intent intent = WizardManagerHelper.getNextIntent(getIntent(), Activity.RESULT_OK); + nextAction(NEXT_REQUEST, intent); + finish(); + return; + } + + setNextText(R.string.next); + mRecoveryUpdateCheckbox = findViewById(R.id.update_recovery_checkbox); + + View cbView = findViewById(R.id.update_recovery_checkbox_view); + cbView.setOnClickListener(v -> { + mRecoveryUpdateCheckbox.setChecked(!mRecoveryUpdateCheckbox.isChecked()); + }); + } + + @Override + public void onResume() { + super.onResume(); + + // Default the checkbox to true, the effect will be reflected when going next + mRecoveryUpdateCheckbox.setChecked( + SystemProperties.getBoolean(UPDATE_RECOVERY_PROP, true)); + } + + @Override + protected void onNextPressed() { + SystemProperties.set(UPDATE_RECOVERY_PROP, + String.valueOf(mRecoveryUpdateCheckbox.isChecked())); + + Intent intent = WizardManagerHelper.getNextIntent(getIntent(), Activity.RESULT_OK); + nextAction(NEXT_REQUEST, intent); + } + + @Override + protected int getLayoutResId() { + return R.layout.update_recovery_page; + } + + @Override + protected int getTitleResId() { + return R.string.update_recovery_title; + } + + @Override + protected int getIconResId() { + return R.drawable.ic_system_update; + } +} diff --git a/src/org/lineageos/setupwizard/util/SetupWizardUtils.java b/src/org/lineageos/setupwizard/util/SetupWizardUtils.java index e9a59783..dd8af26c 100644 --- a/src/org/lineageos/setupwizard/util/SetupWizardUtils.java +++ b/src/org/lineageos/setupwizard/util/SetupWizardUtils.java @@ -37,6 +37,7 @@ import android.content.ComponentName; import android.content.ContentResolver; import android.content.Context; import android.content.Intent; +import android.content.res.Resources; import android.content.SharedPreferences; import android.content.pm.ComponentInfo; import android.content.pm.PackageInfo; @@ -60,11 +61,13 @@ import org.lineageos.setupwizard.BiometricActivity; import org.lineageos.setupwizard.MobileDataActivity; import org.lineageos.setupwizard.SetupWizardApp; import org.lineageos.setupwizard.SimMissingActivity; +import org.lineageos.setupwizard.UpdateRecoveryActivity; import org.lineageos.setupwizard.WifiSetupActivity; import org.lineageos.setupwizard.wizardmanager.WizardManager; import org.lineageos.internal.util.PackageManagerUtils; +import java.io.File; import java.util.ArrayList; import java.util.List; @@ -75,7 +78,10 @@ public class SetupWizardUtils { private static final String GMS_PACKAGE = "com.google.android.gms"; private static final String GMS_SUW_PACKAGE = "com.google.android.setupwizard"; private static final String GMS_TV_SUW_PACKAGE = "com.google.android.tungsten.setupwraith"; + private static final String UPDATER_PACKAGE = "org.lineageos.updater"; + private static final String UPDATE_RECOVERY_EXEC = "/vendor/bin/install-recovery.sh"; + private static final String CONFIG_HIDE_RECOVERY_UPDATE = "config_hideRecoveryUpdate"; private static final String PROP_BUILD_DATE = "ro.build.date.utc"; private SetupWizardUtils(){} @@ -118,6 +124,23 @@ public class SetupWizardUtils { return packageManager.hasSystemFeature(PackageManager.FEATURE_TELEPHONY); } + public static boolean hasRecoveryUpdater(Context context) { + boolean fileExists = new File(UPDATE_RECOVERY_EXEC).exists(); + if (!fileExists) { + return false; + } + + boolean featureHidden = false; + try { + PackageManager pm = context.getPackageManager(); + Resources updaterResources = pm.getResourcesForApplication(UPDATER_PACKAGE); + int res = updaterResources.getIdentifier( + CONFIG_HIDE_RECOVERY_UPDATE, "bool", UPDATER_PACKAGE); + featureHidden = updaterResources.getBoolean(res); + } catch (PackageManager.NameNotFoundException | Resources.NotFoundException ignored) { } + return !featureHidden; + } + public static boolean isMultiSimDevice(Context context) { TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);