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