blob: 4b12fc6e72ade9186f3ad93256b3e8d7cf287e5e [file] [log] [blame]
Steven Moreland80e1e6d2019-06-21 12:35:59 -07001/*
2 * Copyright (C) 2019 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 <android-base/logging.h>
18#include <binder/IPCThreadState.h>
19#include <binder/ProcessState.h>
20#include <binder/Status.h>
21#include <utils/StrongPointer.h>
22
23#include "Access.h"
24#include "ServiceManager.h"
25
Steven Moreland80e1e6d2019-06-21 12:35:59 -070026using ::android::Access;
Steven Moreland46f380b2019-10-16 16:28:21 -070027using ::android::IPCThreadState;
28using ::android::ProcessState;
29using ::android::ServiceManager;
30using ::android::os::IServiceManager;
31using ::android::sp;
Steven Moreland80e1e6d2019-06-21 12:35:59 -070032
33int main(int argc, char** argv) {
34 if (argc > 2) {
35 LOG(FATAL) << "usage: " << argv[0] << " [binder driver]";
36 }
37
38 const char* driver = argc == 2 ? argv[1] : "/dev/binder";
39
Steven Moreland1ac84c42019-07-10 17:51:27 -070040 sp<ProcessState> ps = ProcessState::initWithDriver(driver);
41 ps->setThreadPoolMaxThreadCount(0);
42 ps->setCallRestriction(ProcessState::CallRestriction::FATAL_IF_NOT_ONEWAY);
Steven Moreland80e1e6d2019-06-21 12:35:59 -070043
44 sp<ServiceManager> manager = new ServiceManager(std::make_unique<Access>());
Steven Moreland46f380b2019-10-16 16:28:21 -070045 if (!manager->addService("manager", manager, false /*allowIsolated*/, IServiceManager::DUMP_FLAG_PRIORITY_DEFAULT).isOk()) {
46 LOG(ERROR) << "Could not self register servicemanager";
47 }
48
Steven Moreland80e1e6d2019-06-21 12:35:59 -070049 IPCThreadState::self()->setTheContextObject(manager);
Steven Moreland1ac84c42019-07-10 17:51:27 -070050 ps->becomeContextManager(nullptr, nullptr);
Steven Moreland80e1e6d2019-06-21 12:35:59 -070051
52 IPCThreadState::self()->joinThreadPool();
53
54 // should not be reached
55 return EXIT_FAILURE;
56}