Loading biometrics/fingerprint/aidl/default/Android.bp +18 −4 Original line number Diff line number Diff line cc_binary { name: "android.hardware.biometrics.fingerprint-service.example", vendor: true, relative_install_path: "hw", init_rc: ["fingerprint-default.rc"], vintf_fragments: ["fingerprint-default.xml"], vendor: true, local_include_dirs: ["include"], srcs: [ "main.cpp", "Fingerprint.cpp", "Session.cpp", ], shared_libs: [ "libbase", "libbinder_ndk", "android.hardware.biometrics.fingerprint-V1-ndk_platform", "android.hardware.biometrics.common-V1-ndk_platform", ], } cc_test_host { name: "android.hardware.biometrics.fingerprint.WorkerThreadTest", local_include_dirs: ["include"], srcs: [ "main.cpp", "Fingerprint.cpp", "Session.cpp", "tests/WorkerThreadTest.cpp", "WorkerThread.cpp", ], shared_libs: [ "libcutils", ], test_suites: ["general-tests"], } biometrics/fingerprint/aidl/default/Fingerprint.cpp +30 −36 Original line number Diff line number Diff line Loading @@ -18,50 +18,44 @@ #include "Session.h" namespace aidl::android::hardware::biometrics::fingerprint { namespace { const int kSensorId = 1; const common::SensorStrength kSensorStrength = common::SensorStrength::STRONG; const int kMaxEnrollmentsPerUser = 5; const FingerprintSensorType kSensorType = FingerprintSensorType::REAR; const bool kSupportsNavigationGestures = true; const std::string kHwDeviceName = "fingerprintSensor"; const std::string kHardwareVersion = "vendor/model/revision"; const std::string kFirmwareVersion = "1.01"; const std::string kSerialNumber = "00000001"; constexpr int SENSOR_ID = 1; constexpr common::SensorStrength SENSOR_STRENGTH = common::SensorStrength::STRONG; constexpr int MAX_ENROLLMENTS_PER_USER = 5; constexpr FingerprintSensorType SENSOR_TYPE = FingerprintSensorType::REAR; constexpr bool SUPPORTS_NAVIGATION_GESTURES = true; constexpr char HW_DEVICE_NAME[] = "fingerprintSensor"; constexpr char HW_VERSION[] = "vendor/model/revision"; constexpr char FW_VERSION[] = "1.01"; constexpr char SERIAL_NUMBER[] = "00000001"; ndk::ScopedAStatus Fingerprint::getSensorProps(std::vector<SensorProps>* return_val) { *return_val = std::vector<SensorProps>(); } // namespace std::vector<common::HardwareInfo> hardwareInfos = std::vector<common::HardwareInfo>(); common::HardwareInfo sensorInfo = {kHwDeviceName, kHardwareVersion, kFirmwareVersion, kSerialNumber }; hardwareInfos.push_back(sensorInfo); common::CommonProps commonProps = {kSensorId, kSensorStrength, kMaxEnrollmentsPerUser, Fingerprint::Fingerprint() {} ndk::ScopedAStatus Fingerprint::getSensorProps(std::vector<SensorProps>* out) { std::vector<common::HardwareInfo> hardwareInfos = { {HW_DEVICE_NAME, HW_VERSION, FW_VERSION, SERIAL_NUMBER}}; common::CommonProps commonProps = {SENSOR_ID, SENSOR_STRENGTH, MAX_ENROLLMENTS_PER_USER, hardwareInfos}; SensorLocation sensorLocation = { 0 /* displayId */, 0 /* sensorLocationX */, 0 /* sensorLocationY */, 0 /* sensorRadius */ }; SensorProps props = {commonProps, kSensorType, SensorLocation sensorLocation = {0 /* displayId */, 0 /* sensorLocationX */, 0 /* sensorLocationY */, 0 /* sensorRadius */}; *out = {{commonProps, SENSOR_TYPE, {sensorLocation}, kSupportsNavigationGestures, false /* supportsDetectInteraction */}; return_val->push_back(props); SUPPORTS_NAVIGATION_GESTURES, false /* supportsDetectInteraction */}}; return ndk::ScopedAStatus::ok(); } ndk::ScopedAStatus Fingerprint::createSession(int32_t /*sensorId*/, int32_t /*userId*/, const std::shared_ptr<ISessionCallback>& cb, std::shared_ptr<ISession>* return_val) { *return_val = SharedRefBase::make<Session>(cb); std::shared_ptr<ISession>* out) { *out = SharedRefBase::make<Session>(cb); return ndk::ScopedAStatus::ok(); } } // namespace aidl::android::hardware::biometrics::fingerprint biometrics/fingerprint/aidl/default/Session.cpp +16 −16 Original line number Diff line number Diff line Loading @@ -26,7 +26,7 @@ class CancellationSignal : public common::BnCancellationSignal { ndk::ScopedAStatus cancel() override { return ndk::ScopedAStatus::ok(); } }; Session::Session(std::shared_ptr<ISessionCallback> cb) : cb_(std::move(cb)) {} Session::Session(std::shared_ptr<ISessionCallback> cb) : mCb(std::move(cb)) {} ndk::ScopedAStatus Session::generateChallenge(int32_t /*cookie*/, int32_t /*timeoutSec*/) { LOG(INFO) << "generateChallenge"; Loading @@ -39,32 +39,32 @@ ndk::ScopedAStatus Session::revokeChallenge(int32_t /*cookie*/, int64_t /*challe } ndk::ScopedAStatus Session::enroll(int32_t /*cookie*/, const keymaster::HardwareAuthToken& /*hat*/, std::shared_ptr<common::ICancellationSignal>* /*return_val*/) { std::shared_ptr<common::ICancellationSignal>* /*out*/) { LOG(INFO) << "enroll"; return ndk::ScopedAStatus::ok(); } ndk::ScopedAStatus Session::authenticate(int32_t /*cookie*/, int64_t /*keystoreOperationId*/, std::shared_ptr<common::ICancellationSignal>* return_val) { std::shared_ptr<common::ICancellationSignal>* out) { LOG(INFO) << "authenticate"; if (cb_) { cb_->onStateChanged(0, SessionState::AUTHENTICATING); if (mCb) { mCb->onStateChanged(0, SessionState::AUTHENTICATING); } *return_val = SharedRefBase::make<CancellationSignal>(); *out = SharedRefBase::make<CancellationSignal>(); return ndk::ScopedAStatus::ok(); } ndk::ScopedAStatus Session::detectInteraction( int32_t /*cookie*/, std::shared_ptr<common::ICancellationSignal>* /*return_val*/) { int32_t /*cookie*/, std::shared_ptr<common::ICancellationSignal>* /*out*/) { LOG(INFO) << "detectInteraction"; return ndk::ScopedAStatus::ok(); } ndk::ScopedAStatus Session::enumerateEnrollments(int32_t /*cookie*/) { LOG(INFO) << "enumerateEnrollments"; if (cb_) { cb_->onStateChanged(0, SessionState::ENUMERATING_ENROLLMENTS); cb_->onEnrollmentsEnumerated(std::vector<int32_t>()); if (mCb) { mCb->onStateChanged(0, SessionState::ENUMERATING_ENROLLMENTS); mCb->onEnrollmentsEnumerated(std::vector<int32_t>()); } return ndk::ScopedAStatus::ok(); } Loading @@ -72,18 +72,18 @@ ndk::ScopedAStatus Session::enumerateEnrollments(int32_t /*cookie*/) { ndk::ScopedAStatus Session::removeEnrollments(int32_t /*cookie*/, const std::vector<int32_t>& /*enrollmentIds*/) { LOG(INFO) << "removeEnrollments"; if (cb_) { cb_->onStateChanged(0, SessionState::REMOVING_ENROLLMENTS); cb_->onEnrollmentsRemoved(std::vector<int32_t>()); if (mCb) { mCb->onStateChanged(0, SessionState::REMOVING_ENROLLMENTS); mCb->onEnrollmentsRemoved(std::vector<int32_t>()); } return ndk::ScopedAStatus::ok(); } ndk::ScopedAStatus Session::getAuthenticatorId(int32_t /*cookie*/) { LOG(INFO) << "getAuthenticatorId"; if (cb_) { cb_->onStateChanged(0, SessionState::GETTING_AUTHENTICATOR_ID); cb_->onAuthenticatorIdRetrieved(0 /* authenticatorId */); if (mCb) { mCb->onStateChanged(0, SessionState::GETTING_AUTHENTICATOR_ID); mCb->onAuthenticatorIdRetrieved(0 /* authenticatorId */); } return ndk::ScopedAStatus::ok(); } Loading biometrics/fingerprint/aidl/default/WorkerThread.cpp 0 → 100644 +68 −0 Original line number Diff line number Diff line /* * Copyright (C) 2021 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. */ #include "WorkerThread.h" namespace aidl::android::hardware::biometrics::fingerprint { // It's important that mThread is initialized after everything else because it runs a member // function that may use any member of this class. WorkerThread::WorkerThread(size_t maxQueueSize) : mMaxSize(maxQueueSize), mIsDestructing(false), mQueue(), mQueueMutex(), mQueueCond(), mThread(&WorkerThread::threadFunc, this) {} WorkerThread::~WorkerThread() { // This is a signal for threadFunc to terminate as soon as possible, and a hint for schedule // that it doesn't need to do any work. mIsDestructing = true; mQueueCond.notify_all(); mThread.join(); } bool WorkerThread::schedule(Task&& task) { if (mIsDestructing) { return false; } std::unique_lock<std::mutex> lock(mQueueMutex); if (mQueue.size() >= mMaxSize) { return false; } mQueue.push_back(std::move(task)); lock.unlock(); mQueueCond.notify_one(); return true; } void WorkerThread::threadFunc() { while (!mIsDestructing) { std::unique_lock<std::mutex> lock(mQueueMutex); mQueueCond.wait(lock, [this] { return !mQueue.empty() || mIsDestructing; }); if (mIsDestructing) { return; } Task task = std::move(mQueue.front()); mQueue.pop_front(); lock.unlock(); task(); } } } // namespace aidl::android::hardware::biometrics::fingerprint biometrics/fingerprint/aidl/default/Fingerprint.h→biometrics/fingerprint/aidl/default/include/Fingerprint.h +5 −3 Original line number Diff line number Diff line Loading @@ -20,13 +20,15 @@ namespace aidl::android::hardware::biometrics::fingerprint { class Fingerprint : public BnFingerprint { class Fingerprint final : public BnFingerprint { public: ndk::ScopedAStatus getSensorProps(std::vector<SensorProps>* _aidl_return) override; Fingerprint(); ndk::ScopedAStatus getSensorProps(std::vector<SensorProps>* out) override; ndk::ScopedAStatus createSession(int32_t sensorId, int32_t userId, const std::shared_ptr<ISessionCallback>& cb, std::shared_ptr<ISession>* _aidl_return) override; std::shared_ptr<ISession>* out) override; }; } // namespace aidl::android::hardware::biometrics::fingerprint Loading
biometrics/fingerprint/aidl/default/Android.bp +18 −4 Original line number Diff line number Diff line cc_binary { name: "android.hardware.biometrics.fingerprint-service.example", vendor: true, relative_install_path: "hw", init_rc: ["fingerprint-default.rc"], vintf_fragments: ["fingerprint-default.xml"], vendor: true, local_include_dirs: ["include"], srcs: [ "main.cpp", "Fingerprint.cpp", "Session.cpp", ], shared_libs: [ "libbase", "libbinder_ndk", "android.hardware.biometrics.fingerprint-V1-ndk_platform", "android.hardware.biometrics.common-V1-ndk_platform", ], } cc_test_host { name: "android.hardware.biometrics.fingerprint.WorkerThreadTest", local_include_dirs: ["include"], srcs: [ "main.cpp", "Fingerprint.cpp", "Session.cpp", "tests/WorkerThreadTest.cpp", "WorkerThread.cpp", ], shared_libs: [ "libcutils", ], test_suites: ["general-tests"], }
biometrics/fingerprint/aidl/default/Fingerprint.cpp +30 −36 Original line number Diff line number Diff line Loading @@ -18,50 +18,44 @@ #include "Session.h" namespace aidl::android::hardware::biometrics::fingerprint { namespace { const int kSensorId = 1; const common::SensorStrength kSensorStrength = common::SensorStrength::STRONG; const int kMaxEnrollmentsPerUser = 5; const FingerprintSensorType kSensorType = FingerprintSensorType::REAR; const bool kSupportsNavigationGestures = true; const std::string kHwDeviceName = "fingerprintSensor"; const std::string kHardwareVersion = "vendor/model/revision"; const std::string kFirmwareVersion = "1.01"; const std::string kSerialNumber = "00000001"; constexpr int SENSOR_ID = 1; constexpr common::SensorStrength SENSOR_STRENGTH = common::SensorStrength::STRONG; constexpr int MAX_ENROLLMENTS_PER_USER = 5; constexpr FingerprintSensorType SENSOR_TYPE = FingerprintSensorType::REAR; constexpr bool SUPPORTS_NAVIGATION_GESTURES = true; constexpr char HW_DEVICE_NAME[] = "fingerprintSensor"; constexpr char HW_VERSION[] = "vendor/model/revision"; constexpr char FW_VERSION[] = "1.01"; constexpr char SERIAL_NUMBER[] = "00000001"; ndk::ScopedAStatus Fingerprint::getSensorProps(std::vector<SensorProps>* return_val) { *return_val = std::vector<SensorProps>(); } // namespace std::vector<common::HardwareInfo> hardwareInfos = std::vector<common::HardwareInfo>(); common::HardwareInfo sensorInfo = {kHwDeviceName, kHardwareVersion, kFirmwareVersion, kSerialNumber }; hardwareInfos.push_back(sensorInfo); common::CommonProps commonProps = {kSensorId, kSensorStrength, kMaxEnrollmentsPerUser, Fingerprint::Fingerprint() {} ndk::ScopedAStatus Fingerprint::getSensorProps(std::vector<SensorProps>* out) { std::vector<common::HardwareInfo> hardwareInfos = { {HW_DEVICE_NAME, HW_VERSION, FW_VERSION, SERIAL_NUMBER}}; common::CommonProps commonProps = {SENSOR_ID, SENSOR_STRENGTH, MAX_ENROLLMENTS_PER_USER, hardwareInfos}; SensorLocation sensorLocation = { 0 /* displayId */, 0 /* sensorLocationX */, 0 /* sensorLocationY */, 0 /* sensorRadius */ }; SensorProps props = {commonProps, kSensorType, SensorLocation sensorLocation = {0 /* displayId */, 0 /* sensorLocationX */, 0 /* sensorLocationY */, 0 /* sensorRadius */}; *out = {{commonProps, SENSOR_TYPE, {sensorLocation}, kSupportsNavigationGestures, false /* supportsDetectInteraction */}; return_val->push_back(props); SUPPORTS_NAVIGATION_GESTURES, false /* supportsDetectInteraction */}}; return ndk::ScopedAStatus::ok(); } ndk::ScopedAStatus Fingerprint::createSession(int32_t /*sensorId*/, int32_t /*userId*/, const std::shared_ptr<ISessionCallback>& cb, std::shared_ptr<ISession>* return_val) { *return_val = SharedRefBase::make<Session>(cb); std::shared_ptr<ISession>* out) { *out = SharedRefBase::make<Session>(cb); return ndk::ScopedAStatus::ok(); } } // namespace aidl::android::hardware::biometrics::fingerprint
biometrics/fingerprint/aidl/default/Session.cpp +16 −16 Original line number Diff line number Diff line Loading @@ -26,7 +26,7 @@ class CancellationSignal : public common::BnCancellationSignal { ndk::ScopedAStatus cancel() override { return ndk::ScopedAStatus::ok(); } }; Session::Session(std::shared_ptr<ISessionCallback> cb) : cb_(std::move(cb)) {} Session::Session(std::shared_ptr<ISessionCallback> cb) : mCb(std::move(cb)) {} ndk::ScopedAStatus Session::generateChallenge(int32_t /*cookie*/, int32_t /*timeoutSec*/) { LOG(INFO) << "generateChallenge"; Loading @@ -39,32 +39,32 @@ ndk::ScopedAStatus Session::revokeChallenge(int32_t /*cookie*/, int64_t /*challe } ndk::ScopedAStatus Session::enroll(int32_t /*cookie*/, const keymaster::HardwareAuthToken& /*hat*/, std::shared_ptr<common::ICancellationSignal>* /*return_val*/) { std::shared_ptr<common::ICancellationSignal>* /*out*/) { LOG(INFO) << "enroll"; return ndk::ScopedAStatus::ok(); } ndk::ScopedAStatus Session::authenticate(int32_t /*cookie*/, int64_t /*keystoreOperationId*/, std::shared_ptr<common::ICancellationSignal>* return_val) { std::shared_ptr<common::ICancellationSignal>* out) { LOG(INFO) << "authenticate"; if (cb_) { cb_->onStateChanged(0, SessionState::AUTHENTICATING); if (mCb) { mCb->onStateChanged(0, SessionState::AUTHENTICATING); } *return_val = SharedRefBase::make<CancellationSignal>(); *out = SharedRefBase::make<CancellationSignal>(); return ndk::ScopedAStatus::ok(); } ndk::ScopedAStatus Session::detectInteraction( int32_t /*cookie*/, std::shared_ptr<common::ICancellationSignal>* /*return_val*/) { int32_t /*cookie*/, std::shared_ptr<common::ICancellationSignal>* /*out*/) { LOG(INFO) << "detectInteraction"; return ndk::ScopedAStatus::ok(); } ndk::ScopedAStatus Session::enumerateEnrollments(int32_t /*cookie*/) { LOG(INFO) << "enumerateEnrollments"; if (cb_) { cb_->onStateChanged(0, SessionState::ENUMERATING_ENROLLMENTS); cb_->onEnrollmentsEnumerated(std::vector<int32_t>()); if (mCb) { mCb->onStateChanged(0, SessionState::ENUMERATING_ENROLLMENTS); mCb->onEnrollmentsEnumerated(std::vector<int32_t>()); } return ndk::ScopedAStatus::ok(); } Loading @@ -72,18 +72,18 @@ ndk::ScopedAStatus Session::enumerateEnrollments(int32_t /*cookie*/) { ndk::ScopedAStatus Session::removeEnrollments(int32_t /*cookie*/, const std::vector<int32_t>& /*enrollmentIds*/) { LOG(INFO) << "removeEnrollments"; if (cb_) { cb_->onStateChanged(0, SessionState::REMOVING_ENROLLMENTS); cb_->onEnrollmentsRemoved(std::vector<int32_t>()); if (mCb) { mCb->onStateChanged(0, SessionState::REMOVING_ENROLLMENTS); mCb->onEnrollmentsRemoved(std::vector<int32_t>()); } return ndk::ScopedAStatus::ok(); } ndk::ScopedAStatus Session::getAuthenticatorId(int32_t /*cookie*/) { LOG(INFO) << "getAuthenticatorId"; if (cb_) { cb_->onStateChanged(0, SessionState::GETTING_AUTHENTICATOR_ID); cb_->onAuthenticatorIdRetrieved(0 /* authenticatorId */); if (mCb) { mCb->onStateChanged(0, SessionState::GETTING_AUTHENTICATOR_ID); mCb->onAuthenticatorIdRetrieved(0 /* authenticatorId */); } return ndk::ScopedAStatus::ok(); } Loading
biometrics/fingerprint/aidl/default/WorkerThread.cpp 0 → 100644 +68 −0 Original line number Diff line number Diff line /* * Copyright (C) 2021 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. */ #include "WorkerThread.h" namespace aidl::android::hardware::biometrics::fingerprint { // It's important that mThread is initialized after everything else because it runs a member // function that may use any member of this class. WorkerThread::WorkerThread(size_t maxQueueSize) : mMaxSize(maxQueueSize), mIsDestructing(false), mQueue(), mQueueMutex(), mQueueCond(), mThread(&WorkerThread::threadFunc, this) {} WorkerThread::~WorkerThread() { // This is a signal for threadFunc to terminate as soon as possible, and a hint for schedule // that it doesn't need to do any work. mIsDestructing = true; mQueueCond.notify_all(); mThread.join(); } bool WorkerThread::schedule(Task&& task) { if (mIsDestructing) { return false; } std::unique_lock<std::mutex> lock(mQueueMutex); if (mQueue.size() >= mMaxSize) { return false; } mQueue.push_back(std::move(task)); lock.unlock(); mQueueCond.notify_one(); return true; } void WorkerThread::threadFunc() { while (!mIsDestructing) { std::unique_lock<std::mutex> lock(mQueueMutex); mQueueCond.wait(lock, [this] { return !mQueue.empty() || mIsDestructing; }); if (mIsDestructing) { return; } Task task = std::move(mQueue.front()); mQueue.pop_front(); lock.unlock(); task(); } } } // namespace aidl::android::hardware::biometrics::fingerprint
biometrics/fingerprint/aidl/default/Fingerprint.h→biometrics/fingerprint/aidl/default/include/Fingerprint.h +5 −3 Original line number Diff line number Diff line Loading @@ -20,13 +20,15 @@ namespace aidl::android::hardware::biometrics::fingerprint { class Fingerprint : public BnFingerprint { class Fingerprint final : public BnFingerprint { public: ndk::ScopedAStatus getSensorProps(std::vector<SensorProps>* _aidl_return) override; Fingerprint(); ndk::ScopedAStatus getSensorProps(std::vector<SensorProps>* out) override; ndk::ScopedAStatus createSession(int32_t sensorId, int32_t userId, const std::shared_ptr<ISessionCallback>& cb, std::shared_ptr<ISession>* _aidl_return) override; std::shared_ptr<ISession>* out) override; }; } // namespace aidl::android::hardware::biometrics::fingerprint