diff --git a/common.mk b/common.mk index 5d81db9..9bbf887 100644 --- a/common.mk +++ b/common.mk @@ -146,6 +146,10 @@ PRODUCT_PACKAGES += \ android.hardware.drm@1.3-service.clearkey \ libdrmclearkeyplugin +# Fingerprint +PRODUCT_PACKAGES += \ + vendor.lineage.biometrics.fingerprint.inscreen@1.0-service.samsung.sm7125 + # fastbootd PRODUCT_PACKAGES += \ fastbootd @@ -276,7 +280,8 @@ PRODUCT_COPY_FILES += \ frameworks/native/data/etc/android.software.verified_boot.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.software.verified_boot.xml \ frameworks/native/data/etc/android.software.vulkan.deqp.level-2020-03-01.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.software.vulkan.deqp.level.xml \ frameworks/native/data/etc/com.nxp.mifare.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/com.nxp.mifare.xml \ - frameworks/native/data/etc/handheld_core_hardware.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/handheld_core_hardware.xml + frameworks/native/data/etc/handheld_core_hardware.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/handheld_core_hardware.xml \ + vendor/lineage/config/permissions/vendor.lineage.biometrics.fingerprint.inscreen.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/vendor.lineage.biometrics.fingerprint.inscreen.xml # Power PRODUCT_PACKAGES += \ diff --git a/configs/framework_compatibility_matrix.xml b/configs/framework_compatibility_matrix.xml index 16e5057..aa2986d 100644 --- a/configs/framework_compatibility_matrix.xml +++ b/configs/framework_compatibility_matrix.xml @@ -74,6 +74,14 @@ gnss_vendor + + vendor.lineage.biometrics.fingerprint.inscreen + 1.0 + + IFingerprintInscreen + default + + android.hardware.keymaster 4.0 diff --git a/fod/Android.mk b/fod/Android.mk new file mode 100644 index 0000000..107d202 --- /dev/null +++ b/fod/Android.mk @@ -0,0 +1,45 @@ +# +# Copyright (C) 2020 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. +# + +LOCAL_PATH := $(call my-dir) + +include $(CLEAR_VARS) + +LOCAL_SRC_FILES := \ + FingerprintInscreen.cpp \ + service.cpp + +LOCAL_C_INCLUDES := $(LOCAL_PATH)/include + +LOCAL_SHARED_LIBRARIES := \ + libbase \ + libhardware \ + libhidlbase \ + liblog \ + libhwbinder \ + libutils \ + vendor.lineage.biometrics.fingerprint.inscreen@1.0 \ + vendor.samsung.hardware.biometrics.fingerprint@3.0 + +LOCAL_MODULE := vendor.lineage.biometrics.fingerprint.inscreen@1.0-service.samsung.sm7125 +LOCAL_INIT_RC := vendor.lineage.biometrics.fingerprint.inscreen@1.0-service.samsung.sm7125.rc +LOCAL_MODULE_RELATIVE_PATH := hw +LOCAL_MODULE_TAGS := optional +LOCAL_MODULE_OWNER := samsung +LOCAL_VINTF_FRAGMENTS := vendor.lineage.biometrics.fingerprint.inscreen@1.0-service.samsung.sm7125.xml +LOCAL_VENDOR_MODULE := true + +include $(BUILD_EXECUTABLE) diff --git a/fod/FingerprintInscreen.cpp b/fod/FingerprintInscreen.cpp new file mode 100644 index 0000000..c05933c --- /dev/null +++ b/fod/FingerprintInscreen.cpp @@ -0,0 +1,194 @@ +/* + * 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 FINGERPRINT_ACQUIRED_VENDOR 6 + +#define BRIGHTNESS_PATH "/sys/class/backlight/panel0-backlight/brightness" +#define TSP_CMD_PATH "/sys/class/sec/tsp/cmd" + +#define SEM_FINGER_STATE 22 +#define SEM_PARAM_PRESSED 2 +#define SEM_PARAM_RELEASED 1 +#define SEM_AOSP_FQNAME "android.hardware.biometrics.fingerprint@2.1::IBiometricsFingerprint" + +namespace vendor { +namespace lineage { +namespace biometrics { +namespace fingerprint { +namespace inscreen { +namespace V1_0 { +namespace implementation { + +/* + * Write value to path and close file. + */ +template +static void set(const std::string& path, const T& value) { + std::ofstream file(path); + file << value; +} + +template +static T get(const std::string& path, const T& def) { + std::ifstream file(path); + T result; + + file >> result; + return file.fail() ? def : result; +} + +static hidl_vec stringToVec(const std::string& str) { + auto vec = hidl_vec(); + vec.resize(str.size() + 1); + for (size_t i = 0; i < str.size(); ++i) { + vec[i] = (int8_t) str[i]; + } + vec[str.size()] = '\0'; + return vec; +} + +FingerprintInscreen::FingerprintInscreen() { + mSehBiometricsFingerprintService = ISehBiometricsFingerprint::getService(); +} + +void FingerprintInscreen::requestResult(int, const hidl_vec&) { + // Ignore all results +} + +Return FingerprintInscreen::onStartEnroll() { + return Void(); +} + +Return FingerprintInscreen::onFinishEnroll() { + return Void(); +} + +Return FingerprintInscreen::onPress() { + mPreviousBrightness = get(BRIGHTNESS_PATH, ""); + set(BRIGHTNESS_PATH, "425"); + set(TSP_CMD_PATH, "fod_enable,1,1,0"); + mSehBiometricsFingerprintService->sehRequest(SEM_FINGER_STATE, + SEM_PARAM_PRESSED, stringToVec(SEM_AOSP_FQNAME), FingerprintInscreen::requestResult); + return Void(); +} + +Return FingerprintInscreen::onRelease() { + mSehBiometricsFingerprintService->sehRequest(SEM_FINGER_STATE, + SEM_PARAM_RELEASED, stringToVec(SEM_AOSP_FQNAME), FingerprintInscreen::requestResult); + set(TSP_CMD_PATH, "fod_enable,0"); + if (!mPreviousBrightness.empty()) { + set(BRIGHTNESS_PATH, mPreviousBrightness); + mPreviousBrightness = ""; + } + return Void(); +} + +Return FingerprintInscreen::onShowFODView() { + return Void(); +} + +Return FingerprintInscreen::onHideFODView() { + set(TSP_CMD_PATH, "fod_enable,0"); + if (!mPreviousBrightness.empty()) { + set(BRIGHTNESS_PATH, mPreviousBrightness); + mPreviousBrightness = ""; + } + return Void(); +} + +Return FingerprintInscreen::handleAcquired(int32_t acquiredInfo, int32_t vendorCode) { + std::lock_guard _lock(mCallbackLock); + if (mCallback == nullptr) { + return false; + } + + if (acquiredInfo == FINGERPRINT_ACQUIRED_VENDOR) { + if (vendorCode == 10002) { + Return ret = mCallback->onFingerDown(); + if (!ret.isOk()) { + LOG(ERROR) << "FingerDown() error: " << ret.description(); + } + return true; + } else if (vendorCode == 10001) { + Return ret = mCallback->onFingerUp(); + if (!ret.isOk()) { + LOG(ERROR) << "FingerUp() error: " << ret.description(); + } + return true; + } + } + LOG(ERROR) << "acquiredInfo: " << acquiredInfo << ", vendorCode: " << vendorCode << "\n"; + return false; +} + +Return FingerprintInscreen::handleError(int32_t, int32_t) { + return false; +} + +Return FingerprintInscreen::setLongPressEnabled(bool) { + return Void(); +} + +Return FingerprintInscreen::getDimAmount(int32_t cur_brightness) { + if (cur_brightness <= 12) { + return 2200 / std::max(cur_brightness, 10); + } else if (cur_brightness <= 16) { + return 3000 / cur_brightness; + } else if (cur_brightness <= 20) { + return 3700 / cur_brightness; + } else { + return 4400 / cur_brightness; + } +} + +Return FingerprintInscreen::shouldBoostBrightness() { + return false; +} + +Return FingerprintInscreen::setCallback(const sp& callback) { + { + std::lock_guard _lock(mCallbackLock); + mCallback = callback; + } + return Void(); +} + +Return FingerprintInscreen::getPositionX() { + return 440; +} + +Return FingerprintInscreen::getPositionY() { + return 2020; +} + +Return FingerprintInscreen::getSize() { + return 200; +} + +} // 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..8e557a4 --- /dev/null +++ b/fod/FingerprintInscreen.h @@ -0,0 +1,73 @@ +/* + * 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 ::android::hardware::hidl_vec; +using ::vendor::samsung::hardware::biometrics::fingerprint::V3_0::ISehBiometricsFingerprint; + +class FingerprintInscreen : public IFingerprintInscreen { + public: + FingerprintInscreen(); + + 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 cur_brightness) override; + Return shouldBoostBrightness() override; + Return setCallback(const sp& callback) override; + Return getPositionX() override; + Return getPositionY() override; + Return getSize() override; + + private: + sp mSehBiometricsFingerprintService; + std::mutex mCallbackLock; + sp mCallback; + std::string mPreviousBrightness; + + static void requestResult(int retval, const hidl_vec& outBuf); +}; + +} // 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..7983144 --- /dev/null +++ b/fod/service.cpp @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2020 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.samsung.sm7125" + +#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.samsung.sm7125.rc b/fod/vendor.lineage.biometrics.fingerprint.inscreen@1.0-service.samsung.sm7125.rc new file mode 100644 index 0000000..490119a --- /dev/null +++ b/fod/vendor.lineage.biometrics.fingerprint.inscreen@1.0-service.samsung.sm7125.rc @@ -0,0 +1,9 @@ +service vendor.fingerprint-inscreen-1-0 /vendor/bin/hw/vendor.lineage.biometrics.fingerprint.inscreen@1.0-service.samsung.sm7125 + interface vendor.lineage.biometrics.fingerprint.inscreen@1.0::IFingerprintInscreen default + class hal + user system + group system + shutdown critical + +on boot + chown system system /sys/class/sec/tsp/cmd diff --git a/fod/vendor.lineage.biometrics.fingerprint.inscreen@1.0-service.samsung.sm7125.xml b/fod/vendor.lineage.biometrics.fingerprint.inscreen@1.0-service.samsung.sm7125.xml new file mode 100644 index 0000000..e03c70c --- /dev/null +++ b/fod/vendor.lineage.biometrics.fingerprint.inscreen@1.0-service.samsung.sm7125.xml @@ -0,0 +1,11 @@ + + + vendor.lineage.biometrics.fingerprint.inscreen + hwbinder + 1.0 + + IFingerprintInscreen + default + + + diff --git a/interfaces/Android.bp b/interfaces/Android.bp new file mode 100644 index 0000000..337a0c4 --- /dev/null +++ b/interfaces/Android.bp @@ -0,0 +1,4 @@ +hidl_package_root { + name: "vendor.samsung.hardware", + path: "device/samsung/sm7125-common/interfaces", +} diff --git a/interfaces/biometrics/fingerprint/3.0/Android.bp b/interfaces/biometrics/fingerprint/3.0/Android.bp new file mode 100644 index 0000000..059fbfe --- /dev/null +++ b/interfaces/biometrics/fingerprint/3.0/Android.bp @@ -0,0 +1,14 @@ +// This file is autogenerated by hidl-gen -Landroidbp. + +hidl_interface { + name: "vendor.samsung.hardware.biometrics.fingerprint@3.0", + root: "vendor.samsung.hardware", + srcs: [ + "ISehBiometricsFingerprint.hal", + ], + interfaces: [ + "android.hardware.biometrics.fingerprint@2.1", + "android.hidl.base@1.0", + ], + gen_java: true, +} diff --git a/interfaces/biometrics/fingerprint/3.0/ISehBiometricsFingerprint.hal b/interfaces/biometrics/fingerprint/3.0/ISehBiometricsFingerprint.hal new file mode 100644 index 0000000..0b65edd --- /dev/null +++ b/interfaces/biometrics/fingerprint/3.0/ISehBiometricsFingerprint.hal @@ -0,0 +1,7 @@ +package vendor.samsung.hardware.biometrics.fingerprint@3.0; + +import android.hardware.biometrics.fingerprint@2.1::IBiometricsFingerprint; + +interface ISehBiometricsFingerprint extends android.hardware.biometrics.fingerprint@2.1::IBiometricsFingerprint { + sehRequest(int32_t cmdId, int32_t inParam, vec inBuf) generates (int32_t retval, vec outBuf); +}; diff --git a/proprietary-files.txt b/proprietary-files.txt index a3deaad..95511fa 100644 --- a/proprietary-files.txt +++ b/proprietary-files.txt @@ -657,6 +657,10 @@ vendor/lib64/libsecnativefeature.so vendor/etc/floating_feature.xml # Fingerprint +vendor/bin/hw/vendor.samsung.hardware.biometrics.fingerprint@3.0-service +vendor/etc/init/vendor.samsung.hardware.biometrics.fingerprint@3.0-service.rc +vendor/lib/hw/fingerprint.default.so +vendor/lib64/hw/fingerprint.default.so vendor/lib/libbauthserver.so vendor/lib64/libbauthserver.so vendor/lib/libbauthtzcommon.so diff --git a/rootdir/etc/init.target.rc b/rootdir/etc/init.target.rc index b49653d..30708fa 100644 --- a/rootdir/etc/init.target.rc +++ b/rootdir/etc/init.target.rc @@ -131,6 +131,8 @@ on post-fs-data # For cpusets initialize for Silver Only first and then Silver + Gold # Silver Only configuration cannot work with 0-7 on boot + chown system system /sys/class/lcd/panel/mask_brightness + write /dev/cpuset/audio-app/cpus 1-2 chown system system /sys/kernel/hbtp/display_pwr start rmt_storage diff --git a/sepolicy/vendor/file_contexts b/sepolicy/vendor/file_contexts index 755418d..acf92a1 100644 --- a/sepolicy/vendor/file_contexts +++ b/sepolicy/vendor/file_contexts @@ -18,3 +18,5 @@ /(vendor|system/vendor)/bin/hw/vendor\.lineage\.fastcharge@1\.0-service\.samsung u:object_r:hal_lineage_fastcharge_default_exec:s0 /(vendor|system/vendor)/bin/hw/vendor\.lineage\.touch@1\.0-service\.samsung u:object_r:hal_lineage_touch_default_exec:s0 /(vendor|system/vendor)/bin/hw/vendor\.lineage\.livedisplay@2\.0-service.samsung-qcom\.sm7125 u:object_r:hal_lineage_livedisplay_sysfs_exec:s0 +/(vendor|system/vendor)/bin/hw/vendor.samsung.hardware.biometrics.fingerprint@3.0-service u:object_r:hal_fingerprint_default_exec:s0 +/(vendor|system/vendor)/bin/hw/vendor.lineage.biometrics.fingerprint.inscreen@1.0-service.samsung.sm7125 u:object_r:hal_lineage_fod_default_exec:s0