1*4d7e907cSAndroid Build Coastguard Worker /* 2*4d7e907cSAndroid Build Coastguard Worker * Copyright (C) 2021 The Android Open Source Project 3*4d7e907cSAndroid Build Coastguard Worker * 4*4d7e907cSAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License"); 5*4d7e907cSAndroid Build Coastguard Worker * you may not use this file except in compliance with the License. 6*4d7e907cSAndroid Build Coastguard Worker * You may obtain a copy of the License at 7*4d7e907cSAndroid Build Coastguard Worker * 8*4d7e907cSAndroid Build Coastguard Worker * http://www.apache.org/licenses/LICENSE-2.0 9*4d7e907cSAndroid Build Coastguard Worker * 10*4d7e907cSAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software 11*4d7e907cSAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS, 12*4d7e907cSAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13*4d7e907cSAndroid Build Coastguard Worker * See the License for the specific language governing permissions and 14*4d7e907cSAndroid Build Coastguard Worker * limitations under the License. 15*4d7e907cSAndroid Build Coastguard Worker */ 16*4d7e907cSAndroid Build Coastguard Worker 17*4d7e907cSAndroid Build Coastguard Worker #include <health-impl/HalHealthLoop.h> 18*4d7e907cSAndroid Build Coastguard Worker 19*4d7e907cSAndroid Build Coastguard Worker #include <android-base/logging.h> 20*4d7e907cSAndroid Build Coastguard Worker 21*4d7e907cSAndroid Build Coastguard Worker #include <health-impl/Health.h> 22*4d7e907cSAndroid Build Coastguard Worker #include "health-convert.h" 23*4d7e907cSAndroid Build Coastguard Worker 24*4d7e907cSAndroid Build Coastguard Worker namespace aidl::android::hardware::health { 25*4d7e907cSAndroid Build Coastguard Worker 26*4d7e907cSAndroid Build Coastguard Worker // Unlike the HIDL version android::hardware::health::V2_1::implementation::HalHealthLoop, 27*4d7e907cSAndroid Build Coastguard Worker // do not define HalHealthLoop::Init because we no longer have Health::getHealthConfig. 28*4d7e907cSAndroid Build Coastguard Worker // Let the Health class handle Init. Init(struct healthd_config * config)29*4d7e907cSAndroid Build Coastguard Workervoid HalHealthLoop::Init(struct healthd_config* config) { 30*4d7e907cSAndroid Build Coastguard Worker callback_->OnInit(this, config); 31*4d7e907cSAndroid Build Coastguard Worker } 32*4d7e907cSAndroid Build Coastguard Worker Heartbeat()33*4d7e907cSAndroid Build Coastguard Workervoid HalHealthLoop::Heartbeat() { 34*4d7e907cSAndroid Build Coastguard Worker callback_->OnHeartbeat(); 35*4d7e907cSAndroid Build Coastguard Worker } 36*4d7e907cSAndroid Build Coastguard Worker ScheduleBatteryUpdate()37*4d7e907cSAndroid Build Coastguard Workervoid HalHealthLoop::ScheduleBatteryUpdate() { 38*4d7e907cSAndroid Build Coastguard Worker // ignore errors. impl may not be able to handle any callbacks, so 39*4d7e907cSAndroid Build Coastguard Worker // update() may return errors. 40*4d7e907cSAndroid Build Coastguard Worker if (auto res = service_->update(); !res.isOk()) { 41*4d7e907cSAndroid Build Coastguard Worker LOG(WARNING) << "update() on the health HAL implementation failed with " 42*4d7e907cSAndroid Build Coastguard Worker << res.getDescription(); 43*4d7e907cSAndroid Build Coastguard Worker } 44*4d7e907cSAndroid Build Coastguard Worker 45*4d7e907cSAndroid Build Coastguard Worker HealthInfo health_info; 46*4d7e907cSAndroid Build Coastguard Worker auto res = service_->getHealthInfo(&health_info); 47*4d7e907cSAndroid Build Coastguard Worker CHECK(res.isOk()) << "getHealthInfo() on the health HAL implementation failed with " 48*4d7e907cSAndroid Build Coastguard Worker << res.getDescription(); 49*4d7e907cSAndroid Build Coastguard Worker OnHealthInfoChanged(health_info); 50*4d7e907cSAndroid Build Coastguard Worker } 51*4d7e907cSAndroid Build Coastguard Worker PrepareToWait()52*4d7e907cSAndroid Build Coastguard Workerint HalHealthLoop::PrepareToWait() { 53*4d7e907cSAndroid Build Coastguard Worker return callback_->OnPrepareToWait(); 54*4d7e907cSAndroid Build Coastguard Worker } 55*4d7e907cSAndroid Build Coastguard Worker OnHealthInfoChanged(const HealthInfo & health_info)56*4d7e907cSAndroid Build Coastguard Workervoid HalHealthLoop::OnHealthInfoChanged(const HealthInfo& health_info) { 57*4d7e907cSAndroid Build Coastguard Worker callback_->OnHealthInfoChanged(health_info); 58*4d7e907cSAndroid Build Coastguard Worker set_charger_online(health_info); 59*4d7e907cSAndroid Build Coastguard Worker AdjustWakealarmPeriods(charger_online()); 60*4d7e907cSAndroid Build Coastguard Worker } 61*4d7e907cSAndroid Build Coastguard Worker set_charger_online(const HealthInfo & health_info)62*4d7e907cSAndroid Build Coastguard Workervoid HalHealthLoop::set_charger_online(const HealthInfo& health_info) { 63*4d7e907cSAndroid Build Coastguard Worker charger_online_ = health_info.chargerAcOnline || health_info.chargerUsbOnline || 64*4d7e907cSAndroid Build Coastguard Worker health_info.chargerWirelessOnline || health_info.chargerDockOnline; 65*4d7e907cSAndroid Build Coastguard Worker } 66*4d7e907cSAndroid Build Coastguard Worker 67*4d7e907cSAndroid Build Coastguard Worker } // namespace aidl::android::hardware::health 68