Selene Huang | 31ab404 | 2020-04-29 04:22:39 -0700 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 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 | #define LOG_TAG "android.hardware.keymint1-service" |
| 18 | |
| 19 | #include <android-base/logging.h> |
| 20 | #include <android/binder_manager.h> |
| 21 | #include <android/binder_process.h> |
| 22 | |
| 23 | #include <AndroidKeyMint1Device.h> |
| 24 | #include <keymaster/soft_keymaster_logger.h> |
| 25 | |
| 26 | using aidl::android::hardware::keymint::SecurityLevel; |
| 27 | using aidl::android::hardware::keymint::V1_0::AndroidKeyMint1Device; |
| 28 | |
| 29 | int main() { |
| 30 | // Zero threads seems like a useless pool, but below we'll join this thread to it, increasing |
| 31 | // the pool size to 1. |
| 32 | ABinderProcess_setThreadPoolMaxThreadCount(0); |
| 33 | std::shared_ptr<AndroidKeyMint1Device> km5 = |
| 34 | ndk::SharedRefBase::make<AndroidKeyMint1Device>(SecurityLevel::SOFTWARE); |
| 35 | |
| 36 | keymaster::SoftKeymasterLogger logger; |
| 37 | const auto instanceName = std::string(AndroidKeyMint1Device::descriptor) + "/default"; |
| 38 | LOG(INFO) << "instance: " << instanceName; |
| 39 | binder_status_t status = |
| 40 | AServiceManager_addService(km5->asBinder().get(), instanceName.c_str()); |
| 41 | CHECK(status == STATUS_OK); |
| 42 | |
| 43 | ABinderProcess_joinThreadPool(); |
| 44 | return EXIT_FAILURE; // should not reach |
| 45 | } |