From e7779bb46fbc34354af4440ee4737648ca80d4e6 Mon Sep 17 00:00:00 2001 From: LuK1337 Date: Mon, 22 Jun 2020 20:00:06 +0200 Subject: [PATCH] sm8250-common: Import FOD HAL from device/oneplus/sm8150-common --- BoardConfigCommon.mk | 5 + common.mk | 13 +- fod/Android.bp | 42 ++++ fod/FingerprintInscreen.cpp | 203 ++++++++++++++++++ fod/FingerprintInscreen.h | 76 +++++++ fod/FodExtension.cpp | 25 +++ ...print.inscreen@1.0-service.oneplus_kona.rc | 10 + fod/service.cpp | 50 +++++ framework_manifest.xml | 9 + lineage.dependencies | 4 + soong/Android.bp | 17 ++ soong/fod.go | 40 ++++ soong/main.go | 9 + 13 files changed, 501 insertions(+), 2 deletions(-) create mode 100644 fod/Android.bp create mode 100644 fod/FingerprintInscreen.cpp create mode 100644 fod/FingerprintInscreen.h create mode 100644 fod/FodExtension.cpp create mode 100644 fod/lineage.biometrics.fingerprint.inscreen@1.0-service.oneplus_kona.rc create mode 100644 fod/service.cpp create mode 100644 soong/Android.bp create mode 100644 soong/fod.go create mode 100644 soong/main.go diff --git a/BoardConfigCommon.mk b/BoardConfigCommon.mk index 04e1710..9c72b13 100644 --- a/BoardConfigCommon.mk +++ b/BoardConfigCommon.mk @@ -96,6 +96,11 @@ TARGET_ENABLE_MEDIADRM_64 := true # Filesystem TARGET_FS_CONFIG_GEN := $(COMMON_PATH)/config.fs +# Fingerprint +SOONG_CONFIG_NAMESPACES += ONEPLUS_KONA_FOD +SOONG_CONFIG_ONEPLUS_KONA_FOD := POS_X POS_Y SIZE +TARGET_SURFACEFLINGER_FOD_LIB := //$(COMMON_PATH):libfod_extension.oneplus_kona + # HIDL DEVICE_FRAMEWORK_MANIFEST_FILE := $(COMMON_PATH)/framework_manifest.xml diff --git a/common.mk b/common.mk index d274469..6c98259 100644 --- a/common.mk +++ b/common.mk @@ -41,7 +41,8 @@ PRODUCT_TARGET_VNDK_VERSION := 29 # Permissions PRODUCT_COPY_FILES += \ frameworks/native/data/etc/android.hardware.telephony.ims.xml:$(TARGET_COPY_OUT_SYSTEM)/etc/permissions/android.hardware.telephony.ims.xml \ - frameworks/native/data/etc/handheld_core_hardware.xml:$(TARGET_COPY_OUT_SYSTEM)/etc/permissions/handheld_core_hardware.xml + frameworks/native/data/etc/handheld_core_hardware.xml:$(TARGET_COPY_OUT_SYSTEM)/etc/permissions/handheld_core_hardware.xml \ + vendor/lineage/config/permissions/vendor.lineage.biometrics.fingerprint.inscreen.xml:$(TARGET_COPY_OUT_SYSTEM)/etc/permissions/vendor.lineage.biometrics.fingerprint.inscreen.xml # A/B AB_OTA_UPDATER := true @@ -108,6 +109,13 @@ PRODUCT_PACKAGES += \ PRODUCT_PACKAGES += \ OnePlusDoze +# Fingerprint +PRODUCT_PACKAGES += \ + android.hardware.biometrics.fingerprint@2.1-service.oneplus_kona \ + lineage.biometrics.fingerprint.inscreen@1.0-service.oneplus_kona \ + vendor.oneplus.fingerprint.extension@1.0 \ + vendor.oneplus.hardware.display@1.0 + # HotwordEnrollement app permissions PRODUCT_COPY_FILES += \ $(LOCAL_PATH)/configs/privapp-permissions-hotword.xml:$(TARGET_COPY_OUT_SYSTEM)/etc/permissions/privapp-permissions-hotword.xml @@ -158,7 +166,8 @@ PRODUCT_PACKAGES += \ # Soong namespaces PRODUCT_SOONG_NAMESPACES += \ - $(LOCAL_PATH) + $(LOCAL_PATH) \ + device/oneplus/common # Telephony PRODUCT_PACKAGES += \ diff --git a/fod/Android.bp b/fod/Android.bp new file mode 100644 index 0000000..abe63e0 --- /dev/null +++ b/fod/Android.bp @@ -0,0 +1,42 @@ +// +// 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. + +oneplus_kona_fod_hal_binary { + relative_install_path: "hw", + defaults: ["hidl_defaults"], + name: "lineage.biometrics.fingerprint.inscreen@1.0-service.oneplus_kona", + init_rc: ["lineage.biometrics.fingerprint.inscreen@1.0-service.oneplus_kona.rc"], + srcs: ["service.cpp", "FingerprintInscreen.cpp"], + shared_libs: [ + "libbase", + "libhardware", + "libhidlbase", + "libhidltransport", + "liblog", + "libhwbinder", + "libutils", + "vendor.lineage.biometrics.fingerprint.inscreen@1.0", + "//device/oneplus/common:vendor.oneplus.fingerprint.extension@1.0", + "//device/oneplus/common:vendor.oneplus.hardware.display@1.0", + ], +} + +cc_library_static { + name: "libfod_extension.oneplus_kona", + srcs: ["FodExtension.cpp"], + include_dirs: [ + "frameworks/native/services/surfaceflinger/CompositionEngine/include" + ], +} diff --git a/fod/FingerprintInscreen.cpp b/fod/FingerprintInscreen.cpp new file mode 100644 index 0000000..ed318a1 --- /dev/null +++ b/fod/FingerprintInscreen.cpp @@ -0,0 +1,203 @@ +/* + * 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_ERROR_CANCELED 5 +#define FINGERPRINT_ACQUIRED_VENDOR 6 +#define FINGERPRINT_ERROR_VENDOR 8 + +#define OP_ENABLE_FP_LONGPRESS 3 +#define OP_DISABLE_FP_LONGPRESS 4 +#define OP_RESUME_FP_ENROLL 8 +#define OP_FINISH_FP_ENROLL 10 + +#define OP_DISPLAY_AOD_MODE 8 +#define OP_DISPLAY_NOTIFY_PRESS 9 +#define OP_DISPLAY_SET_DIM 10 + +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; +} + +FingerprintInscreen::FingerprintInscreen() { + this->mFodCircleVisible = false; + this->mIsEnrolling = false; + this->mVendorFpService = IVendorFingerprintExtensions::getService(); + this->mVendorDisplayService = IOneplusDisplay::getService(); +} + +Return FingerprintInscreen::onStartEnroll() { + this->mIsEnrolling = true; + this->mVendorFpService->updateStatus(OP_DISABLE_FP_LONGPRESS); + this->mVendorFpService->updateStatus(OP_RESUME_FP_ENROLL); + + return Void(); +} + +Return FingerprintInscreen::onFinishEnroll() { + this->mIsEnrolling = false; + this->mVendorFpService->updateStatus(OP_FINISH_FP_ENROLL); + + return Void(); +} + +Return FingerprintInscreen::onPress() { + if (mIsEnrolling) { + this->mVendorDisplayService->setMode(OP_DISPLAY_SET_DIM, 1); + } + this->mVendorDisplayService->setMode(OP_DISPLAY_NOTIFY_PRESS, 1); + + return Void(); +} + +Return FingerprintInscreen::onRelease() { + this->mVendorDisplayService->setMode(OP_DISPLAY_SET_DIM, 0); + this->mVendorDisplayService->setMode(OP_DISPLAY_NOTIFY_PRESS, 0); + + return Void(); +} + +Return FingerprintInscreen::onShowFODView() { + this->mFodCircleVisible = true; + this->mVendorDisplayService->setMode(OP_DISPLAY_AOD_MODE, 0); + this->mVendorDisplayService->setMode(OP_DISPLAY_SET_DIM, 0); + this->mVendorDisplayService->setMode(OP_DISPLAY_NOTIFY_PRESS, 0); + + return Void(); +} + +Return FingerprintInscreen::onHideFODView() { + this->mFodCircleVisible = false; + this->mVendorDisplayService->setMode(OP_DISPLAY_AOD_MODE, 0); + this->mVendorDisplayService->setMode(OP_DISPLAY_SET_DIM, 0); + this->mVendorDisplayService->setMode(OP_DISPLAY_NOTIFY_PRESS, 0); + + 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 (mFodCircleVisible && vendorCode == 0) { + Return ret = mCallback->onFingerDown(); + if (!ret.isOk()) { + LOG(ERROR) << "FingerDown() error: " << ret.description(); + } + return true; + } + + if (mFodCircleVisible && vendorCode == 1) { + Return ret = mCallback->onFingerUp(); + if (!ret.isOk()) { + LOG(ERROR) << "FingerUp() error: " << ret.description(); + } + return true; + } + } + + return false; +} + +Return FingerprintInscreen::handleError(int32_t error, int32_t vendorCode) { + switch (error) { + case FINGERPRINT_ERROR_CANCELED: + if (vendorCode == 0) { + this->mIsEnrolling = false; + } + return false; + case FINGERPRINT_ERROR_VENDOR: + // Ignore vendorCode 6 + return vendorCode == 6; + default: + return false; + } +} + +Return FingerprintInscreen::setLongPressEnabled(bool enabled) { + this->mVendorFpService->updateStatus( + enabled ? OP_ENABLE_FP_LONGPRESS : OP_DISABLE_FP_LONGPRESS); + + return Void(); +} + +Return FingerprintInscreen::getDimAmount(int32_t) { + return 0; +} + +Return FingerprintInscreen::shouldBoostBrightness() { + return false; +} + +Return FingerprintInscreen::setCallback(const sp& callback) { + { + std::lock_guard _lock(mCallbackLock); + mCallback = callback; + } + + return Void(); +} + +Return FingerprintInscreen::getPositionX() { + return FOD_POS_X; +} + +Return FingerprintInscreen::getPositionY() { + return FOD_POS_Y; +} + +Return FingerprintInscreen::getSize() { + return FOD_SIZE; +} + +} // 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..b322c26 --- /dev/null +++ b/fod/FingerprintInscreen.h @@ -0,0 +1,76 @@ +/* + * 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 +#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::oneplus::fingerprint::extension::V1_0::IVendorFingerprintExtensions; +using ::vendor::oneplus::hardware::display::V1_0::IOneplusDisplay; + +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: + bool mFodCircleVisible; + bool mIsEnrolling; + + sp mVendorDisplayService; + sp mVendorFpService; + + std::mutex mCallbackLock; + sp mCallback; +}; + +} // 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/FodExtension.cpp b/fod/FodExtension.cpp new file mode 100644 index 0000000..8dcea16 --- /dev/null +++ b/fod/FodExtension.cpp @@ -0,0 +1,25 @@ +/* + * 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. + */ + +#include + +uint32_t getFodZOrder(uint32_t, bool touched) { + return touched ? 0xfc8 : 0xbd6; +} + +uint64_t getFodUsageBits(uint64_t usageBits, bool) { + return usageBits; +} diff --git a/fod/lineage.biometrics.fingerprint.inscreen@1.0-service.oneplus_kona.rc b/fod/lineage.biometrics.fingerprint.inscreen@1.0-service.oneplus_kona.rc new file mode 100644 index 0000000..c1d05fb --- /dev/null +++ b/fod/lineage.biometrics.fingerprint.inscreen@1.0-service.oneplus_kona.rc @@ -0,0 +1,10 @@ +on init + chown system system /sys/class/drm/card0-DSI-1/op_friginer_print_hbm + chmod 0660 /sys/class/drm/card0-DSI-1/op_friginer_print_hbm + +service fingerprint-inscreen-1-0 /system/bin/hw/lineage.biometrics.fingerprint.inscreen@1.0-service.oneplus_kona + interface vendor.lineage.biometrics.fingerprint.inscreen@1.0::IFingerprintInscreen default + class hal + user system + group system + shutdown critical diff --git a/fod/service.cpp b/fod/service.cpp new file mode 100644 index 0000000..20abb80 --- /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.oneplus_kona" + +#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/framework_manifest.xml b/framework_manifest.xml index 4f741dc..583c61b 100644 --- a/framework_manifest.xml +++ b/framework_manifest.xml @@ -1,4 +1,13 @@ + + vendor.lineage.biometrics.fingerprint.inscreen + hwbinder + 1.0 + + IFingerprintInscreen + default + + vendor.lineage.livedisplay hwbinder diff --git a/lineage.dependencies b/lineage.dependencies index 96ff27f..2e4b00c 100644 --- a/lineage.dependencies +++ b/lineage.dependencies @@ -1,4 +1,8 @@ [ + { + "repository": "android_device_oneplus_common", + "target_path": "device/oneplus/common" + }, { "repository": "android_kernel_oneplus_sm8250", "target_path": "kernel/oneplus/sm8250" diff --git a/soong/Android.bp b/soong/Android.bp new file mode 100644 index 0000000..fa070e6 --- /dev/null +++ b/soong/Android.bp @@ -0,0 +1,17 @@ +bootstrap_go_package { + name: "soong-oneplus-kona-plugins", + pkgPath: "device/oneplus/sm8250-common", + deps: [ + "blueprint", + "blueprint-pathtools", + "soong", + "soong-android", + "soong-cc", + "soong-genrule", + ], + srcs: [ + "fod.go", + "main.go", + ], + pluginFor: ["soong_build"], +} diff --git a/soong/fod.go b/soong/fod.go new file mode 100644 index 0000000..00679d7 --- /dev/null +++ b/soong/fod.go @@ -0,0 +1,40 @@ +package kona + +import ( + "android/soong/android" + "android/soong/cc" + "strings" +) + +func fodFlags(ctx android.BaseContext) []string { + var cflags []string + + var config = ctx.AConfig().VendorConfig("ONEPLUS_KONA_FOD") + var posX = strings.TrimSpace(config.String("POS_X")) + var posY = strings.TrimSpace(config.String("POS_Y")) + var size = strings.TrimSpace(config.String("SIZE")) + + cflags = append(cflags, "-DFOD_POS_X=" + posX, "-DFOD_POS_Y=" + posY, "-DFOD_SIZE=" + size) + return cflags +} + +func fodHalBinary(ctx android.LoadHookContext) { + type props struct { + Target struct { + Android struct { + Cflags []string + } + } + } + + p := &props{} + p.Target.Android.Cflags = fodFlags(ctx) + ctx.AppendProperties(p) +} + +func fodHalBinaryFactory() android.Module { + module, _ := cc.NewBinary(android.HostAndDeviceSupported) + newMod := module.Init() + android.AddLoadHook(newMod, fodHalBinary) + return newMod +} diff --git a/soong/main.go b/soong/main.go new file mode 100644 index 0000000..bc1d727 --- /dev/null +++ b/soong/main.go @@ -0,0 +1,9 @@ +package kona + +import ( + "android/soong/android" +) + +func init() { + android.RegisterModuleType("oneplus_kona_fod_hal_binary", fodHalBinaryFactory) +}