Fix 2594148: confirm PIN/Password before resetting device
This fixes a bug where user was allowed to factory reset the device without entering their PIN/Password. It also fixes the same issue with MediaFormat (Settings->SD Card->Format). Change-Id: I0677a50aa771ad8663513fd7ec398a70953dcde2
This commit is contained in:
@@ -54,7 +54,7 @@ public class ChooseLockGeneric extends PreferenceActivity {
|
|||||||
|
|
||||||
if (!mPasswordConfirmed) {
|
if (!mPasswordConfirmed) {
|
||||||
ChooseLockSettingsHelper helper = new ChooseLockSettingsHelper(this);
|
ChooseLockSettingsHelper helper = new ChooseLockSettingsHelper(this);
|
||||||
if (!helper.launchConfirmationActivity(CONFIRM_EXISTING_REQUEST)) {
|
if (!helper.launchConfirmationActivity(CONFIRM_EXISTING_REQUEST, null, null)) {
|
||||||
mPasswordConfirmed = true; // no password set, so no need to confirm
|
mPasswordConfirmed = true; // no password set, so no need to confirm
|
||||||
updatePreferencesOrFinish();
|
updatePreferencesOrFinish();
|
||||||
}
|
}
|
||||||
|
@@ -119,7 +119,8 @@ public class ChooseLockPassword extends Activity implements OnClickListener, OnE
|
|||||||
if (savedInstanceState == null) {
|
if (savedInstanceState == null) {
|
||||||
updateStage(Stage.Introduction);
|
updateStage(Stage.Introduction);
|
||||||
if (confirmCredentials) {
|
if (confirmCredentials) {
|
||||||
mChooseLockSettingsHelper.launchConfirmationActivity(CONFIRM_EXISTING_REQUEST);
|
mChooseLockSettingsHelper.launchConfirmationActivity(CONFIRM_EXISTING_REQUEST,
|
||||||
|
null, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -288,7 +288,8 @@ public class ChooseLockPattern extends Activity implements View.OnClickListener{
|
|||||||
// there isn't an existing password or the user confirms their password.
|
// there isn't an existing password or the user confirms their password.
|
||||||
updateStage(Stage.NeedToConfirm);
|
updateStage(Stage.NeedToConfirm);
|
||||||
boolean launchedConfirmationActivity =
|
boolean launchedConfirmationActivity =
|
||||||
mChooseLockSettingsHelper.launchConfirmationActivity(CONFIRM_EXISTING_REQUEST);
|
mChooseLockSettingsHelper.launchConfirmationActivity(CONFIRM_EXISTING_REQUEST,
|
||||||
|
null, null);
|
||||||
if (!launchedConfirmationActivity) {
|
if (!launchedConfirmationActivity) {
|
||||||
updateStage(Stage.Introduction);
|
updateStage(Stage.Introduction);
|
||||||
}
|
}
|
||||||
|
@@ -37,18 +37,22 @@ public class ChooseLockSettingsHelper {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* If a pattern, password or PIN exists, prompt the user before allowing them to change it.
|
* If a pattern, password or PIN exists, prompt the user before allowing them to change it.
|
||||||
|
* @param message optional message to display about the action about to be done
|
||||||
|
* @param details optional detail message to display
|
||||||
* @return true if one exists and we launched an activity to confirm it
|
* @return true if one exists and we launched an activity to confirm it
|
||||||
* @see #onActivityResult(int, int, android.content.Intent)
|
* @see #onActivityResult(int, int, android.content.Intent)
|
||||||
*/
|
*/
|
||||||
protected boolean launchConfirmationActivity(int request) {
|
protected boolean launchConfirmationActivity(int request,
|
||||||
|
CharSequence message, CharSequence details) {
|
||||||
boolean launched = false;
|
boolean launched = false;
|
||||||
switch (mLockPatternUtils.getKeyguardStoredPasswordQuality()) {
|
switch (mLockPatternUtils.getKeyguardStoredPasswordQuality()) {
|
||||||
case DevicePolicyManager.PASSWORD_QUALITY_SOMETHING:
|
case DevicePolicyManager.PASSWORD_QUALITY_SOMETHING:
|
||||||
launched = confirmPattern(request);
|
launched = confirmPattern(request, message, details);
|
||||||
break;
|
break;
|
||||||
case DevicePolicyManager.PASSWORD_QUALITY_NUMERIC:
|
case DevicePolicyManager.PASSWORD_QUALITY_NUMERIC:
|
||||||
case DevicePolicyManager.PASSWORD_QUALITY_ALPHABETIC:
|
case DevicePolicyManager.PASSWORD_QUALITY_ALPHABETIC:
|
||||||
case DevicePolicyManager.PASSWORD_QUALITY_ALPHANUMERIC:
|
case DevicePolicyManager.PASSWORD_QUALITY_ALPHANUMERIC:
|
||||||
|
// TODO: update UI layout for ConfirmPassword to show message and details
|
||||||
launched = confirmPassword(request);
|
launched = confirmPassword(request);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -57,14 +61,19 @@ public class ChooseLockSettingsHelper {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Launch screen to confirm the existing lock pattern.
|
* Launch screen to confirm the existing lock pattern.
|
||||||
|
* @param message shown in header of ConfirmLockPattern if not null
|
||||||
|
* @param details shown in footer of ConfirmLockPattern if not null
|
||||||
* @see #onActivityResult(int, int, android.content.Intent)
|
* @see #onActivityResult(int, int, android.content.Intent)
|
||||||
* @return true if we launched an activity to confirm pattern
|
* @return true if we launched an activity to confirm pattern
|
||||||
*/
|
*/
|
||||||
private boolean confirmPattern(int request) {
|
private boolean confirmPattern(int request, CharSequence message, CharSequence details) {
|
||||||
if (!mLockPatternUtils.isLockPatternEnabled() || !mLockPatternUtils.savedPatternExists()) {
|
if (!mLockPatternUtils.isLockPatternEnabled() || !mLockPatternUtils.savedPatternExists()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final Intent intent = new Intent();
|
final Intent intent = new Intent();
|
||||||
|
// supply header and footer text in the intent
|
||||||
|
intent.putExtra(ConfirmLockPattern.HEADER_TEXT, message);
|
||||||
|
intent.putExtra(ConfirmLockPattern.FOOTER_TEXT, details);
|
||||||
intent.setClassName("com.android.settings", "com.android.settings.ConfirmLockPattern");
|
intent.setClassName("com.android.settings", "com.android.settings.ConfirmLockPattern");
|
||||||
mActivity.startActivityForResult(intent, request);
|
mActivity.startActivityForResult(intent, request);
|
||||||
return true;
|
return true;
|
||||||
|
@@ -71,17 +71,14 @@ public class MasterClear extends Activity {
|
|||||||
/**
|
/**
|
||||||
* Keyguard validation is run using the standard {@link ConfirmLockPattern}
|
* Keyguard validation is run using the standard {@link ConfirmLockPattern}
|
||||||
* component as a subactivity
|
* component as a subactivity
|
||||||
|
* @param request the request code to be returned once confirmation finishes
|
||||||
|
* @return true if confirmation launched
|
||||||
*/
|
*/
|
||||||
private void runKeyguardConfirmation() {
|
private boolean runKeyguardConfirmation(int request) {
|
||||||
final Intent intent = new Intent();
|
return new ChooseLockSettingsHelper(this)
|
||||||
intent.setClassName("com.android.settings",
|
.launchConfirmationActivity(request,
|
||||||
"com.android.settings.ConfirmLockPattern");
|
getText(R.string.master_clear_gesture_prompt),
|
||||||
// supply header and footer text in the intent
|
|
||||||
intent.putExtra(ConfirmLockPattern.HEADER_TEXT,
|
|
||||||
getText(R.string.master_clear_gesture_prompt));
|
|
||||||
intent.putExtra(ConfirmLockPattern.FOOTER_TEXT,
|
|
||||||
getText(R.string.master_clear_gesture_explanation));
|
getText(R.string.master_clear_gesture_explanation));
|
||||||
startActivityForResult(intent, KEYGUARD_REQUEST);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -96,6 +93,8 @@ public class MasterClear extends Activity {
|
|||||||
// confirmation prompt; otherwise, go back to the initial state.
|
// confirmation prompt; otherwise, go back to the initial state.
|
||||||
if (resultCode == Activity.RESULT_OK) {
|
if (resultCode == Activity.RESULT_OK) {
|
||||||
establishFinalConfirmationState();
|
establishFinalConfirmationState();
|
||||||
|
} else if (resultCode == Activity.RESULT_CANCELED) {
|
||||||
|
finish();
|
||||||
} else {
|
} else {
|
||||||
establishInitialState();
|
establishInitialState();
|
||||||
}
|
}
|
||||||
@@ -108,9 +107,7 @@ public class MasterClear extends Activity {
|
|||||||
*/
|
*/
|
||||||
private Button.OnClickListener mInitiateListener = new Button.OnClickListener() {
|
private Button.OnClickListener mInitiateListener = new Button.OnClickListener() {
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
if (mLockUtils.isLockPatternEnabled()) {
|
if (!runKeyguardConfirmation(KEYGUARD_REQUEST)) {
|
||||||
runKeyguardConfirmation();
|
|
||||||
} else {
|
|
||||||
establishFinalConfirmationState();
|
establishFinalConfirmationState();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -88,16 +88,11 @@ public class MediaFormat extends Activity {
|
|||||||
* Keyguard validation is run using the standard {@link ConfirmLockPattern}
|
* Keyguard validation is run using the standard {@link ConfirmLockPattern}
|
||||||
* component as a subactivity
|
* component as a subactivity
|
||||||
*/
|
*/
|
||||||
private void runKeyguardConfirmation() {
|
private boolean runKeyguardConfirmation(int request) {
|
||||||
final Intent intent = new Intent();
|
return new ChooseLockSettingsHelper(this)
|
||||||
intent.setClassName("com.android.settings",
|
.launchConfirmationActivity(request,
|
||||||
"com.android.settings.ConfirmLockPattern");
|
getText(R.string.media_format_gesture_prompt),
|
||||||
// supply header and footer text in the intent
|
|
||||||
intent.putExtra(ConfirmLockPattern.HEADER_TEXT,
|
|
||||||
getText(R.string.media_format_gesture_prompt));
|
|
||||||
intent.putExtra(ConfirmLockPattern.FOOTER_TEXT,
|
|
||||||
getText(R.string.media_format_gesture_explanation));
|
getText(R.string.media_format_gesture_explanation));
|
||||||
startActivityForResult(intent, KEYGUARD_REQUEST);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -112,6 +107,8 @@ public class MediaFormat extends Activity {
|
|||||||
// confirmation prompt; otherwise, go back to the initial state.
|
// confirmation prompt; otherwise, go back to the initial state.
|
||||||
if (resultCode == Activity.RESULT_OK) {
|
if (resultCode == Activity.RESULT_OK) {
|
||||||
establishFinalConfirmationState();
|
establishFinalConfirmationState();
|
||||||
|
} else if (resultCode == Activity.RESULT_CANCELED) {
|
||||||
|
finish();
|
||||||
} else {
|
} else {
|
||||||
establishInitialState();
|
establishInitialState();
|
||||||
}
|
}
|
||||||
@@ -124,9 +121,7 @@ public class MediaFormat extends Activity {
|
|||||||
*/
|
*/
|
||||||
private Button.OnClickListener mInitiateListener = new Button.OnClickListener() {
|
private Button.OnClickListener mInitiateListener = new Button.OnClickListener() {
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
if (mLockUtils.isLockPatternEnabled()) {
|
if (!runKeyguardConfirmation(KEYGUARD_REQUEST)) {
|
||||||
runKeyguardConfirmation();
|
|
||||||
} else {
|
|
||||||
establishFinalConfirmationState();
|
establishFinalConfirmationState();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user