1 /*
2 * Copyright (C) 2016 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 "include/hal_conversion.h"
18
19 namespace android {
20 namespace hardware {
21 namespace health {
22 namespace V1_0 {
23 namespace hal_conversion {
24
convertToHealthConfig(const struct healthd_config * hc,HealthConfig & config)25 void convertToHealthConfig(const struct healthd_config *hc, HealthConfig& config) {
26 config.periodicChoresIntervalFast = hc->periodic_chores_interval_fast;
27 config.periodicChoresIntervalSlow = hc->periodic_chores_interval_slow;
28
29 config.batteryStatusPath = hc->batteryStatusPath.string();
30 config.batteryHealthPath = hc->batteryHealthPath.string();
31 config.batteryPresentPath = hc->batteryPresentPath.string();
32 config.batteryCapacityPath = hc->batteryCapacityPath.string();
33 config.batteryVoltagePath = hc->batteryVoltagePath.string();
34 config.batteryTemperaturePath = hc->batteryTemperaturePath.string();
35 config.batteryTechnologyPath = hc->batteryTechnologyPath.string();
36 config.batteryCurrentNowPath = hc->batteryCurrentNowPath.string();
37 config.batteryCurrentAvgPath = hc->batteryCurrentAvgPath.string();
38 config.batteryChargeCounterPath = hc->batteryChargeCounterPath.string();
39 config.batteryFullChargePath = hc->batteryFullChargePath.string();
40 config.batteryCycleCountPath = hc->batteryCycleCountPath.string();
41
42 }
43
convertFromHealthConfig(const HealthConfig & c,struct healthd_config * hc)44 void convertFromHealthConfig(const HealthConfig& c, struct healthd_config *hc) {
45 hc->periodic_chores_interval_fast = c.periodicChoresIntervalFast;
46 hc->periodic_chores_interval_slow = c.periodicChoresIntervalSlow;
47
48 hc->batteryStatusPath =
49 android::String8(c.batteryStatusPath.c_str(),
50 c.batteryStatusPath.size());
51
52 hc->batteryHealthPath =
53 android::String8(c.batteryHealthPath.c_str(),
54 c.batteryHealthPath.size());
55
56 hc->batteryPresentPath =
57 android::String8(c.batteryPresentPath.c_str(),
58 c.batteryPresentPath.size());
59
60 hc->batteryCapacityPath =
61 android::String8(c.batteryCapacityPath.c_str(),
62 c.batteryCapacityPath.size());
63
64 hc->batteryVoltagePath =
65 android::String8(c.batteryVoltagePath.c_str(),
66 c.batteryVoltagePath.size());
67
68 hc->batteryTemperaturePath =
69 android::String8(c.batteryTemperaturePath.c_str(),
70 c.batteryTemperaturePath.size());
71
72 hc->batteryTechnologyPath =
73 android::String8(c.batteryTechnologyPath.c_str(),
74 c.batteryTechnologyPath.size());
75
76 hc->batteryCurrentNowPath =
77 android::String8(c.batteryCurrentNowPath.c_str(),
78 c.batteryCurrentNowPath.size());
79
80 hc->batteryCurrentAvgPath =
81 android::String8(c.batteryCurrentAvgPath.c_str(),
82 c.batteryCurrentNowPath.size());
83
84 hc->batteryChargeCounterPath =
85 android::String8(c.batteryChargeCounterPath.c_str(),
86 c.batteryChargeCounterPath.size());
87
88 hc->batteryFullChargePath =
89 android::String8(c.batteryFullChargePath.c_str(),
90 c.batteryFullChargePath.size());
91
92 hc->batteryCycleCountPath =
93 android::String8(c.batteryCycleCountPath.c_str(),
94 c.batteryCycleCountPath.size());
95
96 // energyCounter is handled through special means so all calls to
97 // the function go across the HALs
98
99 // boot_min_cap - never used in Android (only in charger-mode).
100
101 // screen_on - never used in Android (only in charger mode).
102 }
103
convertToHealthInfo(const struct android::BatteryProperties * p,HealthInfo & info)104 void convertToHealthInfo(const struct android::BatteryProperties *p,
105 HealthInfo& info) {
106 info.chargerAcOnline = p->chargerAcOnline;
107 info.chargerUsbOnline = p->chargerUsbOnline;
108 info.chargerWirelessOnline = p->chargerWirelessOnline;
109 info.maxChargingCurrent = p->maxChargingCurrent;
110 info.maxChargingVoltage = p->maxChargingVoltage;
111 info.batteryStatus = static_cast<BatteryStatus>(p->batteryStatus);
112 info.batteryHealth = static_cast<BatteryHealth>(p->batteryHealth);
113 info.batteryPresent = p->batteryPresent;
114 info.batteryLevel = p->batteryLevel;
115 info.batteryVoltage = p->batteryVoltage;
116 info.batteryTemperature = p->batteryTemperature;
117 info.batteryCurrent = p->batteryCurrent;
118 info.batteryCycleCount = p->batteryCycleCount;
119 info.batteryFullCharge = p->batteryFullCharge;
120 info.batteryChargeCounter = p->batteryChargeCounter;
121 info.batteryTechnology = p->batteryTechnology;
122 }
123
convertFromHealthInfo(const HealthInfo & info,struct android::BatteryProperties * p)124 void convertFromHealthInfo(const HealthInfo& info,
125 struct android::BatteryProperties *p) {
126 p->chargerAcOnline = info.chargerAcOnline;
127 p->chargerUsbOnline = info.chargerUsbOnline;
128 p->chargerWirelessOnline = info.chargerWirelessOnline;
129 p->maxChargingCurrent = info.maxChargingCurrent;
130 p->maxChargingVoltage = info.maxChargingVoltage;
131 p->batteryStatus = static_cast<int>(info.batteryStatus);
132 p->batteryHealth = static_cast<int>(info.batteryHealth);
133 p->batteryPresent = info.batteryPresent;
134 p->batteryLevel = info.batteryLevel;
135 p->batteryVoltage = info.batteryVoltage;
136 p->batteryTemperature = info.batteryTemperature;
137 p->batteryCurrent = info.batteryCurrent;
138 p->batteryCycleCount = info.batteryCycleCount;
139 p->batteryFullCharge = info.batteryFullCharge;
140 p->batteryChargeCounter = info.batteryChargeCounter;
141 p->batteryTechnology = android::String8(info.batteryTechnology.c_str());
142 }
143
144 } // namespace hal_conversion
145 } // namespace V1_0
146 } // namespace health
147 } // namespace hardware
148 } // namespace android
149