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