• 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.fingerprint;
18 
19 import static android.hardware.fingerprint.FingerprintSensorProperties.TYPE_POWER_BUTTON;
20 import static android.hardware.fingerprint.FingerprintSensorProperties.TYPE_UDFPS_OPTICAL;
21 import static android.hardware.fingerprint.FingerprintSensorProperties.TYPE_UDFPS_ULTRASONIC;
22 
23 import android.annotation.NonNull;
24 import android.annotation.Nullable;
25 import android.hardware.biometrics.ComponentInfoInternal;
26 import android.hardware.biometrics.SensorLocationInternal;
27 import android.hardware.biometrics.SensorProperties;
28 import android.hardware.biometrics.SensorPropertiesInternal;
29 import android.os.Parcel;
30 
31 import java.util.List;
32 
33 /**
34  * Container for fingerprint sensor properties.
35  * @hide
36  */
37 public class FingerprintSensorPropertiesInternal extends SensorPropertiesInternal {
38     /**
39      * See {@link FingerprintSensorProperties.SensorType}.
40      */
41     public final @FingerprintSensorProperties.SensorType int sensorType;
42     public final boolean halControlsIllumination;
43 
44     private final List<SensorLocationInternal> mSensorLocations;
45 
FingerprintSensorPropertiesInternal(int sensorId, @SensorProperties.Strength int strength, int maxEnrollmentsPerUser, @NonNull List<ComponentInfoInternal> componentInfo, @FingerprintSensorProperties.SensorType int sensorType, boolean halControlsIllumination, boolean resetLockoutRequiresHardwareAuthToken, @NonNull List<SensorLocationInternal> sensorLocations)46     public FingerprintSensorPropertiesInternal(int sensorId,
47             @SensorProperties.Strength int strength, int maxEnrollmentsPerUser,
48             @NonNull List<ComponentInfoInternal> componentInfo,
49             @FingerprintSensorProperties.SensorType int sensorType,
50             boolean halControlsIllumination,
51             boolean resetLockoutRequiresHardwareAuthToken,
52             @NonNull List<SensorLocationInternal> sensorLocations) {
53         // IBiometricsFingerprint@2.1 handles lockout in the framework, so the challenge is not
54         // required as it can only be generated/attested/verified by TEE components.
55         // IFingerprint@1.0 handles lockout below the HAL, but does not require a challenge. See
56         // the HAL interface for more details.
57         super(sensorId, strength, maxEnrollmentsPerUser, componentInfo,
58             resetLockoutRequiresHardwareAuthToken, false /* resetLockoutRequiresChallenge */);
59         this.sensorType = sensorType;
60         this.halControlsIllumination = halControlsIllumination;
61         this.mSensorLocations = List.copyOf(sensorLocations);
62     }
63 
64     /**
65      * Initializes SensorProperties with specified values
66      */
FingerprintSensorPropertiesInternal(int sensorId, @SensorProperties.Strength int strength, int maxEnrollmentsPerUser, @NonNull List<ComponentInfoInternal> componentInfo, @FingerprintSensorProperties.SensorType int sensorType, boolean resetLockoutRequiresHardwareAuthToken)67     public FingerprintSensorPropertiesInternal(int sensorId,
68             @SensorProperties.Strength int strength, int maxEnrollmentsPerUser,
69             @NonNull List<ComponentInfoInternal> componentInfo,
70             @FingerprintSensorProperties.SensorType int sensorType,
71             boolean resetLockoutRequiresHardwareAuthToken) {
72         // TODO(b/179175438): Value should be provided from the HAL
73         this(sensorId, strength, maxEnrollmentsPerUser, componentInfo, sensorType,
74                 false /* halControlsIllumination */, resetLockoutRequiresHardwareAuthToken,
75                 List.of(new SensorLocationInternal("" /* displayId */, 540 /* sensorLocationX */,
76                         1636 /* sensorLocationY */, 130 /* sensorRadius */)));
77     }
78 
FingerprintSensorPropertiesInternal(Parcel in)79     protected FingerprintSensorPropertiesInternal(Parcel in) {
80         super(in);
81         sensorType = in.readInt();
82         halControlsIllumination = in.readBoolean();
83         mSensorLocations = in.createTypedArrayList(SensorLocationInternal.CREATOR);
84     }
85 
86     public static final Creator<FingerprintSensorPropertiesInternal> CREATOR =
87             new Creator<FingerprintSensorPropertiesInternal>() {
88                 @Override
89                 public FingerprintSensorPropertiesInternal createFromParcel(Parcel in) {
90                     return new FingerprintSensorPropertiesInternal(in);
91                 }
92 
93                 @Override
94                 public FingerprintSensorPropertiesInternal[] newArray(int size) {
95                     return new FingerprintSensorPropertiesInternal[size];
96                 }
97             };
98 
99     @Override
describeContents()100     public int describeContents() {
101         return 0;
102     }
103 
104     @Override
writeToParcel(Parcel dest, int flags)105     public void writeToParcel(Parcel dest, int flags) {
106         super.writeToParcel(dest, flags);
107         dest.writeInt(sensorType);
108         dest.writeBoolean(halControlsIllumination);
109         dest.writeTypedList(mSensorLocations);
110     }
111 
isAnyUdfpsType()112     public boolean isAnyUdfpsType() {
113         switch (sensorType) {
114             case TYPE_UDFPS_OPTICAL:
115             case TYPE_UDFPS_ULTRASONIC:
116                 return true;
117             default:
118                 return false;
119         }
120     }
121 
122     /**
123      * Returns if sensor type is ultrasonic Udfps
124      * @return true if sensor is ultrasonic Udfps, false otherwise
125      */
isUltrasonicUdfps()126     public boolean isUltrasonicUdfps() {
127         return sensorType == TYPE_UDFPS_ULTRASONIC;
128     }
129 
130     /**
131      * Returns if sensor type is side-FPS
132      * @return true if sensor is side-fps, false otherwise
133      */
isAnySidefpsType()134     public boolean isAnySidefpsType() {
135         switch (sensorType) {
136             case TYPE_POWER_BUTTON:
137                 return true;
138             default:
139                 return false;
140         }
141     }
142 
143     /**
144      * Get the default location.
145      *
146      * Use this method when the sensor's relationship to the displays on the device do not
147      * matter.
148      * @return
149      */
150     @NonNull
getLocation()151     public SensorLocationInternal getLocation() {
152         final SensorLocationInternal location = getLocation("" /* displayId */);
153         return location != null ? location : SensorLocationInternal.DEFAULT;
154     }
155 
156     /**
157      * Get the location of a sensor relative to a physical display layout.
158      *
159      * @param displayId stable display id
160      * @return location or null if none is specified
161      */
162     @Nullable
getLocation(String displayId)163     public SensorLocationInternal getLocation(String displayId) {
164         for (SensorLocationInternal location : mSensorLocations) {
165             if (location.displayId.equals(displayId)) {
166                 return location;
167             }
168         }
169         return null;
170     }
171 
172     /**
173      * Gets all locations relative to all supported display layouts.
174      * @return supported locations
175      */
176     @NonNull
getAllLocations()177     public List<SensorLocationInternal> getAllLocations() {
178         return mSensorLocations;
179     }
180 
181     @Override
toString()182     public String toString() {
183         return "ID: " + sensorId + ", Strength: " + sensorStrength + ", Type: " + sensorType;
184     }
185 }
186