@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mDPM = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE); mKeyStore = KeyStore.getInstance(); mChooseLockSettingsHelper = new ChooseLockSettingsHelper(this.getActivity()); // Defaults to needing to confirm credentials final boolean confirmCredentials = getActivity().getIntent().getBooleanExtra(CONFIRM_CREDENTIALS, true); if (getActivity() instanceof ChooseLockGeneric.InternalActivity) { mPasswordConfirmed = !confirmCredentials; } if (savedInstanceState != null) { mPasswordConfirmed = savedInstanceState.getBoolean(PASSWORD_CONFIRMED); mWaitingForConfirmation = savedInstanceState.getBoolean(WAITING_FOR_CONFIRMATION); mFinishPending = savedInstanceState.getBoolean(FINISH_PENDING); } if (mPasswordConfirmed) { updatePreferencesOrFinish(); } else if (!mWaitingForConfirmation) { ChooseLockSettingsHelper helper = new ChooseLockSettingsHelper(this.getActivity(), this); if (!helper.launchConfirmationActivity(CONFIRM_EXISTING_REQUEST, null, null)) { mPasswordConfirmed = true; // no password set, so no need to confirm updatePreferencesOrFinish(); } else { mWaitingForConfirmation = true; } } }
/** * Invokes an activity to change the user's pattern, password or PIN based on given quality and * minimum quality specified by DevicePolicyManager. If quality is {@link * DevicePolicyManager#PASSWORD_QUALITY_UNSPECIFIED}, password is cleared. * * @param quality the desired quality. Ignored if DevicePolicyManager requires more security * @param disabled whether or not to show LockScreen at all. Only meaningful when quality is * {@link DevicePolicyManager#PASSWORD_QUALITY_UNSPECIFIED} */ void updateUnlockMethodAndFinish(int quality, boolean disabled) { // Sanity check. We should never get here without confirming user's existing password. if (!mPasswordConfirmed) { throw new IllegalStateException("Tried to update password without confirming it"); } final boolean isFallback = getActivity() .getIntent() .getBooleanExtra(LockPatternUtils.LOCKSCREEN_BIOMETRIC_WEAK_FALLBACK, false); quality = upgradeQuality(quality); if (quality >= DevicePolicyManager.PASSWORD_QUALITY_NUMERIC) { int minLength = mDPM.getPasswordMinimumLength(null); if (minLength < MIN_PASSWORD_LENGTH) { minLength = MIN_PASSWORD_LENGTH; } final int maxLength = mDPM.getPasswordMaximumLength(quality); Intent intent = new Intent().setClass(getActivity(), ChooseLockPassword.class); intent.putExtra(LockPatternUtils.PASSWORD_TYPE_KEY, quality); intent.putExtra(ChooseLockPassword.PASSWORD_MIN_KEY, minLength); intent.putExtra(ChooseLockPassword.PASSWORD_MAX_KEY, maxLength); intent.putExtra(CONFIRM_CREDENTIALS, false); intent.putExtra(LockPatternUtils.LOCKSCREEN_BIOMETRIC_WEAK_FALLBACK, isFallback); if (isFallback) { startActivityForResult(intent, FALLBACK_REQUEST); return; } else { intent.addFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT); startActivity(intent); } } else if (quality == DevicePolicyManager.PASSWORD_QUALITY_SOMETHING) { boolean showTutorial = !mChooseLockSettingsHelper.utils().isPatternEverChosen(); Intent intent = new Intent(); intent.setClass( getActivity(), showTutorial ? ChooseLockPatternTutorial.class : ChooseLockPattern.class); intent.putExtra("key_lock_method", "pattern"); intent.putExtra(CONFIRM_CREDENTIALS, false); intent.putExtra(LockPatternUtils.LOCKSCREEN_BIOMETRIC_WEAK_FALLBACK, isFallback); if (isFallback) { startActivityForResult(intent, FALLBACK_REQUEST); return; } else { intent.addFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT); startActivity(intent); } } else if (quality == DevicePolicyManager.PASSWORD_QUALITY_BIOMETRIC_WEAK) { Intent intent = getBiometricSensorIntent(); startActivity(intent); } else if (quality == DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED) { mChooseLockSettingsHelper.utils().clearLock(false); mChooseLockSettingsHelper.utils().setLockScreenDisabled(disabled); getActivity().setResult(Activity.RESULT_OK); } finish(); }
@Override public void onResume() { super.onResume(); if (!mPasswordConfirmed && !mCanceled) { ChooseLockSettingsHelper helper = new ChooseLockSettingsHelper(this.getActivity(), this); if (!helper.launchConfirmationActivity(CONFIRM_EXISTING_REQUEST, null, null)) { mPasswordConfirmed = true; // no password set, so no need to confirm updatePreferencesOrFinish(); } } else { updatePreferencesOrFinish(); } }
@Override public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) { final String key = preference.getKey(); final LockPatternUtils lockPatternUtils = mChooseLockSettingsHelper.utils(); if (KEY_UNLOCK_SET_OR_CHANGE.equals(key)) { startFragment( this, "com.android.settings.ChooseLockGeneric$ChooseLockGenericFragment", SET_OR_CHANGE_LOCK_METHOD_REQUEST, null); } else if (KEY_BIOMETRIC_WEAK_IMPROVE_MATCHING.equals(key)) { ChooseLockSettingsHelper helper = new ChooseLockSettingsHelper(this.getActivity(), this); if (!helper.launchConfirmationActivity( CONFIRM_EXISTING_FOR_BIOMETRIC_IMPROVE_REQUEST, null, null)) { startBiometricWeakImprove(); // no password set, so no need to confirm } } else if (KEY_LOCK_ENABLED.equals(key)) { lockPatternUtils.setLockPatternEnabled(isToggled(preference)); } else if (KEY_VISIBLE_PATTERN.equals(key)) { lockPatternUtils.setVisiblePatternEnabled(isToggled(preference)); } else if (KEY_TACTILE_FEEDBACK_ENABLED.equals(key)) { lockPatternUtils.setTactileFeedbackEnabled(isToggled(preference)); } else if (KEY_POWER_INSTANTLY_LOCKS.equals(key)) { lockPatternUtils.setPowerButtonInstantlyLocks(isToggled(preference)); } else if (preference == mShowPassword) { Settings.System.putInt( getContentResolver(), Settings.System.TEXT_SHOW_PASSWORD, mShowPassword.isChecked() ? 1 : 0); } else if (preference == mToggleAppInstallation) { if (mToggleAppInstallation.isChecked()) { mToggleAppInstallation.setChecked(false); warnAppInstallation(); } else { setNonMarketAppsAllowed(false); } } else { // If we didn't handle it, let preferences handle it. return super.onPreferenceTreeClick(preferenceScreen, preference); } return true; }
private Intent getBiometricSensorIntent() { Intent fallBackIntent = new Intent().setClass(getActivity(), ChooseLockGeneric.class); fallBackIntent.putExtra(LockPatternUtils.LOCKSCREEN_BIOMETRIC_WEAK_FALLBACK, true); fallBackIntent.putExtra(CONFIRM_CREDENTIALS, false); fallBackIntent.putExtra( EXTRA_SHOW_FRAGMENT_TITLE, R.string.backup_lock_settings_picker_title); boolean showTutorial = ALWAY_SHOW_TUTORIAL || !mChooseLockSettingsHelper.utils().isBiometricWeakEverChosen(); Intent intent = new Intent(); intent.setClassName("com.android.facelock", "com.android.facelock.SetupIntro"); intent.putExtra("showTutorial", showTutorial); PendingIntent pending = PendingIntent.getActivity(getActivity(), 0, fallBackIntent, 0); intent.putExtra("PendingIntent", pending); return intent; }
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == CONFIRM_EXISTING_REQUEST && resultCode == Activity.RESULT_OK) { mPasswordConfirmed = true; updatePreferencesOrFinish(); } else if (requestCode == FALLBACK_REQUEST) { mChooseLockSettingsHelper.utils().deleteTempGallery(); getActivity().setResult(resultCode); finish(); } else { mCanceled = true; getActivity().setResult(Activity.RESULT_CANCELED); finish(); } }
/** * * Disables preferences that are less secure than required quality. * * @param quality the requested quality. */ private void disableUnusablePreferences(final int quality, MutableBoolean allowBiometric) { final PreferenceScreen entries = getPreferenceScreen(); final boolean onlyShowFallback = getActivity() .getIntent() .getBooleanExtra(LockPatternUtils.LOCKSCREEN_BIOMETRIC_WEAK_FALLBACK, false); final boolean weakBiometricAvailable = mChooseLockSettingsHelper.utils().isBiometricWeakInstalled(); // if there are multiple users, disable "None" setting UserManager mUm = (UserManager) getSystemService(Context.USER_SERVICE); List<UserInfo> users = mUm.getUsers(true); final boolean singleUser = users.size() == 1; for (int i = entries.getPreferenceCount() - 1; i >= 0; --i) { Preference pref = entries.getPreference(i); if (pref instanceof PreferenceScreen) { final String key = ((PreferenceScreen) pref).getKey(); boolean enabled = true; boolean visible = true; if (KEY_UNLOCK_SET_OFF.equals(key)) { enabled = quality <= DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED; visible = singleUser; // don't show when there's more than 1 user } else if (KEY_UNLOCK_SET_NONE.equals(key)) { enabled = quality <= DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED; } else if (KEY_UNLOCK_SET_BIOMETRIC_WEAK.equals(key)) { enabled = quality <= DevicePolicyManager.PASSWORD_QUALITY_BIOMETRIC_WEAK || allowBiometric.value; visible = weakBiometricAvailable; // If not available, then don't show it. } else if (KEY_UNLOCK_SET_PATTERN.equals(key)) { enabled = quality <= DevicePolicyManager.PASSWORD_QUALITY_SOMETHING; } else if (KEY_UNLOCK_SET_PIN.equals(key)) { enabled = quality <= DevicePolicyManager.PASSWORD_QUALITY_NUMERIC; } else if (KEY_UNLOCK_SET_PASSWORD.equals(key)) { enabled = quality <= DevicePolicyManager.PASSWORD_QUALITY_COMPLEX; } if (!visible || (onlyShowFallback && !allowedForFallback(key))) { entries.removePreference(pref); } else if (!enabled) { pref.setSummary(R.string.unlock_set_unlock_disabled_summary); pref.setEnabled(false); } } } }
@Override public void onResume() { super.onResume(); // Make sure we reload the preference hierarchy since some of these settings // depend on others... createPreferenceHierarchy(); final LockPatternUtils lockPatternUtils = mChooseLockSettingsHelper.utils(); if (mVisiblePattern != null) { mVisiblePattern.setChecked(lockPatternUtils.isVisiblePatternEnabled()); } if (mTactileFeedback != null) { mTactileFeedback.setChecked(lockPatternUtils.isTactileFeedbackEnabled()); } if (mPowerButtonInstantlyLocks != null) { mPowerButtonInstantlyLocks.setChecked(lockPatternUtils.getPowerButtonInstantlyLocks()); } mShowPassword.setChecked( Settings.System.getInt(getContentResolver(), Settings.System.TEXT_SHOW_PASSWORD, 1) != 0); KeyStore.State state = KeyStore.getInstance().state(); mResetCredentials.setEnabled(state != KeyStore.State.UNINITIALIZED); // Location Settings updateLocationToggles(); if (mSettingsObserver == null) { mSettingsObserver = new Observer() { public void update(Observable o, Object arg) { updateLocationToggles(); } }; mContentQueryMap.addObserver(mSettingsObserver); } }
/** * * Disables preferences that are less secure than required quality. * * @param quality the requested quality. */ private void disableUnusablePreferences(final int quality) { final PreferenceScreen entries = getPreferenceScreen(); final boolean onlyShowFallback = getActivity() .getIntent() .getBooleanExtra(LockPatternUtils.LOCKSCREEN_BIOMETRIC_WEAK_FALLBACK, false); final boolean weakBiometricAvailable = mChooseLockSettingsHelper.utils().isBiometricWeakInstalled(); for (int i = entries.getPreferenceCount() - 1; i >= 0; --i) { Preference pref = entries.getPreference(i); if (pref instanceof PreferenceScreen) { final String key = ((PreferenceScreen) pref).getKey(); boolean enabled = true; boolean visible = true; if (KEY_UNLOCK_SET_OFF.equals(key)) { enabled = quality <= DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED; } else if (KEY_UNLOCK_SET_NONE.equals(key)) { enabled = quality <= DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED; } else if (KEY_UNLOCK_SET_BIOMETRIC_WEAK.equals(key)) { enabled = quality <= DevicePolicyManager.PASSWORD_QUALITY_BIOMETRIC_WEAK; visible = weakBiometricAvailable; // If not available, then don't show it. } else if (KEY_UNLOCK_SET_PATTERN.equals(key)) { enabled = quality <= DevicePolicyManager.PASSWORD_QUALITY_SOMETHING; } else if (KEY_UNLOCK_SET_PIN.equals(key)) { enabled = quality <= DevicePolicyManager.PASSWORD_QUALITY_NUMERIC; } else if (KEY_UNLOCK_SET_PASSWORD.equals(key)) { enabled = quality <= DevicePolicyManager.PASSWORD_QUALITY_COMPLEX; } if (!visible || (onlyShowFallback && !allowedForFallback(key))) { entries.removePreference(pref); } else if (!enabled) { pref.setSummary(R.string.unlock_set_unlock_disabled_summary); pref.setEnabled(false); } } } }