OSDN Git Service

DO NOT MERGE ANYWHERE Fix NPE when UID has no packages.
authorErik Wolsheimer <ewol@google.com>
Mon, 6 Jun 2016 17:49:02 +0000 (10:49 -0700)
committerErik Wolsheimer <ewol@google.com>
Mon, 6 Jun 2016 17:49:02 +0000 (10:49 -0700)
CP of 377ded0fce449f77cd7efae35f97722cdab52693

BUG: 25224723
BUG: 28815187
Change-Id: I248468f0d9ccd6aef36b2076bf7f90efb833efd2

core/java/android/content/pm/PackageManager.java
services/core/java/com/android/server/net/NetworkPolicyManagerService.java

index c8e9402..c229869 100644 (file)
@@ -2692,7 +2692,7 @@ public abstract class PackageManager {
      * @return Returns an array of one or more packages assigned to the user
      * id, or null if there are no known packages with the given id.
      */
-    public abstract String[] getPackagesForUid(int uid);
+    public abstract @Nullable String[] getPackagesForUid(int uid);
 
     /**
      * Retrieve the official name associated with a user id.  This name is
@@ -2705,7 +2705,7 @@ public abstract class PackageManager {
      * @return Returns a unique name for the given user id, or null if the
      * user id is not currently assigned.
      */
-    public abstract String getNameForUid(int uid);
+    public abstract @Nullable String getNameForUid(int uid);
 
     /**
      * Return the user id associated with a shared user name. Multiple
index cb3bcb0..75b37c2 100644 (file)
@@ -2319,9 +2319,11 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
         final String[] packages = mContext.getPackageManager().getPackagesForUid(uid);
         final int userId = UserHandle.getUserId(uid);
 
-        for (String packageName : packages) {
-            if (!mUsageStats.isAppIdle(packageName, uid, userId)) {
-                return false;
+        if (!ArrayUtils.isEmpty(packages)) {
+            for (String packageName : packages) {
+                if (!mUsageStats.isAppIdle(packageName, uid, userId)) {
+                    return false;
+                }
             }
         }
         return true;