blob: e0ca1ace2ac4f6b737ed140022bafcd77df14504 [file] [log] [blame]
Kevin Chynaae4a152018-01-18 11:48:09 -08001/*
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 Chynf8688a02019-08-27 17:04:05 -070014 * limitations under the License.
Kevin Chynaae4a152018-01-18 11:48:09 -080015 */
16
Kevin Chyne9275662018-07-23 16:42:06 -070017package com.android.systemui.biometrics;
Kevin Chynaae4a152018-01-18 11:48:09 -080018
Ilya Matyukhin0f9da352019-10-03 14:10:01 -070019import static android.hardware.biometrics.BiometricAuthenticator.TYPE_FACE;
20import static android.hardware.biometrics.BiometricAuthenticator.TYPE_FINGERPRINT;
Curtis Belmonte13eb5812019-10-22 14:17:30 -070021import static android.hardware.biometrics.BiometricManager.Authenticators;
Ilya Matyukhin0f9da352019-10-03 14:10:01 -070022
Kevin Chyn050315f2019-08-08 14:22:54 -070023import android.app.ActivityManager;
24import android.app.ActivityTaskManager;
25import android.app.IActivityTaskManager;
26import android.app.TaskStackListener;
Kevin Chyne181b8d2019-11-05 15:02:52 -080027import android.content.BroadcastReceiver;
Kevin Chyn42653e82018-01-19 14:15:46 -080028import android.content.Context;
Kevin Chyne181b8d2019-11-05 15:02:52 -080029import android.content.Intent;
30import android.content.IntentFilter;
Kevin Chynaae4a152018-01-18 11:48:09 -080031import android.content.pm.PackageManager;
Gus Prevasa7df7b22018-10-30 10:29:34 -040032import android.content.res.Configuration;
Kevin Chyn8429da22019-09-24 12:42:35 -070033import android.hardware.biometrics.BiometricConstants;
Vishwath Mohanecf00ce2018-04-05 10:28:24 -070034import android.hardware.biometrics.BiometricPrompt;
Kevin Chyn23289ef2018-11-28 16:32:36 -080035import android.hardware.biometrics.IBiometricServiceReceiverInternal;
Ilya Matyukhin0f9da352019-10-03 14:10:01 -070036import android.hardware.face.FaceManager;
37import android.hardware.fingerprint.FingerprintManager;
Kevin Chynaae4a152018-01-18 11:48:09 -080038import android.os.Bundle;
Kevin Chyn050315f2019-08-08 14:22:54 -070039import android.os.Handler;
40import android.os.Looper;
Kevin Chyn42653e82018-01-19 14:15:46 -080041import android.os.RemoteException;
Kevin Chynaae4a152018-01-18 11:48:09 -080042import android.util.Log;
Kevin Chyn42653e82018-01-19 14:15:46 -080043import android.view.WindowManager;
Kevin Chynaae4a152018-01-18 11:48:09 -080044
Ilya Matyukhin0f9da352019-10-03 14:10:01 -070045import com.android.internal.R;
Kevin Chyn050315f2019-08-08 14:22:54 -070046import com.android.internal.annotations.VisibleForTesting;
Kevin Chyn42653e82018-01-19 14:15:46 -080047import com.android.internal.os.SomeArgs;
Kevin Chynaae4a152018-01-18 11:48:09 -080048import com.android.systemui.SystemUI;
49import com.android.systemui.statusbar.CommandQueue;
50
Kevin Chyn050315f2019-08-08 14:22:54 -070051import java.util.List;
52
Dave Mankoffbcaca8a2019-10-31 18:04:08 -040053import javax.inject.Inject;
54import javax.inject.Singleton;
55
Kevin Chyne9275662018-07-23 16:42:06 -070056/**
Kevin Chync53d9812019-07-30 18:10:30 -070057 * Receives messages sent from {@link com.android.server.biometrics.BiometricService} and shows the
58 * appropriate biometric UI (e.g. BiometricDialogView).
Kevin Chyne9275662018-07-23 16:42:06 -070059 */
Dave Mankoffbcaca8a2019-10-31 18:04:08 -040060@Singleton
Kevin Chynf8688a02019-08-27 17:04:05 -070061public class AuthController extends SystemUI implements CommandQueue.Callbacks,
62 AuthDialogCallback {
Kevin Chynfc468262019-08-20 17:17:11 -070063
Kevin Chynf8688a02019-08-27 17:04:05 -070064 private static final String TAG = "BiometricPrompt/AuthController";
Kevin Chyn42653e82018-01-19 14:15:46 -080065 private static final boolean DEBUG = true;
66
Dave Mankoffbcaca8a2019-10-31 18:04:08 -040067 private final CommandQueue mCommandQueue;
Kevin Chyn050315f2019-08-08 14:22:54 -070068 private final Injector mInjector;
69
Kevin Chync53d9812019-07-30 18:10:30 -070070 // TODO: These should just be saved from onSaveState
Gus Prevasa7df7b22018-10-30 10:29:34 -040071 private SomeArgs mCurrentDialogArgs;
Kevin Chyn050315f2019-08-08 14:22:54 -070072 @VisibleForTesting
Kevin Chynf8688a02019-08-27 17:04:05 -070073 AuthDialog mCurrentDialog;
Kevin Chync53d9812019-07-30 18:10:30 -070074
Kevin Chyn050315f2019-08-08 14:22:54 -070075 private Handler mHandler = new Handler(Looper.getMainLooper());
Kevin Chyn42653e82018-01-19 14:15:46 -080076 private WindowManager mWindowManager;
Kevin Chyn050315f2019-08-08 14:22:54 -070077 @VisibleForTesting
78 IActivityTaskManager mActivityTaskManager;
79 @VisibleForTesting
80 BiometricTaskStackListener mTaskStackListener;
81 @VisibleForTesting
82 IBiometricServiceReceiverInternal mReceiver;
83
84 public class BiometricTaskStackListener extends TaskStackListener {
85 @Override
86 public void onTaskStackChanged() {
87 mHandler.post(mTaskStackChangedRunnable);
88 }
89 }
90
Kevin Chyne181b8d2019-11-05 15:02:52 -080091 @VisibleForTesting
92 final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
93 @Override
94 public void onReceive(Context context, Intent intent) {
95 if (mCurrentDialog != null
96 && Intent.ACTION_CLOSE_SYSTEM_DIALOGS.equals(intent.getAction())) {
97 Log.w(TAG, "ACTION_CLOSE_SYSTEM_DIALOGS received");
98 mCurrentDialog.dismissWithoutCallback(true /* animate */);
99 mCurrentDialog = null;
100
101 try {
102 if (mReceiver != null) {
103 mReceiver.onDialogDismissed(BiometricPrompt.DISMISSED_REASON_USER_CANCEL);
104 mReceiver = null;
105 }
106 } catch (RemoteException e) {
107 Log.e(TAG, "Remote exception", e);
108 }
109 }
110 }
111 };
112
Kevin Chyn050315f2019-08-08 14:22:54 -0700113 private final Runnable mTaskStackChangedRunnable = () -> {
114 if (mCurrentDialog != null) {
115 try {
116 final String clientPackage = mCurrentDialog.getOpPackageName();
117 Log.w(TAG, "Task stack changed, current client: " + clientPackage);
118 final List<ActivityManager.RunningTaskInfo> runningTasks =
119 mActivityTaskManager.getTasks(1);
120 if (!runningTasks.isEmpty()) {
121 final String topPackage = runningTasks.get(0).topActivity.getPackageName();
122 if (!topPackage.contentEquals(clientPackage)) {
123 Log.w(TAG, "Evicting client due to: " + topPackage);
124 mCurrentDialog.dismissWithoutCallback(true /* animate */);
125 mCurrentDialog = null;
Curtis Belmonteffa9d872019-10-24 12:55:01 -0700126 if (mReceiver != null) {
127 mReceiver.onDialogDismissed(
128 BiometricPrompt.DISMISSED_REASON_USER_CANCEL);
129 mReceiver = null;
130 }
Kevin Chyn050315f2019-08-08 14:22:54 -0700131 }
132 }
133 } catch (RemoteException e) {
134 Log.e(TAG, "Remote exception", e);
135 }
136 }
137 };
Kevin Chyn42653e82018-01-19 14:15:46 -0800138
Kevin Chync53d9812019-07-30 18:10:30 -0700139 @Override
140 public void onTryAgainPressed() {
Curtis Belmonteffa9d872019-10-24 12:55:01 -0700141 if (mReceiver == null) {
142 Log.e(TAG, "onTryAgainPressed: Receiver is null");
143 return;
144 }
Kevin Chync53d9812019-07-30 18:10:30 -0700145 try {
146 mReceiver.onTryAgainPressed();
147 } catch (RemoteException e) {
148 Log.e(TAG, "RemoteException when handling try again", e);
Kevin Chyn5906c172018-07-23 15:43:02 -0700149 }
150 }
151
Kevin Chync53d9812019-07-30 18:10:30 -0700152 @Override
Kevin Chynff168dc2019-09-16 16:04:38 -0700153 public void onDeviceCredentialPressed() {
Curtis Belmonteffa9d872019-10-24 12:55:01 -0700154 if (mReceiver == null) {
155 Log.e(TAG, "onDeviceCredentialPressed: Receiver is null");
156 return;
157 }
Kevin Chynff168dc2019-09-16 16:04:38 -0700158 try {
159 mReceiver.onDeviceCredentialPressed();
160 } catch (RemoteException e) {
161 Log.e(TAG, "RemoteException when handling credential button", e);
162 }
163 }
164
165 @Override
Kevin Chyn050315f2019-08-08 14:22:54 -0700166 public void onDismissed(@DismissedReason int reason) {
Kevin Chync53d9812019-07-30 18:10:30 -0700167 switch (reason) {
Kevin Chynf8688a02019-08-27 17:04:05 -0700168 case AuthDialogCallback.DISMISSED_USER_CANCELED:
Kevin Chync53d9812019-07-30 18:10:30 -0700169 sendResultAndCleanUp(BiometricPrompt.DISMISSED_REASON_USER_CANCEL);
170 break;
171
Kevin Chynf8688a02019-08-27 17:04:05 -0700172 case AuthDialogCallback.DISMISSED_BUTTON_NEGATIVE:
Kevin Chync53d9812019-07-30 18:10:30 -0700173 sendResultAndCleanUp(BiometricPrompt.DISMISSED_REASON_NEGATIVE);
174 break;
175
Kevin Chynf8688a02019-08-27 17:04:05 -0700176 case AuthDialogCallback.DISMISSED_BUTTON_POSITIVE:
Kevin Chynff168dc2019-09-16 16:04:38 -0700177 sendResultAndCleanUp(BiometricPrompt.DISMISSED_REASON_BIOMETRIC_CONFIRMED);
Kevin Chync53d9812019-07-30 18:10:30 -0700178 break;
179
Kevin Chynff168dc2019-09-16 16:04:38 -0700180 case AuthDialogCallback.DISMISSED_BIOMETRIC_AUTHENTICATED:
181 sendResultAndCleanUp(
182 BiometricPrompt.DISMISSED_REASON_BIOMETRIC_CONFIRM_NOT_REQUIRED);
Kevin Chync53d9812019-07-30 18:10:30 -0700183 break;
184
Kevin Chynf8688a02019-08-27 17:04:05 -0700185 case AuthDialogCallback.DISMISSED_ERROR:
Kevin Chync53d9812019-07-30 18:10:30 -0700186 sendResultAndCleanUp(BiometricPrompt.DISMISSED_REASON_ERROR);
Kevin Chync53d9812019-07-30 18:10:30 -0700187 break;
Kevin Chyn050315f2019-08-08 14:22:54 -0700188
Kevin Chynf8688a02019-08-27 17:04:05 -0700189 case AuthDialogCallback.DISMISSED_BY_SYSTEM_SERVER:
Kevin Chyn050315f2019-08-08 14:22:54 -0700190 sendResultAndCleanUp(BiometricPrompt.DISMISSED_REASON_SERVER_REQUESTED);
191 break;
192
Kevin Chynff168dc2019-09-16 16:04:38 -0700193 case AuthDialogCallback.DISMISSED_CREDENTIAL_AUTHENTICATED:
194 sendResultAndCleanUp(BiometricPrompt.DISMISSED_REASON_CREDENTIAL_CONFIRMED);
195 break;
196
Kevin Chync53d9812019-07-30 18:10:30 -0700197 default:
198 Log.e(TAG, "Unhandled reason: " + reason);
199 break;
Kevin Chync94b7db2019-05-15 17:28:16 -0700200 }
Kevin Chync53d9812019-07-30 18:10:30 -0700201 }
202
Kevin Chyn050315f2019-08-08 14:22:54 -0700203 private void sendResultAndCleanUp(@DismissedReason int reason) {
Kevin Chync53d9812019-07-30 18:10:30 -0700204 if (mReceiver == null) {
Curtis Belmonteffa9d872019-10-24 12:55:01 -0700205 Log.e(TAG, "sendResultAndCleanUp: Receiver is null");
Kevin Chync53d9812019-07-30 18:10:30 -0700206 return;
207 }
208 try {
Kevin Chyn050315f2019-08-08 14:22:54 -0700209 mReceiver.onDialogDismissed(reason);
Kevin Chync53d9812019-07-30 18:10:30 -0700210 } catch (RemoteException e) {
211 Log.w(TAG, "Remote exception", e);
212 }
Kevin Chyn050315f2019-08-08 14:22:54 -0700213 onDialogDismissed(reason);
214 }
215
216 public static class Injector {
217 IActivityTaskManager getActivityTaskManager() {
218 return ActivityTaskManager.getService();
219 }
220 }
221
Dave Mankoffbcaca8a2019-10-31 18:04:08 -0400222 @Inject
223 public AuthController(Context context, CommandQueue commandQueue) {
224 this(context, commandQueue, new Injector());
Kevin Chyn050315f2019-08-08 14:22:54 -0700225 }
226
227 @VisibleForTesting
Dave Mankoffbcaca8a2019-10-31 18:04:08 -0400228 AuthController(Context context, CommandQueue commandQueue, Injector injector) {
Dave Mankoffa5d8a392019-10-10 12:21:09 -0400229 super(context);
Dave Mankoffbcaca8a2019-10-31 18:04:08 -0400230 mCommandQueue = commandQueue;
Kevin Chyn050315f2019-08-08 14:22:54 -0700231 mInjector = injector;
Kevin Chyne181b8d2019-11-05 15:02:52 -0800232
233 IntentFilter filter = new IntentFilter();
234 filter.addAction(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
235
236 context.registerReceiver(mBroadcastReceiver, filter);
Kevin Chync53d9812019-07-30 18:10:30 -0700237 }
Kevin Chync94b7db2019-05-15 17:28:16 -0700238
Kevin Chynaae4a152018-01-18 11:48:09 -0800239 @Override
240 public void start() {
Kevin Chyne1912712019-01-04 14:22:34 -0800241 final PackageManager pm = mContext.getPackageManager();
242 if (pm.hasSystemFeature(PackageManager.FEATURE_FINGERPRINT)
243 || pm.hasSystemFeature(PackageManager.FEATURE_FACE)
244 || pm.hasSystemFeature(PackageManager.FEATURE_IRIS)) {
Dave Mankoffbcaca8a2019-10-31 18:04:08 -0400245 mCommandQueue.addCallback(this);
Gus Prevasa7df7b22018-10-30 10:29:34 -0400246 mWindowManager = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
Kevin Chyn050315f2019-08-08 14:22:54 -0700247 mActivityTaskManager = mInjector.getActivityTaskManager();
248
249 try {
250 mTaskStackListener = new BiometricTaskStackListener();
251 mActivityTaskManager.registerTaskStackListener(mTaskStackListener);
252 } catch (RemoteException e) {
253 Log.w(TAG, "Unable to register task stack listener", e);
254 }
Gus Prevasa7df7b22018-10-30 10:29:34 -0400255 }
256 }
257
Kevin Chynaae4a152018-01-18 11:48:09 -0800258 @Override
Kevin Chyn86f1b8e2019-09-24 19:00:49 -0700259 public void showAuthenticationDialog(Bundle bundle, IBiometricServiceReceiverInternal receiver,
260 int biometricModality, boolean requireConfirmation, int userId, String opPackageName) {
261 final int authenticators = Utils.getAuthenticators(bundle);
262
Kevin Chyn158fefb2019-01-03 18:59:05 -0800263 if (DEBUG) {
Kevin Chyn86f1b8e2019-09-24 19:00:49 -0700264 Log.d(TAG, "showAuthenticationDialog, authenticators: " + authenticators
265 + ", biometricModality: " + biometricModality
Kevin Chyn158fefb2019-01-03 18:59:05 -0800266 + ", requireConfirmation: " + requireConfirmation);
267 }
Kevin Chyn42653e82018-01-19 14:15:46 -0800268 SomeArgs args = SomeArgs.obtain();
269 args.arg1 = bundle;
270 args.arg2 = receiver;
Kevin Chyn86f1b8e2019-09-24 19:00:49 -0700271 args.argi1 = biometricModality;
Kevin Chyn6cf54e82018-09-18 19:13:27 -0700272 args.arg3 = requireConfirmation;
Kevin Chyn1b9f8df2018-11-12 19:04:55 -0800273 args.argi2 = userId;
Kevin Chyn050315f2019-08-08 14:22:54 -0700274 args.arg4 = opPackageName;
Kevin Chync53d9812019-07-30 18:10:30 -0700275
276 boolean skipAnimation = false;
277 if (mCurrentDialog != null) {
278 Log.w(TAG, "mCurrentDialog: " + mCurrentDialog);
279 skipAnimation = true;
280 }
Kevin Chyn86f1b8e2019-09-24 19:00:49 -0700281
282 showDialog(args, skipAnimation, null /* savedState */);
Kevin Chynaae4a152018-01-18 11:48:09 -0800283 }
284
285 @Override
Ilya Matyukhin0f9da352019-10-03 14:10:01 -0700286 public void onBiometricAuthenticated() {
287 mCurrentDialog.onAuthenticationSucceeded();
Kevin Chyn42653e82018-01-19 14:15:46 -0800288 }
289
Kevin Chync53d9812019-07-30 18:10:30 -0700290 @Override
291 public void onBiometricHelp(String message) {
292 if (DEBUG) Log.d(TAG, "onBiometricHelp: " + message);
293
294 mCurrentDialog.onHelp(message);
Kevin Chyn42653e82018-01-19 14:15:46 -0800295 }
296
Ilya Matyukhin0f9da352019-10-03 14:10:01 -0700297 private String getErrorString(int modality, int error, int vendorCode) {
298 switch (modality) {
299 case TYPE_FACE:
300 return FaceManager.getErrorString(mContext, error, vendorCode);
Kevin Chyn8429da22019-09-24 12:42:35 -0700301
Ilya Matyukhin0f9da352019-10-03 14:10:01 -0700302 case TYPE_FINGERPRINT:
303 return FingerprintManager.getErrorString(mContext, error, vendorCode);
304
305 default:
306 return "";
307 }
308 }
309
310 @Override
311 public void onBiometricError(int modality, int error, int vendorCode) {
312 if (DEBUG) {
313 Log.d(TAG, String.format("onBiometricError(%d, %d, %d)", modality, error, vendorCode));
314 }
315
316 final boolean isLockout = (error == BiometricConstants.BIOMETRIC_ERROR_LOCKOUT)
317 || (error == BiometricConstants.BIOMETRIC_ERROR_LOCKOUT_PERMANENT);
318
319 // TODO(b/141025588): Create separate methods for handling hard and soft errors.
320 final boolean isSoftError = (error == BiometricConstants.BIOMETRIC_PAUSED_REJECTED
321 || error == BiometricConstants.BIOMETRIC_ERROR_TIMEOUT);
322
Kevin Chyn8429da22019-09-24 12:42:35 -0700323 if (mCurrentDialog.isAllowDeviceCredentials() && isLockout) {
Ilya Matyukhin0f9da352019-10-03 14:10:01 -0700324 if (DEBUG) Log.d(TAG, "onBiometricError, lockout");
Kevin Chyn8429da22019-09-24 12:42:35 -0700325 mCurrentDialog.animateToCredentialUI();
Ilya Matyukhin0f9da352019-10-03 14:10:01 -0700326 } else if (isSoftError) {
327 final String errorMessage = (error == BiometricConstants.BIOMETRIC_PAUSED_REJECTED)
328 ? mContext.getString(R.string.biometric_not_recognized)
329 : getErrorString(modality, error, vendorCode);
330 if (DEBUG) Log.d(TAG, "onBiometricError, soft error: " + errorMessage);
331 mCurrentDialog.onAuthenticationFailed(errorMessage);
Kevin Chyn8429da22019-09-24 12:42:35 -0700332 } else {
Ilya Matyukhin0f9da352019-10-03 14:10:01 -0700333 final String errorMessage = getErrorString(modality, error, vendorCode);
334 if (DEBUG) Log.d(TAG, "onBiometricError, hard error: " + errorMessage);
335 mCurrentDialog.onError(errorMessage);
Kevin Chyn8429da22019-09-24 12:42:35 -0700336 }
Kevin Chyn42653e82018-01-19 14:15:46 -0800337 }
338
Kevin Chync53d9812019-07-30 18:10:30 -0700339 @Override
Kevin Chyn86f1b8e2019-09-24 19:00:49 -0700340 public void hideAuthenticationDialog() {
341 if (DEBUG) Log.d(TAG, "hideAuthenticationDialog");
Kevin Chync53d9812019-07-30 18:10:30 -0700342
Kevin Chyn050315f2019-08-08 14:22:54 -0700343 mCurrentDialog.dismissFromSystemServer();
Kevin Chyn22910722019-12-13 16:57:51 -0800344
345 // BiometricService will have already sent the callback to the client in this case.
346 // This avoids a round trip to SystemUI. So, just dismiss the dialog and we're done.
347 mCurrentDialog = null;
Kevin Chync53d9812019-07-30 18:10:30 -0700348 }
349
Kevin Chyn86f1b8e2019-09-24 19:00:49 -0700350 private void showDialog(SomeArgs args, boolean skipAnimation, Bundle savedState) {
Kevin Chync53d9812019-07-30 18:10:30 -0700351 mCurrentDialogArgs = args;
352 final int type = args.argi1;
Kevin Chyn050315f2019-08-08 14:22:54 -0700353 final Bundle biometricPromptBundle = (Bundle) args.arg1;
354 final boolean requireConfirmation = (boolean) args.arg3;
355 final int userId = args.argi2;
356 final String opPackageName = (String) args.arg4;
Kevin Chync53d9812019-07-30 18:10:30 -0700357
358 // Create a new dialog but do not replace the current one yet.
Kevin Chynf8688a02019-08-27 17:04:05 -0700359 final AuthDialog newDialog = buildDialog(
Kevin Chyn050315f2019-08-08 14:22:54 -0700360 biometricPromptBundle,
361 requireConfirmation,
362 userId,
363 type,
Kevin Chynfc468262019-08-20 17:17:11 -0700364 opPackageName,
Kevin Chyn86f1b8e2019-09-24 19:00:49 -0700365 skipAnimation);
Kevin Chync53d9812019-07-30 18:10:30 -0700366
367 if (newDialog == null) {
368 Log.e(TAG, "Unsupported type: " + type);
Kevin Chyn42653e82018-01-19 14:15:46 -0800369 return;
370 }
Kevin Chync53d9812019-07-30 18:10:30 -0700371
372 if (DEBUG) {
Kevin Chyn86f1b8e2019-09-24 19:00:49 -0700373 Log.d(TAG, "showDialog: " + args
Kevin Chync53d9812019-07-30 18:10:30 -0700374 + " savedState: " + savedState
375 + " mCurrentDialog: " + mCurrentDialog
376 + " newDialog: " + newDialog
Kevin Chyn86f1b8e2019-09-24 19:00:49 -0700377 + " type: " + type);
Kevin Chync53d9812019-07-30 18:10:30 -0700378 }
379
Kevin Chyn9cf89912019-08-30 13:33:58 -0700380 if (mCurrentDialog != null) {
Kevin Chync53d9812019-07-30 18:10:30 -0700381 // If somehow we're asked to show a dialog, the old one doesn't need to be animated
382 // away. This can happen if the app cancels and re-starts auth during configuration
383 // change. This is ugly because we also have to do things on onConfigurationChanged
384 // here.
385 mCurrentDialog.dismissWithoutCallback(false /* animate */);
386 }
387
388 mReceiver = (IBiometricServiceReceiverInternal) args.arg2;
389 mCurrentDialog = newDialog;
Kevin Chyn9cf89912019-08-30 13:33:58 -0700390 mCurrentDialog.show(mWindowManager, savedState);
Kevin Chync53d9812019-07-30 18:10:30 -0700391 }
392
Kevin Chyn050315f2019-08-08 14:22:54 -0700393 private void onDialogDismissed(@DismissedReason int reason) {
394 if (DEBUG) Log.d(TAG, "onDialogDismissed: " + reason);
Kevin Chync53d9812019-07-30 18:10:30 -0700395 if (mCurrentDialog == null) {
396 Log.w(TAG, "Dialog already dismissed");
Kevin Chyn42653e82018-01-19 14:15:46 -0800397 }
398 mReceiver = null;
Kevin Chync53d9812019-07-30 18:10:30 -0700399 mCurrentDialog = null;
Kevin Chyn23289ef2018-11-28 16:32:36 -0800400 }
401
Gus Prevasa7df7b22018-10-30 10:29:34 -0400402 @Override
403 protected void onConfigurationChanged(Configuration newConfig) {
Kevin Chyn02129b12018-11-01 16:47:12 -0700404 super.onConfigurationChanged(newConfig);
Kevin Chyne1912712019-01-04 14:22:34 -0800405
406 // Save the state of the current dialog (buttons showing, etc)
Kevin Chyne1912712019-01-04 14:22:34 -0800407 if (mCurrentDialog != null) {
Kevin Chync53d9812019-07-30 18:10:30 -0700408 final Bundle savedState = new Bundle();
Kevin Chyne1912712019-01-04 14:22:34 -0800409 mCurrentDialog.onSaveState(savedState);
Kevin Chync53d9812019-07-30 18:10:30 -0700410 mCurrentDialog.dismissWithoutCallback(false /* animate */);
411 mCurrentDialog = null;
Kevin Chyne1912712019-01-04 14:22:34 -0800412
Kevin Chyn27da7182019-09-11 12:17:55 -0700413 // Only show the dialog if necessary. If it was animating out, the dialog is supposed
414 // to send its pending callback immediately.
415 if (savedState.getInt(AuthDialog.KEY_CONTAINER_STATE)
416 != AuthContainerView.STATE_ANIMATING_OUT) {
Kevin Chyn8cbb4882019-09-19 16:49:02 -0700417 final boolean credentialShowing =
418 savedState.getBoolean(AuthDialog.KEY_CREDENTIAL_SHOWING);
Kevin Chyn86f1b8e2019-09-24 19:00:49 -0700419 if (credentialShowing) {
420 // TODO: Clean this up
421 Bundle bundle = (Bundle) mCurrentDialogArgs.arg1;
422 bundle.putInt(BiometricPrompt.KEY_AUTHENTICATORS_ALLOWED,
Curtis Belmonte13eb5812019-10-22 14:17:30 -0700423 Authenticators.DEVICE_CREDENTIAL);
Kevin Chyn86f1b8e2019-09-24 19:00:49 -0700424 }
Kevin Chyn8cbb4882019-09-19 16:49:02 -0700425
Kevin Chyn86f1b8e2019-09-24 19:00:49 -0700426 showDialog(mCurrentDialogArgs, true /* skipAnimation */, savedState);
Kevin Chyn27da7182019-09-11 12:17:55 -0700427 }
Gus Prevasa7df7b22018-10-30 10:29:34 -0400428 }
Kevin Chync53d9812019-07-30 18:10:30 -0700429 }
Kevin Chyne1912712019-01-04 14:22:34 -0800430
Kevin Chynf8688a02019-08-27 17:04:05 -0700431 protected AuthDialog buildDialog(Bundle biometricPromptBundle, boolean requireConfirmation,
Kevin Chyn86f1b8e2019-09-24 19:00:49 -0700432 int userId, int type, String opPackageName, boolean skipIntro) {
Kevin Chynd837ced2019-09-11 16:09:43 -0700433 return new AuthContainerView.Builder(mContext)
434 .setCallback(this)
435 .setBiometricPromptBundle(biometricPromptBundle)
436 .setRequireConfirmation(requireConfirmation)
437 .setUserId(userId)
438 .setOpPackageName(opPackageName)
439 .setSkipIntro(skipIntro)
440 .build(type);
Gus Prevasa7df7b22018-10-30 10:29:34 -0400441 }
Kevin Chynaae4a152018-01-18 11:48:09 -0800442}