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

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;
}

View File

@@ -73,25 +73,25 @@ public class ChooseLockPattern extends SettingsActivity {
}
public static Intent createIntent(Context context,
boolean requirePassword, boolean confirmCredentials) {
boolean requirePassword, boolean confirmCredentials, int userId) {
Intent intent = new Intent(context, ChooseLockPattern.class);
intent.putExtra("key_lock_method", "pattern");
intent.putExtra(ChooseLockGeneric.CONFIRM_CREDENTIALS, confirmCredentials);
intent.putExtra(EncryptionInterstitial.EXTRA_REQUIRE_PASSWORD, requirePassword);
intent.putExtra(ChooseLockGeneric.KEY_USER_ID, userId);
return intent;
}
public static Intent createIntent(Context context,
boolean requirePassword, String pattern) {
Intent intent = createIntent(context, requirePassword, false);
boolean requirePassword, String pattern, int userId) {
Intent intent = createIntent(context, requirePassword, false, userId);
intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_PASSWORD, pattern);
return intent;
}
public static Intent createIntent(Context context,
boolean requirePassword, long challenge) {
Intent intent = createIntent(context, requirePassword, false);
boolean requirePassword, long challenge, int userId) {
Intent intent = createIntent(context, requirePassword, false, userId);
intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_HAS_CHALLENGE, true);
intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE, challenge);
return intent;
@@ -355,6 +355,7 @@ public class ChooseLockPattern extends SettingsActivity {
private ChooseLockSettingsHelper mChooseLockSettingsHelper;
private SaveAndFinishWorker mSaveAndFinishWorker;
private int mUserId;
private static final String KEY_UI_STAGE = "uiStage";
private static final String KEY_PATTERN_CHOICE = "chosenPattern";
@@ -367,6 +368,9 @@ public class ChooseLockPattern extends SettingsActivity {
if (!(getActivity() instanceof ChooseLockPattern)) {
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
@@ -415,7 +419,8 @@ public class ChooseLockPattern extends SettingsActivity {
boolean launchedConfirmationActivity =
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);
if (!launchedConfirmationActivity) {
updateStage(Stage.Introduction);
}
@@ -644,7 +649,7 @@ public class ChooseLockPattern extends SettingsActivity {
final boolean required = getActivity().getIntent().getBooleanExtra(
EncryptionInterstitial.EXTRA_REQUIRE_PASSWORD, true);
mSaveAndFinishWorker.start(mChooseLockSettingsHelper.utils(), required,
mHasChallenge, mChallenge, mChosenPattern, mCurrentPattern);
mHasChallenge, mChallenge, mChosenPattern, mCurrentPattern, mUserId);
}
@Override
@@ -666,16 +671,18 @@ public class ChooseLockPattern extends SettingsActivity {
private List<LockPatternView.Cell> mChosenPattern;
private String mCurrentPattern;
private boolean mLockVirgin;
private int mUserId;
public void start(LockPatternUtils utils, boolean credentialRequired,
boolean hasChallenge, long challenge,
List<LockPatternView.Cell> chosenPattern, String currentPattern) {
List<LockPatternView.Cell> chosenPattern, String currentPattern, int userId) {
prepare(utils, credentialRequired, hasChallenge, challenge);
mCurrentPattern = currentPattern;
mChosenPattern = chosenPattern;
mUserId = userId;
mLockVirgin = !mUtils.isPatternEverChosen(UserHandle.myUserId());
mLockVirgin = !mUtils.isPatternEverChosen(mUserId);
start();
}
@@ -683,7 +690,7 @@ public class ChooseLockPattern extends SettingsActivity {
@Override
protected Intent saveAndVerifyInBackground() {
Intent result = null;
final int userId = UserHandle.myUserId();
final int userId = mUserId;
mUtils.saveLockPattern(mChosenPattern, mCurrentPattern, userId);
if (mHasChallenge) {
@@ -708,7 +715,7 @@ public class ChooseLockPattern extends SettingsActivity {
@Override
protected void finish(Intent resultData) {
if (mLockVirgin) {
mUtils.setVisiblePatternEnabled(true, UserHandle.myUserId());
mUtils.setVisiblePatternEnabled(true, mUserId);
}
super.finish(resultData);

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);

View File

@@ -108,7 +108,9 @@ public class ConfirmLockPassword extends ConfirmDeviceCredentialBaseActivity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
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

View File

@@ -113,7 +113,9 @@ public class ConfirmLockPattern extends ConfirmDeviceCredentialBaseActivity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
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

View File

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

View File

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

View File

@@ -1165,6 +1165,38 @@ public final class Utils {
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) {
UserManager um = UserManager.get(context);
if (um != null) {