diff --git a/fod/Android.bp b/fod/Android.bp new file mode 100644 index 0000000..da09e4d --- /dev/null +++ b/fod/Android.bp @@ -0,0 +1,37 @@ +// +// Copyright (C) 2019 The LineageOS Project +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +cc_binary { + relative_install_path: "hw", + defaults: ["hidl_defaults"], + name: "vendor.lineage.biometrics.fingerprint.inscreen@1.0-service.xiaomi_sdm845", + init_rc: ["vendor.lineage.biometrics.fingerprint.inscreen@1.0-service.xiaomi_sdm845.rc"], + srcs: [ + "service.cpp", + "FingerprintInscreen.cpp", + ], + vendor: true, + shared_libs: [ + "libbase", + "libhardware", + "libhidlbase", + "libhidltransport", + "liblog", + "libhwbinder", + "libutils", + "vendor.lineage.biometrics.fingerprint.inscreen@1.0", + "vendor.xiaomi.hardware.fingerprintextension@1.0", + ], +} diff --git a/fod/FingerprintInscreen.cpp b/fod/FingerprintInscreen.cpp new file mode 100644 index 0000000..b41a740 --- /dev/null +++ b/fod/FingerprintInscreen.cpp @@ -0,0 +1,146 @@ +/* + * Copyright (C) 2019 The LineageOS Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define LOG_TAG "FingerprintInscreenService" + +#include "FingerprintInscreen.h" + +#include + +#include +#include + +#define COMMAND_NIT 10 +#define PARAM_NIT_FOD 3 +#define PARAM_NIT_NONE 0 + +#define DISPPARAM_PATH "/sys/devices/platform/soc/ae00000.qcom,mdss_mdp/drm/card0/card0-DSI-1/disp_param" +#define DISPPARAM_HBM_FOD_ON "0x20000" +#define DISPPARAM_HBM_FOD_OFF "0xE0000" + +#define FOD_STATUS_PATH "/sys/devices/virtual/touch/tp_dev/fod_status" +#define FOD_STATUS_ON 1 +#define FOD_STATUS_OFF 0 + +#define FOD_SENSOR_X 453 +#define FOD_SENSOR_Y 1640 +#define FOD_SENSOR_SIZE 173 + +namespace { + +template +static void set(const std::string& path, const T& value) { + std::ofstream file(path); + file << value; +} + +} // anonymous namespace + +namespace vendor { +namespace lineage { +namespace biometrics { +namespace fingerprint { +namespace inscreen { +namespace V1_0 { +namespace implementation { + +FingerprintInscreen::FingerprintInscreen() { + xiaomiFingerprintService = IXiaomiFingerprint::getService(); +} + +Return FingerprintInscreen::getPositionX() { + return FOD_SENSOR_X; +} + +Return FingerprintInscreen::getPositionY() { + return FOD_SENSOR_Y; +} + +Return FingerprintInscreen::getSize() { + return FOD_SENSOR_SIZE; +} + +Return FingerprintInscreen::onStartEnroll() { + return Void(); +} + +Return FingerprintInscreen::onFinishEnroll() { + return Void(); +} + +Return FingerprintInscreen::onPress() { + set(DISPPARAM_PATH, DISPPARAM_HBM_FOD_ON); + xiaomiFingerprintService->extCmd(COMMAND_NIT, PARAM_NIT_FOD); + return Void(); +} + +Return FingerprintInscreen::onRelease() { + set(DISPPARAM_PATH, DISPPARAM_HBM_FOD_OFF); + xiaomiFingerprintService->extCmd(COMMAND_NIT, PARAM_NIT_NONE); + return Void(); +} + +Return FingerprintInscreen::onShowFODView() { + set(FOD_STATUS_PATH, FOD_STATUS_ON); + return Void(); +} + +Return FingerprintInscreen::onHideFODView() { + set(FOD_STATUS_PATH, FOD_STATUS_OFF); + return Void(); +} + +Return FingerprintInscreen::handleAcquired(int32_t acquiredInfo, int32_t vendorCode) { + LOG(ERROR) << "acquiredInfo: " << acquiredInfo << ", vendorCode: " << vendorCode << "\n"; + return false; +} + +Return FingerprintInscreen::handleError(int32_t error, int32_t vendorCode) { + LOG(ERROR) << "error: " << error << ", vendorCode: " << vendorCode << "\n"; + return false; +} + +Return FingerprintInscreen::setLongPressEnabled(bool) { + return Void(); +} + +Return FingerprintInscreen::getDimAmount(int32_t brightness) { + float alpha; + + if (brightness > 62) { + alpha = 1.0 - pow(brightness / 255.0 * 430.0 / 600.0, 0.45); + } else { + alpha = 1.0 - pow(brightness / 200.0, 0.45); + } + + return 255 * alpha; +} + +Return FingerprintInscreen::shouldBoostBrightness() { + return false; +} + +Return FingerprintInscreen::setCallback(const sp& /* callback */) { + return Void(); +} + +} // namespace implementation +} // namespace V1_0 +} // namespace inscreen +} // namespace fingerprint +} // namespace biometrics +} // namespace lineage +} // namespace vendor diff --git a/fod/FingerprintInscreen.h b/fod/FingerprintInscreen.h new file mode 100644 index 0000000..d414dd9 --- /dev/null +++ b/fod/FingerprintInscreen.h @@ -0,0 +1,67 @@ +/* + * Copyright (C) 2019 The LineageOS Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef VENDOR_LINEAGE_BIOMETRICS_FINGERPRINT_INSCREEN_V1_0_FINGERPRINTINSCREEN_H +#define VENDOR_LINEAGE_BIOMETRICS_FINGERPRINT_INSCREEN_V1_0_FINGERPRINTINSCREEN_H + +#include +#include + +namespace vendor { +namespace lineage { +namespace biometrics { +namespace fingerprint { +namespace inscreen { +namespace V1_0 { +namespace implementation { + +using ::android::sp; +using ::android::hardware::Return; +using ::android::hardware::Void; +using ::vendor::xiaomi::hardware::fingerprintextension::V1_0::IXiaomiFingerprint; + +class FingerprintInscreen : public IFingerprintInscreen { + public: + FingerprintInscreen(); + Return getPositionX() override; + Return getPositionY() override; + Return getSize() override; + Return onStartEnroll() override; + Return onFinishEnroll() override; + Return onPress() override; + Return onRelease() override; + Return onShowFODView() override; + Return onHideFODView() override; + Return handleAcquired(int32_t acquiredInfo, int32_t vendorCode) override; + Return handleError(int32_t error, int32_t vendorCode) override; + Return setLongPressEnabled(bool enabled) override; + Return getDimAmount(int32_t brightness) override; + Return shouldBoostBrightness() override; + Return setCallback(const sp& callback) override; + + private: + sp xiaomiFingerprintService; +}; + +} // namespace implementation +} // namespace V1_0 +} // namespace inscreen +} // namespace fingerprint +} // namespace biometrics +} // namespace lineage +} // namespace vendor + +#endif // VENDOR_LINEAGE_BIOMETRICS_FINGERPRINT_INSCREEN_V1_0_FINGERPRINTINSCREEN_H diff --git a/fod/service.cpp b/fod/service.cpp new file mode 100644 index 0000000..3b86e26 --- /dev/null +++ b/fod/service.cpp @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2019 The LineageOS Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define LOG_TAG "lineage.biometrics.fingerprint.inscreen@1.0-service.xiaomi_sdm845" + +#include +#include + +#include "FingerprintInscreen.h" + +using android::hardware::configureRpcThreadpool; +using android::hardware::joinRpcThreadpool; + +using vendor::lineage::biometrics::fingerprint::inscreen::V1_0::IFingerprintInscreen; +using vendor::lineage::biometrics::fingerprint::inscreen::V1_0::implementation::FingerprintInscreen; + +using android::OK; +using android::status_t; + +int main() { + android::sp service = new FingerprintInscreen(); + + configureRpcThreadpool(1, true); + + status_t status = service->registerAsService(); + if (status != OK) { + LOG(ERROR) << "Cannot register FOD HAL service."; + return 1; + } + + LOG(INFO) << "FOD HAL service ready."; + + joinRpcThreadpool(); + + LOG(ERROR) << "FOD HAL service failed to join thread pool."; + return 1; +} diff --git a/fod/vendor.lineage.biometrics.fingerprint.inscreen@1.0-service.xiaomi_sdm845.rc b/fod/vendor.lineage.biometrics.fingerprint.inscreen@1.0-service.xiaomi_sdm845.rc new file mode 100644 index 0000000..3952b6d --- /dev/null +++ b/fod/vendor.lineage.biometrics.fingerprint.inscreen@1.0-service.xiaomi_sdm845.rc @@ -0,0 +1,11 @@ +on boot + chown system system /sys/devices/virtual/touch/tp_dev/fod_status + + chmod 0644 /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_sdm845 + interface vendor.lineage.biometrics.fingerprint.inscreen@1.0::IFingerprintInscreen default + class hal + user system + group system + shutdown critical diff --git a/sepolicy/vendor/file.te b/sepolicy/vendor/file.te index f5b674e..27b50ec 100644 --- a/sepolicy/vendor/file.te +++ b/sepolicy/vendor/file.te @@ -7,6 +7,7 @@ type thermal_data_file, data_file_type, file_type; type proc_tp, proc_type, fs_type; +type sysfs_fod, sysfs_type, fs_type; type sysfs_gps, sysfs_type, fs_type; type sysfs_wireless_supply, sysfs_type, fs_type; diff --git a/sepolicy/vendor/file_contexts b/sepolicy/vendor/file_contexts index d561794..86ccd59 100644 --- a/sepolicy/vendor/file_contexts +++ b/sepolicy/vendor/file_contexts @@ -45,6 +45,7 @@ /vendor/bin/hw/android\.hardware\.light@2\.0-service\.xiaomi_sdm845 u:object_r:hal_light_default_exec:s0 /vendor/bin/hw/android\.hardware\.neuralnetworks@1\.1-service-qti u:object_r:hal_neuralnetworks_default_exec:s0 /vendor/bin/hw/android\.hardware\.power@1\.2-service\.xiaomi_sdm845 u:object_r:hal_power_default_exec:s0 +/vendor/bin/hw/vendor\.lineage\.biometrics\.fingerprint\.inscreen@1.0-service\.xiaomi_sdm845 u:object_r:hal_lineage_fod_sdm845_exec:s0 /vendor/bin/hw/vendor\.lineage\.livedisplay@2\.0-service\.xiaomi_sdm845 u:object_r:hal_lineage_livedisplay_qti_exec:s0 # Persist files diff --git a/sepolicy/vendor/genfs_contexts b/sepolicy/vendor/genfs_contexts index 6810331..f06f9d7 100644 --- a/sepolicy/vendor/genfs_contexts +++ b/sepolicy/vendor/genfs_contexts @@ -15,5 +15,7 @@ genfscon sysfs /devices/platform/soc/soc:fingerprint_fpc/fingerdown_wait u genfscon sysfs /devices/platform/soc/soc:fingerprint_fpc/irq u:object_r:sysfs_fingerprint:s0 genfscon sysfs /devices/platform/soc/soc:fingerprint_fpc/wakeup_enable u:object_r:sysfs_fingerprint:s0 genfscon sysfs /devices/platform/soc/soc:fingerprint_goodix/proximity_state u:object_r:sysfs_fingerprint:s0 +genfscon sysfs /devices/platform/soc/soc:qcom,dsi-display-primary/fod_hbm u:object_r:sysfs_fod:s0 genfscon sysfs /devices/platform/soc/soc:qcom,ipa_fws/subsys2/restart_level u:object_r:sysfs_ssr_toggle:s0 genfscon sysfs /devices/platform/soc/soc:qcom,kgsl-hyp/subsys3/restart_level u:object_r:sysfs_ssr_toggle:s0 +genfscon sysfs /devices/virtual/touch/tp_dev/fod_status u:object_r:sysfs_fod:s0 diff --git a/sepolicy/vendor/hal_fingerprint_default.te b/sepolicy/vendor/hal_fingerprint_default.te index 7dbc69a..3680a47 100644 --- a/sepolicy/vendor/hal_fingerprint_default.te +++ b/sepolicy/vendor/hal_fingerprint_default.te @@ -5,6 +5,8 @@ allow hal_fingerprint_default self:netlink_socket create_socket_perms_no_ioctl; allow hal_fingerprint_default sysfs_fingerprint:file rw_file_perms; allow hal_fingerprint_default tee_device:chr_file rw_file_perms; allow hal_fingerprint_default uhid_device:chr_file rw_file_perms; +allow hal_fingerprint_default input_device:dir r_dir_perms; +allow hal_fingerprint_default input_device:chr_file rw_file_perms; set_prop(hal_fingerprint_default, vendor_fp_prop) hal_client_domain(hal_fingerprint_default, hal_perf) diff --git a/sepolicy/vendor/hal_lineage_fod_sdm845.te b/sepolicy/vendor/hal_lineage_fod_sdm845.te new file mode 100644 index 0000000..33c13fd --- /dev/null +++ b/sepolicy/vendor/hal_lineage_fod_sdm845.te @@ -0,0 +1,13 @@ +type hal_lineage_fod_sdm845, domain; +hal_server_domain(hal_lineage_fod_sdm845, hal_lineage_fod) + +type hal_lineage_fod_sdm845_exec, exec_type, vendor_file_type, file_type; +init_daemon_domain(hal_lineage_fod_sdm845) + +allow hal_lineage_fod_sdm845 sysfs_fod:file rw_file_perms; +allow hal_lineage_fod_sdm845 sysfs_graphics:dir r_dir_perms; +allow hal_lineage_fod_sdm845 sysfs_graphics:file rw_file_perms; + +binder_call(hal_lineage_fod_sdm845, hal_fingerprint_default) + +hal_client_domain(hal_lineage_fod_sdm845, hal_fingerprint)