Refactor Choose/Confirm Lock flow to take user id

This is a first step to allow this flow to be reused for setting
a work profile-specific lock, to be used with the work challenge.

Change-Id: Iaa65fdab9021cda5f0a1d3bc526a6b54f8a7dd16
This commit is contained in:
Clara Bayarri
2015-10-12 12:07:02 +01:00
parent 39b467482d
commit fe432e838e
9 changed files with 166 additions and 70 deletions

View File

@@ -82,6 +82,15 @@ public class ChooseLockPassword extends SettingsActivity {
return intent;
}
public static Intent createIntent(Context context, int quality,
int minLength, final int maxLength, boolean requirePasswordToDecrypt,
boolean confirmCredentials, int userId) {
Intent intent = createIntent(context, quality, minLength, maxLength,
requirePasswordToDecrypt, confirmCredentials);
intent.putExtra(ChooseLockGeneric.KEY_USER_ID, userId);
return intent;
}
public static Intent createIntent(Context context, int quality,
int minLength, final int maxLength, boolean requirePasswordToDecrypt, String password) {
Intent intent = createIntent(context, quality, minLength, maxLength,
@@ -90,6 +99,14 @@ public class ChooseLockPassword extends SettingsActivity {
return intent;
}
public static Intent createIntent(Context context, int quality, int minLength,
int maxLength, boolean requirePasswordToDecrypt, String password, int userId) {
Intent intent = createIntent(context, quality, minLength, maxLength,
requirePasswordToDecrypt, password);
intent.putExtra(ChooseLockGeneric.KEY_USER_ID, userId);
return intent;
}
public static Intent createIntent(Context context, int quality,
int minLength, final int maxLength, boolean requirePasswordToDecrypt, long challenge) {
Intent intent = createIntent(context, quality, minLength, maxLength,
@@ -99,6 +116,14 @@ public class ChooseLockPassword extends SettingsActivity {
return intent;
}
public static Intent createIntent(Context context, int quality, int minLength,
int maxLength, boolean requirePasswordToDecrypt, long challenge, int userId) {
Intent intent = createIntent(context, quality, minLength, maxLength,
requirePasswordToDecrypt, challenge);
intent.putExtra(ChooseLockGeneric.KEY_USER_ID, userId);
return intent;
}
@Override
protected boolean isValidFragment(String fragmentName) {
if (ChooseLockPasswordFragment.class.getName().equals(fragmentName)) return true;
@@ -160,6 +185,8 @@ public class ChooseLockPassword extends SettingsActivity {
private static final long ERROR_MESSAGE_TIMEOUT = 3000;
private static final int MSG_SHOW_ERROR = 1;
private int mUserId;
private Handler mHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
@@ -210,32 +237,34 @@ public class ChooseLockPassword extends SettingsActivity {
if (!(getActivity() instanceof ChooseLockPassword)) {
throw new SecurityException("Fragment contained in wrong activity");
}
// Only take this argument into account if it belongs to the current profile.
mUserId = Utils.getSameOwnerUserId(getActivity(), intent.getExtras());
mRequestedQuality = Math.max(intent.getIntExtra(LockPatternUtils.PASSWORD_TYPE_KEY,
mRequestedQuality), mLockPatternUtils.getRequestedPasswordQuality(
UserHandle.myUserId()));
mUserId));
mPasswordMinLength = Math.max(Math.max(
LockPatternUtils.MIN_LOCK_PASSWORD_SIZE,
intent.getIntExtra(PASSWORD_MIN_KEY, mPasswordMinLength)),
mLockPatternUtils.getRequestedMinimumPasswordLength(UserHandle.myUserId()));
mLockPatternUtils.getRequestedMinimumPasswordLength(mUserId));
mPasswordMaxLength = intent.getIntExtra(PASSWORD_MAX_KEY, mPasswordMaxLength);
mPasswordMinLetters = Math.max(intent.getIntExtra(PASSWORD_MIN_LETTERS_KEY,
mPasswordMinLetters), mLockPatternUtils.getRequestedPasswordMinimumLetters(
UserHandle.myUserId()));
mUserId));
mPasswordMinUpperCase = Math.max(intent.getIntExtra(PASSWORD_MIN_UPPERCASE_KEY,
mPasswordMinUpperCase), mLockPatternUtils.getRequestedPasswordMinimumUpperCase(
UserHandle.myUserId()));
mUserId));
mPasswordMinLowerCase = Math.max(intent.getIntExtra(PASSWORD_MIN_LOWERCASE_KEY,
mPasswordMinLowerCase), mLockPatternUtils.getRequestedPasswordMinimumLowerCase(
UserHandle.myUserId()));
mUserId));
mPasswordMinNumeric = Math.max(intent.getIntExtra(PASSWORD_MIN_NUMERIC_KEY,
mPasswordMinNumeric), mLockPatternUtils.getRequestedPasswordMinimumNumeric(
UserHandle.myUserId()));
mUserId));
mPasswordMinSymbols = Math.max(intent.getIntExtra(PASSWORD_MIN_SYMBOLS_KEY,
mPasswordMinSymbols), mLockPatternUtils.getRequestedPasswordMinimumSymbols(
UserHandle.myUserId()));
mUserId));
mPasswordMinNonLetter = Math.max(intent.getIntExtra(PASSWORD_MIN_NONLETTER_KEY,
mPasswordMinNonLetter), mLockPatternUtils.getRequestedPasswordMinimumNonLetter(
UserHandle.myUserId()));
mUserId));
mChooseLockSettingsHelper = new ChooseLockSettingsHelper(getActivity());
}
@@ -289,7 +318,8 @@ public class ChooseLockPassword extends SettingsActivity {
updateStage(Stage.Introduction);
if (confirmCredentials) {
mChooseLockSettingsHelper.launchConfirmationActivity(CONFIRM_EXISTING_REQUEST,
getString(R.string.unlock_set_unlock_launch_picker_title), true);
getString(R.string.unlock_set_unlock_launch_picker_title), true,
mUserId);
}
} else {
// restore from previous state
@@ -477,7 +507,7 @@ public class ChooseLockPassword extends SettingsActivity {
return getString(R.string.lockpassword_password_requires_digit);
}
}
if(mLockPatternUtils.checkPasswordHistory(password, UserHandle.myUserId())) {
if(mLockPatternUtils.checkPasswordHistory(password, mUserId)) {
return getString(mIsAlphaMode ? R.string.lockpassword_password_recently_used
: R.string.lockpassword_pin_recently_used);
}
@@ -618,7 +648,7 @@ public class ChooseLockPassword extends SettingsActivity {
final boolean required = getActivity().getIntent().getBooleanExtra(
EncryptionInterstitial.EXTRA_REQUIRE_PASSWORD, true);
mSaveAndFinishWorker.start(mLockPatternUtils, required, mHasChallenge, mChallenge,
mChosenPassword, mCurrentPassword, mRequestedQuality);
mChosenPassword, mCurrentPassword, mRequestedQuality, mUserId);
}
@Override
@@ -640,15 +670,17 @@ public class ChooseLockPassword extends SettingsActivity {
private String mChosenPassword;
private String mCurrentPassword;
private int mRequestedQuality;
private int mUserId;
public void start(LockPatternUtils utils, boolean required,
boolean hasChallenge, long challenge,
String chosenPassword, String currentPassword, int requestedQuality) {
String chosenPassword, String currentPassword, int requestedQuality, int userId) {
prepare(utils, required, hasChallenge, challenge);
mChosenPassword = chosenPassword;
mCurrentPassword = currentPassword;
mRequestedQuality = requestedQuality;
mUserId = userId;
start();
}
@@ -656,14 +688,13 @@ public class ChooseLockPassword extends SettingsActivity {
@Override
protected Intent saveAndVerifyInBackground() {
Intent result = null;
final int userId = UserHandle.myUserId();
mUtils.saveLockPassword(mChosenPassword, mCurrentPassword, mRequestedQuality,
userId);
mUserId);
if (mHasChallenge) {
byte[] token;
try {
token = mUtils.verifyPassword(mChosenPassword, mChallenge, userId);
token = mUtils.verifyPassword(mChosenPassword, mChallenge, mUserId);
} catch (RequestThrottledException e) {
token = null;
}