1 /* 2 * Copyright (C) 2021 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 <health2impl/HalHealthLoop.h> 20 21 #include <charger/healthd_mode_charger.h> 22 23 namespace android { 24 25 // An implementation of Charger backed by HIDL implementation. Uses HIDL health 26 // HAL's HalHealthLoop. 27 class ChargerHidl : public ::android::ChargerConfigurationInterface, 28 public ::android::hardware::health::V2_1::implementation::HalHealthLoop { 29 using HalHealthLoop = ::android::hardware::health::V2_1::implementation::HalHealthLoop; 30 using HealthInfo_2_1 = android::hardware::health::V2_1::HealthInfo; 31 32 public: 33 explicit ChargerHidl(const sp<android::hardware::health::V2_1::IHealth>& service); 34 std::optional<bool> ChargerShouldKeepScreenOn() override; ChargerIsOnline()35 bool ChargerIsOnline() override { return HalHealthLoop::charger_online(); } ChargerInitConfig(healthd_config * config)36 void ChargerInitConfig(healthd_config* config) override { return HalHealthLoop::Init(config); } ChargerRegisterEvent(int fd,BoundFunction func,EventWakeup wakeup)37 int ChargerRegisterEvent(int fd, BoundFunction func, EventWakeup wakeup) override { 38 return HalHealthLoop::RegisterEvent(fd, func, wakeup); 39 } 40 bool ChargerEnableSuspend() override; 41 // HealthLoop overrides Heartbeat()42 void Heartbeat() override { charger_->OnHeartbeat(); } PrepareToWait()43 int PrepareToWait() override { return charger_->OnPrepareToWait(); } Init(struct healthd_config * config)44 void Init(struct healthd_config* config) override { charger_->OnInit(config); } 45 // HalHealthLoop overrides 46 void OnHealthInfoChanged(const HealthInfo_2_1& health_info) override; 47 48 private: 49 sp<android::hardware::health::V2_1::IHealth> service_; 50 std::unique_ptr<Charger> charger_; 51 }; 52 53 } // namespace android 54 55 int healthd_charger_main(int argc, char** argv); 56