1 /* 2 * Copyright (C) 2023 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.face; 18 19 import android.annotation.NonNull; 20 import android.content.Context; 21 import android.hardware.biometrics.BiometricAuthenticator; 22 import android.hardware.biometrics.BiometricManager; 23 import android.hardware.biometrics.common.CommonProps; 24 import android.hardware.biometrics.common.SensorStrength; 25 import android.hardware.biometrics.face.SensorProps; 26 27 import com.android.internal.R; 28 29 /** 30 * Parse HIDL face sensor config and map it to SensorProps.aidl to match AIDL. 31 * See core/res/res/values/config.xml config_biometric_sensors 32 * @hide 33 */ 34 public final class HidlFaceSensorConfig extends SensorProps { 35 private int mSensorId; 36 private int mModality; 37 private int mStrength; 38 39 /** 40 * Parse through the config string and map it to SensorProps.aidl. 41 * @throws IllegalArgumentException when config string has unexpected format 42 */ parse(@onNull String config, @NonNull Context context)43 public void parse(@NonNull String config, @NonNull Context context) 44 throws IllegalArgumentException { 45 final String[] elems = config.split(":"); 46 if (elems.length < 3) { 47 throw new IllegalArgumentException(); 48 } 49 mSensorId = Integer.parseInt(elems[0]); 50 mModality = Integer.parseInt(elems[1]); 51 mStrength = Integer.parseInt(elems[2]); 52 mapHidlToAidlFaceSensorConfigurations(context); 53 } 54 55 @BiometricAuthenticator.Modality getModality()56 public int getModality() { 57 return mModality; 58 } 59 mapHidlToAidlFaceSensorConfigurations(@onNull Context context)60 private void mapHidlToAidlFaceSensorConfigurations(@NonNull Context context) { 61 commonProps = new CommonProps(); 62 commonProps.sensorId = mSensorId; 63 commonProps.sensorStrength = authenticatorStrengthToPropertyStrength(mStrength); 64 halControlsPreview = context.getResources().getBoolean( 65 R.bool.config_faceAuthSupportsSelfIllumination); 66 commonProps.maxEnrollmentsPerUser = context.getResources().getInteger( 67 R.integer.config_faceMaxTemplatesPerUser); 68 commonProps.componentInfo = null; 69 supportsDetectInteraction = false; 70 } 71 authenticatorStrengthToPropertyStrength( @iometricManager.Authenticators.Types int strength)72 private byte authenticatorStrengthToPropertyStrength( 73 @BiometricManager.Authenticators.Types int strength) { 74 switch (strength) { 75 case BiometricManager.Authenticators.BIOMETRIC_CONVENIENCE: 76 return SensorStrength.CONVENIENCE; 77 case BiometricManager.Authenticators.BIOMETRIC_WEAK: 78 return SensorStrength.WEAK; 79 case BiometricManager.Authenticators.BIOMETRIC_STRONG: 80 return SensorStrength.STRONG; 81 default: 82 throw new IllegalArgumentException("Unknown strength: " + strength); 83 } 84 } 85 } 86