1 /* 2 * Copyright (C) 2019 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 #pragma once 18 19 #include <optional> 20 21 #include <android/hardware/health/2.1/IHealth.h> 22 #include <health/HealthLoop.h> 23 24 namespace android { 25 namespace hardware { 26 namespace health { 27 namespace V2_1 { 28 namespace implementation { 29 30 // An implementation of HealthLoop for using a given health HAL. This is useful 31 // for services that opens the passthrough implementation and starts the HealthLoop 32 // to periodically poll data from the implementation. 33 class HalHealthLoop : public HealthLoop { 34 public: HalHealthLoop(const std::string & name,const sp<IHealth> & service)35 HalHealthLoop(const std::string& name, const sp<IHealth>& service) 36 : instance_name_(name), service_(service) {} 37 38 protected: 39 virtual void Init(struct healthd_config* config) override; 40 virtual void Heartbeat() override; 41 virtual int PrepareToWait() override; 42 virtual void ScheduleBatteryUpdate() override; 43 44 // HealthLoop periodically calls ScheduleBatteryUpdate, which calls 45 // OnHealthInfoChanged callback. A client can override this function to 46 // broadcast the health_info to interested listeners. By default, this 47 // adjust uevents / wakealarm periods. 48 virtual void OnHealthInfoChanged(const HealthInfo& health_info); 49 instance_name()50 const std::string& instance_name() const { return instance_name_; } service()51 const sp<IHealth>& service() const { return service_; } charger_online()52 bool charger_online() const { return charger_online_; } 53 54 // Helpers for subclasses to implement OnHealthInfoChanged. 55 void set_charger_online(const HealthInfo& health_info); 56 57 private: 58 std::string instance_name_; 59 sp<IHealth> service_; 60 bool charger_online_ = false; 61 }; 62 63 } // namespace implementation 64 } // namespace V2_1 65 } // namespace health 66 } // namespace hardware 67 } // namespace android 68