Register VHAL to car watchdog
- For health checking, the car watchdog client attemps to get
PERF_VEHICLE_SPEED.
- If successful, it regards VHAL is healhty and responds to the car
watchdog daemon. Otherwise, VHAL will be killed by the daemon.
Bug: 154367059
Bug: 154262220
Test: dumpsys android.automotive.watchdog.ICarWatchdog/default and check
if vehicle hal is registered as a client
Change-Id: I2eb466550c56f25ba550ebbd35dc8fde9681ea59
diff --git a/automotive/vehicle/2.0/default/VehicleService.cpp b/automotive/vehicle/2.0/default/VehicleService.cpp
index 127eb98..32e5e70 100644
--- a/automotive/vehicle/2.0/default/VehicleService.cpp
+++ b/automotive/vehicle/2.0/default/VehicleService.cpp
@@ -20,9 +20,12 @@
#include <iostream>
+#include <android/binder_process.h>
+#include <utils/Looper.h>
#include <vhal_v2_0/EmulatedVehicleConnector.h>
#include <vhal_v2_0/EmulatedVehicleHal.h>
#include <vhal_v2_0/VehicleHalManager.h>
+#include <vhal_v2_0/WatchdogClient.h>
using namespace android;
using namespace android::hardware;
@@ -36,7 +39,7 @@
auto service = std::make_unique<VehicleHalManager>(hal.get());
connector->setValuePool(hal->getValuePool());
- configureRpcThreadpool(4, true /* callerWillJoin */);
+ configureRpcThreadpool(4, false /* callerWillJoin */);
ALOGI("Registering as service...");
status_t status = service->registerAsService();
@@ -46,8 +49,22 @@
return 1;
}
+ // Setup a binder thread pool to be a car watchdog client.
+ ABinderProcess_setThreadPoolMaxThreadCount(1);
+ ABinderProcess_startThreadPool();
+ sp<Looper> looper(Looper::prepare(0 /* opts */));
+ std::shared_ptr<WatchdogClient> watchdogClient =
+ ndk::SharedRefBase::make<WatchdogClient>(looper, service.get());
+ // The current health check is done in the main thread, so it falls short of capturing the real
+ // situation. Checking through HAL binder thread should be considered.
+ if (!watchdogClient->initialize()) {
+ ALOGE("Failed to initialize car watchdog client");
+ return 1;
+ }
ALOGI("Ready");
- joinRpcThreadpool();
+ while (true) {
+ looper->pollAll(-1 /* timeoutMillis */);
+ }
return 1;
}