otter: fingerprint: add support for goodix udfps

Change-Id: Iea8b175f7ea5d48a8aa7336bab91d2c35a4de462
Signed-off-by: Alexander Martinz <amartinz@shiftphones.com>
diff --git a/fingerprint/Android.bp b/fingerprint/Android.bp
index b541224..891b564 100644
--- a/fingerprint/Android.bp
+++ b/fingerprint/Android.bp
@@ -15,6 +15,7 @@
     ],
 
     shared_libs: [
+        "libbase",
         "libcutils",
         "liblog",
         "libhidlbase",
diff --git a/fingerprint/BiometricsFingerprint.cpp b/fingerprint/BiometricsFingerprint.cpp
index b777b0a..de65f4e 100644
--- a/fingerprint/BiometricsFingerprint.cpp
+++ b/fingerprint/BiometricsFingerprint.cpp
@@ -18,6 +18,7 @@
 
 #include <hardware/hw_auth_token.h>
 
+#include <android-base/file.h>
 #include <hardware/hardware.h>
 #include "fingerprint.h"
 #include "BiometricsFingerprint.h"
@@ -32,6 +33,18 @@
 namespace V2_3 {
 namespace implementation {
 
+#define UDFPS_HBM_PATH "/sys/class/display/panel/bl_fps_func"
+#define UDFPS_HBM_ON "1"
+#define UDFPS_HBM_OFF "0"
+
+#define CMD_FINGERPRINT_EVENT 0xA
+#define CMD_FINGERPRINT_EVENT_DOWN 1
+#define CMD_FINGERPRINT_EVENT_UP 0
+
+static void setUdfpsHbm(bool status) {
+    android::base::WriteStringToFile(status ? UDFPS_HBM_ON : UDFPS_HBM_OFF, UDFPS_HBM_PATH);
+}
+
 // Supported fingerprint HAL version
 static const uint16_t kVersion = HARDWARE_MODULE_API_VERSION(2, 1);
 
@@ -353,14 +366,18 @@
 // Methods from ::android::hardware::biometrics::fingerprint::V2_3::IBiometricsFingerprint follow.
 
 Return<bool> BiometricsFingerprint::isUdfps(uint32_t) {
-    return false;
+    return true;
 }
 
 Return<void> BiometricsFingerprint::onFingerDown(uint32_t, uint32_t, float, float) {
+    setUdfpsHbm(true);
+    mDevice->send_customized_command(mDevice, CMD_FINGERPRINT_EVENT, CMD_FINGERPRINT_EVENT_DOWN);
     return Void();
 }
 
 Return<void> BiometricsFingerprint::onFingerUp() {
+    setUdfpsHbm(false);
+    mDevice->send_customized_command(mDevice, CMD_FINGERPRINT_EVENT, CMD_FINGERPRINT_EVENT_UP);
     return Void();
 }
 
diff --git a/fingerprint/fingerprint.h b/fingerprint/fingerprint.h
index 86ced9b..55e4148 100644
--- a/fingerprint/fingerprint.h
+++ b/fingerprint/fingerprint.h
@@ -260,6 +260,9 @@
      */
     int (*authenticate)(struct fingerprint_device *dev, uint64_t operation_id, uint32_t gid);
 
+    /* Goodix */
+    int (*send_customized_command)(struct fingerprint_device *dev, uint32_t command, uint32_t extras);
+
     /* Reserved for backward binary compatibility */
     void *reserved[4];
 } fingerprint_device_t;