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