aidl: fingerprint: Add support for libsfp_sensor
Co-Authored-By: Tim Zimmermann <tim@linux4.de>
Change-Id: I7fbbb1467f87b688057eac24d2434274e1105e05
diff --git a/aidl/fingerprint/LegacyHAL.cpp b/aidl/fingerprint/LegacyHAL.cpp
index 54f5a35..143efc6 100644
--- a/aidl/fingerprint/LegacyHAL.cpp
+++ b/aidl/fingerprint/LegacyHAL.cpp
@@ -18,6 +18,10 @@
bool LegacyHAL::openHal(fingerprint_notify_t notify) {
void* handle = dlopen("libbauthserver.so", RTLD_NOW);
+
+ if (!handle)
+ handle = dlopen("libsfp_sensor.so", RTLD_NOW);
+
if (handle) {
int err;
diff --git a/aidl/fingerprint/Session.cpp b/aidl/fingerprint/Session.cpp
index aa4bdae..722190d 100644
--- a/aidl/fingerprint/Session.cpp
+++ b/aidl/fingerprint/Session.cpp
@@ -13,6 +13,7 @@
#include <android-base/logging.h>
+#include <dirent.h>
#include <endian.h>
#include <thread>
@@ -42,8 +43,8 @@
mDeathRecipient = AIBinder_DeathRecipient_new(onClientDeath);
char filename[64];
- snprintf(filename, sizeof(filename), "/data/vendor_de/%d/fpdata/");
- mHal.ss_fingerprint_set_active_group(userId, &filename[0]);
+ snprintf(filename, sizeof(filename), FINGERPRINT_DATA_DIR, userId);
+ mHal.ss_fingerprint_set_active_group(userId, filename);
}
ndk::ScopedAStatus Session::generateChallenge() {
@@ -119,9 +120,32 @@
ndk::ScopedAStatus Session::enumerateEnrollments() {
LOG(INFO) << "enumerateEnrollments";
- int32_t error = mHal.ss_fingerprint_enumerate();
- if (error)
- LOG(ERROR) << "ss_fingerprint_enumerate failed: " << error;
+ if (mHal.ss_fingerprint_enumerate) {
+ int32_t error = mHal.ss_fingerprint_enumerate();
+ if (error)
+ LOG(ERROR) << "ss_fingerprint_enumerate failed: " << error;
+ } else {
+ std::vector<int> enrollments;
+ char filename[64];
+ snprintf(filename, sizeof(filename), FINGERPRINT_DATA_DIR, mUserId);
+
+ DIR* directory = opendir(filename);
+ if (directory) {
+ struct dirent* entry;
+ while ((entry = readdir(directory))) {
+ int uid, fid;
+ if (sscanf(entry->d_name, "User_%d_%dtmpl.dat", &uid, &fid)) {
+ if (uid == mUserId)
+ enrollments.push_back(fid);
+ }
+ }
+ closedir(directory);
+ } else {
+ LOG(WARNING) << "Failed to open " << filename;
+ }
+
+ mCb->onEnrollmentsEnumerated(enrollments);
+ }
return ndk::ScopedAStatus::ok();
}
diff --git a/aidl/fingerprint/Session.h b/aidl/fingerprint/Session.h
index dc3bd3d..cc91831 100644
--- a/aidl/fingerprint/Session.h
+++ b/aidl/fingerprint/Session.h
@@ -14,6 +14,8 @@
#include "LegacyHAL.h"
#include "LockoutTracker.h"
+#define FINGERPRINT_DATA_DIR "/data/vendor/biometrics/fp/User_%d/"
+
using ::aidl::android::hardware::biometrics::common::ICancellationSignal;
using ::aidl::android::hardware::biometrics::common::OperationContext;
using ::aidl::android::hardware::biometrics::fingerprint::PointerContext;