diff --git a/sepolicy/vendor/file.te b/sepolicy/vendor/file.te index 799d7cb..e76b758 100644 --- a/sepolicy/vendor/file.te +++ b/sepolicy/vendor/file.te @@ -20,4 +20,5 @@ type sysfs_fuse, fs_type, sysfs_type; type sysfs_memplus, fs_type, sysfs_type; type sysfs_project_info, fs_type, sysfs_type; type sysfs_tpd, fs_type, sysfs_type; +type sysfs_tri_state_key, sysfs_type, fs_type; type vendor_sysfs_video_call_on, fs_type, sysfs_type; diff --git a/sepolicy/vendor/file_contexts b/sepolicy/vendor/file_contexts index 5cfb89a..788edca 100644 --- a/sepolicy/vendor/file_contexts +++ b/sepolicy/vendor/file_contexts @@ -89,6 +89,7 @@ # Sys files (wakeup) /sys/devices/platform/soc/c440000\.qcom,spmi/spmi-0/spmi0-00/c440000\.qcom,spmi:qcom,pm8150@0:qcom,pm8150_rtc/rtc/rtc0/wakeup[0-9]+(/.*)? u:object_r:sysfs_wakeup:s0 /sys/devices/platform/soc/soc:oneplus_wlchg/power_supply/wireless/wakeup[0-9]+(/.*)? u:object_r:sysfs_wakeup:s0 +/sys/devices/platform/soc/soc:tri_state_key/hall_data_calib u:object_r:sysfs_tri_state_key:s0 /sys/devices/virtual/diag/diag/wakeup[0-9]+(/.*)? u:object_r:sysfs_wakeup:s0 /sys/devices/virtual/misc/msm_aac/wakeup[0-9]+(/.*)? u:object_r:sysfs_wakeup:s0 /sys/devices/virtual/misc/msm_alac/wakeup[0-9]+(/.*)? u:object_r:sysfs_wakeup:s0 diff --git a/sepolicy/vendor/tri-state-key_daemon.te b/sepolicy/vendor/tri-state-key_daemon.te index 08fdb5d..cdde618 100644 --- a/sepolicy/vendor/tri-state-key_daemon.te +++ b/sepolicy/vendor/tri-state-key_daemon.te @@ -5,3 +5,9 @@ init_daemon_domain(tri-state-key_daemon) allow tri-state-key_daemon uhid_device:chr_file rw_file_perms; allow tri-state-key_daemon self:netlink_kobject_uevent_socket create_socket_perms_no_ioctl; + +allow tri-state-key_daemon sysfs_tri_state_key:file w_file_perms; + +allow tri-state-key_daemon mnt_vendor_file:dir search; + +r_dir_file(tri-state-key_daemon, oem_file) diff --git a/tri-state-key/main.cpp b/tri-state-key/main.cpp index a721634..c3a3dfa 100644 --- a/tri-state-key/main.cpp +++ b/tri-state-key/main.cpp @@ -16,6 +16,7 @@ #define LOG_TAG "tri-state-key_daemon" +#include #include #include #include @@ -24,10 +25,15 @@ #include "uevent_listener.h" +#define HALL_CALIBRATION_DATA "/sys/devices/platform/soc/soc:tri_state_key/hall_data_calib" +#define HALL_PERSIST_CALIBRATION_DATA "/mnt/vendor/persist/engineermode/tri_state_hall_data" + #define KEY_MODE_NORMAL 601 #define KEY_MODE_VIBRATION 602 #define KEY_MODE_SILENCE 603 +using android::base::ReadFileToString; +using android::base::WriteStringToFile; using android::Uevent; using android::UeventListener; @@ -39,6 +45,11 @@ int main() { LOG(INFO) << "Started"; + if (std::string hallData; ReadFileToString(HALL_PERSIST_CALIBRATION_DATA, &hallData)) { + std::replace(hallData.begin(), hallData.end(), ';', ','); + WriteStringToFile(hallData, HALL_CALIBRATION_DATA); + } + uinputFd = open("/dev/uinput", O_WRONLY | O_NONBLOCK); if (uinputFd < 0) { LOG(ERROR) << "Unable to open uinput node"; diff --git a/tri-state-key/tri-state-key_daemon.rc b/tri-state-key/tri-state-key_daemon.rc index 028d472..0886ab9 100644 --- a/tri-state-key/tri-state-key_daemon.rc +++ b/tri-state-key/tri-state-key_daemon.rc @@ -1,4 +1,7 @@ on fs + chown system system /sys/devices/platform/soc/soc:tri_state_key/hall_data_calib + chown system system /mnt/vendor/persist/engineermode/tri_state_hall_data + start tri-state-key_daemon service tri-state-key_daemon /vendor/bin/tri-state-key_daemon