• 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.IntDef;
20 import android.annotation.NonNull;
21 import android.annotation.TestApi;
22 
23 import java.lang.annotation.Retention;
24 import java.lang.annotation.RetentionPolicy;
25 import java.util.ArrayList;
26 import java.util.List;
27 
28 /**
29  * The base class containing all modality-agnostic information.
30  * @hide
31  */
32 @TestApi
33 public class SensorProperties {
34     /**
35      * A sensor that meets the requirements for Class 1 biometrics as defined in the CDD. This does
36      * not correspond to a public BiometricManager.Authenticators constant. Sensors of this strength
37      * are not available to applications via the public API surface.
38      */
39     public static final int STRENGTH_CONVENIENCE = 0;
40 
41     /**
42      * A sensor that meets the requirements for Class 2 biometrics as defined in the CDD.
43      * Corresponds to BiometricManager.Authenticators.BIOMETRIC_WEAK.
44      */
45     public static final int STRENGTH_WEAK = 1;
46 
47     /**
48      * A sensor that meets the requirements for Class 3 biometrics as defined in the CDD.
49      * Corresponds to BiometricManager.Authenticators.BIOMETRIC_STRONG.
50      *
51      * Notably, this is the only strength that allows generation of HardwareAuthToken(s).
52      */
53     public static final int STRENGTH_STRONG = 2;
54 
55     /**
56      * @hide
57      */
58     @IntDef({STRENGTH_CONVENIENCE, STRENGTH_WEAK, STRENGTH_STRONG})
59     @Retention(RetentionPolicy.SOURCE)
60     public @interface Strength {}
61 
62     /**
63      * A class storing the component info for a subsystem of the sensor.
64      */
65     public static final class ComponentInfo {
66         @NonNull private final String mComponentId;
67         @NonNull private final String mHardwareVersion;
68         @NonNull private final String mFirmwareVersion;
69         @NonNull private final String mSerialNumber;
70         @NonNull private final String mSoftwareVersion;
71 
72         /**
73          * @hide
74          */
ComponentInfo(@onNull String componentId, @NonNull String hardwareVersion, @NonNull String firmwareVersion, @NonNull String serialNumber, @NonNull String softwareVersion)75         public ComponentInfo(@NonNull String componentId, @NonNull String hardwareVersion,
76                 @NonNull String firmwareVersion, @NonNull String serialNumber,
77                 @NonNull String softwareVersion) {
78             mComponentId = componentId;
79             mHardwareVersion = hardwareVersion;
80             mFirmwareVersion = firmwareVersion;
81             mSerialNumber = serialNumber;
82             mSoftwareVersion = softwareVersion;
83         }
84 
85         /**
86          * @return The unique identifier for the subsystem.
87          */
88         @NonNull
getComponentId()89         public String getComponentId() {
90             return mComponentId;
91         }
92 
93         /**
94          * @return The hardware version for the subsystem. For example, <vendor>/<model>/<revision>.
95          */
96         @NonNull
getHardwareVersion()97         public String getHardwareVersion() {
98             return mHardwareVersion;
99         }
100 
101         /**
102          * @return The firmware version for the subsystem.
103          */
104         @NonNull
getFirmwareVersion()105         public String getFirmwareVersion() {
106             return mFirmwareVersion;
107         }
108 
109         /**
110          * @return The serial number for the subsystem.
111          */
112         @NonNull
getSerialNumber()113         public String getSerialNumber() {
114             return mSerialNumber;
115         }
116 
117         /**
118          * @return The software version for the subsystem.
119          * For example, <vendor>/<version>/<revision>.
120          */
121         @NonNull
getSoftwareVersion()122         public String getSoftwareVersion() {
123             return mSoftwareVersion;
124         }
125 
126         /**
127          * Constructs a {@link ComponentInfo} from the internal parcelable representation.
128          * @hide
129          */
from(ComponentInfoInternal internalComp)130         public static ComponentInfo from(ComponentInfoInternal internalComp) {
131             return new ComponentInfo(internalComp.componentId, internalComp.hardwareVersion,
132                     internalComp.firmwareVersion, internalComp.serialNumber,
133                     internalComp.softwareVersion);
134         }
135     }
136 
137     private final int mSensorId;
138     @Strength private final int mSensorStrength;
139     private final List<ComponentInfo> mComponentInfo;
140 
141     /**
142      * @hide
143      */
SensorProperties(int sensorId, @Strength int sensorStrength, List<ComponentInfo> componentInfo)144     public SensorProperties(int sensorId, @Strength int sensorStrength,
145             List<ComponentInfo> componentInfo) {
146         mSensorId = sensorId;
147         mSensorStrength = sensorStrength;
148         mComponentInfo = componentInfo;
149     }
150 
151     /**
152      * @return The sensor's unique identifier.
153      */
getSensorId()154     public int getSensorId() {
155         return mSensorId;
156     }
157 
158     /**
159      * @return The sensor's strength.
160      */
161     @Strength
getSensorStrength()162     public int getSensorStrength() {
163         return mSensorStrength;
164     }
165 
166     /**
167      * @return The sensor's component info.
168      */
169     @NonNull
getComponentInfo()170     public List<ComponentInfo> getComponentInfo() {
171         return mComponentInfo;
172     }
173 
174     /**
175      * Constructs a {@link SensorProperties} from the internal parcelable representation.
176      * @hide
177      */
from(SensorPropertiesInternal internalProp)178     public static SensorProperties from(SensorPropertiesInternal internalProp) {
179         final List<ComponentInfo> componentInfo = new ArrayList<>();
180         for (ComponentInfoInternal internalComp : internalProp.componentInfo) {
181             componentInfo.add(ComponentInfo.from(internalComp));
182         }
183         return new SensorProperties(internalProp.sensorId, internalProp.sensorStrength,
184                 componentInfo);
185     }
186 }
187