aidl: fingerprint: Add support for libsfp_sensor
authorJ0SH1X <aljoshua.hell@gmail.com>
Tue, 30 Jan 2024 16:48:14 +0000 (17:48 +0100)
committerJan Altensen (Stricted) <info@stricted.net>
Fri, 21 Jun 2024 04:02:30 +0000 (04:02 +0000)
Co-Authored-By: Tim Zimmermann <tim@linux4.de>
Change-Id: I7fbbb1467f87b688057eac24d2434274e1105e05

aidl/fingerprint/LegacyHAL.cpp
aidl/fingerprint/Session.cpp
aidl/fingerprint/Session.h

index 54f5a358d36e396e6685d63c04d42e2b7c83c45f..143efc6578d6351d89cfdae90601d78efd5acb97 100644 (file)
@@ -18,6 +18,10 @@ namespace fingerprint {
 
 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;
 
index aa4bdaecd5aa0ca065ef2eec85212f418bc5d035..722190dba2b3e0f3e2d9f67509fafe2197d056da 100644 (file)
@@ -13,6 +13,7 @@
 
 #include <android-base/logging.h>
 
+#include <dirent.h>
 #include <endian.h>
 #include <thread>
 
@@ -42,8 +43,8 @@ Session::Session(LegacyHAL hal, int userId, std::shared_ptr<ISessionCallback> cb
     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::detectInteraction(std::shared_ptr<ICancellationSigna
 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();
 }
index dc3bd3d3e3798e51674cd6339657a888e745a5e6..cc91831bcb3b4b9a1328b9e61b51aed5f528e597 100644 (file)
@@ -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;