• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 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 
17 #include <android-base/logging.h>
18 #include <android/binder_manager.h>
19 #include <android/binder_process.h>
20 
21 #include "DumpstateDevice.h"
22 #include "WatchdogClient.h"
23 
24 #include <vsockinfo.h>
25 
26 using ::aidl::android::hardware::dumpstate::implementation::DumpstateDevice;
27 using ::aidl::android::hardware::dumpstate::implementation::WatchdogClient;
28 using ::android::OK;
29 using ::android::sp;
30 using ::android::hardware::automotive::utils::VsockConnectionInfo;
31 
main()32 int main() {
33     const auto si = VsockConnectionInfo::fromRoPropertyStore(
34             {
35                     "ro.boot.vendor.dumpstate.server.cid",
36                     "ro.vendor.dumpstate.server.cid",
37             },
38             {
39                     "ro.boot.vendor.dumpstate.server.port",
40                     "ro.vendor.dumpstate.server.port",
41             });
42 
43     if (!si) {
44         ALOGE("failed to get server connection cid/port; configure and try again.");
45         return 1;
46     } else {
47         ALOGI("Connecting to vsock server at %s", si->str().c_str());
48     }
49 
50     ABinderProcess_setThreadPoolMaxThreadCount(0);
51 
52     // Create an instance of our service class
53     std::shared_ptr<DumpstateDevice> dumpstateImpl =
54             ndk::SharedRefBase::make<DumpstateDevice>(si->str());
55 
56     const std::string instance = std::string() + DumpstateDevice::descriptor + "/default";
57     binder_status_t status =
58             AServiceManager_addService(dumpstateImpl->asBinder().get(), instance.c_str());
59     CHECK(status == STATUS_OK);
60 
61     ABinderProcess_joinThreadPool();
62     return EXIT_FAILURE;  // should not reach
63 }
64