am 8f008e73: Merge "More multi-user methods in PM" into jb-mr1-dev

* commit '8f008e737a84be289d07cc603f98da1bbbfcf837':
  More multi-user methods in PM
This commit is contained in:
Amith Yamasani
2012-09-08 20:23:33 -07:00
committed by Android Git Automerger
6 changed files with 104 additions and 9 deletions

View File

@@ -42,6 +42,7 @@ import android.net.Uri;
import android.os.IUserManager;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.UserHandle;
import java.io.File;
import java.lang.reflect.Field;
@@ -241,6 +242,7 @@ public final class Pm {
boolean listDisabled = false, listEnabled = false;
boolean listSystem = false, listThirdParty = false;
boolean listInstaller = false;
int userId = UserHandle.USER_OWNER;
try {
String opt;
while ((opt=nextOption()) != null) {
@@ -260,6 +262,8 @@ public final class Pm {
listThirdParty = true;
} else if (opt.equals("-i")) {
listInstaller = true;
} else if (opt.equals("--user")) {
userId = Integer.parseInt(nextArg());
} else if (opt.equals("-u")) {
getFlags |= PackageManager.GET_UNINSTALLED_PACKAGES;
} else {
@@ -275,7 +279,7 @@ public final class Pm {
String filter = nextArg();
try {
final List<PackageInfo> packages = getInstalledPackages(mPm, getFlags);
final List<PackageInfo> packages = getInstalledPackages(mPm, getFlags, userId);
int count = packages.size();
for (int p = 0 ; p < count ; p++) {
@@ -309,7 +313,7 @@ public final class Pm {
}
@SuppressWarnings("unchecked")
private List<PackageInfo> getInstalledPackages(IPackageManager pm, int flags)
private List<PackageInfo> getInstalledPackages(IPackageManager pm, int flags, int userId)
throws RemoteException {
final List<PackageInfo> packageInfos = new ArrayList<PackageInfo>();
PackageInfo lastItem = null;
@@ -317,7 +321,7 @@ public final class Pm {
do {
final String lastKey = lastItem != null ? lastItem.packageName : null;
slice = pm.getInstalledPackages(flags, lastKey);
slice = pm.getInstalledPackages(flags, lastKey, userId);
lastItem = slice.populateList(packageInfos, PackageInfo.CREATOR);
} while (!slice.isLastSlice());
@@ -1420,7 +1424,7 @@ public final class Pm {
}
private static void showUsage() {
System.err.println("usage: pm list packages [-f] [-d] [-e] [-s] [-3] [-i] [-u] [FILTER]");
System.err.println("usage: pm list packages [-f] [-d] [-e] [-s] [-3] [-i] [-u] [--user USER_ID] [FILTER]");
System.err.println(" pm list permission-groups");
System.err.println(" pm list permissions [-g] [-f] [-d] [-u] [GROUP]");
System.err.println(" pm list instrumentation [-f] [TARGET-PACKAGE]");

View File

@@ -407,6 +407,12 @@ final class ApplicationPackageManager extends PackageManager {
@SuppressWarnings("unchecked")
@Override
public List<PackageInfo> getInstalledPackages(int flags) {
return getInstalledPackages(flags, UserHandle.myUserId());
}
/** @hide */
@Override
public List<PackageInfo> getInstalledPackages(int flags, int userId) {
try {
final List<PackageInfo> packageInfos = new ArrayList<PackageInfo>();
PackageInfo lastItem = null;
@@ -414,7 +420,7 @@ final class ApplicationPackageManager extends PackageManager {
do {
final String lastKey = lastItem != null ? lastItem.packageName : null;
slice = mPM.getInstalledPackages(flags, lastKey);
slice = mPM.getInstalledPackages(flags, lastKey, userId);
lastItem = slice.populateList(packageInfos, PackageInfo.CREATOR);
} while (!slice.isLastSlice());
@@ -460,12 +466,19 @@ final class ApplicationPackageManager extends PackageManager {
@Override
public List<ResolveInfo> queryIntentActivities(Intent intent,
int flags) {
return queryIntentActivitiesForUser(intent, flags, UserHandle.myUserId());
}
/** @hide Same as above but for a specific user */
@Override
public List<ResolveInfo> queryIntentActivitiesForUser(Intent intent,
int flags, int userId) {
try {
return mPM.queryIntentActivities(
intent,
intent.resolveTypeIfNeeded(mContext.getContentResolver()),
flags,
UserHandle.myUserId());
userId);
} catch (RemoteException e) {
throw new RuntimeException("Package manager has died", e);
}

View File

@@ -127,7 +127,7 @@ interface IPackageManager {
* limit that kicks in when flags are included that bloat up the data
* returned.
*/
ParceledListSlice getInstalledPackages(int flags, in String lastRead);
ParceledListSlice getInstalledPackages(int flags, in String lastRead, in int userId);
/**
* This implements getInstalledApplications via a "last returned row"

View File

@@ -1468,6 +1468,45 @@ public abstract class PackageManager {
*/
public abstract List<PackageInfo> getInstalledPackages(int flags);
/**
* Return a List of all packages that are installed on the device, for a specific user.
* Requesting a list of installed packages for another user
* will require the permission INTERACT_ACROSS_USERS_FULL.
* @param flags Additional option flags. Use any combination of
* {@link #GET_ACTIVITIES},
* {@link #GET_GIDS},
* {@link #GET_CONFIGURATIONS},
* {@link #GET_INSTRUMENTATION},
* {@link #GET_PERMISSIONS},
* {@link #GET_PROVIDERS},
* {@link #GET_RECEIVERS},
* {@link #GET_SERVICES},
* {@link #GET_SIGNATURES},
* {@link #GET_UNINSTALLED_PACKAGES} to modify the data returned.
* @param userId The user for whom the installed packages are to be listed
*
* @return A List of PackageInfo objects, one for each package that is
* installed on the device. In the unlikely case of there being no
* installed packages, an empty list is returned.
* If flag GET_UNINSTALLED_PACKAGES is set, a list of all
* applications including those deleted with DONT_DELETE_DATA
* (partially installed apps with data directory) will be returned.
*
* @see #GET_ACTIVITIES
* @see #GET_GIDS
* @see #GET_CONFIGURATIONS
* @see #GET_INSTRUMENTATION
* @see #GET_PERMISSIONS
* @see #GET_PROVIDERS
* @see #GET_RECEIVERS
* @see #GET_SERVICES
* @see #GET_SIGNATURES
* @see #GET_UNINSTALLED_PACKAGES
*
* @hide
*/
public abstract List<PackageInfo> getInstalledPackages(int flags, int userId);
/**
* Check whether a particular package has been granted a particular
* permission.
@@ -1754,6 +1793,29 @@ public abstract class PackageManager {
public abstract List<ResolveInfo> queryIntentActivities(Intent intent,
int flags);
/**
* Retrieve all activities that can be performed for the given intent, for a specific user.
*
* @param intent The desired intent as per resolveActivity().
* @param flags Additional option flags. The most important is
* {@link #MATCH_DEFAULT_ONLY}, to limit the resolution to only
* those activities that support the {@link android.content.Intent#CATEGORY_DEFAULT}.
*
* @return A List&lt;ResolveInfo&gt; containing one entry for each matching
* Activity. These are ordered from best to worst match -- that
* is, the first item in the list is what is returned by
* {@link #resolveActivity}. If there are no matching activities, an empty
* list is returned.
*
* @see #MATCH_DEFAULT_ONLY
* @see #GET_INTENT_FILTERS
* @see #GET_RESOLVED_FILTER
* @hide
*/
public abstract List<ResolveInfo> queryIntentActivitiesForUser(Intent intent,
int flags, int userId);
/**
* Retrieve a set of activities that should be presented to the user as
* similar options. This is like {@link #queryIntentActivities}, except it

View File

@@ -2891,11 +2891,14 @@ public class PackageManagerService extends IPackageManager.Stub {
return index;
}
public ParceledListSlice<PackageInfo> getInstalledPackages(int flags, String lastRead) {
@Override
public ParceledListSlice<PackageInfo> getInstalledPackages(int flags, String lastRead,
int userId) {
final ParceledListSlice<PackageInfo> list = new ParceledListSlice<PackageInfo>();
final boolean listUninstalled = (flags & PackageManager.GET_UNINSTALLED_PACKAGES) != 0;
final String[] keys;
int userId = UserHandle.getCallingUserId();
enforceCrossUserPermission(Binder.getCallingUid(), userId, true, "get installed packages");
// writer
synchronized (mPackages) {

View File

@@ -140,6 +140,12 @@ public class MockPackageManager extends PackageManager {
throw new UnsupportedOperationException();
}
/** @hide */
@Override
public List<PackageInfo> getInstalledPackages(int flags, int userId) {
throw new UnsupportedOperationException();
}
@Override
public int checkPermission(String permName, String pkgName) {
throw new UnsupportedOperationException();
@@ -215,6 +221,13 @@ public class MockPackageManager extends PackageManager {
throw new UnsupportedOperationException();
}
/** @hide */
@Override
public List<ResolveInfo> queryIntentActivitiesForUser(Intent intent,
int flags, int userId) {
throw new UnsupportedOperationException();
}
@Override
public List<ResolveInfo> queryIntentActivityOptions(ComponentName caller,
Intent[] specifics, Intent intent, int flags) {