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() {
private String mUserPassword;
private LockPatternUtils mLockPatternUtils;
private FingerprintManager mFingerprintManager;
+ private int mUserId;
private RemovalCallback mRemovalCallback = new RemovalCallback() {
@Override
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 {
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);
}
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:
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,
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 {
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
}
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,
requirePasswordToDecrypt, false);
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,
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;
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) {
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());
}
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
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);
}
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
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();
}
@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;
}
}
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;
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";
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
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);
}
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
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();
}
@Override
protected Intent saveAndVerifyInBackground() {
Intent result = null;
- final int userId = UserHandle.myUserId();
+ final int userId = mUserId;
mUtils.saveLockPattern(mChosenPattern, mCurrentPattern, userId);
if (mHasChallenge) {
@Override
protected void finish(Intent resultData) {
if (mLockVirgin) {
- mUtils.setVisiblePatternEnabled(true, UserHandle.myUserId());
+ mUtils.setVisiblePatternEnabled(true, mUserId);
}
super.finish(resultData);
* 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.
+ *
+ * @param title title of the confirmation screen; shown in the action bar
* @param header header of the confirmation screen; shown as large text
* @param description description of the confirmation screen
* @param returnCredentials if true, put credentials into intent. Note that if this is true,
@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));
}
/**
@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:
returnCredentials || hasChallenge
? ConfirmLockPassword.InternalActivity.class
: ConfirmLockPassword.class, external,
- hasChallenge, challenge);
+ hasChallenge, challenge, effectiveUserId);
break;
}
return launched;
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);
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);
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
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
@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);
@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);
@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);
@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);
@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);
@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);
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;
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;
}
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) {