diff --git a/base.mk b/base.mk index 43f3707..c2172e4 100644 --- a/base.mk +++ b/base.mk @@ -189,6 +189,7 @@ PRODUCT_COPY_FILES += \ PRODUCT_PACKAGES += \ android.hardware.biometrics.fingerprint@2.1-service.oppo.compat \ + android.hardware.biometrics.fingerprint@2.1-service.oplus.compat \ PRODUCT_PACKAGES += \ vr_hwc \ diff --git a/hal/oplus-fp/Android.bp b/hal/oplus-fp/Android.bp new file mode 100644 index 0000000..6f9448b --- /dev/null +++ b/hal/oplus-fp/Android.bp @@ -0,0 +1,23 @@ +cc_binary { + name: "android.hardware.biometrics.fingerprint@2.1-service.oplus.compat", + defaults: ["hidl_defaults"], + init_rc: ["android.hardware.biometrics.fingerprint@2.1-service.oplus.rc"], + relative_install_path: "hw", + srcs: [ + "BiometricsFingerprint.cpp", + "service.cpp", + ], + cflags: [ + "-Wno-unused-parameter", + ], + shared_libs: [ + "libcutils", + "liblog", + "libhidlbase", + "libhardware", + "libutils", + "libbase", + "android.hardware.biometrics.fingerprint@2.1", + "vendor.oplus.hardware.biometrics.fingerprint@2.1", + ], +} diff --git a/hal/oplus-fp/BiometricsFingerprint.cpp b/hal/oplus-fp/BiometricsFingerprint.cpp new file mode 100644 index 0000000..9f4a18a --- /dev/null +++ b/hal/oplus-fp/BiometricsFingerprint.cpp @@ -0,0 +1,267 @@ +/* + * 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.1-service.oplus.compat" +#define LOG_VERBOSE "android.hardware.biometrics.fingerprint@2.1-service.oplus.compat" + +#include +#include +#include "BiometricsFingerprint.h" + +#include +#include +#include +#include + +namespace android { +namespace hardware { +namespace biometrics { +namespace fingerprint { +namespace V2_1 { +namespace implementation { + +BiometricsFingerprint::BiometricsFingerprint() { + for(int i=0; i<10; i++) { + mOplusBiometricsFingerprint = vendor::oplus::hardware::biometrics::fingerprint::V2_1::IBiometricsFingerprint::tryGetService(); + if(mOplusBiometricsFingerprint != nullptr) break; + sleep(10); + } + if(mOplusBiometricsFingerprint == nullptr) exit(0); +} + +static bool receivedCancel; +static bool receivedEnumerate; +static uint64_t myDeviceId; +static std::vector knownFingers; +class OplusClientCallback : public vendor::oplus::hardware::biometrics::fingerprint::V2_1::IBiometricsFingerprintClientCallback { +public: + sp mClientCallback; + + OplusClientCallback(sp clientCallback) : mClientCallback(clientCallback) {} + Return onEnrollResult(uint64_t deviceId, uint32_t fingerId, + uint32_t groupId, uint32_t remaining) { + ALOGE("onEnrollResult %" PRIu64 " %u %u %u", deviceId, fingerId, groupId, remaining); + if(mClientCallback != nullptr) + mClientCallback->onEnrollResult(deviceId, fingerId, groupId, remaining); + return Void(); + } + + Return onAcquired(uint64_t deviceId, vendor::oplus::hardware::biometrics::fingerprint::V2_1::FingerprintAcquiredInfo acquiredInfo, + int32_t vendorCode) { + ALOGE("onAcquired %" PRIu64 " %d", deviceId, vendorCode); + if(mClientCallback != nullptr) + mClientCallback->onAcquired(deviceId, OplusToAOSPFingerprintAcquiredInfo(acquiredInfo), vendorCode); + return Void(); + } + + Return onAuthenticated(uint64_t deviceId, uint32_t fingerId, uint32_t groupId, + const hidl_vec& token) { + ALOGE("onAuthenticated %" PRIu64 " %u %u", deviceId, fingerId, groupId); + if(mClientCallback != nullptr) + mClientCallback->onAuthenticated(deviceId, fingerId, groupId, token); + return Void(); + } + + Return onError(uint64_t deviceId, vendor::oplus::hardware::biometrics::fingerprint::V2_1::FingerprintError error, int32_t vendorCode) { + ALOGE("onError %" PRIu64 " %d", deviceId, vendorCode); + if(error == vendor::oplus::hardware::biometrics::fingerprint::V2_1::FingerprintError::ERROR_CANCELED) { + receivedCancel = true; + } + if(mClientCallback != nullptr) + mClientCallback->onError(deviceId, OplusToAOSPFingerprintError(error), vendorCode); + return Void(); + } + + Return onRemoved(uint64_t deviceId, uint32_t fingerId, uint32_t groupId, + uint32_t remaining) { + ALOGE("onRemoved %" PRIu64 " %" PRIu32, deviceId, fingerId); + if(mClientCallback != nullptr) + mClientCallback->onRemoved(deviceId, fingerId, groupId, remaining); + return Void(); + } + + Return onEnumerate(uint64_t deviceId, uint32_t fingerId, uint32_t groupId, + uint32_t remaining) { + receivedEnumerate = true; + ALOGE("onEnumerate %" PRIu64 " %u %u %u", deviceId, fingerId, groupId, remaining); + if(mClientCallback != nullptr) + mClientCallback->onEnumerate(deviceId, fingerId, groupId, remaining); + return Void(); + } + + Return onTouchUp(uint64_t deviceId) { return Void(); } + Return onTouchDown(uint64_t deviceId) { return Void(); } + Return onSyncTemplates(uint64_t deviceId, const hidl_vec& fingerId, uint32_t remaining) { + ALOGE("onSyncTemplates %" PRIu64 " %zu %" PRIu32, deviceId, fingerId.size(), remaining); + myDeviceId = deviceId; + + for(auto fid : fingerId) { + ALOGE("\t- %u", fid); + } + knownFingers = fingerId; + + return Void(); + } + Return onFingerprintCmd(int32_t deviceId, const hidl_vec& groupId, uint32_t remaining) { return Void(); } + Return onImageInfoAcquired(uint32_t type, uint32_t quality, uint32_t match_score) { return Void(); } + Return onMonitorEventTriggered(uint32_t type, const hidl_string& data) { return Void(); } + Return onEngineeringInfoUpdated(uint32_t length, const hidl_vec& keys, const hidl_vec& values) { return Void(); } + Return onUIReady(int64_t deviceId) { return Void(); } + +private: + + Return OplusToAOSPFingerprintAcquiredInfo(vendor::oplus::hardware::biometrics::fingerprint::V2_1::FingerprintAcquiredInfo info) { + switch(info) { + case vendor::oplus::hardware::biometrics::fingerprint::V2_1::FingerprintAcquiredInfo::ACQUIRED_GOOD: return android::hardware::biometrics::fingerprint::V2_1::FingerprintAcquiredInfo::ACQUIRED_GOOD; + case vendor::oplus::hardware::biometrics::fingerprint::V2_1::FingerprintAcquiredInfo::ACQUIRED_PARTIAL: return android::hardware::biometrics::fingerprint::V2_1::FingerprintAcquiredInfo::ACQUIRED_PARTIAL; + case vendor::oplus::hardware::biometrics::fingerprint::V2_1::FingerprintAcquiredInfo::ACQUIRED_INSUFFICIENT: return android::hardware::biometrics::fingerprint::V2_1::FingerprintAcquiredInfo::ACQUIRED_INSUFFICIENT; + case vendor::oplus::hardware::biometrics::fingerprint::V2_1::FingerprintAcquiredInfo::ACQUIRED_IMAGER_DIRTY: return android::hardware::biometrics::fingerprint::V2_1::FingerprintAcquiredInfo::ACQUIRED_IMAGER_DIRTY; + case vendor::oplus::hardware::biometrics::fingerprint::V2_1::FingerprintAcquiredInfo::ACQUIRED_TOO_SLOW: return android::hardware::biometrics::fingerprint::V2_1::FingerprintAcquiredInfo::ACQUIRED_TOO_SLOW; + case vendor::oplus::hardware::biometrics::fingerprint::V2_1::FingerprintAcquiredInfo::ACQUIRED_TOO_FAST: return android::hardware::biometrics::fingerprint::V2_1::FingerprintAcquiredInfo::ACQUIRED_TOO_FAST; + case vendor::oplus::hardware::biometrics::fingerprint::V2_1::FingerprintAcquiredInfo::ACQUIRED_VENDOR: return android::hardware::biometrics::fingerprint::V2_1::FingerprintAcquiredInfo::ACQUIRED_VENDOR; + default: + return android::hardware::biometrics::fingerprint::V2_1::FingerprintAcquiredInfo::ACQUIRED_GOOD; + } + } + + Return OplusToAOSPFingerprintError(vendor::oplus::hardware::biometrics::fingerprint::V2_1::FingerprintError error) { + switch(error) { + case vendor::oplus::hardware::biometrics::fingerprint::V2_1::FingerprintError::ERROR_NO_ERROR: return android::hardware::biometrics::fingerprint::V2_1::FingerprintError::ERROR_NO_ERROR; + case vendor::oplus::hardware::biometrics::fingerprint::V2_1::FingerprintError::ERROR_HW_UNAVAILABLE: return android::hardware::biometrics::fingerprint::V2_1::FingerprintError::ERROR_HW_UNAVAILABLE; + case vendor::oplus::hardware::biometrics::fingerprint::V2_1::FingerprintError::ERROR_UNABLE_TO_PROCESS: return android::hardware::biometrics::fingerprint::V2_1::FingerprintError::ERROR_UNABLE_TO_PROCESS; + case vendor::oplus::hardware::biometrics::fingerprint::V2_1::FingerprintError::ERROR_TIMEOUT: return android::hardware::biometrics::fingerprint::V2_1::FingerprintError::ERROR_TIMEOUT; + case vendor::oplus::hardware::biometrics::fingerprint::V2_1::FingerprintError::ERROR_NO_SPACE: return android::hardware::biometrics::fingerprint::V2_1::FingerprintError::ERROR_NO_SPACE; + case vendor::oplus::hardware::biometrics::fingerprint::V2_1::FingerprintError::ERROR_CANCELED: return android::hardware::biometrics::fingerprint::V2_1::FingerprintError::ERROR_CANCELED; + case vendor::oplus::hardware::biometrics::fingerprint::V2_1::FingerprintError::ERROR_UNABLE_TO_REMOVE: return android::hardware::biometrics::fingerprint::V2_1::FingerprintError::ERROR_UNABLE_TO_REMOVE; + case vendor::oplus::hardware::biometrics::fingerprint::V2_1::FingerprintError::ERROR_LOCKOUT: return android::hardware::biometrics::fingerprint::V2_1::FingerprintError::ERROR_LOCKOUT; + case vendor::oplus::hardware::biometrics::fingerprint::V2_1::FingerprintError::ERROR_VENDOR: return android::hardware::biometrics::fingerprint::V2_1::FingerprintError::ERROR_VENDOR; + default: + return android::hardware::biometrics::fingerprint::V2_1::FingerprintError::ERROR_NO_ERROR; + } + } +}; + +Return BiometricsFingerprint::setNotify( + const sp& clientCallback) { + ALOGE("setNotify"); + mOplusClientCallback = new OplusClientCallback(clientCallback); + return mOplusBiometricsFingerprint->setNotify(mOplusClientCallback); +} + +Return BiometricsFingerprint::OplusToAOSPRequestStatus(vendor::oplus::hardware::biometrics::fingerprint::V2_1::RequestStatus req) { + switch(req) { + case vendor::oplus::hardware::biometrics::fingerprint::V2_1::RequestStatus::SYS_UNKNOWN: return RequestStatus::SYS_UNKNOWN; + case vendor::oplus::hardware::biometrics::fingerprint::V2_1::RequestStatus::SYS_OK: return RequestStatus::SYS_OK; + case vendor::oplus::hardware::biometrics::fingerprint::V2_1::RequestStatus::SYS_ENOENT: return RequestStatus::SYS_ENOENT; + case vendor::oplus::hardware::biometrics::fingerprint::V2_1::RequestStatus::SYS_EINTR: return RequestStatus::SYS_EINTR; + case vendor::oplus::hardware::biometrics::fingerprint::V2_1::RequestStatus::SYS_EIO: return RequestStatus::SYS_EIO; + case vendor::oplus::hardware::biometrics::fingerprint::V2_1::RequestStatus::SYS_EAGAIN: return RequestStatus::SYS_EAGAIN; + case vendor::oplus::hardware::biometrics::fingerprint::V2_1::RequestStatus::SYS_ENOMEM: return RequestStatus::SYS_ENOMEM; + case vendor::oplus::hardware::biometrics::fingerprint::V2_1::RequestStatus::SYS_EACCES: return RequestStatus::SYS_EACCES; + case vendor::oplus::hardware::biometrics::fingerprint::V2_1::RequestStatus::SYS_EFAULT: return RequestStatus::SYS_EFAULT; + case vendor::oplus::hardware::biometrics::fingerprint::V2_1::RequestStatus::SYS_EBUSY: return RequestStatus::SYS_EBUSY; + case vendor::oplus::hardware::biometrics::fingerprint::V2_1::RequestStatus::SYS_EINVAL: return RequestStatus::SYS_EINVAL; + case vendor::oplus::hardware::biometrics::fingerprint::V2_1::RequestStatus::SYS_ENOSPC: return RequestStatus::SYS_ENOSPC; + case vendor::oplus::hardware::biometrics::fingerprint::V2_1::RequestStatus::SYS_ETIMEDOUT: return RequestStatus::SYS_ETIMEDOUT; + default: + return RequestStatus::SYS_UNKNOWN; + } +} + +Return BiometricsFingerprint::preEnroll() { + ALOGE("preEnroll"); + return mOplusBiometricsFingerprint->preEnroll(); +} + +Return BiometricsFingerprint::enroll(const hidl_array& hat, + uint32_t gid, uint32_t timeoutSec) { + ALOGE("enroll"); + return OplusToAOSPRequestStatus(mOplusBiometricsFingerprint->enroll(hat, gid, timeoutSec)); +} + +Return BiometricsFingerprint::postEnroll() { + ALOGE("postEnroll"); + return OplusToAOSPRequestStatus(mOplusBiometricsFingerprint->postEnroll()); +} + +Return BiometricsFingerprint::getAuthenticatorId() { + ALOGE("getAuthId"); + return mOplusBiometricsFingerprint->getAuthenticatorId(); +} + +Return BiometricsFingerprint::cancel() { + receivedCancel = false; + RequestStatus ret = OplusToAOSPRequestStatus(mOplusBiometricsFingerprint->cancel()); + ALOGE("CANCELING"); + if(!receivedCancel) { + ALOGE("Sending cancel error"); + mOplusClientCallback->mClientCallback->onError( + myDeviceId, + android::hardware::biometrics::fingerprint::V2_1::FingerprintError::ERROR_CANCELED, + 0); + } + return ret; +} + +Return BiometricsFingerprint::enumerate() { + receivedEnumerate = false; + RequestStatus ret = OplusToAOSPRequestStatus(mOplusBiometricsFingerprint->enumerate()); + ALOGE("ENUMERATING"); + if(ret == RequestStatus::SYS_OK && !receivedEnumerate) { + size_t nFingers = knownFingers.size(); + ALOGE("received fingers, sending our own %zu", nFingers); + if(nFingers > 0) { + for(auto finger: knownFingers) { + mOplusClientCallback->mClientCallback->onEnumerate( + myDeviceId, + finger, + 0, + --nFingers); + + } + } else { + mOplusClientCallback->mClientCallback->onEnumerate( + myDeviceId, + 0, + 0, + 0); + + } + } + return ret; +} + +Return BiometricsFingerprint::remove(uint32_t gid, uint32_t fid) { + ALOGE("remove"); + return OplusToAOSPRequestStatus(mOplusBiometricsFingerprint->remove(gid, fid)); +} + +Return BiometricsFingerprint::setActiveGroup(uint32_t gid, + const hidl_string& storePath) { + ALOGE("setActiveGroup"); + return OplusToAOSPRequestStatus(mOplusBiometricsFingerprint->setActiveGroup(gid, storePath)); +} + +Return BiometricsFingerprint::authenticate(uint64_t operationId, uint32_t gid) { + ALOGE("auth"); + return OplusToAOSPRequestStatus(mOplusBiometricsFingerprint->authenticate(operationId, gid)); +} + +} // namespace implementation +} // namespace V2_1 +} // namespace fingerprint +} // namespace biometrics +} // namespace hardware +} // namespace android diff --git a/hal/oplus-fp/BiometricsFingerprint.h b/hal/oplus-fp/BiometricsFingerprint.h new file mode 100644 index 0000000..487192a --- /dev/null +++ b/hal/oplus-fp/BiometricsFingerprint.h @@ -0,0 +1,78 @@ +/* + * 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. + */ + +#ifndef ANDROID_HARDWARE_BIOMETRICS_FINGERPRINT_V2_1_BIOMETRICSFINGERPRINT_H +#define ANDROID_HARDWARE_BIOMETRICS_FINGERPRINT_V2_1_BIOMETRICSFINGERPRINT_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace android { +namespace hardware { +namespace biometrics { +namespace fingerprint { +namespace V2_1 { +namespace implementation { + +using ::android::hardware::biometrics::fingerprint::V2_1::IBiometricsFingerprint; +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::OK; +using ::android::sp; +using ::android::status_t; + +class OplusClientCallback; +struct BiometricsFingerprint : public IBiometricsFingerprint { +public: + BiometricsFingerprint(); + + // 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; + +private: + sp mOplusBiometricsFingerprint; + sp mOplusClientCallback; + static Return OplusToAOSPRequestStatus(vendor::oplus::hardware::biometrics::fingerprint::V2_1::RequestStatus req); +}; + +} // namespace implementation +} // namespace V2_1 +} // namespace fingerprint +} // namespace biometrics +} // namespace hardware +} // namespace android + +#endif // ANDROID_HARDWARE_BIOMETRICS_FINGERPRINT_V2_1_BIOMETRICSFINGERPRINT_H diff --git a/hal/oplus-fp/android.hardware.biometrics.fingerprint@2.1-service.oplus.rc b/hal/oplus-fp/android.hardware.biometrics.fingerprint@2.1-service.oplus.rc new file mode 100644 index 0000000..a78f5ec --- /dev/null +++ b/hal/oplus-fp/android.hardware.biometrics.fingerprint@2.1-service.oplus.rc @@ -0,0 +1,9 @@ +service fps_hal.oplus.compat /system/bin/hw/android.hardware.biometrics.fingerprint@2.1-service.oppo.compat + # "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 + writepid /dev/cpuset/system-background/tasks + oneshot diff --git a/hal/oplus-fp/service.cpp b/hal/oplus-fp/service.cpp new file mode 100644 index 0000000..4b7623e --- /dev/null +++ b/hal/oplus-fp/service.cpp @@ -0,0 +1,61 @@ +/* + * 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.1-service.realme_sdm710" + +#include +#include + +#include "BiometricsFingerprint.h" + +using android::hardware::biometrics::fingerprint::V2_1::IBiometricsFingerprint; +using android::hardware::biometrics::fingerprint::V2_1::implementation::BiometricsFingerprint; +using android::hardware::configureRpcThreadpool; +using android::hardware::joinRpcThreadpool; +using android::OK; +using android::sp; +using android::status_t; + +int main() { + sp biometricsFingerprint; + status_t status; + + LOG(INFO) << "Fingerprint HAL Adapter service is starting."; + + biometricsFingerprint = new BiometricsFingerprint(); + if (biometricsFingerprint == nullptr) { + LOG(ERROR) << "Can not create an instance of Fingerprint HAL Adapter BiometricsFingerprint Iface, exiting."; + goto shutdown; + } + + configureRpcThreadpool(1, true /*callerWillJoin*/); + + status = biometricsFingerprint->registerAsService(); + if (status != OK) { + LOG(ERROR) << "Could not register service for Fingerprint HAL Adapter BiometricsFingerprint Iface (" + << status << ")"; + goto shutdown; + } + + LOG(INFO) << "Fingerprint HAL Adapter service is ready."; + joinRpcThreadpool(); + // Should not pass this line + +shutdown: + // In normal operation, we don't expect the thread pool to shutdown + LOG(ERROR) << "Fingerprint HAL Adapter service is shutting down."; + return 1; +} diff --git a/rw-system.sh b/rw-system.sh index 38271b4..42dc655 100644 --- a/rw-system.sh +++ b/rw-system.sh @@ -305,7 +305,12 @@ fi foundFingerprint=false for manifest in /vendor/manifest.xml /vendor/etc/vintf/manifest.xml /odm/etc/vintf/manifest.xml;do - if grep -q -e android.hardware.biometrics.fingerprint -e vendor.oppo.hardware.biometrics.fingerprint $manifest;then + if grep -q \ + -e android.hardware.biometrics.fingerprint \ + -e vendor.oppo.hardware.biometrics.fingerprint \ + -e vendor.oplus.hardware.biometrics.fingerprint \ + $manifest; + then foundFingerprint=true fi done