Fix NPE when UID has no packages.

Bug: 25224723
Change-Id: I637214666a1f02bd23474c27a285eea9152cfa9d
This commit is contained in:
Jeff Sharkey
2016-01-10 13:15:41 -07:00
parent 2b60ca45a1
commit 377ded0fce
2 changed files with 7 additions and 5 deletions

View File

@@ -3115,7 +3115,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
@@ -3128,7 +3128,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

View File

@@ -2234,9 +2234,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;