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

@@ -76,6 +76,22 @@ public final class ChooseLockSettingsHelper {
return launchConfirmationActivity(request, title, null, null, returnCredentials, false);
}
/**
* If a pattern, password or PIN exists, prompt the user before allowing them to change it.
*
* @param title title of the confirmation screen; shown in the action bar
* @param returnCredentials if true, put credentials into intent. Note that if this is true,
* this can only be called internally.
* @param userId The userId for whom the lock should be confirmed.
* @return true if one exists and we launched an activity to confirm it
* @see Activity#onActivityResult(int, int, android.content.Intent)
*/
boolean launchConfirmationActivity(int request, CharSequence title, boolean returnCredentials,
int userId) {
return launchConfirmationActivity(request, title, null, null,
returnCredentials, false, false, 0, Utils.getSameOwnerUserId(mActivity, userId));
}
/**
* If a pattern, password or PIN exists, prompt the user before allowing them to change it.
*
@@ -93,7 +109,7 @@ public final class ChooseLockSettingsHelper {
@Nullable CharSequence header, @Nullable CharSequence description,
boolean returnCredentials, boolean external) {
return launchConfirmationActivity(request, title, header, description,
returnCredentials, external, false, 0);
returnCredentials, external, false, 0, Utils.getEffectiveUserId(mActivity));
}
/**
@@ -109,24 +125,22 @@ public final class ChooseLockSettingsHelper {
@Nullable CharSequence header, @Nullable CharSequence description,
long challenge) {
return launchConfirmationActivity(request, title, header, description,
false, false, true, challenge);
false, false, true, challenge, Utils.getEffectiveUserId(mActivity));
}
private boolean launchConfirmationActivity(int request, @Nullable CharSequence title,
@Nullable CharSequence header, @Nullable CharSequence description,
boolean returnCredentials, boolean external, boolean hasChallenge,
long challenge) {
long challenge, int effectiveUserId) {
boolean launched = false;
int effectiveUserId = Utils.getEffectiveUserId(mActivity);
switch (mLockPatternUtils.getKeyguardStoredPasswordQuality(effectiveUserId)) {
case DevicePolicyManager.PASSWORD_QUALITY_SOMETHING:
launched = launchConfirmationActivity(request, title, header, description,
returnCredentials || hasChallenge
? ConfirmLockPattern.InternalActivity.class
: ConfirmLockPattern.class, external,
hasChallenge, challenge);
hasChallenge, challenge, effectiveUserId);
break;
case DevicePolicyManager.PASSWORD_QUALITY_NUMERIC:
case DevicePolicyManager.PASSWORD_QUALITY_NUMERIC_COMPLEX:
@@ -137,7 +151,7 @@ public final class ChooseLockSettingsHelper {
returnCredentials || hasChallenge
? ConfirmLockPassword.InternalActivity.class
: ConfirmLockPassword.class, external,
hasChallenge, challenge);
hasChallenge, challenge, effectiveUserId);
break;
}
return launched;
@@ -145,7 +159,7 @@ public final class ChooseLockSettingsHelper {
private boolean launchConfirmationActivity(int request, CharSequence title, CharSequence header,
CharSequence message, Class<?> activityClass, boolean external, boolean hasChallenge,
long challenge) {
long challenge, int userId) {
final Intent intent = new Intent();
intent.putExtra(ConfirmDeviceCredentialBaseFragment.TITLE_TEXT, title);
intent.putExtra(ConfirmDeviceCredentialBaseFragment.HEADER_TEXT, header);
@@ -156,6 +170,7 @@ public final class ChooseLockSettingsHelper {
intent.putExtra(ConfirmDeviceCredentialBaseFragment.SHOW_WHEN_LOCKED, external);
intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_HAS_CHALLENGE, hasChallenge);
intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE, challenge);
intent.putExtra(ChooseLockGeneric.KEY_USER_ID, userId);
intent.setClassName(ConfirmDeviceCredentialBaseFragment.PACKAGE, activityClass.getName());
if (external) {
intent.addFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT);