Andrew Scull | 9ba2657 | 2021-05-27 19:20:46 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2021, 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.security.keymint-service" |
| 18 | |
| 19 | #include <AndroidKeyMintDevice.h> |
| 20 | #include <android-base/logging.h> |
| 21 | #include <android/binder_manager.h> |
| 22 | #include <android/binder_process.h> |
| 23 | #include <keymaster/soft_keymaster_logger.h> |
| 24 | |
Andrew Scull | dd07787 | 2021-06-01 10:22:07 +0000 | [diff] [blame] | 25 | #include "MicrodroidKeyMintDevice.h" |
| 26 | |
| 27 | using aidl::android::hardware::security::keymint::MicrodroidKeyMintDevice; |
Andrew Scull | 9ba2657 | 2021-05-27 19:20:46 +0000 | [diff] [blame] | 28 | using aidl::android::hardware::security::keymint::SecurityLevel; |
| 29 | |
Andrew Scull | 9ba2657 | 2021-05-27 19:20:46 +0000 | [diff] [blame] | 30 | int main() { |
Andrew Scull | 70bbb1f | 2021-07-06 11:00:38 +0000 | [diff] [blame] | 31 | // Zero threads seems like a useless pool, but below we'll join this thread |
| 32 | // to it, increasing the pool size to 1. |
Andrew Scull | 9ba2657 | 2021-05-27 19:20:46 +0000 | [diff] [blame] | 33 | ABinderProcess_setThreadPoolMaxThreadCount(0); |
Andrew Scull | 70bbb1f | 2021-07-06 11:00:38 +0000 | [diff] [blame] | 34 | |
Andrew Scull | 9ba2657 | 2021-05-27 19:20:46 +0000 | [diff] [blame] | 35 | // Add Keymint Service |
Andrew Scull | dd07787 | 2021-06-01 10:22:07 +0000 | [diff] [blame] | 36 | std::shared_ptr<MicrodroidKeyMintDevice> keyMint = |
Andrew Scull | 70bbb1f | 2021-07-06 11:00:38 +0000 | [diff] [blame] | 37 | ndk::SharedRefBase::make<MicrodroidKeyMintDevice>(SecurityLevel::SOFTWARE); |
| 38 | auto instanceName = std::string(MicrodroidKeyMintDevice::descriptor) + "/default"; |
| 39 | LOG(INFO) << "adding keymint service instance: " << instanceName; |
| 40 | binder_status_t status = |
| 41 | AServiceManager_addService(keyMint->asBinder().get(), instanceName.c_str()); |
| 42 | CHECK(status == STATUS_OK); |
Andrew Scull | 9ba2657 | 2021-05-27 19:20:46 +0000 | [diff] [blame] | 43 | |
| 44 | ABinderProcess_joinThreadPool(); |
| 45 | return EXIT_FAILURE; // should not reach |
| 46 | } |