Merge "1/n: Make ChooseLockSettingsHelper into a builder"
This commit is contained in:
@@ -139,8 +139,11 @@ public class MasterClear extends InstrumentedFragment implements OnGlobalLayoutL
|
||||
*/
|
||||
private boolean runKeyguardConfirmation(int request) {
|
||||
Resources res = getActivity().getResources();
|
||||
return new ChooseLockSettingsHelper(getActivity(), this).launchConfirmationActivity(
|
||||
request, res.getText(R.string.master_clear_short_title));
|
||||
final ChooseLockSettingsHelper.Builder builder =
|
||||
new ChooseLockSettingsHelper.Builder(getActivity(), this);
|
||||
return builder.setRequestCode(request)
|
||||
.setTitle(res.getText(R.string.master_clear_short_title))
|
||||
.show();
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
|
@@ -92,8 +92,11 @@ public class ResetNetwork extends InstrumentedFragment {
|
||||
*/
|
||||
private boolean runKeyguardConfirmation(int request) {
|
||||
Resources res = getActivity().getResources();
|
||||
return new ChooseLockSettingsHelper(getActivity(), this).launchConfirmationActivity(
|
||||
request, res.getText(R.string.reset_network_title));
|
||||
final ChooseLockSettingsHelper.Builder builder =
|
||||
new ChooseLockSettingsHelper.Builder(getActivity(), this);
|
||||
return builder.setRequestCode(request)
|
||||
.setTitle(res.getText(R.string.reset_network_title))
|
||||
.show();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -634,7 +634,7 @@ public final class Utils extends com.android.settingslib.Utils {
|
||||
*
|
||||
* @param isInternal indicating if the caller is "internal" to the system,
|
||||
* meaning we're willing to trust extras like
|
||||
* {@link ChooseLockSettingsHelper#EXTRA_ALLOW_ANY_USER}.
|
||||
* {@link ChooseLockSettingsHelper#EXTRA_KEY_ALLOW_ANY_USER}.
|
||||
* @throws SecurityException if the given userId does not belong to the
|
||||
* current user group.
|
||||
*/
|
||||
@@ -643,7 +643,7 @@ public final class Utils extends com.android.settingslib.Utils {
|
||||
return getCredentialOwnerUserId(context);
|
||||
}
|
||||
final boolean allowAnyUser = isInternal
|
||||
&& bundle.getBoolean(ChooseLockSettingsHelper.EXTRA_ALLOW_ANY_USER, false);
|
||||
&& bundle.getBoolean(ChooseLockSettingsHelper.EXTRA_KEY_ALLOW_ANY_USER, false);
|
||||
final int userId = bundle.getInt(Intent.EXTRA_USER_ID, UserHandle.myUserId());
|
||||
if (userId == LockPatternUtils.USER_FRP) {
|
||||
return allowAnyUser ? userId : enforceSystemUser(context, userId);
|
||||
|
@@ -163,11 +163,13 @@ public class AddAccountSettings extends Activity {
|
||||
} else {
|
||||
// If the user is locked by fbe: we couldn't start the authenticator. So we must ask the
|
||||
// user to unlock it first.
|
||||
ChooseLockSettingsHelper helper = new ChooseLockSettingsHelper(this);
|
||||
if (!helper.launchConfirmationActivity(UNLOCK_WORK_PROFILE_REQUEST,
|
||||
getString(R.string.unlock_set_unlock_launch_picker_title),
|
||||
false,
|
||||
mUserHandle.getIdentifier())) {
|
||||
final ChooseLockSettingsHelper.Builder builder =
|
||||
new ChooseLockSettingsHelper.Builder(this);
|
||||
final boolean launched = builder.setRequestCode(UNLOCK_WORK_PROFILE_REQUEST)
|
||||
.setTitle(getString(R.string.unlock_set_unlock_launch_picker_title))
|
||||
.setUserId(mUserHandle.getIdentifier())
|
||||
.show();
|
||||
if (!launched) {
|
||||
requestChooseAccount();
|
||||
}
|
||||
}
|
||||
|
@@ -39,9 +39,11 @@ public class ConvertToFbe extends InstrumentedFragment {
|
||||
|
||||
private boolean runKeyguardConfirmation(int request) {
|
||||
Resources res = getActivity().getResources();
|
||||
return new ChooseLockSettingsHelper(getActivity(), this)
|
||||
.launchConfirmationActivity(request,
|
||||
res.getText(R.string.convert_to_file_encryption));
|
||||
final ChooseLockSettingsHelper.Builder builder =
|
||||
new ChooseLockSettingsHelper.Builder(getActivity(), this);
|
||||
return builder.setRequestCode(request)
|
||||
.setTitle(res.getText(R.string.convert_to_file_encryption))
|
||||
.show();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -181,18 +181,19 @@ public abstract class BiometricEnrollBase extends InstrumentedActivity {
|
||||
}
|
||||
|
||||
protected void launchConfirmLock(int titleResId, long challenge) {
|
||||
ChooseLockSettingsHelper helper = new ChooseLockSettingsHelper(this);
|
||||
boolean launchedConfirmationActivity;
|
||||
if (mUserId == UserHandle.USER_NULL) {
|
||||
launchedConfirmationActivity = helper.launchConfirmationActivity(CONFIRM_REQUEST,
|
||||
getString(titleResId),
|
||||
null, null, challenge, true /* foregroundOnly */);
|
||||
} else {
|
||||
launchedConfirmationActivity = helper.launchConfirmationActivity(CONFIRM_REQUEST,
|
||||
getString(titleResId),
|
||||
null, null, challenge, mUserId, true /* foregroundOnly */);
|
||||
final ChooseLockSettingsHelper.Builder builder = new ChooseLockSettingsHelper.Builder(this);
|
||||
builder.setRequestCode(CONFIRM_REQUEST)
|
||||
.setTitle(getString(titleResId))
|
||||
.setChallenge(challenge)
|
||||
.setForegroundOnly(true)
|
||||
.setReturnCredentials(true);
|
||||
|
||||
if (mUserId != UserHandle.USER_NULL) {
|
||||
builder.setUserId(mUserId);
|
||||
}
|
||||
if (!launchedConfirmationActivity) {
|
||||
|
||||
final boolean launched = builder.show();
|
||||
if (!launched) {
|
||||
// This shouldn't happen, as we should only end up at this step if a lock thingy is
|
||||
// already set.
|
||||
finish();
|
||||
|
@@ -184,7 +184,7 @@ public abstract class BiometricEnrollIntroduction extends BiometricEnrollBase
|
||||
}
|
||||
|
||||
private void updatePasswordQuality() {
|
||||
final int passwordQuality = new ChooseLockSettingsHelper(this).utils()
|
||||
final int passwordQuality = new LockPatternUtils(this)
|
||||
.getActivePasswordQuality(mUserManager.getCredentialOwnerProfile(mUserId));
|
||||
mHasPassword = passwordQuality != DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED;
|
||||
}
|
||||
|
@@ -206,12 +206,18 @@ public class FaceSettings extends DashboardFragment {
|
||||
// created while Keyguard is showing, in which case the resetLockout revokeChallenge
|
||||
// will invalidate the too-early created challenge here.
|
||||
final long challenge = mFaceManager.generateChallengeBlocking();
|
||||
ChooseLockSettingsHelper helper = new ChooseLockSettingsHelper(getActivity(), this);
|
||||
final ChooseLockSettingsHelper.Builder builder =
|
||||
new ChooseLockSettingsHelper.Builder(getActivity(), this);
|
||||
final boolean launched = builder.setRequestCode(CONFIRM_REQUEST)
|
||||
.setTitle(getString(R.string.security_settings_face_preference_title))
|
||||
.setChallenge(challenge)
|
||||
.setUserId(mUserId)
|
||||
.setForegroundOnly(true)
|
||||
.setReturnCredentials(true)
|
||||
.show();
|
||||
|
||||
mConfirmingPassword = true;
|
||||
if (!helper.launchConfirmationActivity(CONFIRM_REQUEST,
|
||||
getString(R.string.security_settings_face_preference_title),
|
||||
null, null, challenge, mUserId, true /* foregroundOnly */)) {
|
||||
if (!launched) {
|
||||
Log.e(TAG, "Password not set");
|
||||
finish();
|
||||
}
|
||||
|
@@ -634,12 +634,19 @@ public class FingerprintSettings extends SubSettings {
|
||||
}
|
||||
|
||||
private void launchChooseOrConfirmLock() {
|
||||
Intent intent = new Intent();
|
||||
long challenge = mFingerprintManager.generateChallengeBlocking();
|
||||
ChooseLockSettingsHelper helper = new ChooseLockSettingsHelper(getActivity(), this);
|
||||
if (!helper.launchConfirmationActivity(CONFIRM_REQUEST,
|
||||
getString(R.string.security_settings_fingerprint_preference_title),
|
||||
null, null, challenge, mUserId, true /* foregroundOnly */)) {
|
||||
final Intent intent = new Intent();
|
||||
final long challenge = mFingerprintManager.generateChallengeBlocking();
|
||||
final ChooseLockSettingsHelper.Builder builder =
|
||||
new ChooseLockSettingsHelper.Builder(getActivity(), this);
|
||||
final boolean launched = builder.setRequestCode(CONFIRM_REQUEST)
|
||||
.setTitle(getString(R.string.security_settings_fingerprint_preference_title))
|
||||
.setChallenge(challenge)
|
||||
.setUserId(mUserId)
|
||||
.setForegroundOnly(true)
|
||||
.setReturnCredentials(true)
|
||||
.show();
|
||||
|
||||
if (!launched) {
|
||||
intent.setClassName(SETTINGS_PACKAGE_NAME, ChooseLockGeneric.class.getName());
|
||||
intent.putExtra(ChooseLockGeneric.ChooseLockGenericFragment.MINIMUM_QUALITY_KEY,
|
||||
DevicePolicyManager.PASSWORD_QUALITY_SOMETHING);
|
||||
|
@@ -52,8 +52,8 @@ public class OemUnlockPreferenceController extends DeveloperOptionsPreferenceCon
|
||||
private final OemLockManager mOemLockManager;
|
||||
private final UserManager mUserManager;
|
||||
private final TelephonyManager mTelephonyManager;
|
||||
private final Activity mActivity;
|
||||
private final DevelopmentSettingsDashboardFragment mFragment;
|
||||
private final ChooseLockSettingsHelper mChooseLockSettingsHelper;
|
||||
private RestrictedSwitchPreference mPreference;
|
||||
|
||||
public OemUnlockPreferenceController(Context context, Activity activity,
|
||||
@@ -69,12 +69,8 @@ public class OemUnlockPreferenceController extends DeveloperOptionsPreferenceCon
|
||||
}
|
||||
mUserManager = (UserManager) context.getSystemService(Context.USER_SERVICE);
|
||||
mTelephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
|
||||
mActivity = activity;
|
||||
mFragment = fragment;
|
||||
if (activity != null || mFragment != null) {
|
||||
mChooseLockSettingsHelper = new ChooseLockSettingsHelper(activity, mFragment);
|
||||
} else {
|
||||
mChooseLockSettingsHelper = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -204,8 +200,11 @@ public class OemUnlockPreferenceController extends DeveloperOptionsPreferenceCon
|
||||
|
||||
@VisibleForTesting
|
||||
boolean showKeyguardConfirmation(Resources resources, int requestCode) {
|
||||
return mChooseLockSettingsHelper.launchConfirmationActivity(
|
||||
requestCode, resources.getString(R.string.oem_unlock_enable));
|
||||
final ChooseLockSettingsHelper.Builder builder =
|
||||
new ChooseLockSettingsHelper.Builder(mActivity, mFragment);
|
||||
return builder.setRequestCode(requestCode)
|
||||
.setTitle(resources.getString(R.string.oem_unlock_enable))
|
||||
.show();
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
|
@@ -160,11 +160,16 @@ public class BuildNumberPreferenceController extends BasePreferenceController im
|
||||
if (mDevHitCountdown == 0 && !mProcessingLastDevHit) {
|
||||
// Add 1 count back, then start password confirmation flow.
|
||||
mDevHitCountdown++;
|
||||
final ChooseLockSettingsHelper helper =
|
||||
new ChooseLockSettingsHelper(mActivity, mFragment);
|
||||
mProcessingLastDevHit = helper.launchConfirmationActivity(
|
||||
REQUEST_CONFIRM_PASSWORD_FOR_DEV_PREF,
|
||||
mContext.getString(R.string.unlock_set_unlock_launch_picker_title));
|
||||
|
||||
final String title = mContext
|
||||
.getString(R.string.unlock_set_unlock_launch_picker_title);
|
||||
final ChooseLockSettingsHelper.Builder builder =
|
||||
new ChooseLockSettingsHelper.Builder(mActivity, mFragment);
|
||||
mProcessingLastDevHit = builder
|
||||
.setRequestCode(REQUEST_CONFIRM_PASSWORD_FOR_DEV_PREF)
|
||||
.setTitle(title)
|
||||
.show();
|
||||
|
||||
if (!mProcessingLastDevHit) {
|
||||
enableDevelopmentSettings();
|
||||
}
|
||||
|
@@ -103,8 +103,14 @@ public class StorageWizardMigrateConfirm extends StorageWizardBase {
|
||||
Log.d(TAG, "User " + user.id + " is currently locked; requesting unlock");
|
||||
final CharSequence description = TextUtils.expandTemplate(
|
||||
getText(R.string.storage_wizard_move_unlock), user.name);
|
||||
new ChooseLockSettingsHelper(this).launchConfirmationActivityForAnyUser(
|
||||
REQUEST_CREDENTIAL, null, null, description, user.id);
|
||||
final ChooseLockSettingsHelper.Builder builder =
|
||||
new ChooseLockSettingsHelper.Builder(this);
|
||||
builder.setRequestCode(REQUEST_CREDENTIAL)
|
||||
.setDescription(description)
|
||||
.setUserId(user.id)
|
||||
.setAllowAnyUserId(true)
|
||||
.setChallenge(0L)
|
||||
.show();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@@ -85,8 +85,14 @@ public class StorageWizardMoveConfirm extends StorageWizardBase {
|
||||
Log.d(TAG, "User " + user.id + " is currently locked; requesting unlock");
|
||||
final CharSequence description = TextUtils.expandTemplate(
|
||||
getText(R.string.storage_wizard_move_unlock), user.name);
|
||||
new ChooseLockSettingsHelper(this).launchConfirmationActivityForAnyUser(
|
||||
REQUEST_CREDENTIAL, null, null, description, user.id);
|
||||
final ChooseLockSettingsHelper.Builder builder =
|
||||
new ChooseLockSettingsHelper.Builder(this);
|
||||
builder.setRequestCode(REQUEST_CREDENTIAL)
|
||||
.setDescription(description)
|
||||
.setUserId(user.id)
|
||||
.setChallenge(0L)
|
||||
.setAllowAnyUserId(true)
|
||||
.show();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@@ -142,7 +142,7 @@ public class ChooseLockGeneric extends SettingsActivity {
|
||||
@VisibleForTesting
|
||||
static final int SKIP_FINGERPRINT_REQUEST = 104;
|
||||
|
||||
private ChooseLockSettingsHelper mChooseLockSettingsHelper;
|
||||
private LockPatternUtils mLockPatternUtils;
|
||||
private DevicePolicyManager mDpm;
|
||||
private boolean mHasChallenge = false;
|
||||
private long mChallenge;
|
||||
@@ -150,7 +150,6 @@ public class ChooseLockGeneric extends SettingsActivity {
|
||||
private boolean mWaitingForConfirmation = false;
|
||||
private boolean mForChangeCredRequiredForBoot = false;
|
||||
private LockscreenCredential mUserPassword;
|
||||
private LockPatternUtils mLockPatternUtils;
|
||||
private FingerprintManager mFingerprintManager;
|
||||
private FaceManager mFaceManager;
|
||||
private int mUserId;
|
||||
@@ -199,7 +198,6 @@ public class ChooseLockGeneric extends SettingsActivity {
|
||||
mFingerprintManager = Utils.getFingerprintManagerOrNull(activity);
|
||||
mFaceManager = Utils.getFaceManagerOrNull(activity);
|
||||
mDpm = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);
|
||||
mChooseLockSettingsHelper = new ChooseLockSettingsHelper(activity);
|
||||
mLockPatternUtils = new LockPatternUtils(activity);
|
||||
mIsSetNewPassword = ACTION_SET_NEW_PARENT_PROFILE_PASSWORD.equals(chooseLockAction)
|
||||
|| ACTION_SET_NEW_PASSWORD.equals(chooseLockAction);
|
||||
@@ -274,15 +272,17 @@ public class ChooseLockGeneric extends SettingsActivity {
|
||||
mUserId), false);
|
||||
}
|
||||
} else if (!mWaitingForConfirmation) {
|
||||
ChooseLockSettingsHelper helper =
|
||||
new ChooseLockSettingsHelper(activity, this);
|
||||
final ChooseLockSettingsHelper.Builder builder =
|
||||
new ChooseLockSettingsHelper.Builder(activity, this);
|
||||
builder.setRequestCode(CONFIRM_EXISTING_REQUEST)
|
||||
.setTitle(getString(R.string.unlock_set_unlock_launch_picker_title))
|
||||
.setReturnCredentials(true)
|
||||
.setUserId(mUserId);
|
||||
boolean managedProfileWithUnifiedLock =
|
||||
UserManager.get(activity).isManagedProfile(mUserId)
|
||||
&& !mLockPatternUtils.isSeparateProfileChallengeEnabled(mUserId);
|
||||
boolean skipConfirmation = managedProfileWithUnifiedLock && !mIsSetNewPassword;
|
||||
if (skipConfirmation
|
||||
|| !helper.launchConfirmationActivity(CONFIRM_EXISTING_REQUEST,
|
||||
getString(R.string.unlock_set_unlock_launch_picker_title), true, mUserId)) {
|
||||
if (skipConfirmation || !builder.show()) {
|
||||
mPasswordConfirmed = true; // no password set, so no need to confirm
|
||||
updatePreferencesOrFinish(savedInstanceState != null);
|
||||
} else {
|
||||
@@ -797,10 +797,10 @@ public class ChooseLockGeneric extends SettingsActivity {
|
||||
if (mUserPassword != null) {
|
||||
// No need to call setLockCredential if the user currently doesn't
|
||||
// have a password
|
||||
mChooseLockSettingsHelper.utils().setLockCredential(
|
||||
mLockPatternUtils.setLockCredential(
|
||||
LockscreenCredential.createNone(), mUserPassword, mUserId);
|
||||
}
|
||||
mChooseLockSettingsHelper.utils().setLockScreenDisabled(disabled, mUserId);
|
||||
mLockPatternUtils.setLockScreenDisabled(disabled, mUserId);
|
||||
getActivity().setResult(Activity.RESULT_OK);
|
||||
finish();
|
||||
}
|
||||
|
@@ -228,7 +228,6 @@ public class ChooseLockPassword extends SettingsActivity {
|
||||
private LockPatternUtils mLockPatternUtils;
|
||||
private SaveAndFinishWorker mSaveAndFinishWorker;
|
||||
private int mRequestedQuality = DevicePolicyManager.PASSWORD_QUALITY_NUMERIC;
|
||||
private ChooseLockSettingsHelper mChooseLockSettingsHelper;
|
||||
protected Stage mUiStage = Stage.Introduction;
|
||||
private PasswordRequirementAdapter mPasswordRequirementAdapter;
|
||||
private GlifLayout mLayout;
|
||||
@@ -396,8 +395,6 @@ public class ChooseLockPassword extends SettingsActivity {
|
||||
mLockPatternUtils.getRequestedPasswordMetrics(mUnificationProfileId));
|
||||
}
|
||||
|
||||
mChooseLockSettingsHelper = new ChooseLockSettingsHelper(getActivity());
|
||||
|
||||
if (intent.getBooleanExtra(
|
||||
ChooseLockSettingsHelper.EXTRA_KEY_FOR_CHANGE_CRED_REQUIRED_FOR_BOOT, false)) {
|
||||
SaveAndFinishWorker w = new SaveAndFinishWorker();
|
||||
@@ -406,10 +403,11 @@ public class ChooseLockPassword extends SettingsActivity {
|
||||
LockscreenCredential currentCredential = intent.getParcelableExtra(
|
||||
ChooseLockSettingsHelper.EXTRA_KEY_PASSWORD);
|
||||
|
||||
final LockPatternUtils utils = new LockPatternUtils(getActivity());
|
||||
|
||||
w.setBlocking(true);
|
||||
w.setListener(this);
|
||||
w.start(mChooseLockSettingsHelper.utils(), required, false, 0,
|
||||
currentCredential, currentCredential, mUserId);
|
||||
w.start(utils, required, false, 0, currentCredential, currentCredential, mUserId);
|
||||
}
|
||||
mTextChangedHandler = new TextChangedHandler();
|
||||
}
|
||||
@@ -499,9 +497,13 @@ public class ChooseLockPassword extends SettingsActivity {
|
||||
if (savedInstanceState == null) {
|
||||
updateStage(Stage.Introduction);
|
||||
if (confirmCredentials) {
|
||||
mChooseLockSettingsHelper.launchConfirmationActivity(CONFIRM_EXISTING_REQUEST,
|
||||
getString(R.string.unlock_set_unlock_launch_picker_title), true,
|
||||
mUserId);
|
||||
final ChooseLockSettingsHelper.Builder builder =
|
||||
new ChooseLockSettingsHelper.Builder(getActivity());
|
||||
builder.setRequestCode(CONFIRM_EXISTING_REQUEST)
|
||||
.setTitle(getString(R.string.unlock_set_unlock_launch_picker_title))
|
||||
.setReturnCredentials(true)
|
||||
.setUserId(mUserId)
|
||||
.show();
|
||||
}
|
||||
} else {
|
||||
|
||||
|
@@ -452,7 +452,7 @@ public class ChooseLockPattern extends SettingsActivity {
|
||||
}
|
||||
};
|
||||
|
||||
private ChooseLockSettingsHelper mChooseLockSettingsHelper;
|
||||
private LockPatternUtils mLockPatternUtils;
|
||||
private SaveAndFinishWorker mSaveAndFinishWorker;
|
||||
protected int mUserId;
|
||||
protected boolean mForFingerprint;
|
||||
@@ -465,7 +465,6 @@ public class ChooseLockPattern extends SettingsActivity {
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
mChooseLockSettingsHelper = new ChooseLockSettingsHelper(getActivity());
|
||||
if (!(getActivity() instanceof ChooseLockPattern)) {
|
||||
throw new SecurityException("Fragment contained in wrong activity");
|
||||
}
|
||||
@@ -473,6 +472,8 @@ public class ChooseLockPattern extends SettingsActivity {
|
||||
// Only take this argument into account if it belongs to the current profile.
|
||||
mUserId = Utils.getUserIdFromBundle(getActivity(), intent.getExtras());
|
||||
|
||||
mLockPatternUtils = new LockPatternUtils(getActivity());
|
||||
|
||||
if (intent.getBooleanExtra(
|
||||
ChooseLockSettingsHelper.EXTRA_KEY_FOR_CHANGE_CRED_REQUIRED_FOR_BOOT, false)) {
|
||||
SaveAndFinishWorker w = new SaveAndFinishWorker();
|
||||
@@ -482,8 +483,7 @@ public class ChooseLockPattern extends SettingsActivity {
|
||||
ChooseLockSettingsHelper.EXTRA_KEY_PASSWORD);
|
||||
w.setBlocking(true);
|
||||
w.setListener(this);
|
||||
w.start(mChooseLockSettingsHelper.utils(), required,
|
||||
false, 0, current, current, mUserId);
|
||||
w.start(mLockPatternUtils, required, false, 0, current, current, mUserId);
|
||||
}
|
||||
mForFingerprint = intent.getBooleanExtra(
|
||||
ChooseLockSettingsHelper.EXTRA_KEY_FOR_FINGERPRINT, false);
|
||||
@@ -543,7 +543,7 @@ public class ChooseLockPattern extends SettingsActivity {
|
||||
mLockPatternView = (LockPatternView) view.findViewById(R.id.lockPattern);
|
||||
mLockPatternView.setOnPatternListener(mChooseNewLockPatternListener);
|
||||
mLockPatternView.setTactileFeedbackEnabled(
|
||||
mChooseLockSettingsHelper.utils().isTactileFeedbackEnabled());
|
||||
mLockPatternUtils.isTactileFeedbackEnabled());
|
||||
mLockPatternView.setFadePattern(false);
|
||||
|
||||
mFooterText = (TextView) view.findViewById(R.id.footerText);
|
||||
@@ -572,12 +572,16 @@ public class ChooseLockPattern extends SettingsActivity {
|
||||
// first launch. As a security measure, we're in NeedToConfirm mode until we
|
||||
// know there isn't an existing password or the user confirms their password.
|
||||
updateStage(Stage.NeedToConfirm);
|
||||
boolean launchedConfirmationActivity =
|
||||
mChooseLockSettingsHelper.launchConfirmationActivity(
|
||||
CONFIRM_EXISTING_REQUEST,
|
||||
getString(R.string.unlock_set_unlock_launch_picker_title), true,
|
||||
mUserId);
|
||||
if (!launchedConfirmationActivity) {
|
||||
|
||||
final ChooseLockSettingsHelper.Builder builder =
|
||||
new ChooseLockSettingsHelper.Builder(getActivity());
|
||||
final boolean launched = builder.setRequestCode(CONFIRM_EXISTING_REQUEST)
|
||||
.setTitle(getString(R.string.unlock_set_unlock_launch_picker_title))
|
||||
.setReturnCredentials(true)
|
||||
.setUserId(mUserId)
|
||||
.show();
|
||||
|
||||
if (!launched) {
|
||||
updateStage(Stage.Introduction);
|
||||
}
|
||||
} else {
|
||||
@@ -853,7 +857,7 @@ public class ChooseLockPattern extends SettingsActivity {
|
||||
profileCredential);
|
||||
}
|
||||
}
|
||||
mSaveAndFinishWorker.start(mChooseLockSettingsHelper.utils(), required,
|
||||
mSaveAndFinishWorker.start(mLockPatternUtils, required,
|
||||
mHasChallenge, mChallenge, mChosenPattern, mCurrentCredential, mUserId);
|
||||
}
|
||||
|
||||
|
@@ -18,14 +18,15 @@ package com.android.settings.password;
|
||||
|
||||
import static com.android.settings.Utils.SETTINGS_PACKAGE_NAME;
|
||||
|
||||
import android.annotation.NonNull;
|
||||
import android.annotation.Nullable;
|
||||
import android.app.Activity;
|
||||
import android.app.KeyguardManager;
|
||||
import android.app.admin.DevicePolicyManager;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentSender;
|
||||
import android.os.Bundle;
|
||||
import android.os.UserManager;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import androidx.fragment.app.Fragment;
|
||||
@@ -39,6 +40,8 @@ import com.google.android.setupcompat.util.WizardManagerHelper;
|
||||
|
||||
public final class ChooseLockSettingsHelper {
|
||||
|
||||
private static final String TAG = "ChooseLockSettingsHelper";
|
||||
|
||||
public static final String EXTRA_KEY_TYPE = "type";
|
||||
public static final String EXTRA_KEY_PASSWORD = "password";
|
||||
public static final String EXTRA_KEY_RETURN_CREDENTIALS = "return_credentials";
|
||||
@@ -84,319 +87,192 @@ public final class ChooseLockSettingsHelper {
|
||||
* controls if we relax the enforcement of
|
||||
* {@link Utils#enforceSameOwner(android.content.Context, int)}.
|
||||
*/
|
||||
public static final String EXTRA_ALLOW_ANY_USER = "allow_any_user";
|
||||
public static final String EXTRA_KEY_ALLOW_ANY_USER = "allow_any_user";
|
||||
|
||||
@VisibleForTesting LockPatternUtils mLockPatternUtils;
|
||||
private Activity mActivity;
|
||||
private Fragment mFragment;
|
||||
@VisibleForTesting @NonNull LockPatternUtils mLockPatternUtils;
|
||||
@NonNull private final Activity mActivity;
|
||||
@Nullable private final Fragment mFragment;
|
||||
@NonNull private final Builder mBuilder;
|
||||
|
||||
public ChooseLockSettingsHelper(Activity activity) {
|
||||
private ChooseLockSettingsHelper(@NonNull Builder builder, @NonNull Activity activity,
|
||||
@Nullable Fragment fragment) {
|
||||
mBuilder = builder;
|
||||
mActivity = activity;
|
||||
mFragment = fragment;
|
||||
mLockPatternUtils = new LockPatternUtils(activity);
|
||||
}
|
||||
|
||||
public ChooseLockSettingsHelper(Activity activity, Fragment fragment) {
|
||||
this(activity);
|
||||
mFragment = fragment;
|
||||
}
|
||||
public static class Builder {
|
||||
@NonNull private final Activity mActivity;
|
||||
@Nullable private Fragment mFragment;
|
||||
|
||||
public LockPatternUtils utils() {
|
||||
return mLockPatternUtils;
|
||||
private int mRequestCode;
|
||||
@Nullable private CharSequence mTitle;
|
||||
@Nullable private CharSequence mHeader;
|
||||
@Nullable private CharSequence mDescription;
|
||||
@Nullable private CharSequence mAlternateButton;
|
||||
private boolean mReturnCredentials;
|
||||
private boolean mExternal;
|
||||
private boolean mForegroundOnly;
|
||||
// ChooseLockSettingsHelper will determine the caller's userId if none provided.
|
||||
private int mUserId;
|
||||
private boolean mAllowAnyUserId;
|
||||
// The challenge can be 0, which is different than "no challenge"
|
||||
@Nullable Long mChallenge;
|
||||
|
||||
public Builder(@NonNull Activity activity) {
|
||||
mActivity = activity;
|
||||
mUserId = Utils.getCredentialOwnerUserId(mActivity);
|
||||
}
|
||||
|
||||
public Builder(@NonNull Activity activity, @NonNull Fragment fragment) {
|
||||
this(activity);
|
||||
mFragment = fragment;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param requestCode for onActivityResult
|
||||
*/
|
||||
@NonNull public Builder setRequestCode(int requestCode) {
|
||||
mRequestCode = requestCode;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param title of the confirmation screen; shown in the action bar
|
||||
*/
|
||||
@NonNull public Builder setTitle(@Nullable CharSequence title) {
|
||||
mTitle = title;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param header of the confirmation screen; shown as large text
|
||||
*/
|
||||
@NonNull public Builder setHeader(@Nullable CharSequence header) {
|
||||
mHeader = header;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param description of the confirmation screen
|
||||
*/
|
||||
@NonNull public Builder setDescription(@Nullable CharSequence description) {
|
||||
mDescription = description;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param alternateButton text for an alternate button
|
||||
*/
|
||||
@NonNull public Builder setAlternateButton(@Nullable CharSequence alternateButton) {
|
||||
mAlternateButton = alternateButton;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param returnCredentials if true, puts the following credentials into intent for
|
||||
* onActivityResult with the following keys:
|
||||
* {@link #EXTRA_KEY_TYPE}, {@link #EXTRA_KEY_PASSWORD},
|
||||
* {@link #EXTRA_KEY_CHALLENGE_TOKEN}.
|
||||
* Note that if this is true, this can only be called internally.
|
||||
*/
|
||||
@NonNull public Builder setReturnCredentials(boolean returnCredentials) {
|
||||
mReturnCredentials = returnCredentials;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param userId for whom the credential should be confirmed.
|
||||
*/
|
||||
@NonNull public Builder setUserId(int userId) {
|
||||
mUserId = userId;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param allowAnyUserId Allows the caller to prompt for credentials of any user, including
|
||||
* those which aren't associated with the current user. As an example,
|
||||
* this is useful when unlocking the storage for secondary users.
|
||||
*/
|
||||
@NonNull public Builder setAllowAnyUserId(boolean allowAnyUserId) {
|
||||
mAllowAnyUserId = allowAnyUserId;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param external specifies whether this activity is launched externally, meaning that it
|
||||
* will get a dark theme, allow biometric authentication, and it will
|
||||
* forward the activity result.
|
||||
*/
|
||||
@NonNull public Builder setExternal(boolean external) {
|
||||
mExternal = external;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param foregroundOnly if true, the confirmation activity will be finished if it loses
|
||||
* foreground.
|
||||
*/
|
||||
@NonNull public Builder setForegroundOnly(boolean foregroundOnly) {
|
||||
mForegroundOnly = foregroundOnly;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param challenge an opaque payload that will be wrapped in the Gatekeeper's payload
|
||||
* if authentication is successful. Common use case is for the caller's
|
||||
* secure layer (e.g. Trusted Execution Environment) to 1) verify that
|
||||
* the Gatekeeper HAT's HMAC is valid, and 2) if so, perform an operation
|
||||
* based on the challenge.
|
||||
*/
|
||||
@NonNull public Builder setChallenge(long challenge) {
|
||||
mChallenge = challenge;
|
||||
return this;
|
||||
}
|
||||
|
||||
@NonNull public ChooseLockSettingsHelper build() {
|
||||
if (!mAllowAnyUserId && mUserId != LockPatternUtils.USER_FRP) {
|
||||
Utils.enforceSameOwner(mActivity, mUserId);
|
||||
}
|
||||
|
||||
if (mExternal && mReturnCredentials) {
|
||||
throw new IllegalArgumentException("External and ReturnCredentials specified. "
|
||||
+ " External callers should never be allowed to receive credentials in"
|
||||
+ " onActivityResult");
|
||||
}
|
||||
|
||||
if (mChallenge != null && !mReturnCredentials) {
|
||||
// HAT containing the signed challenge will not be available to the caller.
|
||||
Log.w(TAG, "Challenge set but not requesting ReturnCredentials. Are you sure this"
|
||||
+ " is what you want?");
|
||||
}
|
||||
|
||||
return new ChooseLockSettingsHelper(this, mActivity, mFragment);
|
||||
}
|
||||
|
||||
public boolean show() {
|
||||
return build().launch();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
* @return true if one exists and we launched an activity to confirm it
|
||||
* @see Activity#onActivityResult(int, int, android.content.Intent)
|
||||
* If a PIN, Pattern, or Password exists, prompt the user to confirm it.
|
||||
* @return true if the confirmation activity is shown (e.g. user has a credential set up)
|
||||
*/
|
||||
public boolean launchConfirmationActivity(int request, CharSequence title) {
|
||||
return launchConfirmationActivity(
|
||||
request /* request */,
|
||||
title /* title */,
|
||||
null /* header */,
|
||||
null /* description */,
|
||||
false /* returnCredentials */,
|
||||
false /* external */,
|
||||
false /* foregroundOnly */);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* @return true if one exists and we launched an activity to confirm it
|
||||
* @see Activity#onActivityResult(int, int, android.content.Intent)
|
||||
*/
|
||||
public boolean launchConfirmationActivity(int request, CharSequence title, boolean returnCredentials) {
|
||||
return launchConfirmationActivity(
|
||||
request /* request */,
|
||||
title /* title */,
|
||||
null /* header */,
|
||||
null /* description */,
|
||||
returnCredentials /* returnCredentials */,
|
||||
false /* external */,
|
||||
false /* foregroundOnly */);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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)
|
||||
*/
|
||||
public boolean launchConfirmationActivity(int request, CharSequence title,
|
||||
boolean returnCredentials, int userId) {
|
||||
return launchConfirmationActivity(
|
||||
request /* request */,
|
||||
title /* title */,
|
||||
null /* header */,
|
||||
null /* description */,
|
||||
returnCredentials /* returnCredentials */,
|
||||
false /* external */,
|
||||
false /* hasChallenge */,
|
||||
0 /* challenge */,
|
||||
Utils.enforceSameOwner(mActivity, userId) /* userId */,
|
||||
false /* foregroundOnly */);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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,
|
||||
* this can only be called internally.
|
||||
* @param external specifies whether this activity is launched externally, meaning that it will
|
||||
* get a dark theme, allow fingerprint authentication and it will forward
|
||||
* activity result.
|
||||
* @param foregroundOnly if the confirmation activity should be finished if it loses foreground.
|
||||
* @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, @Nullable CharSequence title,
|
||||
@Nullable CharSequence header, @Nullable CharSequence description,
|
||||
boolean returnCredentials, boolean external, boolean foregroundOnly) {
|
||||
return launchConfirmationActivity(
|
||||
request /* request */,
|
||||
title /* title */,
|
||||
header /* header */,
|
||||
description /* description */,
|
||||
returnCredentials /* returnCredentials */,
|
||||
external /* external */,
|
||||
false /* hasChallenge */,
|
||||
0 /* challenge */,
|
||||
Utils.getCredentialOwnerUserId(mActivity) /* userId */,
|
||||
foregroundOnly /* foregroundOnly */);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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,
|
||||
* this can only be called internally.
|
||||
* @param external specifies whether this activity is launched externally, meaning that it will
|
||||
* get a dark theme, allow fingerprint authentication and it will forward
|
||||
* activity result.
|
||||
* @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, @Nullable CharSequence title,
|
||||
@Nullable CharSequence header, @Nullable CharSequence description,
|
||||
boolean returnCredentials, boolean external, int userId) {
|
||||
return launchConfirmationActivity(
|
||||
request /* request */,
|
||||
title /* title */,
|
||||
header /* header */,
|
||||
description /* description */,
|
||||
returnCredentials /* returnCredentials */,
|
||||
external /* external */,
|
||||
false /* hasChallenge */,
|
||||
0 /* challenge */,
|
||||
Utils.enforceSameOwner(mActivity, userId) /* userId */,
|
||||
false /* foregroundOnly */);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 challenge a challenge to be verified against the device credential.
|
||||
* @param foregroundOnly if the confirmation activity should be finished if it loses foreground.
|
||||
* @return true if one exists and we launched an activity to confirm it
|
||||
* @see Activity#onActivityResult(int, int, android.content.Intent)
|
||||
*/
|
||||
public boolean launchConfirmationActivity(int request, @Nullable CharSequence title,
|
||||
@Nullable CharSequence header, @Nullable CharSequence description,
|
||||
long challenge, boolean foregroundOnly) {
|
||||
return launchConfirmationActivity(
|
||||
request /* request */,
|
||||
title /* title */,
|
||||
header /* header */,
|
||||
description /* description */,
|
||||
true /* returnCredentials */,
|
||||
false /* external */,
|
||||
true /* hasChallenge */,
|
||||
challenge /* challenge */,
|
||||
Utils.getCredentialOwnerUserId(mActivity) /* userId */,
|
||||
foregroundOnly /* foregroundOnly */);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 challenge a challenge to be verified against the device credential.
|
||||
* @param userId The userId for whom the lock should be confirmed.
|
||||
* @param foregroundOnly if the confirmation activity should be finished if it loses foreground.
|
||||
* @return true if one exists and we launched an activity to confirm it
|
||||
* @see Activity#onActivityResult(int, int, android.content.Intent)
|
||||
*/
|
||||
public boolean launchConfirmationActivity(int request, @Nullable CharSequence title,
|
||||
@Nullable CharSequence header, @Nullable CharSequence description,
|
||||
long challenge, int userId, boolean foregroundOnly) {
|
||||
return launchConfirmationActivity(
|
||||
request /* request */,
|
||||
title /* title */,
|
||||
header /* header */,
|
||||
description /* description */,
|
||||
true /* returnCredentials */,
|
||||
false /* external */,
|
||||
true /* hasChallenge */,
|
||||
challenge /* challenge */,
|
||||
Utils.enforceSameOwner(mActivity, userId) /* userId */,
|
||||
foregroundOnly);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 external specifies whether this activity is launched externally, meaning that it will
|
||||
* get a dark theme, allow fingerprint authentication and it will forward
|
||||
* activity result.
|
||||
* @param challenge a challenge to be verified against the device credential.
|
||||
* @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)
|
||||
*/
|
||||
public boolean launchConfirmationActivityWithExternalAndChallenge(int request,
|
||||
@Nullable CharSequence title, @Nullable CharSequence header,
|
||||
@Nullable CharSequence description, boolean external, long challenge, int userId) {
|
||||
return launchConfirmationActivity(
|
||||
request /* request */,
|
||||
title /* title */,
|
||||
header /* header */,
|
||||
description /* description */,
|
||||
false /* returnCredentials */,
|
||||
external /* external */,
|
||||
true /* hasChallenge */,
|
||||
challenge /* challenge */,
|
||||
Utils.enforceSameOwner(mActivity, userId) /* userId */,
|
||||
false /* foregroundOnly */);
|
||||
}
|
||||
|
||||
/**
|
||||
* Variant that allows you to prompt for credentials of any user, including
|
||||
* those which aren't associated with the current user. As an example, this
|
||||
* is useful when unlocking the storage for secondary users.
|
||||
*/
|
||||
public boolean launchConfirmationActivityForAnyUser(int request,
|
||||
@Nullable CharSequence title, @Nullable CharSequence header,
|
||||
@Nullable CharSequence description, int userId) {
|
||||
final Bundle extras = new Bundle();
|
||||
extras.putBoolean(EXTRA_ALLOW_ANY_USER, true);
|
||||
return launchConfirmationActivity(
|
||||
request /* request */,
|
||||
title /* title */,
|
||||
header /* header */,
|
||||
description /* description */,
|
||||
false /* returnCredentials */,
|
||||
false /* external */,
|
||||
true /* hasChallenge */,
|
||||
0 /* challenge */,
|
||||
userId /* userId */,
|
||||
extras /* extras */);
|
||||
public boolean launch() {
|
||||
final long challenge = mBuilder.mChallenge != null ? mBuilder.mChallenge : 0L;
|
||||
return launchConfirmationActivity(mBuilder.mRequestCode, mBuilder.mTitle, mBuilder.mHeader,
|
||||
mBuilder.mDescription, mBuilder.mReturnCredentials, mBuilder.mExternal,
|
||||
mBuilder.mChallenge != null, challenge, mBuilder.mUserId,
|
||||
mBuilder.mAlternateButton, mBuilder.mAllowAnyUserId, mBuilder.mForegroundOnly);
|
||||
}
|
||||
|
||||
private boolean launchConfirmationActivity(int request, @Nullable CharSequence title,
|
||||
@Nullable CharSequence header, @Nullable CharSequence description,
|
||||
boolean returnCredentials, boolean external, boolean hasChallenge,
|
||||
long challenge, int userId, boolean foregroundOnly) {
|
||||
return launchConfirmationActivity(
|
||||
request /* request */,
|
||||
title /* title */,
|
||||
header /* header */,
|
||||
description /* description */,
|
||||
returnCredentials /* returnCredentials */,
|
||||
external /* external */,
|
||||
hasChallenge /* hasChallenge */,
|
||||
challenge /* challenge */,
|
||||
userId /* userId */,
|
||||
null /* alternateButton */,
|
||||
null /* extras */,
|
||||
foregroundOnly /* foregroundOnly */);
|
||||
}
|
||||
|
||||
private boolean launchConfirmationActivity(int request, @Nullable CharSequence title,
|
||||
@Nullable CharSequence header, @Nullable CharSequence description,
|
||||
boolean returnCredentials, boolean external, boolean hasChallenge,
|
||||
long challenge, int userId, Bundle extras) {
|
||||
return launchConfirmationActivity(
|
||||
request /* request */,
|
||||
title /* title */,
|
||||
header /* header */,
|
||||
description /* description */,
|
||||
returnCredentials /* returnCredentials */,
|
||||
external /* external */,
|
||||
hasChallenge /* hasChallenge */,
|
||||
challenge /* challenge */,
|
||||
userId /* userId */,
|
||||
null /* alternateButton */,
|
||||
extras /* extras */,
|
||||
false /* foregroundOnly */);
|
||||
}
|
||||
|
||||
public boolean launchFrpConfirmationActivity(int request, @Nullable CharSequence header,
|
||||
@Nullable CharSequence description, @Nullable CharSequence alternateButton) {
|
||||
return launchConfirmationActivity(
|
||||
request /* request */,
|
||||
null /* title */,
|
||||
header /* header */,
|
||||
description /* description */,
|
||||
false /* returnCredentials */,
|
||||
true /* external */,
|
||||
false /* hasChallenge */,
|
||||
0 /* challenge */,
|
||||
LockPatternUtils.USER_FRP /* userId */,
|
||||
alternateButton /* alternateButton */,
|
||||
null /* extras */,
|
||||
false /* foregroundOnly */);
|
||||
}
|
||||
|
||||
private boolean launchConfirmationActivity(int request, @Nullable CharSequence title,
|
||||
@Nullable CharSequence header, @Nullable CharSequence description,
|
||||
boolean returnCredentials, boolean external, boolean hasChallenge,
|
||||
long challenge, int userId, @Nullable CharSequence alternateButton, Bundle extras,
|
||||
boolean foregroundOnly) {
|
||||
long challenge, int userId, @Nullable CharSequence alternateButton,
|
||||
boolean allowAnyUser, boolean foregroundOnly) {
|
||||
final int effectiveUserId = UserManager.get(mActivity).getCredentialOwnerProfile(userId);
|
||||
boolean launched = false;
|
||||
|
||||
@@ -406,7 +282,7 @@ public final class ChooseLockSettingsHelper {
|
||||
returnCredentials || hasChallenge
|
||||
? ConfirmLockPattern.InternalActivity.class
|
||||
: ConfirmLockPattern.class, returnCredentials, external,
|
||||
hasChallenge, challenge, userId, alternateButton, extras,
|
||||
hasChallenge, challenge, userId, alternateButton, allowAnyUser,
|
||||
foregroundOnly);
|
||||
break;
|
||||
case DevicePolicyManager.PASSWORD_QUALITY_NUMERIC:
|
||||
@@ -419,7 +295,7 @@ public final class ChooseLockSettingsHelper {
|
||||
returnCredentials || hasChallenge
|
||||
? ConfirmLockPassword.InternalActivity.class
|
||||
: ConfirmLockPassword.class, returnCredentials, external,
|
||||
hasChallenge, challenge, userId, alternateButton, extras,
|
||||
hasChallenge, challenge, userId, alternateButton, allowAnyUser,
|
||||
foregroundOnly);
|
||||
break;
|
||||
}
|
||||
@@ -429,7 +305,7 @@ public final class ChooseLockSettingsHelper {
|
||||
private boolean launchConfirmationActivity(int request, CharSequence title, CharSequence header,
|
||||
CharSequence message, Class<?> activityClass, boolean returnCredentials,
|
||||
boolean external, boolean hasChallenge, long challenge,
|
||||
int userId, @Nullable CharSequence alternateButton, Bundle extras,
|
||||
int userId, @Nullable CharSequence alternateButton, boolean allowAnyUser,
|
||||
boolean foregroundOnly) {
|
||||
final Intent intent = new Intent();
|
||||
intent.putExtra(ConfirmDeviceCredentialBaseFragment.TITLE_TEXT, title);
|
||||
@@ -446,9 +322,8 @@ public final class ChooseLockSettingsHelper {
|
||||
intent.putExtra(Intent.EXTRA_USER_ID, userId);
|
||||
intent.putExtra(KeyguardManager.EXTRA_ALTERNATE_BUTTON_LABEL, alternateButton);
|
||||
intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_FOREGROUND_ONLY, foregroundOnly);
|
||||
if (extras != null) {
|
||||
intent.putExtras(extras);
|
||||
}
|
||||
intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_ALLOW_ANY_USER, allowAnyUser);
|
||||
|
||||
intent.setClassName(SETTINGS_PACKAGE_NAME, activityClass.getName());
|
||||
if (external) {
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT);
|
||||
|
@@ -98,7 +98,6 @@ public class ConfirmDeviceCredentialActivity extends FragmentActivity {
|
||||
private LockPatternUtils mLockPatternUtils;
|
||||
private UserManager mUserManager;
|
||||
private TrustManager mTrustManager;
|
||||
private ChooseLockSettingsHelper mChooseLockSettingsHelper;
|
||||
private Handler mHandler = new Handler(Looper.getMainLooper());
|
||||
private Context mContext;
|
||||
private boolean mCheckDevicePolicyManager;
|
||||
@@ -214,8 +213,6 @@ public class ConfirmDeviceCredentialActivity extends FragmentActivity {
|
||||
mTitle = getTitleFromOrganizationName(mUserId);
|
||||
}
|
||||
|
||||
|
||||
mChooseLockSettingsHelper = new ChooseLockSettingsHelper(this);
|
||||
final LockPatternUtils lockPatternUtils = new LockPatternUtils(this);
|
||||
|
||||
final PromptInfo promptInfo = new PromptInfo();
|
||||
@@ -240,8 +237,14 @@ public class ConfirmDeviceCredentialActivity extends FragmentActivity {
|
||||
// tied profile so it will enable work mode and unlock managed profile, when personal
|
||||
// challenge is unlocked.
|
||||
if (frp) {
|
||||
launchedCDC = mChooseLockSettingsHelper.launchFrpConfirmationActivity(
|
||||
0, mTitle, mDetails, alternateButton);
|
||||
final ChooseLockSettingsHelper.Builder builder =
|
||||
new ChooseLockSettingsHelper.Builder(this);
|
||||
launchedCDC = builder.setHeader(mTitle) // Show the title in the header location
|
||||
.setDescription(mDetails)
|
||||
.setAlternateButton(alternateButton)
|
||||
.setExternal(true)
|
||||
.setUserId(LockPatternUtils.USER_FRP)
|
||||
.show();
|
||||
} else if (isManagedProfile && isInternalActivity()
|
||||
&& !lockPatternUtils.isSeparateProfileChallengeEnabled(mUserId)) {
|
||||
mCredentialMode = CREDENTIAL_MANAGED;
|
||||
@@ -385,15 +388,22 @@ public class ConfirmDeviceCredentialActivity extends FragmentActivity {
|
||||
// LockPatternChecker and LockPatternUtils. verifyPassword should be the only API to use,
|
||||
// which optionally accepts a challenge.
|
||||
if (mCredentialMode == CREDENTIAL_MANAGED) {
|
||||
launched = mChooseLockSettingsHelper
|
||||
.launchConfirmationActivityWithExternalAndChallenge(
|
||||
0 /* request code */, null /* title */, mTitle, mDetails,
|
||||
true /* isExternal */, 0L /* challenge */, mUserId);
|
||||
final ChooseLockSettingsHelper.Builder builder =
|
||||
new ChooseLockSettingsHelper.Builder(this);
|
||||
launched = builder.setHeader(mTitle)
|
||||
.setDescription(mDetails)
|
||||
.setExternal(true)
|
||||
.setUserId(mUserId)
|
||||
.setChallenge(0L)
|
||||
.show();
|
||||
} else if (mCredentialMode == CREDENTIAL_NORMAL) {
|
||||
launched = mChooseLockSettingsHelper.launchConfirmationActivity(
|
||||
0 /* request code */, null /* title */,
|
||||
mTitle, mDetails, false /* returnCredentials */, true /* isExternal */,
|
||||
mUserId);
|
||||
final ChooseLockSettingsHelper.Builder builder =
|
||||
new ChooseLockSettingsHelper.Builder(this);
|
||||
launched = builder.setHeader(mTitle) // Show the title string in the header area
|
||||
.setDescription(mDetails)
|
||||
.setExternal(true)
|
||||
.setUserId(mUserId)
|
||||
.show();
|
||||
}
|
||||
if (!launched) {
|
||||
Log.d(TAG, "No pin/pattern/pass set");
|
||||
|
@@ -357,9 +357,11 @@ public final class CredentialStorage extends FragmentActivity {
|
||||
*/
|
||||
private boolean confirmKeyGuard(int requestCode) {
|
||||
final Resources res = getResources();
|
||||
return new ChooseLockSettingsHelper(this)
|
||||
.launchConfirmationActivity(requestCode,
|
||||
res.getText(R.string.credentials_title), true);
|
||||
final ChooseLockSettingsHelper.Builder builder =
|
||||
new ChooseLockSettingsHelper.Builder(this);
|
||||
return builder.setRequestCode(requestCode)
|
||||
.setTitle(res.getText(R.string.credentials_title))
|
||||
.show();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -37,6 +37,7 @@ import android.widget.Button;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.preference.Preference;
|
||||
|
||||
import com.android.internal.widget.LockPatternUtils;
|
||||
import com.android.internal.widget.LockscreenCredential;
|
||||
import com.android.settings.CryptKeeperConfirm;
|
||||
import com.android.settings.R;
|
||||
@@ -169,17 +170,20 @@ public class CryptKeeperSettings extends InstrumentedPreferenceFragment {
|
||||
* @return true if confirmation launched
|
||||
*/
|
||||
private boolean runKeyguardConfirmation(int request) {
|
||||
Resources res = getActivity().getResources();
|
||||
ChooseLockSettingsHelper helper = new ChooseLockSettingsHelper(getActivity(), this);
|
||||
|
||||
if (helper.utils().getKeyguardStoredPasswordQuality(UserHandle.myUserId())
|
||||
final LockPatternUtils utils = new LockPatternUtils(getActivity());
|
||||
if (utils.getKeyguardStoredPasswordQuality(UserHandle.myUserId())
|
||||
== DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED) {
|
||||
showFinalConfirmation(StorageManager.CRYPT_TYPE_DEFAULT, "".getBytes());
|
||||
return true;
|
||||
}
|
||||
|
||||
return helper.launchConfirmationActivity(request,
|
||||
res.getText(R.string.crypt_keeper_encrypt_title), true);
|
||||
final Resources res = getActivity().getResources();
|
||||
final ChooseLockSettingsHelper.Builder builder =
|
||||
new ChooseLockSettingsHelper.Builder(getActivity(), this);
|
||||
return builder.setRequestCode(request)
|
||||
.setTitle(res.getText(R.string.crypt_keeper_encrypt_title))
|
||||
.setReturnCredentials(true)
|
||||
.show();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -118,11 +118,15 @@ public class LockUnificationPreferenceController extends AbstractPreferenceContr
|
||||
startUnification();
|
||||
} else {
|
||||
final String title = mContext.getString(R.string.unlock_set_unlock_launch_picker_title);
|
||||
final ChooseLockSettingsHelper helper =
|
||||
new ChooseLockSettingsHelper(mHost.getActivity(), mHost);
|
||||
if (!helper.launchConfirmationActivity(
|
||||
UNUNIFY_LOCK_CONFIRM_DEVICE_REQUEST,
|
||||
title, true /* returnCredentials */, MY_USER_ID)) {
|
||||
final ChooseLockSettingsHelper.Builder builder =
|
||||
new ChooseLockSettingsHelper.Builder(mHost.getActivity(), mHost);
|
||||
final boolean launched = builder.setRequestCode(UNUNIFY_LOCK_CONFIRM_DEVICE_REQUEST)
|
||||
.setTitle(title)
|
||||
.setReturnCredentials(true)
|
||||
.setUserId(MY_USER_ID)
|
||||
.show();
|
||||
|
||||
if (!launched) {
|
||||
ununifyLocks();
|
||||
}
|
||||
}
|
||||
@@ -176,10 +180,14 @@ public class LockUnificationPreferenceController extends AbstractPreferenceContr
|
||||
// Confirm profile lock
|
||||
final String title = mContext.getString(
|
||||
R.string.unlock_set_unlock_launch_picker_title_profile);
|
||||
final ChooseLockSettingsHelper helper =
|
||||
new ChooseLockSettingsHelper(mHost.getActivity(), mHost);
|
||||
if (!helper.launchConfirmationActivity(
|
||||
UNIFY_LOCK_CONFIRM_PROFILE_REQUEST, title, true, mProfileUserId)) {
|
||||
final ChooseLockSettingsHelper.Builder builder =
|
||||
new ChooseLockSettingsHelper.Builder(mHost.getActivity(), mHost);
|
||||
final boolean launched = builder.setRequestCode(UNIFY_LOCK_CONFIRM_PROFILE_REQUEST)
|
||||
.setTitle(title)
|
||||
.setReturnCredentials(true)
|
||||
.setUserId(mProfileUserId)
|
||||
.show();
|
||||
if (!launched) {
|
||||
// If profile has no lock, go straight to unification.
|
||||
unifyLocks();
|
||||
// TODO: update relevant prefs.
|
||||
|
@@ -120,11 +120,14 @@ public class TrustAgentListPreferenceController extends AbstractPreferenceContro
|
||||
if (!mTrustAgentsKeyList.contains(preference.getKey())) {
|
||||
return super.handlePreferenceTreeClick(preference);
|
||||
}
|
||||
final ChooseLockSettingsHelper helper = new ChooseLockSettingsHelper(
|
||||
mHost.getActivity(), mHost);
|
||||
|
||||
final ChooseLockSettingsHelper.Builder builder =
|
||||
new ChooseLockSettingsHelper.Builder(mHost.getActivity(), mHost);
|
||||
final boolean confirmationLaunched = builder.setRequestCode(CHANGE_TRUST_AGENT_SETTINGS)
|
||||
.setTitle(preference.getTitle())
|
||||
.show();
|
||||
|
||||
mTrustAgentClickIntent = preference.getIntent();
|
||||
boolean confirmationLaunched = helper.launchConfirmationActivity(
|
||||
CHANGE_TRUST_AGENT_SETTINGS, preference.getTitle());
|
||||
|
||||
if (!confirmationLaunched && mTrustAgentClickIntent != null) {
|
||||
// If this returns false, it means no password confirmation is required.
|
||||
|
@@ -38,16 +38,17 @@ public class ChooseLockSettingsHelperTest {
|
||||
@Test
|
||||
public void testLaunchConfirmationActivityWithExternalAndChallenge() {
|
||||
final Activity activity = Robolectric.setupActivity(Activity.class);
|
||||
ChooseLockSettingsHelper helper = getChooseLockSettingsHelper(activity);
|
||||
helper.launchConfirmationActivityWithExternalAndChallenge(
|
||||
100, // request
|
||||
"title",
|
||||
"header",
|
||||
"description",
|
||||
true, // external
|
||||
10000L,
|
||||
UserHandle.myUserId()
|
||||
);
|
||||
|
||||
ChooseLockSettingsHelper.Builder builder = new ChooseLockSettingsHelper.Builder(activity);
|
||||
builder.setRequestCode(100)
|
||||
.setTitle("title")
|
||||
.setHeader("header")
|
||||
.setDescription("description")
|
||||
.setExternal(true)
|
||||
.setChallenge(10000L)
|
||||
.setUserId(UserHandle.myUserId());
|
||||
ChooseLockSettingsHelper helper = getChooseLockSettingsHelper(builder);
|
||||
helper.launch();
|
||||
|
||||
ShadowActivity shadowActivity = Shadows.shadowOf(activity);
|
||||
Intent startedIntent = shadowActivity.getNextStartedActivity();
|
||||
@@ -73,16 +74,17 @@ public class ChooseLockSettingsHelperTest {
|
||||
@Test
|
||||
public void testLaunchConfirmationActivityInternalAndChallenge() {
|
||||
final Activity activity = Robolectric.setupActivity(Activity.class);
|
||||
ChooseLockSettingsHelper helper = getChooseLockSettingsHelper(activity);
|
||||
helper.launchConfirmationActivityWithExternalAndChallenge(
|
||||
100,
|
||||
"title",
|
||||
"header",
|
||||
"description",
|
||||
false, // external
|
||||
10000L,
|
||||
UserHandle.myUserId()
|
||||
);
|
||||
|
||||
ChooseLockSettingsHelper.Builder builder = new ChooseLockSettingsHelper.Builder(activity);
|
||||
builder.setRequestCode(100)
|
||||
.setTitle("title")
|
||||
.setHeader("header")
|
||||
.setDescription("description")
|
||||
.setChallenge(10000L)
|
||||
.setUserId(UserHandle.myUserId());
|
||||
ChooseLockSettingsHelper helper = getChooseLockSettingsHelper(builder);
|
||||
helper.launch();
|
||||
|
||||
ShadowActivity shadowActivity = Shadows.shadowOf(activity);
|
||||
Intent startedIntent = shadowActivity.getNextStartedActivity();
|
||||
|
||||
@@ -109,8 +111,14 @@ public class ChooseLockSettingsHelperTest {
|
||||
Intent intent = new Intent()
|
||||
.putExtra(WizardManagerHelper.EXTRA_THEME, ThemeHelper.THEME_GLIF_V2);
|
||||
Activity activity = Robolectric.buildActivity(Activity.class, intent).get();
|
||||
ChooseLockSettingsHelper helper = getChooseLockSettingsHelper(activity);
|
||||
helper.launchConfirmationActivity(123, "test title", true, 0 /* userId */);
|
||||
|
||||
ChooseLockSettingsHelper.Builder builder = new ChooseLockSettingsHelper.Builder(activity);
|
||||
builder.setRequestCode(123)
|
||||
.setTitle("test title")
|
||||
.setReturnCredentials(true)
|
||||
.setUserId(0);
|
||||
ChooseLockSettingsHelper helper = getChooseLockSettingsHelper(builder);
|
||||
helper.launch();
|
||||
|
||||
ShadowActivity shadowActivity = Shadows.shadowOf(activity);
|
||||
IntentForResult startedActivity = shadowActivity.getNextStartedActivityForResult();
|
||||
@@ -119,12 +127,13 @@ public class ChooseLockSettingsHelperTest {
|
||||
.isEqualTo(ThemeHelper.THEME_GLIF_V2);
|
||||
}
|
||||
|
||||
private ChooseLockSettingsHelper getChooseLockSettingsHelper(Activity activity) {
|
||||
private ChooseLockSettingsHelper getChooseLockSettingsHelper(
|
||||
ChooseLockSettingsHelper.Builder builder) {
|
||||
LockPatternUtils mockLockPatternUtils = mock(LockPatternUtils.class);
|
||||
when(mockLockPatternUtils.getKeyguardStoredPasswordQuality(anyInt()))
|
||||
.thenReturn(DevicePolicyManager.PASSWORD_QUALITY_SOMETHING);
|
||||
|
||||
ChooseLockSettingsHelper helper = new ChooseLockSettingsHelper(activity);
|
||||
ChooseLockSettingsHelper helper = builder.build();
|
||||
helper.mLockPatternUtils = mockLockPatternUtils;
|
||||
return helper;
|
||||
}
|
||||
|
Reference in New Issue
Block a user