From a6624039b5b8c9a1fff16bb6e2c094ca0070b536 Mon Sep 17 00:00:00 2001 From: SebaUbuntu Date: Sat, 28 May 2022 22:47:16 +0200 Subject: [PATCH] sm7250-common: Move to common Xiaomi fingerprint HIDL Change-Id: I6c29a831e985ee440c92a98aad8d33f25b9e5b2d --- BoardConfigCommon.mk | 2 +- biometrics/Android.bp | 44 -- biometrics/BiometricsFingerprint.cpp | 452 ------------------ biometrics/BiometricsFingerprint.h | 97 ---- ...cs.fingerprint@2.3-service.xiaomi_lito.xml | 20 - biometrics/service.cpp | 59 --- biometrics/xiaomi_fingerprint.h | 172 ------- fod/Android.bp | 16 - fod/UdfpsExtension.cpp | 19 - lito.mk | 10 +- rootdir/Android.bp | 7 + .../etc/init.fingerprint.rc | 11 - rootdir/etc/init.qcom.rc | 1 + sepolicy/vendor/file_contexts | 2 +- sepolicy/vendor/hwservice_contexts | 1 - 15 files changed, 14 insertions(+), 899 deletions(-) delete mode 100644 biometrics/Android.bp delete mode 100644 biometrics/BiometricsFingerprint.cpp delete mode 100644 biometrics/BiometricsFingerprint.h delete mode 100644 biometrics/android.hardware.biometrics.fingerprint@2.3-service.xiaomi_lito.xml delete mode 100644 biometrics/service.cpp delete mode 100644 biometrics/xiaomi_fingerprint.h delete mode 100644 fod/Android.bp delete mode 100644 fod/UdfpsExtension.cpp rename biometrics/android.hardware.biometrics.fingerprint@2.3-service.xiaomi_lito.rc => rootdir/etc/init.fingerprint.rc (82%) diff --git a/BoardConfigCommon.mk b/BoardConfigCommon.mk index 59c3714..952d4bb 100644 --- a/BoardConfigCommon.mk +++ b/BoardConfigCommon.mk @@ -79,7 +79,7 @@ SOONG_CONFIG_XIAOMI_LITO_FINGERPRINT := FOD SOONG_CONFIG_XIAOMI_LITO_FINGERPRINT_FOD ?= false ifeq ($(TARGET_HAS_FOD),true) SOONG_CONFIG_XIAOMI_LITO_FINGERPRINT_FOD := true -TARGET_SURFACEFLINGER_UDFPS_LIB := //$(COMMON_PATH):libudfps_extension.xiaomi_lito +TARGET_SURFACEFLINGER_UDFPS_LIB := //hardware/xiaomi:libudfps_extension.xiaomi endif # FM diff --git a/biometrics/Android.bp b/biometrics/Android.bp deleted file mode 100644 index 6e77a5d..0000000 --- a/biometrics/Android.bp +++ /dev/null @@ -1,44 +0,0 @@ -soong_config_module_type { - name: "xiaomi_lito_fingerprint_hal_cc_defaults", - module_type: "cc_defaults", - config_namespace: "XIAOMI_LITO_FINGERPRINT", - bool_variables: ["FOD"], - properties: ["cppflags"], -} - -xiaomi_lito_fingerprint_hal_cc_defaults { - name: "xiaomi_lito_fingerprint_hal_defaults", - soong_config_variables: { - FOD: { - cppflags: ["-DFOD"], - }, - }, -} - -cc_binary { - name: "android.hardware.biometrics.fingerprint@2.3-service.xiaomi_lito", - defaults: [ - "hidl_defaults", - "xiaomi_lito_fingerprint_hal_defaults", - ], - relative_install_path: "hw", - init_rc: ["android.hardware.biometrics.fingerprint@2.3-service.xiaomi_lito.rc"], - vintf_fragments: ["android.hardware.biometrics.fingerprint@2.3-service.xiaomi_lito.xml"], - srcs: [ - "BiometricsFingerprint.cpp", - "service.cpp", - ], - shared_libs: [ - "libbase", - "libcutils", - "liblog", - "libhidlbase", - "libhardware", - "libutils", - "android.hardware.biometrics.fingerprint@2.1", - "android.hardware.biometrics.fingerprint@2.2", - "android.hardware.biometrics.fingerprint@2.3", - "//hardware/xiaomi:vendor.xiaomi.hardware.fingerprintextension@1.0", - ], - vendor: true, -} diff --git a/biometrics/BiometricsFingerprint.cpp b/biometrics/BiometricsFingerprint.cpp deleted file mode 100644 index 96f0ebe..0000000 --- a/biometrics/BiometricsFingerprint.cpp +++ /dev/null @@ -1,452 +0,0 @@ -/* - * Copyright (C) 2017 The Android Open Source Project - * Copyright (C) 2021 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 "android.hardware.biometrics.fingerprint@2.3-service.xiaomi_lito" -#define LOG_VERBOSE "android.hardware.biometrics.fingerprint@2.3-service.xiaomi_lito" - -#include -#include - -#include "xiaomi_fingerprint.h" -#include "BiometricsFingerprint.h" - -#include -#include -#include -#include - -namespace android { -namespace hardware { -namespace biometrics { -namespace fingerprint { -namespace V2_3 { -namespace implementation { - -// Supported fingerprint HAL version -static const uint16_t kVersion = HARDWARE_MODULE_API_VERSION(2, 1); - -// List of fingerprint HALs -static const char *kHALClasses[] = { - "fpc", - "goodix_fod", - "goodix_fod6", -}; - -using RequestStatus = - android::hardware::biometrics::fingerprint::V2_1::RequestStatus; - -BiometricsFingerprint *BiometricsFingerprint::sInstance = nullptr; - -#define COMMAND_NIT 10 -#define PARAM_NIT_FOD 1 -#define PARAM_NIT_NONE 0 - -#define FOD_UI_PATH "/sys/devices/platform/soc/soc:qcom,dsi-display-primary/fod_ui" - -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'; -} - -BiometricsFingerprint::BiometricsFingerprint() : mClientCallback(nullptr), mDevice(nullptr) { - sInstance = this; // keep track of the most recent instance - for (const auto& class_name : kHALClasses) { - mDevice = openHal(class_name); - if (!mDevice) { - ALOGE("Can't open HAL module, class %s", class_name); - } else { - ALOGI("Opened fingerprint HAL, class %s", class_name); - break; - } - } - -#ifdef FOD - 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; - } - - extCmd(COMMAND_NIT, readBool(fd) ? PARAM_NIT_FOD : PARAM_NIT_NONE); - } - }).detach(); -#endif -} - -BiometricsFingerprint::~BiometricsFingerprint() { - ALOGV("~BiometricsFingerprint()"); - if (mDevice == nullptr) { - ALOGE("No valid device"); - return; - } - int err; - if (0 != (err = mDevice->common.close( - reinterpret_cast(mDevice)))) { - ALOGE("Can't close fingerprint module, error: %d", err); - return; - } - mDevice = nullptr; -} - -Return BiometricsFingerprint::ErrorFilter(int32_t error) { - switch(error) { - case 0: return RequestStatus::SYS_OK; - case -2: return RequestStatus::SYS_ENOENT; - case -4: return RequestStatus::SYS_EINTR; - case -5: return RequestStatus::SYS_EIO; - case -11: return RequestStatus::SYS_EAGAIN; - case -12: return RequestStatus::SYS_ENOMEM; - case -13: return RequestStatus::SYS_EACCES; - case -14: return RequestStatus::SYS_EFAULT; - case -16: return RequestStatus::SYS_EBUSY; - case -22: return RequestStatus::SYS_EINVAL; - case -28: return RequestStatus::SYS_ENOSPC; - case -110: return RequestStatus::SYS_ETIMEDOUT; - default: - ALOGE("An unknown error returned from fingerprint vendor library: %d", error); - return RequestStatus::SYS_UNKNOWN; - } -} - -// Translate from errors returned by traditional HAL (see fingerprint.h) to -// HIDL-compliant FingerprintError. -FingerprintError BiometricsFingerprint::VendorErrorFilter(int32_t error, - int32_t* vendorCode) { - *vendorCode = 0; - switch(error) { - case FINGERPRINT_ERROR_HW_UNAVAILABLE: - return FingerprintError::ERROR_HW_UNAVAILABLE; - case FINGERPRINT_ERROR_UNABLE_TO_PROCESS: - return FingerprintError::ERROR_UNABLE_TO_PROCESS; - case FINGERPRINT_ERROR_TIMEOUT: - return FingerprintError::ERROR_TIMEOUT; - case FINGERPRINT_ERROR_NO_SPACE: - return FingerprintError::ERROR_NO_SPACE; - case FINGERPRINT_ERROR_CANCELED: - return FingerprintError::ERROR_CANCELED; - case FINGERPRINT_ERROR_UNABLE_TO_REMOVE: - return FingerprintError::ERROR_UNABLE_TO_REMOVE; - case FINGERPRINT_ERROR_LOCKOUT: - return FingerprintError::ERROR_LOCKOUT; - default: - if (error >= FINGERPRINT_ERROR_VENDOR_BASE) { - // vendor specific code. - *vendorCode = error - FINGERPRINT_ERROR_VENDOR_BASE; - return FingerprintError::ERROR_VENDOR; - } - } - ALOGE("Unknown error from fingerprint vendor library: %d", error); - return FingerprintError::ERROR_UNABLE_TO_PROCESS; -} - -// Translate acquired messages returned by traditional HAL (see fingerprint.h) -// to HIDL-compliant FingerprintAcquiredInfo. -FingerprintAcquiredInfo BiometricsFingerprint::VendorAcquiredFilter( - int32_t info, int32_t* vendorCode) { - *vendorCode = 0; - switch(info) { - case FINGERPRINT_ACQUIRED_GOOD: - return FingerprintAcquiredInfo::ACQUIRED_GOOD; - case FINGERPRINT_ACQUIRED_PARTIAL: - return FingerprintAcquiredInfo::ACQUIRED_PARTIAL; - case FINGERPRINT_ACQUIRED_INSUFFICIENT: - return FingerprintAcquiredInfo::ACQUIRED_INSUFFICIENT; - case FINGERPRINT_ACQUIRED_IMAGER_DIRTY: - return FingerprintAcquiredInfo::ACQUIRED_IMAGER_DIRTY; - case FINGERPRINT_ACQUIRED_TOO_SLOW: - return FingerprintAcquiredInfo::ACQUIRED_TOO_SLOW; - case FINGERPRINT_ACQUIRED_TOO_FAST: - return FingerprintAcquiredInfo::ACQUIRED_TOO_FAST; - default: - if (info >= FINGERPRINT_ACQUIRED_VENDOR_BASE) { - // vendor specific code. - *vendorCode = info - FINGERPRINT_ACQUIRED_VENDOR_BASE; - return FingerprintAcquiredInfo::ACQUIRED_VENDOR; - } - } - ALOGE("Unknown acquiredmsg from fingerprint vendor library: %d", info); - return FingerprintAcquiredInfo::ACQUIRED_INSUFFICIENT; -} - -Return BiometricsFingerprint::setNotify( - const sp& clientCallback) { - std::lock_guard lock(mClientCallbackMutex); - mClientCallback = clientCallback; - // This is here because HAL 2.1 doesn't have a way to propagate a - // unique token for its driver. Subsequent versions should send a unique - // token for each call to setNotify(). This is fine as long as there's only - // one fingerprint device on the platform. - return reinterpret_cast(mDevice); -} - -Return BiometricsFingerprint::preEnroll() { - return mDevice->pre_enroll(mDevice); -} - -Return BiometricsFingerprint::enroll(const hidl_array& hat, - uint32_t gid, uint32_t timeoutSec) { - const hw_auth_token_t* authToken = - reinterpret_cast(hat.data()); - return ErrorFilter(mDevice->enroll(mDevice, authToken, gid, timeoutSec)); -} - -Return BiometricsFingerprint::postEnroll() { - return ErrorFilter(mDevice->post_enroll(mDevice)); -} - -Return BiometricsFingerprint::getAuthenticatorId() { - return mDevice->get_authenticator_id(mDevice); -} - -Return BiometricsFingerprint::cancel() { - return ErrorFilter(mDevice->cancel(mDevice)); -} - -Return BiometricsFingerprint::enumerate() { - return ErrorFilter(mDevice->enumerate(mDevice)); -} - -Return BiometricsFingerprint::remove(uint32_t gid, uint32_t fid) { - return ErrorFilter(mDevice->remove(mDevice, gid, fid)); -} - -Return BiometricsFingerprint::setActiveGroup(uint32_t gid, - const hidl_string& storePath) { - if (storePath.size() >= PATH_MAX || storePath.size() <= 0) { - ALOGE("Bad path length: %zd", storePath.size()); - return RequestStatus::SYS_EINVAL; - } - if (access(storePath.c_str(), W_OK)) { - return RequestStatus::SYS_EINVAL; - } - - return ErrorFilter(mDevice->set_active_group(mDevice, gid, - storePath.c_str())); -} - -Return BiometricsFingerprint::authenticate(uint64_t operationId, - uint32_t gid) { - return ErrorFilter(mDevice->authenticate(mDevice, operationId, gid)); -} - -IBiometricsFingerprint* BiometricsFingerprint::getInstance() { - if (!sInstance) { - sInstance = new BiometricsFingerprint(); - } - return sInstance; -} - -IXiaomiFingerprint* BiometricsFingerprint::getXiaomiInstance() { - if (!sInstance) { - sInstance = new BiometricsFingerprint(); - } - return sInstance; -} - -xiaomi_fingerprint_device_t* BiometricsFingerprint::openHal(const char *class_name) { - int err; - const hw_module_t *hw_mdl = nullptr; - ALOGD("Opening fingerprint hal library..."); - if (0 != (err = hw_get_module_by_class(FINGERPRINT_HARDWARE_MODULE_ID, class_name, &hw_mdl))) { - ALOGE("Can't open fingerprint HW Module, class %s, error: %d", class_name, err); - return nullptr; - } - - if (hw_mdl == nullptr) { - ALOGE("No valid fingerprint module, class %s", class_name); - return nullptr; - } - - fingerprint_module_t const *module = - reinterpret_cast(hw_mdl); - if (module->common.methods->open == nullptr) { - ALOGE("No valid open method, class %s", class_name); - return nullptr; - } - - hw_device_t *device = nullptr; - - if (0 != (err = module->common.methods->open(hw_mdl, nullptr, &device))) { - ALOGE("Can't open fingerprint methods, class %s, error: %d", class_name, err); - return nullptr; - } - - if (kVersion != device->version) { - // enforce version on new devices because of HIDL@2.1 translation layer - ALOGE("Wrong fp version, class %s. Expected %d, got %d", class_name, kVersion, device->version); - return nullptr; - } - - xiaomi_fingerprint_device_t* fp_device = - reinterpret_cast(device); - - if (0 != (err = - fp_device->set_notify(fp_device, BiometricsFingerprint::notify))) { - ALOGE("Can't register fingerprint module callback, class %s, error: %d", class_name, err); - return nullptr; - } - - return fp_device; -} - -void BiometricsFingerprint::notify(const fingerprint_msg_t *msg) { - BiometricsFingerprint* thisPtr = static_cast( - BiometricsFingerprint::getInstance()); - std::lock_guard lock(thisPtr->mClientCallbackMutex); - if (thisPtr == nullptr || thisPtr->mClientCallback == nullptr) { - ALOGE("Receiving callbacks before the client callback is registered."); - return; - } - const uint64_t devId = reinterpret_cast(thisPtr->mDevice); - switch (msg->type) { - case FINGERPRINT_ERROR: { - int32_t vendorCode = 0; - FingerprintError result = VendorErrorFilter(msg->data.error, &vendorCode); - ALOGD("onError(%d)", result); - if (!thisPtr->mClientCallback->onError(devId, result, vendorCode).isOk()) { - ALOGE("failed to invoke fingerprint onError callback"); - } - } - break; - case FINGERPRINT_ACQUIRED: { - int32_t vendorCode = 0; - FingerprintAcquiredInfo result = - VendorAcquiredFilter(msg->data.acquired.acquired_info, &vendorCode); - ALOGD("onAcquired(%d)", result); - if (!thisPtr->mClientCallback->onAcquired(devId, result, vendorCode).isOk()) { - ALOGE("failed to invoke fingerprint onAcquired callback"); - } - } - break; - case FINGERPRINT_TEMPLATE_ENROLLING: - ALOGD("onEnrollResult(fid=%d, gid=%d, rem=%d)", - msg->data.enroll.finger.fid, - msg->data.enroll.finger.gid, - msg->data.enroll.samples_remaining); - if (!thisPtr->mClientCallback->onEnrollResult(devId, - msg->data.enroll.finger.fid, - msg->data.enroll.finger.gid, - msg->data.enroll.samples_remaining).isOk()) { - ALOGE("failed to invoke fingerprint onEnrollResult callback"); - } - break; - case FINGERPRINT_TEMPLATE_REMOVED: - ALOGD("onRemove(fid=%d, gid=%d, rem=%d)", - msg->data.removed.finger.fid, - msg->data.removed.finger.gid, - msg->data.removed.remaining_templates); - if (!thisPtr->mClientCallback->onRemoved(devId, - msg->data.removed.finger.fid, - msg->data.removed.finger.gid, - msg->data.removed.remaining_templates).isOk()) { - ALOGE("failed to invoke fingerprint onRemoved callback"); - } - break; - case FINGERPRINT_AUTHENTICATED: - if (msg->data.authenticated.finger.fid != 0) { - ALOGD("onAuthenticated(fid=%d, gid=%d)", - msg->data.authenticated.finger.fid, - msg->data.authenticated.finger.gid); - const uint8_t* hat = - reinterpret_cast(&msg->data.authenticated.hat); - const hidl_vec token( - std::vector(hat, hat + sizeof(msg->data.authenticated.hat))); - if (!thisPtr->mClientCallback->onAuthenticated(devId, - msg->data.authenticated.finger.fid, - msg->data.authenticated.finger.gid, - token).isOk()) { - ALOGE("failed to invoke fingerprint onAuthenticated callback"); - } - } else { - // Not a recognized fingerprint - if (!thisPtr->mClientCallback->onAuthenticated(devId, - msg->data.authenticated.finger.fid, - msg->data.authenticated.finger.gid, - hidl_vec()).isOk()) { - ALOGE("failed to invoke fingerprint onAuthenticated callback"); - } - } - break; - case FINGERPRINT_TEMPLATE_ENUMERATING: - ALOGD("onEnumerate(fid=%d, gid=%d, rem=%d)", - msg->data.enumerated.finger.fid, - msg->data.enumerated.finger.gid, - msg->data.enumerated.remaining_templates); - if (!thisPtr->mClientCallback->onEnumerate(devId, - msg->data.enumerated.finger.fid, - msg->data.enumerated.finger.gid, - msg->data.enumerated.remaining_templates).isOk()) { - ALOGE("failed to invoke fingerprint onEnumerate callback"); - } - break; - } -} - -Return BiometricsFingerprint::isUdfps(uint32_t /*sensorId*/) { -#if FOD - return true; -#else - return false; -#endif -} - -Return BiometricsFingerprint::onFingerDown(uint32_t /*x*/, uint32_t /*y*/, - float /*minor*/, float /*major*/) { - return Void(); -} - -Return BiometricsFingerprint::onFingerUp() { - return Void(); -} - -Return BiometricsFingerprint::extCmd(int32_t cmd, int32_t param) { - return mDevice->extCmd(mDevice, cmd, param); -} - -} // namespace implementation -} // namespace V2_3 -} // namespace fingerprint -} // namespace biometrics -} // namespace hardware -} // namespace android \ No newline at end of file diff --git a/biometrics/BiometricsFingerprint.h b/biometrics/BiometricsFingerprint.h deleted file mode 100644 index b5e91c5..0000000 --- a/biometrics/BiometricsFingerprint.h +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Copyright (C) 2017 The Android Open Source Project - * Copyright (C) 2021 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 ANDROID_HARDWARE_BIOMETRICS_FINGERPRINT_V2_3_BIOMETRICSFINGERPRINT_H -#define ANDROID_HARDWARE_BIOMETRICS_FINGERPRINT_V2_3_BIOMETRICSFINGERPRINT_H - -#include -#include -#include "xiaomi_fingerprint.h" -#include -#include -#include -#include - -namespace android { -namespace hardware { -namespace biometrics { -namespace fingerprint { -namespace V2_3 { -namespace implementation { - -using ::android::hardware::biometrics::fingerprint::V2_3::IBiometricsFingerprint; -using ::android::hardware::biometrics::fingerprint::V2_1::FingerprintAcquiredInfo; -using ::android::hardware::biometrics::fingerprint::V2_1::FingerprintError; -using ::android::hardware::biometrics::fingerprint::V2_1::IBiometricsFingerprintClientCallback; -using ::android::hardware::biometrics::fingerprint::V2_1::RequestStatus; -using ::android::hardware::Return; -using ::android::hardware::Void; -using ::android::hardware::hidl_vec; -using ::android::hardware::hidl_string; -using ::android::sp; -using ::vendor::xiaomi::hardware::fingerprintextension::V1_0::IXiaomiFingerprint; - -struct BiometricsFingerprint : public IBiometricsFingerprint, public IXiaomiFingerprint { -public: - BiometricsFingerprint(); - ~BiometricsFingerprint(); - - // Method to wrap legacy HAL with BiometricsFingerprint class - static IBiometricsFingerprint* getInstance(); - static IXiaomiFingerprint* getXiaomiInstance(); - - // Methods from ::android::hardware::biometrics::fingerprint::V2_1::IBiometricsFingerprint follow. - Return setNotify(const sp& clientCallback) override; - Return preEnroll() override; - Return enroll(const hidl_array& hat, uint32_t gid, uint32_t timeoutSec) override; - Return postEnroll() override; - Return getAuthenticatorId() override; - Return cancel() override; - Return enumerate() override; - Return remove(uint32_t gid, uint32_t fid) override; - Return setActiveGroup(uint32_t gid, const hidl_string& storePath) override; - Return authenticate(uint64_t operationId, uint32_t gid) override; - - // Methods from ::android::hardware::biometrics::fingerprint::V2_3::IBiometricsFingerprint follow. - Return isUdfps(uint32_t sensorId) override; - Return onFingerDown(uint32_t x, uint32_t y, float minor, float major) override; - Return onFingerUp() override; - - // Methods from ::vendor::xiaomi::hardware::fingerprintextension::V1_0::IXiaomiFingerprint follow. - Return extCmd(int32_t cmd, int32_t param) override; - -private: - static xiaomi_fingerprint_device_t* openHal(const char *class_name); - static void notify(const fingerprint_msg_t *msg); /* Static callback for legacy HAL implementation */ - static Return ErrorFilter(int32_t error); - static FingerprintError VendorErrorFilter(int32_t error, int32_t* vendorCode); - static FingerprintAcquiredInfo VendorAcquiredFilter(int32_t error, int32_t* vendorCode); - static BiometricsFingerprint* sInstance; - - std::mutex mClientCallbackMutex; - sp mClientCallback; - xiaomi_fingerprint_device_t *mDevice; -}; - -} // namespace implementation -} // namespace V2_3 -} // namespace fingerprint -} // namespace biometrics -} // namespace hardware -} // namespace android - -#endif // ANDROID_HARDWARE_BIOMETRICS_FINGERPRINT_V2_3_BIOMETRICSFINGERPRINT_H diff --git a/biometrics/android.hardware.biometrics.fingerprint@2.3-service.xiaomi_lito.xml b/biometrics/android.hardware.biometrics.fingerprint@2.3-service.xiaomi_lito.xml deleted file mode 100644 index c54524a..0000000 --- a/biometrics/android.hardware.biometrics.fingerprint@2.3-service.xiaomi_lito.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - android.hardware.biometrics.fingerprint - hwbinder - 2.3 - - IBiometricsFingerprint - default - - - - vendor.xiaomi.hardware.fingerprintextension - hwbinder - 1.0 - - IXiaomiFingerprint - default - - - diff --git a/biometrics/service.cpp b/biometrics/service.cpp deleted file mode 100644 index e88178e..0000000 --- a/biometrics/service.cpp +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (C) 2017 The Android Open Source 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 "android.hardware.biometrics.fingerprint@2.3-service.xiaomi_lito" - -#include -#include -#include -#include -#include -#include -#include "BiometricsFingerprint.h" - -using android::hardware::biometrics::fingerprint::V2_3::IBiometricsFingerprint; -using android::hardware::biometrics::fingerprint::V2_3::implementation::BiometricsFingerprint; -using android::hardware::configureRpcThreadpool; -using android::hardware::joinRpcThreadpool; -using android::sp; -using vendor::xiaomi::hardware::fingerprintextension::V1_0::IXiaomiFingerprint; - -int main() { - android::sp bio = BiometricsFingerprint::getInstance(); - android::sp xfe = BiometricsFingerprint::getXiaomiInstance(); - - configureRpcThreadpool(1, true /*callerWillJoin*/); - - if (bio != nullptr) { - if (::android::OK != bio->registerAsService()) { - return 1; - } - } else { - ALOGE("Can't create instance of BiometricsFingerprint, nullptr"); - } - - if (xfe != nullptr) { - if (::android::OK != xfe->registerAsService()) { - return 1; - } - } else { - ALOGE("Can't create instance of XiaomiFingerprint, nullptr"); - } - - joinRpcThreadpool(); - - return 0; // should never get here -} diff --git a/biometrics/xiaomi_fingerprint.h b/biometrics/xiaomi_fingerprint.h deleted file mode 100644 index 7d6d14f..0000000 --- a/biometrics/xiaomi_fingerprint.h +++ /dev/null @@ -1,172 +0,0 @@ -/* - * Copyright (C) 2021 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 XIAOMI_FINGERPRINT_H -#define XIAOMI_FINGERPRINT_H - -#include -#include - -typedef struct xiaomi_fingerprint_device { - /** - * Common methods of the fingerprint device. This *must* be the first member - * of fingerprint_device as users of this structure will cast a hw_device_t - * to fingerprint_device pointer in contexts where it's known - * the hw_device_t references a fingerprint_device. - */ - struct hw_device_t common; - - /* - * Client provided callback function to receive notifications. - * Do not set by hand, use the function above instead. - */ - fingerprint_notify_t notify; - - /* - * Set notification callback: - * Registers a user function that would receive notifications from the HAL - * The call will block if the HAL state machine is in busy state until HAL - * leaves the busy state. - * - * Function return: 0 if callback function is successfuly registered - * or a negative number in case of error, generally from the errno.h set. - */ - int (*set_notify)(struct xiaomi_fingerprint_device *dev, fingerprint_notify_t notify); - - /* - * Fingerprint pre-enroll enroll request: - * Generates a unique token to upper layers to indicate the start of an enrollment transaction. - * This token will be wrapped by security for verification and passed to enroll() for - * verification before enrollment will be allowed. This is to ensure adding a new fingerprint - * template was preceded by some kind of credential confirmation (e.g. device password). - * - * Function return: 0 if function failed - * otherwise, a uint64_t of token - */ - uint64_t (*pre_enroll)(struct xiaomi_fingerprint_device *dev); - - /* - * Fingerprint enroll request: - * Switches the HAL state machine to collect and store a new fingerprint - * template. Switches back as soon as enroll is complete - * (fingerprint_msg.type == FINGERPRINT_TEMPLATE_ENROLLING && - * fingerprint_msg.data.enroll.samples_remaining == 0) - * or after timeout_sec seconds. - * The fingerprint template will be assigned to the group gid. User has a choice - * to supply the gid or set it to 0 in which case a unique group id will be generated. - * - * Function return: 0 if enrollment process can be successfully started - * or a negative number in case of error, generally from the errno.h set. - * A notify() function may be called indicating the error condition. - */ - int (*enroll)(struct xiaomi_fingerprint_device *dev, const hw_auth_token_t *hat, - uint32_t gid, uint32_t timeout_sec); - - /* - * Finishes the enroll operation and invalidates the pre_enroll() generated challenge. - * This will be called at the end of a multi-finger enrollment session to indicate - * that no more fingers will be added. - * - * Function return: 0 if the request is accepted - * or a negative number in case of error, generally from the errno.h set. - */ - int (*post_enroll)(struct xiaomi_fingerprint_device *dev); - - /* - * get_authenticator_id: - * Returns a token associated with the current fingerprint set. This value will - * change whenever a new fingerprint is enrolled, thus creating a new fingerprint - * set. - * - * Function return: current authenticator id or 0 if function failed. - */ - uint64_t (*get_authenticator_id)(struct xiaomi_fingerprint_device *dev); - - /* - * Cancel pending enroll or authenticate, sending FINGERPRINT_ERROR_CANCELED - * to all running clients. Switches the HAL state machine back to the idle state. - * Unlike enroll_done() doesn't invalidate the pre_enroll() challenge. - * - * Function return: 0 if cancel request is accepted - * or a negative number in case of error, generally from the errno.h set. - */ - int (*cancel)(struct xiaomi_fingerprint_device *dev); - - /* - * Enumerate all the fingerprint templates found in the directory set by - * set_active_group() - * For each template found a notify() will be called with: - * fingerprint_msg.type == FINGERPRINT_TEMPLATE_ENUMERATED - * fingerprint_msg.data.enumerated.finger indicating a template id - * fingerprint_msg.data.enumerated.remaining_templates indicating how many more - * enumeration messages to expect. - * Note: If there are no fingerprints, then this should return 0 and the first fingerprint - * enumerated should have fingerid=0 and remaining=0 - * Function return: 0 if enumerate request is accepted - * or a negative number in case of error, generally from the errno.h set. - */ - int (*enumerate)(struct xiaomi_fingerprint_device *dev); - - /* - * Fingerprint remove request: - * Deletes a fingerprint template. - * Works only within the path set by set_active_group(). - * The fid parameter can be used as a widcard: - * * fid == 0 -- delete all the templates in the group. - * * fid != 0 -- delete this specific template from the group. - * For each template found a notify() will be called with: - * fingerprint_msg.type == FINGERPRINT_TEMPLATE_REMOVED - * fingerprint_msg.data.removed.finger indicating a template id deleted - * fingerprint_msg.data.removed.remaining_templates indicating how many more - * templates will be deleted by this operation. - * - * Function return: 0 if fingerprint template(s) can be successfully deleted - * or a negative number in case of error, generally from the errno.h set. - */ - int (*remove)(struct xiaomi_fingerprint_device *dev, uint32_t gid, uint32_t fid); - - /* - * Restricts the HAL operation to a set of fingerprints belonging to a - * group provided. - * The caller must provide a path to a storage location within the user's - * data directory. - * - * Function return: 0 on success - * or a negative number in case of error, generally from the errno.h set. - */ - int (*set_active_group)(struct xiaomi_fingerprint_device *dev, uint32_t gid, - const char *store_path); - - /* - * Authenticates an operation identifed by operation_id - * - * Function return: 0 on success - * or a negative number in case of error, generally from the errno.h set. - */ - int (*authenticate)(struct xiaomi_fingerprint_device *dev, uint64_t operation_id, uint32_t gid); - - /* - * Call a Xiaomi fingerprint extension command. - */ - int (*extCmd)(struct xiaomi_fingerprint_device *dev, int32_t cmd, int32_t param); - - /* - * Reserved for backward binary compatibility - */ - void *reserved[4]; -} xiaomi_fingerprint_device_t; - -#endif // XIAOMI_FINGERPRINT_H diff --git a/fod/Android.bp b/fod/Android.bp deleted file mode 100644 index e4be52d..0000000 --- a/fod/Android.bp +++ /dev/null @@ -1,16 +0,0 @@ -// -// Copyright (C) 2019-2021 The LineageOS Project -// -// SPDX-License-Identifier: Apache-2.0 -// - -cc_library_static { - name: "libudfps_extension.xiaomi_lito", - srcs: ["UdfpsExtension.cpp"], - include_dirs: [ - "frameworks/native/services/surfaceflinger/CompositionEngine/include" - ], - header_libs: [ - "generated_kernel_headers", - ], -} diff --git a/fod/UdfpsExtension.cpp b/fod/UdfpsExtension.cpp deleted file mode 100644 index 547c300..0000000 --- a/fod/UdfpsExtension.cpp +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Copyright (C) 2021 The LineageOS Project - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include - -uint32_t getUdfpsZOrder(uint32_t z, bool touched) { - if (touched) { - z |= FOD_PRESSED_LAYER_ZORDER; - } - return z; -} - -uint64_t getUdfpsUsageBits(uint64_t usageBits, bool) { - return usageBits; -} diff --git a/lito.mk b/lito.mk index 66a6c43..8032694 100644 --- a/lito.mk +++ b/lito.mk @@ -201,17 +201,14 @@ PRODUCT_PACKAGES += \ fastbootd # Fingerprint +PRODUCT_PACKAGES += \ + android.hardware.biometrics.fingerprint@2.3-service.xiaomi + ifeq ($(TARGET_HAS_FOD),true) PRODUCT_PACKAGES += \ vendor.goodix.hardware.biometrics.fingerprint@2.1.vendor endif -PRODUCT_PACKAGES += \ - android.hardware.biometrics.fingerprint@2.3-service.xiaomi_lito - -PRODUCT_PACKAGES += \ - vendor.xiaomi.hardware.fingerprintextension@1.0.vendor - # FM PRODUCT_PACKAGES += \ FM2 \ @@ -370,6 +367,7 @@ PRODUCT_PACKAGES += \ init.qti.dcvs.sh PRODUCT_PACKAGES += \ + init.fingerprint.rc \ init.qcom.power.rc \ init.qcom.rc \ init.target.rc \ diff --git a/rootdir/Android.bp b/rootdir/Android.bp index 39a31aa..c0b5000 100644 --- a/rootdir/Android.bp +++ b/rootdir/Android.bp @@ -61,6 +61,13 @@ prebuilt_etc { } // Init configuration files +prebuilt_etc { + name: "init.fingerprint.rc", + src: "etc/init.fingerprint.rc", + sub_dir: "init/hw", + vendor: true, +} + prebuilt_etc { name: "init.qcom.power.rc", src: "etc/init.qcom.power.rc", diff --git a/biometrics/android.hardware.biometrics.fingerprint@2.3-service.xiaomi_lito.rc b/rootdir/etc/init.fingerprint.rc similarity index 82% rename from biometrics/android.hardware.biometrics.fingerprint@2.3-service.xiaomi_lito.rc rename to rootdir/etc/init.fingerprint.rc index be40f68..4f24597 100644 --- a/biometrics/android.hardware.biometrics.fingerprint@2.3-service.xiaomi_lito.rc +++ b/rootdir/etc/init.fingerprint.rc @@ -1,11 +1,3 @@ -service vendor.fps_hal /vendor/bin/hw/android.hardware.biometrics.fingerprint@2.3-service.xiaomi_lito - # "class hal" causes a race condition on some devices due to files created - # in /data. As a workaround, postpone startup until later in boot once - # /data is mounted. - class late_start - user system - group system input uhid - on init # Goodix fingerprint chmod 0666 /dev/goodix_fp @@ -42,9 +34,6 @@ on boot chmod 0744 /sys/class/drm/card0-DSI-1/panel_info chmod 0666 /dev/input/event2 - chown system system /sys/devices/platform/soc/soc:qcom,dsi-display-primary/fod_ui - chmod 0444 /sys/devices/platform/soc/soc:qcom,dsi-display-primary/fod_ui - on post-fs-data mkdir /data/vendor/fpc 0770 system system mkdir /data/vendor/goodix 0770 system system diff --git a/rootdir/etc/init.qcom.rc b/rootdir/etc/init.qcom.rc index fc02db7..4661eb7 100644 --- a/rootdir/etc/init.qcom.rc +++ b/rootdir/etc/init.qcom.rc @@ -25,6 +25,7 @@ # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # +import /vendor/etc/init/hw/init.fingerprint.rc import /vendor/etc/init/hw/init.qti.ufs.rc import /vendor/etc/init/hw/init.qcom.power.rc import /vendor/etc/init/hw/init.qcom.usb.rc diff --git a/sepolicy/vendor/file_contexts b/sepolicy/vendor/file_contexts index 2b31931..0e3b3f2 100644 --- a/sepolicy/vendor/file_contexts +++ b/sepolicy/vendor/file_contexts @@ -28,7 +28,7 @@ /dev/mius(.*)? u:object_r:ultrasound_device:s0 # Fingerprint -/vendor/bin/hw/android\.hardware\.biometrics\.fingerprint@2.3-service\.xiaomi_lito u:object_r:hal_fingerprint_default_exec:s0 +/vendor/bin/hw/android\.hardware\.biometrics\.fingerprint@2.3-service\.xiaomi u:object_r:hal_fingerprint_default_exec:s0 # Fingerprint - devices /dev/goodix_fp u:object_r:fingerprint_device:s0 diff --git a/sepolicy/vendor/hwservice_contexts b/sepolicy/vendor/hwservice_contexts index 95ec5ad..1edc7a3 100644 --- a/sepolicy/vendor/hwservice_contexts +++ b/sepolicy/vendor/hwservice_contexts @@ -9,7 +9,6 @@ vendor.goodix.hardware.cap.biometrics.fingerprint::IGoodixFingerprintDaemon vendor.goodix.hardware.cap.biometrics.fingerprint::IGoodixFingerprintDaemonExt u:object_r:hal_fingerprint_hwservice:s0 vendor.goodix.hardware.interfaces.biometrics.fingerprint::IGoodixFingerprintDaemon u:object_r:hal_fingerprint_hwservice:s0 vendor.goodix.hardware.interfaces.biometrics.fingerprint::IGoodixFingerprintDaemonExt u:object_r:hal_fingerprint_hwservice:s0 -vendor.xiaomi.hardware.fingerprintextension::IXiaomiFingerprint u:object_r:hal_fingerprint_hwservice:s0 # Mlipay vendor.xiaomi.hardware.mlipay::IMlipayService u:object_r:hal_mlipay_hwservice:s0