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