From 0e2c0f37d98bb5539b0fe41865aaf1add0ff1bb3 Mon Sep 17 00:00:00 2001 From: Kenny Root Date: Fri, 15 Apr 2011 17:50:10 -0700 Subject: Break apart queries to getInstalled* API To avoid blowing past the Binder IPC limit, change the PackageManagerService to have a DB-like interaction where the client tells the service the last "row" that it read. The fact that we use a HashMap instead of a TreeMap makes this problematic. For now we're just making a new ArrayList for the keys and then sorting them for each call. This can make the API slower for callers of this, but it's probably greatly overshadowed by the cost of the data transfer itself. Bug: 4064282 Change-Id: Ic370fd148d4c3813ae4f2daffa1a7c28d63d5a09 --- cmds/pm/src/com/android/commands/pm/Pm.java | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'cmds/pm') diff --git a/cmds/pm/src/com/android/commands/pm/Pm.java b/cmds/pm/src/com/android/commands/pm/Pm.java index 326e2c8..2ee512f 100644 --- a/cmds/pm/src/com/android/commands/pm/Pm.java +++ b/cmds/pm/src/com/android/commands/pm/Pm.java @@ -30,14 +30,15 @@ import android.content.pm.InstrumentationInfo; import android.content.pm.PackageInfo; import android.content.pm.PackageItemInfo; import android.content.pm.PackageManager; +import android.content.pm.ParceledListSlice; import android.content.pm.PermissionGroupInfo; import android.content.pm.PermissionInfo; import android.content.res.AssetManager; import android.content.res.Resources; import android.net.Uri; +import android.os.Parcel; import android.os.RemoteException; import android.os.ServiceManager; -import android.provider.Settings; import java.io.File; import java.lang.reflect.Field; @@ -223,7 +224,7 @@ public final class Pm { String filter = nextArg(); try { - List packages = mPm.getInstalledPackages(getFlags); + final List packages = getInstalledPackages(mPm, getFlags); int count = packages.size(); for (int p = 0 ; p < count ; p++) { @@ -247,6 +248,22 @@ public final class Pm { } } + @SuppressWarnings("unchecked") + private List getInstalledPackages(IPackageManager pm, int flags) + throws RemoteException { + final List packageInfos = new ArrayList(); + PackageInfo lastItem = null; + ParceledListSlice slice; + + do { + final String lastKey = lastItem != null ? lastItem.packageName : null; + slice = pm.getInstalledPackages(flags, lastKey); + lastItem = slice.populateList(packageInfos, PackageInfo.CREATOR); + } while (!slice.isLastSlice()); + + return packageInfos; + } + /** * Lists all of the features supported by the current device. * -- cgit v1.1