blob: 3901a763c3d96be56d1f8e6be0a2b62cfcfa481b [file] [log] [blame]
Yifan Honge4382112019-10-02 19:09:37 -07001/*
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#include <health2impl/HalHealthLoop.h>
18
19#include <android-base/logging.h>
20#include <hal_conversion.h>
21#include <hidl/HidlTransportSupport.h>
22#include <hwbinder/IPCThreadState.h>
23
24#include <health2impl/Health.h>
25
26using android::hardware::configureRpcThreadpool;
27using android::hardware::handleTransportPoll;
28using android::hardware::IPCThreadState;
29using android::hardware::setupTransportPolling;
30
31using android::hardware::health::V1_0::hal_conversion::convertFromHealthConfig;
32using android::hardware::health::V2_0::Result;
33
34namespace android {
35namespace hardware {
36namespace health {
37namespace V2_1 {
38namespace implementation {
39
40void HalHealthLoop::Init(struct healthd_config* config) {
41 // Retrieve healthd_config from the HAL.
42 service_->getHealthConfig([config](auto res, const auto& health_config) {
43 CHECK(res == Result::SUCCESS);
44
45 convertFromHealthConfig(health_config.battery, config);
46 config->boot_min_cap = health_config.bootMinCap;
47
48 // Leave screen_on empty because it is handled in GetScreenOn below.
49
50 // Leave ignorePowerSupplyNames empty because it isn't
51 // used by clients of health HAL.
52 });
53}
54
55void HalHealthLoop::Heartbeat(void) {
56 // noop
57}
58
59void HalHealthLoop::ScheduleBatteryUpdate() {
60 // ignore errors. impl may not be able to handle any callbacks, so
61 // update() may return errors.
62 Result res = service_->update();
63 if (res != Result::SUCCESS) {
64 LOG(WARNING) << "update() on the health HAL implementation failed with " << toString(res);
65 }
66
67 service_->getHealthInfo_2_1([this](auto res, const auto& health_info) {
68 CHECK(res == Result::SUCCESS)
69 << "getHealthInfo_2_1() on the health HAL implementation failed with "
70 << toString(res);
71 this->OnHealthInfoChanged(health_info);
72 });
73}
74
75int HalHealthLoop::PrepareToWait() {
76 return -1;
77}
78
79void HalHealthLoop::OnHealthInfoChanged(const HealthInfo& health_info) {
80 set_charger_online(health_info);
81 AdjustWakealarmPeriods(charger_online());
82}
83
84void HalHealthLoop::set_charger_online(const HealthInfo& health_info) {
85 const auto& props = health_info.legacy.legacy;
86 charger_online_ =
87 props.chargerAcOnline || props.chargerUsbOnline || props.chargerWirelessOnline;
88}
89
90} // namespace implementation
91} // namespace V2_1
92} // namespace health
93} // namespace hardware
94} // namespace android