sm8350-common: fod: add thread listening for fod_ui sysfs event

This commit is contained in:
Cosmin Tanislav 2021-09-24 16:08:16 +03:00
parent 5122e1bcc3
commit 10db1ddc09
3 changed files with 53 additions and 2 deletions

View File

@ -21,6 +21,11 @@
#include <android-base/logging.h>
#include <fstream>
#include <cmath>
#include <thread>
#include <fcntl.h>
#include <poll.h>
#include <sys/stat.h>
#define FINGERPRINT_ACQUIRED_VENDOR 6
@ -32,6 +37,8 @@
#define FOD_STATUS_ON 1
#define FOD_STATUS_OFF 0
#define FOD_UI_PATH "/sys/devices/platform/soc/soc:qcom,dsi-display-primary/fod_ui"
#define FOD_HBM_PATH "/sys/devices/platform/soc/soc:qcom,dsi-display-primary/fod_hbm"
#define FOD_HBM_ON 1
#define FOD_HBM_OFF 0
@ -48,6 +55,25 @@ static void set(const std::string& path, const T& value) {
file << value;
}
static bool readBool(int fd) {
char c;
int rc;
rc = lseek(fd, 0, SEEK_SET);
if (rc) {
LOG(ERROR) << "failed to seek fd, err: " << rc;
return false;
}
rc = read(fd, &c, sizeof(char));
if (rc != 1) {
LOG(ERROR) << "failed to read bool from fd, err: " << rc;
return false;
}
return c != '0';
}
} // anonymous namespace
namespace vendor {
@ -60,6 +86,31 @@ namespace implementation {
FingerprintInscreen::FingerprintInscreen() {
xiaomiFingerprintService = IXiaomiFingerprint::getService();
std::thread([this]() {
int fd = open(FOD_UI_PATH, O_RDONLY);
if (fd < 0) {
LOG(ERROR) << "failed to open fd, err: " << fd;
return;
}
struct pollfd fodUiPoll = {
.fd = fd,
.events = POLLERR | POLLPRI,
.revents = 0,
};
while (true) {
int rc = poll(&fodUiPoll, 1, -1);
if (rc < 0) {
LOG(ERROR) << "failed to poll fd, err: " << rc;
continue;
}
xiaomiFingerprintService->extCmd(COMMAND_NIT,
readBool(fd) ? PARAM_NIT_FOD : PARAM_NIT_NONE);
}
}).detach();
}
Return<int32_t> FingerprintInscreen::getPositionX() {
@ -94,12 +145,10 @@ Return<void> FingerprintInscreen::onRelease() {
Return<void> FingerprintInscreen::onShowFODView() {
set(FOD_STATUS_PATH, FOD_STATUS_ON);
xiaomiFingerprintService->extCmd(COMMAND_NIT, PARAM_NIT_FOD);
return Void();
}
Return<void> FingerprintInscreen::onHideFODView() {
xiaomiFingerprintService->extCmd(COMMAND_NIT, PARAM_NIT_NONE);
set(FOD_STATUS_PATH, FOD_STATUS_OFF);
return Void();
}

View File

@ -1,5 +1,6 @@
on boot
chown system system /sys/devices/platform/soc/soc:qcom,dsi-display-primary/fod_hbm
chown system system /sys/devices/platform/soc/soc:qcom,dsi-display-primary/fod_ui
chown system system /sys/devices/virtual/touch/tp_dev/fod_status
service fingerprint-inscreen-1-0 /vendor/bin/hw/vendor.lineage.biometrics.fingerprint.inscreen@1.0-service.xiaomi_sm8350

View File

@ -12,4 +12,5 @@
# FOD
/vendor/bin/hw/vendor\.lineage\.biometrics\.fingerprint\.inscreen@1.0-service\.xiaomi_sm8350 u:object_r:hal_lineage_fod_default_exec:s0
/sys/devices/platform/soc/soc:qcom,dsi-display-primary/fod_hbm u:object_r:vendor_sysfs_fod:s0
/sys/devices/platform/soc/soc:qcom,dsi-display-primary/fod_ui u:object_r:vendor_sysfs_fod:s0
/sys/devices/virtual/touch/tp_dev/fod_status u:object_r:vendor_sysfs_fod:s0