summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Nicolas Prevot <nprevot@google.com> 2015-09-21 11:39:42 +0100
committer Nicolas Prevot <nprevot@google.com> 2015-09-21 11:39:42 +0100
commit3b0fc3cf24e1fecdbc11808483c2109415ebfdd2 (patch)
tree7956d80abb8a83bc7f346b416c59528fb92e0461
parentd6fb31adde6cf6c17ee794fd51ea23dbe88ac20e (diff)
Add more methods that take a userId to PackageManager.
Add methods installPackageAsUser and installExistingPackageAsUser and deletePackageAsUser and getPackageInfoAsUser. Change-Id: I9a3ff96f968b4f8d21a57cc7760679628d35c1a9 BUG:23516394
-rw-r--r--core/java/android/app/ApplicationPackageManager.java52
-rw-r--r--core/java/android/content/pm/PackageManager.java103
-rw-r--r--test-runner/src/android/test/mock/MockPackageManager.java34
3 files changed, 175 insertions, 14 deletions
diff --git a/core/java/android/app/ApplicationPackageManager.java b/core/java/android/app/ApplicationPackageManager.java
index 0cd02dd397c1..9ec84ca61239 100644
--- a/core/java/android/app/ApplicationPackageManager.java
+++ b/core/java/android/app/ApplicationPackageManager.java
@@ -126,8 +126,14 @@ final class ApplicationPackageManager extends PackageManager {
@Override
public PackageInfo getPackageInfo(String packageName, int flags)
throws NameNotFoundException {
+ return getPackageInfoAsUser(packageName, flags, mContext.getUserId());
+ }
+
+ @Override
+ public PackageInfo getPackageInfoAsUser(String packageName, int flags, int userId)
+ throws NameNotFoundException {
try {
- PackageInfo pi = mPM.getPackageInfo(packageName, flags, mContext.getUserId());
+ PackageInfo pi = mPM.getPackageInfo(packageName, flags, userId);
if (pi != null) {
return pi;
}
@@ -1335,10 +1341,17 @@ final class ApplicationPackageManager extends PackageManager {
@Override
public void installPackage(Uri packageURI, IPackageInstallObserver observer, int flags,
String installerPackageName) {
+ installPackageAsUser(packageURI, observer, flags, installerPackageName,
+ UserHandle.myUserId());
+ }
+
+ @Override
+ public void installPackageAsUser(Uri packageURI, IPackageInstallObserver observer, int flags,
+ String installerPackageName, int userId) {
final VerificationParams verificationParams = new VerificationParams(null, null,
null, VerificationParams.NO_UID, null);
installCommon(packageURI, new LegacyPackageInstallObserver(observer), flags,
- installerPackageName, verificationParams, null);
+ installerPackageName, verificationParams, null, userId);
}
@Override
@@ -1348,7 +1361,7 @@ final class ApplicationPackageManager extends PackageManager {
final VerificationParams verificationParams = new VerificationParams(verificationURI, null,
null, VerificationParams.NO_UID, manifestDigest);
installCommon(packageURI, new LegacyPackageInstallObserver(observer), flags,
- installerPackageName, verificationParams, encryptionParams);
+ installerPackageName, verificationParams, encryptionParams, UserHandle.myUserId());
}
@Override
@@ -1356,7 +1369,7 @@ final class ApplicationPackageManager extends PackageManager {
IPackageInstallObserver observer, int flags, String installerPackageName,
VerificationParams verificationParams, ContainerEncryptionParams encryptionParams) {
installCommon(packageURI, new LegacyPackageInstallObserver(observer), flags,
- installerPackageName, verificationParams, encryptionParams);
+ installerPackageName, verificationParams, encryptionParams, UserHandle.myUserId());
}
@Override
@@ -1364,7 +1377,8 @@ final class ApplicationPackageManager extends PackageManager {
int flags, String installerPackageName) {
final VerificationParams verificationParams = new VerificationParams(null, null,
null, VerificationParams.NO_UID, null);
- installCommon(packageURI, observer, flags, installerPackageName, verificationParams, null);
+ installCommon(packageURI, observer, flags, installerPackageName, verificationParams, null,
+ UserHandle.myUserId());
}
@Override
@@ -1375,7 +1389,7 @@ final class ApplicationPackageManager extends PackageManager {
final VerificationParams verificationParams = new VerificationParams(verificationURI, null,
null, VerificationParams.NO_UID, manifestDigest);
installCommon(packageURI, observer, flags, installerPackageName, verificationParams,
- encryptionParams);
+ encryptionParams, UserHandle.myUserId());
}
@Override
@@ -1383,12 +1397,13 @@ final class ApplicationPackageManager extends PackageManager {
PackageInstallObserver observer, int flags, String installerPackageName,
VerificationParams verificationParams, ContainerEncryptionParams encryptionParams) {
installCommon(packageURI, observer, flags, installerPackageName, verificationParams,
- encryptionParams);
+ encryptionParams, UserHandle.myUserId());
}
private void installCommon(Uri packageURI,
PackageInstallObserver observer, int flags, String installerPackageName,
- VerificationParams verificationParams, ContainerEncryptionParams encryptionParams) {
+ VerificationParams verificationParams, ContainerEncryptionParams encryptionParams,
+ int userId) {
if (!"file".equals(packageURI.getScheme())) {
throw new UnsupportedOperationException("Only file:// URIs are supported");
}
@@ -1398,17 +1413,22 @@ final class ApplicationPackageManager extends PackageManager {
final String originPath = packageURI.getPath();
try {
- mPM.installPackage(originPath, observer.getBinder(), flags, installerPackageName,
- verificationParams, null);
+ mPM.installPackageAsUser(originPath, observer.getBinder(), flags, installerPackageName,
+ verificationParams, null, userId);
} catch (RemoteException ignored) {
}
}
@Override
- public int installExistingPackage(String packageName)
+ public int installExistingPackage(String packageName) throws NameNotFoundException {
+ return installExistingPackageAsUser(packageName, UserHandle.myUserId());
+ }
+
+ @Override
+ public int installExistingPackageAsUser(String packageName, int userId)
throws NameNotFoundException {
try {
- int res = mPM.installExistingPackageAsUser(packageName, UserHandle.myUserId());
+ int res = mPM.installExistingPackageAsUser(packageName, userId);
if (res == INSTALL_FAILED_INVALID_URI) {
throw new NameNotFoundException("Package " + packageName + " doesn't exist");
}
@@ -1706,8 +1726,14 @@ final class ApplicationPackageManager extends PackageManager {
@Override
public void deletePackage(String packageName, IPackageDeleteObserver observer, int flags) {
+ deletePackageAsUser(packageName, observer, flags, UserHandle.myUserId());
+ }
+
+ @Override
+ public void deletePackageAsUser(String packageName, IPackageDeleteObserver observer, int flags,
+ int userId) {
try {
- mPM.deletePackageAsUser(packageName, observer, UserHandle.myUserId(), flags);
+ mPM.deletePackageAsUser(packageName, observer, userId, flags);
} catch (RemoteException e) {
// Should never happen!
}
diff --git a/core/java/android/content/pm/PackageManager.java b/core/java/android/content/pm/PackageManager.java
index c8e9402e6442..a92f4ef0a5a9 100644
--- a/core/java/android/content/pm/PackageManager.java
+++ b/core/java/android/content/pm/PackageManager.java
@@ -2032,6 +2032,48 @@ public abstract class PackageManager {
throws NameNotFoundException;
/**
+ * @hide
+ * Retrieve overall information about an application package that is
+ * installed on the system.
+ * <p>
+ * Throws {@link NameNotFoundException} if a package with the given name can
+ * not be found on the system.
+ * Fails if the calling context lacks the
+ * {@link android.Manifest.permission#INTERACT_ACROSS_USERS} permission and
+ * the target user is not the calling user.
+ *
+ * @param packageName The full name (i.e. com.google.apps.contacts) of the
+ * desired package.
+ * @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 id.
+ * @return Returns a PackageInfo object containing information about the
+ * package. If flag GET_UNINSTALLED_PACKAGES is set and if the
+ * package is not found in the list of installed applications, the
+ * package information is retrieved from the list of uninstalled
+ * applications (which includes installed applications as well as
+ * applications with data directory i.e. applications which had been
+ * deleted with {@code DONT_DELETE_DATA} flag set).
+ * @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
+ */
+ public abstract PackageInfo getPackageInfoAsUser(String packageName, int flags, int userId)
+ throws NameNotFoundException;
+
+ /**
* Map from the current package names in use on the device to whatever
* the current canonical name of that package is.
* @param names Array of current names to be mapped.
@@ -3588,6 +3630,38 @@ public abstract class PackageManager {
String installerPackageName);
/**
+ * @hide
+ * Install a package. Since this may take a little while, the result will be
+ * posted back to the given observer. An installation will fail if the calling
+ * context lacks the {@link android.Manifest.permission#INSTALL_PACKAGES}
+ * permission or the {@link android.Manifest.permission#INTERACT_ACROSS_USERS_FULL}
+ * permission when the target user is not the calling user, the package named
+ * in the package file's manifest is already installed, or if there's no space
+ * available on the device.
+ * @param packageURI The location of the package file to install. This can
+ * be a 'file:' or a 'content:' URI.
+ * @param observer An observer callback to get notified when the package
+ * installation is complete.
+ * {@link IPackageInstallObserver#packageInstalled(String, int)}
+ * will be called when that happens. This parameter must not be
+ * null.
+ * @param flags - possible values: {@link #INSTALL_FORWARD_LOCK},
+ * {@link #INSTALL_REPLACE_EXISTING},
+ * {@link #INSTALL_ALLOW_TEST}.
+ * @param installerPackageName Optional package name of the application that
+ * is performing the installation. This identifies which market
+ * the package came from.
+ * @param userId The user id
+ * @deprecated Use {@link #installPackage(Uri, PackageInstallObserver, int,
+ * String)} instead. This method will continue to be supported
+ * but the older observer interface will not get additional
+ * failure details.
+ */
+ public abstract void installPackageAsUser(
+ Uri packageURI, IPackageInstallObserver observer, int flags,
+ String installerPackageName, int userId);
+
+ /**
* Similar to
* {@link #installPackage(Uri, IPackageInstallObserver, int, String)} but
* with an extra verification file provided.
@@ -3756,6 +3830,14 @@ public abstract class PackageManager {
throws NameNotFoundException;
/**
+ * If there is already an application with the given package name installed
+ * on the system for other users, also install it for the specified user.
+ * @hide
+ */
+ public abstract int installExistingPackageAsUser(String packageName, int userId)
+ throws NameNotFoundException;
+
+ /**
* Allows a package listening to the
* {@link Intent#ACTION_PACKAGE_NEEDS_VERIFICATION package verification
* broadcast} to respond to the package manager. The response must include
@@ -3968,6 +4050,27 @@ public abstract class PackageManager {
String packageName, IPackageDeleteObserver observer, int flags);
/**
+ * Attempts to delete a package. Since this may take a little while, the result will
+ * be posted back to the given observer. A deletion will fail if the calling context
+ * lacks the {@link android.Manifest.permission#DELETE_PACKAGES} permission or the
+ * {@link android.Manifest.permission#INTERACT_ACROSS_USERS_FULL} permission when the target
+ * user is not the calling user, if the named package cannot be found, or if the named package
+ * is a "system package".
+ * (TODO: include pointer to documentation on "system packages")
+ *
+ * @param packageName The name of the package to delete
+ * @param observer An observer callback to get notified when the package deletion is
+ * complete. {@link android.content.pm.IPackageDeleteObserver#packageDeleted(boolean)} will be
+ * called when that happens. observer may be null to indicate that no callback is desired.
+ * @param flags - possible values: {@link #DELETE_KEEP_DATA}, {@link #DELETE_ALL_USERS}.
+ * @param userId - The user Id
+ *
+ * @hide
+ */
+ public abstract void deletePackageAsUser(
+ String packageName, IPackageDeleteObserver observer, int flags, int userId);
+
+ /**
* Retrieve the package name of the application that installed a package. This identifies
* which market the package came from.
*
diff --git a/test-runner/src/android/test/mock/MockPackageManager.java b/test-runner/src/android/test/mock/MockPackageManager.java
index 1ff621a6cac9..cfc4499bd616 100644
--- a/test-runner/src/android/test/mock/MockPackageManager.java
+++ b/test-runner/src/android/test/mock/MockPackageManager.java
@@ -64,7 +64,14 @@ public class MockPackageManager extends PackageManager {
@Override
public PackageInfo getPackageInfo(String packageName, int flags)
- throws NameNotFoundException {
+ throws NameNotFoundException {
+ throw new UnsupportedOperationException();
+ }
+
+ /** @hide */
+ @Override
+ public PackageInfo getPackageInfoAsUser(String packageName, int flags, int userId)
+ throws NameNotFoundException {
throw new UnsupportedOperationException();
}
@@ -524,6 +531,13 @@ public class MockPackageManager extends PackageManager {
throw new UnsupportedOperationException();
}
+ /** @hide */
+ @Override
+ public void installPackageAsUser(Uri packageURI, IPackageInstallObserver observer,
+ int flags, String installerPackageName, int userId) {
+ throw new UnsupportedOperationException();
+ }
+
@Override
public void setInstallerPackageName(String targetPackage,
String installerPackageName) {
@@ -629,6 +643,15 @@ public class MockPackageManager extends PackageManager {
throw new UnsupportedOperationException();
}
+ /**
+ * @hide - to match hiding in superclass
+ */
+ @Override
+ public void deletePackageAsUser(
+ String packageName, IPackageDeleteObserver observer, int flags, int userId) {
+ throw new UnsupportedOperationException();
+ }
+
@Override
public void addPackageToPreferred(String packageName) {
throw new UnsupportedOperationException();
@@ -797,6 +820,15 @@ public class MockPackageManager extends PackageManager {
throw new UnsupportedOperationException();
}
+ /**
+ * @hide
+ */
+ @Override
+ public int installExistingPackageAsUser(String packageName, int userId)
+ throws NameNotFoundException {
+ throw new UnsupportedOperationException();
+ }
+
@Override
public void verifyPendingInstall(int id, int verificationCode) {
throw new UnsupportedOperationException();