Merge "Fix mobile radio battery consumption double counting" into sc-v2-dev

This commit is contained in:
TreeHugger Robot
2022-03-29 20:19:40 +00:00
committed by Android (Google) Code Review
2 changed files with 8 additions and 6 deletions

View File

@@ -99,9 +99,9 @@ public class MobileRadioPowerCalculator extends PowerCalculator {
calculateApp(app, uid, powerPerPacketMah, total, query);
}
final long consumptionUC = batteryStats.getMobileRadioMeasuredBatteryConsumptionUC();
final int powerModel = getPowerModel(consumptionUC, query);
calculateRemaining(total, powerModel, batteryStats, rawRealtimeUs, consumptionUC);
final long totalConsumptionUC = batteryStats.getMobileRadioMeasuredBatteryConsumptionUC();
final int powerModel = getPowerModel(totalConsumptionUC, query);
calculateRemaining(total, powerModel, batteryStats, rawRealtimeUs, totalConsumptionUC);
if (total.remainingPowerMah != 0 || total.totalAppPowerMah != 0) {
builder.getAggregateBatteryConsumerBuilder(
@@ -229,12 +229,13 @@ public class MobileRadioPowerCalculator extends PowerCalculator {
private void calculateRemaining(PowerAndDuration total,
@BatteryConsumer.PowerModel int powerModel, BatteryStats batteryStats,
long rawRealtimeUs, long consumptionUC) {
long rawRealtimeUs, long totalConsumptionUC) {
long signalTimeMs = 0;
double powerMah = 0;
if (powerModel == BatteryConsumer.POWER_MODEL_MEASURED_ENERGY) {
powerMah = uCtoMah(consumptionUC);
powerMah = uCtoMah(totalConsumptionUC) - total.totalAppPowerMah;
if (powerMah < 0) powerMah = 0;
}
for (int i = 0; i < NUM_SIGNAL_STRENGTH_LEVELS; i++) {

View File

@@ -166,8 +166,9 @@ public class MobileRadioPowerCalculatorTest {
.isEqualTo(BatteryConsumer.POWER_MODEL_MEASURED_ENERGY);
BatteryConsumer deviceConsumer = mStatsRule.getDeviceBatteryConsumer();
// 10_000_000 micro-Coulomb * 1/1000 milli/micro * 1/3600 hour/second = 2.77778 mAh
assertThat(deviceConsumer.getConsumedPower(BatteryConsumer.POWER_COMPONENT_MOBILE_RADIO))
.isWithin(PRECISION).of(4.31711);
.isWithin(PRECISION).of(2.77778);
assertThat(deviceConsumer.getPowerModel(BatteryConsumer.POWER_COMPONENT_MOBILE_RADIO))
.isEqualTo(BatteryConsumer.POWER_MODEL_MEASURED_ENERGY);