Merge "Add factory reset intent to the settings app." into main
This commit is contained in:
@@ -16,6 +16,11 @@
|
|||||||
android:name="com.android.settings.USE_BIOMETRIC_PROVIDER"
|
android:name="com.android.settings.USE_BIOMETRIC_PROVIDER"
|
||||||
android:protectionLevel="signature|privileged"/>
|
android:protectionLevel="signature|privileged"/>
|
||||||
|
|
||||||
|
<!-- Permissions for acting as the factory reset preparation application. -->
|
||||||
|
<permission
|
||||||
|
android:name="com.android.settings.permissions.PREPARE_FACTORY_RESET"
|
||||||
|
android:protectionLevel="signature|privileged"/>
|
||||||
|
|
||||||
<uses-permission android:name="android.permission.REQUEST_NETWORK_SCORES" />
|
<uses-permission android:name="android.permission.REQUEST_NETWORK_SCORES" />
|
||||||
<uses-permission android:name="android.permission.WRITE_MEDIA_STORAGE" />
|
<uses-permission android:name="android.permission.WRITE_MEDIA_STORAGE" />
|
||||||
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />
|
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />
|
||||||
|
@@ -94,7 +94,6 @@ public class MainClear extends InstrumentedFragment implements OnGlobalLayoutLis
|
|||||||
static final int KEYGUARD_REQUEST = 55;
|
static final int KEYGUARD_REQUEST = 55;
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
static final int CREDENTIAL_CONFIRM_REQUEST = 56;
|
static final int CREDENTIAL_CONFIRM_REQUEST = 56;
|
||||||
|
|
||||||
private static final String KEY_SHOW_ESIM_RESET_CHECKBOX =
|
private static final String KEY_SHOW_ESIM_RESET_CHECKBOX =
|
||||||
"masterclear.allow_retain_esim_profiles_after_fdr";
|
"masterclear.allow_retain_esim_profiles_after_fdr";
|
||||||
|
|
||||||
|
@@ -17,18 +17,32 @@ package com.android.settings.system;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.content.pm.PackageInfo;
|
||||||
|
import android.content.pm.PackageManager;
|
||||||
|
import android.content.pm.ResolveInfo;
|
||||||
import android.os.UserManager;
|
import android.os.UserManager;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
import androidx.activity.result.ActivityResultLauncher;
|
||||||
|
import androidx.activity.result.contract.ActivityResultContracts;
|
||||||
import androidx.preference.Preference;
|
import androidx.preference.Preference;
|
||||||
|
|
||||||
import com.android.settings.R;
|
|
||||||
import com.android.settings.Settings;
|
import com.android.settings.Settings;
|
||||||
import com.android.settings.Utils;
|
|
||||||
import com.android.settings.core.BasePreferenceController;
|
import com.android.settings.core.BasePreferenceController;
|
||||||
|
import com.android.settings.factory_reset.Flags;
|
||||||
|
|
||||||
public class FactoryResetPreferenceController extends BasePreferenceController {
|
public class FactoryResetPreferenceController extends BasePreferenceController {
|
||||||
|
|
||||||
|
private static final String TAG = "FactoryResetPreference";
|
||||||
|
|
||||||
|
private static final String ACTION_PREPARE_FACTORY_RESET =
|
||||||
|
"com.android.settings.ACTION_PREPARE_FACTORY_RESET";
|
||||||
|
|
||||||
|
private static final String PREPARE_FACTORY_RESET_PERMISSION =
|
||||||
|
"com.android.settings.permissions.PREPARE_FACTORY_RESET";
|
||||||
|
|
||||||
private final UserManager mUm;
|
private final UserManager mUm;
|
||||||
|
private ActivityResultLauncher<Intent> mFactoryResetPreparationLauncher;
|
||||||
|
|
||||||
public FactoryResetPreferenceController(Context context, String preferenceKey) {
|
public FactoryResetPreferenceController(Context context, String preferenceKey) {
|
||||||
super(context, preferenceKey);
|
super(context, preferenceKey);
|
||||||
@@ -44,10 +58,73 @@ public class FactoryResetPreferenceController extends BasePreferenceController {
|
|||||||
@Override
|
@Override
|
||||||
public boolean handlePreferenceTreeClick(Preference preference) {
|
public boolean handlePreferenceTreeClick(Preference preference) {
|
||||||
if (mPreferenceKey.equals(preference.getKey())) {
|
if (mPreferenceKey.equals(preference.getKey())) {
|
||||||
final Intent intent = new Intent(mContext, Settings.FactoryResetActivity.class);
|
if (Flags.enableFactoryResetWizard()) {
|
||||||
mContext.startActivity(intent);
|
startFactoryResetPreparationActivity();
|
||||||
|
} else {
|
||||||
|
startFactoryResetActivity();
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void startFactoryResetPreparationActivity() {
|
||||||
|
Intent prepareFactoryResetIntent = getPrepareFactoryResetIntent();
|
||||||
|
if (prepareFactoryResetIntent != null && mFactoryResetPreparationLauncher != null) {
|
||||||
|
mFactoryResetPreparationLauncher.launch(prepareFactoryResetIntent);
|
||||||
|
} else {
|
||||||
|
startFactoryResetActivity();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// We check that the activity that can handle the factory reset preparation action is indeed
|
||||||
|
// a system app with proper permissions.
|
||||||
|
private Intent getPrepareFactoryResetIntent() {
|
||||||
|
final Intent prepareFactoryResetWizardRequest = new Intent(ACTION_PREPARE_FACTORY_RESET);
|
||||||
|
final PackageManager pm = mContext.getPackageManager();
|
||||||
|
final ResolveInfo resolution = pm.resolveActivity(prepareFactoryResetWizardRequest, 0);
|
||||||
|
if (resolution != null
|
||||||
|
&& resolution.activityInfo != null) {
|
||||||
|
String packageName = resolution.activityInfo.packageName;
|
||||||
|
PackageInfo factoryResetWizardPackageInfo;
|
||||||
|
try {
|
||||||
|
factoryResetWizardPackageInfo = pm.getPackageInfo(packageName, 0);
|
||||||
|
} catch (PackageManager.NameNotFoundException e) {
|
||||||
|
Log.e(TAG, "Unable to resolve a Factory Reset Handler Application");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (factoryResetWizardPackageInfo.requestedPermissions == null
|
||||||
|
|| factoryResetWizardPackageInfo.requestedPermissions.length == 0) {
|
||||||
|
Log.e(TAG, "Factory Reset Handler has no permissions requested.");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
for (int i = 0; i < factoryResetWizardPackageInfo.requestedPermissions.length; i++) {
|
||||||
|
String permission = factoryResetWizardPackageInfo.requestedPermissions[i];
|
||||||
|
boolean isGranted =
|
||||||
|
(factoryResetWizardPackageInfo.requestedPermissionsFlags[i]
|
||||||
|
& PackageInfo.REQUESTED_PERMISSION_GRANTED) != 0;
|
||||||
|
if (permission.equals(PREPARE_FACTORY_RESET_PERMISSION) && isGranted) {
|
||||||
|
return prepareFactoryResetWizardRequest;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return prepareFactoryResetWizardRequest;
|
||||||
|
}
|
||||||
|
Log.i(TAG, "Unable to resolve a Factory Reset Handler Activity");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setFragment(ResetDashboardFragment fragment) {
|
||||||
|
if (Flags.enableFactoryResetWizard()) {
|
||||||
|
mFactoryResetPreparationLauncher = fragment.registerForActivityResult(
|
||||||
|
new ActivityResultContracts.StartActivityForResult(),
|
||||||
|
result -> {
|
||||||
|
startFactoryResetActivity();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void startFactoryResetActivity() {
|
||||||
|
final Intent intent = new Intent(mContext, Settings.FactoryResetActivity.class);
|
||||||
|
mContext.startActivity(intent);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -65,6 +65,11 @@ public class ResetDashboardFragment extends DashboardFragment {
|
|||||||
if (SubscriptionUtil.isSimHardwareVisible(context)) {
|
if (SubscriptionUtil.isSimHardwareVisible(context)) {
|
||||||
use(EraseEuiccDataController.class).setFragment(this);
|
use(EraseEuiccDataController.class).setFragment(this);
|
||||||
}
|
}
|
||||||
|
FactoryResetPreferenceController factoryResetPreferenceController =
|
||||||
|
use(FactoryResetPreferenceController.class);
|
||||||
|
if (factoryResetPreferenceController != null) {
|
||||||
|
factoryResetPreferenceController.setFragment(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Reference in New Issue
Block a user