Yifan Hong | 4db762a | 2018-07-10 15:49:21 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 20 | using android::hardware::health::V2_0::IHealth; |
| 21 | using android::hardware::health::V2_0::implementation::Health; |
| 22 | |
| 23 | static struct healthd_config gHealthdConfig = { |
Yifan Hong | 4db762a | 2018-07-10 15:49:21 -0700 | [diff] [blame] | 24 | .energyCounter = nullptr, |
| 25 | .boot_min_cap = 0, |
| 26 | .screen_on = nullptr}; |
| 27 | |
| 28 | void healthd_board_init(struct healthd_config*) { |
| 29 | // use defaults |
| 30 | } |
| 31 | |
| 32 | int 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 Valsaraju | bf0b9fa | 2018-09-28 10:44:02 -0700 | [diff] [blame] | 37 | void healthd_mode_default_impl_init(struct healthd_config*) { |
| 38 | // noop |
| 39 | } |
| 40 | |
| 41 | int healthd_mode_default_impl_preparetowait(void) { |
| 42 | return -1; |
| 43 | } |
| 44 | |
| 45 | void healthd_mode_default_impl_heartbeat(void) { |
| 46 | // noop |
| 47 | } |
| 48 | |
| 49 | void healthd_mode_default_impl_battery_update(struct android::BatteryProperties*) { |
| 50 | // noop |
| 51 | } |
| 52 | |
| 53 | static 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 Hong | 4db762a | 2018-07-10 15:49:21 -0700 | [diff] [blame] | 60 | extern "C" IHealth* HIDL_FETCH_IHealth(const char* name) { |
| 61 | const static std::string providedInstance{"backup"}; |
Hridya Valsaraju | bf0b9fa | 2018-09-28 10:44:02 -0700 | [diff] [blame] | 62 | healthd_mode_ops = &healthd_mode_default_impl_ops; |
Yifan Hong | 4db762a | 2018-07-10 15:49:21 -0700 | [diff] [blame] | 63 | if (providedInstance == name) { |
| 64 | // use defaults |
| 65 | // Health class stores static instance |
| 66 | return Health::initInstance(&gHealthdConfig).get(); |
| 67 | } |
| 68 | return nullptr; |
| 69 | } |