Merge "Fix issue #25817435: Batterystats missing UIDs for secondary users" into nyc-dev

am: 966f1c9

* commit '966f1c93487b8bc9e259de11e1aaf0fb35b11dc2':
  Fix issue #25817435: Batterystats missing UIDs for secondary users
This commit is contained in:
Dianne Hackborn
2016-03-25 01:57:17 +00:00
committed by android-build-merger
3 changed files with 18 additions and 12 deletions

View File

@@ -30,6 +30,8 @@ import android.content.pm.ApplicationInfo;
import android.telephony.SignalStrength; import android.telephony.SignalStrength;
import android.text.format.DateFormat; import android.text.format.DateFormat;
import android.util.ArrayMap; import android.util.ArrayMap;
import android.util.MutableBoolean;
import android.util.Pair;
import android.util.Printer; import android.util.Printer;
import android.util.SparseArray; import android.util.SparseArray;
import android.util.SparseIntArray; import android.util.SparseIntArray;
@@ -5317,26 +5319,28 @@ public abstract class BatteryStats implements Parcelable {
} }
if (apps != null) { if (apps != null) {
SparseArray<ArrayList<String>> uids = new SparseArray<ArrayList<String>>(); SparseArray<Pair<ArrayList<String>, MutableBoolean>> uids = new SparseArray<>();
for (int i=0; i<apps.size(); i++) { for (int i=0; i<apps.size(); i++) {
ApplicationInfo ai = apps.get(i); ApplicationInfo ai = apps.get(i);
ArrayList<String> pkgs = uids.get(ai.uid); Pair<ArrayList<String>, MutableBoolean> pkgs = uids.get(
UserHandle.getAppId(ai.uid));
if (pkgs == null) { if (pkgs == null) {
pkgs = new ArrayList<String>(); pkgs = new Pair<>(new ArrayList<String>(), new MutableBoolean(false));
uids.put(ai.uid, pkgs); uids.put(UserHandle.getAppId(ai.uid), pkgs);
} }
pkgs.add(ai.packageName); pkgs.first.add(ai.packageName);
} }
SparseArray<? extends Uid> uidStats = getUidStats(); SparseArray<? extends Uid> uidStats = getUidStats();
final int NU = uidStats.size(); final int NU = uidStats.size();
String[] lineArgs = new String[2]; String[] lineArgs = new String[2];
for (int i=0; i<NU; i++) { for (int i=0; i<NU; i++) {
int uid = uidStats.keyAt(i); int uid = UserHandle.getAppId(uidStats.keyAt(i));
ArrayList<String> pkgs = uids.get(uid); Pair<ArrayList<String>, MutableBoolean> pkgs = uids.get(uid);
if (pkgs != null) { if (pkgs != null && !pkgs.second.value) {
for (int j=0; j<pkgs.size(); j++) { pkgs.second.value = true;
for (int j=0; j<pkgs.first.size(); j++) {
lineArgs[0] = Integer.toString(uid); lineArgs[0] = Integer.toString(uid);
lineArgs[1] = pkgs.get(j); lineArgs[1] = pkgs.first.get(j);
dumpLine(pw, 0 /* uid */, "i" /* category */, UID_DATA, dumpLine(pw, 0 /* uid */, "i" /* category */, UID_DATA,
(Object[])lineArgs); (Object[])lineArgs);
} }

View File

@@ -1170,7 +1170,8 @@ public final class BatteryStatsService extends IBatteryStats.Stub
} }
if (useCheckinFormat) { if (useCheckinFormat) {
List<ApplicationInfo> apps = mContext.getPackageManager().getInstalledApplications(0); List<ApplicationInfo> apps = mContext.getPackageManager().getInstalledApplications(
PackageManager.MATCH_UNINSTALLED_PACKAGES | PackageManager.MATCH_ALL);
if (isRealCheckin) { if (isRealCheckin) {
// For a real checkin, first we want to prefer to use the last complete checkin // For a real checkin, first we want to prefer to use the last complete checkin
// file if there is one. // file if there is one.

View File

@@ -4456,7 +4456,8 @@ final class Settings {
} }
} }
if ((permissionNames != null || dumpAll) && ps.pkg.requestedPermissions != null if ((permissionNames != null || dumpAll) && ps.pkg != null
&& ps.pkg.requestedPermissions != null
&& ps.pkg.requestedPermissions.size() > 0) { && ps.pkg.requestedPermissions.size() > 0) {
final ArrayList<String> perms = ps.pkg.requestedPermissions; final ArrayList<String> perms = ps.pkg.requestedPermissions;
pw.print(prefix); pw.println(" requested permissions:"); pw.print(prefix); pw.println(" requested permissions:");