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