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:
@@ -42,6 +42,7 @@ import android.net.Uri;
|
|||||||
import android.os.IUserManager;
|
import android.os.IUserManager;
|
||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
import android.os.ServiceManager;
|
import android.os.ServiceManager;
|
||||||
|
import android.os.UserHandle;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
@@ -241,6 +242,7 @@ public final class Pm {
|
|||||||
boolean listDisabled = false, listEnabled = false;
|
boolean listDisabled = false, listEnabled = false;
|
||||||
boolean listSystem = false, listThirdParty = false;
|
boolean listSystem = false, listThirdParty = false;
|
||||||
boolean listInstaller = false;
|
boolean listInstaller = false;
|
||||||
|
int userId = UserHandle.USER_OWNER;
|
||||||
try {
|
try {
|
||||||
String opt;
|
String opt;
|
||||||
while ((opt=nextOption()) != null) {
|
while ((opt=nextOption()) != null) {
|
||||||
@@ -260,6 +262,8 @@ public final class Pm {
|
|||||||
listThirdParty = true;
|
listThirdParty = true;
|
||||||
} else if (opt.equals("-i")) {
|
} else if (opt.equals("-i")) {
|
||||||
listInstaller = true;
|
listInstaller = true;
|
||||||
|
} else if (opt.equals("--user")) {
|
||||||
|
userId = Integer.parseInt(nextArg());
|
||||||
} else if (opt.equals("-u")) {
|
} else if (opt.equals("-u")) {
|
||||||
getFlags |= PackageManager.GET_UNINSTALLED_PACKAGES;
|
getFlags |= PackageManager.GET_UNINSTALLED_PACKAGES;
|
||||||
} else {
|
} else {
|
||||||
@@ -275,7 +279,7 @@ public final class Pm {
|
|||||||
String filter = nextArg();
|
String filter = nextArg();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
final List<PackageInfo> packages = getInstalledPackages(mPm, getFlags);
|
final List<PackageInfo> packages = getInstalledPackages(mPm, getFlags, userId);
|
||||||
|
|
||||||
int count = packages.size();
|
int count = packages.size();
|
||||||
for (int p = 0 ; p < count ; p++) {
|
for (int p = 0 ; p < count ; p++) {
|
||||||
@@ -309,7 +313,7 @@ public final class Pm {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
private List<PackageInfo> getInstalledPackages(IPackageManager pm, int flags)
|
private List<PackageInfo> getInstalledPackages(IPackageManager pm, int flags, int userId)
|
||||||
throws RemoteException {
|
throws RemoteException {
|
||||||
final List<PackageInfo> packageInfos = new ArrayList<PackageInfo>();
|
final List<PackageInfo> packageInfos = new ArrayList<PackageInfo>();
|
||||||
PackageInfo lastItem = null;
|
PackageInfo lastItem = null;
|
||||||
@@ -317,7 +321,7 @@ public final class Pm {
|
|||||||
|
|
||||||
do {
|
do {
|
||||||
final String lastKey = lastItem != null ? lastItem.packageName : null;
|
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);
|
lastItem = slice.populateList(packageInfos, PackageInfo.CREATOR);
|
||||||
} while (!slice.isLastSlice());
|
} while (!slice.isLastSlice());
|
||||||
|
|
||||||
@@ -1420,7 +1424,7 @@ public final class Pm {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static void showUsage() {
|
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 permission-groups");
|
||||||
System.err.println(" pm list permissions [-g] [-f] [-d] [-u] [GROUP]");
|
System.err.println(" pm list permissions [-g] [-f] [-d] [-u] [GROUP]");
|
||||||
System.err.println(" pm list instrumentation [-f] [TARGET-PACKAGE]");
|
System.err.println(" pm list instrumentation [-f] [TARGET-PACKAGE]");
|
||||||
|
|||||||
@@ -407,6 +407,12 @@ final class ApplicationPackageManager extends PackageManager {
|
|||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Override
|
@Override
|
||||||
public List<PackageInfo> getInstalledPackages(int flags) {
|
public List<PackageInfo> getInstalledPackages(int flags) {
|
||||||
|
return getInstalledPackages(flags, UserHandle.myUserId());
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @hide */
|
||||||
|
@Override
|
||||||
|
public List<PackageInfo> getInstalledPackages(int flags, int userId) {
|
||||||
try {
|
try {
|
||||||
final List<PackageInfo> packageInfos = new ArrayList<PackageInfo>();
|
final List<PackageInfo> packageInfos = new ArrayList<PackageInfo>();
|
||||||
PackageInfo lastItem = null;
|
PackageInfo lastItem = null;
|
||||||
@@ -414,7 +420,7 @@ final class ApplicationPackageManager extends PackageManager {
|
|||||||
|
|
||||||
do {
|
do {
|
||||||
final String lastKey = lastItem != null ? lastItem.packageName : null;
|
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);
|
lastItem = slice.populateList(packageInfos, PackageInfo.CREATOR);
|
||||||
} while (!slice.isLastSlice());
|
} while (!slice.isLastSlice());
|
||||||
|
|
||||||
@@ -460,12 +466,19 @@ final class ApplicationPackageManager extends PackageManager {
|
|||||||
@Override
|
@Override
|
||||||
public List<ResolveInfo> queryIntentActivities(Intent intent,
|
public List<ResolveInfo> queryIntentActivities(Intent intent,
|
||||||
int flags) {
|
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 {
|
try {
|
||||||
return mPM.queryIntentActivities(
|
return mPM.queryIntentActivities(
|
||||||
intent,
|
intent,
|
||||||
intent.resolveTypeIfNeeded(mContext.getContentResolver()),
|
intent.resolveTypeIfNeeded(mContext.getContentResolver()),
|
||||||
flags,
|
flags,
|
||||||
UserHandle.myUserId());
|
userId);
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
throw new RuntimeException("Package manager has died", e);
|
throw new RuntimeException("Package manager has died", e);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -127,7 +127,7 @@ interface IPackageManager {
|
|||||||
* limit that kicks in when flags are included that bloat up the data
|
* limit that kicks in when flags are included that bloat up the data
|
||||||
* returned.
|
* 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"
|
* This implements getInstalledApplications via a "last returned row"
|
||||||
|
|||||||
@@ -1468,6 +1468,45 @@ public abstract class PackageManager {
|
|||||||
*/
|
*/
|
||||||
public abstract List<PackageInfo> getInstalledPackages(int flags);
|
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
|
* Check whether a particular package has been granted a particular
|
||||||
* permission.
|
* permission.
|
||||||
@@ -1754,6 +1793,29 @@ public abstract class PackageManager {
|
|||||||
public abstract List<ResolveInfo> queryIntentActivities(Intent intent,
|
public abstract List<ResolveInfo> queryIntentActivities(Intent intent,
|
||||||
int flags);
|
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<ResolveInfo> 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
|
* Retrieve a set of activities that should be presented to the user as
|
||||||
* similar options. This is like {@link #queryIntentActivities}, except it
|
* similar options. This is like {@link #queryIntentActivities}, except it
|
||||||
|
|||||||
@@ -2891,11 +2891,14 @@ public class PackageManagerService extends IPackageManager.Stub {
|
|||||||
return index;
|
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 ParceledListSlice<PackageInfo> list = new ParceledListSlice<PackageInfo>();
|
||||||
final boolean listUninstalled = (flags & PackageManager.GET_UNINSTALLED_PACKAGES) != 0;
|
final boolean listUninstalled = (flags & PackageManager.GET_UNINSTALLED_PACKAGES) != 0;
|
||||||
final String[] keys;
|
final String[] keys;
|
||||||
int userId = UserHandle.getCallingUserId();
|
|
||||||
|
enforceCrossUserPermission(Binder.getCallingUid(), userId, true, "get installed packages");
|
||||||
|
|
||||||
// writer
|
// writer
|
||||||
synchronized (mPackages) {
|
synchronized (mPackages) {
|
||||||
|
|||||||
@@ -140,6 +140,12 @@ public class MockPackageManager extends PackageManager {
|
|||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @hide */
|
||||||
|
@Override
|
||||||
|
public List<PackageInfo> getInstalledPackages(int flags, int userId) {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int checkPermission(String permName, String pkgName) {
|
public int checkPermission(String permName, String pkgName) {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
@@ -215,6 +221,13 @@ public class MockPackageManager extends PackageManager {
|
|||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @hide */
|
||||||
|
@Override
|
||||||
|
public List<ResolveInfo> queryIntentActivitiesForUser(Intent intent,
|
||||||
|
int flags, int userId) {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<ResolveInfo> queryIntentActivityOptions(ComponentName caller,
|
public List<ResolveInfo> queryIntentActivityOptions(ComponentName caller,
|
||||||
Intent[] specifics, Intent intent, int flags) {
|
Intent[] specifics, Intent intent, int flags) {
|
||||||
|
|||||||
Reference in New Issue
Block a user