blob: a710535facf8086994c303a37ff360f2a9210082 [file] [log] [blame]
Selene Huang31ab4042020-04-29 04:22:39 -07001/*
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
Shawn Willden08a7e432020-12-11 13:05:27 +000017#define LOG_TAG "android.hardware.security.keymint-service"
Selene Huang31ab4042020-04-29 04:22:39 -070018
19#include <android-base/logging.h>
20#include <android/binder_manager.h>
21#include <android/binder_process.h>
22
Shawn Willden08a7e432020-12-11 13:05:27 +000023#include <AndroidKeyMintDevice.h>
Selene Huang31ab4042020-04-29 04:22:39 -070024#include <keymaster/soft_keymaster_logger.h>
25
Shawn Willden08a7e432020-12-11 13:05:27 +000026using aidl::android::hardware::security::keymint::AndroidKeyMintDevice;
27using aidl::android::hardware::security::keymint::SecurityLevel;
Selene Huang31ab4042020-04-29 04:22:39 -070028
29int 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);
Shawn Willden08a7e432020-12-11 13:05:27 +000033 std::shared_ptr<AndroidKeyMintDevice> keyMint =
34 ndk::SharedRefBase::make<AndroidKeyMintDevice>(SecurityLevel::SOFTWARE);
Selene Huang31ab4042020-04-29 04:22:39 -070035
36 keymaster::SoftKeymasterLogger logger;
Shawn Willden08a7e432020-12-11 13:05:27 +000037 const auto instanceName = std::string(AndroidKeyMintDevice::descriptor) + "/default";
Selene Huang31ab4042020-04-29 04:22:39 -070038 LOG(INFO) << "instance: " << instanceName;
39 binder_status_t status =
Shawn Willden08a7e432020-12-11 13:05:27 +000040 AServiceManager_addService(keyMint->asBinder().get(), instanceName.c_str());
Selene Huang31ab4042020-04-29 04:22:39 -070041 CHECK(status == STATUS_OK);
42
43 ABinderProcess_joinThreadPool();
44 return EXIT_FAILURE; // should not reach
45}