blob: 3353d62053f9ce6aec5b84358c336ef1e6110690 [file] [log] [blame]
Jim Miller00d24762009-12-22 19:04:57 -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;
Jim Miller00d24762009-12-22 19:04:57 -080018
Fan Zhangc3fd2892019-01-29 16:00:19 -080019import static com.android.settings.Utils.SETTINGS_PACKAGE_NAME;
20
Jorim Jaggi8a09b612015-04-06 17:47:18 -070021import android.annotation.Nullable;
Jim Miller00d24762009-12-22 19:04:57 -080022import android.app.Activity;
Adrian Roos5a9a3cd2017-03-30 18:02:25 -070023import android.app.KeyguardManager;
Jim Milleraf366a32010-03-25 18:45:22 -070024import android.app.admin.DevicePolicyManager;
Jim Miller00d24762009-12-22 19:04:57 -080025import android.content.Intent;
Clara Bayarric5cde052015-10-22 17:24:43 +010026import android.content.IntentSender;
Jeff Sharkey219ec912017-12-19 14:57:39 -070027import android.os.Bundle;
Ricky Wai996d0df2016-04-05 16:33:47 +010028import android.os.UserManager;
Jim Miller00d24762009-12-22 19:04:57 -080029
Fan Zhang23f8d592018-08-28 15:11:40 -070030import androidx.annotation.VisibleForTesting;
31import androidx.fragment.app.Fragment;
32
Jorim Jaggi8a09b612015-04-06 17:47:18 -070033import com.android.internal.widget.LockPatternUtils;
cnchencaf122b2019-04-03 16:18:34 +080034import com.android.settings.SetupWizardUtils;
Maurice Lam2eb170c2017-04-28 16:18:47 -070035import com.android.settings.Utils;
Pasty Changc1f86002018-12-11 02:22:55 +000036
37import com.google.android.setupcompat.util.WizardManagerHelper;
Jorim Jaggi8a09b612015-04-06 17:47:18 -070038
Brian Carlstrom0e88f4d2011-06-02 16:47:15 -070039public final class ChooseLockSettingsHelper {
40
Maurice Lam2eb170c2017-04-28 16:18:47 -070041 public static final String EXTRA_KEY_TYPE = "type";
42 public static final String EXTRA_KEY_PASSWORD = "password";
Victor Chang5e0a46b2016-05-13 17:06:59 +010043 public static final String EXTRA_KEY_RETURN_CREDENTIALS = "return_credentials";
Jorim Jaggi5ad75f02015-04-22 16:17:23 -070044 public static final String EXTRA_KEY_HAS_CHALLENGE = "has_challenge";
45 public static final String EXTRA_KEY_CHALLENGE = "challenge";
46 public static final String EXTRA_KEY_CHALLENGE_TOKEN = "hw_auth_token";
Maurice Lamc0e78792015-07-20 14:49:29 -070047 public static final String EXTRA_KEY_FOR_FINGERPRINT = "for_fingerprint";
Kevin Chyn81dc0292018-06-28 14:59:38 -070048 public static final String EXTRA_KEY_FOR_FACE = "for_face";
Adrian Roos62775bf2016-01-28 13:23:53 -080049 public static final String EXTRA_KEY_FOR_CHANGE_CRED_REQUIRED_FOR_BOOT = "for_cred_req_boot";
Kevin Chyne27a3042019-07-26 14:53:20 -070050 public static final String EXTRA_KEY_FOREGROUND_ONLY = "foreground_only";
Andres Morales6609b0c2015-04-12 15:38:25 -070051
Jeff Sharkey219ec912017-12-19 14:57:39 -070052 /**
Bernard Chau92db5bf2018-12-17 18:03:24 +000053 * Intent extra for passing the requested min password complexity to later steps in the set new
54 * screen lock flow.
55 */
56 public static final String EXTRA_KEY_REQUESTED_MIN_COMPLEXITY = "requested_min_complexity";
57
58 /**
59 * Intent extra for passing the label of the calling app to later steps in the set new screen
60 * lock flow.
61 */
62 public static final String EXTRA_KEY_CALLER_APP_NAME = "caller_app_name";
63
64 /**
Alex Kershaw29d2bff2019-05-17 15:36:28 +010065 * Intent extra indicating that the calling app is an admin, such as a Device Adimn, Device
66 * Owner, or Profile Owner.
67 */
68 public static final String EXTRA_KEY_IS_CALLING_APP_ADMIN = "is_calling_app_admin";
69
70 /**
Jeff Sharkey219ec912017-12-19 14:57:39 -070071 * When invoked via {@link ConfirmLockPassword.InternalActivity}, this flag
72 * controls if we relax the enforcement of
73 * {@link Utils#enforceSameOwner(android.content.Context, int)}.
74 */
75 public static final String EXTRA_ALLOW_ANY_USER = "allow_any_user";
Brian Carlstrom0e88f4d2011-06-02 16:47:15 -070076
Victor Chang5e0a46b2016-05-13 17:06:59 +010077 @VisibleForTesting LockPatternUtils mLockPatternUtils;
Jim Miller00d24762009-12-22 19:04:57 -080078 private Activity mActivity;
Amith Yamasanib14e1e02010-11-02 09:52:29 -070079 private Fragment mFragment;
Jim Miller00d24762009-12-22 19:04:57 -080080
81 public ChooseLockSettingsHelper(Activity activity) {
82 mActivity = activity;
Jim Miller47d380f2010-01-20 13:37:14 -080083 mLockPatternUtils = new LockPatternUtils(activity);
Jim Miller00d24762009-12-22 19:04:57 -080084 }
85
Amith Yamasanib14e1e02010-11-02 09:52:29 -070086 public ChooseLockSettingsHelper(Activity activity, Fragment fragment) {
87 this(activity);
88 mFragment = fragment;
89 }
90
Jim Miller00d24762009-12-22 19:04:57 -080091 public LockPatternUtils utils() {
92 return mLockPatternUtils;
93 }
94
95 /**
96 * If a pattern, password or PIN exists, prompt the user before allowing them to change it.
Jorim Jaggi8a09b612015-04-06 17:47:18 -070097 *
98 * @param title title of the confirmation screen; shown in the action bar
Jim Miller00d24762009-12-22 19:04:57 -080099 * @return true if one exists and we launched an activity to confirm it
Jorim Jaggi8a09b612015-04-06 17:47:18 -0700100 * @see Activity#onActivityResult(int, int, android.content.Intent)
Jim Miller00d24762009-12-22 19:04:57 -0800101 */
Paul Lawrence0e1a46c2015-11-04 05:09:02 -0800102 public boolean launchConfirmationActivity(int request, CharSequence title) {
Kevin Chyn80ecfd92018-10-04 12:59:35 -0700103 return launchConfirmationActivity(
104 request /* request */,
105 title /* title */,
106 null /* header */,
107 null /* description */,
108 false /* returnCredentials */,
Kevin Chyne27a3042019-07-26 14:53:20 -0700109 false /* external */,
110 false /* foregroundOnly */);
Paul Lawrence20444042014-07-07 13:10:16 -0700111 }
112
113 /**
114 * If a pattern, password or PIN exists, prompt the user before allowing them to change it.
Jorim Jaggi8a09b612015-04-06 17:47:18 -0700115 *
116 * @param title title of the confirmation screen; shown in the action bar
Paul Lawrence20444042014-07-07 13:10:16 -0700117 * @param returnCredentials if true, put credentials into intent. Note that if this is true,
Jorim Jaggi8a09b612015-04-06 17:47:18 -0700118 * this can only be called internally.
Paul Lawrence20444042014-07-07 13:10:16 -0700119 * @return true if one exists and we launched an activity to confirm it
Jorim Jaggi8a09b612015-04-06 17:47:18 -0700120 * @see Activity#onActivityResult(int, int, android.content.Intent)
Paul Lawrence20444042014-07-07 13:10:16 -0700121 */
Maurice Lam2eb170c2017-04-28 16:18:47 -0700122 public boolean launchConfirmationActivity(int request, CharSequence title, boolean returnCredentials) {
Kevin Chyn80ecfd92018-10-04 12:59:35 -0700123 return launchConfirmationActivity(
124 request /* request */,
125 title /* title */,
126 null /* header */,
127 null /* description */,
128 returnCredentials /* returnCredentials */,
Kevin Chyne27a3042019-07-26 14:53:20 -0700129 false /* external */,
130 false /* foregroundOnly */);
Jorim Jaggi8a09b612015-04-06 17:47:18 -0700131 }
132
133 /**
134 * If a pattern, password or PIN exists, prompt the user before allowing them to change it.
135 *
136 * @param title title of the confirmation screen; shown in the action bar
Clara Bayarrife432e82015-10-12 12:07:02 +0100137 * @param returnCredentials if true, put credentials into intent. Note that if this is true,
138 * this can only be called internally.
139 * @param userId The userId for whom the lock should be confirmed.
140 * @return true if one exists and we launched an activity to confirm it
141 * @see Activity#onActivityResult(int, int, android.content.Intent)
142 */
Nicolas Prevota599c8f2016-04-06 11:19:08 +0100143 public boolean launchConfirmationActivity(int request, CharSequence title,
144 boolean returnCredentials, int userId) {
Kevin Chyn80ecfd92018-10-04 12:59:35 -0700145 return launchConfirmationActivity(
146 request /* request */,
147 title /* title */,
148 null /* header */,
149 null /* description */,
150 returnCredentials /* returnCredentials */,
151 false /* external */,
152 false /* hasChallenge */,
153 0 /* challenge */,
Kevin Chyne27a3042019-07-26 14:53:20 -0700154 Utils.enforceSameOwner(mActivity, userId) /* userId */,
155 false /* foregroundOnly */);
Clara Bayarrife432e82015-10-12 12:07:02 +0100156 }
157
158 /**
159 * If a pattern, password or PIN exists, prompt the user before allowing them to change it.
160 *
161 * @param title title of the confirmation screen; shown in the action bar
Jorim Jaggi8a09b612015-04-06 17:47:18 -0700162 * @param header header of the confirmation screen; shown as large text
163 * @param description description of the confirmation screen
164 * @param returnCredentials if true, put credentials into intent. Note that if this is true,
165 * this can only be called internally.
166 * @param external specifies whether this activity is launched externally, meaning that it will
Victor Chang5e0a46b2016-05-13 17:06:59 +0100167 * get a dark theme, allow fingerprint authentication and it will forward
168 * activity result.
Kevin Chyne27a3042019-07-26 14:53:20 -0700169 * @param foregroundOnly if the confirmation activity should be finished if it loses foreground.
Jorim Jaggi8a09b612015-04-06 17:47:18 -0700170 * @return true if one exists and we launched an activity to confirm it
171 * @see Activity#onActivityResult(int, int, android.content.Intent)
172 */
173 boolean launchConfirmationActivity(int request, @Nullable CharSequence title,
174 @Nullable CharSequence header, @Nullable CharSequence description,
Kevin Chyne27a3042019-07-26 14:53:20 -0700175 boolean returnCredentials, boolean external, boolean foregroundOnly) {
Kevin Chyn80ecfd92018-10-04 12:59:35 -0700176 return launchConfirmationActivity(
177 request /* request */,
178 title /* title */,
179 header /* header */,
180 description /* description */,
181 returnCredentials /* returnCredentials */,
182 external /* external */,
183 false /* hasChallenge */,
184 0 /* challenge */,
Kevin Chyne27a3042019-07-26 14:53:20 -0700185 Utils.getCredentialOwnerUserId(mActivity) /* userId */,
186 foregroundOnly /* foregroundOnly */);
Andres Morales6609b0c2015-04-12 15:38:25 -0700187 }
188
189 /**
190 * If a pattern, password or PIN exists, prompt the user before allowing them to change it.
Clara Bayarric5cde052015-10-22 17:24:43 +0100191 *
192 * @param title title of the confirmation screen; shown in the action bar
193 * @param header header of the confirmation screen; shown as large text
194 * @param description description of the confirmation screen
195 * @param returnCredentials if true, put credentials into intent. Note that if this is true,
196 * this can only be called internally.
197 * @param external specifies whether this activity is launched externally, meaning that it will
Victor Chang5e0a46b2016-05-13 17:06:59 +0100198 * get a dark theme, allow fingerprint authentication and it will forward
199 * activity result.
Clara Bayarric5cde052015-10-22 17:24:43 +0100200 * @param userId The userId for whom the lock should be confirmed.
201 * @return true if one exists and we launched an activity to confirm it
202 * @see Activity#onActivityResult(int, int, android.content.Intent)
203 */
204 boolean launchConfirmationActivity(int request, @Nullable CharSequence title,
205 @Nullable CharSequence header, @Nullable CharSequence description,
206 boolean returnCredentials, boolean external, int userId) {
Kevin Chyn80ecfd92018-10-04 12:59:35 -0700207 return launchConfirmationActivity(
208 request /* request */,
209 title /* title */,
210 header /* header */,
211 description /* description */,
212 returnCredentials /* returnCredentials */,
213 external /* external */,
214 false /* hasChallenge */,
215 0 /* challenge */,
Kevin Chyne27a3042019-07-26 14:53:20 -0700216 Utils.enforceSameOwner(mActivity, userId) /* userId */,
217 false /* foregroundOnly */);
Clara Bayarric5cde052015-10-22 17:24:43 +0100218 }
219
220 /**
221 * If a pattern, password or PIN exists, prompt the user before allowing them to change it.
Victor Chang5e0a46b2016-05-13 17:06:59 +0100222 *
223 * @param title title of the confirmation screen; shown in the action bar
224 * @param header header of the confirmation screen; shown as large text
225 * @param description description of the confirmation screen
Andres Morales6609b0c2015-04-12 15:38:25 -0700226 * @param challenge a challenge to be verified against the device credential.
Kevin Chyne27a3042019-07-26 14:53:20 -0700227 * @param foregroundOnly if the confirmation activity should be finished if it loses foreground.
Andres Morales6609b0c2015-04-12 15:38:25 -0700228 * @return true if one exists and we launched an activity to confirm it
Victor Chang5e0a46b2016-05-13 17:06:59 +0100229 * @see Activity#onActivityResult(int, int, android.content.Intent)
Andres Morales6609b0c2015-04-12 15:38:25 -0700230 */
Jorim Jaggi5ad75f02015-04-22 16:17:23 -0700231 public boolean launchConfirmationActivity(int request, @Nullable CharSequence title,
Andres Morales6609b0c2015-04-12 15:38:25 -0700232 @Nullable CharSequence header, @Nullable CharSequence description,
Kevin Chyne27a3042019-07-26 14:53:20 -0700233 long challenge, boolean foregroundOnly) {
Kevin Chyn80ecfd92018-10-04 12:59:35 -0700234 return launchConfirmationActivity(
235 request /* request */,
236 title /* title */,
237 header /* header */,
238 description /* description */,
239 true /* returnCredentials */,
240 false /* external */,
241 true /* hasChallenge */,
242 challenge /* challenge */,
Kevin Chyne27a3042019-07-26 14:53:20 -0700243 Utils.getCredentialOwnerUserId(mActivity) /* userId */,
244 foregroundOnly /* foregroundOnly */);
Andres Morales6609b0c2015-04-12 15:38:25 -0700245 }
246
Clara Bayarri40db4bb2016-01-07 17:10:27 +0000247 /**
248 * If a pattern, password or PIN exists, prompt the user before allowing them to change it.
Victor Chang5e0a46b2016-05-13 17:06:59 +0100249 *
250 * @param title title of the confirmation screen; shown in the action bar
251 * @param header header of the confirmation screen; shown as large text
252 * @param description description of the confirmation screen
Clara Bayarri40db4bb2016-01-07 17:10:27 +0000253 * @param challenge a challenge to be verified against the device credential.
Clara Bayarri40db4bb2016-01-07 17:10:27 +0000254 * @param userId The userId for whom the lock should be confirmed.
Kevin Chyne27a3042019-07-26 14:53:20 -0700255 * @param foregroundOnly if the confirmation activity should be finished if it loses foreground.
Clara Bayarri40db4bb2016-01-07 17:10:27 +0000256 * @return true if one exists and we launched an activity to confirm it
Victor Chang5e0a46b2016-05-13 17:06:59 +0100257 * @see Activity#onActivityResult(int, int, android.content.Intent)
Clara Bayarri40db4bb2016-01-07 17:10:27 +0000258 */
259 public boolean launchConfirmationActivity(int request, @Nullable CharSequence title,
260 @Nullable CharSequence header, @Nullable CharSequence description,
Kevin Chyne27a3042019-07-26 14:53:20 -0700261 long challenge, int userId, boolean foregroundOnly) {
Kevin Chyn80ecfd92018-10-04 12:59:35 -0700262 return launchConfirmationActivity(
263 request /* request */,
264 title /* title */,
265 header /* header */,
266 description /* description */,
267 true /* returnCredentials */,
268 false /* external */,
269 true /* hasChallenge */,
270 challenge /* challenge */,
Kevin Chyne27a3042019-07-26 14:53:20 -0700271 Utils.enforceSameOwner(mActivity, userId) /* userId */,
272 foregroundOnly);
Victor Chang5e0a46b2016-05-13 17:06:59 +0100273 }
274
275 /**
276 * If a pattern, password or PIN exists, prompt the user before allowing them to change it.
277 *
278 * @param title title of the confirmation screen; shown in the action bar
279 * @param header header of the confirmation screen; shown as large text
280 * @param description description of the confirmation screen
281 * @param external specifies whether this activity is launched externally, meaning that it will
282 * get a dark theme, allow fingerprint authentication and it will forward
283 * activity result.
284 * @param challenge a challenge to be verified against the device credential.
285 * @param userId The userId for whom the lock should be confirmed.
286 * @return true if one exists and we launched an activity to confirm it
287 * @see Activity#onActivityResult(int, int, android.content.Intent)
288 */
289 public boolean launchConfirmationActivityWithExternalAndChallenge(int request,
290 @Nullable CharSequence title, @Nullable CharSequence header,
291 @Nullable CharSequence description, boolean external, long challenge, int userId) {
Kevin Chyn80ecfd92018-10-04 12:59:35 -0700292 return launchConfirmationActivity(
293 request /* request */,
294 title /* title */,
295 header /* header */,
296 description /* description */,
297 false /* returnCredentials */,
298 external /* external */,
299 true /* hasChallenge */,
300 challenge /* challenge */,
Kevin Chyne27a3042019-07-26 14:53:20 -0700301 Utils.enforceSameOwner(mActivity, userId) /* userId */,
302 false /* foregroundOnly */);
Clara Bayarri40db4bb2016-01-07 17:10:27 +0000303 }
304
Jeff Sharkey219ec912017-12-19 14:57:39 -0700305 /**
306 * Variant that allows you to prompt for credentials of any user, including
307 * those which aren't associated with the current user. As an example, this
308 * is useful when unlocking the storage for secondary users.
309 */
310 public boolean launchConfirmationActivityForAnyUser(int request,
311 @Nullable CharSequence title, @Nullable CharSequence header,
312 @Nullable CharSequence description, int userId) {
313 final Bundle extras = new Bundle();
314 extras.putBoolean(EXTRA_ALLOW_ANY_USER, true);
Kevin Chyn80ecfd92018-10-04 12:59:35 -0700315 return launchConfirmationActivity(
316 request /* request */,
317 title /* title */,
318 header /* header */,
319 description /* description */,
320 false /* returnCredentials */,
321 false /* external */,
322 true /* hasChallenge */,
323 0 /* challenge */,
324 userId /* userId */,
325 extras /* extras */);
Jeff Sharkey219ec912017-12-19 14:57:39 -0700326 }
327
Andres Morales6609b0c2015-04-12 15:38:25 -0700328 private boolean launchConfirmationActivity(int request, @Nullable CharSequence title,
329 @Nullable CharSequence header, @Nullable CharSequence description,
330 boolean returnCredentials, boolean external, boolean hasChallenge,
Kevin Chyne27a3042019-07-26 14:53:20 -0700331 long challenge, int userId, boolean foregroundOnly) {
Kevin Chyn80ecfd92018-10-04 12:59:35 -0700332 return launchConfirmationActivity(
333 request /* request */,
334 title /* title */,
335 header /* header */,
336 description /* description */,
337 returnCredentials /* returnCredentials */,
338 external /* external */,
339 hasChallenge /* hasChallenge */,
340 challenge /* challenge */,
341 userId /* userId */,
342 null /* alternateButton */,
Kevin Chyne27a3042019-07-26 14:53:20 -0700343 null /* extras */,
344 foregroundOnly /* foregroundOnly */);
Jeff Sharkey219ec912017-12-19 14:57:39 -0700345 }
346
347 private boolean launchConfirmationActivity(int request, @Nullable CharSequence title,
348 @Nullable CharSequence header, @Nullable CharSequence description,
349 boolean returnCredentials, boolean external, boolean hasChallenge,
350 long challenge, int userId, Bundle extras) {
Kevin Chyn80ecfd92018-10-04 12:59:35 -0700351 return launchConfirmationActivity(
352 request /* request */,
353 title /* title */,
354 header /* header */,
355 description /* description */,
356 returnCredentials /* returnCredentials */,
357 external /* external */,
358 hasChallenge /* hasChallenge */,
359 challenge /* challenge */,
360 userId /* userId */,
361 null /* alternateButton */,
Kevin Chyne27a3042019-07-26 14:53:20 -0700362 extras /* extras */,
363 false /* foregroundOnly */);
Adrian Roos5a9a3cd2017-03-30 18:02:25 -0700364 }
365
366 public boolean launchFrpConfirmationActivity(int request, @Nullable CharSequence header,
367 @Nullable CharSequence description, @Nullable CharSequence alternateButton) {
Kevin Chyn80ecfd92018-10-04 12:59:35 -0700368 return launchConfirmationActivity(
369 request /* request */,
370 null /* title */,
371 header /* header */,
372 description /* description */,
373 false /* returnCredentials */,
374 true /* external */,
375 false /* hasChallenge */,
376 0 /* challenge */,
377 LockPatternUtils.USER_FRP /* userId */,
378 alternateButton /* alternateButton */,
Kevin Chyne27a3042019-07-26 14:53:20 -0700379 null /* extras */,
380 false /* foregroundOnly */);
Adrian Roos5a9a3cd2017-03-30 18:02:25 -0700381 }
382
383 private boolean launchConfirmationActivity(int request, @Nullable CharSequence title,
384 @Nullable CharSequence header, @Nullable CharSequence description,
385 boolean returnCredentials, boolean external, boolean hasChallenge,
Kevin Chyne27a3042019-07-26 14:53:20 -0700386 long challenge, int userId, @Nullable CharSequence alternateButton, Bundle extras,
387 boolean foregroundOnly) {
Ricky Wai996d0df2016-04-05 16:33:47 +0100388 final int effectiveUserId = UserManager.get(mActivity).getCredentialOwnerProfile(userId);
Jim Miller00d24762009-12-22 19:04:57 -0800389 boolean launched = false;
Andres Morales7bdffd82015-08-04 16:55:00 -0700390
Andres Morales7bdffd82015-08-04 16:55:00 -0700391 switch (mLockPatternUtils.getKeyguardStoredPasswordQuality(effectiveUserId)) {
Jim Milleraf366a32010-03-25 18:45:22 -0700392 case DevicePolicyManager.PASSWORD_QUALITY_SOMETHING:
Jorim Jaggi8a09b612015-04-06 17:47:18 -0700393 launched = launchConfirmationActivity(request, title, header, description,
Andres Morales6609b0c2015-04-12 15:38:25 -0700394 returnCredentials || hasChallenge
Jorim Jaggi8a09b612015-04-06 17:47:18 -0700395 ? ConfirmLockPattern.InternalActivity.class
Victor Chang5e0a46b2016-05-13 17:06:59 +0100396 : ConfirmLockPattern.class, returnCredentials, external,
Kevin Chyne27a3042019-07-26 14:53:20 -0700397 hasChallenge, challenge, userId, alternateButton, extras,
398 foregroundOnly);
Jim Miller00d24762009-12-22 19:04:57 -0800399 break;
Jim Milleraf366a32010-03-25 18:45:22 -0700400 case DevicePolicyManager.PASSWORD_QUALITY_NUMERIC:
Nicolas Prevot8fd852e2014-01-25 01:02:04 +0000401 case DevicePolicyManager.PASSWORD_QUALITY_NUMERIC_COMPLEX:
Jim Milleraf366a32010-03-25 18:45:22 -0700402 case DevicePolicyManager.PASSWORD_QUALITY_ALPHABETIC:
Jim Miller9c1e7f82010-04-08 00:48:52 -0700403 case DevicePolicyManager.PASSWORD_QUALITY_ALPHANUMERIC:
Konstantin Lopyrev57fbf692010-05-27 16:01:41 -0700404 case DevicePolicyManager.PASSWORD_QUALITY_COMPLEX:
Toni Barzice7d6e4d2016-03-30 11:43:19 -0700405 case DevicePolicyManager.PASSWORD_QUALITY_MANAGED:
Jorim Jaggi8a09b612015-04-06 17:47:18 -0700406 launched = launchConfirmationActivity(request, title, header, description,
Andres Morales6609b0c2015-04-12 15:38:25 -0700407 returnCredentials || hasChallenge
Jorim Jaggi8a09b612015-04-06 17:47:18 -0700408 ? ConfirmLockPassword.InternalActivity.class
Victor Chang5e0a46b2016-05-13 17:06:59 +0100409 : ConfirmLockPassword.class, returnCredentials, external,
Kevin Chyne27a3042019-07-26 14:53:20 -0700410 hasChallenge, challenge, userId, alternateButton, extras,
411 foregroundOnly);
Jim Miller00d24762009-12-22 19:04:57 -0800412 break;
413 }
414 return launched;
415 }
416
Jorim Jaggi8a09b612015-04-06 17:47:18 -0700417 private boolean launchConfirmationActivity(int request, CharSequence title, CharSequence header,
Victor Chang5e0a46b2016-05-13 17:06:59 +0100418 CharSequence message, Class<?> activityClass, boolean returnCredentials,
419 boolean external, boolean hasChallenge, long challenge,
Kevin Chyne27a3042019-07-26 14:53:20 -0700420 int userId, @Nullable CharSequence alternateButton, Bundle extras,
421 boolean foregroundOnly) {
Jim Miller00d24762009-12-22 19:04:57 -0800422 final Intent intent = new Intent();
Jorim Jaggi8a09b612015-04-06 17:47:18 -0700423 intent.putExtra(ConfirmDeviceCredentialBaseFragment.TITLE_TEXT, title);
424 intent.putExtra(ConfirmDeviceCredentialBaseFragment.HEADER_TEXT, header);
425 intent.putExtra(ConfirmDeviceCredentialBaseFragment.DETAILS_TEXT, message);
Maurice Lam02833722018-04-25 17:53:13 -0700426 // TODO: Remove dark theme and show_cancel_button options since they are no longer used
Maurice Lam3e3b8a92018-03-21 18:21:04 -0700427 intent.putExtra(ConfirmDeviceCredentialBaseFragment.DARK_THEME, false);
Maurice Lam02833722018-04-25 17:53:13 -0700428 intent.putExtra(ConfirmDeviceCredentialBaseFragment.SHOW_CANCEL_BUTTON, false);
Jorim Jaggi8a09b612015-04-06 17:47:18 -0700429 intent.putExtra(ConfirmDeviceCredentialBaseFragment.SHOW_WHEN_LOCKED, external);
Kevin Chynb3ee2312018-10-04 15:01:43 -0700430 intent.putExtra(ConfirmDeviceCredentialBaseFragment.USE_FADE_ANIMATION, external);
Victor Chang5e0a46b2016-05-13 17:06:59 +0100431 intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_RETURN_CREDENTIALS, returnCredentials);
Andres Morales6609b0c2015-04-12 15:38:25 -0700432 intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_HAS_CHALLENGE, hasChallenge);
433 intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE, challenge);
Clara Bayarri6934a042015-10-14 11:07:35 +0100434 intent.putExtra(Intent.EXTRA_USER_ID, userId);
Adrian Roos5a9a3cd2017-03-30 18:02:25 -0700435 intent.putExtra(KeyguardManager.EXTRA_ALTERNATE_BUTTON_LABEL, alternateButton);
Kevin Chyne27a3042019-07-26 14:53:20 -0700436 intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_FOREGROUND_ONLY, foregroundOnly);
Jeff Sharkey219ec912017-12-19 14:57:39 -0700437 if (extras != null) {
438 intent.putExtras(extras);
439 }
Fan Zhangc3fd2892019-01-29 16:00:19 -0800440 intent.setClassName(SETTINGS_PACKAGE_NAME, activityClass.getName());
Jorim Jaggi74a22832015-09-10 20:12:19 -0700441 if (external) {
442 intent.addFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT);
443 if (mFragment != null) {
Clara Bayarri86ebaa22015-12-10 12:35:27 +0000444 copyOptionalExtras(mFragment.getActivity().getIntent(), intent);
Jorim Jaggi74a22832015-09-10 20:12:19 -0700445 mFragment.startActivity(intent);
446 } else {
Clara Bayarri86ebaa22015-12-10 12:35:27 +0000447 copyOptionalExtras(mActivity.getIntent(), intent);
Jorim Jaggi74a22832015-09-10 20:12:19 -0700448 mActivity.startActivity(intent);
449 }
Amith Yamasanib14e1e02010-11-02 09:52:29 -0700450 } else {
Jorim Jaggi74a22832015-09-10 20:12:19 -0700451 if (mFragment != null) {
Maurice Lam84617252017-06-12 12:15:40 -0700452 copyInternalExtras(mFragment.getActivity().getIntent(), intent);
Jorim Jaggi74a22832015-09-10 20:12:19 -0700453 mFragment.startActivityForResult(intent, request);
454 } else {
Maurice Lam84617252017-06-12 12:15:40 -0700455 copyInternalExtras(mActivity.getIntent(), intent);
Jorim Jaggi74a22832015-09-10 20:12:19 -0700456 mActivity.startActivityForResult(intent, request);
457 }
Amith Yamasanib14e1e02010-11-02 09:52:29 -0700458 }
Jim Miller00d24762009-12-22 19:04:57 -0800459 return true;
460 }
Clara Bayarri86ebaa22015-12-10 12:35:27 +0000461
462 private void copyOptionalExtras(Intent inIntent, Intent outIntent) {
463 IntentSender intentSender = inIntent.getParcelableExtra(Intent.EXTRA_INTENT);
464 if (intentSender != null) {
465 outIntent.putExtra(Intent.EXTRA_INTENT, intentSender);
466 }
467 int taskId = inIntent.getIntExtra(Intent.EXTRA_TASK_ID, -1);
468 if (taskId != -1) {
469 outIntent.putExtra(Intent.EXTRA_TASK_ID, taskId);
470 }
471 // If we will launch another activity once credentials are confirmed, exclude from recents.
472 // This is a workaround to a framework bug where affinity is incorrect for activities
473 // that are started from a no display activity, as is ConfirmDeviceCredentialActivity.
474 // TODO: Remove once that bug is fixed.
475 if (intentSender != null || taskId != -1) {
476 outIntent.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Tony Makb7f1edd2016-03-18 12:20:28 +0000477 outIntent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
Clara Bayarri86ebaa22015-12-10 12:35:27 +0000478 }
479 }
Maurice Lam84617252017-06-12 12:15:40 -0700480
481 private void copyInternalExtras(Intent inIntent, Intent outIntent) {
cnchencaf122b2019-04-03 16:18:34 +0800482 SetupWizardUtils.copySetupExtras(inIntent, outIntent);
Maurice Lam84617252017-06-12 12:15:40 -0700483 String theme = inIntent.getStringExtra(WizardManagerHelper.EXTRA_THEME);
484 if (theme != null) {
485 outIntent.putExtra(WizardManagerHelper.EXTRA_THEME, theme);
486 }
487 }
Jim Miller00d24762009-12-22 19:04:57 -0800488}