Fix mobile radio battery consumption double counting

On ODPM enabled devices, the total mobile radio power consumption was
being used when reporting the idle/suspended power. This means app
mobile radio power consumption was effectively being double counted.

Bug: 209525694
Test: atest MobileRadioPowerCalculatorTest
Change-Id: Ibc1a504014ac10c285b71273ba50493ba237f6a9
Merged-In: Ibc1a504014ac10c285b71273ba50493ba237f6a9
This commit is contained in:
Michael Wachenschwanz
2022-03-15 16:22:56 -07:00
parent 0f2b3ccafd
commit 05dcf05246
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);