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 = { |
| 24 | .batteryStatusPath = android::String8(android::String8::kEmptyString), |
| 25 | .batteryHealthPath = android::String8(android::String8::kEmptyString), |
| 26 | .batteryPresentPath = android::String8(android::String8::kEmptyString), |
| 27 | .batteryCapacityPath = android::String8(android::String8::kEmptyString), |
| 28 | .batteryVoltagePath = android::String8(android::String8::kEmptyString), |
| 29 | .batteryTemperaturePath = android::String8(android::String8::kEmptyString), |
| 30 | .batteryTechnologyPath = android::String8(android::String8::kEmptyString), |
| 31 | .batteryCurrentNowPath = android::String8(android::String8::kEmptyString), |
| 32 | .batteryCurrentAvgPath = android::String8(android::String8::kEmptyString), |
| 33 | .batteryChargeCounterPath = android::String8(android::String8::kEmptyString), |
| 34 | .batteryFullChargePath = android::String8(android::String8::kEmptyString), |
| 35 | .batteryCycleCountPath = android::String8(android::String8::kEmptyString), |
| 36 | .energyCounter = nullptr, |
| 37 | .boot_min_cap = 0, |
| 38 | .screen_on = nullptr}; |
| 39 | |
| 40 | void healthd_board_init(struct healthd_config*) { |
| 41 | // use defaults |
| 42 | } |
| 43 | |
| 44 | int healthd_board_battery_update(struct android::BatteryProperties*) { |
| 45 | // return 0 to log periodic polled battery status to kernel log |
| 46 | return 0; |
| 47 | } |
| 48 | |
Hridya Valsaraju | bf0b9fa | 2018-09-28 10:44:02 -0700 | [diff] [blame^] | 49 | void healthd_mode_default_impl_init(struct healthd_config*) { |
| 50 | // noop |
| 51 | } |
| 52 | |
| 53 | int healthd_mode_default_impl_preparetowait(void) { |
| 54 | return -1; |
| 55 | } |
| 56 | |
| 57 | void healthd_mode_default_impl_heartbeat(void) { |
| 58 | // noop |
| 59 | } |
| 60 | |
| 61 | void healthd_mode_default_impl_battery_update(struct android::BatteryProperties*) { |
| 62 | // noop |
| 63 | } |
| 64 | |
| 65 | static struct healthd_mode_ops healthd_mode_default_impl_ops = { |
| 66 | .init = healthd_mode_default_impl_init, |
| 67 | .preparetowait = healthd_mode_default_impl_preparetowait, |
| 68 | .heartbeat = healthd_mode_default_impl_heartbeat, |
| 69 | .battery_update = healthd_mode_default_impl_battery_update, |
| 70 | }; |
| 71 | |
Yifan Hong | 4db762a | 2018-07-10 15:49:21 -0700 | [diff] [blame] | 72 | extern "C" IHealth* HIDL_FETCH_IHealth(const char* name) { |
| 73 | const static std::string providedInstance{"backup"}; |
Hridya Valsaraju | bf0b9fa | 2018-09-28 10:44:02 -0700 | [diff] [blame^] | 74 | healthd_mode_ops = &healthd_mode_default_impl_ops; |
Yifan Hong | 4db762a | 2018-07-10 15:49:21 -0700 | [diff] [blame] | 75 | if (providedInstance == name) { |
| 76 | // use defaults |
| 77 | // Health class stores static instance |
| 78 | return Health::initInstance(&gHealthdConfig).get(); |
| 79 | } |
| 80 | return nullptr; |
| 81 | } |