Jim Miller | 00d2476 | 2009-12-22 19:04:57 -0800 | [diff] [blame] | 1 | /* |
| 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 Lam | 2eb170c | 2017-04-28 16:18:47 -0700 | [diff] [blame] | 17 | package com.android.settings.password; |
Jim Miller | 00d2476 | 2009-12-22 19:04:57 -0800 | [diff] [blame] | 18 | |
Fan Zhang | c3fd289 | 2019-01-29 16:00:19 -0800 | [diff] [blame] | 19 | import static com.android.settings.Utils.SETTINGS_PACKAGE_NAME; |
| 20 | |
Jorim Jaggi | 8a09b61 | 2015-04-06 17:47:18 -0700 | [diff] [blame] | 21 | import android.annotation.Nullable; |
Jim Miller | 00d2476 | 2009-12-22 19:04:57 -0800 | [diff] [blame] | 22 | import android.app.Activity; |
Adrian Roos | 5a9a3cd | 2017-03-30 18:02:25 -0700 | [diff] [blame] | 23 | import android.app.KeyguardManager; |
Jim Miller | af366a3 | 2010-03-25 18:45:22 -0700 | [diff] [blame] | 24 | import android.app.admin.DevicePolicyManager; |
Jim Miller | 00d2476 | 2009-12-22 19:04:57 -0800 | [diff] [blame] | 25 | import android.content.Intent; |
Clara Bayarri | c5cde05 | 2015-10-22 17:24:43 +0100 | [diff] [blame] | 26 | import android.content.IntentSender; |
Jeff Sharkey | 219ec91 | 2017-12-19 14:57:39 -0700 | [diff] [blame] | 27 | import android.os.Bundle; |
Ricky Wai | 996d0df | 2016-04-05 16:33:47 +0100 | [diff] [blame] | 28 | import android.os.UserManager; |
Jim Miller | 00d2476 | 2009-12-22 19:04:57 -0800 | [diff] [blame] | 29 | |
Fan Zhang | 23f8d59 | 2018-08-28 15:11:40 -0700 | [diff] [blame] | 30 | import androidx.annotation.VisibleForTesting; |
| 31 | import androidx.fragment.app.Fragment; |
| 32 | |
Jorim Jaggi | 8a09b61 | 2015-04-06 17:47:18 -0700 | [diff] [blame] | 33 | import com.android.internal.widget.LockPatternUtils; |
cnchen | caf122b | 2019-04-03 16:18:34 +0800 | [diff] [blame] | 34 | import com.android.settings.SetupWizardUtils; |
Maurice Lam | 2eb170c | 2017-04-28 16:18:47 -0700 | [diff] [blame] | 35 | import com.android.settings.Utils; |
Pasty Chang | c1f8600 | 2018-12-11 02:22:55 +0000 | [diff] [blame] | 36 | |
| 37 | import com.google.android.setupcompat.util.WizardManagerHelper; |
Jorim Jaggi | 8a09b61 | 2015-04-06 17:47:18 -0700 | [diff] [blame] | 38 | |
Brian Carlstrom | 0e88f4d | 2011-06-02 16:47:15 -0700 | [diff] [blame] | 39 | public final class ChooseLockSettingsHelper { |
| 40 | |
Maurice Lam | 2eb170c | 2017-04-28 16:18:47 -0700 | [diff] [blame] | 41 | public static final String EXTRA_KEY_TYPE = "type"; |
| 42 | public static final String EXTRA_KEY_PASSWORD = "password"; |
Victor Chang | 5e0a46b | 2016-05-13 17:06:59 +0100 | [diff] [blame] | 43 | public static final String EXTRA_KEY_RETURN_CREDENTIALS = "return_credentials"; |
Jorim Jaggi | 5ad75f0 | 2015-04-22 16:17:23 -0700 | [diff] [blame] | 44 | 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 Lam | c0e7879 | 2015-07-20 14:49:29 -0700 | [diff] [blame] | 47 | public static final String EXTRA_KEY_FOR_FINGERPRINT = "for_fingerprint"; |
Kevin Chyn | 81dc029 | 2018-06-28 14:59:38 -0700 | [diff] [blame] | 48 | public static final String EXTRA_KEY_FOR_FACE = "for_face"; |
Adrian Roos | 62775bf | 2016-01-28 13:23:53 -0800 | [diff] [blame] | 49 | public static final String EXTRA_KEY_FOR_CHANGE_CRED_REQUIRED_FOR_BOOT = "for_cred_req_boot"; |
Kevin Chyn | e27a304 | 2019-07-26 14:53:20 -0700 | [diff] [blame] | 50 | public static final String EXTRA_KEY_FOREGROUND_ONLY = "foreground_only"; |
Andres Morales | 6609b0c | 2015-04-12 15:38:25 -0700 | [diff] [blame] | 51 | |
Jeff Sharkey | 219ec91 | 2017-12-19 14:57:39 -0700 | [diff] [blame] | 52 | /** |
Bernard Chau | 92db5bf | 2018-12-17 18:03:24 +0000 | [diff] [blame] | 53 | * 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 Kershaw | 29d2bff | 2019-05-17 15:36:28 +0100 | [diff] [blame] | 65 | * 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 Sharkey | 219ec91 | 2017-12-19 14:57:39 -0700 | [diff] [blame] | 71 | * 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 Carlstrom | 0e88f4d | 2011-06-02 16:47:15 -0700 | [diff] [blame] | 76 | |
Victor Chang | 5e0a46b | 2016-05-13 17:06:59 +0100 | [diff] [blame] | 77 | @VisibleForTesting LockPatternUtils mLockPatternUtils; |
Jim Miller | 00d2476 | 2009-12-22 19:04:57 -0800 | [diff] [blame] | 78 | private Activity mActivity; |
Amith Yamasani | b14e1e0 | 2010-11-02 09:52:29 -0700 | [diff] [blame] | 79 | private Fragment mFragment; |
Jim Miller | 00d2476 | 2009-12-22 19:04:57 -0800 | [diff] [blame] | 80 | |
| 81 | public ChooseLockSettingsHelper(Activity activity) { |
| 82 | mActivity = activity; |
Jim Miller | 47d380f | 2010-01-20 13:37:14 -0800 | [diff] [blame] | 83 | mLockPatternUtils = new LockPatternUtils(activity); |
Jim Miller | 00d2476 | 2009-12-22 19:04:57 -0800 | [diff] [blame] | 84 | } |
| 85 | |
Amith Yamasani | b14e1e0 | 2010-11-02 09:52:29 -0700 | [diff] [blame] | 86 | public ChooseLockSettingsHelper(Activity activity, Fragment fragment) { |
| 87 | this(activity); |
| 88 | mFragment = fragment; |
| 89 | } |
| 90 | |
Jim Miller | 00d2476 | 2009-12-22 19:04:57 -0800 | [diff] [blame] | 91 | 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 Jaggi | 8a09b61 | 2015-04-06 17:47:18 -0700 | [diff] [blame] | 97 | * |
| 98 | * @param title title of the confirmation screen; shown in the action bar |
Jim Miller | 00d2476 | 2009-12-22 19:04:57 -0800 | [diff] [blame] | 99 | * @return true if one exists and we launched an activity to confirm it |
Jorim Jaggi | 8a09b61 | 2015-04-06 17:47:18 -0700 | [diff] [blame] | 100 | * @see Activity#onActivityResult(int, int, android.content.Intent) |
Jim Miller | 00d2476 | 2009-12-22 19:04:57 -0800 | [diff] [blame] | 101 | */ |
Paul Lawrence | 0e1a46c | 2015-11-04 05:09:02 -0800 | [diff] [blame] | 102 | public boolean launchConfirmationActivity(int request, CharSequence title) { |
Kevin Chyn | 80ecfd9 | 2018-10-04 12:59:35 -0700 | [diff] [blame] | 103 | return launchConfirmationActivity( |
| 104 | request /* request */, |
| 105 | title /* title */, |
| 106 | null /* header */, |
| 107 | null /* description */, |
| 108 | false /* returnCredentials */, |
Kevin Chyn | e27a304 | 2019-07-26 14:53:20 -0700 | [diff] [blame] | 109 | false /* external */, |
| 110 | false /* foregroundOnly */); |
Paul Lawrence | 2044404 | 2014-07-07 13:10:16 -0700 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | /** |
| 114 | * If a pattern, password or PIN exists, prompt the user before allowing them to change it. |
Jorim Jaggi | 8a09b61 | 2015-04-06 17:47:18 -0700 | [diff] [blame] | 115 | * |
| 116 | * @param title title of the confirmation screen; shown in the action bar |
Paul Lawrence | 2044404 | 2014-07-07 13:10:16 -0700 | [diff] [blame] | 117 | * @param returnCredentials if true, put credentials into intent. Note that if this is true, |
Jorim Jaggi | 8a09b61 | 2015-04-06 17:47:18 -0700 | [diff] [blame] | 118 | * this can only be called internally. |
Paul Lawrence | 2044404 | 2014-07-07 13:10:16 -0700 | [diff] [blame] | 119 | * @return true if one exists and we launched an activity to confirm it |
Jorim Jaggi | 8a09b61 | 2015-04-06 17:47:18 -0700 | [diff] [blame] | 120 | * @see Activity#onActivityResult(int, int, android.content.Intent) |
Paul Lawrence | 2044404 | 2014-07-07 13:10:16 -0700 | [diff] [blame] | 121 | */ |
Maurice Lam | 2eb170c | 2017-04-28 16:18:47 -0700 | [diff] [blame] | 122 | public boolean launchConfirmationActivity(int request, CharSequence title, boolean returnCredentials) { |
Kevin Chyn | 80ecfd9 | 2018-10-04 12:59:35 -0700 | [diff] [blame] | 123 | return launchConfirmationActivity( |
| 124 | request /* request */, |
| 125 | title /* title */, |
| 126 | null /* header */, |
| 127 | null /* description */, |
| 128 | returnCredentials /* returnCredentials */, |
Kevin Chyn | e27a304 | 2019-07-26 14:53:20 -0700 | [diff] [blame] | 129 | false /* external */, |
| 130 | false /* foregroundOnly */); |
Jorim Jaggi | 8a09b61 | 2015-04-06 17:47:18 -0700 | [diff] [blame] | 131 | } |
| 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 Bayarri | fe432e8 | 2015-10-12 12:07:02 +0100 | [diff] [blame] | 137 | * @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 Prevot | a599c8f | 2016-04-06 11:19:08 +0100 | [diff] [blame] | 143 | public boolean launchConfirmationActivity(int request, CharSequence title, |
| 144 | boolean returnCredentials, int userId) { |
Kevin Chyn | 80ecfd9 | 2018-10-04 12:59:35 -0700 | [diff] [blame] | 145 | 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 Chyn | e27a304 | 2019-07-26 14:53:20 -0700 | [diff] [blame] | 154 | Utils.enforceSameOwner(mActivity, userId) /* userId */, |
| 155 | false /* foregroundOnly */); |
Clara Bayarri | fe432e8 | 2015-10-12 12:07:02 +0100 | [diff] [blame] | 156 | } |
| 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 Jaggi | 8a09b61 | 2015-04-06 17:47:18 -0700 | [diff] [blame] | 162 | * @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 Chang | 5e0a46b | 2016-05-13 17:06:59 +0100 | [diff] [blame] | 167 | * get a dark theme, allow fingerprint authentication and it will forward |
| 168 | * activity result. |
Kevin Chyn | e27a304 | 2019-07-26 14:53:20 -0700 | [diff] [blame] | 169 | * @param foregroundOnly if the confirmation activity should be finished if it loses foreground. |
Jorim Jaggi | 8a09b61 | 2015-04-06 17:47:18 -0700 | [diff] [blame] | 170 | * @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 Chyn | e27a304 | 2019-07-26 14:53:20 -0700 | [diff] [blame] | 175 | boolean returnCredentials, boolean external, boolean foregroundOnly) { |
Kevin Chyn | 80ecfd9 | 2018-10-04 12:59:35 -0700 | [diff] [blame] | 176 | 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 Chyn | e27a304 | 2019-07-26 14:53:20 -0700 | [diff] [blame] | 185 | Utils.getCredentialOwnerUserId(mActivity) /* userId */, |
| 186 | foregroundOnly /* foregroundOnly */); |
Andres Morales | 6609b0c | 2015-04-12 15:38:25 -0700 | [diff] [blame] | 187 | } |
| 188 | |
| 189 | /** |
| 190 | * If a pattern, password or PIN exists, prompt the user before allowing them to change it. |
Clara Bayarri | c5cde05 | 2015-10-22 17:24:43 +0100 | [diff] [blame] | 191 | * |
| 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 Chang | 5e0a46b | 2016-05-13 17:06:59 +0100 | [diff] [blame] | 198 | * get a dark theme, allow fingerprint authentication and it will forward |
| 199 | * activity result. |
Clara Bayarri | c5cde05 | 2015-10-22 17:24:43 +0100 | [diff] [blame] | 200 | * @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 Chyn | 80ecfd9 | 2018-10-04 12:59:35 -0700 | [diff] [blame] | 207 | 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 Chyn | e27a304 | 2019-07-26 14:53:20 -0700 | [diff] [blame] | 216 | Utils.enforceSameOwner(mActivity, userId) /* userId */, |
| 217 | false /* foregroundOnly */); |
Clara Bayarri | c5cde05 | 2015-10-22 17:24:43 +0100 | [diff] [blame] | 218 | } |
| 219 | |
| 220 | /** |
| 221 | * If a pattern, password or PIN exists, prompt the user before allowing them to change it. |
Victor Chang | 5e0a46b | 2016-05-13 17:06:59 +0100 | [diff] [blame] | 222 | * |
| 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 Morales | 6609b0c | 2015-04-12 15:38:25 -0700 | [diff] [blame] | 226 | * @param challenge a challenge to be verified against the device credential. |
Kevin Chyn | e27a304 | 2019-07-26 14:53:20 -0700 | [diff] [blame] | 227 | * @param foregroundOnly if the confirmation activity should be finished if it loses foreground. |
Andres Morales | 6609b0c | 2015-04-12 15:38:25 -0700 | [diff] [blame] | 228 | * @return true if one exists and we launched an activity to confirm it |
Victor Chang | 5e0a46b | 2016-05-13 17:06:59 +0100 | [diff] [blame] | 229 | * @see Activity#onActivityResult(int, int, android.content.Intent) |
Andres Morales | 6609b0c | 2015-04-12 15:38:25 -0700 | [diff] [blame] | 230 | */ |
Jorim Jaggi | 5ad75f0 | 2015-04-22 16:17:23 -0700 | [diff] [blame] | 231 | public boolean launchConfirmationActivity(int request, @Nullable CharSequence title, |
Andres Morales | 6609b0c | 2015-04-12 15:38:25 -0700 | [diff] [blame] | 232 | @Nullable CharSequence header, @Nullable CharSequence description, |
Kevin Chyn | e27a304 | 2019-07-26 14:53:20 -0700 | [diff] [blame] | 233 | long challenge, boolean foregroundOnly) { |
Kevin Chyn | 80ecfd9 | 2018-10-04 12:59:35 -0700 | [diff] [blame] | 234 | 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 Chyn | e27a304 | 2019-07-26 14:53:20 -0700 | [diff] [blame] | 243 | Utils.getCredentialOwnerUserId(mActivity) /* userId */, |
| 244 | foregroundOnly /* foregroundOnly */); |
Andres Morales | 6609b0c | 2015-04-12 15:38:25 -0700 | [diff] [blame] | 245 | } |
| 246 | |
Clara Bayarri | 40db4bb | 2016-01-07 17:10:27 +0000 | [diff] [blame] | 247 | /** |
| 248 | * If a pattern, password or PIN exists, prompt the user before allowing them to change it. |
Victor Chang | 5e0a46b | 2016-05-13 17:06:59 +0100 | [diff] [blame] | 249 | * |
| 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 Bayarri | 40db4bb | 2016-01-07 17:10:27 +0000 | [diff] [blame] | 253 | * @param challenge a challenge to be verified against the device credential. |
Clara Bayarri | 40db4bb | 2016-01-07 17:10:27 +0000 | [diff] [blame] | 254 | * @param userId The userId for whom the lock should be confirmed. |
Kevin Chyn | e27a304 | 2019-07-26 14:53:20 -0700 | [diff] [blame] | 255 | * @param foregroundOnly if the confirmation activity should be finished if it loses foreground. |
Clara Bayarri | 40db4bb | 2016-01-07 17:10:27 +0000 | [diff] [blame] | 256 | * @return true if one exists and we launched an activity to confirm it |
Victor Chang | 5e0a46b | 2016-05-13 17:06:59 +0100 | [diff] [blame] | 257 | * @see Activity#onActivityResult(int, int, android.content.Intent) |
Clara Bayarri | 40db4bb | 2016-01-07 17:10:27 +0000 | [diff] [blame] | 258 | */ |
| 259 | public boolean launchConfirmationActivity(int request, @Nullable CharSequence title, |
| 260 | @Nullable CharSequence header, @Nullable CharSequence description, |
Kevin Chyn | e27a304 | 2019-07-26 14:53:20 -0700 | [diff] [blame] | 261 | long challenge, int userId, boolean foregroundOnly) { |
Kevin Chyn | 80ecfd9 | 2018-10-04 12:59:35 -0700 | [diff] [blame] | 262 | 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 Chyn | e27a304 | 2019-07-26 14:53:20 -0700 | [diff] [blame] | 271 | Utils.enforceSameOwner(mActivity, userId) /* userId */, |
| 272 | foregroundOnly); |
Victor Chang | 5e0a46b | 2016-05-13 17:06:59 +0100 | [diff] [blame] | 273 | } |
| 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 Chyn | 80ecfd9 | 2018-10-04 12:59:35 -0700 | [diff] [blame] | 292 | 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 Chyn | e27a304 | 2019-07-26 14:53:20 -0700 | [diff] [blame] | 301 | Utils.enforceSameOwner(mActivity, userId) /* userId */, |
| 302 | false /* foregroundOnly */); |
Clara Bayarri | 40db4bb | 2016-01-07 17:10:27 +0000 | [diff] [blame] | 303 | } |
| 304 | |
Jeff Sharkey | 219ec91 | 2017-12-19 14:57:39 -0700 | [diff] [blame] | 305 | /** |
| 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 Chyn | 80ecfd9 | 2018-10-04 12:59:35 -0700 | [diff] [blame] | 315 | 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 Sharkey | 219ec91 | 2017-12-19 14:57:39 -0700 | [diff] [blame] | 326 | } |
| 327 | |
Andres Morales | 6609b0c | 2015-04-12 15:38:25 -0700 | [diff] [blame] | 328 | private boolean launchConfirmationActivity(int request, @Nullable CharSequence title, |
| 329 | @Nullable CharSequence header, @Nullable CharSequence description, |
| 330 | boolean returnCredentials, boolean external, boolean hasChallenge, |
Kevin Chyn | e27a304 | 2019-07-26 14:53:20 -0700 | [diff] [blame] | 331 | long challenge, int userId, boolean foregroundOnly) { |
Kevin Chyn | 80ecfd9 | 2018-10-04 12:59:35 -0700 | [diff] [blame] | 332 | 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 Chyn | e27a304 | 2019-07-26 14:53:20 -0700 | [diff] [blame] | 343 | null /* extras */, |
| 344 | foregroundOnly /* foregroundOnly */); |
Jeff Sharkey | 219ec91 | 2017-12-19 14:57:39 -0700 | [diff] [blame] | 345 | } |
| 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 Chyn | 80ecfd9 | 2018-10-04 12:59:35 -0700 | [diff] [blame] | 351 | 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 Chyn | e27a304 | 2019-07-26 14:53:20 -0700 | [diff] [blame] | 362 | extras /* extras */, |
| 363 | false /* foregroundOnly */); |
Adrian Roos | 5a9a3cd | 2017-03-30 18:02:25 -0700 | [diff] [blame] | 364 | } |
| 365 | |
| 366 | public boolean launchFrpConfirmationActivity(int request, @Nullable CharSequence header, |
| 367 | @Nullable CharSequence description, @Nullable CharSequence alternateButton) { |
Kevin Chyn | 80ecfd9 | 2018-10-04 12:59:35 -0700 | [diff] [blame] | 368 | 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 Chyn | e27a304 | 2019-07-26 14:53:20 -0700 | [diff] [blame] | 379 | null /* extras */, |
| 380 | false /* foregroundOnly */); |
Adrian Roos | 5a9a3cd | 2017-03-30 18:02:25 -0700 | [diff] [blame] | 381 | } |
| 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 Chyn | e27a304 | 2019-07-26 14:53:20 -0700 | [diff] [blame] | 386 | long challenge, int userId, @Nullable CharSequence alternateButton, Bundle extras, |
| 387 | boolean foregroundOnly) { |
Ricky Wai | 996d0df | 2016-04-05 16:33:47 +0100 | [diff] [blame] | 388 | final int effectiveUserId = UserManager.get(mActivity).getCredentialOwnerProfile(userId); |
Jim Miller | 00d2476 | 2009-12-22 19:04:57 -0800 | [diff] [blame] | 389 | boolean launched = false; |
Andres Morales | 7bdffd8 | 2015-08-04 16:55:00 -0700 | [diff] [blame] | 390 | |
Andres Morales | 7bdffd8 | 2015-08-04 16:55:00 -0700 | [diff] [blame] | 391 | switch (mLockPatternUtils.getKeyguardStoredPasswordQuality(effectiveUserId)) { |
Jim Miller | af366a3 | 2010-03-25 18:45:22 -0700 | [diff] [blame] | 392 | case DevicePolicyManager.PASSWORD_QUALITY_SOMETHING: |
Jorim Jaggi | 8a09b61 | 2015-04-06 17:47:18 -0700 | [diff] [blame] | 393 | launched = launchConfirmationActivity(request, title, header, description, |
Andres Morales | 6609b0c | 2015-04-12 15:38:25 -0700 | [diff] [blame] | 394 | returnCredentials || hasChallenge |
Jorim Jaggi | 8a09b61 | 2015-04-06 17:47:18 -0700 | [diff] [blame] | 395 | ? ConfirmLockPattern.InternalActivity.class |
Victor Chang | 5e0a46b | 2016-05-13 17:06:59 +0100 | [diff] [blame] | 396 | : ConfirmLockPattern.class, returnCredentials, external, |
Kevin Chyn | e27a304 | 2019-07-26 14:53:20 -0700 | [diff] [blame] | 397 | hasChallenge, challenge, userId, alternateButton, extras, |
| 398 | foregroundOnly); |
Jim Miller | 00d2476 | 2009-12-22 19:04:57 -0800 | [diff] [blame] | 399 | break; |
Jim Miller | af366a3 | 2010-03-25 18:45:22 -0700 | [diff] [blame] | 400 | case DevicePolicyManager.PASSWORD_QUALITY_NUMERIC: |
Nicolas Prevot | 8fd852e | 2014-01-25 01:02:04 +0000 | [diff] [blame] | 401 | case DevicePolicyManager.PASSWORD_QUALITY_NUMERIC_COMPLEX: |
Jim Miller | af366a3 | 2010-03-25 18:45:22 -0700 | [diff] [blame] | 402 | case DevicePolicyManager.PASSWORD_QUALITY_ALPHABETIC: |
Jim Miller | 9c1e7f8 | 2010-04-08 00:48:52 -0700 | [diff] [blame] | 403 | case DevicePolicyManager.PASSWORD_QUALITY_ALPHANUMERIC: |
Konstantin Lopyrev | 57fbf69 | 2010-05-27 16:01:41 -0700 | [diff] [blame] | 404 | case DevicePolicyManager.PASSWORD_QUALITY_COMPLEX: |
Toni Barzic | e7d6e4d | 2016-03-30 11:43:19 -0700 | [diff] [blame] | 405 | case DevicePolicyManager.PASSWORD_QUALITY_MANAGED: |
Jorim Jaggi | 8a09b61 | 2015-04-06 17:47:18 -0700 | [diff] [blame] | 406 | launched = launchConfirmationActivity(request, title, header, description, |
Andres Morales | 6609b0c | 2015-04-12 15:38:25 -0700 | [diff] [blame] | 407 | returnCredentials || hasChallenge |
Jorim Jaggi | 8a09b61 | 2015-04-06 17:47:18 -0700 | [diff] [blame] | 408 | ? ConfirmLockPassword.InternalActivity.class |
Victor Chang | 5e0a46b | 2016-05-13 17:06:59 +0100 | [diff] [blame] | 409 | : ConfirmLockPassword.class, returnCredentials, external, |
Kevin Chyn | e27a304 | 2019-07-26 14:53:20 -0700 | [diff] [blame] | 410 | hasChallenge, challenge, userId, alternateButton, extras, |
| 411 | foregroundOnly); |
Jim Miller | 00d2476 | 2009-12-22 19:04:57 -0800 | [diff] [blame] | 412 | break; |
| 413 | } |
| 414 | return launched; |
| 415 | } |
| 416 | |
Jorim Jaggi | 8a09b61 | 2015-04-06 17:47:18 -0700 | [diff] [blame] | 417 | private boolean launchConfirmationActivity(int request, CharSequence title, CharSequence header, |
Victor Chang | 5e0a46b | 2016-05-13 17:06:59 +0100 | [diff] [blame] | 418 | CharSequence message, Class<?> activityClass, boolean returnCredentials, |
| 419 | boolean external, boolean hasChallenge, long challenge, |
Kevin Chyn | e27a304 | 2019-07-26 14:53:20 -0700 | [diff] [blame] | 420 | int userId, @Nullable CharSequence alternateButton, Bundle extras, |
| 421 | boolean foregroundOnly) { |
Jim Miller | 00d2476 | 2009-12-22 19:04:57 -0800 | [diff] [blame] | 422 | final Intent intent = new Intent(); |
Jorim Jaggi | 8a09b61 | 2015-04-06 17:47:18 -0700 | [diff] [blame] | 423 | intent.putExtra(ConfirmDeviceCredentialBaseFragment.TITLE_TEXT, title); |
| 424 | intent.putExtra(ConfirmDeviceCredentialBaseFragment.HEADER_TEXT, header); |
| 425 | intent.putExtra(ConfirmDeviceCredentialBaseFragment.DETAILS_TEXT, message); |
Maurice Lam | 0283372 | 2018-04-25 17:53:13 -0700 | [diff] [blame] | 426 | // TODO: Remove dark theme and show_cancel_button options since they are no longer used |
Maurice Lam | 3e3b8a9 | 2018-03-21 18:21:04 -0700 | [diff] [blame] | 427 | intent.putExtra(ConfirmDeviceCredentialBaseFragment.DARK_THEME, false); |
Maurice Lam | 0283372 | 2018-04-25 17:53:13 -0700 | [diff] [blame] | 428 | intent.putExtra(ConfirmDeviceCredentialBaseFragment.SHOW_CANCEL_BUTTON, false); |
Jorim Jaggi | 8a09b61 | 2015-04-06 17:47:18 -0700 | [diff] [blame] | 429 | intent.putExtra(ConfirmDeviceCredentialBaseFragment.SHOW_WHEN_LOCKED, external); |
Kevin Chyn | b3ee231 | 2018-10-04 15:01:43 -0700 | [diff] [blame] | 430 | intent.putExtra(ConfirmDeviceCredentialBaseFragment.USE_FADE_ANIMATION, external); |
Victor Chang | 5e0a46b | 2016-05-13 17:06:59 +0100 | [diff] [blame] | 431 | intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_RETURN_CREDENTIALS, returnCredentials); |
Andres Morales | 6609b0c | 2015-04-12 15:38:25 -0700 | [diff] [blame] | 432 | intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_HAS_CHALLENGE, hasChallenge); |
| 433 | intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE, challenge); |
Clara Bayarri | 6934a04 | 2015-10-14 11:07:35 +0100 | [diff] [blame] | 434 | intent.putExtra(Intent.EXTRA_USER_ID, userId); |
Adrian Roos | 5a9a3cd | 2017-03-30 18:02:25 -0700 | [diff] [blame] | 435 | intent.putExtra(KeyguardManager.EXTRA_ALTERNATE_BUTTON_LABEL, alternateButton); |
Kevin Chyn | e27a304 | 2019-07-26 14:53:20 -0700 | [diff] [blame] | 436 | intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_FOREGROUND_ONLY, foregroundOnly); |
Jeff Sharkey | 219ec91 | 2017-12-19 14:57:39 -0700 | [diff] [blame] | 437 | if (extras != null) { |
| 438 | intent.putExtras(extras); |
| 439 | } |
Fan Zhang | c3fd289 | 2019-01-29 16:00:19 -0800 | [diff] [blame] | 440 | intent.setClassName(SETTINGS_PACKAGE_NAME, activityClass.getName()); |
Jorim Jaggi | 74a2283 | 2015-09-10 20:12:19 -0700 | [diff] [blame] | 441 | if (external) { |
| 442 | intent.addFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT); |
| 443 | if (mFragment != null) { |
Clara Bayarri | 86ebaa2 | 2015-12-10 12:35:27 +0000 | [diff] [blame] | 444 | copyOptionalExtras(mFragment.getActivity().getIntent(), intent); |
Jorim Jaggi | 74a2283 | 2015-09-10 20:12:19 -0700 | [diff] [blame] | 445 | mFragment.startActivity(intent); |
| 446 | } else { |
Clara Bayarri | 86ebaa2 | 2015-12-10 12:35:27 +0000 | [diff] [blame] | 447 | copyOptionalExtras(mActivity.getIntent(), intent); |
Jorim Jaggi | 74a2283 | 2015-09-10 20:12:19 -0700 | [diff] [blame] | 448 | mActivity.startActivity(intent); |
| 449 | } |
Amith Yamasani | b14e1e0 | 2010-11-02 09:52:29 -0700 | [diff] [blame] | 450 | } else { |
Jorim Jaggi | 74a2283 | 2015-09-10 20:12:19 -0700 | [diff] [blame] | 451 | if (mFragment != null) { |
Maurice Lam | 8461725 | 2017-06-12 12:15:40 -0700 | [diff] [blame] | 452 | copyInternalExtras(mFragment.getActivity().getIntent(), intent); |
Jorim Jaggi | 74a2283 | 2015-09-10 20:12:19 -0700 | [diff] [blame] | 453 | mFragment.startActivityForResult(intent, request); |
| 454 | } else { |
Maurice Lam | 8461725 | 2017-06-12 12:15:40 -0700 | [diff] [blame] | 455 | copyInternalExtras(mActivity.getIntent(), intent); |
Jorim Jaggi | 74a2283 | 2015-09-10 20:12:19 -0700 | [diff] [blame] | 456 | mActivity.startActivityForResult(intent, request); |
| 457 | } |
Amith Yamasani | b14e1e0 | 2010-11-02 09:52:29 -0700 | [diff] [blame] | 458 | } |
Jim Miller | 00d2476 | 2009-12-22 19:04:57 -0800 | [diff] [blame] | 459 | return true; |
| 460 | } |
Clara Bayarri | 86ebaa2 | 2015-12-10 12:35:27 +0000 | [diff] [blame] | 461 | |
| 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 Mak | b7f1edd | 2016-03-18 12:20:28 +0000 | [diff] [blame] | 477 | outIntent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY); |
Clara Bayarri | 86ebaa2 | 2015-12-10 12:35:27 +0000 | [diff] [blame] | 478 | } |
| 479 | } |
Maurice Lam | 8461725 | 2017-06-12 12:15:40 -0700 | [diff] [blame] | 480 | |
| 481 | private void copyInternalExtras(Intent inIntent, Intent outIntent) { |
cnchen | caf122b | 2019-04-03 16:18:34 +0800 | [diff] [blame] | 482 | SetupWizardUtils.copySetupExtras(inIntent, outIntent); |
Maurice Lam | 8461725 | 2017-06-12 12:15:40 -0700 | [diff] [blame] | 483 | String theme = inIntent.getStringExtra(WizardManagerHelper.EXTRA_THEME); |
| 484 | if (theme != null) { |
| 485 | outIntent.putExtra(WizardManagerHelper.EXTRA_THEME, theme); |
| 486 | } |
| 487 | } |
Jim Miller | 00d2476 | 2009-12-22 19:04:57 -0800 | [diff] [blame] | 488 | } |