diff --git a/biometrics/fingerprint/2.1/IBiometricsFingerprint.hal b/biometrics/fingerprint/2.1/IBiometricsFingerprint.hal index b7f8d8837d..3b24a2cb9b 100644 --- a/biometrics/fingerprint/2.1/IBiometricsFingerprint.hal +++ b/biometrics/fingerprint/2.1/IBiometricsFingerprint.hal @@ -25,13 +25,12 @@ interface IBiometricsFingerprint { * This call must block if the HAL state machine is in busy state until HAL * leaves the busy state. * - * @return isOk indicates if the request is accepted. - * @return debugErrno is a value the framework logs in case isOk == false. + * @return debugErrno is a value the framework logs in case it is not 0. */ @callflow(next={"setActiveGroup"}) @entry setNotify(IBiometricsFingerprintClientCallback clientCallback) - generates (bool isOk, int32_t debugErrno); + generates (RequestStatus debugErrno); /* * Fingerprint pre-enroll enroll request: @@ -62,25 +61,23 @@ interface IBiometricsFingerprint { * @param gid a framework defined fingerprint set (group) id. * @param timeoutSec a timeout in seconds. * - * @return isOk indicates if the request is accepted. - * @return debugErrno is a value the framework logs in case isOk == false. + * @return debugErrno is a value the framework logs in case it is not 0. * * A notify() function may be called with a more detailed error structure. */ @callflow(next={"cancel", "enroll", "postEnroll", "remove"}) - enroll(HwAuthToken hat, uint32_t gid, uint32_t timeoutSec) - generates (bool isOk, int32_t debugErrno); + enroll(uint8_t[69] hat, uint32_t gid, uint32_t timeoutSec) + generates (RequestStatus debugErrno); /* * Finishes the enroll operation and invalidates the preEnroll() generated * challenge. This must be called at the end of a multi-finger enrollment * session to indicate that no more fingers may be added. * - * @return isOk indicates if the request is accepted. - * @return debugErrno is a value the framework logs in case isOk == false. + * @return debugErrno is a value the framework logs in case it is not 0. */ @callflow(next={"authenticate", "setActiveGroup", "enumerate", "remove"}) - postEnroll() generates (bool isOk, int32_t debugErrno); + postEnroll() generates (RequestStatus debugErrno); /* * getAuthenticatorId: @@ -99,12 +96,11 @@ interface IBiometricsFingerprint { * to all running clients. Switches the HAL state machine back to the idle * state. Unlike enrollDone() doesn't invalidate the preEnroll() challenge. * - * @return isOk indicates if the request is accepted. - * @return debugErrno is a value the framework logs in case isOk == false. + * @return debugErrno is a value the framework logs in case it is not 0. */ @callflow(next={"authenticate", "enroll", "enumerate", "remove", "setActiveGroup"}) - cancel() generates (bool isOk, int32_t debugErrno); + cancel() generates (RequestStatus debugErrno); /* * Enumerate all the fingerprint templates found in the directory set by @@ -115,11 +111,10 @@ interface IBiometricsFingerprint { * fingerprintMsg.data.enumerated.remainingTemplates indicating how many more * enumeration messages to expect. * - * @return isOk indicates if the request is accepted. - * @return debugErrno is a value the framework logs in case isOk == false. + * @return debugErrno is a value the framework logs in case it is not 0. */ @callflow(next={"remove", "enroll", "authenticate", "setActiveGroup"}) - enumerate() generates (bool isOk, int32_t debugErrno); + enumerate() generates (RequestStatus debugErrno); /* * Fingerprint remove request: @@ -135,12 +130,11 @@ interface IBiometricsFingerprint { * @param fid template id to delete or 0 to delete all templates within the * current group. * - * @return isOk indicates if the request is accepted. - * @return debugErrno is a value the framework logs in case isOk == false. + * @return debugErrno is a value the framework logs in case it is not 0. */ @callflow(next={"enumerate", "authenticate", "cancel", "getAuthenticatorId", "setActiveGroup"}) - remove(uint32_t gid, uint32_t fid) generates (bool isOk, int32_t debugErrno); + remove(uint32_t gid, uint32_t fid) generates (RequestStatus debugErrno); /* * Restricts the HAL operation to a set of fingerprints belonging to a group @@ -150,12 +144,11 @@ interface IBiometricsFingerprint { * @param gid the fingerprint group (set) id. * @param storePath filesystem path to the template storage directory. * - * @return isOk indicates if the request is accepted. - * @return debugErrno is a value the framework logs in case isOk == false. + * @return debugErrno is a value the framework logs in case it is not 0. */ @callflow(next={"authenticate", "preEnroll", "enumerate", "remove"}) setActiveGroup(uint32_t gid, string storePath) - generates (bool isOk, int32_t debugErrno); + generates (RequestStatus debugErrno); /* * Authenticates an operation identified by operationId @@ -163,10 +156,9 @@ interface IBiometricsFingerprint { * @param operationId operation id. * @param gid fingerprint group id. * - * @return isOk indicates if the request is accepted. - * @return debugErrno is a value the framework logs in case isOk == false. + * @return debugErrno is a value the framework logs in case it is not 0. */ @callflow(next={"cancel", "preEnroll", "remove"}) authenticate(uint64_t operationId, uint32_t gid) - generates (bool isOk, int32_t debugErrno); + generates (RequestStatus debugErrno); }; diff --git a/biometrics/fingerprint/2.1/default/BiometricsFingerprint.cpp b/biometrics/fingerprint/2.1/default/BiometricsFingerprint.cpp index 3ee7836ee1..13166862d6 100644 --- a/biometrics/fingerprint/2.1/default/BiometricsFingerprint.cpp +++ b/biometrics/fingerprint/2.1/default/BiometricsFingerprint.cpp @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#define LOG_TAG "android.hardware.biometrics.fingerprint@2.1-impl" #include #include @@ -25,6 +26,9 @@ namespace fingerprint { namespace V2_1 { namespace implementation { +using RequestStatus = + android::hardware::biometrics::fingerprint::V2_1::RequestStatus; + sp BiometricsFingerprint::mClientCallback = nullptr; @@ -46,78 +50,81 @@ BiometricsFingerprint::~BiometricsFingerprint() { mDevice = NULL; } -Return BiometricsFingerprint::setNotify( - const sp& clientCallback, - setNotify_cb cb) { +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"); + return RequestStatus::SYS_UNKNOWN; + } +} + +Return BiometricsFingerprint::setNotify( + const sp& clientCallback) { mClientCallback = clientCallback; - int32_t debugErrno = mDevice->set_notify(mDevice, notify); - cb(debugErrno == 0, debugErrno); - return Void(); + return RequestStatus::SYS_OK; } Return BiometricsFingerprint::preEnroll() { return mDevice->pre_enroll(mDevice); } -Return BiometricsFingerprint::enroll(const HwAuthToken& hat, uint32_t gid, - uint32_t timeoutSec, enroll_cb cb) { +Return BiometricsFingerprint::enroll(const hidl_array& hat, + uint32_t gid, uint32_t timeoutSec) { const hw_auth_token_t* authToken = - reinterpret_cast(&hat); - int32_t debugErrno = mDevice->enroll(mDevice, authToken, gid, timeoutSec); - cb(debugErrno == 0, debugErrno); - return Void(); + reinterpret_cast(hat.data()); + return ErrorFilter(mDevice->enroll(mDevice, authToken, gid, timeoutSec)); } -Return BiometricsFingerprint::postEnroll(postEnroll_cb cb) { - int32_t debugErrno = mDevice->post_enroll(mDevice); - cb(debugErrno == 0, debugErrno); - return Void(); +Return BiometricsFingerprint::postEnroll() { + return ErrorFilter(mDevice->post_enroll(mDevice)); } Return BiometricsFingerprint::getAuthenticatorId() { return mDevice->get_authenticator_id(mDevice); } -Return BiometricsFingerprint::cancel(cancel_cb cb) { - int32_t debugErrno = mDevice->cancel(mDevice); - cb(debugErrno == 0, debugErrno); - return Void(); +Return BiometricsFingerprint::cancel() { + return ErrorFilter(mDevice->cancel(mDevice)); } -Return BiometricsFingerprint::enumerate(enumerate_cb cb) { - int32_t debugErrno = mDevice->enumerate(mDevice); - cb(debugErrno == 0, debugErrno); - return Void(); +Return BiometricsFingerprint::enumerate() { + return ErrorFilter(mDevice->enumerate(mDevice)); } -Return BiometricsFingerprint::remove(uint32_t gid, uint32_t fid, - remove_cb cb) { - int32_t debugErrno = mDevice->remove(mDevice, gid, fid); - cb(debugErrno == 0, debugErrno); - return Void(); +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, setActiveGroup_cb cb) { +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()); } - int32_t debugErrno = mDevice->set_active_group(mDevice, gid, - storePath.c_str()); - cb(debugErrno == 0, debugErrno); - return Void(); + return ErrorFilter(mDevice->set_active_group(mDevice, gid, + storePath.c_str())); } -Return BiometricsFingerprint::authenticate(uint64_t operationId, - uint32_t gid, authenticate_cb cb) { - int32_t debugErrno = mDevice->authenticate(mDevice, operationId, gid); - cb(debugErrno == 0, debugErrno); - return Void(); +Return BiometricsFingerprint::authenticate(uint64_t operationId, + uint32_t gid) { + return ErrorFilter(mDevice->authenticate(mDevice, operationId, gid)); } IBiometricsFingerprint* HIDL_FETCH_IBiometricsFingerprint(const char*) { int err; const hw_module_t *hw_mdl = NULL; + ALOGE("Opening fingerprint hal library..."); if (0 != (err = hw_get_module(FINGERPRINT_HARDWARE_MODULE_ID, &hw_mdl))) { ALOGE("Can't open fingerprint HW Module, error: %d", err); return nullptr; @@ -141,8 +148,16 @@ IBiometricsFingerprint* HIDL_FETCH_IBiometricsFingerprint(const char*) { return nullptr; } - return new BiometricsFingerprint( - reinterpret_cast(device)); + 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, error: %d", err); + return nullptr; + } + + return new BiometricsFingerprint(fp_device); } } // namespace implementation diff --git a/biometrics/fingerprint/2.1/default/BiometricsFingerprint.h b/biometrics/fingerprint/2.1/default/BiometricsFingerprint.h index 4fdc328285..de8727b1d1 100644 --- a/biometrics/fingerprint/2.1/default/BiometricsFingerprint.h +++ b/biometrics/fingerprint/2.1/default/BiometricsFingerprint.h @@ -14,14 +14,14 @@ * limitations under the License. */ -#ifndef HIDL_GENERATED_android_hardware_biometrics_fingerprint_V2_1_BiometricsFingerprint_H_ -#define HIDL_GENERATED_android_hardware_biometrics_fingerprint_V2_1_BiometricsFingerprint_H_ +#ifndef ANDROID_HARDWARE_BIOMETRICS_FINGERPRINT_V2_1_BIOMETRICSFINGERPRINT_H +#define ANDROID_HARDWARE_BIOMETRICS_FINGERPRINT_V2_1_BIOMETRICSFINGERPRINT_H #include +#include #include #include -#include namespace android { namespace hardware { namespace biometrics { @@ -29,9 +29,9 @@ namespace fingerprint { namespace V2_1 { namespace implementation { -using ::android::hardware::biometrics::fingerprint::V2_1::HwAuthToken; 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; @@ -43,16 +43,16 @@ public: BiometricsFingerprint(fingerprint_device_t *device); ~BiometricsFingerprint(); // Methods from ::android::hardware::biometrics::fingerprint::V2_1::IBiometricsFingerprint follow. - Return setNotify(const sp& clientCallback, setNotify_cb _hidl_cb) override; - Return preEnroll() override; - Return enroll(const HwAuthToken& hat, uint32_t gid, uint32_t timeoutSec, enroll_cb _hidl_cb) override; - Return postEnroll(postEnroll_cb _hidl_cb) override; - Return getAuthenticatorId() override; - Return cancel(cancel_cb _hidl_cb) override; - Return enumerate(enumerate_cb _hidl_cb) override; - Return remove(uint32_t gid, uint32_t fid, remove_cb _hidl_cb) override; - Return setActiveGroup(uint32_t gid, const hidl_string& storePath, setActiveGroup_cb _hidl_cb) override; - Return authenticate(uint64_t operationId, uint32_t gid, authenticate_cb _hidl_cb) override; + 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; static void notify(const fingerprint_msg_t *notify_msg) { if (mClientCallback == nullptr) { ALOGE("Receiving callbacks before the client callback is registered."); @@ -63,6 +63,7 @@ public: mClientCallback->notify(msg); } private: + Return ErrorFilter(int32_t error); static sp mClientCallback; fingerprint_device_t *mDevice; }; @@ -76,4 +77,4 @@ extern "C" IBiometricsFingerprint* HIDL_FETCH_IBiometricsFingerprint(const char* } // namespace hardware } // namespace android -#endif // HIDL_GENERATED_android_hardware_biometrics_fingerprint_V2_1_BiometricsFingerprint_H_ +#endif // ANDROID_HARDWARE_BIOMETRICS_FINGERPRINT_V2_1_BIOMETRICSFINGERPRINT_H diff --git a/biometrics/fingerprint/2.1/types.hal b/biometrics/fingerprint/2.1/types.hal index cf68c04a3c..201ec7cbae 100644 --- a/biometrics/fingerprint/2.1/types.hal +++ b/biometrics/fingerprint/2.1/types.hal @@ -16,6 +16,27 @@ package android.hardware.biometrics.fingerprint@2.1; +/* + * Request status indicates whether the request is accepted by the vendor + * implementation or not. These values are taken from the errno set, + * except for the SYS_UNKNOWN + */ +enum RequestStatus : int32_t { + SYS_UNKNOWN = 1, + SYS_OK = 0, + SYS_ENOENT = -2, + SYS_EINTR = -4, + SYS_EIO = -5, + SYS_EAGAIN = -11, + SYS_ENOMEM = -12, + SYS_EACCES = -13, + SYS_EFAULT = -14, + SYS_EBUSY = -16, + SYS_EINVAL = -22, + SYS_ENOSPC = -28, + SYS_ETIMEDOUT = -110, +}; + /* * Fingerprint errors are meant to tell the framework to terminate the current * operation and ask for the user to correct the situation. These will almost @@ -66,25 +87,6 @@ enum FingerprintAcquiredInfo : int32_t { ACQUIRED_VENDOR_BASE = 1000, }; -/* TODO import from keymaster HIDL when available */ -enum HwAuthenticatorType : uint32_t { - HW_AUTH_NONE = 0, - HW_AUTH_PASSWORD = 1, - HW_AUTH_FINGERPRINT = 2, - HW_AUTH_ANY = 0xffffffff, -}; - -/* TODO import from keymaster HIDL when available */ -struct HwAuthToken { - uint8_t version; - uint64_t challenge; - uint64_t userId; - uint64_t authenticatorId; - uint32_t authenticatorType; - uint64_t timestamp; - uint8_t[32] hmac; -}; - struct FingerprintFingerId { /* Group ID */ uint32_t gid; @@ -121,7 +123,7 @@ struct FingerprintAuthenticated { /* Matched template ID */ FingerprintFingerId finger; /* Authentication result from the keymaster */ - HwAuthToken hat; + uint8_t[69] hat; }; /* Run time type identification for the notify() call payload. */ @@ -137,12 +139,12 @@ enum FingerprintMsgType : int32_t { struct FingerprintMsg { /* Selects the payload below */ FingerprintMsgType type; - union data { + union Data { FingerprintError error; FingerprintEnroll enroll; FingerprintEnumerated enumerated; FingerprintRemoved removed; FingerprintAcquired acquired; FingerprintAuthenticated authenticated; - }; + } data; };