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