blob: 3ee7836ee19c410bc1ce0e30378572afdc74bd51 [file] [log] [blame]
Sasha Levitskiy965bd322016-10-21 10:55:25 -07001/*
2 * Copyright (C) 2016 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include <hardware/hardware.h>
18#include <hardware/fingerprint.h>
19#include "BiometricsFingerprint.h"
20
21namespace android {
22namespace hardware {
23namespace biometrics {
24namespace fingerprint {
25namespace V2_1 {
26namespace implementation {
27
28sp<IBiometricsFingerprintClientCallback>
29 BiometricsFingerprint::mClientCallback = nullptr;
30
31BiometricsFingerprint::BiometricsFingerprint(fingerprint_device_t *device)
32 : mDevice(device) {}
33
34BiometricsFingerprint::~BiometricsFingerprint() {
35 ALOG(LOG_VERBOSE, LOG_TAG, "nativeCloseHal()\n");
36 if (mDevice == NULL) {
37 ALOGE("No valid device");
38 return;
39 }
40 int err;
41 if (0 != (err = mDevice->common.close(
42 reinterpret_cast<hw_device_t*>(mDevice)))) {
43 ALOGE("Can't close fingerprint module, error: %d", err);
44 return;
45 }
46 mDevice = NULL;
47}
48
49Return<void> BiometricsFingerprint::setNotify(
50 const sp<IBiometricsFingerprintClientCallback>& clientCallback,
51 setNotify_cb cb) {
52 mClientCallback = clientCallback;
53 int32_t debugErrno = mDevice->set_notify(mDevice, notify);
54 cb(debugErrno == 0, debugErrno);
55 return Void();
56}
57
58Return<uint64_t> BiometricsFingerprint::preEnroll() {
59 return mDevice->pre_enroll(mDevice);
60}
61
62Return<void> BiometricsFingerprint::enroll(const HwAuthToken& hat, uint32_t gid,
63 uint32_t timeoutSec, enroll_cb cb) {
64 const hw_auth_token_t* authToken =
65 reinterpret_cast<const hw_auth_token_t*>(&hat);
66 int32_t debugErrno = mDevice->enroll(mDevice, authToken, gid, timeoutSec);
67 cb(debugErrno == 0, debugErrno);
68 return Void();
69}
70
71Return<void> BiometricsFingerprint::postEnroll(postEnroll_cb cb) {
72 int32_t debugErrno = mDevice->post_enroll(mDevice);
73 cb(debugErrno == 0, debugErrno);
74 return Void();
75}
76
77Return<uint64_t> BiometricsFingerprint::getAuthenticatorId() {
78 return mDevice->get_authenticator_id(mDevice);
79}
80
81Return<void> BiometricsFingerprint::cancel(cancel_cb cb) {
82 int32_t debugErrno = mDevice->cancel(mDevice);
83 cb(debugErrno == 0, debugErrno);
84 return Void();
85}
86
87Return<void> BiometricsFingerprint::enumerate(enumerate_cb cb) {
88 int32_t debugErrno = mDevice->enumerate(mDevice);
89 cb(debugErrno == 0, debugErrno);
90 return Void();
91}
92
93Return<void> BiometricsFingerprint::remove(uint32_t gid, uint32_t fid,
94 remove_cb cb) {
95 int32_t debugErrno = mDevice->remove(mDevice, gid, fid);
96 cb(debugErrno == 0, debugErrno);
97 return Void();
98}
99
100Return<void> BiometricsFingerprint::setActiveGroup(uint32_t gid,
101 const hidl_string& storePath, setActiveGroup_cb cb) {
102 if (storePath.size() >= PATH_MAX || storePath.size() <= 0) {
103 ALOGE("Bad path length: %zd", storePath.size());
104 }
105 int32_t debugErrno = mDevice->set_active_group(mDevice, gid,
106 storePath.c_str());
107 cb(debugErrno == 0, debugErrno);
108 return Void();
109}
110
111Return<void> BiometricsFingerprint::authenticate(uint64_t operationId,
112 uint32_t gid, authenticate_cb cb) {
113 int32_t debugErrno = mDevice->authenticate(mDevice, operationId, gid);
114 cb(debugErrno == 0, debugErrno);
115 return Void();
116}
117
118IBiometricsFingerprint* HIDL_FETCH_IBiometricsFingerprint(const char*) {
119 int err;
120 const hw_module_t *hw_mdl = NULL;
121 if (0 != (err = hw_get_module(FINGERPRINT_HARDWARE_MODULE_ID, &hw_mdl))) {
122 ALOGE("Can't open fingerprint HW Module, error: %d", err);
123 return nullptr;
124 }
125 if (hw_mdl == NULL) {
126 ALOGE("No valid fingerprint module");
127 return nullptr;
128 }
129
130 fingerprint_module_t const *module =
131 reinterpret_cast<const fingerprint_module_t*>(hw_mdl);
132 if (module->common.methods->open == NULL) {
133 ALOGE("No valid open method");
134 return nullptr;
135 }
136
137 hw_device_t *device = NULL;
138
139 if (0 != (err = module->common.methods->open(hw_mdl, NULL, &device))) {
140 ALOGE("Can't open fingerprint methods, error: %d", err);
141 return nullptr;
142 }
143
144 return new BiometricsFingerprint(
145 reinterpret_cast<fingerprint_device_t*>(device));
146}
147
148} // namespace implementation
149} // namespace V2_1
150} // namespace fingerprint
151} // namespace biometrics
152} // namespace hardware
153} // namespace android