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 17 package com.android.systemui.biometrics; 18 19 import android.annotation.IntDef; 20 import android.annotation.NonNull; 21 import android.annotation.Nullable; 22 import android.hardware.biometrics.BiometricAuthenticator.Modality; 23 import android.os.Bundle; 24 import android.view.WindowManager; 25 26 import java.lang.annotation.Retention; 27 import java.lang.annotation.RetentionPolicy; 28 29 /** 30 * Interface for the biometric dialog UI. 31 */ 32 public interface AuthDialog { 33 34 String KEY_CONTAINER_STATE = "container_state"; 35 String KEY_BIOMETRIC_SHOWING = "biometric_showing"; 36 String KEY_CREDENTIAL_SHOWING = "credential_showing"; 37 38 String KEY_BIOMETRIC_CONFIRM_VISIBILITY = "confirm_visibility"; 39 String KEY_BIOMETRIC_TRY_AGAIN_VISIBILITY = "try_agian_visibility"; 40 String KEY_BIOMETRIC_STATE = "state"; 41 String KEY_BIOMETRIC_INDICATOR_STRING = "indicator_string"; // error / help / hint 42 String KEY_BIOMETRIC_INDICATOR_ERROR_SHOWING = "error_is_temporary"; 43 String KEY_BIOMETRIC_INDICATOR_HELP_SHOWING = "hint_is_temporary"; 44 String KEY_BIOMETRIC_DIALOG_SIZE = "size"; 45 46 String KEY_BIOMETRIC_SENSOR_TYPE = "sensor_type"; 47 String KEY_BIOMETRIC_SENSOR_PROPS = "sensor_props"; 48 49 int SIZE_UNKNOWN = 0; 50 /** 51 * Minimal UI, showing only biometric icon. 52 */ 53 int SIZE_SMALL = 1; 54 /** 55 * Normal-sized biometric UI, showing title, icon, buttons, etc. 56 */ 57 int SIZE_MEDIUM = 2; 58 /** 59 * Full-screen credential UI. 60 */ 61 int SIZE_LARGE = 3; 62 @Retention(RetentionPolicy.SOURCE) 63 @IntDef({SIZE_UNKNOWN, SIZE_SMALL, SIZE_MEDIUM, SIZE_LARGE}) 64 @interface DialogSize {} 65 66 /** 67 * Parameters used when laying out {@link AuthBiometricView}, its sublclasses, and 68 * {@link AuthPanelController}. 69 */ 70 class LayoutParams { 71 final int mMediumHeight; 72 final int mMediumWidth; 73 LayoutParams(int mediumWidth, int mediumHeight)74 LayoutParams(int mediumWidth, int mediumHeight) { 75 mMediumWidth = mediumWidth; 76 mMediumHeight = mediumHeight; 77 } 78 } 79 80 /** 81 * Animation duration, from small to medium dialog, including back panel, icon translation, etc 82 */ 83 int ANIMATE_SMALL_TO_MEDIUM_DURATION_MS = 150; 84 /** 85 * Animation duration from medium to large dialog, including biometric fade out, back panel, etc 86 */ 87 int ANIMATE_MEDIUM_TO_LARGE_DURATION_MS = 450; 88 /** 89 * Delay before notifying {@link AuthCredentialView} to start animating in. 90 */ 91 int ANIMATE_CREDENTIAL_START_DELAY_MS = ANIMATE_MEDIUM_TO_LARGE_DURATION_MS * 2 / 3; 92 /** 93 * Animation duration when sliding in credential UI 94 */ 95 int ANIMATE_CREDENTIAL_INITIAL_DURATION_MS = 150; 96 97 /** 98 * Show the dialog. 99 * @param wm 100 */ show(WindowManager wm, @Nullable Bundle savedState)101 void show(WindowManager wm, @Nullable Bundle savedState); 102 103 /** 104 * Dismiss the dialog without sending a callback. 105 */ dismissWithoutCallback(boolean animate)106 void dismissWithoutCallback(boolean animate); 107 108 /** 109 * Dismiss the dialog. Animate away. 110 */ dismissFromSystemServer()111 void dismissFromSystemServer(); 112 113 /** 114 * Biometric authenticated. May be pending user confirmation, or completed. 115 */ onAuthenticationSucceeded()116 void onAuthenticationSucceeded(); 117 118 /** 119 * Authentication failed (reject, timeout). Dialog stays showing. 120 * @param modality sensor modality that triggered the error 121 * @param failureReason message 122 */ onAuthenticationFailed(@odality int modality, String failureReason)123 void onAuthenticationFailed(@Modality int modality, String failureReason); 124 125 /** 126 * Authentication rejected, or help message received. 127 * @param modality sensor modality that triggered the help message 128 * @param help message 129 */ onHelp(@odality int modality, String help)130 void onHelp(@Modality int modality, String help); 131 132 /** 133 * Authentication failed. Dialog going away. 134 * @param modality sensor modality that triggered the error 135 * @param error message 136 */ onError(@odality int modality, String error)137 void onError(@Modality int modality, String error); 138 139 /** 140 * Save the current state. 141 * @param outState 142 */ onSaveState(@onNull Bundle outState)143 void onSaveState(@NonNull Bundle outState); 144 145 /** 146 * Get the client's package name 147 */ getOpPackageName()148 String getOpPackageName(); 149 150 /** 151 * Animate to credential UI. Typically called after biometric is locked out. 152 */ animateToCredentialUI()153 void animateToCredentialUI(); 154 155 /** 156 * @return true if device credential is allowed. 157 */ isAllowDeviceCredentials()158 boolean isAllowDeviceCredentials(); 159 160 /** 161 * Called when the device's orientation changed and the dialog may need to do another 162 * layout. This is most relevant to UDFPS since configuration changes are not sent by 163 * the framework in equivalent cases (landscape to reverse landscape) but the dialog 164 * must remain fixed on the physical sensor location. 165 */ onOrientationChanged()166 void onOrientationChanged(); 167 } 168