SetupWizard: Add activity to toggle recovery updates

Change-Id: I8157d812c1b616b10dd4204d12cc8fb21d4eee50
This commit is contained in:
Alessandro Astone
2020-11-13 01:03:12 +01:00
committed by Bruno Martins
parent 7423d88cd0
commit d93e0e1bbd
8 changed files with 266 additions and 1 deletions

View File

@@ -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;
}
}

View File

@@ -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);