1 /* 2 * Copyright (C) 2020 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 android.hardware.biometrics; 18 19 import android.annotation.NonNull; 20 import android.annotation.Nullable; 21 import android.os.Parcel; 22 import android.os.Parcelable; 23 24 import java.util.ArrayList; 25 import java.util.List; 26 27 /** 28 * Contains the information set/requested by the caller of the {@link BiometricPrompt} 29 * @hide 30 */ 31 public class PromptInfo implements Parcelable { 32 33 @NonNull private CharSequence mTitle; 34 private boolean mUseDefaultTitle; 35 @Nullable private CharSequence mSubtitle; 36 @Nullable private CharSequence mDescription; 37 @Nullable private CharSequence mDeviceCredentialTitle; 38 @Nullable private CharSequence mDeviceCredentialSubtitle; 39 @Nullable private CharSequence mDeviceCredentialDescription; 40 @Nullable private CharSequence mNegativeButtonText; 41 private boolean mConfirmationRequested = true; // default to true 42 private boolean mDeviceCredentialAllowed; 43 private @BiometricManager.Authenticators.Types int mAuthenticators; 44 private boolean mDisallowBiometricsIfPolicyExists; 45 private boolean mReceiveSystemEvents; 46 @NonNull private List<Integer> mAllowedSensorIds = new ArrayList<>(); 47 private boolean mAllowBackgroundAuthentication; 48 private boolean mIgnoreEnrollmentState; 49 PromptInfo()50 public PromptInfo() { 51 52 } 53 PromptInfo(Parcel in)54 PromptInfo(Parcel in) { 55 mTitle = in.readCharSequence(); 56 mUseDefaultTitle = in.readBoolean(); 57 mSubtitle = in.readCharSequence(); 58 mDescription = in.readCharSequence(); 59 mDeviceCredentialTitle = in.readCharSequence(); 60 mDeviceCredentialSubtitle = in.readCharSequence(); 61 mDeviceCredentialDescription = in.readCharSequence(); 62 mNegativeButtonText = in.readCharSequence(); 63 mConfirmationRequested = in.readBoolean(); 64 mDeviceCredentialAllowed = in.readBoolean(); 65 mAuthenticators = in.readInt(); 66 mDisallowBiometricsIfPolicyExists = in.readBoolean(); 67 mReceiveSystemEvents = in.readBoolean(); 68 mAllowedSensorIds = in.readArrayList(Integer.class.getClassLoader()); 69 mAllowBackgroundAuthentication = in.readBoolean(); 70 mIgnoreEnrollmentState = in.readBoolean(); 71 } 72 73 public static final Creator<PromptInfo> CREATOR = new Creator<PromptInfo>() { 74 @Override 75 public PromptInfo createFromParcel(Parcel in) { 76 return new PromptInfo(in); 77 } 78 79 @Override 80 public PromptInfo[] newArray(int size) { 81 return new PromptInfo[size]; 82 } 83 }; 84 85 @Override describeContents()86 public int describeContents() { 87 return 0; 88 } 89 90 @Override writeToParcel(Parcel dest, int flags)91 public void writeToParcel(Parcel dest, int flags) { 92 dest.writeCharSequence(mTitle); 93 dest.writeBoolean(mUseDefaultTitle); 94 dest.writeCharSequence(mSubtitle); 95 dest.writeCharSequence(mDescription); 96 dest.writeCharSequence(mDeviceCredentialTitle); 97 dest.writeCharSequence(mDeviceCredentialSubtitle); 98 dest.writeCharSequence(mDeviceCredentialDescription); 99 dest.writeCharSequence(mNegativeButtonText); 100 dest.writeBoolean(mConfirmationRequested); 101 dest.writeBoolean(mDeviceCredentialAllowed); 102 dest.writeInt(mAuthenticators); 103 dest.writeBoolean(mDisallowBiometricsIfPolicyExists); 104 dest.writeBoolean(mReceiveSystemEvents); 105 dest.writeList(mAllowedSensorIds); 106 dest.writeBoolean(mAllowBackgroundAuthentication); 107 dest.writeBoolean(mIgnoreEnrollmentState); 108 } 109 containsTestConfigurations()110 public boolean containsTestConfigurations() { 111 if (!mAllowedSensorIds.isEmpty()) { 112 return true; 113 } else if (mAllowBackgroundAuthentication) { 114 return true; 115 } 116 return false; 117 } 118 containsPrivateApiConfigurations()119 public boolean containsPrivateApiConfigurations() { 120 if (mDisallowBiometricsIfPolicyExists) { 121 return true; 122 } else if (mUseDefaultTitle) { 123 return true; 124 } else if (mDeviceCredentialTitle != null) { 125 return true; 126 } else if (mDeviceCredentialSubtitle != null) { 127 return true; 128 } else if (mDeviceCredentialDescription != null) { 129 return true; 130 } else if (mReceiveSystemEvents) { 131 return true; 132 } 133 return false; 134 } 135 136 // Setters 137 setTitle(CharSequence title)138 public void setTitle(CharSequence title) { 139 mTitle = title; 140 } 141 setUseDefaultTitle(boolean useDefaultTitle)142 public void setUseDefaultTitle(boolean useDefaultTitle) { 143 mUseDefaultTitle = useDefaultTitle; 144 } 145 setSubtitle(CharSequence subtitle)146 public void setSubtitle(CharSequence subtitle) { 147 mSubtitle = subtitle; 148 } 149 setDescription(CharSequence description)150 public void setDescription(CharSequence description) { 151 mDescription = description; 152 } 153 setDeviceCredentialTitle(CharSequence deviceCredentialTitle)154 public void setDeviceCredentialTitle(CharSequence deviceCredentialTitle) { 155 mDeviceCredentialTitle = deviceCredentialTitle; 156 } 157 setDeviceCredentialSubtitle(CharSequence deviceCredentialSubtitle)158 public void setDeviceCredentialSubtitle(CharSequence deviceCredentialSubtitle) { 159 mDeviceCredentialSubtitle = deviceCredentialSubtitle; 160 } 161 setDeviceCredentialDescription(CharSequence deviceCredentialDescription)162 public void setDeviceCredentialDescription(CharSequence deviceCredentialDescription) { 163 mDeviceCredentialDescription = deviceCredentialDescription; 164 } 165 setNegativeButtonText(CharSequence negativeButtonText)166 public void setNegativeButtonText(CharSequence negativeButtonText) { 167 mNegativeButtonText = negativeButtonText; 168 } 169 setConfirmationRequested(boolean confirmationRequested)170 public void setConfirmationRequested(boolean confirmationRequested) { 171 mConfirmationRequested = confirmationRequested; 172 } 173 setDeviceCredentialAllowed(boolean deviceCredentialAllowed)174 public void setDeviceCredentialAllowed(boolean deviceCredentialAllowed) { 175 mDeviceCredentialAllowed = deviceCredentialAllowed; 176 } 177 setAuthenticators(int authenticators)178 public void setAuthenticators(int authenticators) { 179 mAuthenticators = authenticators; 180 } 181 setDisallowBiometricsIfPolicyExists(boolean disallowBiometricsIfPolicyExists)182 public void setDisallowBiometricsIfPolicyExists(boolean disallowBiometricsIfPolicyExists) { 183 mDisallowBiometricsIfPolicyExists = disallowBiometricsIfPolicyExists; 184 } 185 setReceiveSystemEvents(boolean receiveSystemEvents)186 public void setReceiveSystemEvents(boolean receiveSystemEvents) { 187 mReceiveSystemEvents = receiveSystemEvents; 188 } 189 setAllowedSensorIds(@onNull List<Integer> sensorIds)190 public void setAllowedSensorIds(@NonNull List<Integer> sensorIds) { 191 mAllowedSensorIds = sensorIds; 192 } 193 setAllowBackgroundAuthentication(boolean allow)194 public void setAllowBackgroundAuthentication(boolean allow) { 195 mAllowBackgroundAuthentication = allow; 196 } 197 setIgnoreEnrollmentState(boolean ignoreEnrollmentState)198 public void setIgnoreEnrollmentState(boolean ignoreEnrollmentState) { 199 mIgnoreEnrollmentState = ignoreEnrollmentState; 200 } 201 202 // Getters 203 getTitle()204 public CharSequence getTitle() { 205 return mTitle; 206 } 207 isUseDefaultTitle()208 public boolean isUseDefaultTitle() { 209 return mUseDefaultTitle; 210 } 211 getSubtitle()212 public CharSequence getSubtitle() { 213 return mSubtitle; 214 } 215 getDescription()216 public CharSequence getDescription() { 217 return mDescription; 218 } 219 getDeviceCredentialTitle()220 public CharSequence getDeviceCredentialTitle() { 221 return mDeviceCredentialTitle; 222 } 223 getDeviceCredentialSubtitle()224 public CharSequence getDeviceCredentialSubtitle() { 225 return mDeviceCredentialSubtitle; 226 } 227 getDeviceCredentialDescription()228 public CharSequence getDeviceCredentialDescription() { 229 return mDeviceCredentialDescription; 230 } 231 getNegativeButtonText()232 public CharSequence getNegativeButtonText() { 233 return mNegativeButtonText; 234 } 235 isConfirmationRequested()236 public boolean isConfirmationRequested() { 237 return mConfirmationRequested; 238 } 239 240 /** 241 * This value is read once by {@link com.android.server.biometrics.BiometricService} and 242 * combined into {@link #getAuthenticators()}. 243 * @deprecated 244 * @return 245 */ 246 @Deprecated isDeviceCredentialAllowed()247 public boolean isDeviceCredentialAllowed() { 248 return mDeviceCredentialAllowed; 249 } 250 getAuthenticators()251 public int getAuthenticators() { 252 return mAuthenticators; 253 } 254 isDisallowBiometricsIfPolicyExists()255 public boolean isDisallowBiometricsIfPolicyExists() { 256 return mDisallowBiometricsIfPolicyExists; 257 } 258 isReceiveSystemEvents()259 public boolean isReceiveSystemEvents() { 260 return mReceiveSystemEvents; 261 } 262 263 @NonNull getAllowedSensorIds()264 public List<Integer> getAllowedSensorIds() { 265 return mAllowedSensorIds; 266 } 267 isAllowBackgroundAuthentication()268 public boolean isAllowBackgroundAuthentication() { 269 return mAllowBackgroundAuthentication; 270 } 271 isIgnoreEnrollmentState()272 public boolean isIgnoreEnrollmentState() { 273 return mIgnoreEnrollmentState; 274 } 275 } 276