FingerprintService启动-Android13
- 1、指纹服务启动
- 1.1 rc启动Binder对接指纹厂商TA库
- 1.2 FingerprintService启动
- 1.2.1 SystemServer启动FingerprintService
- 1.2.2 注册Binder服务fingerprint
- 2、获取底层信息
- 2.1 AIDL 对接TA中获取
- 2.2 指纹类型判断
android13-release
1、指纹服务启动
1.1 rc启动Binder对接指纹厂商TA库
android虚拟设备
这里android.hardware.biometrics.fingerprint@2.1-service.rc
,实际现在Android 13
上使用AIDL
调用指纹厂商TA so库
(HIDL转换AIDL了解一下:AOSP > 文档 > 核心主题 > HIDL;对于fwk层实质是一样的,之前只是区分hwBinder域
,这里注册的Binder服务android.hardware.biometrics.fingerprint@2.1::IBiometricsFingerprint/default
)
12-24 09:54:06.228 0 0 I init : Parsing file /vendor/etc/init/android.hardware.biometrics.fingerprint@2.1-service.rc...
12-24 09:54:16.601 511 511 D android.hardware.biometrics.fingerprint@2.1-service: Opening fingerprint hal library...
12-24 09:54:16.616 511 511 D FingerprintHal: ----------------> fingerprint_open ----------------->
12-24 09:54:16.616 511 511 D FingerprintHal: ----------------> set_notify_callback ----------------->
12-24 09:54:16.616 511 511 D FingerprintHal: fingerprint callback notification set
12-24 09:54:16.620 511 526 D FingerprintHal: ----------------> listenerFunction ----------------->
12-24 09:54:16.646 511 511 I HidlServiceManagement: Registered android.hardware.biometrics.fingerprint@2.1::IBiometricsFingerprint/default
12-24 09:54:16.646 511 511 I HidlServiceManagement: Removing namespace from process name android.hardware.biometrics.fingerprint@2.1-service to fingerprint@2.1-service.
1.2 FingerprintService启动
1.2.1 SystemServer启动FingerprintService
12-24 09:54:36.628 606 606 D SystemServerTiming: StartFingerprintSensor
12-24 09:54:36.628 606 606 I SystemServiceManager: Starting com.android.server.biometrics.sensors.fingerprint.FingerprintService
12-24 09:54:36.629 606 606 V SystemServerTiming: StartFingerprintSensor took to complete: 1ms
frameworks/base/services/java/com/android/server/SystemServer.java
if (hasFeatureFingerprint) {t.traceBegin("StartFingerprintSensor");final FingerprintService fingerprintService =mSystemServiceManager.startService(FingerprintService.class);t.traceEnd();
}// Start this service after all biometric sensor services are started.
t.traceBegin("StartBiometricService");
mSystemServiceManager.startService(BiometricService.class);
t.traceEnd();t.traceBegin("StartAuthService");
mSystemServiceManager.startService(AuthService.class);
t.traceEnd();
1.2.2 注册Binder服务fingerprint
接收来自FingerprintManager的调用
frameworks/base/services/core/java/com/android/server/biometrics/sensors/fingerprint/FingerprintService.java
public FingerprintService(Context context) {super(context);mServiceWrapper = new FingerprintServiceWrapper();mAppOps = context.getSystemService(AppOpsManager.class);mGestureAvailabilityDispatcher = new GestureAvailabilityDispatcher();mLockoutResetDispatcher = new LockoutResetDispatcher(context);mLockPatternUtils = new LockPatternUtils(context);mServiceProviders = new ArrayList<>();mBiometricStateCallback = new BiometricStateCallback();mAuthenticatorsRegisteredCallbacks = new RemoteCallbackList<>();mSensorProps = new ArrayList<>();mHandler = new Handler(Looper.getMainLooper());}@Overridepublic void onStart() {publishBinderService(Context.FINGERPRINT_SERVICE, mServiceWrapper);}
2、获取底层信息
实际获取在
AuthService
服务调用fingerprintService.registerAuthenticators(hidlFingerprintSensors);
frameworks/base/services/core/java/com/android/server/biometrics/AuthService.java
/*** Registration of all HIDL and AIDL biometric HALs starts here.* The flow looks like this:* AuthService* └── .onStart()* └── .registerAuthenticators(...)* ├── FaceService.registerAuthenticators(...)* │ └── for (p : serviceProviders)* │ └── for (s : p.sensors)* │ └── BiometricService.registerAuthenticator(s)* │* ├── FingerprintService.registerAuthenticators(...)* │ └── for (p : serviceProviders)* │ └── for (s : p.sensors)* │ └── BiometricService.registerAuthenticator(s)* │* └── IrisService.registerAuthenticators(...)* └── for (p : serviceProviders)* └── for (s : p.sensors)* └── BiometricService.registerAuthenticator(s)*/@Overridepublic void onStart() {mBiometricService = mInjector.getBiometricService();final SensorConfig[] hidlConfigs;if (!mInjector.isHidlDisabled(getContext())) {final int firstApiLevel = SystemProperties.getInt(SYSPROP_FIRST_API_LEVEL, 0);final int apiLevel = SystemProperties.getInt(SYSPROP_API_LEVEL, firstApiLevel);String[] configStrings = mInjector.getConfiguration(getContext());if (configStrings.length == 0 && apiLevel == Build.VERSION_CODES.R) {// For backwards compatibility with R where biometrics could work without being// configured in config_biometric_sensors. In the absence of a vendor provided// configuration, we assume the weakest biometric strength (i.e. convenience).Slog.w(TAG, "Found R vendor partition without config_biometric_sensors");configStrings = generateRSdkCompatibleConfiguration();}hidlConfigs = new SensorConfig[configStrings.length];for (int i = 0; i < configStrings.length; ++i) {hidlConfigs[i] = new SensorConfig(configStrings[i]);}} else {hidlConfigs = null;}// Registers HIDL and AIDL authenticators, but only HIDL configs need to be provided.registerAuthenticators(hidlConfigs);mInjector.publishBinderService(this, mImpl);}
下面日志是之前的HAIL:
12-24 09:54:36.650 606 606 D AuthService: Registering HIDL ID: 0 Modality: 2 Strength: 15
12-24 09:55:05.131 606 1740 D Fingerprint21: Daemon was null, reconnecting, current operation: null
12-24 09:55:05.186 606 1740 D Fingerprint21: Fingerprint HAL ready, HAL ID: 132452338342080
12-24 11:05:23.563 606 606 D Fingerprint21: handleError, client: FingerprintEnrollClient, error: 5, vendorCode: 0
2.1 AIDL 对接TA中获取
addAidlProviders()
获取TA信息,fp.getSensorProps()
现在指纹类型
和显示位置
从HAL中获取,转化成FingerprintSensorPropertiesInternal
private void addAidlProviders() {final String[] instances = ServiceManager.getDeclaredInstances(IFingerprint.DESCRIPTOR);if (instances == null || instances.length == 0) {return;}for (String instance : instances) {final String fqName = IFingerprint.DESCRIPTOR + "/" + instance;final IFingerprint fp = IFingerprint.Stub.asInterface(Binder.allowBlocking(ServiceManager.waitForDeclaredService(fqName)));if (fp == null) {Slog.e(TAG, "Unable to get declared service: " + fqName);continue;}try {final SensorProps[] props = fp.getSensorProps();final FingerprintProvider provider =new FingerprintProvider(getContext(), mBiometricStateCallback, props,instance, mLockoutResetDispatcher,mGestureAvailabilityDispatcher,BiometricContext.getInstance(getContext()));mServiceProviders.add(provider);} catch (RemoteException e) {Slog.e(TAG, "Remote exception in getSensorProps: " + fqName);}}
}@Override // Binder call
public void registerAuthenticators(@NonNull List<FingerprintSensorPropertiesInternal> hidlSensors) {Utils.checkPermission(getContext(), USE_BIOMETRIC_INTERNAL);// Some HAL might not be started before the system service and will cause the code below// to wait, and some of the operations below might take a significant amount of time to// complete (calls to the HALs). To avoid blocking the rest of system server we put// this on a background thread.final ServiceThread thread = new ServiceThread(TAG, Process.THREAD_PRIORITY_BACKGROUND,true /* allowIo */);thread.start();final Handler handler = new Handler(thread.getLooper());handler.post(() -> {addHidlProviders(hidlSensors);addAidlProviders();final IBiometricService biometricService = IBiometricService.Stub.asInterface(ServiceManager.getService(Context.BIOMETRIC_SERVICE));// Register each sensor individually with BiometricServicefor (ServiceProvider provider : mServiceProviders) {final List<FingerprintSensorPropertiesInternal> props =provider.getSensorProperties();for (FingerprintSensorPropertiesInternal prop : props) {final int sensorId = prop.sensorId;final @BiometricManager.Authenticators.Types int strength =Utils.propertyStrengthToAuthenticatorStrength(prop.sensorStrength);final FingerprintAuthenticator authenticator = new FingerprintAuthenticator(mServiceWrapper, sensorId);try {biometricService.registerAuthenticator(sensorId, TYPE_FINGERPRINT,strength, authenticator);} catch (RemoteException e) {Slog.e(TAG, "Remote exception when registering sensorId: " + sensorId);}}}synchronized (mLock) {for (ServiceProvider provider : mServiceProviders) {mSensorProps.addAll(provider.getSensorProperties());}}broadcastCurrentEnrollmentState(null); // broadcasts to all listenersbroadcastAllAuthenticatorsRegistered();});
}
2.2 指纹类型判断
- 指纹类型:屏下指纹(
TYPE_UDFPS_OPTICAL、TYPE_UDFPS_ULTRASONIC
)、侧边指纹(TYPE_POWER_BUTTON
)- 屏下指纹和侧边指纹判断:
isAnyUdfpsType
、isAnySidefpsType
- 日志查看:
FingerprintProvider.*Added: ID
frameworks/base/services/core/java/com/android/server/biometrics/sensors/fingerprint/aidl/FingerprintProvider.java
- 类型对照
frameworks/base/core/java/android/hardware/fingerprint/FingerprintSensorProperties.java
/*** @hide*/public static final int TYPE_UNKNOWN = 0;/*** @hide*/public static final int TYPE_REAR = 1;/*** @hide*/public static final int TYPE_UDFPS_ULTRASONIC = 2;/*** @hide*/public static final int TYPE_UDFPS_OPTICAL = 3;/*** @hide*/public static final int TYPE_POWER_BUTTON = 4;/*** @hide*/public static final int TYPE_HOME_BUTTON = 5;/*** @hide*/@IntDef({TYPE_UNKNOWN,TYPE_REAR,TYPE_UDFPS_ULTRASONIC,TYPE_UDFPS_OPTICAL,TYPE_POWER_BUTTON,TYPE_HOME_BUTTON})@Retention(RetentionPolicy.SOURCE)public @interface SensorType {}
- 屏下指纹和侧边指纹判断
hardware/interfaces/biometrics/fingerprint/aidl/android/hardware/biometrics/fingerprint/FingerprintSensorType.aidl
package android.hardware.biometrics.fingerprint;@VintfStability
@Backing(type="byte")
enum FingerprintSensorType {UNKNOWN,REAR,UNDER_DISPLAY_ULTRASONIC,UNDER_DISPLAY_OPTICAL,POWER_BUTTON,HOME_BUTTON
}
public boolean isAnyUdfpsType() {switch (sensorType) {case TYPE_UDFPS_OPTICAL:case TYPE_UDFPS_ULTRASONIC:return true;default:return false;}}/*** Returns if sensor type is side-FPS* @return true if sensor is side-fps, false otherwise*/public boolean isAnySidefpsType() {switch (sensorType) {case TYPE_POWER_BUTTON:return true;default:return false;}}