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 #include <android/binder_process.h>
17
18 #include <cutils/properties.h>
19 #include <hidl/HidlSupport.h>
20 #include <hidl/HidlTransportSupport.h>
21
22 #include <utils/Errors.h>
23 #include <utils/Looper.h>
24 #include <utils/StrongPointer.h>
25
26 #include <sstream>
27
28 #include "DumpstateDevice.h"
29 #include "WatchdogClient.h"
30
31 #include <vsockinfo.h>
32
33 using android::Looper;
34 using ::android::OK;
35 using ::android::sp;
36 using ::android::hardware::configureRpcThreadpool;
37 using ::android::hardware::joinRpcThreadpool;
38 using ::android::hardware::automotive::utils::VsockConnectionInfo;
39 using ::android::hardware::dumpstate::V1_1::IDumpstateDevice;
40 using ::android::hardware::dumpstate::V1_1::implementation::makeVirtualizationDumpstateDevice;
41 using ::android::hardware::dumpstate::V1_1::implementation::WatchdogClient;
42
main()43 int main() {
44 const auto si = VsockConnectionInfo::fromRoPropertyStore(
45 {
46 "ro.boot.vendor.dumpstate.server.cid",
47 "ro.vendor.dumpstate.server.cid",
48 },
49 {
50 "ro.boot.vendor.dumpstate.server.port",
51 "ro.vendor.dumpstate.server.port",
52 });
53
54 if (!si) {
55 ALOGE("failed to get server connection cid/port; configure and try again.");
56 return 1;
57 } else {
58 ALOGI("Connecting to vsock server at %s", si->str().c_str());
59 }
60
61 auto dumpstate = makeVirtualizationDumpstateDevice(si->str());
62 // This method MUST be called before interacting with any HIDL interfaces.
63 configureRpcThreadpool(2, true);
64 if (dumpstate->registerAsService() != OK) {
65 ALOGE("Could not register service.");
66 return 1;
67 }
68
69 // Setup a binder thread pool to be a car watchdog client.
70 ABinderProcess_setThreadPoolMaxThreadCount(1);
71 ABinderProcess_startThreadPool();
72 android::sp<Looper> looper(Looper::prepare(0 /* opts */));
73 auto watchdogClient = ndk::SharedRefBase::make<WatchdogClient>(looper, dumpstate.get());
74 if (!watchdogClient->initialize()) {
75 ALOGE("Failed to initialize car watchdog client");
76 return 1;
77 }
78
79 while (true) {
80 looper->pollAll(-1 /* timeoutMillis */);
81 }
82 }
83