Kevin Chyn | fc46826 | 2019-08-20 17:17:11 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2019 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 | f8688a0 | 2019-08-27 17:04:05 -0700 | [diff] [blame] | 17 | package com.android.systemui.biometrics; |
Kevin Chyn | fc46826 | 2019-08-20 17:17:11 -0700 | [diff] [blame] | 18 | |
Kevin Chyn | 2b1d3d8 | 2019-08-27 16:38:22 -0700 | [diff] [blame] | 19 | import android.annotation.IntDef; |
Kevin Chyn | 9cf8991 | 2019-08-30 13:33:58 -0700 | [diff] [blame] | 20 | import android.annotation.NonNull; |
| 21 | import android.annotation.Nullable; |
Kevin Chyn | fc46826 | 2019-08-20 17:17:11 -0700 | [diff] [blame] | 22 | import android.content.Context; |
| 23 | import android.graphics.PixelFormat; |
Kevin Chyn | 889de4c | 2019-09-05 18:17:32 -0700 | [diff] [blame] | 24 | import android.hardware.biometrics.BiometricAuthenticator; |
Kevin Chyn | 0a45b66 | 2020-03-27 10:15:50 -0700 | [diff] [blame] | 25 | import android.hardware.biometrics.BiometricConstants; |
Kevin Chyn | fc46826 | 2019-08-20 17:17:11 -0700 | [diff] [blame] | 26 | import android.os.Binder; |
| 27 | import android.os.Bundle; |
Kevin Chyn | 656a697 | 2019-10-25 14:16:41 -0700 | [diff] [blame] | 28 | import android.os.Handler; |
Kevin Chyn | fc46826 | 2019-08-20 17:17:11 -0700 | [diff] [blame] | 29 | import android.os.IBinder; |
Kevin Chyn | 656a697 | 2019-10-25 14:16:41 -0700 | [diff] [blame] | 30 | import android.os.Looper; |
Kevin Chyn | b54bdfc | 2020-01-17 16:07:00 -0800 | [diff] [blame] | 31 | import android.os.UserManager; |
Kevin Chyn | fc46826 | 2019-08-20 17:17:11 -0700 | [diff] [blame] | 32 | import android.util.Log; |
| 33 | import android.view.KeyEvent; |
| 34 | import android.view.LayoutInflater; |
| 35 | import android.view.View; |
| 36 | import android.view.ViewGroup; |
| 37 | import android.view.WindowManager; |
| 38 | import android.view.animation.Interpolator; |
Kevin Chyn | ff168dc | 2019-09-16 16:04:38 -0700 | [diff] [blame] | 39 | import android.widget.FrameLayout; |
Kevin Chyn | fc46826 | 2019-08-20 17:17:11 -0700 | [diff] [blame] | 40 | import android.widget.ImageView; |
| 41 | import android.widget.LinearLayout; |
| 42 | import android.widget.ScrollView; |
| 43 | |
| 44 | import com.android.internal.annotations.VisibleForTesting; |
| 45 | import com.android.systemui.Dependency; |
| 46 | import com.android.systemui.Interpolators; |
| 47 | import com.android.systemui.R; |
Kevin Chyn | fc46826 | 2019-08-20 17:17:11 -0700 | [diff] [blame] | 48 | import com.android.systemui.keyguard.WakefulnessLifecycle; |
| 49 | |
Kevin Chyn | 2b1d3d8 | 2019-08-27 16:38:22 -0700 | [diff] [blame] | 50 | import java.lang.annotation.Retention; |
| 51 | import java.lang.annotation.RetentionPolicy; |
| 52 | |
Kevin Chyn | fc46826 | 2019-08-20 17:17:11 -0700 | [diff] [blame] | 53 | /** |
| 54 | * Top level container/controller for the BiometricPrompt UI. |
| 55 | */ |
| 56 | public class AuthContainerView extends LinearLayout |
Kevin Chyn | f8688a0 | 2019-08-27 17:04:05 -0700 | [diff] [blame] | 57 | implements AuthDialog, WakefulnessLifecycle.Observer { |
Kevin Chyn | fc46826 | 2019-08-20 17:17:11 -0700 | [diff] [blame] | 58 | |
| 59 | private static final String TAG = "BiometricPrompt/AuthContainerView"; |
| 60 | private static final int ANIMATION_DURATION_SHOW_MS = 250; |
| 61 | private static final int ANIMATION_DURATION_AWAY_MS = 350; // ms |
| 62 | |
Kevin Chyn | 27da718 | 2019-09-11 12:17:55 -0700 | [diff] [blame] | 63 | static final int STATE_UNKNOWN = 0; |
| 64 | static final int STATE_ANIMATING_IN = 1; |
| 65 | static final int STATE_PENDING_DISMISS = 2; |
| 66 | static final int STATE_SHOWING = 3; |
| 67 | static final int STATE_ANIMATING_OUT = 4; |
| 68 | static final int STATE_GONE = 5; |
Kevin Chyn | 2b1d3d8 | 2019-08-27 16:38:22 -0700 | [diff] [blame] | 69 | |
| 70 | @Retention(RetentionPolicy.SOURCE) |
| 71 | @IntDef({STATE_UNKNOWN, STATE_ANIMATING_IN, STATE_PENDING_DISMISS, STATE_SHOWING, |
| 72 | STATE_ANIMATING_OUT, STATE_GONE}) |
| 73 | @interface ContainerState {} |
| 74 | |
Kevin Chyn | 504f77d | 2019-08-26 15:36:19 -0700 | [diff] [blame] | 75 | final Config mConfig; |
Kevin Chyn | b54bdfc | 2020-01-17 16:07:00 -0800 | [diff] [blame] | 76 | final int mEffectiveUserId; |
Kevin Chyn | 656a697 | 2019-10-25 14:16:41 -0700 | [diff] [blame] | 77 | private final Handler mHandler; |
Kevin Chyn | 86f1b8e | 2019-09-24 19:00:49 -0700 | [diff] [blame] | 78 | private final Injector mInjector; |
Kevin Chyn | fc46826 | 2019-08-20 17:17:11 -0700 | [diff] [blame] | 79 | private final IBinder mWindowToken = new Binder(); |
| 80 | private final WindowManager mWindowManager; |
| 81 | private final AuthPanelController mPanelController; |
| 82 | private final Interpolator mLinearOutSlowIn; |
Kevin Chyn | 504f77d | 2019-08-26 15:36:19 -0700 | [diff] [blame] | 83 | @VisibleForTesting final BiometricCallback mBiometricCallback; |
Kevin Chyn | ff168dc | 2019-09-16 16:04:38 -0700 | [diff] [blame] | 84 | private final CredentialCallback mCredentialCallback; |
Kevin Chyn | fc46826 | 2019-08-20 17:17:11 -0700 | [diff] [blame] | 85 | |
Kevin Chyn | ff168dc | 2019-09-16 16:04:38 -0700 | [diff] [blame] | 86 | @VisibleForTesting final FrameLayout mFrameLayout; |
Kevin Chyn | 86f1b8e | 2019-09-24 19:00:49 -0700 | [diff] [blame] | 87 | @VisibleForTesting @Nullable AuthBiometricView mBiometricView; |
| 88 | @VisibleForTesting @Nullable AuthCredentialView mCredentialView; |
Kevin Chyn | fc46826 | 2019-08-20 17:17:11 -0700 | [diff] [blame] | 89 | |
Kevin Chyn | 517d7fb | 2020-02-06 11:22:28 -0800 | [diff] [blame] | 90 | @VisibleForTesting final ImageView mBackgroundView; |
Kevin Chyn | 86f1b8e | 2019-09-24 19:00:49 -0700 | [diff] [blame] | 91 | @VisibleForTesting final ScrollView mBiometricScrollView; |
Kevin Chyn | fc46826 | 2019-08-20 17:17:11 -0700 | [diff] [blame] | 92 | private final View mPanelView; |
| 93 | |
| 94 | private final float mTranslationY; |
| 95 | |
| 96 | @VisibleForTesting final WakefulnessLifecycle mWakefulnessLifecycle; |
| 97 | |
Kevin Chyn | 2b1d3d8 | 2019-08-27 16:38:22 -0700 | [diff] [blame] | 98 | private @ContainerState int mContainerState = STATE_UNKNOWN; |
Kevin Chyn | fc46826 | 2019-08-20 17:17:11 -0700 | [diff] [blame] | 99 | |
Kevin Chyn | 27da718 | 2019-09-11 12:17:55 -0700 | [diff] [blame] | 100 | // Non-null only if the dialog is in the act of dismissing and has not sent the reason yet. |
| 101 | @Nullable @AuthDialogCallback.DismissedReason Integer mPendingCallbackReason; |
Kevin Chyn | c8cb685 | 2020-03-10 18:29:15 -0700 | [diff] [blame] | 102 | // HAT received from LockSettingsService when credential is verified. |
| 103 | @Nullable byte[] mCredentialAttestation; |
Kevin Chyn | 27da718 | 2019-09-11 12:17:55 -0700 | [diff] [blame] | 104 | |
Kevin Chyn | 504f77d | 2019-08-26 15:36:19 -0700 | [diff] [blame] | 105 | static class Config { |
Kevin Chyn | fc46826 | 2019-08-20 17:17:11 -0700 | [diff] [blame] | 106 | Context mContext; |
Kevin Chyn | f8688a0 | 2019-08-27 17:04:05 -0700 | [diff] [blame] | 107 | AuthDialogCallback mCallback; |
Kevin Chyn | fc46826 | 2019-08-20 17:17:11 -0700 | [diff] [blame] | 108 | Bundle mBiometricPromptBundle; |
| 109 | boolean mRequireConfirmation; |
| 110 | int mUserId; |
| 111 | String mOpPackageName; |
| 112 | int mModalityMask; |
| 113 | boolean mSkipIntro; |
Kevin Chyn | c8cb685 | 2020-03-10 18:29:15 -0700 | [diff] [blame] | 114 | long mOperationId; |
Kevin Chyn | fa7069d | 2020-05-07 13:43:39 -0700 | [diff] [blame] | 115 | int mSysUiSessionId; |
Kevin Chyn | fc46826 | 2019-08-20 17:17:11 -0700 | [diff] [blame] | 116 | } |
| 117 | |
| 118 | public static class Builder { |
| 119 | Config mConfig; |
| 120 | |
| 121 | public Builder(Context context) { |
| 122 | mConfig = new Config(); |
| 123 | mConfig.mContext = context; |
| 124 | } |
| 125 | |
Kevin Chyn | f8688a0 | 2019-08-27 17:04:05 -0700 | [diff] [blame] | 126 | public Builder setCallback(AuthDialogCallback callback) { |
Kevin Chyn | fc46826 | 2019-08-20 17:17:11 -0700 | [diff] [blame] | 127 | mConfig.mCallback = callback; |
| 128 | return this; |
| 129 | } |
| 130 | |
| 131 | public Builder setBiometricPromptBundle(Bundle bundle) { |
| 132 | mConfig.mBiometricPromptBundle = bundle; |
| 133 | return this; |
| 134 | } |
| 135 | |
| 136 | public Builder setRequireConfirmation(boolean requireConfirmation) { |
| 137 | mConfig.mRequireConfirmation = requireConfirmation; |
| 138 | return this; |
| 139 | } |
| 140 | |
| 141 | public Builder setUserId(int userId) { |
| 142 | mConfig.mUserId = userId; |
| 143 | return this; |
| 144 | } |
| 145 | |
| 146 | public Builder setOpPackageName(String opPackageName) { |
| 147 | mConfig.mOpPackageName = opPackageName; |
| 148 | return this; |
| 149 | } |
| 150 | |
| 151 | public Builder setSkipIntro(boolean skip) { |
| 152 | mConfig.mSkipIntro = skip; |
| 153 | return this; |
| 154 | } |
| 155 | |
Kevin Chyn | c8cb685 | 2020-03-10 18:29:15 -0700 | [diff] [blame] | 156 | public Builder setOperationId(long operationId) { |
| 157 | mConfig.mOperationId = operationId; |
| 158 | return this; |
| 159 | } |
| 160 | |
Kevin Chyn | fa7069d | 2020-05-07 13:43:39 -0700 | [diff] [blame] | 161 | public Builder setSysUiSessionId(int sysUiSessionId) { |
| 162 | mConfig.mSysUiSessionId = sysUiSessionId; |
| 163 | return this; |
| 164 | } |
| 165 | |
Kevin Chyn | 889de4c | 2019-09-05 18:17:32 -0700 | [diff] [blame] | 166 | public AuthContainerView build(int modalityMask) { |
| 167 | mConfig.mModalityMask = modalityMask; |
Kevin Chyn | 86f1b8e | 2019-09-24 19:00:49 -0700 | [diff] [blame] | 168 | return new AuthContainerView(mConfig, new Injector()); |
| 169 | } |
| 170 | } |
| 171 | |
| 172 | public static class Injector { |
| 173 | ScrollView getBiometricScrollView(FrameLayout parent) { |
| 174 | return parent.findViewById(R.id.biometric_scrollview); |
| 175 | } |
| 176 | |
| 177 | FrameLayout inflateContainerView(LayoutInflater factory, ViewGroup root) { |
| 178 | return (FrameLayout) factory.inflate( |
| 179 | R.layout.auth_container_view, root, false /* attachToRoot */); |
| 180 | } |
| 181 | |
Kevin Chyn | bac72c4 | 2020-01-21 14:30:26 -0800 | [diff] [blame] | 182 | AuthPanelController getPanelController(Context context, View panelView) { |
| 183 | return new AuthPanelController(context, panelView); |
Kevin Chyn | 86f1b8e | 2019-09-24 19:00:49 -0700 | [diff] [blame] | 184 | } |
| 185 | |
| 186 | ImageView getBackgroundView(FrameLayout parent) { |
| 187 | return parent.findViewById(R.id.background); |
| 188 | } |
| 189 | |
| 190 | View getPanelView(FrameLayout parent) { |
| 191 | return parent.findViewById(R.id.panel); |
Kevin Chyn | fc46826 | 2019-08-20 17:17:11 -0700 | [diff] [blame] | 192 | } |
Kevin Chyn | 656a697 | 2019-10-25 14:16:41 -0700 | [diff] [blame] | 193 | |
| 194 | int getAnimateCredentialStartDelayMs() { |
| 195 | return AuthDialog.ANIMATE_CREDENTIAL_START_DELAY_MS; |
| 196 | } |
Kevin Chyn | b54bdfc | 2020-01-17 16:07:00 -0800 | [diff] [blame] | 197 | |
| 198 | UserManager getUserManager(Context context) { |
| 199 | return UserManager.get(context); |
| 200 | } |
| 201 | |
| 202 | int getCredentialType(Context context, int effectiveUserId) { |
| 203 | return Utils.getCredentialType(context, effectiveUserId); |
| 204 | } |
Kevin Chyn | fc46826 | 2019-08-20 17:17:11 -0700 | [diff] [blame] | 205 | } |
| 206 | |
Kevin Chyn | 504f77d | 2019-08-26 15:36:19 -0700 | [diff] [blame] | 207 | @VisibleForTesting |
| 208 | final class BiometricCallback implements AuthBiometricView.Callback { |
| 209 | @Override |
| 210 | public void onAction(int action) { |
Kevin Chyn | fa7069d | 2020-05-07 13:43:39 -0700 | [diff] [blame] | 211 | Log.d(TAG, "onAction: " + action |
| 212 | + ", sysUiSessionId: " + mConfig.mSysUiSessionId |
| 213 | + ", state: " + mContainerState); |
Kevin Chyn | 504f77d | 2019-08-26 15:36:19 -0700 | [diff] [blame] | 214 | switch (action) { |
| 215 | case AuthBiometricView.Callback.ACTION_AUTHENTICATED: |
Kevin Chyn | ff168dc | 2019-09-16 16:04:38 -0700 | [diff] [blame] | 216 | animateAway(AuthDialogCallback.DISMISSED_BIOMETRIC_AUTHENTICATED); |
Kevin Chyn | 504f77d | 2019-08-26 15:36:19 -0700 | [diff] [blame] | 217 | break; |
| 218 | case AuthBiometricView.Callback.ACTION_USER_CANCELED: |
Kevin Chyn | 0a45b66 | 2020-03-27 10:15:50 -0700 | [diff] [blame] | 219 | sendEarlyUserCanceled(); |
Kevin Chyn | f8688a0 | 2019-08-27 17:04:05 -0700 | [diff] [blame] | 220 | animateAway(AuthDialogCallback.DISMISSED_USER_CANCELED); |
Kevin Chyn | 504f77d | 2019-08-26 15:36:19 -0700 | [diff] [blame] | 221 | break; |
| 222 | case AuthBiometricView.Callback.ACTION_BUTTON_NEGATIVE: |
Kevin Chyn | f8688a0 | 2019-08-27 17:04:05 -0700 | [diff] [blame] | 223 | animateAway(AuthDialogCallback.DISMISSED_BUTTON_NEGATIVE); |
Kevin Chyn | 504f77d | 2019-08-26 15:36:19 -0700 | [diff] [blame] | 224 | break; |
| 225 | case AuthBiometricView.Callback.ACTION_BUTTON_TRY_AGAIN: |
| 226 | mConfig.mCallback.onTryAgainPressed(); |
| 227 | break; |
Kevin Chyn | 889de4c | 2019-09-05 18:17:32 -0700 | [diff] [blame] | 228 | case AuthBiometricView.Callback.ACTION_ERROR: |
| 229 | animateAway(AuthDialogCallback.DISMISSED_ERROR); |
| 230 | break; |
Kevin Chyn | 396a841 | 2019-09-16 11:35:18 -0700 | [diff] [blame] | 231 | case AuthBiometricView.Callback.ACTION_USE_DEVICE_CREDENTIAL: |
Kevin Chyn | ff168dc | 2019-09-16 16:04:38 -0700 | [diff] [blame] | 232 | mConfig.mCallback.onDeviceCredentialPressed(); |
Kevin Chyn | 656a697 | 2019-10-25 14:16:41 -0700 | [diff] [blame] | 233 | mHandler.postDelayed(() -> { |
| 234 | addCredentialView(false /* animatePanel */, true /* animateContents */); |
| 235 | }, mInjector.getAnimateCredentialStartDelayMs()); |
Kevin Chyn | 396a841 | 2019-09-16 11:35:18 -0700 | [diff] [blame] | 236 | break; |
Kevin Chyn | 504f77d | 2019-08-26 15:36:19 -0700 | [diff] [blame] | 237 | default: |
| 238 | Log.e(TAG, "Unhandled action: " + action); |
| 239 | } |
Kevin Chyn | fc46826 | 2019-08-20 17:17:11 -0700 | [diff] [blame] | 240 | } |
Kevin Chyn | 504f77d | 2019-08-26 15:36:19 -0700 | [diff] [blame] | 241 | } |
Kevin Chyn | fc46826 | 2019-08-20 17:17:11 -0700 | [diff] [blame] | 242 | |
Kevin Chyn | ff168dc | 2019-09-16 16:04:38 -0700 | [diff] [blame] | 243 | final class CredentialCallback implements AuthCredentialView.Callback { |
| 244 | @Override |
Kevin Chyn | c8cb685 | 2020-03-10 18:29:15 -0700 | [diff] [blame] | 245 | public void onCredentialMatched(byte[] attestation) { |
| 246 | mCredentialAttestation = attestation; |
Kevin Chyn | ff168dc | 2019-09-16 16:04:38 -0700 | [diff] [blame] | 247 | animateAway(AuthDialogCallback.DISMISSED_CREDENTIAL_AUTHENTICATED); |
| 248 | } |
| 249 | } |
| 250 | |
Kevin Chyn | 504f77d | 2019-08-26 15:36:19 -0700 | [diff] [blame] | 251 | @VisibleForTesting |
Kevin Chyn | 86f1b8e | 2019-09-24 19:00:49 -0700 | [diff] [blame] | 252 | AuthContainerView(Config config, Injector injector) { |
Kevin Chyn | fc46826 | 2019-08-20 17:17:11 -0700 | [diff] [blame] | 253 | super(config.mContext); |
| 254 | |
| 255 | mConfig = config; |
Kevin Chyn | 86f1b8e | 2019-09-24 19:00:49 -0700 | [diff] [blame] | 256 | mInjector = injector; |
| 257 | |
Kevin Chyn | b54bdfc | 2020-01-17 16:07:00 -0800 | [diff] [blame] | 258 | mEffectiveUserId = mInjector.getUserManager(mContext) |
| 259 | .getCredentialOwnerProfile(mConfig.mUserId); |
| 260 | |
Kevin Chyn | 656a697 | 2019-10-25 14:16:41 -0700 | [diff] [blame] | 261 | mHandler = new Handler(Looper.getMainLooper()); |
Kevin Chyn | fc46826 | 2019-08-20 17:17:11 -0700 | [diff] [blame] | 262 | mWindowManager = mContext.getSystemService(WindowManager.class); |
| 263 | mWakefulnessLifecycle = Dependency.get(WakefulnessLifecycle.class); |
| 264 | |
| 265 | mTranslationY = getResources() |
| 266 | .getDimension(R.dimen.biometric_dialog_animation_translation_offset); |
| 267 | mLinearOutSlowIn = Interpolators.LINEAR_OUT_SLOW_IN; |
Kevin Chyn | 504f77d | 2019-08-26 15:36:19 -0700 | [diff] [blame] | 268 | mBiometricCallback = new BiometricCallback(); |
Kevin Chyn | ff168dc | 2019-09-16 16:04:38 -0700 | [diff] [blame] | 269 | mCredentialCallback = new CredentialCallback(); |
Kevin Chyn | fc46826 | 2019-08-20 17:17:11 -0700 | [diff] [blame] | 270 | |
| 271 | final LayoutInflater factory = LayoutInflater.from(mContext); |
Kevin Chyn | 86f1b8e | 2019-09-24 19:00:49 -0700 | [diff] [blame] | 272 | mFrameLayout = mInjector.inflateContainerView(factory, this); |
Kevin Chyn | fc46826 | 2019-08-20 17:17:11 -0700 | [diff] [blame] | 273 | |
Kevin Chyn | 86f1b8e | 2019-09-24 19:00:49 -0700 | [diff] [blame] | 274 | mPanelView = mInjector.getPanelView(mFrameLayout); |
Kevin Chyn | bac72c4 | 2020-01-21 14:30:26 -0800 | [diff] [blame] | 275 | mPanelController = mInjector.getPanelController(mContext, mPanelView); |
Kevin Chyn | fc46826 | 2019-08-20 17:17:11 -0700 | [diff] [blame] | 276 | |
Kevin Chyn | 86f1b8e | 2019-09-24 19:00:49 -0700 | [diff] [blame] | 277 | // Inflate biometric view only if necessary. |
| 278 | if (Utils.isBiometricAllowed(mConfig.mBiometricPromptBundle)) { |
| 279 | if (config.mModalityMask == BiometricAuthenticator.TYPE_FINGERPRINT) { |
| 280 | mBiometricView = (AuthBiometricFingerprintView) |
| 281 | factory.inflate(R.layout.auth_biometric_fingerprint_view, null, false); |
| 282 | } else if (config.mModalityMask == BiometricAuthenticator.TYPE_FACE) { |
| 283 | mBiometricView = (AuthBiometricFaceView) |
| 284 | factory.inflate(R.layout.auth_biometric_face_view, null, false); |
| 285 | } else { |
| 286 | Log.e(TAG, "Unsupported biometric modality: " + config.mModalityMask); |
| 287 | mBiometricView = null; |
| 288 | mBackgroundView = null; |
| 289 | mBiometricScrollView = null; |
| 290 | return; |
| 291 | } |
Kevin Chyn | 889de4c | 2019-09-05 18:17:32 -0700 | [diff] [blame] | 292 | } |
| 293 | |
Kevin Chyn | 86f1b8e | 2019-09-24 19:00:49 -0700 | [diff] [blame] | 294 | mBiometricScrollView = mInjector.getBiometricScrollView(mFrameLayout); |
| 295 | mBackgroundView = mInjector.getBackgroundView(mFrameLayout); |
Kevin Chyn | 889de4c | 2019-09-05 18:17:32 -0700 | [diff] [blame] | 296 | |
Kevin Chyn | ff168dc | 2019-09-16 16:04:38 -0700 | [diff] [blame] | 297 | addView(mFrameLayout); |
Kevin Chyn | fc46826 | 2019-08-20 17:17:11 -0700 | [diff] [blame] | 298 | |
Kevin Chyn | 0a45b66 | 2020-03-27 10:15:50 -0700 | [diff] [blame] | 299 | // TODO: De-dupe the logic with AuthCredentialPasswordView |
Kevin Chyn | fc46826 | 2019-08-20 17:17:11 -0700 | [diff] [blame] | 300 | setOnKeyListener((v, keyCode, event) -> { |
| 301 | if (keyCode != KeyEvent.KEYCODE_BACK) { |
| 302 | return false; |
| 303 | } |
| 304 | if (event.getAction() == KeyEvent.ACTION_UP) { |
Kevin Chyn | 0a45b66 | 2020-03-27 10:15:50 -0700 | [diff] [blame] | 305 | sendEarlyUserCanceled(); |
Kevin Chyn | f8688a0 | 2019-08-27 17:04:05 -0700 | [diff] [blame] | 306 | animateAway(AuthDialogCallback.DISMISSED_USER_CANCELED); |
Kevin Chyn | fc46826 | 2019-08-20 17:17:11 -0700 | [diff] [blame] | 307 | } |
| 308 | return true; |
| 309 | }); |
| 310 | |
Curtis Belmonte | bca4454 | 2020-05-08 13:40:31 -0700 | [diff] [blame] | 311 | setImportantForAccessibility(IMPORTANT_FOR_ACCESSIBILITY_NO); |
Kevin Chyn | fc46826 | 2019-08-20 17:17:11 -0700 | [diff] [blame] | 312 | setFocusableInTouchMode(true); |
| 313 | requestFocus(); |
| 314 | } |
| 315 | |
Kevin Chyn | 0a45b66 | 2020-03-27 10:15:50 -0700 | [diff] [blame] | 316 | void sendEarlyUserCanceled() { |
| 317 | mConfig.mCallback.onSystemEvent( |
| 318 | BiometricConstants.BIOMETRIC_SYSTEM_EVENT_EARLY_USER_CANCEL); |
| 319 | } |
| 320 | |
Kevin Chyn | 8429da2 | 2019-09-24 12:42:35 -0700 | [diff] [blame] | 321 | @Override |
| 322 | public boolean isAllowDeviceCredentials() { |
Kevin Chyn | 86f1b8e | 2019-09-24 19:00:49 -0700 | [diff] [blame] | 323 | return Utils.isDeviceCredentialAllowed(mConfig.mBiometricPromptBundle); |
Kevin Chyn | 8429da2 | 2019-09-24 12:42:35 -0700 | [diff] [blame] | 324 | } |
| 325 | |
Kevin Chyn | 8cbb488 | 2019-09-19 16:49:02 -0700 | [diff] [blame] | 326 | private void addBiometricView() { |
| 327 | mBiometricView.setRequireConfirmation(mConfig.mRequireConfirmation); |
| 328 | mBiometricView.setPanelController(mPanelController); |
| 329 | mBiometricView.setBiometricPromptBundle(mConfig.mBiometricPromptBundle); |
| 330 | mBiometricView.setCallback(mBiometricCallback); |
| 331 | mBiometricView.setBackgroundView(mBackgroundView); |
| 332 | mBiometricView.setUserId(mConfig.mUserId); |
Kevin Chyn | b54bdfc | 2020-01-17 16:07:00 -0800 | [diff] [blame] | 333 | mBiometricView.setEffectiveUserId(mEffectiveUserId); |
Kevin Chyn | 8cbb488 | 2019-09-19 16:49:02 -0700 | [diff] [blame] | 334 | mBiometricScrollView.addView(mBiometricView); |
| 335 | } |
| 336 | |
| 337 | /** |
| 338 | * Adds the credential view. When going from biometric to credential view, the biometric |
| 339 | * view starts the panel expansion animation. If the credential view is being shown first, |
| 340 | * it should own the panel expansion. |
| 341 | * @param animatePanel if the credential view needs to own the panel expansion animation |
| 342 | */ |
Kevin Chyn | 86f1b8e | 2019-09-24 19:00:49 -0700 | [diff] [blame] | 343 | private void addCredentialView(boolean animatePanel, boolean animateContents) { |
Kevin Chyn | ff168dc | 2019-09-16 16:04:38 -0700 | [diff] [blame] | 344 | final LayoutInflater factory = LayoutInflater.from(mContext); |
Kevin Chyn | b54bdfc | 2020-01-17 16:07:00 -0800 | [diff] [blame] | 345 | |
| 346 | final @Utils.CredentialType int credentialType = mInjector.getCredentialType( |
| 347 | mContext, mEffectiveUserId); |
| 348 | |
Kevin Chyn | 8110ebb | 2019-10-02 11:16:31 -0700 | [diff] [blame] | 349 | switch (credentialType) { |
| 350 | case Utils.CREDENTIAL_PATTERN: |
| 351 | mCredentialView = (AuthCredentialView) factory.inflate( |
| 352 | R.layout.auth_credential_pattern_view, null, false); |
| 353 | break; |
| 354 | case Utils.CREDENTIAL_PIN: |
| 355 | case Utils.CREDENTIAL_PASSWORD: |
| 356 | mCredentialView = (AuthCredentialView) factory.inflate( |
| 357 | R.layout.auth_credential_password_view, null, false); |
| 358 | break; |
| 359 | default: |
| 360 | throw new IllegalStateException("Unknown credential type: " + credentialType); |
| 361 | } |
| 362 | |
Kevin Chyn | 517d7fb | 2020-02-06 11:22:28 -0800 | [diff] [blame] | 363 | // The background is used for detecting taps / cancelling authentication. Since the |
| 364 | // credential view is full-screen and should not be canceled from background taps, |
| 365 | // disable it. |
| 366 | mBackgroundView.setOnClickListener(null); |
| 367 | mBackgroundView.setImportantForAccessibility(IMPORTANT_FOR_ACCESSIBILITY_NO); |
| 368 | |
Kevin Chyn | 8110ebb | 2019-10-02 11:16:31 -0700 | [diff] [blame] | 369 | mCredentialView.setContainerView(this); |
Kevin Chyn | bc3347f | 2020-02-20 16:45:59 -0800 | [diff] [blame] | 370 | mCredentialView.setUserId(mConfig.mUserId); |
Kevin Chyn | c8cb685 | 2020-03-10 18:29:15 -0700 | [diff] [blame] | 371 | mCredentialView.setOperationId(mConfig.mOperationId); |
Kevin Chyn | b54bdfc | 2020-01-17 16:07:00 -0800 | [diff] [blame] | 372 | mCredentialView.setEffectiveUserId(mEffectiveUserId); |
| 373 | mCredentialView.setCredentialType(credentialType); |
Kevin Chyn | ff168dc | 2019-09-16 16:04:38 -0700 | [diff] [blame] | 374 | mCredentialView.setCallback(mCredentialCallback); |
| 375 | mCredentialView.setBiometricPromptBundle(mConfig.mBiometricPromptBundle); |
Kevin Chyn | 8cbb488 | 2019-09-19 16:49:02 -0700 | [diff] [blame] | 376 | mCredentialView.setPanelController(mPanelController, animatePanel); |
Kevin Chyn | 86f1b8e | 2019-09-24 19:00:49 -0700 | [diff] [blame] | 377 | mCredentialView.setShouldAnimateContents(animateContents); |
Kevin Chyn | ff168dc | 2019-09-16 16:04:38 -0700 | [diff] [blame] | 378 | mFrameLayout.addView(mCredentialView); |
| 379 | } |
| 380 | |
Kevin Chyn | fc46826 | 2019-08-20 17:17:11 -0700 | [diff] [blame] | 381 | @Override |
| 382 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { |
| 383 | super.onMeasure(widthMeasureSpec, heightMeasureSpec); |
| 384 | mPanelController.setContainerDimensions(getMeasuredWidth(), getMeasuredHeight()); |
| 385 | } |
| 386 | |
| 387 | @Override |
| 388 | public void onAttachedToWindow() { |
| 389 | super.onAttachedToWindow(); |
Kevin Chyn | 86f1b8e | 2019-09-24 19:00:49 -0700 | [diff] [blame] | 390 | onAttachedToWindowInternal(); |
| 391 | } |
| 392 | |
| 393 | @VisibleForTesting |
| 394 | void onAttachedToWindowInternal() { |
Kevin Chyn | fc46826 | 2019-08-20 17:17:11 -0700 | [diff] [blame] | 395 | mWakefulnessLifecycle.addObserver(this); |
| 396 | |
Kevin Chyn | 86f1b8e | 2019-09-24 19:00:49 -0700 | [diff] [blame] | 397 | if (Utils.isBiometricAllowed(mConfig.mBiometricPromptBundle)) { |
| 398 | addBiometricView(); |
| 399 | } else if (Utils.isDeviceCredentialAllowed(mConfig.mBiometricPromptBundle)) { |
| 400 | addCredentialView(true /* animatePanel */, false /* animateContents */); |
| 401 | } else { |
| 402 | throw new IllegalStateException("Unknown configuration: " |
| 403 | + Utils.getAuthenticators(mConfig.mBiometricPromptBundle)); |
Kevin Chyn | 8cbb488 | 2019-09-19 16:49:02 -0700 | [diff] [blame] | 404 | } |
| 405 | |
Kevin Chyn | fc46826 | 2019-08-20 17:17:11 -0700 | [diff] [blame] | 406 | if (mConfig.mSkipIntro) { |
Kevin Chyn | 2b1d3d8 | 2019-08-27 16:38:22 -0700 | [diff] [blame] | 407 | mContainerState = STATE_SHOWING; |
Kevin Chyn | fc46826 | 2019-08-20 17:17:11 -0700 | [diff] [blame] | 408 | } else { |
Kevin Chyn | 2b1d3d8 | 2019-08-27 16:38:22 -0700 | [diff] [blame] | 409 | mContainerState = STATE_ANIMATING_IN; |
Kevin Chyn | fc46826 | 2019-08-20 17:17:11 -0700 | [diff] [blame] | 410 | // The background panel and content are different views since we need to be able to |
| 411 | // animate them separately in other places. |
| 412 | mPanelView.setY(mTranslationY); |
Kevin Chyn | ff168dc | 2019-09-16 16:04:38 -0700 | [diff] [blame] | 413 | mBiometricScrollView.setY(mTranslationY); |
Kevin Chyn | fc46826 | 2019-08-20 17:17:11 -0700 | [diff] [blame] | 414 | |
| 415 | setAlpha(0f); |
| 416 | postOnAnimation(() -> { |
| 417 | mPanelView.animate() |
| 418 | .translationY(0) |
| 419 | .setDuration(ANIMATION_DURATION_SHOW_MS) |
| 420 | .setInterpolator(mLinearOutSlowIn) |
| 421 | .withLayer() |
| 422 | .withEndAction(this::onDialogAnimatedIn) |
| 423 | .start(); |
Kevin Chyn | ff168dc | 2019-09-16 16:04:38 -0700 | [diff] [blame] | 424 | mBiometricScrollView.animate() |
Kevin Chyn | fc46826 | 2019-08-20 17:17:11 -0700 | [diff] [blame] | 425 | .translationY(0) |
| 426 | .setDuration(ANIMATION_DURATION_SHOW_MS) |
| 427 | .setInterpolator(mLinearOutSlowIn) |
| 428 | .withLayer() |
| 429 | .start(); |
Kevin Chyn | 86f1b8e | 2019-09-24 19:00:49 -0700 | [diff] [blame] | 430 | if (mCredentialView != null && mCredentialView.isAttachedToWindow()) { |
| 431 | mCredentialView.setY(mTranslationY); |
| 432 | mCredentialView.animate() |
| 433 | .translationY(0) |
| 434 | .setDuration(ANIMATION_DURATION_SHOW_MS) |
| 435 | .setInterpolator(mLinearOutSlowIn) |
| 436 | .withLayer() |
| 437 | .start(); |
| 438 | } |
Kevin Chyn | fc46826 | 2019-08-20 17:17:11 -0700 | [diff] [blame] | 439 | animate() |
| 440 | .alpha(1f) |
| 441 | .setDuration(ANIMATION_DURATION_SHOW_MS) |
| 442 | .setInterpolator(mLinearOutSlowIn) |
| 443 | .withLayer() |
| 444 | .start(); |
| 445 | }); |
| 446 | } |
| 447 | } |
| 448 | |
| 449 | @Override |
| 450 | public void onDetachedFromWindow() { |
| 451 | super.onDetachedFromWindow(); |
| 452 | mWakefulnessLifecycle.removeObserver(this); |
| 453 | } |
| 454 | |
| 455 | @Override |
| 456 | public void onStartedGoingToSleep() { |
Kevin Chyn | f8688a0 | 2019-08-27 17:04:05 -0700 | [diff] [blame] | 457 | animateAway(AuthDialogCallback.DISMISSED_USER_CANCELED); |
Kevin Chyn | fc46826 | 2019-08-20 17:17:11 -0700 | [diff] [blame] | 458 | } |
| 459 | |
| 460 | @Override |
Kevin Chyn | 9cf8991 | 2019-08-30 13:33:58 -0700 | [diff] [blame] | 461 | public void show(WindowManager wm, @Nullable Bundle savedState) { |
Kevin Chyn | 86f1b8e | 2019-09-24 19:00:49 -0700 | [diff] [blame] | 462 | if (mBiometricView != null) { |
| 463 | mBiometricView.restoreState(savedState); |
| 464 | } |
Kevin Chyn | fc46826 | 2019-08-20 17:17:11 -0700 | [diff] [blame] | 465 | wm.addView(this, getLayoutParams(mWindowToken)); |
| 466 | } |
| 467 | |
| 468 | @Override |
| 469 | public void dismissWithoutCallback(boolean animate) { |
| 470 | if (animate) { |
| 471 | animateAway(false /* sendReason */, 0 /* reason */); |
| 472 | } else { |
Kevin Chyn | fa7069d | 2020-05-07 13:43:39 -0700 | [diff] [blame] | 473 | removeWindowIfAttached(false /* sendReason */); |
Kevin Chyn | fc46826 | 2019-08-20 17:17:11 -0700 | [diff] [blame] | 474 | } |
| 475 | } |
| 476 | |
| 477 | @Override |
| 478 | public void dismissFromSystemServer() { |
Kevin Chyn | fa7069d | 2020-05-07 13:43:39 -0700 | [diff] [blame] | 479 | removeWindowIfAttached(true /* sendReason */); |
Kevin Chyn | fc46826 | 2019-08-20 17:17:11 -0700 | [diff] [blame] | 480 | } |
| 481 | |
| 482 | @Override |
| 483 | public void onAuthenticationSucceeded() { |
| 484 | mBiometricView.onAuthenticationSucceeded(); |
| 485 | } |
| 486 | |
| 487 | @Override |
| 488 | public void onAuthenticationFailed(String failureReason) { |
Kevin Chyn | 504f77d | 2019-08-26 15:36:19 -0700 | [diff] [blame] | 489 | mBiometricView.onAuthenticationFailed(failureReason); |
Kevin Chyn | fc46826 | 2019-08-20 17:17:11 -0700 | [diff] [blame] | 490 | } |
| 491 | |
| 492 | @Override |
| 493 | public void onHelp(String help) { |
Kevin Chyn | 504f77d | 2019-08-26 15:36:19 -0700 | [diff] [blame] | 494 | mBiometricView.onHelp(help); |
Kevin Chyn | fc46826 | 2019-08-20 17:17:11 -0700 | [diff] [blame] | 495 | } |
| 496 | |
| 497 | @Override |
| 498 | public void onError(String error) { |
Kevin Chyn | 889de4c | 2019-09-05 18:17:32 -0700 | [diff] [blame] | 499 | mBiometricView.onError(error); |
Kevin Chyn | fc46826 | 2019-08-20 17:17:11 -0700 | [diff] [blame] | 500 | } |
| 501 | |
| 502 | @Override |
Kevin Chyn | 9cf8991 | 2019-08-30 13:33:58 -0700 | [diff] [blame] | 503 | public void onSaveState(@NonNull Bundle outState) { |
Kevin Chyn | 27da718 | 2019-09-11 12:17:55 -0700 | [diff] [blame] | 504 | outState.putInt(AuthDialog.KEY_CONTAINER_STATE, mContainerState); |
Kevin Chyn | 8cbb488 | 2019-09-19 16:49:02 -0700 | [diff] [blame] | 505 | // In the case where biometric and credential are both allowed, we can assume that |
| 506 | // biometric isn't showing if credential is showing since biometric is shown first. |
| 507 | outState.putBoolean(AuthDialog.KEY_BIOMETRIC_SHOWING, |
| 508 | mBiometricView != null && mCredentialView == null); |
| 509 | outState.putBoolean(AuthDialog.KEY_CREDENTIAL_SHOWING, mCredentialView != null); |
Kevin Chyn | 86f1b8e | 2019-09-24 19:00:49 -0700 | [diff] [blame] | 510 | |
| 511 | if (mBiometricView != null) { |
| 512 | mBiometricView.onSaveState(outState); |
| 513 | } |
Kevin Chyn | fc46826 | 2019-08-20 17:17:11 -0700 | [diff] [blame] | 514 | } |
| 515 | |
| 516 | @Override |
| 517 | public String getOpPackageName() { |
| 518 | return mConfig.mOpPackageName; |
| 519 | } |
| 520 | |
Kevin Chyn | 8429da2 | 2019-09-24 12:42:35 -0700 | [diff] [blame] | 521 | @Override |
| 522 | public void animateToCredentialUI() { |
| 523 | mBiometricView.startTransitionToCredentialUI(); |
| 524 | } |
| 525 | |
Kevin Chyn | 504f77d | 2019-08-26 15:36:19 -0700 | [diff] [blame] | 526 | @VisibleForTesting |
| 527 | void animateAway(int reason) { |
Kevin Chyn | fc46826 | 2019-08-20 17:17:11 -0700 | [diff] [blame] | 528 | animateAway(true /* sendReason */, reason); |
| 529 | } |
| 530 | |
Kevin Chyn | f8688a0 | 2019-08-27 17:04:05 -0700 | [diff] [blame] | 531 | private void animateAway(boolean sendReason, @AuthDialogCallback.DismissedReason int reason) { |
Kevin Chyn | 2b1d3d8 | 2019-08-27 16:38:22 -0700 | [diff] [blame] | 532 | if (mContainerState == STATE_ANIMATING_IN) { |
Kevin Chyn | fc46826 | 2019-08-20 17:17:11 -0700 | [diff] [blame] | 533 | Log.w(TAG, "startDismiss(): waiting for onDialogAnimatedIn"); |
Kevin Chyn | 2b1d3d8 | 2019-08-27 16:38:22 -0700 | [diff] [blame] | 534 | mContainerState = STATE_PENDING_DISMISS; |
Kevin Chyn | fc46826 | 2019-08-20 17:17:11 -0700 | [diff] [blame] | 535 | return; |
| 536 | } |
| 537 | |
Kevin Chyn | 2b1d3d8 | 2019-08-27 16:38:22 -0700 | [diff] [blame] | 538 | if (mContainerState == STATE_ANIMATING_OUT) { |
| 539 | Log.w(TAG, "Already dismissing, sendReason: " + sendReason + " reason: " + reason); |
| 540 | return; |
| 541 | } |
| 542 | mContainerState = STATE_ANIMATING_OUT; |
| 543 | |
Kevin Chyn | 27da718 | 2019-09-11 12:17:55 -0700 | [diff] [blame] | 544 | if (sendReason) { |
| 545 | mPendingCallbackReason = reason; |
| 546 | } else { |
| 547 | mPendingCallbackReason = null; |
| 548 | } |
| 549 | |
Kevin Chyn | fc46826 | 2019-08-20 17:17:11 -0700 | [diff] [blame] | 550 | final Runnable endActionRunnable = () -> { |
| 551 | setVisibility(View.INVISIBLE); |
Kevin Chyn | fa7069d | 2020-05-07 13:43:39 -0700 | [diff] [blame] | 552 | removeWindowIfAttached(true /* sendReason */); |
Kevin Chyn | fc46826 | 2019-08-20 17:17:11 -0700 | [diff] [blame] | 553 | }; |
| 554 | |
| 555 | postOnAnimation(() -> { |
| 556 | mPanelView.animate() |
| 557 | .translationY(mTranslationY) |
| 558 | .setDuration(ANIMATION_DURATION_AWAY_MS) |
| 559 | .setInterpolator(mLinearOutSlowIn) |
| 560 | .withLayer() |
| 561 | .withEndAction(endActionRunnable) |
| 562 | .start(); |
Kevin Chyn | ff168dc | 2019-09-16 16:04:38 -0700 | [diff] [blame] | 563 | mBiometricScrollView.animate() |
Kevin Chyn | fc46826 | 2019-08-20 17:17:11 -0700 | [diff] [blame] | 564 | .translationY(mTranslationY) |
| 565 | .setDuration(ANIMATION_DURATION_AWAY_MS) |
| 566 | .setInterpolator(mLinearOutSlowIn) |
| 567 | .withLayer() |
| 568 | .start(); |
Kevin Chyn | ff168dc | 2019-09-16 16:04:38 -0700 | [diff] [blame] | 569 | if (mCredentialView != null && mCredentialView.isAttachedToWindow()) { |
| 570 | mCredentialView.animate() |
| 571 | .translationY(mTranslationY) |
| 572 | .setDuration(ANIMATION_DURATION_AWAY_MS) |
| 573 | .setInterpolator(mLinearOutSlowIn) |
| 574 | .withLayer() |
| 575 | .start(); |
| 576 | } |
Kevin Chyn | fc46826 | 2019-08-20 17:17:11 -0700 | [diff] [blame] | 577 | animate() |
| 578 | .alpha(0f) |
| 579 | .setDuration(ANIMATION_DURATION_AWAY_MS) |
| 580 | .setInterpolator(mLinearOutSlowIn) |
| 581 | .withLayer() |
| 582 | .start(); |
| 583 | }); |
| 584 | } |
| 585 | |
Kevin Chyn | 27da718 | 2019-09-11 12:17:55 -0700 | [diff] [blame] | 586 | private void sendPendingCallbackIfNotNull() { |
Kevin Chyn | fa7069d | 2020-05-07 13:43:39 -0700 | [diff] [blame] | 587 | Log.d(TAG, "pendingCallback: " + mPendingCallbackReason |
| 588 | + " sysUISessionId: " + mConfig.mSysUiSessionId); |
Kevin Chyn | 27da718 | 2019-09-11 12:17:55 -0700 | [diff] [blame] | 589 | if (mPendingCallbackReason != null) { |
Kevin Chyn | c8cb685 | 2020-03-10 18:29:15 -0700 | [diff] [blame] | 590 | mConfig.mCallback.onDismissed(mPendingCallbackReason, mCredentialAttestation); |
Kevin Chyn | 27da718 | 2019-09-11 12:17:55 -0700 | [diff] [blame] | 591 | mPendingCallbackReason = null; |
| 592 | } |
| 593 | } |
| 594 | |
Kevin Chyn | fa7069d | 2020-05-07 13:43:39 -0700 | [diff] [blame] | 595 | private void removeWindowIfAttached(boolean sendReason) { |
| 596 | if (sendReason) { |
| 597 | sendPendingCallbackIfNotNull(); |
| 598 | } |
Kevin Chyn | 27da718 | 2019-09-11 12:17:55 -0700 | [diff] [blame] | 599 | |
Kevin Chyn | 889de4c | 2019-09-05 18:17:32 -0700 | [diff] [blame] | 600 | if (mContainerState == STATE_GONE) { |
Kevin Chyn | fa7069d | 2020-05-07 13:43:39 -0700 | [diff] [blame] | 601 | Log.w(TAG, "Container already STATE_GONE, mSysUiSessionId: " + mConfig.mSysUiSessionId); |
Kevin Chyn | 889de4c | 2019-09-05 18:17:32 -0700 | [diff] [blame] | 602 | return; |
| 603 | } |
Kevin Chyn | fa7069d | 2020-05-07 13:43:39 -0700 | [diff] [blame] | 604 | Log.d(TAG, "Removing container, mSysUiSessionId: " + mConfig.mSysUiSessionId); |
Kevin Chyn | 889de4c | 2019-09-05 18:17:32 -0700 | [diff] [blame] | 605 | mContainerState = STATE_GONE; |
| 606 | mWindowManager.removeView(this); |
| 607 | } |
| 608 | |
Kevin Chyn | fc46826 | 2019-08-20 17:17:11 -0700 | [diff] [blame] | 609 | private void onDialogAnimatedIn() { |
Kevin Chyn | 2b1d3d8 | 2019-08-27 16:38:22 -0700 | [diff] [blame] | 610 | if (mContainerState == STATE_PENDING_DISMISS) { |
Kevin Chyn | fc46826 | 2019-08-20 17:17:11 -0700 | [diff] [blame] | 611 | Log.d(TAG, "onDialogAnimatedIn(): mPendingDismissDialog=true, dismissing now"); |
| 612 | animateAway(false /* sendReason */, 0); |
Kevin Chyn | fc46826 | 2019-08-20 17:17:11 -0700 | [diff] [blame] | 613 | return; |
| 614 | } |
Kevin Chyn | 2b1d3d8 | 2019-08-27 16:38:22 -0700 | [diff] [blame] | 615 | mContainerState = STATE_SHOWING; |
Kevin Chyn | 86f1b8e | 2019-09-24 19:00:49 -0700 | [diff] [blame] | 616 | if (mBiometricView != null) { |
| 617 | mBiometricView.onDialogAnimatedIn(); |
| 618 | } |
Kevin Chyn | fc46826 | 2019-08-20 17:17:11 -0700 | [diff] [blame] | 619 | } |
| 620 | |
| 621 | /** |
| 622 | * @param windowToken token for the window |
| 623 | * @return |
| 624 | */ |
| 625 | public static WindowManager.LayoutParams getLayoutParams(IBinder windowToken) { |
Curtis Belmonte | 23b8d49 | 2020-02-04 14:24:39 -0800 | [diff] [blame] | 626 | final int windowFlags = WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED |
| 627 | | WindowManager.LayoutParams.FLAG_SECURE; |
Kevin Chyn | fc46826 | 2019-08-20 17:17:11 -0700 | [diff] [blame] | 628 | final WindowManager.LayoutParams lp = new WindowManager.LayoutParams( |
| 629 | ViewGroup.LayoutParams.MATCH_PARENT, |
| 630 | ViewGroup.LayoutParams.MATCH_PARENT, |
Heemin Seog | 2cf45dd | 2020-02-24 15:43:29 -0800 | [diff] [blame] | 631 | WindowManager.LayoutParams.TYPE_STATUS_BAR_SUB_PANEL, |
Curtis Belmonte | 23b8d49 | 2020-02-04 14:24:39 -0800 | [diff] [blame] | 632 | windowFlags, |
Kevin Chyn | fc46826 | 2019-08-20 17:17:11 -0700 | [diff] [blame] | 633 | PixelFormat.TRANSLUCENT); |
Roshan Pius | a3f89c6 | 2019-10-11 08:50:53 -0700 | [diff] [blame] | 634 | lp.privateFlags |= WindowManager.LayoutParams.SYSTEM_FLAG_SHOW_FOR_ALL_USERS; |
Kevin Chyn | fc46826 | 2019-08-20 17:17:11 -0700 | [diff] [blame] | 635 | lp.setTitle("BiometricPrompt"); |
| 636 | lp.token = windowToken; |
Kevin Chyn | fc46826 | 2019-08-20 17:17:11 -0700 | [diff] [blame] | 637 | return lp; |
| 638 | } |
| 639 | } |