1 /*
2 * Copyright (C) 2020 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 "Fingerprint.h"
18 #include "VirtualHal.h"
19
20 #include <android-base/logging.h>
21 #include <android/binder_manager.h>
22 #include <android/binder_process.h>
23
24 using aidl::android::hardware::biometrics::fingerprint::Fingerprint;
25 using aidl::android::hardware::biometrics::fingerprint::VirtualHal;
26
main(int argc,char ** argv)27 int main(int argc, char** argv) {
28 if (argc < 2) {
29 LOG(ERROR) << "Missing argument -> exiting";
30 return EXIT_FAILURE;
31 }
32
33 LOG(INFO) << "Fingerprint HAL started: " << argv[1];
34 ABinderProcess_setThreadPoolMaxThreadCount(0);
35 std::shared_ptr<Fingerprint> hal = ndk::SharedRefBase::make<Fingerprint>();
36 std::shared_ptr<VirtualHal> hal_vhal = ndk::SharedRefBase::make<VirtualHal>(hal);
37
38 if (hal->connected()) {
39 if (strcmp(argv[1], "default") == 0) {
40 const std::string instance = std::string(Fingerprint::descriptor) + "/default";
41 auto binder = hal->asBinder();
42 auto binder_ext = hal_vhal->asBinder();
43 CHECK(STATUS_OK == AIBinder_setExtension(binder.get(), binder_ext.get()));
44 binder_status_t status =
45 AServiceManager_registerLazyService(binder.get(), instance.c_str());
46 CHECK_EQ(status, STATUS_OK);
47 LOG(INFO) << "started IFingerprint/default";
48 } else if (strcmp(argv[1], "virtual") == 0) {
49 const std::string instance = std::string(VirtualHal::descriptor) + "/virtual";
50 auto binder = hal_vhal->asBinder();
51 binder_status_t status =
52 AServiceManager_registerLazyService(binder.get(), instance.c_str());
53 CHECK_EQ(status, STATUS_OK);
54 LOG(INFO) << "started IVirtualHal/virtual";
55 } else {
56 LOG(ERROR) << "Unexpected argument: " << argv[1];
57 return EXIT_FAILURE;
58 }
59 AServiceManager_forceLazyServicesPersist(true);
60 } else {
61 LOG(ERROR) << "Fingerprint HAL is not connected";
62 }
63
64 ABinderProcess_joinThreadPool();
65 return EXIT_FAILURE; // should not reach
66 }
67