health 2.0: Check health_loop status for passthrough usage

health HAL is used as passthrough in recovery mode and hence
healthd_main() is not invoked. Add checks in
healthd_battery_update_internal() and healthd_register_event()
to return when health_loop is NULL.

Test: fastboot getvar battery-voltage works in fastbootd.
Bug: 144299329

Change-Id: I0a975a4bfe942813f9c5b3936df91cc3d8fa9674
This commit is contained in:
Hridya Valsaraju 2019-11-22 15:06:08 -08:00 committed by Yifan Hong
parent 3d3c792bb8
commit 55f1a1f3f6

View file

@ -49,11 +49,14 @@ class HealthLoopAdapter : public HealthLoop {
static std::unique_ptr<HealthLoopAdapter> health_loop; static std::unique_ptr<HealthLoopAdapter> health_loop;
int healthd_register_event(int fd, void (*handler)(uint32_t), EventWakeup wakeup) { int healthd_register_event(int fd, void (*handler)(uint32_t), EventWakeup wakeup) {
if (!health_loop) return -1;
auto wrapped_handler = [handler](auto*, uint32_t epevents) { handler(epevents); }; auto wrapped_handler = [handler](auto*, uint32_t epevents) { handler(epevents); };
return health_loop->RegisterEvent(fd, wrapped_handler, wakeup); return health_loop->RegisterEvent(fd, wrapped_handler, wakeup);
} }
void healthd_battery_update_internal(bool charger_online) { void healthd_battery_update_internal(bool charger_online) {
if (!health_loop) return;
health_loop->AdjustWakealarmPeriods(charger_online); health_loop->AdjustWakealarmPeriods(charger_online);
} }