From 29fa5da482b21d4de2756e759b1d6e61cc523af3 Mon Sep 17 00:00:00 2001 From: "Christopher R. Palmer" Date: Mon, 9 Jan 2017 05:35:05 -0500 Subject: [PATCH] whyred: fingerprint: Load goodix HAL if loading the fpc HAL fails Change-Id: I5d45d1c655e69c34de16e6813eee80b07d30dda9 --- fingerprint/FingerprintWrapper.cpp | 37 ++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/fingerprint/FingerprintWrapper.cpp b/fingerprint/FingerprintWrapper.cpp index 52e58dc..2ea2396 100644 --- a/fingerprint/FingerprintWrapper.cpp +++ b/fingerprint/FingerprintWrapper.cpp @@ -38,18 +38,37 @@ static union { const hw_module_t *hw_module; } vendor; -static bool ensure_vendor_module_is_loaded(void) +static bool try_hal(const char *class_name, const char *device_name) +{ + const hw_module_t *module; + + int rv = hw_get_module_by_class("fingerprint", class_name, &module); + if (rv) { + ALOGE("Failed to open fingerprint module: class %s, error %d", class_name, rv); + vendor.module = NULL; + } else { + hw_device_t *device; + + ALOGI("loaded fingerprint module, class %s: %s version %x", class_name, module->name, + module->module_api_version); + if (module->methods->open(module, device_name, &device) == 0) { + device->close(device); + ALOGI("Successfully loaded the device for fingerprint module, class %s", class_name); + vendor.hw_module = module; + } else { + ALOGE("Failed to open a device using fingerprint HAL, class %s", class_name); + } + } + return vendor.module != NULL; +} + +static bool ensure_vendor_module_is_loaded(const char *device_name) { android::Mutex::Autolock lock(vendor_mutex); if (!vendor.module) { - int rv = hw_get_module_by_class("fingerprint", "vendor", &vendor.hw_module); - if (rv) { - ALOGE("failed to open vendor module, error %d", rv); - vendor.module = NULL; - } else { - ALOGI("loaded vendor module: %s version %x", vendor.module->common.name, - vendor.module->common.module_api_version); + if (!try_hal("fpc", device_name)) { + try_hal("goodix", device_name); } } @@ -140,7 +159,7 @@ static int device_open(const hw_module_t *module, const char *name, hw_device_t int rv; device_t *device; - if (!ensure_vendor_module_is_loaded()) { + if (!ensure_vendor_module_is_loaded(name)) { return -EINVAL; }