OSDN Git Service

Don't crash when procstats has data for a now-disused uid
authorChristopher Tate <ctate@google.com>
Mon, 19 Aug 2013 00:26:48 +0000 (17:26 -0700)
committerChristopher Tate <ctate@google.com>
Mon, 19 Aug 2013 00:26:48 +0000 (17:26 -0700)
That is, PackageManager.getPackagesForUid(uid) can return null,
so deal with it.

Bug 10374656

Change-Id: I4eacd48c809b778e131d37dba0e86c583553e41f

src/com/android/settings/applications/ProcessStatsUi.java

index ec49e0d..8e98d23 100644 (file)
@@ -335,26 +335,31 @@ public class ProcessStatsUi extends PreferenceFragment {
             }
             if (targetApp == null) {
                 String[] packages = pm.getPackagesForUid(proc.mUid);
-                for (String curPkg : packages) {
-                    try {
-                        final PackageInfo pi = pm.getPackageInfo(curPkg,
-                                PackageManager.GET_DISABLED_COMPONENTS |
-                                PackageManager.GET_DISABLED_UNTIL_USED_COMPONENTS |
-                                PackageManager.GET_UNINSTALLED_PACKAGES);
-                        if (pi.sharedUserLabel != 0) {
-                            targetApp = pi.applicationInfo;
-                            final CharSequence nm = pm.getText(curPkg,
-                                    pi.sharedUserLabel, pi.applicationInfo);
-                            if (nm != null) {
-                                label = nm.toString() + " (" + proc.mName + ")";
-                            } else {
-                                label = targetApp.loadLabel(pm).toString() + " ("
-                                        + proc.mName + ")";
+                if (packages != null) {
+                    for (String curPkg : packages) {
+                        try {
+                            final PackageInfo pi = pm.getPackageInfo(curPkg,
+                                    PackageManager.GET_DISABLED_COMPONENTS |
+                                    PackageManager.GET_DISABLED_UNTIL_USED_COMPONENTS |
+                                    PackageManager.GET_UNINSTALLED_PACKAGES);
+                            if (pi.sharedUserLabel != 0) {
+                                targetApp = pi.applicationInfo;
+                                final CharSequence nm = pm.getText(curPkg,
+                                        pi.sharedUserLabel, pi.applicationInfo);
+                                if (nm != null) {
+                                    label = nm.toString() + " (" + proc.mName + ")";
+                                } else {
+                                    label = targetApp.loadLabel(pm).toString() + " ("
+                                            + proc.mName + ")";
+                                }
+                                break;
                             }
-                            break;
+                        } catch (PackageManager.NameNotFoundException e) {
                         }
-                    } catch (PackageManager.NameNotFoundException e) {
                     }
+                } else {
+                    // no current packages for this uid, typically because of uninstall
+                    Log.i(TAG, "No package for uid " + proc.mUid);
                 }
             }
             pref.setTitle(label);