blob: 6809f35e87476d8fafc005f1d7219da1e76aaa2b [file] [log] [blame]
Dianne Hackbornabc3dc62010-01-20 13:40:19 -08001/*
2 * Copyright (C) 2010 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Maurice Lam2eb170c2017-04-28 16:18:47 -070017package com.android.settings.password;
Dianne Hackbornabc3dc62010-01-20 13:40:19 -080018
Steven Ng4fdcec72016-09-26 22:13:08 +010019import static android.app.admin.DevicePolicyManager.ACTION_SET_NEW_PARENT_PROFILE_PASSWORD;
20import static android.app.admin.DevicePolicyManager.ACTION_SET_NEW_PASSWORD;
Bernard Chau92db5bf2018-12-17 18:03:24 +000021import static android.app.admin.DevicePolicyManager.PASSWORD_COMPLEXITY_HIGH;
22import static android.app.admin.DevicePolicyManager.PASSWORD_COMPLEXITY_LOW;
23import static android.app.admin.DevicePolicyManager.PASSWORD_COMPLEXITY_MEDIUM;
24import static android.app.admin.DevicePolicyManager.PASSWORD_COMPLEXITY_NONE;
Fan Zhang23f8d592018-08-28 15:11:40 -070025
Fan Zhang9864a702018-11-27 11:29:09 -080026import static com.android.settings.password.ChooseLockPassword.ChooseLockPasswordFragment.RESULT_FINISHED;
Bernard Chau92db5bf2018-12-17 18:03:24 +000027import static com.android.settings.password.ChooseLockSettingsHelper.EXTRA_KEY_CALLER_APP_NAME;
Alex Kershaw29d2bff2019-05-17 15:36:28 +010028import static com.android.settings.password.ChooseLockSettingsHelper.EXTRA_KEY_IS_CALLING_APP_ADMIN;
Bernard Chau92db5bf2018-12-17 18:03:24 +000029import static com.android.settings.password.ChooseLockSettingsHelper.EXTRA_KEY_REQUESTED_MIN_COMPLEXITY;
Steven Ng4fdcec72016-09-26 22:13:08 +010030
Svetoslav52448442014-09-29 18:15:45 -070031import android.accessibilityservice.AccessibilityServiceInfo;
Jim Miller17e9e192010-12-07 20:41:41 -080032import android.app.Activity;
Lucky Zhang3bcea022014-11-25 18:22:14 -080033import android.app.Dialog;
Dianne Hackborn4037c7f2010-02-26 17:26:55 -080034import android.app.admin.DevicePolicyManager;
Bernard Chau92db5bf2018-12-17 18:03:24 +000035import android.app.admin.DevicePolicyManager.PasswordComplexity;
Fan Zhang31b21002019-01-16 13:49:47 -080036import android.app.settings.SettingsEnums;
Dianne Hackbornabc3dc62010-01-20 13:40:19 -080037import android.content.Context;
38import android.content.Intent;
Kevin Chyn0b956872018-06-29 13:09:32 -070039import android.hardware.face.FaceManager;
Jim Miller595982d2015-04-01 16:49:33 -070040import android.hardware.fingerprint.FingerprintManager;
Jason Monk39b46742015-09-10 15:52:51 -040041import android.os.Bundle;
Jason Monk39b46742015-09-10 15:52:51 -040042import android.os.UserHandle;
Xiaohui Chenf9ee84d2015-10-21 11:25:35 -070043import android.os.UserManager;
Paul Lawrence23c2acf2016-03-10 13:54:56 -080044import android.os.storage.StorageManager;
Adrian Roos62775bf2016-01-28 13:23:53 -080045import android.text.TextUtils;
rich cannings27d6f8d2013-05-29 14:54:58 -070046import android.util.EventLog;
Lucky Zhang3bcea022014-11-25 18:22:14 -080047import android.util.Log;
Svetoslav52448442014-09-29 18:15:45 -070048import android.view.accessibility.AccessibilityManager;
Steven Ng4fdcec72016-09-26 22:13:08 +010049import android.widget.TextView;
Jim Millerd16c9b72015-03-24 16:02:59 -070050
Fan Zhang23f8d592018-08-28 15:11:40 -070051import androidx.annotation.StringRes;
52import androidx.annotation.VisibleForTesting;
53import androidx.appcompat.app.AlertDialog;
54import androidx.fragment.app.Fragment;
55import androidx.fragment.app.FragmentManager;
56import androidx.preference.Preference;
57import androidx.preference.PreferenceScreen;
58
Gilles Debunne64650542011-08-23 11:01:35 -070059import com.android.internal.widget.LockPatternUtils;
Rubin Xu010116a2019-09-11 17:36:37 +010060import com.android.internal.widget.LockscreenCredential;
Maurice Lam2eb170c2017-04-28 16:18:47 -070061import com.android.settings.EncryptionInterstitial;
62import com.android.settings.EventLogTags;
63import com.android.settings.R;
64import com.android.settings.SettingsActivity;
65import com.android.settings.SettingsPreferenceFragment;
66import com.android.settings.Utils;
Kevin Chyn5ab064f2019-04-12 15:19:12 -070067import com.android.settings.biometrics.BiometricEnrollActivity;
Kevin Chyn4882e872018-06-25 17:58:31 -070068import com.android.settings.biometrics.BiometricEnrollBase;
Kevin Chyn81dc0292018-06-28 14:59:38 -070069import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
Raff Tsai4778a9a2018-08-29 23:22:12 +080070import com.android.settings.search.SearchFeatureProvider;
Maurice Lam2eb170c2017-04-28 16:18:47 -070071import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
Philip P. Moltmanne3f72112018-08-28 15:01:43 -070072import com.android.settingslib.RestrictedLockUtilsInternal;
Sudheer Shanka9c324682016-01-18 11:17:23 +000073import com.android.settingslib.RestrictedPreference;
74
Raff Tsaic8987752019-10-18 09:57:49 +080075import com.google.android.setupcompat.util.WizardManagerHelper;
Ricky Wai751de372016-04-06 15:28:28 +010076
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080077public class ChooseLockGeneric extends SettingsActivity {
Jim Miller0698a212014-10-16 19:49:07 -070078 public static final String CONFIRM_CREDENTIALS = "confirm_credentials";
Dianne Hackbornabc3dc62010-01-20 13:40:19 -080079
80 @Override
Jim Miller17e9e192010-12-07 20:41:41 -080081 public Intent getIntent() {
82 Intent modIntent = new Intent(super.getIntent());
Maurice Lam52c75ba2014-11-25 14:06:38 -080083 modIntent.putExtra(EXTRA_SHOW_FRAGMENT, getFragmentClass().getName());
Jim Miller17e9e192010-12-07 20:41:41 -080084 return modIntent;
85 }
Jim Millerbbb4afa2010-04-08 19:40:19 -070086
Amith Yamasania677ee22013-07-26 13:38:41 -070087 @Override
88 protected boolean isValidFragment(String fragmentName) {
89 if (ChooseLockGenericFragment.class.getName().equals(fragmentName)) return true;
90 return false;
91 }
92
Maurice Lam52c75ba2014-11-25 14:06:38 -080093 /* package */ Class<? extends Fragment> getFragmentClass() {
94 return ChooseLockGenericFragment.class;
95 }
96
Amith Yamasani66026772013-09-25 14:05:33 -070097 public static class InternalActivity extends ChooseLockGeneric {
98 }
99
Jim Miller17e9e192010-12-07 20:41:41 -0800100 public static class ChooseLockGenericFragment extends SettingsPreferenceFragment {
Maurice Lamedb39442017-04-27 18:54:33 -0700101
Jim Miller3fb2fb82015-03-11 20:17:39 -0700102 private static final String TAG = "ChooseLockGenericFragment";
Steven Ng4fdcec72016-09-26 22:13:08 +0100103 private static final String KEY_SKIP_FINGERPRINT = "unlock_skip_fingerprint";
Kevin Chyn81dc0292018-06-28 14:59:38 -0700104 private static final String KEY_SKIP_FACE = "unlock_skip_face";
Jim Miller17e9e192010-12-07 20:41:41 -0800105 private static final String PASSWORD_CONFIRMED = "password_confirmed";
Jim Miller47f1cd42012-04-27 18:11:03 -0700106 private static final String WAITING_FOR_CONFIRMATION = "waiting_for_confirmation";
Brian Carlstromd4023b72011-05-25 13:24:20 -0700107 public static final String MINIMUM_QUALITY_KEY = "minimum_quality";
Jim Miller3fb2fb82015-03-11 20:17:39 -0700108 public static final String HIDE_DISABLED_PREFS = "hide_disabled_prefs";
Lucky Zhang3bcea022014-11-25 18:22:14 -0800109 public static final String TAG_FRP_WARNING_DIALOG = "frp_warning_dialog";
Sunny Shao1bebe192019-08-12 20:33:47 +0800110 public static final String KEY_LOCK_SETTINGS_FOOTER ="lock_settings_footer";
Jim Millerbbb4afa2010-04-08 19:40:19 -0700111
Maurice Lamedb39442017-04-27 18:54:33 -0700112 /**
113 * Boolean extra determining whether a "screen lock options" button should be shown. This
114 * extra is both sent and received by ChooseLockGeneric.
115 *
116 * When this extra is false, nothing will be done.
117 * When ChooseLockGeneric receives this extra set as true, and if ChooseLockGeneric is
118 * starting ChooseLockPassword or ChooseLockPattern automatically without user interaction,
119 * ChooseLockGeneric will set this extra to true when starting ChooseLockPassword/Pattern.
120 *
121 * This gives the user the choice to select a different screen lock type, even if
122 * ChooseLockGeneric selected a default.
123 */
124 public static final String EXTRA_SHOW_OPTIONS_BUTTON = "show_options_button";
125
126 /**
127 * Original intent extras used to start this activity. This is passed to ChooseLockPassword
128 * when the "screen lock options" button is shown, so that when that button is clicked,
129 * ChooseLockGeneric can be relaunched with the same extras.
130 */
131 public static final String EXTRA_CHOOSE_LOCK_GENERIC_EXTRAS = "choose_lock_generic_extras";
132
Doris Ling06d264d2018-06-12 16:33:05 -0700133 @VisibleForTesting
134 static final int CONFIRM_EXISTING_REQUEST = 100;
Raff Tsai4778a9a2018-08-29 23:22:12 +0800135 @VisibleForTesting
136 static final int ENABLE_ENCRYPTION_REQUEST = 101;
137 @VisibleForTesting
138 static final int CHOOSE_LOCK_REQUEST = 102;
139 @VisibleForTesting
Kevin Chyn5ab064f2019-04-12 15:19:12 -0700140 static final int CHOOSE_LOCK_BEFORE_BIOMETRIC_REQUEST = 103;
Raff Tsai4778a9a2018-08-29 23:22:12 +0800141 @VisibleForTesting
142 static final int SKIP_FINGERPRINT_REQUEST = 104;
Danielle Millett80412e72011-10-17 19:21:19 -0400143
Jim Miller17e9e192010-12-07 20:41:41 -0800144 private ChooseLockSettingsHelper mChooseLockSettingsHelper;
145 private DevicePolicyManager mDPM;
Andres Morales6609b0c2015-04-12 15:38:25 -0700146 private boolean mHasChallenge = false;
147 private long mChallenge;
Jim Miller17e9e192010-12-07 20:41:41 -0800148 private boolean mPasswordConfirmed = false;
Jim Miller47f1cd42012-04-27 18:11:03 -0700149 private boolean mWaitingForConfirmation = false;
Adrian Roos62775bf2016-01-28 13:23:53 -0800150 private boolean mForChangeCredRequiredForBoot = false;
Rubin Xu010116a2019-09-11 17:36:37 +0100151 private LockscreenCredential mUserPassword;
Jim Miller0698a212014-10-16 19:49:07 -0700152 private LockPatternUtils mLockPatternUtils;
Jim Miller92186872015-03-04 18:07:32 -0800153 private FingerprintManager mFingerprintManager;
Kevin Chyn0b956872018-06-29 13:09:32 -0700154 private FaceManager mFaceManager;
Clara Bayarrife432e82015-10-12 12:07:02 +0100155 private int mUserId;
Toni Barzice7d6e4d2016-03-30 11:43:19 -0700156 private ManagedLockPasswordProvider mManagedPasswordProvider;
Steven Ng4fdcec72016-09-26 22:13:08 +0100157 private boolean mIsSetNewPassword = false;
Kevin Chynae16e552017-04-14 13:33:21 -0700158 private UserManager mUserManager;
Maurice Lamedb39442017-04-27 18:54:33 -0700159 private ChooseLockGenericController mController;
Jim Millerbbb4afa2010-04-08 19:40:19 -0700160
Bernard Chau92db5bf2018-12-17 18:03:24 +0000161 /**
162 * From intent extra {@link ChooseLockSettingsHelper#EXTRA_KEY_REQUESTED_MIN_COMPLEXITY}.
163 */
164 @PasswordComplexity private int mRequestedMinComplexity;
165
166 /** From intent extra {@link ChooseLockSettingsHelper#EXTRA_KEY_CALLER_APP_NAME}. */
167 private String mCallerAppName = null;
168
Alex Kershaw29d2bff2019-05-17 15:36:28 +0100169 /**
170 * The value from the intent extra {@link
171 * ChooseLockSettingsHelper#EXTRA_KEY_IS_CALLING_APP_ADMIN}.
172 */
173 private boolean mIsCallingAppAdmin;
174
Udam Saini8ef4c622016-02-03 17:31:11 -0800175 protected boolean mForFingerprint = false;
Kevin Chyn81dc0292018-06-28 14:59:38 -0700176 protected boolean mForFace = false;
Udam Saini8ef4c622016-02-03 17:31:11 -0800177
Jim Miller17e9e192010-12-07 20:41:41 -0800178 @Override
Fan Zhang65076132016-08-08 10:25:13 -0700179 public int getMetricsCategory() {
Fan Zhang31b21002019-01-16 13:49:47 -0800180 return SettingsEnums.CHOOSE_LOCK_GENERIC;
Chris Wren8a963ba2015-03-20 10:29:14 -0400181 }
182
183 @Override
Jim Miller17e9e192010-12-07 20:41:41 -0800184 public void onCreate(Bundle savedInstanceState) {
185 super.onCreate(savedInstanceState);
Doris Ling882bef32018-07-31 14:04:44 -0700186 final Activity activity = getActivity();
Raff Tsaic8987752019-10-18 09:57:49 +0800187 if (!WizardManagerHelper.isDeviceProvisioned(activity)
188 && !canRunBeforeDeviceProvisioned()) {
Maurice Lame7cad182019-03-29 10:58:54 -0700189 Log.i(TAG, "Refusing to start because device is not provisioned");
Doris Ling882bef32018-07-31 14:04:44 -0700190 activity.finish();
191 return;
192 }
Jim Miller17e9e192010-12-07 20:41:41 -0800193
Steven Ng4fdcec72016-09-26 22:13:08 +0100194 String chooseLockAction = getActivity().getIntent().getAction();
Jeff Sharkeyab508072016-10-11 14:25:22 -0600195 mFingerprintManager = Utils.getFingerprintManagerOrNull(getActivity());
Kevin Chyn0b956872018-06-29 13:09:32 -0700196 mFaceManager = Utils.getFaceManagerOrNull(getActivity());
Jim Miller17e9e192010-12-07 20:41:41 -0800197 mDPM = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);
198 mChooseLockSettingsHelper = new ChooseLockSettingsHelper(this.getActivity());
Jim Miller0698a212014-10-16 19:49:07 -0700199 mLockPatternUtils = new LockPatternUtils(getActivity());
Steven Ng4fdcec72016-09-26 22:13:08 +0100200 mIsSetNewPassword = ACTION_SET_NEW_PARENT_PROFILE_PASSWORD.equals(chooseLockAction)
201 || ACTION_SET_NEW_PASSWORD.equals(chooseLockAction);
Jim Miller17e9e192010-12-07 20:41:41 -0800202
Danielle Millettc474a882011-09-14 11:42:06 -0400203 // Defaults to needing to confirm credentials
204 final boolean confirmCredentials = getActivity().getIntent()
205 .getBooleanExtra(CONFIRM_CREDENTIALS, true);
Amith Yamasani66026772013-09-25 14:05:33 -0700206 if (getActivity() instanceof ChooseLockGeneric.InternalActivity) {
207 mPasswordConfirmed = !confirmCredentials;
Rubin Xu010116a2019-09-11 17:36:37 +0100208 mUserPassword = getActivity().getIntent().getParcelableExtra(
Pavel Grafov40e187b2017-10-11 22:57:09 +0100209 ChooseLockSettingsHelper.EXTRA_KEY_PASSWORD);
Amith Yamasani66026772013-09-25 14:05:33 -0700210 }
Danielle Millettc474a882011-09-14 11:42:06 -0400211
Andres Morales6609b0c2015-04-12 15:38:25 -0700212 mHasChallenge = getActivity().getIntent().getBooleanExtra(
213 ChooseLockSettingsHelper.EXTRA_KEY_HAS_CHALLENGE, false);
214 mChallenge = getActivity().getIntent().getLongExtra(
215 ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE, 0);
Maurice Lamc0e78792015-07-20 14:49:29 -0700216 mForFingerprint = getActivity().getIntent().getBooleanExtra(
217 ChooseLockSettingsHelper.EXTRA_KEY_FOR_FINGERPRINT, false);
Kevin Chyn81dc0292018-06-28 14:59:38 -0700218 mForFace = getActivity().getIntent().getBooleanExtra(
219 ChooseLockSettingsHelper.EXTRA_KEY_FOR_FACE, false);
Bernard Chau92db5bf2018-12-17 18:03:24 +0000220 mRequestedMinComplexity = getActivity().getIntent()
221 .getIntExtra(EXTRA_KEY_REQUESTED_MIN_COMPLEXITY, PASSWORD_COMPLEXITY_NONE);
222 mCallerAppName =
223 getActivity().getIntent().getStringExtra(EXTRA_KEY_CALLER_APP_NAME);
Alex Kershaw29d2bff2019-05-17 15:36:28 +0100224 mIsCallingAppAdmin = getActivity().getIntent()
225 .getBooleanExtra(EXTRA_KEY_IS_CALLING_APP_ADMIN, /* defValue= */ false);
Adrian Roos62775bf2016-01-28 13:23:53 -0800226 mForChangeCredRequiredForBoot = getArguments() != null && getArguments().getBoolean(
227 ChooseLockSettingsHelper.EXTRA_KEY_FOR_CHANGE_CRED_REQUIRED_FOR_BOOT);
Kevin Chynae16e552017-04-14 13:33:21 -0700228 mUserManager = UserManager.get(getActivity());
Andres Morales6609b0c2015-04-12 15:38:25 -0700229
Jim Miller17e9e192010-12-07 20:41:41 -0800230 if (savedInstanceState != null) {
231 mPasswordConfirmed = savedInstanceState.getBoolean(PASSWORD_CONFIRMED);
Jim Miller47f1cd42012-04-27 18:11:03 -0700232 mWaitingForConfirmation = savedInstanceState.getBoolean(WAITING_FOR_CONFIRMATION);
Pavel Grafov40e187b2017-10-11 22:57:09 +0100233 if (mUserPassword == null) {
Rubin Xu010116a2019-09-11 17:36:37 +0100234 mUserPassword = savedInstanceState.getParcelable(
Pavel Grafov40e187b2017-10-11 22:57:09 +0100235 ChooseLockSettingsHelper.EXTRA_KEY_PASSWORD);
236 }
Jim Miller17e9e192010-12-07 20:41:41 -0800237 }
238
Tony Mak8f41b9b2016-11-23 11:36:18 +0000239 // a) If this is started from other user, use that user id.
240 // b) If this is started from the same user, read the extra if this is launched
241 // from Settings app itself.
242 // c) Otherwise, use UserHandle.myUserId().
243 mUserId = Utils.getSecureTargetUser(
Benjamin Franzae07b502016-01-08 17:16:19 +0000244 getActivity().getActivityToken(),
245 UserManager.get(getActivity()),
Tony Mak8f41b9b2016-11-23 11:36:18 +0000246 getArguments(),
Benjamin Franzae07b502016-01-08 17:16:19 +0000247 getActivity().getIntent().getExtras()).getIdentifier();
Lenka Trochtovabb8e8172019-01-25 17:21:54 +0100248 mController = new ChooseLockGenericController(
249 getContext(), mUserId, mRequestedMinComplexity, mLockPatternUtils);
Steven Ng4fdcec72016-09-26 22:13:08 +0100250 if (ACTION_SET_NEW_PASSWORD.equals(chooseLockAction)
Robin Lee78867162016-09-12 16:25:28 +0900251 && UserManager.get(getActivity()).isManagedProfile(mUserId)
Mahaver Choprabc18b402016-05-04 13:11:17 +0100252 && mLockPatternUtils.isSeparateProfileChallengeEnabled(mUserId)) {
253 getActivity().setTitle(R.string.lock_settings_picker_title_profile);
254 }
255
Toni Barzice7d6e4d2016-03-30 11:43:19 -0700256 mManagedPasswordProvider = ManagedLockPasswordProvider.get(getActivity(), mUserId);
257
Jim Miller47f1cd42012-04-27 18:11:03 -0700258 if (mPasswordConfirmed) {
Maurice Lam2bb62382017-08-15 16:26:05 -0700259 updatePreferencesOrFinish(savedInstanceState != null);
Adrian Roos62775bf2016-01-28 13:23:53 -0800260 if (mForChangeCredRequiredForBoot) {
261 maybeEnableEncryption(mLockPatternUtils.getKeyguardStoredPasswordQuality(
262 mUserId), false);
263 }
Jim Miller47f1cd42012-04-27 18:11:03 -0700264 } else if (!mWaitingForConfirmation) {
Andy Stadler6370c872011-01-21 16:25:22 -0800265 ChooseLockSettingsHelper helper =
266 new ChooseLockSettingsHelper(this.getActivity(), this);
Robin Lee78867162016-09-12 16:25:28 +0900267 boolean managedProfileWithUnifiedLock =
268 UserManager.get(getActivity()).isManagedProfile(mUserId)
Ricky Wai4bbf0652016-04-01 16:31:56 +0100269 && !mLockPatternUtils.isSeparateProfileChallengeEnabled(mUserId);
Rubin Xuc5489772018-03-28 15:14:35 +0100270 boolean skipConfirmation = managedProfileWithUnifiedLock && !mIsSetNewPassword;
271 if (skipConfirmation
Ricky Wai4bbf0652016-04-01 16:31:56 +0100272 || !helper.launchConfirmationActivity(CONFIRM_EXISTING_REQUEST,
Clara Bayarrife432e82015-10-12 12:07:02 +0100273 getString(R.string.unlock_set_unlock_launch_picker_title), true, mUserId)) {
Jim Miller17e9e192010-12-07 20:41:41 -0800274 mPasswordConfirmed = true; // no password set, so no need to confirm
Maurice Lam2bb62382017-08-15 16:26:05 -0700275 updatePreferencesOrFinish(savedInstanceState != null);
Jim Miller47f1cd42012-04-27 18:11:03 -0700276 } else {
277 mWaitingForConfirmation = true;
Jim Miller17e9e192010-12-07 20:41:41 -0800278 }
Jim Millerbbb4afa2010-04-08 19:40:19 -0700279 }
Udam Saini8ef4c622016-02-03 17:31:11 -0800280 addHeaderView();
281 }
282
Doris Ling882bef32018-07-31 14:04:44 -0700283 protected boolean canRunBeforeDeviceProvisioned() {
284 return false;
285 }
286
Doris Ling3e6d80c2018-10-16 17:11:54 -0700287 protected Class<? extends ChooseLockGeneric.InternalActivity> getInternalActivityClass() {
288 return ChooseLockGeneric.InternalActivity.class;
289 }
290
Udam Saini8ef4c622016-02-03 17:31:11 -0800291 protected void addHeaderView() {
Maurice Lam87fadbe2015-08-03 15:33:25 -0700292 if (mForFingerprint) {
Jason Monk39b46742015-09-10 15:52:51 -0400293 setHeaderView(R.layout.choose_lock_generic_fingerprint_header);
Steven Ng4fdcec72016-09-26 22:13:08 +0100294 if (mIsSetNewPassword) {
295 ((TextView) getHeaderView().findViewById(R.id.fingerprint_header_description))
296 .setText(R.string.fingerprint_unlock_title);
297 }
Kevin Chyn81dc0292018-06-28 14:59:38 -0700298 } else if (mForFace) {
299 setHeaderView(R.layout.choose_lock_generic_face_header);
300 if (mIsSetNewPassword) {
301 ((TextView) getHeaderView().findViewById(R.id.face_header_description))
302 .setText(R.string.face_unlock_title);
303 }
Maurice Lam87fadbe2015-08-03 15:33:25 -0700304 }
305 }
306
307 @Override
Jason Monk39b46742015-09-10 15:52:51 -0400308 public boolean onPreferenceTreeClick(Preference preference) {
Jim Miller17e9e192010-12-07 20:41:41 -0800309 final String key = preference.getKey();
rich cannings27d6f8d2013-05-29 14:54:58 -0700310
Clara Bayarrife432e82015-10-12 12:07:02 +0100311 if (!isUnlockMethodSecure(key) && mLockPatternUtils.isSecure(mUserId)) {
Lucky Zhang3bcea022014-11-25 18:22:14 -0800312 // Show the disabling FRP warning only when the user is switching from a secure
313 // unlock method to an insecure one
314 showFactoryResetProtectionWarningDialog(key);
315 return true;
Kevin Chyn81dc0292018-06-28 14:59:38 -0700316 } else if (KEY_SKIP_FINGERPRINT.equals(key) || KEY_SKIP_FACE.equals(key)) {
Steven Ng436256c2017-02-23 10:34:28 +0000317 Intent chooseLockGenericIntent = new Intent(getActivity(),
Doris Ling3e6d80c2018-10-16 17:11:54 -0700318 getInternalActivityClass());
Steven Ng4fdcec72016-09-26 22:13:08 +0100319 chooseLockGenericIntent.setAction(getIntent().getAction());
Tony Mak8f41b9b2016-11-23 11:36:18 +0000320 // Forward the target user id to ChooseLockGeneric.
321 chooseLockGenericIntent.putExtra(Intent.EXTRA_USER_ID, mUserId);
Steven Ng436256c2017-02-23 10:34:28 +0000322 chooseLockGenericIntent.putExtra(CONFIRM_CREDENTIALS, !mPasswordConfirmed);
Bernard Chau92db5bf2018-12-17 18:03:24 +0000323 chooseLockGenericIntent.putExtra(EXTRA_KEY_REQUESTED_MIN_COMPLEXITY,
324 mRequestedMinComplexity);
325 chooseLockGenericIntent.putExtra(EXTRA_KEY_CALLER_APP_NAME, mCallerAppName);
Pavel Grafov40e187b2017-10-11 22:57:09 +0100326 if (mUserPassword != null) {
327 chooseLockGenericIntent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_PASSWORD,
328 mUserPassword);
329 }
Steven Ng4fdcec72016-09-26 22:13:08 +0100330 startActivityForResult(chooseLockGenericIntent, SKIP_FINGERPRINT_REQUEST);
331 return true;
Jim Miller17e9e192010-12-07 20:41:41 -0800332 } else {
Lucky Zhang3bcea022014-11-25 18:22:14 -0800333 return setUnlockMethod(key);
Jim Miller17e9e192010-12-07 20:41:41 -0800334 }
Jim Millerbbb4afa2010-04-08 19:40:19 -0700335 }
Jim Millerbbb4afa2010-04-08 19:40:19 -0700336
Jim Miller46c7f6d2014-10-13 18:15:17 -0700337 /**
338 * If the device has encryption already enabled, then ask the user if they
339 * also want to encrypt the phone with this password.
340 *
341 * @param quality
342 * @param disabled
343 */
Andres Moralesa0e12362015-04-02 09:00:41 -0700344 // TODO: why does this take disabled, its always called with a quality higher than
345 // what makes sense with disabled == true
Jim Miller46c7f6d2014-10-13 18:15:17 -0700346 private void maybeEnableEncryption(int quality, boolean disabled) {
Andrei Kapishnikov146fc112015-04-09 11:08:16 -0400347 DevicePolicyManager dpm = (DevicePolicyManager) getSystemService(DEVICE_POLICY_SERVICE);
Xiaohui Chenf9ee84d2015-10-21 11:25:35 -0700348 if (UserManager.get(getActivity()).isAdminUser()
Clara Bayarri93bcfcb2015-10-16 12:36:57 +0100349 && mUserId == UserHandle.myUserId()
Xiaohui Chenf9ee84d2015-10-21 11:25:35 -0700350 && LockPatternUtils.isDeviceEncryptionEnabled()
Paul Lawrencefb4c5832016-01-29 13:25:36 -0800351 && !LockPatternUtils.isFileEncryptionEnabled()
Andrei Kapishnikov146fc112015-04-09 11:08:16 -0400352 && !dpm.getDoNotAskCredentialsOnBoot()) {
Udam Sainiedac1362015-12-08 17:28:19 -0800353 // Get the intent that the encryption interstitial should start for creating
354 // the new unlock method.
Maurice Lam2eb170c2017-04-28 16:18:47 -0700355 Intent unlockMethodIntent = getIntentForUnlockMethod(quality);
Adrian Roos62775bf2016-01-28 13:23:53 -0800356 unlockMethodIntent.putExtra(
357 ChooseLockSettingsHelper.EXTRA_KEY_FOR_CHANGE_CRED_REQUIRED_FOR_BOOT,
358 mForChangeCredRequiredForBoot);
Maurice Lamecd2b7b2014-12-01 10:41:49 -0800359 final Context context = getActivity();
Jim Miller0698a212014-10-16 19:49:07 -0700360 // If accessibility is enabled and the user hasn't seen this dialog before, set the
361 // default state to agree with that which is compatible with accessibility
362 // (password not required).
Maurice Lamecd2b7b2014-12-01 10:41:49 -0800363 final boolean accEn = AccessibilityManager.getInstance(context).isEnabled();
Jim Miller0698a212014-10-16 19:49:07 -0700364 final boolean required = mLockPatternUtils.isCredentialRequiredToDecrypt(!accEn);
Udam Sainiedac1362015-12-08 17:28:19 -0800365 Intent intent = getEncryptionInterstitialIntent(context, quality, required,
366 unlockMethodIntent);
Maurice Lamc0e78792015-07-20 14:49:29 -0700367 intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_FOR_FINGERPRINT,
368 mForFingerprint);
Kevin Chyn81dc0292018-06-28 14:59:38 -0700369 intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_FOR_FACE,
370 mForFace);
Steven Ng378dec12016-10-25 17:23:30 +0100371 startActivityForResult(
372 intent,
373 mIsSetNewPassword && mHasChallenge
Kevin Chyn5ab064f2019-04-12 15:19:12 -0700374 ? CHOOSE_LOCK_BEFORE_BIOMETRIC_REQUEST
Steven Ng378dec12016-10-25 17:23:30 +0100375 : ENABLE_ENCRYPTION_REQUEST);
Jim Miller46c7f6d2014-10-13 18:15:17 -0700376 } else {
Adrian Roos62775bf2016-01-28 13:23:53 -0800377 if (mForChangeCredRequiredForBoot) {
378 // Welp, couldn't change it. Oh well.
379 finish();
380 return;
381 }
Maurice Lamedb39442017-04-27 18:54:33 -0700382 updateUnlockMethodAndFinish(quality, disabled, false /* chooseLockSkipped */);
Jim Miller46c7f6d2014-10-13 18:15:17 -0700383 }
384 }
385
Jim Miller17e9e192010-12-07 20:41:41 -0800386 @Override
387 public void onActivityResult(int requestCode, int resultCode, Intent data) {
388 super.onActivityResult(requestCode, resultCode, data);
Jim Miller47f1cd42012-04-27 18:11:03 -0700389 mWaitingForConfirmation = false;
Jim Miller17e9e192010-12-07 20:41:41 -0800390 if (requestCode == CONFIRM_EXISTING_REQUEST && resultCode == Activity.RESULT_OK) {
391 mPasswordConfirmed = true;
Doris Ling06d264d2018-06-12 16:33:05 -0700392 mUserPassword = data != null
Rubin Xu010116a2019-09-11 17:36:37 +0100393 ? data.getParcelableExtra(ChooseLockSettingsHelper.EXTRA_KEY_PASSWORD)
Doris Ling06d264d2018-06-12 16:33:05 -0700394 : null;
Maurice Lam2bb62382017-08-15 16:26:05 -0700395 updatePreferencesOrFinish(false /* isRecreatingActivity */);
Adrian Roos62775bf2016-01-28 13:23:53 -0800396 if (mForChangeCredRequiredForBoot) {
Rubin Xu010116a2019-09-11 17:36:37 +0100397 if (mUserPassword != null && !mUserPassword.isNone()) {
Adrian Roos62775bf2016-01-28 13:23:53 -0800398 maybeEnableEncryption(
399 mLockPatternUtils.getKeyguardStoredPasswordQuality(mUserId), false);
400 } else {
401 finish();
402 }
403 }
Maurice Lame9d2abc2015-12-14 18:03:54 -0800404 } else if (requestCode == CHOOSE_LOCK_REQUEST
405 || requestCode == ENABLE_ENCRYPTION_REQUEST) {
Adrian Roos77181e92016-02-25 15:43:24 -0800406 if (resultCode != RESULT_CANCELED || mForChangeCredRequiredForBoot) {
Maurice Lame9d2abc2015-12-14 18:03:54 -0800407 getActivity().setResult(resultCode, data);
408 finish();
Maurice Lamedb39442017-04-27 18:54:33 -0700409 } else {
410 // If PASSWORD_TYPE_KEY is set, this activity is used as a trampoline to start
411 // the actual password enrollment. If the result is canceled, which means the
412 // user pressed back, finish the activity with result canceled.
413 int quality = getIntent().getIntExtra(LockPatternUtils.PASSWORD_TYPE_KEY, -1);
414 if (quality != -1) {
415 getActivity().setResult(RESULT_CANCELED, data);
416 finish();
417 }
Maurice Lame9d2abc2015-12-14 18:03:54 -0800418 }
Kevin Chyn5ab064f2019-04-12 15:19:12 -0700419 } else if (requestCode == CHOOSE_LOCK_BEFORE_BIOMETRIC_REQUEST
Kevin Chyn4882e872018-06-25 17:58:31 -0700420 && resultCode == BiometricEnrollBase.RESULT_FINISHED) {
Kevin Chyn5ab064f2019-04-12 15:19:12 -0700421 Intent intent = getBiometricEnrollIntent(getActivity());
Steven Ng4fdcec72016-09-26 22:13:08 +0100422 if (data != null) {
423 intent.putExtras(data.getExtras());
424 }
Tony Mak8f41b9b2016-11-23 11:36:18 +0000425 // Forward the target user id to fingerprint setup page.
426 intent.putExtra(Intent.EXTRA_USER_ID, mUserId);
Steven Ng4fdcec72016-09-26 22:13:08 +0100427 startActivity(intent);
428 finish();
429 } else if (requestCode == SKIP_FINGERPRINT_REQUEST) {
430 if (resultCode != RESULT_CANCELED) {
431 getActivity().setResult(
432 resultCode == RESULT_FINISHED ? RESULT_OK : resultCode, data);
433 finish();
434 }
Raff Tsai4778a9a2018-08-29 23:22:12 +0800435 } else if (requestCode == SearchFeatureProvider.REQUEST_CODE) {
436 return;
Jim Miller17e9e192010-12-07 20:41:41 -0800437 } else {
438 getActivity().setResult(Activity.RESULT_CANCELED);
439 finish();
440 }
Adrian Roos62775bf2016-01-28 13:23:53 -0800441 if (requestCode == Activity.RESULT_CANCELED && mForChangeCredRequiredForBoot) {
442 finish();
443 }
Jim Miller17e9e192010-12-07 20:41:41 -0800444 }
445
Kevin Chyn5ab064f2019-04-12 15:19:12 -0700446 protected Intent getBiometricEnrollIntent(Context context) {
447 final Intent intent =
448 new Intent(context, BiometricEnrollActivity.InternalActivity.class);
449 intent.putExtra(BiometricEnrollActivity.EXTRA_SKIP_INTRO, true);
450 return intent;
Udam Sainid6b1c662016-11-01 11:20:14 -0700451 }
452
Jim Miller17e9e192010-12-07 20:41:41 -0800453 @Override
454 public void onSaveInstanceState(Bundle outState) {
455 super.onSaveInstanceState(outState);
456 // Saved so we don't force user to re-enter their password if configuration changes
457 outState.putBoolean(PASSWORD_CONFIRMED, mPasswordConfirmed);
Jim Miller47f1cd42012-04-27 18:11:03 -0700458 outState.putBoolean(WAITING_FOR_CONFIRMATION, mWaitingForConfirmation);
Pavel Grafov40e187b2017-10-11 22:57:09 +0100459 if (mUserPassword != null) {
Rubin Xu010116a2019-09-11 17:36:37 +0100460 outState.putParcelable(ChooseLockSettingsHelper.EXTRA_KEY_PASSWORD, mUserPassword);
Pavel Grafov40e187b2017-10-11 22:57:09 +0100461 }
Jim Miller17e9e192010-12-07 20:41:41 -0800462 }
463
Doris Ling06d264d2018-06-12 16:33:05 -0700464 @VisibleForTesting
465 void updatePreferencesOrFinish(boolean isRecreatingActivity) {
Jim Miller5541a862011-09-02 17:33:53 -0700466 Intent intent = getActivity().getIntent();
Maurice Lam446637e2018-10-04 19:49:08 -0700467 int quality = -1;
468 if (StorageManager.isFileEncryptedNativeOrEmulated()) {
469 quality = intent.getIntExtra(LockPatternUtils.PASSWORD_TYPE_KEY, -1);
470 } else {
471 // For non-file encrypted devices we need to show encryption interstitial, so always
472 // show the lock type picker and ignore PASSWORD_TYPE_KEY.
473 Log.i(TAG, "Ignoring PASSWORD_TYPE_KEY because device is not file encrypted");
474 }
Jim Miller17e9e192010-12-07 20:41:41 -0800475 if (quality == -1) {
Andy Stadler6370c872011-01-21 16:25:22 -0800476 // If caller didn't specify password quality, show UI and allow the user to choose.
Jim Miller5541a862011-09-02 17:33:53 -0700477 quality = intent.getIntExtra(MINIMUM_QUALITY_KEY, -1);
Maurice Lamedb39442017-04-27 18:54:33 -0700478 quality = mController.upgradeQuality(quality);
Jim Miller3fb2fb82015-03-11 20:17:39 -0700479 final boolean hideDisabledPrefs = intent.getBooleanExtra(
480 HIDE_DISABLED_PREFS, false);
Jim Miller17e9e192010-12-07 20:41:41 -0800481 final PreferenceScreen prefScreen = getPreferenceScreen();
482 if (prefScreen != null) {
483 prefScreen.removeAll();
484 }
Udam Saini8ef4c622016-02-03 17:31:11 -0800485 addPreferences();
Jim Miller3fb2fb82015-03-11 20:17:39 -0700486 disableUnusablePreferences(quality, hideDisabledPrefs);
Udam Sainibf1483c2016-01-25 08:06:57 -0800487 updatePreferenceText();
Jason Monk9a64a422015-03-30 11:00:36 -0400488 updateCurrentPreference();
Svetoslav52448442014-09-29 18:15:45 -0700489 updatePreferenceSummaryIfNeeded();
Maurice Lam2bb62382017-08-15 16:26:05 -0700490 } else if (!isRecreatingActivity) {
491 // Don't start the activity again if we are recreated for configuration change
Maurice Lamedb39442017-04-27 18:54:33 -0700492 updateUnlockMethodAndFinish(quality, false, true /* chooseLockSkipped */);
Jim Miller17e9e192010-12-07 20:41:41 -0800493 }
494 }
495
Udam Saini8ef4c622016-02-03 17:31:11 -0800496 protected void addPreferences() {
497 addPreferencesFromResource(R.xml.security_settings_picker);
Jeff Sharkeya77652f2016-04-01 23:12:45 -0600498
Sunny Shao1bebe192019-08-12 20:33:47 +0800499 final Preference footer = findPreference(KEY_LOCK_SETTINGS_FOOTER);
Alex Kershaw29d2bff2019-05-17 15:36:28 +0100500 if (!TextUtils.isEmpty(mCallerAppName) && !mIsCallingAppAdmin) {
Sunny Shao1bebe192019-08-12 20:33:47 +0800501 footer.setVisible(true);
Bernard Chau92db5bf2018-12-17 18:03:24 +0000502 footer.setTitle(getFooterString());
Sunny Shao1bebe192019-08-12 20:33:47 +0800503 } else {
504 footer.setVisible(false);
Bernard Chau92db5bf2018-12-17 18:03:24 +0000505 }
506
Jeff Sharkeya77652f2016-04-01 23:12:45 -0600507 // Used for testing purposes
Maurice Lamedb39442017-04-27 18:54:33 -0700508 findPreference(ScreenLockType.NONE.preferenceKey).setViewId(R.id.lock_none);
Jeff Sharkey159dff62016-10-04 13:43:35 -0600509 findPreference(KEY_SKIP_FINGERPRINT).setViewId(R.id.lock_none);
Kevin Chyn81dc0292018-06-28 14:59:38 -0700510 findPreference(KEY_SKIP_FACE).setViewId(R.id.lock_none);
Maurice Lamedb39442017-04-27 18:54:33 -0700511 findPreference(ScreenLockType.PIN.preferenceKey).setViewId(R.id.lock_pin);
512 findPreference(ScreenLockType.PASSWORD.preferenceKey).setViewId(R.id.lock_password);
Udam Saini8ef4c622016-02-03 17:31:11 -0800513 }
514
Bernard Chau92db5bf2018-12-17 18:03:24 +0000515 private String getFooterString() {
516 @StringRes int stringId;
517 switch (mRequestedMinComplexity) {
518 case PASSWORD_COMPLEXITY_HIGH:
519 stringId = R.string.unlock_footer_high_complexity_requested;
520 break;
521 case PASSWORD_COMPLEXITY_MEDIUM:
522 stringId = R.string.unlock_footer_medium_complexity_requested;
523 break;
524 case PASSWORD_COMPLEXITY_LOW:
525 stringId = R.string.unlock_footer_low_complexity_requested;
526 break;
527 case PASSWORD_COMPLEXITY_NONE:
528 default:
529 stringId = R.string.unlock_footer_none_complexity_requested;
530 break;
531 }
532
533 return getResources().getString(stringId, mCallerAppName);
534 }
535
Udam Sainibf1483c2016-01-25 08:06:57 -0800536 private void updatePreferenceText() {
537 if (mForFingerprint) {
Maurice Lamedb39442017-04-27 18:54:33 -0700538 setPreferenceTitle(ScreenLockType.PATTERN,
539 R.string.fingerprint_unlock_set_unlock_pattern);
540 setPreferenceTitle(ScreenLockType.PIN, R.string.fingerprint_unlock_set_unlock_pin);
541 setPreferenceTitle(ScreenLockType.PASSWORD,
542 R.string.fingerprint_unlock_set_unlock_password);
Kevin Chyn81dc0292018-06-28 14:59:38 -0700543 } else if (mForFace) {
544 setPreferenceTitle(ScreenLockType.PATTERN,
545 R.string.face_unlock_set_unlock_pattern);
546 setPreferenceTitle(ScreenLockType.PIN, R.string.face_unlock_set_unlock_pin);
547 setPreferenceTitle(ScreenLockType.PASSWORD,
548 R.string.face_unlock_set_unlock_password);
Udam Sainibf1483c2016-01-25 08:06:57 -0800549 }
Toni Barzice7d6e4d2016-03-30 11:43:19 -0700550
551 if (mManagedPasswordProvider.isSettingManagedPasswordSupported()) {
Maurice Lamedb39442017-04-27 18:54:33 -0700552 setPreferenceTitle(ScreenLockType.MANAGED,
553 mManagedPasswordProvider.getPickerOptionTitle(mForFingerprint));
Toni Barzice7d6e4d2016-03-30 11:43:19 -0700554 } else {
Maurice Lamedb39442017-04-27 18:54:33 -0700555 removePreference(ScreenLockType.MANAGED.preferenceKey);
Toni Barzice7d6e4d2016-03-30 11:43:19 -0700556 }
Steven Ng4fdcec72016-09-26 22:13:08 +0100557
558 if (!(mForFingerprint && mIsSetNewPassword)) {
559 removePreference(KEY_SKIP_FINGERPRINT);
560 }
Kevin Chyn81dc0292018-06-28 14:59:38 -0700561 if (!(mForFace && mIsSetNewPassword)) {
562 removePreference(KEY_SKIP_FACE);
563 }
Udam Sainibf1483c2016-01-25 08:06:57 -0800564 }
565
Maurice Lamedb39442017-04-27 18:54:33 -0700566 private void setPreferenceTitle(ScreenLockType lock, @StringRes int title) {
567 Preference preference = findPreference(lock.preferenceKey);
568 if (preference != null) {
569 preference.setTitle(title);
570 }
571 }
572
573 private void setPreferenceTitle(ScreenLockType lock, CharSequence title) {
574 Preference preference = findPreference(lock.preferenceKey);
575 if (preference != null) {
576 preference.setTitle(title);
577 }
578 }
579
580 private void setPreferenceSummary(ScreenLockType lock, @StringRes int summary) {
581 Preference preference = findPreference(lock.preferenceKey);
582 if (preference != null) {
583 preference.setSummary(summary);
584 }
585 }
586
Jason Monk9a64a422015-03-30 11:00:36 -0400587 private void updateCurrentPreference() {
588 String currentKey = getKeyForCurrent();
589 Preference preference = findPreference(currentKey);
590 if (preference != null) {
591 preference.setSummary(R.string.current_screen_lock);
592 }
593 }
594
595 private String getKeyForCurrent() {
Jason Monke07c947e2016-01-21 14:15:46 -0500596 final int credentialOwner = UserManager.get(getContext())
597 .getCredentialOwnerProfile(mUserId);
Clara Bayarri7402b252016-01-20 15:39:59 +0000598 if (mLockPatternUtils.isLockScreenDisabled(credentialOwner)) {
Maurice Lamedb39442017-04-27 18:54:33 -0700599 return ScreenLockType.NONE.preferenceKey;
Jason Monk9a64a422015-03-30 11:00:36 -0400600 }
Maurice Lamedb39442017-04-27 18:54:33 -0700601 ScreenLockType lock =
602 ScreenLockType.fromQuality(
603 mLockPatternUtils.getKeyguardStoredPasswordQuality(credentialOwner));
604 return lock != null ? lock.preferenceKey : null;
Brian Carlstromd4023b72011-05-25 13:24:20 -0700605 }
606
Jim Miller17e9e192010-12-07 20:41:41 -0800607 /***
Lucky Zhangdf8566a2014-12-05 15:00:20 -0800608 * Disables preferences that are less secure than required quality. The actual
609 * implementation is in disableUnusablePreferenceImpl.
610 *
611 * @param quality the requested quality.
Jim Miller3fb2fb82015-03-11 20:17:39 -0700612 * @param hideDisabledPrefs if false preferences show why they were disabled; otherwise
613 * they're not shown at all.
Lucky Zhangdf8566a2014-12-05 15:00:20 -0800614 */
Jim Miller3fb2fb82015-03-11 20:17:39 -0700615 protected void disableUnusablePreferences(final int quality, boolean hideDisabledPrefs) {
616 disableUnusablePreferencesImpl(quality, hideDisabledPrefs);
Lucky Zhangdf8566a2014-12-05 15:00:20 -0800617 }
618
619 /***
Jim Miller17e9e192010-12-07 20:41:41 -0800620 * Disables preferences that are less secure than required quality.
621 *
622 * @param quality the requested quality.
Lucky Zhangdf8566a2014-12-05 15:00:20 -0800623 * @param hideDisabled whether to hide disable screen lock options.
Jim Miller17e9e192010-12-07 20:41:41 -0800624 */
Lucky Zhangdf8566a2014-12-05 15:00:20 -0800625 protected void disableUnusablePreferencesImpl(final int quality,
Adrian Roosf7887182015-01-07 20:51:57 +0100626 boolean hideDisabled) {
Amith Yamasanicf26bb22011-09-26 10:27:43 -0700627 final PreferenceScreen entries = getPreferenceScreen();
Jim Miller783ea852012-11-01 19:39:21 -0700628
Tony Mak25c3c542016-03-18 13:48:16 +0000629 int adminEnforcedQuality = mDPM.getPasswordQuality(null, mUserId);
Philip P. Moltmanne3f72112018-08-28 15:01:43 -0700630 EnforcedAdmin enforcedAdmin = RestrictedLockUtilsInternal.checkIfPasswordQualityIsSet(
Sudheer Shankaf755baf2016-01-29 22:12:30 +0000631 getActivity(), mUserId);
Maurice Lamedb39442017-04-27 18:54:33 -0700632
633 for (ScreenLockType lock : ScreenLockType.values()) {
634 String key = lock.preferenceKey;
635 Preference pref = findPreference(key);
Sudheer Shanka9c324682016-01-18 11:17:23 +0000636 if (pref instanceof RestrictedPreference) {
Maurice Lamedb39442017-04-27 18:54:33 -0700637 boolean visible = mController.isScreenLockVisible(lock);
638 boolean enabled = mController.isScreenLockEnabled(lock, quality);
639 boolean disabledByAdmin =
640 mController.isScreenLockDisabledByAdmin(lock, adminEnforcedQuality);
Lucky Zhangdf8566a2014-12-05 15:00:20 -0800641 if (hideDisabled) {
Maurice Lamedb39442017-04-27 18:54:33 -0700642 visible = visible && enabled;
Lucky Zhangdf8566a2014-12-05 15:00:20 -0800643 }
Adrian Roosf7887182015-01-07 20:51:57 +0100644 if (!visible) {
Amith Yamasanicf26bb22011-09-26 10:27:43 -0700645 entries.removePreference(pref);
Sudheer Shanka9c324682016-01-18 11:17:23 +0000646 } else if (disabledByAdmin && enforcedAdmin != null) {
647 ((RestrictedPreference) pref).setDisabledByAdmin(enforcedAdmin);
Jim Miller5541a862011-09-02 17:33:53 -0700648 } else if (!enabled) {
Sudheer Shanka9c324682016-01-18 11:17:23 +0000649 // we need to setDisabledByAdmin to null first to disable the padlock
650 // in case it was set earlier.
651 ((RestrictedPreference) pref).setDisabledByAdmin(null);
Jim Miller17e9e192010-12-07 20:41:41 -0800652 pref.setSummary(R.string.unlock_set_unlock_disabled_summary);
653 pref.setEnabled(false);
Sudheer Shanka9c324682016-01-18 11:17:23 +0000654 } else {
655 ((RestrictedPreference) pref).setDisabledByAdmin(null);
Jim Miller17e9e192010-12-07 20:41:41 -0800656 }
657 }
658 }
659 }
660
Svetoslav52448442014-09-29 18:15:45 -0700661 private void updatePreferenceSummaryIfNeeded() {
Paul Lawrence23c2acf2016-03-10 13:54:56 -0800662 // On a default block encrypted device with accessibility, add a warning
663 // that your data is not credential encrypted
664 if (!StorageManager.isBlockEncrypted()) {
665 return;
666 }
667
668 if (StorageManager.isNonDefaultBlockEncrypted()) {
Svetoslav40ca78f2014-10-17 14:37:02 -0700669 return;
670 }
671
Svetoslav52448442014-09-29 18:15:45 -0700672 if (AccessibilityManager.getInstance(getActivity()).getEnabledAccessibilityServiceList(
673 AccessibilityServiceInfo.FEEDBACK_ALL_MASK).isEmpty()) {
674 return;
675 }
676
Maurice Lamedb39442017-04-27 18:54:33 -0700677 setPreferenceSummary(ScreenLockType.PATTERN, R.string.secure_lock_encryption_warning);
678 setPreferenceSummary(ScreenLockType.PIN, R.string.secure_lock_encryption_warning);
679 setPreferenceSummary(ScreenLockType.PASSWORD, R.string.secure_lock_encryption_warning);
680 setPreferenceSummary(ScreenLockType.MANAGED, R.string.secure_lock_encryption_warning);
Svetoslav52448442014-09-29 18:15:45 -0700681 }
682
Rubin Xu010116a2019-09-11 17:36:37 +0100683 protected Intent getLockManagedPasswordIntent(LockscreenCredential password) {
Maurice Lam2eb170c2017-04-28 16:18:47 -0700684 return mManagedPasswordProvider.createIntent(false, password);
Toni Barzice7d6e4d2016-03-30 11:43:19 -0700685 }
686
Pavel Grafov5f139102018-05-04 17:09:28 +0100687 protected Intent getLockPasswordIntent(int quality) {
Maurice Lam2eb170c2017-04-28 16:18:47 -0700688 ChooseLockPassword.IntentBuilder builder =
689 new ChooseLockPassword.IntentBuilder(getContext())
690 .setPasswordQuality(quality)
Bernard Chau92db5bf2018-12-17 18:03:24 +0000691 .setRequestedMinComplexity(mRequestedMinComplexity)
Maurice Lamb49526e2017-05-31 17:55:43 -0700692 .setForFingerprint(mForFingerprint)
Kevin Chyn81dc0292018-06-28 14:59:38 -0700693 .setForFace(mForFace)
Maurice Lam2eb170c2017-04-28 16:18:47 -0700694 .setUserId(mUserId);
695 if (mHasChallenge) {
696 builder.setChallenge(mChallenge);
Pavel Grafov40e187b2017-10-11 22:57:09 +0100697 }
698 if (mUserPassword != null) {
Maurice Lam2eb170c2017-04-28 16:18:47 -0700699 builder.setPassword(mUserPassword);
700 }
701 return builder.build();
Maurice Lam6b19fa92014-11-25 19:25:56 -0800702 }
703
Maurice Lam2eb170c2017-04-28 16:18:47 -0700704 protected Intent getLockPatternIntent() {
705 ChooseLockPattern.IntentBuilder builder =
706 new ChooseLockPattern.IntentBuilder(getContext())
Maurice Lamb49526e2017-05-31 17:55:43 -0700707 .setForFingerprint(mForFingerprint)
Kevin Chyn81dc0292018-06-28 14:59:38 -0700708 .setForFace(mForFace)
Maurice Lam2eb170c2017-04-28 16:18:47 -0700709 .setUserId(mUserId);
710 if (mHasChallenge) {
711 builder.setChallenge(mChallenge);
Pavel Grafov40e187b2017-10-11 22:57:09 +0100712 }
713 if (mUserPassword != null) {
Maurice Lam2eb170c2017-04-28 16:18:47 -0700714 builder.setPattern(mUserPassword);
715 }
716 return builder.build();
Andres Moralesa0e12362015-04-02 09:00:41 -0700717 }
718
Maurice Lamecd2b7b2014-12-01 10:41:49 -0800719 protected Intent getEncryptionInterstitialIntent(Context context, int quality,
Udam Sainiedac1362015-12-08 17:28:19 -0800720 boolean required, Intent unlockMethodIntent) {
721 return EncryptionInterstitial.createStartIntent(context, quality, required,
722 unlockMethodIntent);
Maurice Lamecd2b7b2014-12-01 10:41:49 -0800723 }
724
Jim Miller5541a862011-09-02 17:33:53 -0700725 /**
Jim Miller17e9e192010-12-07 20:41:41 -0800726 * Invokes an activity to change the user's pattern, password or PIN based on given quality
727 * and minimum quality specified by DevicePolicyManager. If quality is
728 * {@link DevicePolicyManager#PASSWORD_QUALITY_UNSPECIFIED}, password is cleared.
729 *
Andy Stadler6370c872011-01-21 16:25:22 -0800730 * @param quality the desired quality. Ignored if DevicePolicyManager requires more security
Jim Miller17e9e192010-12-07 20:41:41 -0800731 * @param disabled whether or not to show LockScreen at all. Only meaningful when quality is
Maurice Lamedb39442017-04-27 18:54:33 -0700732 * @param chooseLockSkipped whether or not this activity is skipped. This is true when this
733 * activity was not shown to the user at all, instead automatically proceeding based on
734 * the given intent extras, typically {@link LockPatternUtils#PASSWORD_TYPE_KEY}.
Jim Miller17e9e192010-12-07 20:41:41 -0800735 * {@link DevicePolicyManager#PASSWORD_QUALITY_UNSPECIFIED}
736 */
Maurice Lamedb39442017-04-27 18:54:33 -0700737 void updateUnlockMethodAndFinish(int quality, boolean disabled, boolean chooseLockSkipped) {
Andy Stadler6370c872011-01-21 16:25:22 -0800738 // Sanity check. We should never get here without confirming user's existing password.
Jim Miller17e9e192010-12-07 20:41:41 -0800739 if (!mPasswordConfirmed) {
Andy Stadler6370c872011-01-21 16:25:22 -0800740 throw new IllegalStateException("Tried to update password without confirming it");
Jim Miller17e9e192010-12-07 20:41:41 -0800741 }
742
Maurice Lamedb39442017-04-27 18:54:33 -0700743 quality = mController.upgradeQuality(quality);
Maurice Lam2eb170c2017-04-28 16:18:47 -0700744 Intent intent = getIntentForUnlockMethod(quality);
Udam Sainiedac1362015-12-08 17:28:19 -0800745 if (intent != null) {
Maurice Lamedb39442017-04-27 18:54:33 -0700746 if (getIntent().getBooleanExtra(EXTRA_SHOW_OPTIONS_BUTTON, false)) {
747 intent.putExtra(EXTRA_SHOW_OPTIONS_BUTTON, chooseLockSkipped);
748 }
749 intent.putExtra(EXTRA_CHOOSE_LOCK_GENERIC_EXTRAS, getIntent().getExtras());
Steven Ng4fdcec72016-09-26 22:13:08 +0100750 startActivityForResult(intent,
751 mIsSetNewPassword && mHasChallenge
Kevin Chyn5ab064f2019-04-12 15:19:12 -0700752 ? CHOOSE_LOCK_BEFORE_BIOMETRIC_REQUEST
Steven Ng4fdcec72016-09-26 22:13:08 +0100753 : CHOOSE_LOCK_REQUEST);
Udam Sainiedac1362015-12-08 17:28:19 -0800754 return;
755 }
Steven Rossc620ba42011-09-28 15:43:41 -0400756
Udam Sainiedac1362015-12-08 17:28:19 -0800757 if (quality == DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED) {
Alex Johnstona0351e22019-10-03 16:02:41 +0100758 // Clearing of user biometrics when screen lock is cleared is done at
759 // LockSettingsService.removeBiometricsForUser().
Rubin Xu3bf2e702019-10-15 23:51:10 +0100760 if (mUserPassword != null) {
761 // No need to call setLockCredential if the user currently doesn't
762 // have a password
763 mChooseLockSettingsHelper.utils().setLockCredential(
764 LockscreenCredential.createNone(), mUserPassword, mUserId);
765 }
Clara Bayarrife432e82015-10-12 12:07:02 +0100766 mChooseLockSettingsHelper.utils().setLockScreenDisabled(disabled, mUserId);
Jim Miller17e9e192010-12-07 20:41:41 -0800767 getActivity().setResult(Activity.RESULT_OK);
Alex Johnstona0351e22019-10-03 16:02:41 +0100768 finish();
Jim Miller17e9e192010-12-07 20:41:41 -0800769 }
Jim Millerbbb4afa2010-04-08 19:40:19 -0700770 }
Amith Yamasanib0b37ae2012-04-23 15:35:36 -0700771
Maurice Lam2eb170c2017-04-28 16:18:47 -0700772 private Intent getIntentForUnlockMethod(int quality) {
Udam Sainiedac1362015-12-08 17:28:19 -0800773 Intent intent = null;
Toni Barzice7d6e4d2016-03-30 11:43:19 -0700774 if (quality >= DevicePolicyManager.PASSWORD_QUALITY_MANAGED) {
Maurice Lam2eb170c2017-04-28 16:18:47 -0700775 intent = getLockManagedPasswordIntent(mUserPassword);
Toni Barzice7d6e4d2016-03-30 11:43:19 -0700776 } else if (quality >= DevicePolicyManager.PASSWORD_QUALITY_NUMERIC) {
Pavel Grafov5f139102018-05-04 17:09:28 +0100777 intent = getLockPasswordIntent(quality);
Udam Sainiedac1362015-12-08 17:28:19 -0800778 } else if (quality == DevicePolicyManager.PASSWORD_QUALITY_SOMETHING) {
Maurice Lam2eb170c2017-04-28 16:18:47 -0700779 intent = getLockPatternIntent();
Udam Sainiedac1362015-12-08 17:28:19 -0800780 }
781 return intent;
782 }
783
Jim Miller92186872015-03-04 18:07:32 -0800784 @Override
785 public void onDestroy() {
786 super.onDestroy();
Jim Miller92186872015-03-04 18:07:32 -0800787 }
788
Amith Yamasanib0b37ae2012-04-23 15:35:36 -0700789 @Override
Fan Zhange0b0e9f2017-11-29 14:55:59 -0800790 public int getHelpResource() {
Amith Yamasanib0b37ae2012-04-23 15:35:36 -0700791 return R.string.help_url_choose_lockscreen;
792 }
793
Clara Bayarri34ec5f92016-01-22 14:59:24 +0000794 private int getResIdForFactoryResetProtectionWarningTitle() {
Robin Lee78867162016-09-12 16:25:28 +0900795 boolean isProfile = UserManager.get(getActivity()).isManagedProfile(mUserId);
Clara Bayarri34ec5f92016-01-22 14:59:24 +0000796 return isProfile ? R.string.unlock_disable_frp_warning_title_profile
797 : R.string.unlock_disable_frp_warning_title;
798 }
799
Adrian Roos38c9b9e2015-07-24 11:30:14 -0700800 private int getResIdForFactoryResetProtectionWarningMessage() {
Jeff Sharkey8d8bb6e2016-10-13 12:59:17 -0600801 final boolean hasFingerprints;
802 if (mFingerprintManager != null && mFingerprintManager.isHardwareDetected()) {
803 hasFingerprints = mFingerprintManager.hasEnrolledFingerprints(mUserId);
804 } else {
805 hasFingerprints = false;
806 }
Robin Lee78867162016-09-12 16:25:28 +0900807 boolean isProfile = UserManager.get(getActivity()).isManagedProfile(mUserId);
Clara Bayarrife432e82015-10-12 12:07:02 +0100808 switch (mLockPatternUtils.getKeyguardStoredPasswordQuality(mUserId)) {
Lucky Zhang3bcea022014-11-25 18:22:14 -0800809 case DevicePolicyManager.PASSWORD_QUALITY_SOMETHING:
Clara Bayarri34ec5f92016-01-22 14:59:24 +0000810 if (hasFingerprints && isProfile) {
811 return R.string
812 .unlock_disable_frp_warning_content_pattern_fingerprint_profile;
813 } else if (hasFingerprints && !isProfile) {
814 return R.string.unlock_disable_frp_warning_content_pattern_fingerprint;
815 } else if (isProfile) {
816 return R.string.unlock_disable_frp_warning_content_pattern_profile;
817 } else {
818 return R.string.unlock_disable_frp_warning_content_pattern;
819 }
Lucky Zhang3bcea022014-11-25 18:22:14 -0800820 case DevicePolicyManager.PASSWORD_QUALITY_NUMERIC:
821 case DevicePolicyManager.PASSWORD_QUALITY_NUMERIC_COMPLEX:
Clara Bayarri34ec5f92016-01-22 14:59:24 +0000822 if (hasFingerprints && isProfile) {
823 return R.string.unlock_disable_frp_warning_content_pin_fingerprint_profile;
824 } else if (hasFingerprints && !isProfile) {
825 return R.string.unlock_disable_frp_warning_content_pin_fingerprint;
826 } else if (isProfile) {
827 return R.string.unlock_disable_frp_warning_content_pin_profile;
828 } else {
829 return R.string.unlock_disable_frp_warning_content_pin;
830 }
Lucky Zhang3bcea022014-11-25 18:22:14 -0800831 case DevicePolicyManager.PASSWORD_QUALITY_ALPHABETIC:
832 case DevicePolicyManager.PASSWORD_QUALITY_ALPHANUMERIC:
833 case DevicePolicyManager.PASSWORD_QUALITY_COMPLEX:
Toni Barzice7d6e4d2016-03-30 11:43:19 -0700834 case DevicePolicyManager.PASSWORD_QUALITY_MANAGED:
Clara Bayarri34ec5f92016-01-22 14:59:24 +0000835 if (hasFingerprints && isProfile) {
836 return R.string
837 .unlock_disable_frp_warning_content_password_fingerprint_profile;
838 } else if (hasFingerprints && !isProfile) {
839 return R.string.unlock_disable_frp_warning_content_password_fingerprint;
840 } else if (isProfile) {
841 return R.string.unlock_disable_frp_warning_content_password_profile;
842 } else {
843 return R.string.unlock_disable_frp_warning_content_password;
844 }
Lucky Zhang3bcea022014-11-25 18:22:14 -0800845 default:
Clara Bayarri34ec5f92016-01-22 14:59:24 +0000846 if (hasFingerprints && isProfile) {
847 return R.string
848 .unlock_disable_frp_warning_content_unknown_fingerprint_profile;
849 } else if (hasFingerprints && !isProfile) {
850 return R.string.unlock_disable_frp_warning_content_unknown_fingerprint;
851 } else if (isProfile) {
852 return R.string.unlock_disable_frp_warning_content_unknown_profile;
853 } else {
854 return R.string.unlock_disable_frp_warning_content_unknown;
855 }
Lucky Zhang3bcea022014-11-25 18:22:14 -0800856 }
857 }
858
859 private boolean isUnlockMethodSecure(String unlockMethod) {
Maurice Lamedb39442017-04-27 18:54:33 -0700860 return !(ScreenLockType.SWIPE.preferenceKey.equals(unlockMethod) ||
861 ScreenLockType.NONE.preferenceKey.equals(unlockMethod));
Lucky Zhang3bcea022014-11-25 18:22:14 -0800862 }
863
864 private boolean setUnlockMethod(String unlockMethod) {
865 EventLog.writeEvent(EventLogTags.LOCK_SCREEN_TYPE, unlockMethod);
866
Maurice Lamedb39442017-04-27 18:54:33 -0700867 ScreenLockType lock = ScreenLockType.fromKey(unlockMethod);
868 if (lock != null) {
869 switch (lock) {
870 case NONE:
871 case SWIPE:
872 updateUnlockMethodAndFinish(
873 lock.defaultQuality,
874 lock == ScreenLockType.NONE,
875 false /* chooseLockSkipped */);
876 return true;
877 case PATTERN:
878 case PIN:
879 case PASSWORD:
880 case MANAGED:
881 maybeEnableEncryption(lock.defaultQuality, false);
882 return true;
883 }
Lucky Zhang3bcea022014-11-25 18:22:14 -0800884 }
Maurice Lamedb39442017-04-27 18:54:33 -0700885 Log.e(TAG, "Encountered unknown unlock method to set: " + unlockMethod);
886 return false;
Lucky Zhang3bcea022014-11-25 18:22:14 -0800887 }
888
889 private void showFactoryResetProtectionWarningDialog(String unlockMethodToSet) {
Clara Bayarri34ec5f92016-01-22 14:59:24 +0000890 int title = getResIdForFactoryResetProtectionWarningTitle();
Adrian Roos38c9b9e2015-07-24 11:30:14 -0700891 int message = getResIdForFactoryResetProtectionWarningMessage();
Lucky Zhang3bcea022014-11-25 18:22:14 -0800892 FactoryResetProtectionWarningDialog dialog =
Clara Bayarri34ec5f92016-01-22 14:59:24 +0000893 FactoryResetProtectionWarningDialog.newInstance(
894 title, message, unlockMethodToSet);
Lucky Zhang3bcea022014-11-25 18:22:14 -0800895 dialog.show(getChildFragmentManager(), TAG_FRP_WARNING_DIALOG);
896 }
897
Fan Zhangac5e5932016-08-24 18:13:33 -0700898 public static class FactoryResetProtectionWarningDialog extends InstrumentedDialogFragment {
Lucky Zhang3bcea022014-11-25 18:22:14 -0800899
Clara Bayarri34ec5f92016-01-22 14:59:24 +0000900 private static final String ARG_TITLE_RES = "titleRes";
Adrian Roos38c9b9e2015-07-24 11:30:14 -0700901 private static final String ARG_MESSAGE_RES = "messageRes";
Lucky Zhang3bcea022014-11-25 18:22:14 -0800902 private static final String ARG_UNLOCK_METHOD_TO_SET = "unlockMethodToSet";
903
Clara Bayarri34ec5f92016-01-22 14:59:24 +0000904 public static FactoryResetProtectionWarningDialog newInstance(
905 int titleRes, int messageRes, String unlockMethodToSet) {
Lucky Zhang3bcea022014-11-25 18:22:14 -0800906 FactoryResetProtectionWarningDialog frag =
907 new FactoryResetProtectionWarningDialog();
908 Bundle args = new Bundle();
Clara Bayarri34ec5f92016-01-22 14:59:24 +0000909 args.putInt(ARG_TITLE_RES, titleRes);
Adrian Roos38c9b9e2015-07-24 11:30:14 -0700910 args.putInt(ARG_MESSAGE_RES, messageRes);
Lucky Zhang3bcea022014-11-25 18:22:14 -0800911 args.putString(ARG_UNLOCK_METHOD_TO_SET, unlockMethodToSet);
912 frag.setArguments(args);
913 return frag;
914 }
915
916 @Override
917 public void show(FragmentManager manager, String tag) {
918 if (manager.findFragmentByTag(tag) == null) {
919 // Prevent opening multiple dialogs if tapped on button quickly
920 super.show(manager, tag);
921 }
922 }
923
924 @Override
925 public Dialog onCreateDialog(Bundle savedInstanceState) {
926 final Bundle args = getArguments();
927
928 return new AlertDialog.Builder(getActivity())
Clara Bayarri34ec5f92016-01-22 14:59:24 +0000929 .setTitle(args.getInt(ARG_TITLE_RES))
Adrian Roos38c9b9e2015-07-24 11:30:14 -0700930 .setMessage(args.getInt(ARG_MESSAGE_RES))
931 .setPositiveButton(R.string.unlock_disable_frp_warning_ok,
Maurice Lamedb39442017-04-27 18:54:33 -0700932 (dialog, whichButton) -> {
933 String unlockMethod = args.getString(ARG_UNLOCK_METHOD_TO_SET);
934 ((ChooseLockGenericFragment) getParentFragment())
935 .setUnlockMethod(unlockMethod);
936 })
937 .setNegativeButton(R.string.cancel, (dialog, whichButton) -> dismiss())
Lucky Zhang3bcea022014-11-25 18:22:14 -0800938 .create();
939 }
Fan Zhangac5e5932016-08-24 18:13:33 -0700940
941 @Override
942 public int getMetricsCategory() {
Fan Zhang31b21002019-01-16 13:49:47 -0800943 return SettingsEnums.DIALOG_FRP;
Fan Zhangac5e5932016-08-24 18:13:33 -0700944 }
Lucky Zhang3bcea022014-11-25 18:22:14 -0800945 }
Jim Millerbbb4afa2010-04-08 19:40:19 -0700946 }
Dianne Hackbornabc3dc62010-01-20 13:40:19 -0800947}