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