1 /**
2  * Copyright (c) 2022, 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 "CarDisplayProxy.h"
18 
19 #include <android-base/logging.h>
20 #include <android/binder_manager.h>
21 #include <android/binder_process.h>
22 
23 #include <string_view>
24 
25 namespace {
26 
27 using ::aidl::android::frameworks::automotive::display::implementation::CarDisplayProxy;
28 
29 constexpr size_t kMaxBinderThreadCount = 1;
30 constexpr std::string_view kServiceName = "/default";
31 
32 }  // namespace
33 
main(int argc,char ** argv)34 int main([[maybe_unused]] int argc, [[maybe_unused]] char** argv) {
35     LOG(INFO) << "cardisplayproxy service is starting";
36     std::shared_ptr<CarDisplayProxy> service = ::ndk::SharedRefBase::make<CarDisplayProxy>();
37 
38     // Registers our service
39     const auto instanceName = std::string(CarDisplayProxy::descriptor) + std::string(kServiceName);
40     binder_exception_t status =
41             AServiceManager_addService(service->asBinder().get(), instanceName.data());
42     if (status != EX_NONE) {
43         LOG(FATAL) << "Error while registering cardisplayproxy service: "
44                    << ::android::statusToString(status).data();
45     }
46 
47     // Prepares the RPC serving thread pool
48     if (!ABinderProcess_setThreadPoolMaxThreadCount(kMaxBinderThreadCount)) {
49         LOG(ERROR) << "Filed to set the binder thread pool";
50         return EXIT_FAILURE;
51     }
52     ABinderProcess_startThreadPool();
53     LOG(INFO) << "Main thread entering thread pool";
54 
55     // In normal operation, we do not expect the thread pool to exit.
56     ABinderProcess_joinThreadPool();
57     LOG(ERROR) << "cardisplayproxyd is shutting down.";
58 
59     return EXIT_SUCCESS;
60 }
61