Merge "BatteryStats custom buckets: don't revive dead Uids" into sc-dev am: 0b905b1ef4

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/13679511

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: I3c66aea7d16498ace91b7381e354d14065c09794
This commit is contained in:
Adam Bookatz
2021-02-25 00:45:28 +00:00
committed by Automerger Merge Worker

View File

@@ -12520,6 +12520,7 @@ public class BatteryStatsImpl extends BatteryStats {
* @param totalEnergyUJ energy (microjoules) used for this bucket since this was last called. * @param totalEnergyUJ energy (microjoules) used for this bucket since this was last called.
* @param uidEnergies map of uid->energy (microjoules) for this bucket since last called. * @param uidEnergies map of uid->energy (microjoules) for this bucket since last called.
* Data inside uidEnergies will not be modified (treated immutable). * Data inside uidEnergies will not be modified (treated immutable).
* Uids not already known to BatteryStats will be ignored.
*/ */
public void updateCustomMeasuredEnergyDataLocked(int customEnergyBucket, public void updateCustomMeasuredEnergyDataLocked(int customEnergyBucket,
long totalEnergyUJ, @Nullable SparseLongArray uidEnergies) { long totalEnergyUJ, @Nullable SparseLongArray uidEnergies) {
@@ -12540,10 +12541,20 @@ public class BatteryStatsImpl extends BatteryStats {
final int uidInt = mapUid(uidEnergies.keyAt(i)); final int uidInt = mapUid(uidEnergies.keyAt(i));
final long uidEnergyUJ = uidEnergies.valueAt(i); final long uidEnergyUJ = uidEnergies.valueAt(i);
if (uidEnergyUJ == 0) continue; if (uidEnergyUJ == 0) continue;
// TODO(b/180030409): Worry about dead Uids (no longer in BSI) being revived by this, final Uid uidObj = getAvailableUidStatsLocked(uidInt);
// or converse problem of not creating a new Uid if its first blame is recorded here. if (uidObj != null) {
final Uid uidObj = getUidStatsLocked(uidInt); uidObj.addEnergyToCustomBucketLocked(uidEnergyUJ, customEnergyBucket, true);
uidObj.addEnergyToCustomBucketLocked(uidEnergyUJ, customEnergyBucket, true); } else {
// Ignore any uid not already known to BatteryStats, rather than creating a new Uid.
// Otherwise we could end up reviving dead Uids. Note that the CPU data is updated
// first, so any uid that has used any CPU should already be known to BatteryStats.
// Recently removed uids (especially common for isolated uids) can reach this path
// and are ignored.
if (!Process.isIsolated(uidInt)) {
Slog.w(TAG, "Received measured energy " + totalEnergyUJ + " for custom bucket "
+ customEnergyBucket + " for non-existent uid " + uidInt);
}
}
} }
} }