1 /*
2  * Copyright (C) 2021 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_CHARGESTATSREPORTER_H
18 #define HARDWARE_GOOGLE_PIXEL_PIXELSTATS_CHARGESTATSREPORTER_H
19 
20 #include <aidl/android/frameworks/stats/IStats.h>
21 #include <pixelstats/PcaChargeStats.h>
22 #include <pixelstats/WirelessChargeStats.h>
23 
24 namespace android {
25 namespace hardware {
26 namespace google {
27 namespace pixel {
28 
29 using aidl::android::frameworks::stats::IStats;
30 
31 /**
32  * A class to upload battery capacity metrics
33  */
34 class ChargeStatsReporter {
35   public:
36     ChargeStatsReporter();
37     void checkAndReport(const std::shared_ptr<IStats> &stats_client, const std::string &path);
38 
39   private:
40     bool checkContentsAndAck(std::string *file_contents, const std::string &path);
41     void ReportVoltageTierStats(const std::shared_ptr<IStats> &stats_client, const char *line,
42                                 const bool has_wireless, const std::string &wfile_contents);
43     void ReportChargeStats(const std::shared_ptr<IStats> &stats_client, const std::string line,
44                            const std::string wline_at, const std::string wline_ac,
45                            const std::string pca_line);
46     bool shouldReportEvent(void);
47     int64_t getTimeSecs(void);
48 
49     WirelessChargeStats wireless_charge_stats_;
50     PcaChargeStats pca_charge_stats_;
51 
52     int log_event_time_secs_ = 0;
53 
54     // Proto messages are 1-indexed and VendorAtom field numbers start at 2, so
55     // store everything in the values array at the index of the field number
56     // -2.
57     const int kVendorAtomOffset = 2;
58 
59     const std::string kThermalChargeMetricsPath =
60             "/sys/devices/platform/google,charger/thermal_stats";
61 
62     const std::string kGChargerMetricsPath = "/sys/devices/platform/google,charger/charge_stats";
63 
64     const std::string kGDualBattMetricsPath = "/sys/class/power_supply/dualbatt/dbatt_stats";
65 };
66 
67 }  // namespace pixel
68 }  // namespace google
69 }  // namespace hardware
70 }  // namespace android
71 
72 #endif  // HARDWARE_GOOGLE_PIXEL_PIXELSTATS_CHARGESTATSREPORTER_H
73