Ilya Matyukhin | a9a3c85 | 2020-08-18 03:09:41 -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 | |
| 17 | #include "Fingerprint.h" |
Jeff Pu | df81c96 | 2024-03-06 10:58:17 -0500 | [diff] [blame] | 18 | #include "VirtualHal.h" |
Ilya Matyukhin | a9a3c85 | 2020-08-18 03:09:41 -0700 | [diff] [blame] | 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; |
Jeff Pu | df81c96 | 2024-03-06 10:58:17 -0500 | [diff] [blame] | 25 | using aidl::android::hardware::biometrics::fingerprint::VirtualHal; |
Ilya Matyukhin | a9a3c85 | 2020-08-18 03:09:41 -0700 | [diff] [blame] | 26 | |
Jeff Pu | e0263c4 | 2024-07-17 12:33:29 -0400 | [diff] [blame^] | 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]; |
Ilya Matyukhin | a9a3c85 | 2020-08-18 03:09:41 -0700 | [diff] [blame] | 34 | ABinderProcess_setThreadPoolMaxThreadCount(0); |
| 35 | std::shared_ptr<Fingerprint> hal = ndk::SharedRefBase::make<Fingerprint>(); |
Jeff Pu | e0263c4 | 2024-07-17 12:33:29 -0400 | [diff] [blame^] | 36 | std::shared_ptr<VirtualHal> hal_vhal = ndk::SharedRefBase::make<VirtualHal>(hal); |
Jeff Pu | df81c96 | 2024-03-06 10:58:17 -0500 | [diff] [blame] | 37 | |
| 38 | if (hal->connected()) { |
Jeff Pu | e0263c4 | 2024-07-17 12:33:29 -0400 | [diff] [blame^] | 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 | } |
Jeff Pu | df81c96 | 2024-03-06 10:58:17 -0500 | [diff] [blame] | 59 | AServiceManager_forceLazyServicesPersist(true); |
| 60 | } else { |
| 61 | LOG(ERROR) << "Fingerprint HAL is not connected"; |
| 62 | } |
Ilya Matyukhin | a9a3c85 | 2020-08-18 03:09:41 -0700 | [diff] [blame] | 63 | |
| 64 | ABinderProcess_joinThreadPool(); |
| 65 | return EXIT_FAILURE; // should not reach |
| 66 | } |