diff options
author | Jim Miller | 2015-05-07 20:52:53 -0500 |
---|---|---|
committer | Jim Miller | 2015-05-20 16:55:31 -0500 |
commit | a34dc46c360d42d843f5fcba22d35862139bacee (patch) | |
tree | 036a1ecc625111a436b31f3d5b0004a81e7da739 /fingerprintd | |
parent | 7eb3abdb3ba500d3acca82b95705f34128251015 (diff) | |
download | platform-system-core-a34dc46c360d42d843f5fcba22d35862139bacee.tar.gz platform-system-core-a34dc46c360d42d843f5fcba22d35862139bacee.tar.xz platform-system-core-a34dc46c360d42d843f5fcba22d35862139bacee.zip |
Move from native FingerprintService implementation to fingerprintd
This adds a new service, fingerprintd, that manages fingerprint
hardware from a separate process. It provides a binder interface that
FingerprintManager uses to talk to the fingerprint HAL.
Change-Id: I64b92589f4d75743ebe96894f07bec515945c61e
Diffstat (limited to 'fingerprintd')
-rw-r--r-- | fingerprintd/Android.mk | 33 | ||||
-rw-r--r-- | fingerprintd/FingerprintDaemonProxy.cpp | 238 | ||||
-rw-r--r-- | fingerprintd/FingerprintDaemonProxy.h | 62 | ||||
-rw-r--r-- | fingerprintd/IFingerprintDaemon.cpp | 186 | ||||
-rw-r--r-- | fingerprintd/IFingerprintDaemon.h | 84 | ||||
-rw-r--r-- | fingerprintd/IFingerprintDaemonCallback.cpp | 91 | ||||
-rw-r--r-- | fingerprintd/IFingerprintDaemonCallback.h | 55 | ||||
-rw-r--r-- | fingerprintd/fingerprintd.cpp | 55 |
8 files changed, 804 insertions, 0 deletions
diff --git a/fingerprintd/Android.mk b/fingerprintd/Android.mk new file mode 100644 index 000000000..48b95258a --- /dev/null +++ b/fingerprintd/Android.mk | |||
@@ -0,0 +1,33 @@ | |||
1 | # | ||
2 | # Copyright (C) 2015 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 | LOCAL_PATH := $(call my-dir) | ||
18 | |||
19 | include $(CLEAR_VARS) | ||
20 | LOCAL_CFLAGS := -Wall -Wextra -Werror -Wunused | ||
21 | LOCAL_SRC_FILES := \ | ||
22 | FingerprintDaemonProxy.cpp \ | ||
23 | IFingerprintDaemon.cpp \ | ||
24 | IFingerprintDaemonCallback.cpp \ | ||
25 | fingerprintd.cpp | ||
26 | LOCAL_MODULE := fingerprintd | ||
27 | LOCAL_SHARED_LIBRARIES := \ | ||
28 | libbinder \ | ||
29 | liblog \ | ||
30 | libhardware \ | ||
31 | libutils \ | ||
32 | libkeystore_binder | ||
33 | include $(BUILD_EXECUTABLE) | ||
diff --git a/fingerprintd/FingerprintDaemonProxy.cpp b/fingerprintd/FingerprintDaemonProxy.cpp new file mode 100644 index 000000000..2091a2c56 --- /dev/null +++ b/fingerprintd/FingerprintDaemonProxy.cpp | |||
@@ -0,0 +1,238 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2015 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 | #define LOG_TAG "fingerprintd" | ||
18 | |||
19 | #include <binder/IServiceManager.h> | ||
20 | #include <hardware/hardware.h> | ||
21 | #include <hardware/fingerprint.h> | ||
22 | #include <hardware/hw_auth_token.h> | ||
23 | #include <keystore/IKeystoreService.h> | ||
24 | #include <keystore/keystore.h> // for error codes | ||
25 | #include <utils/Log.h> | ||
26 | |||
27 | #include "FingerprintDaemonProxy.h" | ||
28 | |||
29 | namespace android { | ||
30 | |||
31 | FingerprintDaemonProxy* FingerprintDaemonProxy::sInstance = NULL; | ||
32 | |||
33 | // Supported fingerprint HAL version | ||
34 | static const uint16_t kVersion = HARDWARE_MODULE_API_VERSION(2, 0); | ||
35 | |||
36 | FingerprintDaemonProxy::FingerprintDaemonProxy() : mModule(NULL), mDevice(NULL), mCallback(NULL) { | ||
37 | |||
38 | } | ||
39 | |||
40 | FingerprintDaemonProxy::~FingerprintDaemonProxy() { | ||
41 | closeHal(); | ||
42 | } | ||
43 | |||
44 | void FingerprintDaemonProxy::hal_notify_callback(fingerprint_msg_t msg) { | ||
45 | FingerprintDaemonProxy* instance = FingerprintDaemonProxy::getInstance(); | ||
46 | const sp<IFingerprintDaemonCallback> callback = instance->mCallback; | ||
47 | if (callback == NULL) { | ||
48 | ALOGE("Invalid callback object"); | ||
49 | return; | ||
50 | } | ||
51 | const int64_t device = (int64_t) instance->mDevice; | ||
52 | switch (msg.type) { | ||
53 | case FINGERPRINT_ERROR: | ||
54 | ALOGD("onError(%d)", msg.data.error); | ||
55 | callback->onError(device, msg.data.error); | ||
56 | break; | ||
57 | case FINGERPRINT_ACQUIRED: | ||
58 | ALOGD("onAcquired(%d)", msg.data.acquired.acquired_info); | ||
59 | callback->onAcquired(device, msg.data.acquired.acquired_info); | ||
60 | break; | ||
61 | case FINGERPRINT_AUTHENTICATED: | ||
62 | ALOGD("onAuthenticated(fid=%d, gid=%d)", | ||
63 | msg.data.authenticated.finger.fid, | ||
64 | msg.data.authenticated.finger.gid); | ||
65 | if (msg.data.authenticated.finger.fid != 0) { | ||
66 | uint8_t* hat = reinterpret_cast<uint8_t *>(&msg.data.authenticated.hat); | ||
67 | instance->notifyKeystore(hat, sizeof(msg.data.authenticated.hat)); | ||
68 | } | ||
69 | callback->onAuthenticated(device, | ||
70 | msg.data.authenticated.finger.fid, | ||
71 | msg.data.authenticated.finger.gid); | ||
72 | break; | ||
73 | case FINGERPRINT_TEMPLATE_ENROLLING: | ||
74 | ALOGD("onEnrollResult(fid=%d, gid=%d, rem=%d)", | ||
75 | msg.data.enroll.finger.fid, | ||
76 | msg.data.enroll.finger.gid, | ||
77 | msg.data.enroll.samples_remaining); | ||
78 | callback->onEnrollResult(device, | ||
79 | msg.data.enroll.finger.fid, | ||
80 | msg.data.enroll.finger.gid, | ||
81 | msg.data.enroll.samples_remaining); | ||
82 | break; | ||
83 | case FINGERPRINT_TEMPLATE_REMOVED: | ||
84 | ALOGD("onRemove(fid=%d, gid=%d)", | ||
85 | msg.data.removed.finger.fid, | ||
86 | msg.data.removed.finger.gid); | ||
87 | callback->onRemoved(device, | ||
88 | msg.data.removed.finger.fid, | ||
89 | msg.data.removed.finger.gid); | ||
90 | break; | ||
91 | default: | ||
92 | ALOGE("invalid msg: %d", msg.type); | ||
93 | return; | ||
94 | } | ||
95 | } | ||
96 | |||
97 | void FingerprintDaemonProxy::notifyKeystore(uint8_t *auth_token, size_t auth_token_length) { | ||
98 | if (auth_token != NULL && auth_token_length > 0) { | ||
99 | // TODO: cache service? | ||
100 | sp < IServiceManager > sm = defaultServiceManager(); | ||
101 | sp < IBinder > binder = sm->getService(String16("android.security.keystore")); | ||
102 | sp < IKeystoreService > service = interface_cast < IKeystoreService > (binder); | ||
103 | if (service != NULL) { | ||
104 | status_t ret = service->addAuthToken(auth_token, auth_token_length); | ||
105 | if (ret != ResponseCode::NO_ERROR) { | ||
106 | ALOGE("Falure sending auth token to KeyStore: %d", ret); | ||
107 | } | ||
108 | } else { | ||
109 | ALOGE("Unable to communicate with KeyStore"); | ||
110 | } | ||
111 | } | ||
112 | } | ||
113 | |||
114 | void FingerprintDaemonProxy::init(const sp<IFingerprintDaemonCallback>& callback) { | ||
115 | if (mCallback != NULL && IInterface::asBinder(callback) != IInterface::asBinder(mCallback)) { | ||
116 | IInterface::asBinder(mCallback)->unlinkToDeath(this); | ||
117 | } | ||
118 | IInterface::asBinder(callback)->linkToDeath(this); | ||
119 | mCallback = callback; | ||
120 | } | ||
121 | |||
122 | int32_t FingerprintDaemonProxy::enroll(const uint8_t* token, ssize_t tokenSize, int32_t groupId, | ||
123 | int32_t timeout) { | ||
124 | ALOG(LOG_VERBOSE, LOG_TAG, "enroll(gid=%d, timeout=%d)\n", groupId, timeout); | ||
125 | if (tokenSize != sizeof(hw_auth_token_t) ) { | ||
126 | ALOG(LOG_VERBOSE, LOG_TAG, "enroll() : invalid token size %d\n", tokenSize); | ||
127 | return -1; | ||
128 | } | ||
129 | const hw_auth_token_t* authToken = reinterpret_cast<const hw_auth_token_t*>(token); | ||
130 | return mDevice->enroll(mDevice, authToken, groupId, timeout); | ||
131 | } | ||
132 | |||
133 | uint64_t FingerprintDaemonProxy::preEnroll() { | ||
134 | return mDevice->pre_enroll(mDevice); | ||
135 | } | ||
136 | |||
137 | int32_t FingerprintDaemonProxy::stopEnrollment() { | ||
138 | ALOG(LOG_VERBOSE, LOG_TAG, "stopEnrollment()\n"); | ||
139 | return mDevice->cancel(mDevice); | ||
140 | } | ||
141 | |||
142 | int32_t FingerprintDaemonProxy::authenticate(uint64_t sessionId, uint32_t groupId) { | ||
143 | ALOG(LOG_VERBOSE, LOG_TAG, "authenticate(sid=%" PRId64 ", gid=%d)\n", sessionId, groupId); | ||
144 | return mDevice->authenticate(mDevice, sessionId, groupId); | ||
145 | } | ||
146 | |||
147 | int32_t FingerprintDaemonProxy::stopAuthentication() { | ||
148 | ALOG(LOG_VERBOSE, LOG_TAG, "stopAuthentication()\n"); | ||
149 | return mDevice->cancel(mDevice); | ||
150 | } | ||
151 | |||
152 | int32_t FingerprintDaemonProxy::remove(int32_t fingerId, int32_t groupId) { | ||
153 | ALOG(LOG_VERBOSE, LOG_TAG, "remove(fid=%d, gid=%d)\n", fingerId, groupId); | ||
154 | fingerprint_finger_id_t finger; | ||
155 | finger.fid = fingerId; | ||
156 | finger.gid = groupId; | ||
157 | return mDevice->remove(mDevice, finger); | ||
158 | } | ||
159 | |||
160 | uint64_t FingerprintDaemonProxy::getAuthenticatorId() { | ||
161 | return mDevice->get_authenticator_id(mDevice); | ||
162 | } | ||
163 | |||
164 | int32_t FingerprintDaemonProxy::setActiveGroup(int32_t groupId, const uint8_t* path, | ||
165 | ssize_t pathlen) { | ||
166 | if (pathlen >= PATH_MAX) { | ||
167 | ALOGE("Path name is too long\n"); | ||
168 | return -1; | ||
169 | } | ||
170 | // Convert to null-terminated string | ||
171 | char path_name[PATH_MAX]; | ||
172 | memcpy(path_name, path, pathlen); | ||
173 | path_name[pathlen] = '\0'; | ||
174 | ALOG(LOG_VERBOSE, LOG_TAG, "setActiveGroup(%d, %s, %d)", groupId, path_name, pathlen); | ||
175 | return mDevice->set_active_group(mDevice, groupId, path_name); | ||
176 | return -1; | ||
177 | } | ||
178 | |||
179 | int64_t FingerprintDaemonProxy::openHal() { | ||
180 | ALOG(LOG_VERBOSE, LOG_TAG, "nativeOpenHal()\n"); | ||
181 | int err; | ||
182 | const hw_module_t *hw_module = NULL; | ||
183 | if (0 != (err = hw_get_module(FINGERPRINT_HARDWARE_MODULE_ID, &hw_module))) { | ||
184 | ALOGE("Can't open fingerprint HW Module, error: %d", err); | ||
185 | return 0; | ||
186 | } | ||
187 | if (NULL == hw_module) { | ||
188 | ALOGE("No valid fingerprint module"); | ||
189 | return 0; | ||
190 | } | ||
191 | |||
192 | mModule = reinterpret_cast<const fingerprint_module_t*>(hw_module); | ||
193 | |||
194 | if (mModule->common.methods->open == NULL) { | ||
195 | ALOGE("No valid open method"); | ||
196 | return 0; | ||
197 | } | ||
198 | |||
199 | hw_device_t *device = NULL; | ||
200 | |||
201 | if (0 != (err = mModule->common.methods->open(hw_module, NULL, &device))) { | ||
202 | ALOGE("Can't open fingerprint methods, error: %d", err); | ||
203 | return 0; | ||
204 | } | ||
205 | |||
206 | if (kVersion != device->version) { | ||
207 | ALOGE("Wrong fp version. Expected %d, got %d", kVersion, device->version); | ||
208 | // return 0; // FIXME | ||
209 | } | ||
210 | |||
211 | mDevice = reinterpret_cast<fingerprint_device_t*>(device); | ||
212 | err = mDevice->set_notify(mDevice, hal_notify_callback); | ||
213 | if (err < 0) { | ||
214 | ALOGE("Failed in call to set_notify(), err=%d", err); | ||
215 | return 0; | ||
216 | } | ||
217 | |||
218 | // Sanity check - remove | ||
219 | if (mDevice->notify != hal_notify_callback) { | ||
220 | ALOGE("NOTIFY not set properly: %p != %p", mDevice->notify, hal_notify_callback); | ||
221 | } | ||
222 | |||
223 | ALOG(LOG_VERBOSE, LOG_TAG, "fingerprint HAL successfully initialized"); | ||
224 | return reinterpret_cast<int64_t>(mDevice); // This is just a handle | ||
225 | } | ||
226 | |||
227 | int32_t FingerprintDaemonProxy::closeHal() { | ||
228 | return -ENOSYS; // TODO | ||
229 | } | ||
230 | |||
231 | void FingerprintDaemonProxy::binderDied(const wp<IBinder>& who) { | ||
232 | ALOGD("binder died"); | ||
233 | if (IInterface::asBinder(mCallback) == who) { | ||
234 | mCallback = NULL; | ||
235 | } | ||
236 | } | ||
237 | |||
238 | } | ||
diff --git a/fingerprintd/FingerprintDaemonProxy.h b/fingerprintd/FingerprintDaemonProxy.h new file mode 100644 index 000000000..95c926bda --- /dev/null +++ b/fingerprintd/FingerprintDaemonProxy.h | |||
@@ -0,0 +1,62 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2015 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 | #ifndef FINGERPRINT_DAEMON_PROXY_H_ | ||
18 | #define FINGERPRINT_DAEMON_PROXY_H_ | ||
19 | |||
20 | #include "IFingerprintDaemon.h" | ||
21 | #include "IFingerprintDaemonCallback.h" | ||
22 | |||
23 | namespace android { | ||
24 | |||
25 | class FingerprintDaemonProxy : public BnFingerprintDaemon { | ||
26 | public: | ||
27 | static FingerprintDaemonProxy* getInstance() { | ||
28 | if (sInstance == NULL) { | ||
29 | sInstance = new FingerprintDaemonProxy(); | ||
30 | } | ||
31 | return sInstance; | ||
32 | } | ||
33 | |||
34 | // These reflect binder methods. | ||
35 | virtual void init(const sp<IFingerprintDaemonCallback>& callback); | ||
36 | virtual int32_t enroll(const uint8_t* token, ssize_t tokenLength, int32_t groupId, int32_t timeout); | ||
37 | virtual uint64_t preEnroll(); | ||
38 | virtual int32_t stopEnrollment(); | ||
39 | virtual int32_t authenticate(uint64_t sessionId, uint32_t groupId); | ||
40 | virtual int32_t stopAuthentication(); | ||
41 | virtual int32_t remove(int32_t fingerId, int32_t groupId); | ||
42 | virtual uint64_t getAuthenticatorId(); | ||
43 | virtual int32_t setActiveGroup(int32_t groupId, const uint8_t* path, ssize_t pathLen); | ||
44 | virtual int64_t openHal(); | ||
45 | virtual int32_t closeHal(); | ||
46 | |||
47 | private: | ||
48 | FingerprintDaemonProxy(); | ||
49 | virtual ~FingerprintDaemonProxy(); | ||
50 | void binderDied(const wp<IBinder>& who); | ||
51 | void notifyKeystore(uint8_t *auth_token, size_t auth_token_length); | ||
52 | static void hal_notify_callback(fingerprint_msg_t msg); | ||
53 | |||
54 | static FingerprintDaemonProxy* sInstance; | ||
55 | fingerprint_module_t const* mModule; | ||
56 | fingerprint_device_t* mDevice; | ||
57 | sp<IFingerprintDaemonCallback> mCallback; | ||
58 | }; | ||
59 | |||
60 | } // namespace android | ||
61 | |||
62 | #endif // FINGERPRINT_DAEMON_PROXY_H_ | ||
diff --git a/fingerprintd/IFingerprintDaemon.cpp b/fingerprintd/IFingerprintDaemon.cpp new file mode 100644 index 000000000..112097984 --- /dev/null +++ b/fingerprintd/IFingerprintDaemon.cpp | |||
@@ -0,0 +1,186 @@ | |||
1 | /* | ||
2 | * Copyright 2015, 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 <inttypes.h> | ||
18 | |||
19 | #include <android_runtime/AndroidRuntime.h> | ||
20 | #include <binder/IPCThreadState.h> | ||
21 | #include <binder/IServiceManager.h> | ||
22 | #include <binder/PermissionCache.h> | ||
23 | #include <utils/String16.h> | ||
24 | #include <utils/Looper.h> | ||
25 | #include <keystore/IKeystoreService.h> | ||
26 | #include <keystore/keystore.h> // for error code | ||
27 | #include <hardware/hardware.h> | ||
28 | #include <hardware/fingerprint.h> | ||
29 | #include <hardware/hw_auth_token.h> | ||
30 | #include "IFingerprintDaemon.h" | ||
31 | #include "IFingerprintDaemonCallback.h" | ||
32 | |||
33 | namespace android { | ||
34 | |||
35 | static const String16 USE_FINGERPRINT_PERMISSION("android.permission.USE_FINGERPRINT"); | ||
36 | static const String16 MANAGE_FINGERPRINT_PERMISSION("android.permission.MANAGE_FINGERPRINT"); | ||
37 | static const String16 HAL_FINGERPRINT_PERMISSION("android.permission.MANAGE_FINGERPRINT"); // TODO | ||
38 | static const String16 DUMP_PERMISSION("android.permission.DUMP"); | ||
39 | |||
40 | const android::String16 | ||
41 | IFingerprintDaemon::descriptor("android.hardware.fingerprint.IFingerprintDaemon"); | ||
42 | |||
43 | const android::String16& | ||
44 | IFingerprintDaemon::getInterfaceDescriptor() const { | ||
45 | return IFingerprintDaemon::descriptor; | ||
46 | } | ||
47 | |||
48 | status_t BnFingerprintDaemon::onTransact(uint32_t code, const Parcel& data, Parcel* reply, | ||
49 | uint32_t flags) { | ||
50 | switch(code) { | ||
51 | case AUTHENTICATE: { | ||
52 | CHECK_INTERFACE(IFingerprintDaemon, data, reply); | ||
53 | if (!checkPermission(HAL_FINGERPRINT_PERMISSION)) { | ||
54 | return PERMISSION_DENIED; | ||
55 | } | ||
56 | const uint64_t sessionId = data.readInt64(); | ||
57 | const uint32_t groupId = data.readInt32(); | ||
58 | const int32_t ret = authenticate(sessionId, groupId); | ||
59 | reply->writeNoException(); | ||
60 | reply->writeInt32(ret); | ||
61 | return NO_ERROR; | ||
62 | }; | ||
63 | case CANCEL_AUTHENTICATION: { | ||
64 | CHECK_INTERFACE(IFingerprintDaemon, data, reply); | ||
65 | if (!checkPermission(HAL_FINGERPRINT_PERMISSION)) { | ||
66 | return PERMISSION_DENIED; | ||
67 | } | ||
68 | const int32_t ret = stopAuthentication(); | ||
69 | reply->writeNoException(); | ||
70 | reply->writeInt32(ret); | ||
71 | return NO_ERROR; | ||
72 | } | ||
73 | case ENROLL: { | ||
74 | CHECK_INTERFACE(IFingerprintDaemon, data, reply); | ||
75 | if (!checkPermission(HAL_FINGERPRINT_PERMISSION)) { | ||
76 | return PERMISSION_DENIED; | ||
77 | } | ||
78 | const ssize_t tokenSize = data.readInt32(); | ||
79 | const uint8_t* token = static_cast<const uint8_t *>(data.readInplace(tokenSize)); | ||
80 | const int32_t groupId = data.readInt32(); | ||
81 | const int32_t timeout = data.readInt32(); | ||
82 | const int32_t ret = enroll(token, tokenSize, groupId, timeout); | ||
83 | reply->writeNoException(); | ||
84 | reply->writeInt32(ret); | ||
85 | return NO_ERROR; | ||
86 | } | ||
87 | case CANCEL_ENROLLMENT: { | ||
88 | CHECK_INTERFACE(IFingerprintDaemon, data, reply); | ||
89 | if (!checkPermission(HAL_FINGERPRINT_PERMISSION)) { | ||
90 | return PERMISSION_DENIED; | ||
91 | } | ||
92 | const int32_t ret = stopEnrollment(); | ||
93 | reply->writeNoException(); | ||
94 | reply->writeInt32(ret); | ||
95 | return NO_ERROR; | ||
96 | } | ||
97 | case PRE_ENROLL: { | ||
98 | CHECK_INTERFACE(IFingerprintDaemon, data, reply); | ||
99 | if (!checkPermission(HAL_FINGERPRINT_PERMISSION)) { | ||
100 | return PERMISSION_DENIED; | ||
101 | } | ||
102 | const uint64_t ret = preEnroll(); | ||
103 | reply->writeNoException(); | ||
104 | reply->writeInt64(ret); | ||
105 | return NO_ERROR; | ||
106 | } | ||
107 | case REMOVE: { | ||
108 | CHECK_INTERFACE(IFingerprintDaemon, data, reply); | ||
109 | if (!checkPermission(HAL_FINGERPRINT_PERMISSION)) { | ||
110 | return PERMISSION_DENIED; | ||
111 | } | ||
112 | const int32_t fingerId = data.readInt32(); | ||
113 | const int32_t groupId = data.readInt32(); | ||
114 | const int32_t ret = remove(fingerId, groupId); | ||
115 | reply->writeNoException(); | ||
116 | reply->writeInt32(ret); | ||
117 | return NO_ERROR; | ||
118 | } | ||
119 | case GET_AUTHENTICATOR_ID: { | ||
120 | CHECK_INTERFACE(IFingerprintDaemon, data, reply); | ||
121 | if (!checkPermission(HAL_FINGERPRINT_PERMISSION)) { | ||
122 | return PERMISSION_DENIED; | ||
123 | } | ||
124 | const uint64_t ret = getAuthenticatorId(); | ||
125 | reply->writeNoException(); | ||
126 | reply->writeInt64(ret); | ||
127 | return NO_ERROR; | ||
128 | } | ||
129 | case SET_ACTIVE_GROUP: { | ||
130 | CHECK_INTERFACE(IFingerprintDaemon, data, reply); | ||
131 | if (!checkPermission(HAL_FINGERPRINT_PERMISSION)) { | ||
132 | return PERMISSION_DENIED; | ||
133 | } | ||
134 | const int32_t group = data.readInt32(); | ||
135 | const ssize_t pathSize = data.readInt32(); | ||
136 | const uint8_t* path = static_cast<const uint8_t *>(data.readInplace(pathSize)); | ||
137 | const int32_t ret = setActiveGroup(group, path, pathSize); | ||
138 | reply->writeNoException(); | ||
139 | reply->writeInt32(ret); | ||
140 | return NO_ERROR; | ||
141 | } | ||
142 | case OPEN_HAL: { | ||
143 | CHECK_INTERFACE(IFingerprintDaemon, data, reply); | ||
144 | if (!checkPermission(HAL_FINGERPRINT_PERMISSION)) { | ||
145 | return PERMISSION_DENIED; | ||
146 | } | ||
147 | const int64_t ret = openHal(); | ||
148 | reply->writeNoException(); | ||
149 | reply->writeInt64(ret); | ||
150 | return NO_ERROR; | ||
151 | } | ||
152 | case CLOSE_HAL: { | ||
153 | CHECK_INTERFACE(IFingerprintDaemon, data, reply); | ||
154 | if (!checkPermission(HAL_FINGERPRINT_PERMISSION)) { | ||
155 | return PERMISSION_DENIED; | ||
156 | } | ||
157 | const int32_t ret = closeHal(); | ||
158 | reply->writeNoException(); | ||
159 | reply->writeInt32(ret); | ||
160 | return NO_ERROR; | ||
161 | } | ||
162 | case INIT: { | ||
163 | CHECK_INTERFACE(IFingerprintDaemon, data, reply); | ||
164 | if (!checkPermission(HAL_FINGERPRINT_PERMISSION)) { | ||
165 | return PERMISSION_DENIED; | ||
166 | } | ||
167 | sp<IFingerprintDaemonCallback> callback = | ||
168 | interface_cast<IFingerprintDaemonCallback>(data.readStrongBinder()); | ||
169 | init(callback); | ||
170 | reply->writeNoException(); | ||
171 | return NO_ERROR; | ||
172 | } | ||
173 | default: | ||
174 | return BBinder::onTransact(code, data, reply, flags); | ||
175 | } | ||
176 | }; | ||
177 | |||
178 | bool BnFingerprintDaemon::checkPermission(const String16& permission) { | ||
179 | const IPCThreadState* ipc = IPCThreadState::self(); | ||
180 | const int calling_pid = ipc->getCallingPid(); | ||
181 | const int calling_uid = ipc->getCallingUid(); | ||
182 | return PermissionCache::checkPermission(permission, calling_pid, calling_uid); | ||
183 | } | ||
184 | |||
185 | |||
186 | }; // namespace android | ||
diff --git a/fingerprintd/IFingerprintDaemon.h b/fingerprintd/IFingerprintDaemon.h new file mode 100644 index 000000000..fe3f64b93 --- /dev/null +++ b/fingerprintd/IFingerprintDaemon.h | |||
@@ -0,0 +1,84 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2015 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 | #ifndef IFINGERPRINT_DAEMON_H_ | ||
18 | #define IFINGERPRINT_DAEMON_H_ | ||
19 | |||
20 | #include <binder/IInterface.h> | ||
21 | #include <binder/Parcel.h> | ||
22 | |||
23 | namespace android { | ||
24 | |||
25 | class IFingerprintDaemonCallback; | ||
26 | |||
27 | /* | ||
28 | * Abstract base class for native implementation of FingerprintService. | ||
29 | * | ||
30 | * Note: This must be kept manually in sync with IFingerprintDaemon.aidl | ||
31 | */ | ||
32 | class IFingerprintDaemon : public IInterface, public IBinder::DeathRecipient { | ||
33 | public: | ||
34 | enum { | ||
35 | AUTHENTICATE = IBinder::FIRST_CALL_TRANSACTION + 0, | ||
36 | CANCEL_AUTHENTICATION = IBinder::FIRST_CALL_TRANSACTION + 1, | ||
37 | ENROLL = IBinder::FIRST_CALL_TRANSACTION + 2, | ||
38 | CANCEL_ENROLLMENT = IBinder::FIRST_CALL_TRANSACTION + 3, | ||
39 | PRE_ENROLL = IBinder::FIRST_CALL_TRANSACTION + 4, | ||
40 | REMOVE = IBinder::FIRST_CALL_TRANSACTION + 5, | ||
41 | GET_AUTHENTICATOR_ID = IBinder::FIRST_CALL_TRANSACTION + 6, | ||
42 | SET_ACTIVE_GROUP = IBinder::FIRST_CALL_TRANSACTION + 7, | ||
43 | OPEN_HAL = IBinder::FIRST_CALL_TRANSACTION + 8, | ||
44 | CLOSE_HAL = IBinder::FIRST_CALL_TRANSACTION + 9, | ||
45 | INIT = IBinder::FIRST_CALL_TRANSACTION + 10, | ||
46 | }; | ||
47 | |||
48 | IFingerprintDaemon() { } | ||
49 | virtual ~IFingerprintDaemon() { } | ||
50 | virtual const android::String16& getInterfaceDescriptor() const; | ||
51 | |||
52 | // Binder interface methods | ||
53 | virtual void init(const sp<IFingerprintDaemonCallback>& callback) = 0; | ||
54 | virtual int32_t enroll(const uint8_t* token, ssize_t tokenLength, int32_t groupId, | ||
55 | int32_t timeout) = 0; | ||
56 | virtual uint64_t preEnroll() = 0; | ||
57 | virtual int32_t stopEnrollment() = 0; | ||
58 | virtual int32_t authenticate(uint64_t sessionId, uint32_t groupId) = 0; | ||
59 | virtual int32_t stopAuthentication() = 0; | ||
60 | virtual int32_t remove(int32_t fingerId, int32_t groupId) = 0; | ||
61 | virtual uint64_t getAuthenticatorId() = 0; | ||
62 | virtual int32_t setActiveGroup(int32_t groupId, const uint8_t* path, ssize_t pathLen) = 0; | ||
63 | virtual int64_t openHal() = 0; | ||
64 | virtual int32_t closeHal() = 0; | ||
65 | |||
66 | // DECLARE_META_INTERFACE - C++ client interface not needed | ||
67 | static const android::String16 descriptor; | ||
68 | static void hal_notify_callback(fingerprint_msg_t msg); | ||
69 | }; | ||
70 | |||
71 | // ---------------------------------------------------------------------------- | ||
72 | |||
73 | class BnFingerprintDaemon: public BnInterface<IFingerprintDaemon> { | ||
74 | public: | ||
75 | virtual status_t onTransact(uint32_t code, const Parcel& data, Parcel* reply, | ||
76 | uint32_t flags = 0); | ||
77 | private: | ||
78 | bool checkPermission(const String16& permission); | ||
79 | }; | ||
80 | |||
81 | } // namespace android | ||
82 | |||
83 | #endif // IFINGERPRINT_DAEMON_H_ | ||
84 | |||
diff --git a/fingerprintd/IFingerprintDaemonCallback.cpp b/fingerprintd/IFingerprintDaemonCallback.cpp new file mode 100644 index 000000000..44d8020ae --- /dev/null +++ b/fingerprintd/IFingerprintDaemonCallback.cpp | |||
@@ -0,0 +1,91 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2015 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 | #define LOG_TAG "IFingerprintDaemonCallback" | ||
18 | #include <stdint.h> | ||
19 | #include <sys/types.h> | ||
20 | #include <utils/Log.h> | ||
21 | #include <binder/Parcel.h> | ||
22 | |||
23 | #include "IFingerprintDaemonCallback.h" | ||
24 | |||
25 | namespace android { | ||
26 | |||
27 | class BpFingerprintDaemonCallback : public BpInterface<IFingerprintDaemonCallback> | ||
28 | { | ||
29 | public: | ||
30 | BpFingerprintDaemonCallback(const sp<IBinder>& impl) : | ||
31 | BpInterface<IFingerprintDaemonCallback>(impl) { | ||
32 | } | ||
33 | virtual status_t onEnrollResult(int64_t devId, int32_t fpId, int32_t gpId, int32_t rem) { | ||
34 | Parcel data, reply; | ||
35 | data.writeInterfaceToken(IFingerprintDaemonCallback::getInterfaceDescriptor()); | ||
36 | data.writeInt64(devId); | ||
37 | data.writeInt32(fpId); | ||
38 | data.writeInt32(gpId); | ||
39 | data.writeInt32(rem); | ||
40 | return remote()->transact(ON_ENROLL_RESULT, data, &reply, IBinder::FLAG_ONEWAY); | ||
41 | } | ||
42 | |||
43 | virtual status_t onAcquired(int64_t devId, int32_t acquiredInfo) { | ||
44 | Parcel data, reply; | ||
45 | data.writeInterfaceToken(IFingerprintDaemonCallback::getInterfaceDescriptor()); | ||
46 | data.writeInt64(devId); | ||
47 | data.writeInt32(acquiredInfo); | ||
48 | return remote()->transact(ON_ACQUIRED, data, &reply, IBinder::FLAG_ONEWAY); | ||
49 | } | ||
50 | |||
51 | virtual status_t onAuthenticated(int64_t devId, int32_t fpId, int32_t gpId) { | ||
52 | Parcel data, reply; | ||
53 | data.writeInterfaceToken(IFingerprintDaemonCallback::getInterfaceDescriptor()); | ||
54 | data.writeInt64(devId); | ||
55 | data.writeInt32(fpId); | ||
56 | data.writeInt32(gpId); | ||
57 | return remote()->transact(ON_AUTHENTICATED, data, &reply, IBinder::FLAG_ONEWAY); | ||
58 | } | ||
59 | |||
60 | virtual status_t onError(int64_t devId, int32_t error) { | ||
61 | Parcel data, reply; | ||
62 | data.writeInterfaceToken(IFingerprintDaemonCallback::getInterfaceDescriptor()); | ||
63 | data.writeInt64(devId); | ||
64 | data.writeInt32(error); | ||
65 | return remote()->transact(ON_ERROR, data, &reply, IBinder::FLAG_ONEWAY); | ||
66 | } | ||
67 | |||
68 | virtual status_t onRemoved(int64_t devId, int32_t fpId, int32_t gpId) { | ||
69 | Parcel data, reply; | ||
70 | data.writeInterfaceToken(IFingerprintDaemonCallback::getInterfaceDescriptor()); | ||
71 | data.writeInt64(devId); | ||
72 | data.writeInt32(fpId); | ||
73 | data.writeInt32(gpId); | ||
74 | return remote()->transact(ON_REMOVED, data, &reply, IBinder::FLAG_ONEWAY); | ||
75 | } | ||
76 | |||
77 | virtual status_t onEnumerate(int64_t devId, const int32_t* fpIds, const int32_t* gpIds, | ||
78 | int32_t sz) { | ||
79 | Parcel data, reply; | ||
80 | data.writeInterfaceToken(IFingerprintDaemonCallback::getInterfaceDescriptor()); | ||
81 | data.writeInt64(devId); | ||
82 | data.writeInt32Array(sz, fpIds); | ||
83 | data.writeInt32Array(sz, gpIds); | ||
84 | return remote()->transact(ON_ENUMERATE, data, &reply, IBinder::FLAG_ONEWAY); | ||
85 | } | ||
86 | }; | ||
87 | |||
88 | IMPLEMENT_META_INTERFACE(FingerprintDaemonCallback, | ||
89 | "android.hardware.fingerprint.IFingerprintDaemonCallback"); | ||
90 | |||
91 | }; // namespace android | ||
diff --git a/fingerprintd/IFingerprintDaemonCallback.h b/fingerprintd/IFingerprintDaemonCallback.h new file mode 100644 index 000000000..6e32213b4 --- /dev/null +++ b/fingerprintd/IFingerprintDaemonCallback.h | |||
@@ -0,0 +1,55 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2015 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 | #ifndef IFINGERPRINT_DAEMON_CALLBACK_H_ | ||
18 | #define IFINGERPRINT_DAEMON_CALLBACK_H_ | ||
19 | |||
20 | #include <inttypes.h> | ||
21 | #include <utils/Errors.h> | ||
22 | #include <binder/IInterface.h> | ||
23 | #include <binder/Parcel.h> | ||
24 | |||
25 | namespace android { | ||
26 | |||
27 | /* | ||
28 | * Communication channel back to FingerprintService.java | ||
29 | */ | ||
30 | class IFingerprintDaemonCallback : public IInterface { | ||
31 | public: | ||
32 | // must be kept in sync with IFingerprintService.aidl | ||
33 | enum { | ||
34 | ON_ENROLL_RESULT = IBinder::FIRST_CALL_TRANSACTION + 0, | ||
35 | ON_ACQUIRED = IBinder::FIRST_CALL_TRANSACTION + 1, | ||
36 | ON_AUTHENTICATED = IBinder::FIRST_CALL_TRANSACTION + 2, | ||
37 | ON_ERROR = IBinder::FIRST_CALL_TRANSACTION + 3, | ||
38 | ON_REMOVED = IBinder::FIRST_CALL_TRANSACTION + 4, | ||
39 | ON_ENUMERATE = IBinder::FIRST_CALL_TRANSACTION + 5, | ||
40 | }; | ||
41 | |||
42 | virtual status_t onEnrollResult(int64_t devId, int32_t fpId, int32_t gpId, int32_t rem) = 0; | ||
43 | virtual status_t onAcquired(int64_t devId, int32_t acquiredInfo) = 0; | ||
44 | virtual status_t onAuthenticated(int64_t devId, int32_t fingerId, int32_t groupId) = 0; | ||
45 | virtual status_t onError(int64_t devId, int32_t error) = 0; | ||
46 | virtual status_t onRemoved(int64_t devId, int32_t fingerId, int32_t groupId) = 0; | ||
47 | virtual status_t onEnumerate(int64_t devId, const int32_t* fpIds, const int32_t* gpIds, | ||
48 | int32_t sz) = 0; | ||
49 | |||
50 | DECLARE_META_INTERFACE(FingerprintDaemonCallback); | ||
51 | }; | ||
52 | |||
53 | }; // namespace android | ||
54 | |||
55 | #endif // IFINGERPRINT_DAEMON_CALLBACK_H_ | ||
diff --git a/fingerprintd/fingerprintd.cpp b/fingerprintd/fingerprintd.cpp new file mode 100644 index 000000000..8fa7ed18e --- /dev/null +++ b/fingerprintd/fingerprintd.cpp | |||
@@ -0,0 +1,55 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2015 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 | #define LOG_TAG "fingerprintd" | ||
18 | |||
19 | #include <cutils/log.h> | ||
20 | #include <utils/Log.h> | ||
21 | |||
22 | #include <binder/IPCThreadState.h> | ||
23 | #include <binder/IServiceManager.h> | ||
24 | #include <binder/PermissionCache.h> | ||
25 | #include <utils/String16.h> | ||
26 | |||
27 | #include <keystore/IKeystoreService.h> | ||
28 | #include <keystore/keystore.h> // for error codes | ||
29 | |||
30 | #include <hardware/hardware.h> | ||
31 | #include <hardware/fingerprint.h> | ||
32 | #include <hardware/hw_auth_token.h> | ||
33 | |||
34 | #include "FingerprintDaemonProxy.h" | ||
35 | |||
36 | int main() { | ||
37 | ALOGI("Starting " LOG_TAG); | ||
38 | android::sp<android::IServiceManager> serviceManager = android::defaultServiceManager(); | ||
39 | android::sp<android::FingerprintDaemonProxy> proxy = | ||
40 | android::FingerprintDaemonProxy::getInstance(); | ||
41 | android::status_t ret = serviceManager->addService( | ||
42 | android::FingerprintDaemonProxy::descriptor, proxy); | ||
43 | if (ret != android::OK) { | ||
44 | ALOGE("Couldn't register " LOG_TAG " binder service!"); | ||
45 | return -1; | ||
46 | } | ||
47 | |||
48 | /* | ||
49 | * We're the only thread in existence, so we're just going to process | ||
50 | * Binder transaction as a single-threaded program. | ||
51 | */ | ||
52 | android::IPCThreadState::self()->joinThreadPool(); | ||
53 | ALOGI("Done"); | ||
54 | return 0; | ||
55 | } | ||