• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2020 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 HARDWARE_GOOGLE_PIXEL_PIXELSTATS_BATTERYCAPACITYREPORTER_H
18 #define HARDWARE_GOOGLE_PIXEL_PIXELSTATS_BATTERYCAPACITYREPORTER_H
19 
20 namespace android {
21 namespace hardware {
22 namespace google {
23 namespace pixel {
24 
25 #define MAX_LOG_EVENTS_PER_HOUR 4
26 
27 /**
28  * A class to upload battery capacity metrics
29  */
30 class BatteryCapacityReporter {
31   public:
32     BatteryCapacityReporter();
33     void checkAndReport(const std::string &path);
34 
35   private:
36     int64_t getTimeSecs();
37 
38     bool parse(const std::string &path);
39     bool checkLogEvent(void);
40     bool shouldReportEvent(void);
41     void reportEvent(void);
42 
43     /**
44      * SOC status translation from sysfs node
45      */
46     enum SOCStatus {
47         SOC_STATUS_UNKNOWN = 0,
48         SOC_STATUS_CONNECTED = 1,
49         SOC_STATUS_DISCONNECTED = 2,
50         SOC_STATUS_FULL = 3,
51     };
52 
53     enum LogReason {
54         LOG_REASON_UNKNOWN = 0,
55         LOG_REASON_CONNECTED = 1,
56         LOG_REASON_DISCONNECTED = 2,
57         LOG_REASON_FULL_CHARGE = 3,
58         LOG_REASON_PERCENT_SKIP = 4,
59         LOG_REASON_DIVERGING_FG = 5,
60     };
61 
62     SOCStatus status_ = SOC_STATUS_UNKNOWN;
63     SOCStatus status_previous_ = SOC_STATUS_UNKNOWN;
64     float gdf_ = 0.0;
65     float ssoc_ = 0.0f;
66     float gdf_curve_ = 0.0f;
67     float ssoc_curve_ = 0.0f;
68     float ssoc_previous_ = -1.0f;
69     float ssoc_gdf_diff_previous_ = 0.0f;
70     LogReason log_reason_ = LOG_REASON_UNKNOWN;
71 
72     int num_events_in_last_hour_ = 0;
73     int64_t log_event_time_secs_[MAX_LOG_EVENTS_PER_HOUR] = {0};
74 
75     // Proto messages are 1-indexed and VendorAtom field numbers start at 2, so
76     // store everything in the values array at the index of the field number
77     // -2.
78     const int kVendorAtomOffset = 2;
79 };
80 
81 }  // namespace pixel
82 }  // namespace google
83 }  // namespace hardware
84 }  // namespace android
85 
86 #endif  // HARDWARE_GOOGLE_PIXEL_PIXELSTATS_BATTERYCAPACITYREPORTER_H
87