Kevin Chyn | aae4a15 | 2018-01-18 11:48:09 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2018 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 |
Kevin Chyn | f8688a0 | 2019-08-27 17:04:05 -0700 | [diff] [blame] | 14 | * limitations under the License. |
Kevin Chyn | aae4a15 | 2018-01-18 11:48:09 -0800 | [diff] [blame] | 15 | */ |
| 16 | |
Kevin Chyn | e927566 | 2018-07-23 16:42:06 -0700 | [diff] [blame] | 17 | package com.android.systemui.biometrics; |
Kevin Chyn | aae4a15 | 2018-01-18 11:48:09 -0800 | [diff] [blame] | 18 | |
Kevin Chyn | 050315f | 2019-08-08 14:22:54 -0700 | [diff] [blame] | 19 | import android.app.ActivityManager; |
| 20 | import android.app.ActivityTaskManager; |
| 21 | import android.app.IActivityTaskManager; |
| 22 | import android.app.TaskStackListener; |
Kevin Chyn | 42653e8 | 2018-01-19 14:15:46 -0800 | [diff] [blame] | 23 | import android.content.Context; |
Kevin Chyn | aae4a15 | 2018-01-18 11:48:09 -0800 | [diff] [blame] | 24 | import android.content.pm.PackageManager; |
Gus Prevas | a7df7b2 | 2018-10-30 10:29:34 -0400 | [diff] [blame] | 25 | import android.content.res.Configuration; |
Kevin Chyn | 86f1b8e | 2019-09-24 19:00:49 -0700 | [diff] [blame] | 26 | import android.hardware.biometrics.Authenticator; |
Kevin Chyn | 8429da2 | 2019-09-24 12:42:35 -0700 | [diff] [blame] | 27 | import android.hardware.biometrics.BiometricConstants; |
Vishwath Mohan | ecf00ce | 2018-04-05 10:28:24 -0700 | [diff] [blame] | 28 | import android.hardware.biometrics.BiometricPrompt; |
Kevin Chyn | 23289ef | 2018-11-28 16:32:36 -0800 | [diff] [blame] | 29 | import android.hardware.biometrics.IBiometricServiceReceiverInternal; |
Kevin Chyn | aae4a15 | 2018-01-18 11:48:09 -0800 | [diff] [blame] | 30 | import android.os.Bundle; |
Kevin Chyn | 050315f | 2019-08-08 14:22:54 -0700 | [diff] [blame] | 31 | import android.os.Handler; |
| 32 | import android.os.Looper; |
Kevin Chyn | 42653e8 | 2018-01-19 14:15:46 -0800 | [diff] [blame] | 33 | import android.os.RemoteException; |
Kevin Chyn | aae4a15 | 2018-01-18 11:48:09 -0800 | [diff] [blame] | 34 | import android.util.Log; |
Kevin Chyn | 42653e8 | 2018-01-19 14:15:46 -0800 | [diff] [blame] | 35 | import android.view.WindowManager; |
Kevin Chyn | aae4a15 | 2018-01-18 11:48:09 -0800 | [diff] [blame] | 36 | |
Kevin Chyn | 050315f | 2019-08-08 14:22:54 -0700 | [diff] [blame] | 37 | import com.android.internal.annotations.VisibleForTesting; |
Kevin Chyn | 42653e8 | 2018-01-19 14:15:46 -0800 | [diff] [blame] | 38 | import com.android.internal.os.SomeArgs; |
Kevin Chyn | aae4a15 | 2018-01-18 11:48:09 -0800 | [diff] [blame] | 39 | import com.android.systemui.SystemUI; |
| 40 | import com.android.systemui.statusbar.CommandQueue; |
| 41 | |
Kevin Chyn | 050315f | 2019-08-08 14:22:54 -0700 | [diff] [blame] | 42 | import java.util.List; |
| 43 | |
Kevin Chyn | e927566 | 2018-07-23 16:42:06 -0700 | [diff] [blame] | 44 | /** |
Kevin Chyn | c53d981 | 2019-07-30 18:10:30 -0700 | [diff] [blame] | 45 | * Receives messages sent from {@link com.android.server.biometrics.BiometricService} and shows the |
| 46 | * appropriate biometric UI (e.g. BiometricDialogView). |
Kevin Chyn | e927566 | 2018-07-23 16:42:06 -0700 | [diff] [blame] | 47 | */ |
Kevin Chyn | f8688a0 | 2019-08-27 17:04:05 -0700 | [diff] [blame] | 48 | public class AuthController extends SystemUI implements CommandQueue.Callbacks, |
| 49 | AuthDialogCallback { |
Kevin Chyn | fc46826 | 2019-08-20 17:17:11 -0700 | [diff] [blame] | 50 | |
Kevin Chyn | f8688a0 | 2019-08-27 17:04:05 -0700 | [diff] [blame] | 51 | private static final String TAG = "BiometricPrompt/AuthController"; |
Kevin Chyn | 42653e8 | 2018-01-19 14:15:46 -0800 | [diff] [blame] | 52 | private static final boolean DEBUG = true; |
| 53 | |
Kevin Chyn | 050315f | 2019-08-08 14:22:54 -0700 | [diff] [blame] | 54 | private final Injector mInjector; |
| 55 | |
Kevin Chyn | c53d981 | 2019-07-30 18:10:30 -0700 | [diff] [blame] | 56 | // TODO: These should just be saved from onSaveState |
Gus Prevas | a7df7b2 | 2018-10-30 10:29:34 -0400 | [diff] [blame] | 57 | private SomeArgs mCurrentDialogArgs; |
Kevin Chyn | 050315f | 2019-08-08 14:22:54 -0700 | [diff] [blame] | 58 | @VisibleForTesting |
Kevin Chyn | f8688a0 | 2019-08-27 17:04:05 -0700 | [diff] [blame] | 59 | AuthDialog mCurrentDialog; |
Kevin Chyn | c53d981 | 2019-07-30 18:10:30 -0700 | [diff] [blame] | 60 | |
Kevin Chyn | 050315f | 2019-08-08 14:22:54 -0700 | [diff] [blame] | 61 | private Handler mHandler = new Handler(Looper.getMainLooper()); |
Kevin Chyn | 42653e8 | 2018-01-19 14:15:46 -0800 | [diff] [blame] | 62 | private WindowManager mWindowManager; |
Kevin Chyn | 050315f | 2019-08-08 14:22:54 -0700 | [diff] [blame] | 63 | @VisibleForTesting |
| 64 | IActivityTaskManager mActivityTaskManager; |
| 65 | @VisibleForTesting |
| 66 | BiometricTaskStackListener mTaskStackListener; |
| 67 | @VisibleForTesting |
| 68 | IBiometricServiceReceiverInternal mReceiver; |
| 69 | |
| 70 | public class BiometricTaskStackListener extends TaskStackListener { |
| 71 | @Override |
| 72 | public void onTaskStackChanged() { |
| 73 | mHandler.post(mTaskStackChangedRunnable); |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | private final Runnable mTaskStackChangedRunnable = () -> { |
| 78 | if (mCurrentDialog != null) { |
| 79 | try { |
| 80 | final String clientPackage = mCurrentDialog.getOpPackageName(); |
| 81 | Log.w(TAG, "Task stack changed, current client: " + clientPackage); |
| 82 | final List<ActivityManager.RunningTaskInfo> runningTasks = |
| 83 | mActivityTaskManager.getTasks(1); |
| 84 | if (!runningTasks.isEmpty()) { |
| 85 | final String topPackage = runningTasks.get(0).topActivity.getPackageName(); |
| 86 | if (!topPackage.contentEquals(clientPackage)) { |
| 87 | Log.w(TAG, "Evicting client due to: " + topPackage); |
| 88 | mCurrentDialog.dismissWithoutCallback(true /* animate */); |
| 89 | mCurrentDialog = null; |
| 90 | mReceiver.onDialogDismissed(BiometricPrompt.DISMISSED_REASON_USER_CANCEL); |
| 91 | mReceiver = null; |
| 92 | } |
| 93 | } |
| 94 | } catch (RemoteException e) { |
| 95 | Log.e(TAG, "Remote exception", e); |
| 96 | } |
| 97 | } |
| 98 | }; |
Kevin Chyn | 42653e8 | 2018-01-19 14:15:46 -0800 | [diff] [blame] | 99 | |
Kevin Chyn | c53d981 | 2019-07-30 18:10:30 -0700 | [diff] [blame] | 100 | @Override |
| 101 | public void onTryAgainPressed() { |
| 102 | try { |
| 103 | mReceiver.onTryAgainPressed(); |
| 104 | } catch (RemoteException e) { |
| 105 | Log.e(TAG, "RemoteException when handling try again", e); |
Kevin Chyn | 5906c17 | 2018-07-23 15:43:02 -0700 | [diff] [blame] | 106 | } |
| 107 | } |
| 108 | |
Kevin Chyn | c53d981 | 2019-07-30 18:10:30 -0700 | [diff] [blame] | 109 | @Override |
Kevin Chyn | ff168dc | 2019-09-16 16:04:38 -0700 | [diff] [blame] | 110 | public void onDeviceCredentialPressed() { |
| 111 | try { |
| 112 | mReceiver.onDeviceCredentialPressed(); |
| 113 | } catch (RemoteException e) { |
| 114 | Log.e(TAG, "RemoteException when handling credential button", e); |
| 115 | } |
| 116 | } |
| 117 | |
| 118 | @Override |
Kevin Chyn | 050315f | 2019-08-08 14:22:54 -0700 | [diff] [blame] | 119 | public void onDismissed(@DismissedReason int reason) { |
Kevin Chyn | c53d981 | 2019-07-30 18:10:30 -0700 | [diff] [blame] | 120 | switch (reason) { |
Kevin Chyn | f8688a0 | 2019-08-27 17:04:05 -0700 | [diff] [blame] | 121 | case AuthDialogCallback.DISMISSED_USER_CANCELED: |
Kevin Chyn | c53d981 | 2019-07-30 18:10:30 -0700 | [diff] [blame] | 122 | sendResultAndCleanUp(BiometricPrompt.DISMISSED_REASON_USER_CANCEL); |
| 123 | break; |
| 124 | |
Kevin Chyn | f8688a0 | 2019-08-27 17:04:05 -0700 | [diff] [blame] | 125 | case AuthDialogCallback.DISMISSED_BUTTON_NEGATIVE: |
Kevin Chyn | c53d981 | 2019-07-30 18:10:30 -0700 | [diff] [blame] | 126 | sendResultAndCleanUp(BiometricPrompt.DISMISSED_REASON_NEGATIVE); |
| 127 | break; |
| 128 | |
Kevin Chyn | f8688a0 | 2019-08-27 17:04:05 -0700 | [diff] [blame] | 129 | case AuthDialogCallback.DISMISSED_BUTTON_POSITIVE: |
Kevin Chyn | ff168dc | 2019-09-16 16:04:38 -0700 | [diff] [blame] | 130 | sendResultAndCleanUp(BiometricPrompt.DISMISSED_REASON_BIOMETRIC_CONFIRMED); |
Kevin Chyn | c53d981 | 2019-07-30 18:10:30 -0700 | [diff] [blame] | 131 | break; |
| 132 | |
Kevin Chyn | ff168dc | 2019-09-16 16:04:38 -0700 | [diff] [blame] | 133 | case AuthDialogCallback.DISMISSED_BIOMETRIC_AUTHENTICATED: |
| 134 | sendResultAndCleanUp( |
| 135 | BiometricPrompt.DISMISSED_REASON_BIOMETRIC_CONFIRM_NOT_REQUIRED); |
Kevin Chyn | c53d981 | 2019-07-30 18:10:30 -0700 | [diff] [blame] | 136 | break; |
| 137 | |
Kevin Chyn | f8688a0 | 2019-08-27 17:04:05 -0700 | [diff] [blame] | 138 | case AuthDialogCallback.DISMISSED_ERROR: |
Kevin Chyn | c53d981 | 2019-07-30 18:10:30 -0700 | [diff] [blame] | 139 | sendResultAndCleanUp(BiometricPrompt.DISMISSED_REASON_ERROR); |
Kevin Chyn | c53d981 | 2019-07-30 18:10:30 -0700 | [diff] [blame] | 140 | break; |
Kevin Chyn | 050315f | 2019-08-08 14:22:54 -0700 | [diff] [blame] | 141 | |
Kevin Chyn | f8688a0 | 2019-08-27 17:04:05 -0700 | [diff] [blame] | 142 | case AuthDialogCallback.DISMISSED_BY_SYSTEM_SERVER: |
Kevin Chyn | 050315f | 2019-08-08 14:22:54 -0700 | [diff] [blame] | 143 | sendResultAndCleanUp(BiometricPrompt.DISMISSED_REASON_SERVER_REQUESTED); |
| 144 | break; |
| 145 | |
Kevin Chyn | ff168dc | 2019-09-16 16:04:38 -0700 | [diff] [blame] | 146 | case AuthDialogCallback.DISMISSED_CREDENTIAL_AUTHENTICATED: |
| 147 | sendResultAndCleanUp(BiometricPrompt.DISMISSED_REASON_CREDENTIAL_CONFIRMED); |
| 148 | break; |
| 149 | |
Kevin Chyn | c53d981 | 2019-07-30 18:10:30 -0700 | [diff] [blame] | 150 | default: |
| 151 | Log.e(TAG, "Unhandled reason: " + reason); |
| 152 | break; |
Kevin Chyn | c94b7db | 2019-05-15 17:28:16 -0700 | [diff] [blame] | 153 | } |
Kevin Chyn | c53d981 | 2019-07-30 18:10:30 -0700 | [diff] [blame] | 154 | } |
| 155 | |
Kevin Chyn | 050315f | 2019-08-08 14:22:54 -0700 | [diff] [blame] | 156 | private void sendResultAndCleanUp(@DismissedReason int reason) { |
Kevin Chyn | c53d981 | 2019-07-30 18:10:30 -0700 | [diff] [blame] | 157 | if (mReceiver == null) { |
| 158 | Log.e(TAG, "Receiver is null"); |
| 159 | return; |
| 160 | } |
| 161 | try { |
Kevin Chyn | 050315f | 2019-08-08 14:22:54 -0700 | [diff] [blame] | 162 | mReceiver.onDialogDismissed(reason); |
Kevin Chyn | c53d981 | 2019-07-30 18:10:30 -0700 | [diff] [blame] | 163 | } catch (RemoteException e) { |
| 164 | Log.w(TAG, "Remote exception", e); |
| 165 | } |
Kevin Chyn | 050315f | 2019-08-08 14:22:54 -0700 | [diff] [blame] | 166 | onDialogDismissed(reason); |
| 167 | } |
| 168 | |
| 169 | public static class Injector { |
| 170 | IActivityTaskManager getActivityTaskManager() { |
| 171 | return ActivityTaskManager.getService(); |
| 172 | } |
| 173 | } |
| 174 | |
Dave Mankoff | a5d8a39 | 2019-10-10 12:21:09 -0400 | [diff] [blame^] | 175 | public AuthController(Context context) { |
| 176 | this(context, new Injector()); |
Kevin Chyn | 050315f | 2019-08-08 14:22:54 -0700 | [diff] [blame] | 177 | } |
| 178 | |
| 179 | @VisibleForTesting |
Dave Mankoff | a5d8a39 | 2019-10-10 12:21:09 -0400 | [diff] [blame^] | 180 | AuthController(Context context, Injector injector) { |
| 181 | super(context); |
Kevin Chyn | 050315f | 2019-08-08 14:22:54 -0700 | [diff] [blame] | 182 | mInjector = injector; |
Kevin Chyn | c53d981 | 2019-07-30 18:10:30 -0700 | [diff] [blame] | 183 | } |
Kevin Chyn | c94b7db | 2019-05-15 17:28:16 -0700 | [diff] [blame] | 184 | |
Kevin Chyn | aae4a15 | 2018-01-18 11:48:09 -0800 | [diff] [blame] | 185 | @Override |
| 186 | public void start() { |
Kevin Chyn | e191271 | 2019-01-04 14:22:34 -0800 | [diff] [blame] | 187 | final PackageManager pm = mContext.getPackageManager(); |
| 188 | if (pm.hasSystemFeature(PackageManager.FEATURE_FINGERPRINT) |
| 189 | || pm.hasSystemFeature(PackageManager.FEATURE_FACE) |
| 190 | || pm.hasSystemFeature(PackageManager.FEATURE_IRIS)) { |
Jason Monk | d7c9855 | 2018-12-04 11:14:50 -0500 | [diff] [blame] | 191 | getComponent(CommandQueue.class).addCallback(this); |
Gus Prevas | a7df7b2 | 2018-10-30 10:29:34 -0400 | [diff] [blame] | 192 | mWindowManager = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE); |
Kevin Chyn | 050315f | 2019-08-08 14:22:54 -0700 | [diff] [blame] | 193 | mActivityTaskManager = mInjector.getActivityTaskManager(); |
| 194 | |
| 195 | try { |
| 196 | mTaskStackListener = new BiometricTaskStackListener(); |
| 197 | mActivityTaskManager.registerTaskStackListener(mTaskStackListener); |
| 198 | } catch (RemoteException e) { |
| 199 | Log.w(TAG, "Unable to register task stack listener", e); |
| 200 | } |
Gus Prevas | a7df7b2 | 2018-10-30 10:29:34 -0400 | [diff] [blame] | 201 | } |
| 202 | } |
| 203 | |
Kevin Chyn | aae4a15 | 2018-01-18 11:48:09 -0800 | [diff] [blame] | 204 | @Override |
Kevin Chyn | 86f1b8e | 2019-09-24 19:00:49 -0700 | [diff] [blame] | 205 | public void showAuthenticationDialog(Bundle bundle, IBiometricServiceReceiverInternal receiver, |
| 206 | int biometricModality, boolean requireConfirmation, int userId, String opPackageName) { |
| 207 | final int authenticators = Utils.getAuthenticators(bundle); |
| 208 | |
Kevin Chyn | 158fefb | 2019-01-03 18:59:05 -0800 | [diff] [blame] | 209 | if (DEBUG) { |
Kevin Chyn | 86f1b8e | 2019-09-24 19:00:49 -0700 | [diff] [blame] | 210 | Log.d(TAG, "showAuthenticationDialog, authenticators: " + authenticators |
| 211 | + ", biometricModality: " + biometricModality |
Kevin Chyn | 158fefb | 2019-01-03 18:59:05 -0800 | [diff] [blame] | 212 | + ", requireConfirmation: " + requireConfirmation); |
| 213 | } |
Kevin Chyn | 42653e8 | 2018-01-19 14:15:46 -0800 | [diff] [blame] | 214 | SomeArgs args = SomeArgs.obtain(); |
| 215 | args.arg1 = bundle; |
| 216 | args.arg2 = receiver; |
Kevin Chyn | 86f1b8e | 2019-09-24 19:00:49 -0700 | [diff] [blame] | 217 | args.argi1 = biometricModality; |
Kevin Chyn | 6cf54e8 | 2018-09-18 19:13:27 -0700 | [diff] [blame] | 218 | args.arg3 = requireConfirmation; |
Kevin Chyn | 1b9f8df | 2018-11-12 19:04:55 -0800 | [diff] [blame] | 219 | args.argi2 = userId; |
Kevin Chyn | 050315f | 2019-08-08 14:22:54 -0700 | [diff] [blame] | 220 | args.arg4 = opPackageName; |
Kevin Chyn | c53d981 | 2019-07-30 18:10:30 -0700 | [diff] [blame] | 221 | |
| 222 | boolean skipAnimation = false; |
| 223 | if (mCurrentDialog != null) { |
| 224 | Log.w(TAG, "mCurrentDialog: " + mCurrentDialog); |
| 225 | skipAnimation = true; |
| 226 | } |
Kevin Chyn | 86f1b8e | 2019-09-24 19:00:49 -0700 | [diff] [blame] | 227 | |
| 228 | showDialog(args, skipAnimation, null /* savedState */); |
Kevin Chyn | aae4a15 | 2018-01-18 11:48:09 -0800 | [diff] [blame] | 229 | } |
| 230 | |
| 231 | @Override |
Kevin Chyn | e674e85 | 2019-04-24 12:39:40 -0700 | [diff] [blame] | 232 | public void onBiometricAuthenticated(boolean authenticated, String failureReason) { |
| 233 | if (DEBUG) Log.d(TAG, "onBiometricAuthenticated: " + authenticated |
| 234 | + " reason: " + failureReason); |
| 235 | |
Kevin Chyn | e191271 | 2019-01-04 14:22:34 -0800 | [diff] [blame] | 236 | if (authenticated) { |
Kevin Chyn | c53d981 | 2019-07-30 18:10:30 -0700 | [diff] [blame] | 237 | mCurrentDialog.onAuthenticationSucceeded(); |
Kevin Chyn | 6cf54e8 | 2018-09-18 19:13:27 -0700 | [diff] [blame] | 238 | } else { |
Kevin Chyn | 3b53d6f | 2019-05-01 11:49:05 -0700 | [diff] [blame] | 239 | mCurrentDialog.onAuthenticationFailed(failureReason); |
Kevin Chyn | 6cf54e8 | 2018-09-18 19:13:27 -0700 | [diff] [blame] | 240 | } |
Kevin Chyn | 42653e8 | 2018-01-19 14:15:46 -0800 | [diff] [blame] | 241 | } |
| 242 | |
Kevin Chyn | c53d981 | 2019-07-30 18:10:30 -0700 | [diff] [blame] | 243 | @Override |
| 244 | public void onBiometricHelp(String message) { |
| 245 | if (DEBUG) Log.d(TAG, "onBiometricHelp: " + message); |
| 246 | |
| 247 | mCurrentDialog.onHelp(message); |
Kevin Chyn | 42653e8 | 2018-01-19 14:15:46 -0800 | [diff] [blame] | 248 | } |
| 249 | |
Kevin Chyn | c53d981 | 2019-07-30 18:10:30 -0700 | [diff] [blame] | 250 | @Override |
Kevin Chyn | 8429da2 | 2019-09-24 12:42:35 -0700 | [diff] [blame] | 251 | public void onBiometricError(int errorCode, String error) { |
| 252 | if (DEBUG) Log.d(TAG, "onBiometricError: " + errorCode + ", " + error); |
| 253 | |
| 254 | final boolean isLockout = errorCode == BiometricConstants.BIOMETRIC_ERROR_LOCKOUT |
| 255 | || errorCode == BiometricConstants.BIOMETRIC_ERROR_LOCKOUT_PERMANENT; |
| 256 | if (mCurrentDialog.isAllowDeviceCredentials() && isLockout) { |
| 257 | mCurrentDialog.animateToCredentialUI(); |
| 258 | } else { |
| 259 | mCurrentDialog.onError(error); |
| 260 | } |
Kevin Chyn | 42653e8 | 2018-01-19 14:15:46 -0800 | [diff] [blame] | 261 | } |
| 262 | |
Kevin Chyn | c53d981 | 2019-07-30 18:10:30 -0700 | [diff] [blame] | 263 | @Override |
Kevin Chyn | 86f1b8e | 2019-09-24 19:00:49 -0700 | [diff] [blame] | 264 | public void hideAuthenticationDialog() { |
| 265 | if (DEBUG) Log.d(TAG, "hideAuthenticationDialog"); |
Kevin Chyn | c53d981 | 2019-07-30 18:10:30 -0700 | [diff] [blame] | 266 | |
Kevin Chyn | 050315f | 2019-08-08 14:22:54 -0700 | [diff] [blame] | 267 | mCurrentDialog.dismissFromSystemServer(); |
Kevin Chyn | c53d981 | 2019-07-30 18:10:30 -0700 | [diff] [blame] | 268 | } |
| 269 | |
Kevin Chyn | 86f1b8e | 2019-09-24 19:00:49 -0700 | [diff] [blame] | 270 | private void showDialog(SomeArgs args, boolean skipAnimation, Bundle savedState) { |
Kevin Chyn | c53d981 | 2019-07-30 18:10:30 -0700 | [diff] [blame] | 271 | mCurrentDialogArgs = args; |
| 272 | final int type = args.argi1; |
Kevin Chyn | 050315f | 2019-08-08 14:22:54 -0700 | [diff] [blame] | 273 | final Bundle biometricPromptBundle = (Bundle) args.arg1; |
| 274 | final boolean requireConfirmation = (boolean) args.arg3; |
| 275 | final int userId = args.argi2; |
| 276 | final String opPackageName = (String) args.arg4; |
Kevin Chyn | c53d981 | 2019-07-30 18:10:30 -0700 | [diff] [blame] | 277 | |
| 278 | // Create a new dialog but do not replace the current one yet. |
Kevin Chyn | f8688a0 | 2019-08-27 17:04:05 -0700 | [diff] [blame] | 279 | final AuthDialog newDialog = buildDialog( |
Kevin Chyn | 050315f | 2019-08-08 14:22:54 -0700 | [diff] [blame] | 280 | biometricPromptBundle, |
| 281 | requireConfirmation, |
| 282 | userId, |
| 283 | type, |
Kevin Chyn | fc46826 | 2019-08-20 17:17:11 -0700 | [diff] [blame] | 284 | opPackageName, |
Kevin Chyn | 86f1b8e | 2019-09-24 19:00:49 -0700 | [diff] [blame] | 285 | skipAnimation); |
Kevin Chyn | c53d981 | 2019-07-30 18:10:30 -0700 | [diff] [blame] | 286 | |
| 287 | if (newDialog == null) { |
| 288 | Log.e(TAG, "Unsupported type: " + type); |
Kevin Chyn | 42653e8 | 2018-01-19 14:15:46 -0800 | [diff] [blame] | 289 | return; |
| 290 | } |
Kevin Chyn | c53d981 | 2019-07-30 18:10:30 -0700 | [diff] [blame] | 291 | |
| 292 | if (DEBUG) { |
Kevin Chyn | 86f1b8e | 2019-09-24 19:00:49 -0700 | [diff] [blame] | 293 | Log.d(TAG, "showDialog: " + args |
Kevin Chyn | c53d981 | 2019-07-30 18:10:30 -0700 | [diff] [blame] | 294 | + " savedState: " + savedState |
| 295 | + " mCurrentDialog: " + mCurrentDialog |
| 296 | + " newDialog: " + newDialog |
Kevin Chyn | 86f1b8e | 2019-09-24 19:00:49 -0700 | [diff] [blame] | 297 | + " type: " + type); |
Kevin Chyn | c53d981 | 2019-07-30 18:10:30 -0700 | [diff] [blame] | 298 | } |
| 299 | |
Kevin Chyn | 9cf8991 | 2019-08-30 13:33:58 -0700 | [diff] [blame] | 300 | if (mCurrentDialog != null) { |
Kevin Chyn | c53d981 | 2019-07-30 18:10:30 -0700 | [diff] [blame] | 301 | // If somehow we're asked to show a dialog, the old one doesn't need to be animated |
| 302 | // away. This can happen if the app cancels and re-starts auth during configuration |
| 303 | // change. This is ugly because we also have to do things on onConfigurationChanged |
| 304 | // here. |
| 305 | mCurrentDialog.dismissWithoutCallback(false /* animate */); |
| 306 | } |
| 307 | |
| 308 | mReceiver = (IBiometricServiceReceiverInternal) args.arg2; |
| 309 | mCurrentDialog = newDialog; |
Kevin Chyn | 9cf8991 | 2019-08-30 13:33:58 -0700 | [diff] [blame] | 310 | mCurrentDialog.show(mWindowManager, savedState); |
Kevin Chyn | c53d981 | 2019-07-30 18:10:30 -0700 | [diff] [blame] | 311 | } |
| 312 | |
Kevin Chyn | 050315f | 2019-08-08 14:22:54 -0700 | [diff] [blame] | 313 | private void onDialogDismissed(@DismissedReason int reason) { |
| 314 | if (DEBUG) Log.d(TAG, "onDialogDismissed: " + reason); |
Kevin Chyn | c53d981 | 2019-07-30 18:10:30 -0700 | [diff] [blame] | 315 | if (mCurrentDialog == null) { |
| 316 | Log.w(TAG, "Dialog already dismissed"); |
Kevin Chyn | 42653e8 | 2018-01-19 14:15:46 -0800 | [diff] [blame] | 317 | } |
| 318 | mReceiver = null; |
Kevin Chyn | c53d981 | 2019-07-30 18:10:30 -0700 | [diff] [blame] | 319 | mCurrentDialog = null; |
Kevin Chyn | 23289ef | 2018-11-28 16:32:36 -0800 | [diff] [blame] | 320 | } |
| 321 | |
Gus Prevas | a7df7b2 | 2018-10-30 10:29:34 -0400 | [diff] [blame] | 322 | @Override |
| 323 | protected void onConfigurationChanged(Configuration newConfig) { |
Kevin Chyn | 02129b1 | 2018-11-01 16:47:12 -0700 | [diff] [blame] | 324 | super.onConfigurationChanged(newConfig); |
Kevin Chyn | e191271 | 2019-01-04 14:22:34 -0800 | [diff] [blame] | 325 | |
| 326 | // Save the state of the current dialog (buttons showing, etc) |
Kevin Chyn | e191271 | 2019-01-04 14:22:34 -0800 | [diff] [blame] | 327 | if (mCurrentDialog != null) { |
Kevin Chyn | c53d981 | 2019-07-30 18:10:30 -0700 | [diff] [blame] | 328 | final Bundle savedState = new Bundle(); |
Kevin Chyn | e191271 | 2019-01-04 14:22:34 -0800 | [diff] [blame] | 329 | mCurrentDialog.onSaveState(savedState); |
Kevin Chyn | c53d981 | 2019-07-30 18:10:30 -0700 | [diff] [blame] | 330 | mCurrentDialog.dismissWithoutCallback(false /* animate */); |
| 331 | mCurrentDialog = null; |
Kevin Chyn | e191271 | 2019-01-04 14:22:34 -0800 | [diff] [blame] | 332 | |
Kevin Chyn | 27da718 | 2019-09-11 12:17:55 -0700 | [diff] [blame] | 333 | // Only show the dialog if necessary. If it was animating out, the dialog is supposed |
| 334 | // to send its pending callback immediately. |
| 335 | if (savedState.getInt(AuthDialog.KEY_CONTAINER_STATE) |
| 336 | != AuthContainerView.STATE_ANIMATING_OUT) { |
Kevin Chyn | 8cbb488 | 2019-09-19 16:49:02 -0700 | [diff] [blame] | 337 | final boolean credentialShowing = |
| 338 | savedState.getBoolean(AuthDialog.KEY_CREDENTIAL_SHOWING); |
Kevin Chyn | 86f1b8e | 2019-09-24 19:00:49 -0700 | [diff] [blame] | 339 | if (credentialShowing) { |
| 340 | // TODO: Clean this up |
| 341 | Bundle bundle = (Bundle) mCurrentDialogArgs.arg1; |
| 342 | bundle.putInt(BiometricPrompt.KEY_AUTHENTICATORS_ALLOWED, |
| 343 | Authenticator.TYPE_CREDENTIAL); |
| 344 | } |
Kevin Chyn | 8cbb488 | 2019-09-19 16:49:02 -0700 | [diff] [blame] | 345 | |
Kevin Chyn | 86f1b8e | 2019-09-24 19:00:49 -0700 | [diff] [blame] | 346 | showDialog(mCurrentDialogArgs, true /* skipAnimation */, savedState); |
Kevin Chyn | 27da718 | 2019-09-11 12:17:55 -0700 | [diff] [blame] | 347 | } |
Gus Prevas | a7df7b2 | 2018-10-30 10:29:34 -0400 | [diff] [blame] | 348 | } |
Kevin Chyn | c53d981 | 2019-07-30 18:10:30 -0700 | [diff] [blame] | 349 | } |
Kevin Chyn | e191271 | 2019-01-04 14:22:34 -0800 | [diff] [blame] | 350 | |
Kevin Chyn | f8688a0 | 2019-08-27 17:04:05 -0700 | [diff] [blame] | 351 | protected AuthDialog buildDialog(Bundle biometricPromptBundle, boolean requireConfirmation, |
Kevin Chyn | 86f1b8e | 2019-09-24 19:00:49 -0700 | [diff] [blame] | 352 | int userId, int type, String opPackageName, boolean skipIntro) { |
Kevin Chyn | d837ced | 2019-09-11 16:09:43 -0700 | [diff] [blame] | 353 | return new AuthContainerView.Builder(mContext) |
| 354 | .setCallback(this) |
| 355 | .setBiometricPromptBundle(biometricPromptBundle) |
| 356 | .setRequireConfirmation(requireConfirmation) |
| 357 | .setUserId(userId) |
| 358 | .setOpPackageName(opPackageName) |
| 359 | .setSkipIntro(skipIntro) |
| 360 | .build(type); |
Gus Prevas | a7df7b2 | 2018-10-30 10:29:34 -0400 | [diff] [blame] | 361 | } |
Kevin Chyn | aae4a15 | 2018-01-18 11:48:09 -0800 | [diff] [blame] | 362 | } |