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

@@ -47,6 +47,7 @@ import com.android.internal.widget.LockPatternUtils;
public class ChooseLockGeneric extends SettingsActivity { public class ChooseLockGeneric extends SettingsActivity {
public static final String CONFIRM_CREDENTIALS = "confirm_credentials"; public static final String CONFIRM_CREDENTIALS = "confirm_credentials";
public static final String KEY_USER_ID = "user_id";
@Override @Override
public Intent getIntent() { public Intent getIntent() {
@@ -102,6 +103,7 @@ public class ChooseLockGeneric extends SettingsActivity {
private String mUserPassword; private String mUserPassword;
private LockPatternUtils mLockPatternUtils; private LockPatternUtils mLockPatternUtils;
private FingerprintManager mFingerprintManager; private FingerprintManager mFingerprintManager;
private int mUserId;
private RemovalCallback mRemovalCallback = new RemovalCallback() { private RemovalCallback mRemovalCallback = new RemovalCallback() {
@Override @Override
@@ -160,13 +162,16 @@ public class ChooseLockGeneric extends SettingsActivity {
ENCRYPT_REQUESTED_DISABLED); ENCRYPT_REQUESTED_DISABLED);
} }
// Only take this argument into account if it belongs to the current profile.
mUserId = Utils.getSameOwnerUserId(getContext(), getArguments());
if (mPasswordConfirmed) { if (mPasswordConfirmed) {
updatePreferencesOrFinish(); updatePreferencesOrFinish();
} else if (!mWaitingForConfirmation) { } else if (!mWaitingForConfirmation) {
ChooseLockSettingsHelper helper = ChooseLockSettingsHelper helper =
new ChooseLockSettingsHelper(this.getActivity(), this); new ChooseLockSettingsHelper(this.getActivity(), this);
if (!helper.launchConfirmationActivity(CONFIRM_EXISTING_REQUEST, if (!helper.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)) {
mPasswordConfirmed = true; // no password set, so no need to confirm mPasswordConfirmed = true; // no password set, so no need to confirm
updatePreferencesOrFinish(); updatePreferencesOrFinish();
} else { } else {
@@ -187,7 +192,7 @@ public class ChooseLockGeneric extends SettingsActivity {
public boolean onPreferenceTreeClick(Preference preference) { public boolean onPreferenceTreeClick(Preference preference) {
final String key = preference.getKey(); final String key = preference.getKey();
if (!isUnlockMethodSecure(key) && mLockPatternUtils.isSecure(UserHandle.myUserId())) { if (!isUnlockMethodSecure(key) && mLockPatternUtils.isSecure(mUserId)) {
// Show the disabling FRP warning only when the user is switching from a secure // Show the disabling FRP warning only when the user is switching from a secure
// unlock method to an insecure one // unlock method to an insecure one
showFactoryResetProtectionWarningDialog(key); showFactoryResetProtectionWarningDialog(key);
@@ -291,10 +296,10 @@ public class ChooseLockGeneric extends SettingsActivity {
} }
private String getKeyForCurrent() { private String getKeyForCurrent() {
if (mLockPatternUtils.isLockScreenDisabled(UserHandle.myUserId())) { if (mLockPatternUtils.isLockScreenDisabled(mUserId)) {
return KEY_UNLOCK_SET_OFF; return KEY_UNLOCK_SET_OFF;
} }
switch (mLockPatternUtils.getKeyguardStoredPasswordQuality(UserHandle.myUserId())) { switch (mLockPatternUtils.getKeyguardStoredPasswordQuality(mUserId)) {
case DevicePolicyManager.PASSWORD_QUALITY_SOMETHING: case DevicePolicyManager.PASSWORD_QUALITY_SOMETHING:
return KEY_UNLOCK_SET_PATTERN; return KEY_UNLOCK_SET_PATTERN;
case DevicePolicyManager.PASSWORD_QUALITY_NUMERIC: case DevicePolicyManager.PASSWORD_QUALITY_NUMERIC:
@@ -408,38 +413,38 @@ public class ChooseLockGeneric extends SettingsActivity {
protected Intent getLockPasswordIntent(Context context, int quality, protected Intent getLockPasswordIntent(Context context, int quality,
int minLength, final int maxLength, int minLength, final int maxLength,
boolean requirePasswordToDecrypt, boolean confirmCredentials) { boolean requirePasswordToDecrypt, boolean confirmCredentials, int userId) {
return ChooseLockPassword.createIntent(context, quality, minLength, return ChooseLockPassword.createIntent(context, quality, minLength,
maxLength, requirePasswordToDecrypt, confirmCredentials); maxLength, requirePasswordToDecrypt, confirmCredentials, userId);
} }
protected Intent getLockPasswordIntent(Context context, int quality, protected Intent getLockPasswordIntent(Context context, int quality,
int minLength, final int maxLength, int minLength, final int maxLength,
boolean requirePasswordToDecrypt, long challenge) { boolean requirePasswordToDecrypt, long challenge, int userId) {
return ChooseLockPassword.createIntent(context, quality, minLength, return ChooseLockPassword.createIntent(context, quality, minLength,
maxLength, requirePasswordToDecrypt, challenge); maxLength, requirePasswordToDecrypt, challenge, userId);
} }
protected Intent getLockPasswordIntent(Context context, int quality, int minLength, protected Intent getLockPasswordIntent(Context context, int quality, int minLength,
final int maxLength, boolean requirePasswordToDecrypt, String password) { int maxLength, boolean requirePasswordToDecrypt, String password, int userId) {
return ChooseLockPassword.createIntent(context, quality, minLength, maxLength, return ChooseLockPassword.createIntent(context, quality, minLength, maxLength,
requirePasswordToDecrypt, password); requirePasswordToDecrypt, password, userId);
} }
protected Intent getLockPatternIntent(Context context, final boolean requirePassword, protected Intent getLockPatternIntent(Context context, final boolean requirePassword,
final boolean confirmCredentials) { final boolean confirmCredentials, int userId) {
return ChooseLockPattern.createIntent(context, requirePassword, return ChooseLockPattern.createIntent(context, requirePassword,
confirmCredentials); confirmCredentials, userId);
} }
protected Intent getLockPatternIntent(Context context, final boolean requirePassword, protected Intent getLockPatternIntent(Context context, final boolean requirePassword,
long challenge) { long challenge, int userId) {
return ChooseLockPattern.createIntent(context, requirePassword, challenge); return ChooseLockPattern.createIntent(context, requirePassword, challenge, userId);
} }
protected Intent getLockPatternIntent(Context context, final boolean requirePassword, protected Intent getLockPatternIntent(Context context, final boolean requirePassword,
final String pattern) { final String pattern, int userId) {
return ChooseLockPattern.createIntent(context, requirePassword, pattern); return ChooseLockPattern.createIntent(context, requirePassword, pattern, userId);
} }
protected Intent getEncryptionInterstitialIntent(Context context, int quality, protected Intent getEncryptionInterstitialIntent(Context context, int quality,
@@ -474,26 +479,25 @@ public class ChooseLockGeneric extends SettingsActivity {
Intent intent; Intent intent;
if (mHasChallenge) { if (mHasChallenge) {
intent = getLockPasswordIntent(context, quality, minLength, intent = getLockPasswordIntent(context, quality, minLength,
maxLength, mRequirePassword, mChallenge); maxLength, mRequirePassword, mChallenge, mUserId);
} else { } else {
intent = getLockPasswordIntent(context, quality, minLength, intent = getLockPasswordIntent(context, quality, minLength,
maxLength, mRequirePassword, mUserPassword); maxLength, mRequirePassword, mUserPassword, mUserId);
} }
startActivityForResult(intent, CHOOSE_LOCK_REQUEST); startActivityForResult(intent, CHOOSE_LOCK_REQUEST);
} else if (quality == DevicePolicyManager.PASSWORD_QUALITY_SOMETHING) { } else if (quality == DevicePolicyManager.PASSWORD_QUALITY_SOMETHING) {
Intent intent; Intent intent;
if (mHasChallenge) { if (mHasChallenge) {
intent = getLockPatternIntent(context, mRequirePassword, intent = getLockPatternIntent(context, mRequirePassword,
mChallenge); mChallenge, mUserId);
} else { } else {
intent = getLockPatternIntent(context, mRequirePassword, intent = getLockPatternIntent(context, mRequirePassword,
mUserPassword); mUserPassword, mUserId);
} }
startActivityForResult(intent, CHOOSE_LOCK_REQUEST); startActivityForResult(intent, CHOOSE_LOCK_REQUEST);
} else if (quality == DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED) { } else if (quality == DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED) {
mChooseLockSettingsHelper.utils().clearLock(UserHandle.myUserId()); mChooseLockSettingsHelper.utils().clearLock(mUserId);
mChooseLockSettingsHelper.utils().setLockScreenDisabled(disabled, mChooseLockSettingsHelper.utils().setLockScreenDisabled(disabled, mUserId);
UserHandle.myUserId());
removeAllFingerprintTemplatesAndFinish(); removeAllFingerprintTemplatesAndFinish();
getActivity().setResult(Activity.RESULT_OK); getActivity().setResult(Activity.RESULT_OK);
} else { } else {
@@ -522,7 +526,7 @@ public class ChooseLockGeneric extends SettingsActivity {
private int getResIdForFactoryResetProtectionWarningMessage() { private int getResIdForFactoryResetProtectionWarningMessage() {
boolean hasFingerprints = mFingerprintManager.hasEnrolledFingerprints(); boolean hasFingerprints = mFingerprintManager.hasEnrolledFingerprints();
switch (mLockPatternUtils.getKeyguardStoredPasswordQuality(UserHandle.myUserId())) { switch (mLockPatternUtils.getKeyguardStoredPasswordQuality(mUserId)) {
case DevicePolicyManager.PASSWORD_QUALITY_SOMETHING: case DevicePolicyManager.PASSWORD_QUALITY_SOMETHING:
return hasFingerprints return hasFingerprints
? R.string.unlock_disable_frp_warning_content_pattern_fingerprint ? R.string.unlock_disable_frp_warning_content_pattern_fingerprint

View File

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

View File

@@ -73,25 +73,25 @@ public class ChooseLockPattern extends SettingsActivity {
} }
public static Intent createIntent(Context context, public static Intent createIntent(Context context,
boolean requirePassword, boolean confirmCredentials) { boolean requirePassword, boolean confirmCredentials, int userId) {
Intent intent = new Intent(context, ChooseLockPattern.class); Intent intent = new Intent(context, ChooseLockPattern.class);
intent.putExtra("key_lock_method", "pattern"); intent.putExtra("key_lock_method", "pattern");
intent.putExtra(ChooseLockGeneric.CONFIRM_CREDENTIALS, confirmCredentials); intent.putExtra(ChooseLockGeneric.CONFIRM_CREDENTIALS, confirmCredentials);
intent.putExtra(EncryptionInterstitial.EXTRA_REQUIRE_PASSWORD, requirePassword); intent.putExtra(EncryptionInterstitial.EXTRA_REQUIRE_PASSWORD, requirePassword);
intent.putExtra(ChooseLockGeneric.KEY_USER_ID, userId);
return intent; return intent;
} }
public static Intent createIntent(Context context, public static Intent createIntent(Context context,
boolean requirePassword, String pattern) { boolean requirePassword, String pattern, int userId) {
Intent intent = createIntent(context, requirePassword, false); Intent intent = createIntent(context, requirePassword, false, userId);
intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_PASSWORD, pattern); intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_PASSWORD, pattern);
return intent; return intent;
} }
public static Intent createIntent(Context context, public static Intent createIntent(Context context,
boolean requirePassword, long challenge) { boolean requirePassword, long challenge, int userId) {
Intent intent = createIntent(context, requirePassword, false); Intent intent = createIntent(context, requirePassword, false, userId);
intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_HAS_CHALLENGE, true); intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_HAS_CHALLENGE, true);
intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE, challenge); intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE, challenge);
return intent; return intent;
@@ -355,6 +355,7 @@ public class ChooseLockPattern extends SettingsActivity {
private ChooseLockSettingsHelper mChooseLockSettingsHelper; private ChooseLockSettingsHelper mChooseLockSettingsHelper;
private SaveAndFinishWorker mSaveAndFinishWorker; private SaveAndFinishWorker mSaveAndFinishWorker;
private int mUserId;
private static final String KEY_UI_STAGE = "uiStage"; private static final String KEY_UI_STAGE = "uiStage";
private static final String KEY_PATTERN_CHOICE = "chosenPattern"; private static final String KEY_PATTERN_CHOICE = "chosenPattern";
@@ -367,6 +368,9 @@ public class ChooseLockPattern extends SettingsActivity {
if (!(getActivity() instanceof ChooseLockPattern)) { if (!(getActivity() instanceof ChooseLockPattern)) {
throw new SecurityException("Fragment contained in wrong activity"); throw new SecurityException("Fragment contained in wrong activity");
} }
Intent intent = getActivity().getIntent();
// Only take this argument into account if it belongs to the current profile.
mUserId = Utils.getSameOwnerUserId(getActivity(), intent.getExtras());
} }
@Override @Override
@@ -415,7 +419,8 @@ public class ChooseLockPattern extends SettingsActivity {
boolean launchedConfirmationActivity = boolean launchedConfirmationActivity =
mChooseLockSettingsHelper.launchConfirmationActivity( mChooseLockSettingsHelper.launchConfirmationActivity(
CONFIRM_EXISTING_REQUEST, CONFIRM_EXISTING_REQUEST,
getString(R.string.unlock_set_unlock_launch_picker_title), true); getString(R.string.unlock_set_unlock_launch_picker_title), true,
mUserId);
if (!launchedConfirmationActivity) { if (!launchedConfirmationActivity) {
updateStage(Stage.Introduction); updateStage(Stage.Introduction);
} }
@@ -644,7 +649,7 @@ public class ChooseLockPattern extends SettingsActivity {
final boolean required = getActivity().getIntent().getBooleanExtra( final boolean required = getActivity().getIntent().getBooleanExtra(
EncryptionInterstitial.EXTRA_REQUIRE_PASSWORD, true); EncryptionInterstitial.EXTRA_REQUIRE_PASSWORD, true);
mSaveAndFinishWorker.start(mChooseLockSettingsHelper.utils(), required, mSaveAndFinishWorker.start(mChooseLockSettingsHelper.utils(), required,
mHasChallenge, mChallenge, mChosenPattern, mCurrentPattern); mHasChallenge, mChallenge, mChosenPattern, mCurrentPattern, mUserId);
} }
@Override @Override
@@ -666,16 +671,18 @@ public class ChooseLockPattern extends SettingsActivity {
private List<LockPatternView.Cell> mChosenPattern; private List<LockPatternView.Cell> mChosenPattern;
private String mCurrentPattern; private String mCurrentPattern;
private boolean mLockVirgin; private boolean mLockVirgin;
private int mUserId;
public void start(LockPatternUtils utils, boolean credentialRequired, public void start(LockPatternUtils utils, boolean credentialRequired,
boolean hasChallenge, long challenge, boolean hasChallenge, long challenge,
List<LockPatternView.Cell> chosenPattern, String currentPattern) { List<LockPatternView.Cell> chosenPattern, String currentPattern, int userId) {
prepare(utils, credentialRequired, hasChallenge, challenge); prepare(utils, credentialRequired, hasChallenge, challenge);
mCurrentPattern = currentPattern; mCurrentPattern = currentPattern;
mChosenPattern = chosenPattern; mChosenPattern = chosenPattern;
mUserId = userId;
mLockVirgin = !mUtils.isPatternEverChosen(UserHandle.myUserId()); mLockVirgin = !mUtils.isPatternEverChosen(mUserId);
start(); start();
} }
@@ -683,7 +690,7 @@ public class ChooseLockPattern extends SettingsActivity {
@Override @Override
protected Intent saveAndVerifyInBackground() { protected Intent saveAndVerifyInBackground() {
Intent result = null; Intent result = null;
final int userId = UserHandle.myUserId(); final int userId = mUserId;
mUtils.saveLockPattern(mChosenPattern, mCurrentPattern, userId); mUtils.saveLockPattern(mChosenPattern, mCurrentPattern, userId);
if (mHasChallenge) { if (mHasChallenge) {
@@ -708,7 +715,7 @@ public class ChooseLockPattern extends SettingsActivity {
@Override @Override
protected void finish(Intent resultData) { protected void finish(Intent resultData) {
if (mLockVirgin) { if (mLockVirgin) {
mUtils.setVisiblePatternEnabled(true, UserHandle.myUserId()); mUtils.setVisiblePatternEnabled(true, mUserId);
} }
super.finish(resultData); super.finish(resultData);

View File

@@ -76,6 +76,22 @@ public final class ChooseLockSettingsHelper {
return launchConfirmationActivity(request, title, null, null, returnCredentials, false); 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. * 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, @Nullable CharSequence header, @Nullable CharSequence description,
boolean returnCredentials, boolean external) { boolean returnCredentials, boolean external) {
return launchConfirmationActivity(request, title, header, description, 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, @Nullable CharSequence header, @Nullable CharSequence description,
long challenge) { long challenge) {
return launchConfirmationActivity(request, title, header, description, 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, private boolean launchConfirmationActivity(int request, @Nullable CharSequence title,
@Nullable CharSequence header, @Nullable CharSequence description, @Nullable CharSequence header, @Nullable CharSequence description,
boolean returnCredentials, boolean external, boolean hasChallenge, boolean returnCredentials, boolean external, boolean hasChallenge,
long challenge) { long challenge, int effectiveUserId) {
boolean launched = false; boolean launched = false;
int effectiveUserId = Utils.getEffectiveUserId(mActivity);
switch (mLockPatternUtils.getKeyguardStoredPasswordQuality(effectiveUserId)) { switch (mLockPatternUtils.getKeyguardStoredPasswordQuality(effectiveUserId)) {
case DevicePolicyManager.PASSWORD_QUALITY_SOMETHING: case DevicePolicyManager.PASSWORD_QUALITY_SOMETHING:
launched = launchConfirmationActivity(request, title, header, description, launched = launchConfirmationActivity(request, title, header, description,
returnCredentials || hasChallenge returnCredentials || hasChallenge
? ConfirmLockPattern.InternalActivity.class ? ConfirmLockPattern.InternalActivity.class
: ConfirmLockPattern.class, external, : ConfirmLockPattern.class, external,
hasChallenge, challenge); hasChallenge, challenge, effectiveUserId);
break; break;
case DevicePolicyManager.PASSWORD_QUALITY_NUMERIC: case DevicePolicyManager.PASSWORD_QUALITY_NUMERIC:
case DevicePolicyManager.PASSWORD_QUALITY_NUMERIC_COMPLEX: case DevicePolicyManager.PASSWORD_QUALITY_NUMERIC_COMPLEX:
@@ -137,7 +151,7 @@ public final class ChooseLockSettingsHelper {
returnCredentials || hasChallenge returnCredentials || hasChallenge
? ConfirmLockPassword.InternalActivity.class ? ConfirmLockPassword.InternalActivity.class
: ConfirmLockPassword.class, external, : ConfirmLockPassword.class, external,
hasChallenge, challenge); hasChallenge, challenge, effectiveUserId);
break; break;
} }
return launched; return launched;
@@ -145,7 +159,7 @@ public final class ChooseLockSettingsHelper {
private boolean launchConfirmationActivity(int request, CharSequence title, CharSequence header, private boolean launchConfirmationActivity(int request, CharSequence title, CharSequence header,
CharSequence message, Class<?> activityClass, boolean external, boolean hasChallenge, CharSequence message, Class<?> activityClass, boolean external, boolean hasChallenge,
long challenge) { long challenge, int userId) {
final Intent intent = new Intent(); final Intent intent = new Intent();
intent.putExtra(ConfirmDeviceCredentialBaseFragment.TITLE_TEXT, title); intent.putExtra(ConfirmDeviceCredentialBaseFragment.TITLE_TEXT, title);
intent.putExtra(ConfirmDeviceCredentialBaseFragment.HEADER_TEXT, header); intent.putExtra(ConfirmDeviceCredentialBaseFragment.HEADER_TEXT, header);
@@ -156,6 +170,7 @@ public final class ChooseLockSettingsHelper {
intent.putExtra(ConfirmDeviceCredentialBaseFragment.SHOW_WHEN_LOCKED, external); intent.putExtra(ConfirmDeviceCredentialBaseFragment.SHOW_WHEN_LOCKED, external);
intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_HAS_CHALLENGE, hasChallenge); intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_HAS_CHALLENGE, hasChallenge);
intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE, challenge); intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE, challenge);
intent.putExtra(ChooseLockGeneric.KEY_USER_ID, userId);
intent.setClassName(ConfirmDeviceCredentialBaseFragment.PACKAGE, activityClass.getName()); intent.setClassName(ConfirmDeviceCredentialBaseFragment.PACKAGE, activityClass.getName());
if (external) { if (external) {
intent.addFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT); intent.addFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT);

View File

@@ -108,7 +108,9 @@ public class ConfirmLockPassword extends ConfirmDeviceCredentialBaseActivity {
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
mLockPatternUtils = new LockPatternUtils(getActivity()); mLockPatternUtils = new LockPatternUtils(getActivity());
mEffectiveUserId = Utils.getEffectiveUserId(getActivity()); Intent intent = getActivity().getIntent();
// Only take this argument into account if it belongs to the current profile.
mEffectiveUserId = Utils.getSameOwnerUserId(getActivity(), intent.getExtras());
} }
@Override @Override

View File

@@ -113,7 +113,9 @@ public class ConfirmLockPattern extends ConfirmDeviceCredentialBaseActivity {
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
mLockPatternUtils = new LockPatternUtils(getActivity()); mLockPatternUtils = new LockPatternUtils(getActivity());
mEffectiveUserId = Utils.getEffectiveUserId(getActivity()); Intent intent = getActivity().getIntent();
// Only take this argument into account if it belongs to the current profile.
mEffectiveUserId = Utils.getSameOwnerUserId(getActivity(), intent.getExtras());
} }
@Override @Override

View File

@@ -120,7 +120,7 @@ public class SetupChooseLockGeneric extends ChooseLockGeneric {
@Override @Override
protected Intent getLockPasswordIntent(Context context, int quality, protected Intent getLockPasswordIntent(Context context, int quality,
int minLength, final int maxLength, int minLength, final int maxLength,
boolean requirePasswordToDecrypt, boolean confirmCredentials) { boolean requirePasswordToDecrypt, boolean confirmCredentials, int userId) {
final Intent intent = SetupChooseLockPassword.createIntent(context, quality, minLength, final Intent intent = SetupChooseLockPassword.createIntent(context, quality, minLength,
maxLength, requirePasswordToDecrypt, confirmCredentials); maxLength, requirePasswordToDecrypt, confirmCredentials);
SetupWizardUtils.copySetupExtras(getActivity().getIntent(), intent); SetupWizardUtils.copySetupExtras(getActivity().getIntent(), intent);
@@ -130,7 +130,7 @@ public class SetupChooseLockGeneric extends ChooseLockGeneric {
@Override @Override
protected Intent getLockPasswordIntent(Context context, int quality, protected Intent getLockPasswordIntent(Context context, int quality,
int minLength, final int maxLength, int minLength, final int maxLength,
boolean requirePasswordToDecrypt, long challenge) { boolean requirePasswordToDecrypt, long challenge, int userId) {
final Intent intent = SetupChooseLockPassword.createIntent(context, quality, minLength, final Intent intent = SetupChooseLockPassword.createIntent(context, quality, minLength,
maxLength, requirePasswordToDecrypt, challenge); maxLength, requirePasswordToDecrypt, challenge);
SetupWizardUtils.copySetupExtras(getActivity().getIntent(), intent); SetupWizardUtils.copySetupExtras(getActivity().getIntent(), intent);
@@ -139,7 +139,7 @@ public class SetupChooseLockGeneric extends ChooseLockGeneric {
@Override @Override
protected Intent getLockPasswordIntent(Context context, int quality, int minLength, protected Intent getLockPasswordIntent(Context context, int quality, int minLength,
final int maxLength, boolean requirePasswordToDecrypt, String password) { int maxLength, boolean requirePasswordToDecrypt, String password, int userId) {
final Intent intent = SetupChooseLockPassword.createIntent(context, quality, minLength, final Intent intent = SetupChooseLockPassword.createIntent(context, quality, minLength,
maxLength, requirePasswordToDecrypt, password); maxLength, requirePasswordToDecrypt, password);
SetupWizardUtils.copySetupExtras(getActivity().getIntent(), intent); SetupWizardUtils.copySetupExtras(getActivity().getIntent(), intent);
@@ -148,7 +148,7 @@ public class SetupChooseLockGeneric extends ChooseLockGeneric {
@Override @Override
protected Intent getLockPatternIntent(Context context, final boolean requirePassword, protected Intent getLockPatternIntent(Context context, final boolean requirePassword,
final boolean confirmCredentials) { final boolean confirmCredentials, int userId) {
final Intent intent = SetupChooseLockPattern.createIntent(context, requirePassword, final Intent intent = SetupChooseLockPattern.createIntent(context, requirePassword,
confirmCredentials); confirmCredentials);
SetupWizardUtils.copySetupExtras(getActivity().getIntent(), intent); SetupWizardUtils.copySetupExtras(getActivity().getIntent(), intent);
@@ -157,7 +157,7 @@ public class SetupChooseLockGeneric extends ChooseLockGeneric {
@Override @Override
protected Intent getLockPatternIntent(Context context, final boolean requirePassword, protected Intent getLockPatternIntent(Context context, final boolean requirePassword,
long challenge) { long challenge, int userId) {
final Intent intent = SetupChooseLockPattern.createIntent(context, requirePassword, final Intent intent = SetupChooseLockPattern.createIntent(context, requirePassword,
challenge); challenge);
SetupWizardUtils.copySetupExtras(getActivity().getIntent(), intent); SetupWizardUtils.copySetupExtras(getActivity().getIntent(), intent);
@@ -166,7 +166,7 @@ public class SetupChooseLockGeneric extends ChooseLockGeneric {
@Override @Override
protected Intent getLockPatternIntent(Context context, final boolean requirePassword, protected Intent getLockPatternIntent(Context context, final boolean requirePassword,
final String pattern) { final String pattern, int userId) {
final Intent intent = SetupChooseLockPattern.createIntent(context, requirePassword, final Intent intent = SetupChooseLockPattern.createIntent(context, requirePassword,
pattern); pattern);
SetupWizardUtils.copySetupExtras(getActivity().getIntent(), intent); SetupWizardUtils.copySetupExtras(getActivity().getIntent(), intent);

View File

@@ -22,6 +22,7 @@ import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.res.Resources; import android.content.res.Resources;
import android.os.Bundle; import android.os.Bundle;
import android.os.UserHandle;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
@@ -42,19 +43,21 @@ public class SetupChooseLockPattern extends ChooseLockPattern {
public static Intent createIntent(Context context, boolean requirePassword, public static Intent createIntent(Context context, boolean requirePassword,
boolean confirmCredentials) { boolean confirmCredentials) {
Intent intent = ChooseLockPattern.createIntent(context, requirePassword, Intent intent = ChooseLockPattern.createIntent(context, requirePassword,
confirmCredentials); confirmCredentials, UserHandle.myUserId());
intent.setClass(context, SetupChooseLockPattern.class); intent.setClass(context, SetupChooseLockPattern.class);
return intent; return intent;
} }
public static Intent createIntent(Context context, boolean requirePassword, String pattern) { public static Intent createIntent(Context context, boolean requirePassword, String pattern) {
Intent intent = ChooseLockPattern.createIntent(context, requirePassword, pattern); Intent intent = ChooseLockPattern.createIntent(
context, requirePassword, pattern, UserHandle.myUserId());
intent.setClass(context, SetupChooseLockPattern.class); intent.setClass(context, SetupChooseLockPattern.class);
return intent; return intent;
} }
public static Intent createIntent(Context context, boolean requirePassword, long challenge) { public static Intent createIntent(Context context, boolean requirePassword, long challenge) {
Intent intent = ChooseLockPattern.createIntent(context, requirePassword, challenge); Intent intent = ChooseLockPattern.createIntent(
context, requirePassword, challenge, UserHandle.myUserId());
intent.setClass(context, SetupChooseLockPattern.class); intent.setClass(context, SetupChooseLockPattern.class);
return intent; return intent;
} }

View File

@@ -1165,6 +1165,38 @@ public final class Utils {
return str; return str;
} }
/**
* Returns the user id present in the bundle with {@link ChooseLockGeneric#KEY_USER_ID} if it
* belongs to the current user.
*
* @throws SecurityException if the given userId does not belong to the current user group.
*/
public static int getSameOwnerUserId(Context context, Bundle bundle) {
if (bundle == null) {
return getEffectiveUserId(context);
}
int userId = bundle.getInt(ChooseLockGeneric.KEY_USER_ID, UserHandle.myUserId());
return getSameOwnerUserId(context, userId);
}
/**
* Returns the given user id if it belongs to the current user.
*
* @throws SecurityException if the given userId does not belong to the current user group.
*/
public static int getSameOwnerUserId(Context context, int userId) {
UserManager um = UserManager.get(context);
if (um != null) {
if (um.getUserProfiles().contains(new UserHandle(userId))) {
return userId;
} else {
throw new SecurityException("Given user id " + userId + " does not belong to user "
+ UserHandle.myUserId());
}
}
return getEffectiveUserId(context);
}
public static int getEffectiveUserId(Context context) { public static int getEffectiveUserId(Context context) {
UserManager um = UserManager.get(context); UserManager um = UserManager.get(context);
if (um != null) { if (um != null) {