Fix missing time-in-foreground and time-in-background for some apps

The gist of the issue is that many apps have two UIDs associated
with them: a regular, "real" UID, e.g. 10123, and a shared group GID,
e.g. 50123, which is used for multiuser support.

Prior to this fix, the code in BatteryAppListPreferenceController,
would go over the list of all UidBatteryConsumers and would randomly
encounter either the "real" UID or the shared GID for each app first.
The UidBatteryConsumer for a shared GID does not have all of the
properties of the real UID, so some information, such as
time-in-foreground and time-in-background would be lost with
a high probability.

After this fix, we process "real" UIDs before shared GIDs ensuring
that time-in-* and other properties such as package names are obtained
for the real UID.  When we later encounter a shared GID for the same app,
we just add the consumed power and time-in-* durations to the real UID's
BatteryEntry.

Bug: 188656360
Test: make RunSettingsRoboTests
Test: make RunSettingsGoogleRoboTests
Change-Id: I4bfea813ac5eb8f866804b2c4a9153eb877fb325
This commit is contained in:
Dmitri Plotnikov
2021-06-08 18:08:51 -07:00
parent c89b3afef5
commit 1afe9c0ddc
4 changed files with 73 additions and 48 deletions

View File

@@ -118,7 +118,8 @@ public class AppBatteryPreferenceController extends BasePreferenceController
final UserManager userManager =
(UserManager) mContext.getSystemService(Context.USER_SERVICE);
final BatteryEntry entry = new BatteryEntry(mContext, /* handler */null, userManager,
mUidBatteryConsumer, /* isHidden */ false, /* packages */ null, mPackageName);
mUidBatteryConsumer, /* isHidden */ false,
mUidBatteryConsumer.getUid(), /* packages */ null, mPackageName);
AdvancedPowerUsageDetail.startBatteryDetailPage(mParent.getActivity(), mParent,
entry, mBatteryPercent);
} else {