• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef DEVICE_GOOGLE_CROSSHATCH_HEALTH_BATTERYRECHARGINGCONTROL_H
18 #define DEVICE_GOOGLE_CROSSHATCH_HEALTH_BATTERYRECHARGINGCONTROL_H
19 
20 #include <android-base/file.h>
21 #include <android-base/logging.h>
22 #include <android-base/strings.h>
23 #include <batteryservice/BatteryService.h>
24 #include <math.h>
25 #include <time.h>
26 #include <utils/Timers.h>
27 #include <string>
28 
29 namespace device {
30 namespace google {
31 namespace crosshatch {
32 namespace health {
33 
34 extern const std::string kChargerStatus;
35 
36 enum RechargeState {
37     WAIT_EOC,          // Wait for the charge done
38     RECHARGING_CYCLE,  // During the recharging cycle state
39     OVER_LOADING,      // When system power draw is higher than what charges the battery
40     NO_POWER_SOURCE,   // No power source detected
41     INACTIVE           // Not active the recharging state checking
42 };
43 
44 struct sysfsStringEnumMap {
45     const char *s;
46     int val;
47 };
48 
49 /**
50  * updateBatteryProperties is called with the active Fuel Gauge properties values.
51  * In bluecross case, the Maxim FG. The charger SOC level should not be considered
52  * and cannot be used to make any assumption on the SOC we should reporting to the
53  * user.
54  *
55  * Once 100% is reached, the class will track the charger status to detect
56  * when reaching charge termination (EOC), then will report 100% as long as
57  * in Full or Charging states.
58  * The power source might be disconnected at any FG level, recharge_soc_ is used
59  * to keep track of that level to be reached within defined transition time.
60  */
61 class BatteryRechargingControl {
62   public:
63     BatteryRechargingControl();
64     void updateBatteryProperties(struct android::BatteryProperties *props);
65 
66   private:
67     enum RechargeState state_;
68     int64_t start_time_;
69     /* Keeps track of the target level to detect OVER_LOADING or 0 when no target is set */
70     int recharge_soc_;
71 
72     int mapSysfsString(const char *str, struct sysfsStringEnumMap map[]);
73     int getBatteryStatus(const char *status);
74     int RemapSOC(int);
75     int64_t getTime();
76 };
77 
78 }  // namespace health
79 }  // namespace crosshatch
80 }  // namespace google
81 }  // namespace device
82 
83 #endif
84