Use user restriction instead of pin to guard factory reset in Settings.
Bug: 14081992
Change-Id: I60f132312368c5097b46ab97e881eec3700ef586
diff --git a/src/com/android/settings/MasterClear.java b/src/com/android/settings/MasterClear.java
index eaf29c6..bbd98fb 100644
--- a/src/com/android/settings/MasterClear.java
+++ b/src/com/android/settings/MasterClear.java
@@ -54,7 +54,6 @@
private static final String TAG = "MasterClear";
private static final int KEYGUARD_REQUEST = 55;
- private static final int PIN_REQUEST = 56;
static final String ERASE_EXTERNAL_EXTRA = "erase_sd";
@@ -62,7 +61,6 @@
private Button mInitiateButton;
private View mExternalStorageContainer;
private CheckBox mExternalStorage;
- private boolean mPinConfirmed;
/**
* Keyguard validation is run using the standard {@link ConfirmLockPattern}
@@ -78,25 +76,11 @@
res.getText(R.string.master_clear_gesture_explanation));
}
- private boolean runRestrictionsChallenge() {
- if (UserManager.get(getActivity()).hasRestrictionsChallenge()) {
- startActivityForResult(
- new Intent(Intent.ACTION_RESTRICTIONS_CHALLENGE), PIN_REQUEST);
- return true;
- }
- return false;
- }
-
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
- if (requestCode == PIN_REQUEST) {
- if (resultCode == Activity.RESULT_OK) {
- mPinConfirmed = true;
- }
- return;
- } else if (requestCode != KEYGUARD_REQUEST) {
+ if (requestCode != KEYGUARD_REQUEST) {
return;
}
@@ -125,10 +109,6 @@
private final Button.OnClickListener mInitiateListener = new Button.OnClickListener() {
public void onClick(View v) {
- mPinConfirmed = false;
- if (runRestrictionsChallenge()) {
- return;
- }
if (!runKeyguardConfirmation(KEYGUARD_REQUEST)) {
showFinalConfirmation();
}
@@ -254,22 +234,14 @@
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
+ if (UserManager.get(getActivity()).hasUserRestriction(
+ UserManager.DISALLOW_FACTORY_RESET)) {
+ return inflater.inflate(R.layout.master_clear_disallowed_screen, null);
+ }
+
mContentView = inflater.inflate(R.layout.master_clear, null);
establishInitialState();
return mContentView;
}
-
- @Override
- public void onResume() {
- super.onResume();
-
- // If this is the second step after restrictions pin challenge
- if (mPinConfirmed) {
- mPinConfirmed = false;
- if (!runKeyguardConfirmation(KEYGUARD_REQUEST)) {
- showFinalConfirmation();
- }
- }
- }
}
diff --git a/src/com/android/settings/MasterClearConfirm.java b/src/com/android/settings/MasterClearConfirm.java
index 9c15c73..4ee17b8 100644
--- a/src/com/android/settings/MasterClearConfirm.java
+++ b/src/com/android/settings/MasterClearConfirm.java
@@ -24,6 +24,7 @@
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
+import android.os.UserManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@@ -80,6 +81,10 @@
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
+ if (UserManager.get(getActivity()).hasUserRestriction(
+ UserManager.DISALLOW_FACTORY_RESET)) {
+ return inflater.inflate(R.layout.master_clear_disallowed_screen, null);
+ }
mContentView = inflater.inflate(R.layout.master_clear_confirm, null);
establishFinalConfirmationState();
return mContentView;
diff --git a/src/com/android/settings/PrivacySettings.java b/src/com/android/settings/PrivacySettings.java
index 7f699c5..aac7638 100644
--- a/src/com/android/settings/PrivacySettings.java
+++ b/src/com/android/settings/PrivacySettings.java
@@ -26,6 +26,7 @@
import android.os.Bundle;
import android.os.RemoteException;
import android.os.ServiceManager;
+import android.os.UserManager;
import android.preference.CheckBoxPreference;
import android.preference.Preference;
import android.preference.PreferenceScreen;
@@ -43,6 +44,7 @@
private static final String BACKUP_DATA = "backup_data";
private static final String AUTO_RESTORE = "auto_restore";
private static final String CONFIGURE_ACCOUNT = "configure_account";
+ private static final String PERSONAL_DATA_CATEGORY = "personal_data_category";
private IBackupManager mBackupManager;
private CheckBoxPreference mBackup;
private CheckBoxPreference mAutoRestore;
@@ -65,6 +67,11 @@
mAutoRestore = (CheckBoxPreference) screen.findPreference(AUTO_RESTORE);
mConfigure = (PreferenceScreen) screen.findPreference(CONFIGURE_ACCOUNT);
+ if (UserManager.get(getActivity()).hasUserRestriction(
+ UserManager.DISALLOW_FACTORY_RESET)) {
+ screen.removePreference(findPreference(PERSONAL_DATA_CATEGORY));
+ }
+
// Vendor specific
if (getActivity().getPackageManager().
resolveContentProvider(GSETTINGS_PROVIDER, 0) == null) {