sm8350-common: Add udfps handler lib

Change-Id: Ib837e4a70015dc24d431458a1cce5b86e87816a9
This commit is contained in:
Arian 2022-05-05 23:40:07 +02:00
parent 16a45dcda2
commit 1799fe9571
5 changed files with 146 additions and 1 deletions

View File

@ -109,7 +109,7 @@ on post-fs-data
# Create fingerprint related directory
mkdir /data/vendor/fpc 0770 system system
mkdir /data/vendor/goodix 0770 system system
mkdir /mnt/vendor/persist/goodix 0770 system system
mkdir /mnt/vendor/persist/goodix 0770 system system
on early-boot
# Enable WLAN cold boot calibration
@ -142,6 +142,9 @@ on boot
write /sys/block/sda/queue/wbt_lat_usec 75000
# Set fingerprint related permissions
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
chown system system /sys/bus/platform/devices/soc:fingerprint_fpc/irq
chown system system /sys/bus/platform/devices/soc:fingerprint_fpc/irq_enable
chown system system /sys/bus/platform/devices/soc:fingerprint_fpc/wakeup_enable

View File

@ -42,6 +42,9 @@
/data/vendor/fpdump(/.*)? u:object_r:vendor_fingerprint_data_file:s0
/data/vendor/goodix(/.*)? u:object_r:vendor_fingerprint_data_file:s0
/vendor/bin/hw/android\.hardware\.biometrics\.fingerprint@2\.3-service\.xiaomi u:object_r:hal_fingerprint_default_exec:s0
/sys/devices/platform/soc/soc:qcom,dsi-display-primary/fod_hbm u:object_r:vendor_sysfs_udfps:s0
/sys/devices/platform/soc/soc:qcom,dsi-display-primary/fod_ui u:object_r:vendor_sysfs_udfps:s0
/sys/devices/virtual/touch/tp_dev/fod_status u:object_r:vendor_sysfs_udfps:s0
# Thermal
/data/vendor/thermal(/.*)? u:object_r:thermal_data_file:s0

View File

@ -1,6 +1,7 @@
type vendor_fingerprint_data_file, data_file_type, file_type;
type vendor_fingerprint_device, dev_type;
type vendor_hal_fingerprint_hwservice_xiaomi, hwservice_manager_type;
type vendor_sysfs_udfps, sysfs_type, fs_type;
vendor_internal_prop(vendor_fp_prop)
vendor_internal_prop(vendor_fp_info_prop)
@ -20,6 +21,9 @@ allow hal_fingerprint_default vendor_sysfs_spss:dir r_dir_perms;
allow hal_fingerprint_default vendor_sysfs_spss:file rw_file_perms;
allow hal_fingerprint_default vendor_sysfs_fingerprint:dir r_dir_perms;
allow hal_fingerprint_default vendor_sysfs_fingerprint:file rw_file_perms;
allow hal_fingerprint_default vendor_sysfs_udfps:file rw_file_perms;
allow hal_fingerprint_default vendor_sysfs_graphics:dir r_dir_perms;
allow hal_fingerprint_default vendor_sysfs_graphics:file rw_file_perms;
# Dev nodes
allow hal_fingerprint_default tee_device:chr_file rw_file_perms;

17
udfps/Android.bp Normal file
View File

@ -0,0 +1,17 @@
//
// Copyright (C) 2022 The LineageOS Project
//
// SPDX-License-Identifier: Apache-2.0
//
cc_library {
name: "libudfpshandler",
vendor: true,
srcs: ["UdfpsHandler.cpp"],
shared_libs: [
"libbase",
],
header_libs: [
"//hardware/xiaomi:xiaomifingerprint_headers",
],
}

118
udfps/UdfpsHandler.cpp Normal file
View File

@ -0,0 +1,118 @@
/*
* Copyright (C) 2022 The LineageOS Project
*
* SPDX-License-Identifier: Apache-2.0
*/
#define LOG_TAG "UdfpsHandler.xiaomi_sm8350"
#include <android-base/logging.h>
#include <fcntl.h>
#include <fstream>
#include <poll.h>
#include <thread>
#include "UdfpsHandler.h"
// Fingerprint hwmodule commands
#define COMMAND_NIT 10
#define PARAM_NIT_UDFPS 1
#define PARAM_NIT_NONE 0
// Touchscreen and HBM
#define FOD_HBM_PATH "/sys/devices/platform/soc/soc:qcom,dsi-display-primary/fod_hbm"
#define FOD_STATUS_PATH "/sys/devices/virtual/touch/tp_dev/fod_status"
#define FOD_UI_PATH "/sys/devices/platform/soc/soc:qcom,dsi-display-primary/fod_ui"
#define FOD_HBM_OFF 0
#define FOD_HBM_ON 1
#define FOD_STATUS_OFF 0
#define FOD_STATUS_ON 1
template <typename T>
static void set(const std::string& path, const T& value) {
std::ofstream file(path);
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';
}
class XiaomiUdfpsHander : public UdfpsHandler {
public:
void init(fingerprint_device_t* device) {
mDevice = device;
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;
}
if (readBool(fd)) {
mDevice->extCmd(mDevice, COMMAND_NIT, PARAM_NIT_UDFPS);
set(FOD_STATUS_PATH, FOD_STATUS_ON);
} else {
mDevice->extCmd(mDevice, COMMAND_NIT, PARAM_NIT_NONE);
set(FOD_HBM_PATH, FOD_HBM_OFF);
set(FOD_STATUS_PATH, FOD_STATUS_OFF);
}
}
}).detach();
}
void onFingerDown(uint32_t /*x*/, uint32_t /*y*/, float /*minor*/, float /*major*/) {
// nothing
}
void onFingerUp() {
// nothing
}
private:
fingerprint_device_t* mDevice;
};
static UdfpsHandler* create() {
return new XiaomiUdfpsHander();
}
static void destroy(UdfpsHandler* handler) {
delete handler;
}
extern "C" UdfpsHandlerFactory UDFPS_HANDLER_FACTORY = {
.create = create,
.destroy = destroy,
};