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

@@ -223,6 +223,18 @@
</intent-filter> </intent-filter>
</activity> </activity>
<activity android:name=".UpdateRecoveryActivity"
android:label="@string/activity_label_empty"
android:excludeFromRecents="true"
android:configChanges="mcc|mnc"
android:immersive="true"
android:windowSoftInputMode="stateAlwaysHidden">
<intent-filter>
<action android:name="org.lineageos.setupwizard.LINEAGE_RECOVERY_UPDATE"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
<activity android:name=".LineageSettingsActivity" <activity android:name=".LineageSettingsActivity"
android:label="@string/activity_label_empty" android:label="@string/activity_label_empty"
android:excludeFromRecents="true" android:excludeFromRecents="true"

View File

@@ -0,0 +1,25 @@
<?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.
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="@color/black"
android:pathData="M17,1.01L7,1c-1.1,0 -2,0.9 -2,2v18c0,1.1 0.9,2 2,2h10c1.1,0 2,-0.9 2,-2L19,3c0,-1.1 -0.9,-1.99 -2,-1.99zM17,19L7,19L7,5h10v14zM16,13h-3L13,8h-2v5L8,13l4,4 4,-4z"/>
</vector>

View File

@@ -0,0 +1,101 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2015 The CyanogenMod Project
Copyright (C) 2017 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.
-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/primary">
<include layout="@layout/header_condensed" />
<FrameLayout android:id="@+id/page"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<ScrollView android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
style="@style/PageContent">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="16sp"
android:layout_marginBottom="@dimen/summary_margin_bottom"
android:paddingLeft="@dimen/content_margin_left"
android:paddingRight="@dimen/content_margin_right"
style="@style/PageSummaryText"
android:text="@string/update_recovery_description" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="16sp"
android:layout_marginBottom="@dimen/summary_margin_bottom"
android:paddingLeft="@dimen/content_margin_left"
android:paddingRight="@dimen/content_margin_right"
style="@style/PageSummaryText"
android:text="@string/update_recovery_warning" />
<LinearLayout
android:id="@+id/update_recovery_checkbox_view"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="@dimen/location_margin_left"
android:paddingRight="@dimen/content_margin_right"
android:background="?android:attr/selectableItemBackground"
android:clickable="true">
<CheckBox
android:id="@+id/update_recovery_checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:layout_marginTop="5dp"
android:duplicateParentState="true"
android:clickable="false" />
<TextView
android:layout_width="0px"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textSize="15sp"
android:textStyle="bold"
android:lineSpacingExtra="@dimen/setup_line_spacing"
android:gravity="top"
android:layout_marginLeft="@dimen/location_text_margin_left"
android:layout_marginRight="@dimen/location_text_margin_right"
android:paddingBottom="@dimen/content_margin_bottom"
android:text="@string/update_recovery_setting"
android:maxLines="5" />
</LinearLayout>
</LinearLayout>
</ScrollView>
</FrameLayout>
<com.google.android.setupdesign.view.NavigationBar
android:id="@+id/navigation_bar"
style="@style/SudNavBarTheme"
android:layout_width="match_parent"
android:layout_height="@dimen/sud_navbar_height" />
</LinearLayout>

View File

@@ -54,6 +54,10 @@
</WizardAction> </WizardAction>
<WizardAction wizard:uri="intent:#Intent;action=org.lineageos.setupwizard.LINEAGE_LOCATION_SETTINGS;end" id="location_settings"> <WizardAction wizard:uri="intent:#Intent;action=org.lineageos.setupwizard.LINEAGE_LOCATION_SETTINGS;end" id="location_settings">
<result wizard:action="recovery_update" />
</WizardAction>
<WizardAction wizard:uri="intent:#Intent;action=org.lineageos.setupwizard.LINEAGE_RECOVERY_UPDATE;end" id="recovery_update">
<result wizard:action="lineage_settings" /> <result wizard:action="lineage_settings" />
</WizardAction> </WizardAction>

View File

