diff options
Diffstat (limited to 'health/BatteryMetricsLogger.cpp')
-rw-r--r-- | health/BatteryMetricsLogger.cpp | 94 |
1 files changed, 27 insertions, 67 deletions
diff --git a/health/BatteryMetricsLogger.cpp b/health/BatteryMetricsLogger.cpp index 3a9beb5d..b5e89918 100644 --- a/health/BatteryMetricsLogger.cpp +++ b/health/BatteryMetricsLogger.cpp @@ -26,7 +26,6 @@ namespace health { using android::sp; using android::frameworks::stats::V1_0::BatteryHealthSnapshotArgs; using android::frameworks::stats::V1_0::IStats; -using ::hardware::google::pixelstats::V1_0::IPixelStats; BatteryMetricsLogger::BatteryMetricsLogger(const char *const batt_res, const char *const batt_ocv, int sample_period, int upload_period) @@ -48,53 +47,29 @@ int64_t BatteryMetricsLogger::getTime(void) { return nanoseconds_to_seconds(systemTime(SYSTEM_TIME_BOOTTIME)); } -bool BatteryMetricsLogger::uploadOutlierMetric(sp<IPixelStats> client, sp<IStats> stats_client, - sampleType type) { - IPixelStats::BatteryHealthSnapshotArgs min_ss = { - .type = static_cast<IPixelStats::BatterySnapshotType>(0), - .temperatureDeciC = min_[type][TEMP], - .voltageMicroV = min_[type][VOLT], - .currentMicroA = min_[type][CURR], - .openCircuitVoltageMicroV = min_[type][OCV], - .resistanceMicroOhm = min_[type][RES], - .levelPercent = min_[type][SOC]}; - IPixelStats::BatteryHealthSnapshotArgs max_ss = { - .type = static_cast<IPixelStats::BatterySnapshotType>(0), - .temperatureDeciC = max_[type][TEMP], - .voltageMicroV = max_[type][VOLT], - .currentMicroA = max_[type][CURR], - .openCircuitVoltageMicroV = max_[type][OCV], - .resistanceMicroOhm = max_[type][RES], - .levelPercent = max_[type][SOC]}; - +bool BatteryMetricsLogger::uploadOutlierMetric(sp<IStats> stats_client, sampleType type) { BatteryHealthSnapshotArgs min_stats_ss = { - .type = static_cast<BatteryHealthSnapshotArgs::BatterySnapshotType>(0), - .temperatureDeciC = min_[type][TEMP], - .voltageMicroV = min_[type][VOLT], - .currentMicroA = min_[type][CURR], - .openCircuitVoltageMicroV = min_[type][OCV], - .resistanceMicroOhm = min_[type][RES], - .levelPercent = min_[type][SOC]}; + .type = static_cast<BatteryHealthSnapshotArgs::BatterySnapshotType>(0), + .temperatureDeciC = min_[type][TEMP], + .voltageMicroV = min_[type][VOLT], + .currentMicroA = min_[type][CURR], + .openCircuitVoltageMicroV = min_[type][OCV], + .resistanceMicroOhm = min_[type][RES], + .levelPercent = min_[type][SOC]}; BatteryHealthSnapshotArgs max_stats_ss = { - .type = static_cast<BatteryHealthSnapshotArgs::BatterySnapshotType>(0), - .temperatureDeciC = max_[type][TEMP], - .voltageMicroV = max_[type][VOLT], - .currentMicroA = max_[type][CURR], - .openCircuitVoltageMicroV = max_[type][OCV], - .resistanceMicroOhm = max_[type][RES], - .levelPercent = max_[type][SOC]}; - if (kSnapshotType[type] < 0) + .type = static_cast<BatteryHealthSnapshotArgs::BatterySnapshotType>(0), + .temperatureDeciC = max_[type][TEMP], + .voltageMicroV = max_[type][VOLT], + .currentMicroA = max_[type][CURR], + .openCircuitVoltageMicroV = max_[type][OCV], + .resistanceMicroOhm = max_[type][RES], + .levelPercent = max_[type][SOC]}; + if (kStatsSnapshotType[type] < 0) return false; - min_ss.type = (IPixelStats::BatterySnapshotType)kSnapshotType[type]; - max_ss.type = (IPixelStats::BatterySnapshotType)(kSnapshotType[type] + 1); - min_stats_ss.type = (BatteryHealthSnapshotArgs::BatterySnapshotType)kStatsSnapshotType[type]; max_stats_ss.type = - (BatteryHealthSnapshotArgs::BatterySnapshotType)(kStatsSnapshotType[type] + 1); - - client->reportBatteryHealthSnapshot(min_ss); - client->reportBatteryHealthSnapshot(max_ss); + (BatteryHealthSnapshotArgs::BatterySnapshotType)(kStatsSnapshotType[type] + 1); stats_client->reportBatteryHealthSnapshot(min_stats_ss); stats_client->reportBatteryHealthSnapshot(max_stats_ss); @@ -123,15 +98,9 @@ bool BatteryMetricsLogger::uploadMetrics(void) { return false; } - sp<IPixelStats> client = IPixelStats::tryGetService(); - if (!client) { - LOG(ERROR) << "Unable to connect to PixelStats service"; - return false; - } - // Only log and upload the min and max for metric types we want to upload for (int metric = 0; metric < NUM_FIELDS; metric++) { - if ((metric == RES && num_res_samples_ == 0) || kSnapshotType[metric] < 0) + if ((metric == RES && num_res_samples_ == 0) || kStatsSnapshotType[metric] < 0) continue; std::string log_min = "min-" + std::to_string(metric) + " "; std::string log_max = "max-" + std::to_string(metric) + " "; @@ -142,28 +111,19 @@ bool BatteryMetricsLogger::uploadMetrics(void) { LOG(INFO) << log_min; LOG(INFO) << log_max; // Upload min/max metrics - uploadOutlierMetric(client, stats_client, static_cast<sampleType>(metric)); + uploadOutlierMetric(stats_client, static_cast<sampleType>(metric)); } // Upload average metric - IPixelStats::BatteryHealthSnapshotArgs avg_res_ss = { - .type = IPixelStats::BatterySnapshotType::AVG_RESISTANCE, - .temperatureDeciC = 0, - .voltageMicroV = 0, - .currentMicroA = 0, - .openCircuitVoltageMicroV = 0, - .resistanceMicroOhm = avg_resistance, - .levelPercent = 0}; BatteryHealthSnapshotArgs avg_res_ss_stats = { - .type = BatteryHealthSnapshotArgs::BatterySnapshotType::AVG_RESISTANCE, - .temperatureDeciC = 0, - .voltageMicroV = 0, - .currentMicroA = 0, - .openCircuitVoltageMicroV = 0, - .resistanceMicroOhm = avg_resistance, - .levelPercent = 0}; + .type = BatteryHealthSnapshotArgs::BatterySnapshotType::AVG_RESISTANCE, + .temperatureDeciC = 0, + .voltageMicroV = 0, + .currentMicroA = 0, + .openCircuitVoltageMicroV = 0, + .resistanceMicroOhm = avg_resistance, + .levelPercent = 0}; if (num_res_samples_) { - client->reportBatteryHealthSnapshot(avg_res_ss); stats_client->reportBatteryHealthSnapshot(avg_res_ss_stats); } @@ -215,7 +175,7 @@ bool BatteryMetricsLogger::recordSample(struct android::BatteryProperties *props for (int metric = 0; metric < NUM_FIELDS; metric++) { // Discard resistance min/max when charging if ((metric == RES && props->batteryStatus == android::BATTERY_STATUS_CHARGING) || - kSnapshotType[metric] < 0) + kStatsSnapshotType[metric] < 0) continue; if (num_samples_ == 0 || (metric == RES && num_res_samples_ == 0) || sample[metric] < min_[metric][metric]) { |