• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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     struct BatteryFGPipeline {
44       int32_t event;
45       int32_t state;
46       int32_t duration;
47       int32_t addr01;
48       int32_t data01;
49       int32_t addr02;
50       int32_t data02;
51       int32_t addr03;
52       int32_t data03;
53       int32_t addr04;
54       int32_t data04;
55       int32_t addr05;
56       int32_t data05;
57       int32_t addr06;
58       int32_t data06;
59       int32_t addr07;
60       int32_t data07;
61       int32_t addr08;
62       int32_t data08;
63       int32_t addr09;
64       int32_t data09;
65       int32_t addr10;
66       int32_t data10;
67       int32_t addr11;
68       int32_t data11;
69       int32_t addr12;
70       int32_t data12;
71       int32_t addr13;
72       int32_t data13;
73       int32_t addr14;
74       int32_t data14;
75       int32_t addr15;
76       int32_t data15;
77       int32_t addr16;
78       int32_t data16;
79     };
80 
81     int64_t getTimeSecs();
82 
83     unsigned int last_ab_check_ = 0;
84     static constexpr unsigned int kNumMaxEvents = 8;
85     unsigned int ab_trigger_time_[kNumMaxEvents] = {0};
86     void reportFGEvent(const std::shared_ptr<IStats> &stats_client, struct BatteryFGPipeline &data);
87 
88     const int kNumFGPipelineFields = sizeof(BatteryFGPipeline) / sizeof(int32_t);
89 };
90 
91 }  // namespace pixel
92 }  // namespace google
93 }  // namespace hardware
94 }  // namespace android
95 
96  #endif  // HARDWARE_GOOGLE_PIXEL_PIXELSTATS_BATTERYFGREPORTER_H
97