1 /* 2 * Copyright (C) 2024 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_BATTERYFGREPORTER_H 18 #define HARDWARE_GOOGLE_PIXEL_PIXELSTATS_BATTERYFGREPORTER_H 19 20 #include <cstdint> 21 #include <string> 22 23 #include <aidl/android/frameworks/stats/IStats.h> 24 25 namespace android { 26 namespace hardware { 27 namespace google { 28 namespace pixel { 29 30 using aidl::android::frameworks::stats::IStats; 31 using aidl::android::frameworks::stats::VendorAtomValue; 32 33 class BatteryFGReporter { 34 public: 35 BatteryFGReporter(); 36 37 void checkAndReportFwUpdate(const std::shared_ptr<IStats> &stats_client, const std::string &path); 38 void checkAndReportFGAbnormality(const std::shared_ptr<IStats> &stats_client, const std::vector<std::string> &paths); 39 40 private: 41 const int kVendorAtomOffset = 2; 42 43 enum FGEventType { 44 EvtFWUpdate = 0x4655, 45 }; 46 47 struct BatteryFGLearningParam { 48 enum FGEventType type; 49 uint16_t fcnom; 50 uint16_t dpacc; 51 uint16_t dqacc; 52 uint16_t fcrep; 53 uint16_t repsoc; 54 uint16_t msoc; 55 uint16_t vfsoc; 56 uint16_t fstat; 57 uint16_t rcomp0; 58 uint16_t tempco; 59 }; 60 61 struct BatteryFGAbnormalData { 62 uint16_t event; 63 uint16_t state; 64 uint16_t cycles; 65 uint16_t vcel; 66 uint16_t avgv; 67 uint16_t curr; 68 uint16_t avgc; 69 uint16_t timerh; 70 uint16_t temp; 71 uint16_t repcap; 72 uint16_t mixcap; 73 uint16_t fcrep; 74 uint16_t fcnom; 75 uint16_t qresd; 76 uint16_t avcap; 77 uint16_t vfremcap; 78 uint16_t repsoc; 79 uint16_t vfsoc; 80 uint16_t msoc; 81 uint16_t vfocv; 82 uint16_t dpacc; 83 uint16_t dqacc; 84 uint16_t qh; 85 uint16_t qh0; 86 uint16_t vfsoc0; 87 uint16_t qrtable20; 88 uint16_t qrtable30; 89 uint16_t status; 90 uint16_t fstat; 91 uint16_t rcomp0; 92 uint16_t tempco; 93 }; 94 95 int64_t getTimeSecs(); 96 97 unsigned int last_ab_check_ = 0; 98 unsigned int ab_trigger_time_[8] = {0}; 99 void setAtomFieldValue(std::vector<VendorAtomValue> *values, int offset, int content); 100 void reportAbnormalEvent(const std::shared_ptr<IStats> &stats_client, 101 struct BatteryFGAbnormalData data); 102 void reportEvent(const std::shared_ptr<IStats> &stats_client, 103 const struct BatteryFGLearningParam ¶ms); 104 105 const int kNumFwUpdateFields = 3; 106 const int kNumAbnormalEventFields = sizeof(BatteryFGAbnormalData) / sizeof(uint16_t); 107 }; 108 109 } // namespace pixel 110 } // namespace google 111 } // namespace hardware 112 } // namespace android 113 114 #endif // HARDWARE_GOOGLE_PIXEL_PIXELSTATS_BATTERYFGREPORTER_H 115