blob: 2cdad0f6376bf1a4f8d02d6038718e43ffc7ebb5 [file] [log] [blame]
Andrew Scull9ba26572021-05-27 19:20:46 +00001/*
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 Sculldd077872021-06-01 10:22:07 +000025#include "MicrodroidKeyMintDevice.h"
26
27using aidl::android::hardware::security::keymint::MicrodroidKeyMintDevice;
Andrew Scull9ba26572021-05-27 19:20:46 +000028using aidl::android::hardware::security::keymint::SecurityLevel;
29
Andrew Scull9ba26572021-05-27 19:20:46 +000030int main() {
Andrew Scull70bbb1f2021-07-06 11:00:38 +000031 // Zero threads seems like a useless pool, but below we'll join this thread
32 // to it, increasing the pool size to 1.
Andrew Scull9ba26572021-05-27 19:20:46 +000033 ABinderProcess_setThreadPoolMaxThreadCount(0);
Andrew Scull70bbb1f2021-07-06 11:00:38 +000034
Andrew Scull9ba26572021-05-27 19:20:46 +000035 // Add Keymint Service
Andrew Sculldd077872021-06-01 10:22:07 +000036 std::shared_ptr<MicrodroidKeyMintDevice> keyMint =
Andrew Scull70bbb1f2021-07-06 11:00:38 +000037 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 Scull9ba26572021-05-27 19:20:46 +000043
44 ABinderProcess_joinThreadPool();
45 return EXIT_FAILURE; // should not reach
46}