blob: 08fee9ea71744b012b6e9735a8f8ee952d1de66c [file] [log] [blame]
Yifan Hong4db762a2018-07-10 15:49:21 -07001/*
2 * Copyright (C) 2018 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 <health2/Health.h>
18#include <healthd/healthd.h>
19
20using android::hardware::health::V2_0::IHealth;
21using android::hardware::health::V2_0::implementation::Health;
22
23static struct healthd_config gHealthdConfig = {
Yifan Hong4db762a2018-07-10 15:49:21 -070024 .energyCounter = nullptr,
25 .boot_min_cap = 0,
26 .screen_on = nullptr};
27
28void healthd_board_init(struct healthd_config*) {
29 // use defaults
30}
31
32int healthd_board_battery_update(struct android::BatteryProperties*) {
33 // return 0 to log periodic polled battery status to kernel log
34 return 0;
35}
36
Hridya Valsarajubf0b9fa2018-09-28 10:44:02 -070037void healthd_mode_default_impl_init(struct healthd_config*) {
38 // noop
39}
40
41int healthd_mode_default_impl_preparetowait(void) {
42 return -1;
43}
44
45void healthd_mode_default_impl_heartbeat(void) {
46 // noop
47}
48
49void healthd_mode_default_impl_battery_update(struct android::BatteryProperties*) {
50 // noop
51}
52
53static struct healthd_mode_ops healthd_mode_default_impl_ops = {
54 .init = healthd_mode_default_impl_init,
55 .preparetowait = healthd_mode_default_impl_preparetowait,
56 .heartbeat = healthd_mode_default_impl_heartbeat,
57 .battery_update = healthd_mode_default_impl_battery_update,
58};
59
Yifan Hong4db762a2018-07-10 15:49:21 -070060extern "C" IHealth* HIDL_FETCH_IHealth(const char* name) {
61 const static std::string providedInstance{"backup"};
Hridya Valsarajubf0b9fa2018-09-28 10:44:02 -070062 healthd_mode_ops = &healthd_mode_default_impl_ops;
Yifan Hong4db762a2018-07-10 15:49:21 -070063 if (providedInstance == name) {
64 // use defaults
65 // Health class stores static instance
66 return Health::initInstance(&gHealthdConfig).get();
67 }
68 return nullptr;
69}