Debian Codegraph @

core/java/android/hardware/fingerprint/FingerprintSensorPropertiesInternal.java

raw symbols SCIP
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
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 // [email protected] handles lockout in the framework, so the challenge is not
54 // required as it can only be generated/attested/verified by TEE components.
55 // [email protected] 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 */
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
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
100 public int describeContents() {
101 return 0;
102 }
103
104 @Override
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
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 side-FPS
124 * @return true if sensor is side-fps, false otherwise
125 */
126 public boolean isAnySidefpsType() {
127 switch (sensorType) {
128 case TYPE_POWER_BUTTON:
129 return true;
130 default:
131 return false;
132 }
133 }
134
135 /**
136 * Get the default location.
137 *
138 * Use this method when the sensor's relationship to the displays on the device do not
139 * matter.
140 * @return
141 */
142 @NonNull
143 public SensorLocationInternal getLocation() {
144 final SensorLocationInternal location = getLocation("" /* displayId */);
145 return location != null ? location : SensorLocationInternal.DEFAULT;
146 }
147
148 /**
149 * Get the location of a sensor relative to a physical display layout.
150 *
151 * @param displayId stable display id
152 * @return location or null if none is specified
153 */
154 @Nullable
155 public SensorLocationInternal getLocation(String displayId) {
156 for (SensorLocationInternal location : mSensorLocations) {
157 if (location.displayId.equals(displayId)) {
158 return location;
159 }
160 }
161 return null;
162 }
163
164 /**
165 * Gets all locations relative to all supported display layouts.
166 * @return supported locations
167 */
168 @NonNull
169 public List<SensorLocationInternal> getAllLocations() {
170 return mSensorLocations;
171 }
172
173 @Override
174 public String toString() {
175 return "ID: " + sensorId + ", Strength: " + sensorStrength + ", Type: " + sensorType;
176 }
177 }