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 */ isUltrasonicUdfps()125 public boolean isUltrasonicUdfps() { 126 return sensorType == TYPE_UDFPS_ULTRASONIC; 127 } 128 129 /** 130 * Returns if sensor type is optical Udfps 131 */ isOpticalUdfps()132 public boolean isOpticalUdfps() { 133 return sensorType == TYPE_UDFPS_OPTICAL; 134 } 135 136 /** 137 * Returns if sensor type is side-FPS 138 */ isAnySidefpsType()139 public boolean isAnySidefpsType() { 140 switch (sensorType) { 141 case TYPE_POWER_BUTTON: 142 return true; 143 default: 144 return false; 145 } 146 } 147 148 /** 149 * Get the default location. 150 * 151 * Use this method when the sensor's relationship to the displays on the device do not 152 * matter. 153 * @return 154 */ 155 @NonNull getLocation()156 public SensorLocationInternal getLocation() { 157 final SensorLocationInternal location = getLocation("" /* displayId */); 158 return location != null ? location : SensorLocationInternal.DEFAULT; 159 } 160 161 /** 162 * Get the location of a sensor relative to a physical display layout. 163 * 164 * @param displayId stable display id 165 * @return location or null if none is specified 166 */ 167 @Nullable getLocation(String displayId)168 public SensorLocationInternal getLocation(String displayId) { 169 for (SensorLocationInternal location : mSensorLocations) { 170 if (location.displayId.equals(displayId)) { 171 return location; 172 } 173 } 174 return null; 175 } 176 177 /** 178 * Gets all locations relative to all supported display layouts. 179 * @return supported locations 180 */ 181 @NonNull getAllLocations()182 public List<SensorLocationInternal> getAllLocations() { 183 return mSensorLocations; 184 } 185 186 @Override toString()187 public String toString() { 188 return "ID: " + sensorId + ", Strength: " + sensorStrength + ", Type: " + sensorType; 189 } 190 } 191