@@ -98,7 +98,10 @@
<result wizard:action="oem_post_setup" /> <result wizard:action="oem_post_setup" />
</WizardAction> </WizardAction>
<WizardAction wizard:script="android.resource://com.google.android.setupwizard/xml/wizard_script_qr_provision_flow" id="qr_provision_flow" /> <WizardAction wizard:script="android.resource://com.google.android.setupwizard/xml/wizard_script_qr_provision_flow" id="qr_provision_flow" />
<WizardAction wizard:uri="intent:#Intent;action=org.lineageos.setupwizard.LINEAGE_SETTINGS;end" id="oem_post_setup"> <WizardAction wizard:uri="intent:#Intent;action=org.lineageos.setupwizard.LINEAGE_RECOVERY_UPDATE;end" id="oem_post_setup">
<result wizard:action="lineage_settings" />
</WizardAction>
<WizardAction wizard:uri="intent:#Intent;action=org.lineageos.setupwizard.LINEAGE_SETTINGS;end" id="lineage_settings">
<result wizard:action="restore" /> <result wizard:action="restore" />
</WizardAction> </WizardAction>
<WizardAction wizard:uri="intent:#Intent;action=org.lineageos.setupwizard.LINEAGE_RESTORE_BACKUP;end" id="restore"> <WizardAction wizard:uri="intent:#Intent;action=org.lineageos.setupwizard.LINEAGE_RESTORE_BACKUP;end" id="restore">

View File

@@ -106,4 +106,10 @@
<string name="intro_restore_subtitle" product="tablet">If you have a backup from your last LineageOS tablet, you can restore it here.</string> <string name="intro_restore_subtitle" product="tablet">If you have a backup from your last LineageOS tablet, you can restore it here.</string>
<string name="intro_restore_subtitle" product="default">If you have a backup from your last LineageOS phone, you can restore it here.</string> <string name="intro_restore_subtitle" product="default">If you have a backup from your last LineageOS phone, you can restore it here.</string>
<string name="intro_restore_button">Restore from backup</string> <string name="intro_restore_button">Restore from backup</string>
<!-- Update Recovery -->
<string name="update_recovery_title">Update Lineage Recovery</string>
<string name="update_recovery_description">Updates Lineage Recovery on first boot subsequent to every update.</string>
<string name="update_recovery_warning">Recovery will be updated as soon as you proceed to the next step. If you wish to keep it intact, disable this feature.</string>
<string name="update_recovery_setting">Update Lineage Recovery alongside the OS</string>
</resources> </resources>

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.ContentResolver;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.res.Resources;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.pm.ComponentInfo; import android.content.pm.ComponentInfo;
import android.content.pm.PackageInfo; import android.content.pm.PackageInfo;
@@ -60,11 +61,13 @@ import org.lineageos.setupwizard.BiometricActivity;
import org.lineageos.setupwizard.MobileDataActivity; import org.lineageos.setupwizard.MobileDataActivity;
import org.lineageos.setupwizard.SetupWizardApp; import org.lineageos.setupwizard.SetupWizardApp;
import org.lineageos.setupwizard.SimMissingActivity; import org.lineageos.setupwizard.SimMissingActivity;
import org.lineageos.setupwizard.UpdateRecoveryActivity;
import org.lineageos.setupwizard.WifiSetupActivity; import org.lineageos.setupwizard.WifiSetupActivity;
import org.lineageos.setupwizard.wizardmanager.WizardManager; import org.lineageos.setupwizard.wizardmanager.WizardManager;
import org.lineageos.internal.util.PackageManagerUtils; import org.lineageos.internal.util.PackageManagerUtils;
import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; 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_PACKAGE = "com.google.android.gms";
private static final String GMS_SUW_PACKAGE = "com.google.android.setupwizard"; 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 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 static final String PROP_BUILD_DATE = "ro.build.date.utc";
private SetupWizardUtils(){} private SetupWizardUtils(){}
@@ -118,6 +124,23 @@ public class SetupWizardUtils {
return packageManager.hasSystemFeature(PackageManager.FEATURE_TELEPHONY); 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) { public static boolean isMultiSimDevice(Context context) {
TelephonyManager tm = TelephonyManager tm =
(TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);