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 |
| 14 | * limitations under the License |
| 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 | 42653e8 | 2018-01-19 14:15:46 -0800 | [diff] [blame] | 19 | import android.content.Context; |
Kevin Chyn | aae4a15 | 2018-01-18 11:48:09 -0800 | [diff] [blame] | 20 | import android.content.pm.PackageManager; |
Gus Prevas | a7df7b2 | 2018-10-30 10:29:34 -0400 | [diff] [blame] | 21 | import android.content.res.Configuration; |
Kevin Chyn | 6cf54e8 | 2018-09-18 19:13:27 -0700 | [diff] [blame] | 22 | import android.hardware.biometrics.BiometricAuthenticator; |
Vishwath Mohan | ecf00ce | 2018-04-05 10:28:24 -0700 | [diff] [blame] | 23 | import android.hardware.biometrics.BiometricPrompt; |
Kevin Chyn | 23289ef | 2018-11-28 16:32:36 -0800 | [diff] [blame] | 24 | import android.hardware.biometrics.IBiometricServiceReceiverInternal; |
Kevin Chyn | aae4a15 | 2018-01-18 11:48:09 -0800 | [diff] [blame] | 25 | import android.os.Bundle; |
Kevin Chyn | 42653e8 | 2018-01-19 14:15:46 -0800 | [diff] [blame] | 26 | import android.os.Handler; |
| 27 | import android.os.Message; |
| 28 | import android.os.RemoteException; |
Kevin Chyn | aae4a15 | 2018-01-18 11:48:09 -0800 | [diff] [blame] | 29 | import android.util.Log; |
Kevin Chyn | 42653e8 | 2018-01-19 14:15:46 -0800 | [diff] [blame] | 30 | import android.view.WindowManager; |
Kevin Chyn | aae4a15 | 2018-01-18 11:48:09 -0800 | [diff] [blame] | 31 | |
Kevin Chyn | 42653e8 | 2018-01-19 14:15:46 -0800 | [diff] [blame] | 32 | import com.android.internal.os.SomeArgs; |
Kevin Chyn | aae4a15 | 2018-01-18 11:48:09 -0800 | [diff] [blame] | 33 | import com.android.systemui.SystemUI; |
| 34 | import com.android.systemui.statusbar.CommandQueue; |
| 35 | |
Kevin Chyn | e927566 | 2018-07-23 16:42:06 -0700 | [diff] [blame] | 36 | /** |
| 37 | * Receives messages sent from AuthenticationClient and shows the appropriate biometric UI (e.g. |
Kevin Chyn | a883fb5 | 2018-09-18 18:23:22 -0700 | [diff] [blame] | 38 | * BiometricDialogView). |
Kevin Chyn | e927566 | 2018-07-23 16:42:06 -0700 | [diff] [blame] | 39 | */ |
| 40 | public class BiometricDialogImpl extends SystemUI implements CommandQueue.Callbacks { |
Kevin Chyn | 5a2ff5d | 2018-08-29 19:07:30 -0700 | [diff] [blame] | 41 | private static final String TAG = "BiometricDialogImpl"; |
Kevin Chyn | 42653e8 | 2018-01-19 14:15:46 -0800 | [diff] [blame] | 42 | private static final boolean DEBUG = true; |
| 43 | |
Kevin Chyn | 5906c17 | 2018-07-23 15:43:02 -0700 | [diff] [blame] | 44 | private static final int MSG_SHOW_DIALOG = 1; |
Kevin Chyn | e927566 | 2018-07-23 16:42:06 -0700 | [diff] [blame] | 45 | private static final int MSG_BIOMETRIC_AUTHENTICATED = 2; |
| 46 | private static final int MSG_BIOMETRIC_HELP = 3; |
| 47 | private static final int MSG_BIOMETRIC_ERROR = 4; |
| 48 | private static final int MSG_HIDE_DIALOG = 5; |
Kevin Chyn | 5906c17 | 2018-07-23 15:43:02 -0700 | [diff] [blame] | 49 | private static final int MSG_BUTTON_NEGATIVE = 6; |
| 50 | private static final int MSG_USER_CANCELED = 7; |
| 51 | private static final int MSG_BUTTON_POSITIVE = 8; |
Kevin Chyn | e191271 | 2019-01-04 14:22:34 -0800 | [diff] [blame^] | 52 | private static final int MSG_TRY_AGAIN_PRESSED = 9; |
Kevin Chyn | 42653e8 | 2018-01-19 14:15:46 -0800 | [diff] [blame] | 53 | |
Gus Prevas | a7df7b2 | 2018-10-30 10:29:34 -0400 | [diff] [blame] | 54 | private SomeArgs mCurrentDialogArgs; |
Kevin Chyn | 6cf54e8 | 2018-09-18 19:13:27 -0700 | [diff] [blame] | 55 | private BiometricDialogView mCurrentDialog; |
Kevin Chyn | 42653e8 | 2018-01-19 14:15:46 -0800 | [diff] [blame] | 56 | private WindowManager mWindowManager; |
Kevin Chyn | 23289ef | 2018-11-28 16:32:36 -0800 | [diff] [blame] | 57 | private IBiometricServiceReceiverInternal mReceiver; |
Kevin Chyn | 42653e8 | 2018-01-19 14:15:46 -0800 | [diff] [blame] | 58 | private boolean mDialogShowing; |
Kevin Chyn | 5906c17 | 2018-07-23 15:43:02 -0700 | [diff] [blame] | 59 | private Callback mCallback = new Callback(); |
Kevin Chyn | 42653e8 | 2018-01-19 14:15:46 -0800 | [diff] [blame] | 60 | |
| 61 | private Handler mHandler = new Handler() { |
| 62 | @Override |
| 63 | public void handleMessage(Message msg) { |
| 64 | switch(msg.what) { |
| 65 | case MSG_SHOW_DIALOG: |
Kevin Chyn | e191271 | 2019-01-04 14:22:34 -0800 | [diff] [blame^] | 66 | handleShowDialog((SomeArgs) msg.obj, false /* skipAnimation */, |
| 67 | null /* savedState */); |
Kevin Chyn | 42653e8 | 2018-01-19 14:15:46 -0800 | [diff] [blame] | 68 | break; |
Kevin Chyn | e927566 | 2018-07-23 16:42:06 -0700 | [diff] [blame] | 69 | case MSG_BIOMETRIC_AUTHENTICATED: |
Kevin Chyn | e191271 | 2019-01-04 14:22:34 -0800 | [diff] [blame^] | 70 | handleBiometricAuthenticated((boolean) msg.obj); |
Kevin Chyn | 42653e8 | 2018-01-19 14:15:46 -0800 | [diff] [blame] | 71 | break; |
Kevin Chyn | e927566 | 2018-07-23 16:42:06 -0700 | [diff] [blame] | 72 | case MSG_BIOMETRIC_HELP: |
Kevin Chyn | e191271 | 2019-01-04 14:22:34 -0800 | [diff] [blame^] | 73 | SomeArgs args = (SomeArgs) msg.obj; |
| 74 | handleBiometricHelp((String) args.arg1 /* message */, |
| 75 | (boolean) args.arg2 /* requireTryAgain */); |
| 76 | args.recycle(); |
Kevin Chyn | 42653e8 | 2018-01-19 14:15:46 -0800 | [diff] [blame] | 77 | break; |
Kevin Chyn | e927566 | 2018-07-23 16:42:06 -0700 | [diff] [blame] | 78 | case MSG_BIOMETRIC_ERROR: |
| 79 | handleBiometricError((String) msg.obj); |
Kevin Chyn | 42653e8 | 2018-01-19 14:15:46 -0800 | [diff] [blame] | 80 | break; |
| 81 | case MSG_HIDE_DIALOG: |
| 82 | handleHideDialog((Boolean) msg.obj); |
| 83 | break; |
| 84 | case MSG_BUTTON_NEGATIVE: |
| 85 | handleButtonNegative(); |
| 86 | break; |
| 87 | case MSG_USER_CANCELED: |
| 88 | handleUserCanceled(); |
| 89 | break; |
| 90 | case MSG_BUTTON_POSITIVE: |
| 91 | handleButtonPositive(); |
| 92 | break; |
Kevin Chyn | 23289ef | 2018-11-28 16:32:36 -0800 | [diff] [blame] | 93 | case MSG_TRY_AGAIN_PRESSED: |
| 94 | handleTryAgainPressed(); |
| 95 | break; |
| 96 | default: |
| 97 | Log.w(TAG, "Unknown message: " + msg.what); |
| 98 | break; |
Kevin Chyn | 42653e8 | 2018-01-19 14:15:46 -0800 | [diff] [blame] | 99 | } |
| 100 | } |
| 101 | }; |
Kevin Chyn | aae4a15 | 2018-01-18 11:48:09 -0800 | [diff] [blame] | 102 | |
Kevin Chyn | 5906c17 | 2018-07-23 15:43:02 -0700 | [diff] [blame] | 103 | private class Callback implements DialogViewCallback { |
| 104 | @Override |
| 105 | public void onUserCanceled() { |
Kevin Chyn | 23289ef | 2018-11-28 16:32:36 -0800 | [diff] [blame] | 106 | mHandler.obtainMessage(MSG_USER_CANCELED).sendToTarget(); |
Kevin Chyn | 5906c17 | 2018-07-23 15:43:02 -0700 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | @Override |
| 110 | public void onErrorShown() { |
| 111 | mHandler.sendMessageDelayed(mHandler.obtainMessage(MSG_HIDE_DIALOG, |
| 112 | false /* userCanceled */), BiometricPrompt.HIDE_DIALOG_DELAY); |
| 113 | } |
| 114 | |
| 115 | @Override |
| 116 | public void onNegativePressed() { |
Kevin Chyn | 23289ef | 2018-11-28 16:32:36 -0800 | [diff] [blame] | 117 | mHandler.obtainMessage(MSG_BUTTON_NEGATIVE).sendToTarget(); |
Kevin Chyn | 5906c17 | 2018-07-23 15:43:02 -0700 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | @Override |
| 121 | public void onPositivePressed() { |
Kevin Chyn | 23289ef | 2018-11-28 16:32:36 -0800 | [diff] [blame] | 122 | mHandler.obtainMessage(MSG_BUTTON_POSITIVE).sendToTarget(); |
| 123 | } |
| 124 | |
| 125 | @Override |
| 126 | public void onTryAgainPressed() { |
| 127 | mHandler.obtainMessage(MSG_TRY_AGAIN_PRESSED).sendToTarget(); |
Kevin Chyn | 5906c17 | 2018-07-23 15:43:02 -0700 | [diff] [blame] | 128 | } |
| 129 | } |
| 130 | |
Kevin Chyn | aae4a15 | 2018-01-18 11:48:09 -0800 | [diff] [blame] | 131 | @Override |
| 132 | public void start() { |
Kevin Chyn | e191271 | 2019-01-04 14:22:34 -0800 | [diff] [blame^] | 133 | final PackageManager pm = mContext.getPackageManager(); |
| 134 | if (pm.hasSystemFeature(PackageManager.FEATURE_FINGERPRINT) |
| 135 | || pm.hasSystemFeature(PackageManager.FEATURE_FACE) |
| 136 | || pm.hasSystemFeature(PackageManager.FEATURE_IRIS)) { |
Jason Monk | d7c9855 | 2018-12-04 11:14:50 -0500 | [diff] [blame] | 137 | getComponent(CommandQueue.class).addCallback(this); |
Gus Prevas | a7df7b2 | 2018-10-30 10:29:34 -0400 | [diff] [blame] | 138 | mWindowManager = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE); |
| 139 | } |
| 140 | } |
| 141 | |
Kevin Chyn | aae4a15 | 2018-01-18 11:48:09 -0800 | [diff] [blame] | 142 | @Override |
Kevin Chyn | 23289ef | 2018-11-28 16:32:36 -0800 | [diff] [blame] | 143 | public void showBiometricDialog(Bundle bundle, IBiometricServiceReceiverInternal receiver, |
| 144 | int type, boolean requireConfirmation, int userId) { |
Kevin Chyn | 158fefb | 2019-01-03 18:59:05 -0800 | [diff] [blame] | 145 | if (DEBUG) { |
| 146 | Log.d(TAG, "showBiometricDialog, type: " + type |
| 147 | + ", requireConfirmation: " + requireConfirmation); |
| 148 | } |
Kevin Chyn | 42653e8 | 2018-01-19 14:15:46 -0800 | [diff] [blame] | 149 | // Remove these messages as they are part of the previous client |
Kevin Chyn | e927566 | 2018-07-23 16:42:06 -0700 | [diff] [blame] | 150 | mHandler.removeMessages(MSG_BIOMETRIC_ERROR); |
| 151 | mHandler.removeMessages(MSG_BIOMETRIC_HELP); |
| 152 | mHandler.removeMessages(MSG_BIOMETRIC_AUTHENTICATED); |
Kevin Chyn | 87f257a | 2018-11-27 16:26:07 -0800 | [diff] [blame] | 153 | mHandler.removeMessages(MSG_HIDE_DIALOG); |
Kevin Chyn | 42653e8 | 2018-01-19 14:15:46 -0800 | [diff] [blame] | 154 | SomeArgs args = SomeArgs.obtain(); |
| 155 | args.arg1 = bundle; |
| 156 | args.arg2 = receiver; |
Kevin Chyn | 6cf54e8 | 2018-09-18 19:13:27 -0700 | [diff] [blame] | 157 | args.argi1 = type; |
| 158 | args.arg3 = requireConfirmation; |
Kevin Chyn | 1b9f8df | 2018-11-12 19:04:55 -0800 | [diff] [blame] | 159 | args.argi2 = userId; |
Kevin Chyn | 42653e8 | 2018-01-19 14:15:46 -0800 | [diff] [blame] | 160 | mHandler.obtainMessage(MSG_SHOW_DIALOG, args).sendToTarget(); |
Kevin Chyn | aae4a15 | 2018-01-18 11:48:09 -0800 | [diff] [blame] | 161 | } |
| 162 | |
| 163 | @Override |
Kevin Chyn | e191271 | 2019-01-04 14:22:34 -0800 | [diff] [blame^] | 164 | public void onBiometricAuthenticated(boolean authenticated) { |
| 165 | if (DEBUG) Log.d(TAG, "onBiometricAuthenticated: " + authenticated); |
| 166 | mHandler.obtainMessage(MSG_BIOMETRIC_AUTHENTICATED, authenticated).sendToTarget(); |
Kevin Chyn | aae4a15 | 2018-01-18 11:48:09 -0800 | [diff] [blame] | 167 | } |
| 168 | |
| 169 | @Override |
Kevin Chyn | e927566 | 2018-07-23 16:42:06 -0700 | [diff] [blame] | 170 | public void onBiometricHelp(String message) { |
| 171 | if (DEBUG) Log.d(TAG, "onBiometricHelp: " + message); |
Kevin Chyn | e191271 | 2019-01-04 14:22:34 -0800 | [diff] [blame^] | 172 | SomeArgs args = SomeArgs.obtain(); |
| 173 | args.arg1 = message; |
| 174 | args.arg2 = false; // requireTryAgain |
| 175 | mHandler.obtainMessage(MSG_BIOMETRIC_HELP, args).sendToTarget(); |
Kevin Chyn | aae4a15 | 2018-01-18 11:48:09 -0800 | [diff] [blame] | 176 | } |
| 177 | |
| 178 | @Override |
Kevin Chyn | e927566 | 2018-07-23 16:42:06 -0700 | [diff] [blame] | 179 | public void onBiometricError(String error) { |
| 180 | if (DEBUG) Log.d(TAG, "onBiometricError: " + error); |
| 181 | mHandler.obtainMessage(MSG_BIOMETRIC_ERROR, error).sendToTarget(); |
Kevin Chyn | aae4a15 | 2018-01-18 11:48:09 -0800 | [diff] [blame] | 182 | } |
| 183 | |
| 184 | @Override |
Kevin Chyn | e927566 | 2018-07-23 16:42:06 -0700 | [diff] [blame] | 185 | public void hideBiometricDialog() { |
| 186 | if (DEBUG) Log.d(TAG, "hideBiometricDialog"); |
Kevin Chyn | 42653e8 | 2018-01-19 14:15:46 -0800 | [diff] [blame] | 187 | mHandler.obtainMessage(MSG_HIDE_DIALOG, false /* userCanceled */).sendToTarget(); |
| 188 | } |
| 189 | |
Kevin Chyn | e191271 | 2019-01-04 14:22:34 -0800 | [diff] [blame^] | 190 | private void handleShowDialog(SomeArgs args, boolean skipAnimation, Bundle savedState) { |
Gus Prevas | a7df7b2 | 2018-10-30 10:29:34 -0400 | [diff] [blame] | 191 | mCurrentDialogArgs = args; |
Kevin Chyn | 6cf54e8 | 2018-09-18 19:13:27 -0700 | [diff] [blame] | 192 | final int type = args.argi1; |
Kevin Chyn | e191271 | 2019-01-04 14:22:34 -0800 | [diff] [blame^] | 193 | |
| 194 | if (type == BiometricAuthenticator.TYPE_FINGERPRINT) { |
| 195 | mCurrentDialog = new FingerprintDialogView(mContext, mCallback); |
| 196 | } else if (type == BiometricAuthenticator.TYPE_FACE) { |
| 197 | mCurrentDialog = new FaceDialogView(mContext, mCallback); |
| 198 | } else { |
| 199 | Log.e(TAG, "Unsupported type: " + type); |
| 200 | } |
| 201 | |
| 202 | if (savedState != null) { |
| 203 | mCurrentDialog.restoreState(savedState); |
| 204 | } |
Kevin Chyn | 6cf54e8 | 2018-09-18 19:13:27 -0700 | [diff] [blame] | 205 | |
Kevin Chyn | 87df068 | 2018-04-10 19:29:23 -0700 | [diff] [blame] | 206 | if (DEBUG) Log.d(TAG, "handleShowDialog, isAnimatingAway: " |
Kevin Chyn | 6cf54e8 | 2018-09-18 19:13:27 -0700 | [diff] [blame] | 207 | + mCurrentDialog.isAnimatingAway() + " type: " + type); |
| 208 | |
| 209 | if (mCurrentDialog.isAnimatingAway()) { |
| 210 | mCurrentDialog.forceRemove(); |
Kevin Chyn | 87df068 | 2018-04-10 19:29:23 -0700 | [diff] [blame] | 211 | } else if (mDialogShowing) { |
Kevin Chyn | 42653e8 | 2018-01-19 14:15:46 -0800 | [diff] [blame] | 212 | Log.w(TAG, "Dialog already showing"); |
| 213 | return; |
| 214 | } |
Kevin Chyn | 23289ef | 2018-11-28 16:32:36 -0800 | [diff] [blame] | 215 | mReceiver = (IBiometricServiceReceiverInternal) args.arg2; |
Kevin Chyn | 6cf54e8 | 2018-09-18 19:13:27 -0700 | [diff] [blame] | 216 | mCurrentDialog.setBundle((Bundle)args.arg1); |
Kevin Chyn | 1b9f8df | 2018-11-12 19:04:55 -0800 | [diff] [blame] | 217 | mCurrentDialog.setRequireConfirmation((boolean) args.arg3); |
| 218 | mCurrentDialog.setUserId(args.argi2); |
Kevin Chyn | 02129b1 | 2018-11-01 16:47:12 -0700 | [diff] [blame] | 219 | mCurrentDialog.setSkipIntro(skipAnimation); |
Kevin Chyn | 6cf54e8 | 2018-09-18 19:13:27 -0700 | [diff] [blame] | 220 | mWindowManager.addView(mCurrentDialog, mCurrentDialog.getLayoutParams()); |
Kevin Chyn | 42653e8 | 2018-01-19 14:15:46 -0800 | [diff] [blame] | 221 | mDialogShowing = true; |
| 222 | } |
| 223 | |
Kevin Chyn | e191271 | 2019-01-04 14:22:34 -0800 | [diff] [blame^] | 224 | private void handleBiometricAuthenticated(boolean authenticated) { |
| 225 | if (DEBUG) Log.d(TAG, "handleBiometricAuthenticated: " + authenticated); |
Kevin Chyn | e927566 | 2018-07-23 16:42:06 -0700 | [diff] [blame] | 226 | |
Kevin Chyn | e191271 | 2019-01-04 14:22:34 -0800 | [diff] [blame^] | 227 | if (authenticated) { |
| 228 | mCurrentDialog.announceForAccessibility( |
| 229 | mContext.getResources() |
| 230 | .getText(mCurrentDialog.getAuthenticatedAccessibilityResourceId())); |
| 231 | if (mCurrentDialog.requiresConfirmation()) { |
| 232 | mCurrentDialog.showConfirmationButton(true /* show */); |
| 233 | } else { |
| 234 | mCurrentDialog.updateState(BiometricDialogView.STATE_AUTHENTICATED); |
| 235 | mHandler.postDelayed(() -> { |
| 236 | handleHideDialog(false /* userCanceled */); |
| 237 | }, mCurrentDialog.getDelayAfterAuthenticatedDurationMs()); |
| 238 | } |
Kevin Chyn | 6cf54e8 | 2018-09-18 19:13:27 -0700 | [diff] [blame] | 239 | } else { |
Kevin Chyn | e191271 | 2019-01-04 14:22:34 -0800 | [diff] [blame^] | 240 | handleBiometricHelp(mContext.getResources() |
| 241 | .getString(com.android.internal.R.string.biometric_not_recognized), |
| 242 | true /* requireTryAgain */); |
| 243 | mCurrentDialog.showTryAgainButton(true /* show */); |
Kevin Chyn | 6cf54e8 | 2018-09-18 19:13:27 -0700 | [diff] [blame] | 244 | } |
Kevin Chyn | 42653e8 | 2018-01-19 14:15:46 -0800 | [diff] [blame] | 245 | } |
| 246 | |
Kevin Chyn | e191271 | 2019-01-04 14:22:34 -0800 | [diff] [blame^] | 247 | private void handleBiometricHelp(String message, boolean requireTryAgain) { |
Kevin Chyn | e927566 | 2018-07-23 16:42:06 -0700 | [diff] [blame] | 248 | if (DEBUG) Log.d(TAG, "handleBiometricHelp: " + message); |
Kevin Chyn | e191271 | 2019-01-04 14:22:34 -0800 | [diff] [blame^] | 249 | mCurrentDialog.showHelpMessage(message, requireTryAgain); |
Kevin Chyn | 42653e8 | 2018-01-19 14:15:46 -0800 | [diff] [blame] | 250 | } |
| 251 | |
Kevin Chyn | e927566 | 2018-07-23 16:42:06 -0700 | [diff] [blame] | 252 | private void handleBiometricError(String error) { |
| 253 | if (DEBUG) Log.d(TAG, "handleBiometricError: " + error); |
Kevin Chyn | 42653e8 | 2018-01-19 14:15:46 -0800 | [diff] [blame] | 254 | if (!mDialogShowing) { |
| 255 | if (DEBUG) Log.d(TAG, "Dialog already dismissed"); |
| 256 | return; |
| 257 | } |
Kevin Chyn | 6cf54e8 | 2018-09-18 19:13:27 -0700 | [diff] [blame] | 258 | mCurrentDialog.showErrorMessage(error); |
Kevin Chyn | 42653e8 | 2018-01-19 14:15:46 -0800 | [diff] [blame] | 259 | } |
| 260 | |
| 261 | private void handleHideDialog(boolean userCanceled) { |
Kevin Chyn | 87df068 | 2018-04-10 19:29:23 -0700 | [diff] [blame] | 262 | if (DEBUG) Log.d(TAG, "handleHideDialog, userCanceled: " + userCanceled); |
Kevin Chyn | 42653e8 | 2018-01-19 14:15:46 -0800 | [diff] [blame] | 263 | if (!mDialogShowing) { |
| 264 | // This can happen if there's a race and we get called from both |
| 265 | // onAuthenticated and onError, etc. |
| 266 | Log.w(TAG, "Dialog already dismissed, userCanceled: " + userCanceled); |
| 267 | return; |
| 268 | } |
| 269 | if (userCanceled) { |
| 270 | try { |
Vishwath Mohan | ecf00ce | 2018-04-05 10:28:24 -0700 | [diff] [blame] | 271 | mReceiver.onDialogDismissed(BiometricPrompt.DISMISSED_REASON_USER_CANCEL); |
Kevin Chyn | 42653e8 | 2018-01-19 14:15:46 -0800 | [diff] [blame] | 272 | } catch (RemoteException e) { |
| 273 | Log.e(TAG, "RemoteException when hiding dialog", e); |
| 274 | } |
| 275 | } |
| 276 | mReceiver = null; |
Kevin Chyn | 42653e8 | 2018-01-19 14:15:46 -0800 | [diff] [blame] | 277 | mDialogShowing = false; |
Kevin Chyn | 6cf54e8 | 2018-09-18 19:13:27 -0700 | [diff] [blame] | 278 | mCurrentDialog.startDismiss(); |
Kevin Chyn | 42653e8 | 2018-01-19 14:15:46 -0800 | [diff] [blame] | 279 | } |
| 280 | |
| 281 | private void handleButtonNegative() { |
| 282 | if (mReceiver == null) { |
| 283 | Log.e(TAG, "Receiver is null"); |
| 284 | return; |
| 285 | } |
| 286 | try { |
Vishwath Mohan | ecf00ce | 2018-04-05 10:28:24 -0700 | [diff] [blame] | 287 | mReceiver.onDialogDismissed(BiometricPrompt.DISMISSED_REASON_NEGATIVE); |
Kevin Chyn | 42653e8 | 2018-01-19 14:15:46 -0800 | [diff] [blame] | 288 | } catch (RemoteException e) { |
| 289 | Log.e(TAG, "Remote exception when handling negative button", e); |
| 290 | } |
| 291 | handleHideDialog(false /* userCanceled */); |
| 292 | } |
| 293 | |
| 294 | private void handleButtonPositive() { |
| 295 | if (mReceiver == null) { |
| 296 | Log.e(TAG, "Receiver is null"); |
| 297 | return; |
| 298 | } |
| 299 | try { |
Vishwath Mohan | ecf00ce | 2018-04-05 10:28:24 -0700 | [diff] [blame] | 300 | mReceiver.onDialogDismissed(BiometricPrompt.DISMISSED_REASON_POSITIVE); |
Kevin Chyn | 42653e8 | 2018-01-19 14:15:46 -0800 | [diff] [blame] | 301 | } catch (RemoteException e) { |
| 302 | Log.e(TAG, "Remote exception when handling positive button", e); |
| 303 | } |
| 304 | handleHideDialog(false /* userCanceled */); |
| 305 | } |
| 306 | |
Kevin Chyn | 42653e8 | 2018-01-19 14:15:46 -0800 | [diff] [blame] | 307 | private void handleUserCanceled() { |
| 308 | handleHideDialog(true /* userCanceled */); |
Kevin Chyn | aae4a15 | 2018-01-18 11:48:09 -0800 | [diff] [blame] | 309 | } |
Gus Prevas | a7df7b2 | 2018-10-30 10:29:34 -0400 | [diff] [blame] | 310 | |
Kevin Chyn | 23289ef | 2018-11-28 16:32:36 -0800 | [diff] [blame] | 311 | private void handleTryAgainPressed() { |
| 312 | try { |
| 313 | mCurrentDialog.clearTemporaryMessage(); |
Kevin Chyn | 23289ef | 2018-11-28 16:32:36 -0800 | [diff] [blame] | 314 | mReceiver.onTryAgainPressed(); |
| 315 | } catch (RemoteException e) { |
| 316 | Log.e(TAG, "RemoteException when handling try again", e); |
| 317 | } |
| 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); |
| 323 | final boolean wasShowing = mDialogShowing; |
Kevin Chyn | e191271 | 2019-01-04 14:22:34 -0800 | [diff] [blame^] | 324 | |
| 325 | // Save the state of the current dialog (buttons showing, etc) |
| 326 | final Bundle savedState = new Bundle(); |
| 327 | if (mCurrentDialog != null) { |
| 328 | mCurrentDialog.onSaveState(savedState); |
| 329 | } |
| 330 | |
Gus Prevas | a7df7b2 | 2018-10-30 10:29:34 -0400 | [diff] [blame] | 331 | if (mDialogShowing) { |
| 332 | mCurrentDialog.forceRemove(); |
Kevin Chyn | 02129b1 | 2018-11-01 16:47:12 -0700 | [diff] [blame] | 333 | mDialogShowing = false; |
Gus Prevas | a7df7b2 | 2018-10-30 10:29:34 -0400 | [diff] [blame] | 334 | } |
Kevin Chyn | e191271 | 2019-01-04 14:22:34 -0800 | [diff] [blame^] | 335 | |
Kevin Chyn | 02129b1 | 2018-11-01 16:47:12 -0700 | [diff] [blame] | 336 | if (wasShowing) { |
Kevin Chyn | e191271 | 2019-01-04 14:22:34 -0800 | [diff] [blame^] | 337 | handleShowDialog(mCurrentDialogArgs, true /* skipAnimation */, savedState); |
Gus Prevas | a7df7b2 | 2018-10-30 10:29:34 -0400 | [diff] [blame] | 338 | } |
| 339 | } |
Kevin Chyn | aae4a15 | 2018-01-18 11:48:09 -0800 | [diff] [blame] | 340 | } |