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