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