From c64322c35212e919906ffd66118c7d5d3ad36636 Mon Sep 17 00:00:00 2001 From: Jacek Surazski Date: Tue, 28 Apr 2009 15:26:38 +0200 Subject: PackageManager keeps track of who installed what. Stores the package name of the installer app in packages.xml --- core/java/android/app/ApplicationContext.java | 15 ++++++-- core/java/android/content/pm/IPackageManager.aidl | 7 +++- core/java/android/content/pm/PackageManager.java | 42 +++++++++++++++++++++-- 3 files changed, 59 insertions(+), 5 deletions(-) (limited to 'core/java') diff --git a/core/java/android/app/ApplicationContext.java b/core/java/android/app/ApplicationContext.java index a1f5a58..bb17dc3 100644 --- a/core/java/android/app/ApplicationContext.java +++ b/core/java/android/app/ApplicationContext.java @@ -2310,15 +2310,26 @@ class ApplicationContext extends Context { } @Override - public void installPackage(Uri packageURI, IPackageInstallObserver observer, int flags) { + public void installPackage(Uri packageURI, IPackageInstallObserver observer, int flags, + String installerPackageName) { try { - mPM.installPackage(packageURI, observer, flags); + mPM.installPackage(packageURI, observer, flags, installerPackageName); } catch (RemoteException e) { // Should never happen! } } @Override + public String getInstallerPackageName(String packageName) { + try { + return mPM.getInstallerPackageName(packageName); + } catch (RemoteException e) { + // Should never happen! + } + return null; + } + + @Override public void deletePackage(String packageName, IPackageDeleteObserver observer, int flags) { try { mPM.deletePackage(packageName, observer, flags); diff --git a/core/java/android/content/pm/IPackageManager.aidl b/core/java/android/content/pm/IPackageManager.aidl index d3f6f3c..c199619 100644 --- a/core/java/android/content/pm/IPackageManager.aidl +++ b/core/java/android/content/pm/IPackageManager.aidl @@ -139,8 +139,11 @@ interface IPackageManager { * @param observer a callback to use to notify when the package installation in finished. * @param flags - possible values: {@link #FORWARD_LOCK_PACKAGE}, * {@link #REPLACE_EXISITING_PACKAGE} + * @param installerPackageName Optional package name of the application that is performing the + * installation. This identifies which market the package came from. */ - void installPackage(in Uri packageURI, IPackageInstallObserver observer, int flags); + void installPackage(in Uri packageURI, IPackageInstallObserver observer, int flags, + in String installerPackageName); /** * Delete a package. @@ -151,6 +154,8 @@ interface IPackageManager { */ void deletePackage(in String packageName, IPackageDeleteObserver observer, int flags); + String getInstallerPackageName(in String packageName); + void addPackageToPreferred(String packageName); void removePackageFromPreferred(String packageName); diff --git a/core/java/android/content/pm/PackageManager.java b/core/java/android/content/pm/PackageManager.java index e2f0ce4..3695516 100644 --- a/core/java/android/content/pm/PackageManager.java +++ b/core/java/android/content/pm/PackageManager.java @@ -1354,8 +1354,35 @@ public abstract class PackageManager { * * @see #installPackage(android.net.Uri) */ + public void installPackage( + Uri packageURI, IPackageInstallObserver observer, int flags) { + installPackage(packageURI, observer, flags, null); + } + + /** + * 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, if 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. observer may be null to indicate that no callback is desired. + * @param flags - possible values: {@link #FORWARD_LOCK_PACKAGE}, + * {@link #REPLACE_EXISTING_PACKAGE} + * @param installerPackageName Optional package name of the application that is performing the + * installation. This identifies which market the package came from. + * + * @see #installPackage(android.net.Uri) + * + * @hide + */ public abstract void installPackage( - Uri packageURI, IPackageInstallObserver observer, int flags); + Uri packageURI, IPackageInstallObserver observer, int flags, + String installerPackageName); /** * Attempts to delete a package. Since this may take a little while, the result will @@ -1374,6 +1401,17 @@ public abstract class PackageManager { */ public abstract void deletePackage( String packageName, IPackageDeleteObserver observer, int flags); + + /** + * Retrieve the package name of the application that installed a package. This identifies + * which market the package came from. + * + * @param packageName The name of the package to query + * + * @hide + */ + public abstract String getInstallerPackageName(String packageName); + /** * Attempts to clear the user data directory of an application. * Since this may take a little while, the result will @@ -1483,7 +1521,7 @@ public abstract class PackageManager { * * @param packageURI The location of the package file to install * - * @see #installPackage(android.net.Uri, IPackageInstallObserver, int) + * @see #installPackage(android.net.Uri, IPackageInstallObserver, int, String) */ public void installPackage(Uri packageURI) { installPackage(packageURI, null, 0); -- cgit v1.1