BatteryStatsImpl: Add parcel methods for DisplayBatteryStats.

DisplayBatteryStats didn't have parcel methods and the estimated
multidisplay screen power was always initialized from 0.
The estimated screen power of the app will become inaccurate
after rebooting.

Bug: 235321975
Test: manual test.
1. Unplug the device.
2. Use an app for a while and keep screen on.
3. Capture the first bug report.
4. Reboot the device.
5. Capture the second bug report.
The estimated screen power of the app shouldn't become lower after rebooting the device.

Author: Shumao Hou <shumao1129@gmail.com>
Change-Id: If74e285102a7350c17c2fc40a205b2031e82f5f4
(cherry picked from commit 79c3779bb1)
This commit is contained in:
Shumao Hou
2022-06-15 15:47:04 -07:00
committed by Dmitri Plotnikov
parent b4d605f778
commit e57b8c1749

View File

@@ -166,8 +166,8 @@ public class BatteryStatsImpl extends BatteryStats {
// In-memory Parcel magic number, used to detect attempts to unmarshall bad data // In-memory Parcel magic number, used to detect attempts to unmarshall bad data
private static final int MAGIC = 0xBA757475; // 'BATSTATS' private static final int MAGIC = 0xBA757475; // 'BATSTATS'
// Current on-disk Parcel version // Current on-disk Parcel version. Must be updated when the format of the parcelable changes
static final int VERSION = 208; public static final int VERSION = 209;
// The maximum number of names wakelocks we will keep track of // The maximum number of names wakelocks we will keep track of
// per uid; once the limit is reached, we batch the remaining wakelocks // per uid; once the limit is reached, we batch the remaining wakelocks
@@ -884,6 +884,28 @@ public class BatteryStatsImpl extends BatteryStats {
screenBrightnessTimers[i].reset(false, elapsedRealtimeUs); screenBrightnessTimers[i].reset(false, elapsedRealtimeUs);
} }
} }
/**
* Write data to summary parcel
*/
public void writeSummaryToParcel(Parcel out, long elapsedRealtimeUs) {
screenOnTimer.writeSummaryFromParcelLocked(out, elapsedRealtimeUs);
screenDozeTimer.writeSummaryFromParcelLocked(out, elapsedRealtimeUs);
for (int i = 0; i < NUM_SCREEN_BRIGHTNESS_BINS; i++) {
screenBrightnessTimers[i].writeSummaryFromParcelLocked(out, elapsedRealtimeUs);
}
}
/**
* Read data from summary parcel
*/
public void readSummaryFromParcel(Parcel in) {
screenOnTimer.readSummaryFromParcelLocked(in);
screenDozeTimer.readSummaryFromParcelLocked(in);
for (int i = 0; i < NUM_SCREEN_BRIGHTNESS_BINS; i++) {
screenBrightnessTimers[i].readSummaryFromParcelLocked(in);
}
}
} }
DisplayBatteryStats[] mPerDisplayBatteryStats; DisplayBatteryStats[] mPerDisplayBatteryStats;
@@ -17275,6 +17297,10 @@ public class BatteryStatsImpl extends BatteryStats {
for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) {
mScreenBrightnessTimer[i].readSummaryFromParcelLocked(in); mScreenBrightnessTimer[i].readSummaryFromParcelLocked(in);
} }
final int numDisplays = in.readInt();
for (int i = 0; i < numDisplays; i++) {
mPerDisplayBatteryStats[i].readSummaryFromParcel(in);
}
mInteractive = false; mInteractive = false;
mInteractiveTimer.readSummaryFromParcelLocked(in); mInteractiveTimer.readSummaryFromParcelLocked(in);
mPhoneOn = false; mPhoneOn = false;
@@ -17784,6 +17810,11 @@ public class BatteryStatsImpl extends BatteryStats {
for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) {
mScreenBrightnessTimer[i].writeSummaryFromParcelLocked(out, nowRealtime); mScreenBrightnessTimer[i].writeSummaryFromParcelLocked(out, nowRealtime);
} }
final int numDisplays = mPerDisplayBatteryStats.length;
out.writeInt(numDisplays);
for (int i = 0; i < numDisplays; i++) {
mPerDisplayBatteryStats[i].writeSummaryToParcel(out, nowRealtime);
}
mInteractiveTimer.writeSummaryFromParcelLocked(out, nowRealtime); mInteractiveTimer.writeSummaryFromParcelLocked(out, nowRealtime);
mPowerSaveModeEnabledTimer.writeSummaryFromParcelLocked(out, nowRealtime); mPowerSaveModeEnabledTimer.writeSummaryFromParcelLocked(out, nowRealtime);
out.writeLong(mLongestLightIdleTimeMs); out.writeLong(mLongestLightIdleTimeMs);