sm8250-common: biometrics: Implement custom HAL loading list

Change-Id: Id545287bed468f39738dbaa4c069660047055585
This commit is contained in:
Sebastiano Barezzi 2021-04-22 13:03:38 +02:00
parent 54d643ec3d
commit 5ac57d355f
No known key found for this signature in database
GPG Key ID: 47760583F393BC44
7 changed files with 71 additions and 14 deletions

View File

@ -67,7 +67,8 @@ TARGET_ENABLE_MEDIADRM_64 := true
TARGET_FS_CONFIG_GEN := $(COMMON_PATH)/config.fs
# Fingerprint
SOONG_CONFIG_NAMESPACES += XIAOMI_KONA_FOD
SOONG_CONFIG_NAMESPACES += XIAOMI_KONA_BIOMETRICS XIAOMI_KONA_FOD
SOONG_CONFIG_XIAOMI_KONA_BIOMETRICS := HAL_CLASSES
SOONG_CONFIG_XIAOMI_KONA_FOD := POS_X POS_Y SIZE
SOONG_CONFIG_XIAOMI_KONA_FOD_POS_X = 439
SOONG_CONFIG_XIAOMI_KONA_FOD_POS_Y = 1655

View File

@ -1,4 +1,4 @@
cc_binary {
xiaomi_kona_biometrics_hal_binary {
name: "android.hardware.biometrics.fingerprint@2.1-service.xiaomi_kona",
defaults: ["hidl_defaults"],
init_rc: ["android.hardware.biometrics.fingerprint@2.1-service.xiaomi_kona.rc"],

View File

@ -1,5 +1,6 @@
/*
* Copyright (C) 2017 The Android Open Source Project
* Copyright (C) 2021 The LineageOS Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -35,16 +36,27 @@ namespace implementation {
// Supported fingerprint HAL version
static const uint16_t kVersion = HARDWARE_MODULE_API_VERSION(2, 1);
// List of fingerprint HALs
static const char *kHALClasses[HAL_CLASSES_SIZE] = {HAL_CLASSES};
using RequestStatus =
android::hardware::biometrics::fingerprint::V2_1::RequestStatus;
BiometricsFingerprint *BiometricsFingerprint::sInstance = nullptr;
BiometricsFingerprint::BiometricsFingerprint() : mClientCallback(nullptr), mDevice(nullptr) {
int i;
const char *class_name;
sInstance = this; // keep track of the most recent instance
mDevice = openHal();
for (i=0; i<HAL_CLASSES_SIZE; i++) {
class_name = kHALClasses[i];
mDevice = openHal(class_name);
if (!mDevice) {
ALOGE("Can't open HAL module");
ALOGE("Can't open HAL module, class %s", class_name);
} else {
ALOGI("Opened fingerprint HAL, class %s", class_name);
break;
}
}
}
@ -211,37 +223,37 @@ IBiometricsFingerprint* BiometricsFingerprint::getInstance() {
return sInstance;
}
fingerprint_device_t* BiometricsFingerprint::openHal() {
fingerprint_device_t* BiometricsFingerprint::openHal(const char *class_name) {
int err;
const hw_module_t *hw_mdl = nullptr;
ALOGD("Opening fingerprint hal library...");
if (0 != (err = hw_get_module(FINGERPRINT_HARDWARE_MODULE_ID, &hw_mdl))) {
ALOGE("Can't open fingerprint HW Module, error: %d", err);
if (0 != (err = hw_get_module_by_class(FINGERPRINT_HARDWARE_MODULE_ID, class_name, &hw_mdl))) {
ALOGE("Can't open fingerprint HW Module, class %s, error: %d", class_name, err);
return nullptr;
}
if (hw_mdl == nullptr) {
ALOGE("No valid fingerprint module");
ALOGE("No valid fingerprint module, class %s", class_name);
return nullptr;
}
fingerprint_module_t const *module =
reinterpret_cast<const fingerprint_module_t*>(hw_mdl);
if (module->common.methods->open == nullptr) {
ALOGE("No valid open method");
ALOGE("No valid open method, class %s", class_name);
return nullptr;
}
hw_device_t *device = nullptr;
if (0 != (err = module->common.methods->open(hw_mdl, nullptr, &device))) {
ALOGE("Can't open fingerprint methods, error: %d", err);
ALOGE("Can't open fingerprint methods, class %s, error: %d", class_name, err);
return nullptr;
}
if (kVersion != device->version) {
// enforce version on new devices because of HIDL@2.1 translation layer
ALOGE("Wrong fp version. Expected %d, got %d", kVersion, device->version);
ALOGE("Wrong fp version, class %s. Expected %d, got %d", class_name, kVersion, device->version);
return nullptr;
}
@ -250,7 +262,7 @@ fingerprint_device_t* BiometricsFingerprint::openHal() {
if (0 != (err =
fp_device->set_notify(fp_device, BiometricsFingerprint::notify))) {
ALOGE("Can't register fingerprint module callback, error: %d", err);
ALOGE("Can't register fingerprint module callback, class %s, error: %d", class_name, err);
return nullptr;
}

View File

@ -1,5 +1,6 @@
/*
* Copyright (C) 2017 The Android Open Source Project
* Copyright (C) 2021 The LineageOS Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -62,7 +63,7 @@ public:
Return<RequestStatus> authenticate(uint64_t operationId, uint32_t gid) override;
private:
static fingerprint_device_t* openHal();
static fingerprint_device_t* openHal(const char *class_name);
static void notify(const fingerprint_msg_t *msg); /* Static callback for legacy HAL implementation */
static Return<RequestStatus> ErrorFilter(int32_t error);
static FingerprintError VendorErrorFilter(int32_t error, int32_t* vendorCode);

View File

@ -10,6 +10,7 @@ bootstrap_go_package {
"soong-genrule",
],
srcs: [
"biometrics.go",
"fod.go",
"main.go",
],

41
soong/biometrics.go Normal file
View File

@ -0,0 +1,41 @@
package kona
import (
"android/soong/android"
"android/soong/cc"
"strconv"
"strings"
)
func biometricsFlags(ctx android.BaseContext) []string {
var cflags []string
var config = ctx.AConfig().VendorConfig("XIAOMI_KONA_BIOMETRICS")
var halClasses = strings.Split(strings.TrimSpace(config.String("HAL_CLASSES")), ",")
cflags = append(cflags, "-DHAL_CLASSES=\"" + strings.Join(halClasses, "\", \"") + "\"")
cflags = append(cflags, " -DHAL_CLASSES_SIZE=" + strconv.Itoa(len(halClasses)))
return cflags
}
func biometricsHalBinary(ctx android.LoadHookContext) {
type props struct {
Target struct {
Android struct {
Cflags []string
}
}
}
p := &props{}
p.Target.Android.Cflags = biometricsFlags(ctx)
ctx.AppendProperties(p)
}
func biometricsHalBinaryFactory() android.Module {
module, _ := cc.NewBinary(android.HostAndDeviceSupported)
newMod := module.Init()
android.AddLoadHook(newMod, biometricsHalBinary)
return newMod
}

View File

@ -5,5 +5,6 @@ import (
)
func init() {
android.RegisterModuleType("xiaomi_kona_biometrics_hal_binary", biometricsHalBinaryFactory)
android.RegisterModuleType("xiaomi_kona_fod_hal_binary", fodHalBinaryFactory)
}