1 /*
2  * Copyright (C) 2024 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 "PackageManagerProxy.h"
18 
19 #include <binder/ProcessState.h>
20 #include <log/log.h>
21 #include <utils/Looper.h>
22 #include <utils/StrongPointer.h>
23 
24 namespace {
25 
26 using ::android::Looper;
27 using ::android::ProcessState;
28 using ::android::sp;
29 using ::google::sdv::packagemanagerproxy::PackageManagerProxy;
30 
31 // Setting the maximum number of Binder threads to 2 was an arbitrary choice,
32 // it can be modified if needed.
33 constexpr size_t kMaxBinderThreadCount = 2;
34 
35 }  // namespace
36 
main(int,char **)37 int main(int /*argc*/, char** /*argv*/) {
38     // Set up the binder
39     sp<ProcessState> ps(ProcessState::self());
40     ps->setThreadPoolMaxThreadCount(kMaxBinderThreadCount);
41     ps->startThreadPool();
42     ps->giveThreadPoolName();
43 
44     sp<Looper> looper(Looper::prepare(/*opts=*/0));
45 
46     // Start the PackageManagerProxy service
47     PackageManagerProxy service;
48     auto result = service.init();
49     if (!result.ok()) {
50         ALOGE("Failed to start service: %s", result.error().message().c_str());
51         exit(result.error().code());
52     }
53 
54     ALOGI("packagemanagerproxyd server started.");
55 
56     while (true) {
57         looper->pollAll(/*timeoutMillis=*/-1);
58     }
59 
60     return 0;
61 }
62