Ilya Matyukhin | 0916698 | 2020-10-12 13:41:03 -0700 | [diff] [blame] | 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 | |
Jeff Pu | a3c5736 | 2024-06-10 15:03:50 +0000 | [diff] [blame] | 17 | #undef LOG_TAG |
| 18 | #define LOG_TAG "FaceVirtualHal" |
| 19 | |
Ilya Matyukhin | 0916698 | 2020-10-12 13:41:03 -0700 | [diff] [blame] | 20 | #include "Face.h" |
Jeff Pu | a3c5736 | 2024-06-10 15:03:50 +0000 | [diff] [blame] | 21 | #include "VirtualHal.h" |
Ilya Matyukhin | 0916698 | 2020-10-12 13:41:03 -0700 | [diff] [blame] | 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; |
Jeff Pu | a3c5736 | 2024-06-10 15:03:50 +0000 | [diff] [blame] | 28 | using aidl::android::hardware::biometrics::face::VirtualHal; |
Ilya Matyukhin | 0916698 | 2020-10-12 13:41:03 -0700 | [diff] [blame] | 29 | |
Jeff Pu | a3c5736 | 2024-06-10 15:03:50 +0000 | [diff] [blame] | 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]; |
Ilya Matyukhin | 0916698 | 2020-10-12 13:41:03 -0700 | [diff] [blame] | 36 | ABinderProcess_setThreadPoolMaxThreadCount(0); |
| 37 | std::shared_ptr<Face> hal = ndk::SharedRefBase::make<Face>(); |
Jeff Pu | a3c5736 | 2024-06-10 15:03:50 +0000 | [diff] [blame] | 38 | std::shared_ptr<VirtualHal> hal_vhal = ndk::SharedRefBase::make<VirtualHal>(hal); |
Ilya Matyukhin | 0916698 | 2020-10-12 13:41:03 -0700 | [diff] [blame] | 39 | |
Jeff Pu | a3c5736 | 2024-06-10 15:03:50 +0000 | [diff] [blame] | 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 | } |
Jeff Pu | 4b5e5ce | 2023-09-06 14:47:49 +0000 | [diff] [blame] | 58 | AServiceManager_forceLazyServicesPersist(true); |
Ilya Matyukhin | 0916698 | 2020-10-12 13:41:03 -0700 | [diff] [blame] | 59 | |
| 60 | ABinderProcess_joinThreadPool(); |
Jeff Pu | a3c5736 | 2024-06-10 15:03:50 +0000 | [diff] [blame] | 61 | return EXIT_FAILURE; // should not reach here |
Ilya Matyukhin | 0916698 | 2020-10-12 13:41:03 -0700 | [diff] [blame] | 62 | } |