1 /* 2 * Copyright (C) 2018 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_HEALTH_LOWBATTERYSHUTDOWNMETRICS_H 18 #define HARDWARE_GOOGLE_PIXEL_HEALTH_LOWBATTERYSHUTDOWNMETRICS_H 19 20 #include <aidl/android/hardware/health/HealthInfo.h> 21 #include <android-base/file.h> 22 #include <android-base/logging.h> 23 #include <android-base/properties.h> 24 #include <android-base/strings.h> 25 #include <batteryservice/BatteryService.h> 26 #include <math.h> 27 #include <time.h> 28 #include <utils/Timers.h> 29 30 #include <string> 31 32 namespace hardware { 33 namespace google { 34 namespace pixel { 35 namespace health { 36 37 class LowBatteryShutdownMetrics { 38 public: 39 LowBatteryShutdownMetrics( 40 const char *const voltage_avg, 41 const char *const persist_prop = "persist.vendor.shutdown.voltage_avg"); 42 // Deprecated. Use logShutdownVoltage(const HealthInfo&) 43 void logShutdownVoltage(struct android::BatteryProperties *props); 44 void logShutdownVoltage(const aidl::android::hardware::health::HealthInfo &health_info); 45 46 private: 47 const char *const kVoltageAvg; 48 const char *const kPersistProp; 49 50 // Helps enforce that we only record kVoltageAvg once per boot cycle 51 bool prop_written_; 52 // Help us avoid polling kPersistProp if it's empty 53 bool prop_empty_; 54 55 bool saveVoltageAvg(); 56 void readStatus(); 57 bool uploadVoltageAvg(); 58 }; 59 60 } // namespace health 61 } // namespace pixel 62 } // namespace google 63 } // namespace hardware 64 65 #endif 66