diff options
author | Christopher Tate <ctate@google.com> | 2014-03-24 16:25:51 -0700 |
---|---|---|
committer | Christopher Tate <ctate@google.com> | 2014-03-25 19:28:54 -0700 |
commit | ab8a501f255b272af887acb0e66eb71cdf24c755 (patch) | |
tree | 4428aa0f60d4a2a309e8882d27fab9c5b20ad5c3 /cmds | |
parent | 48a5dbd3cc5dd8a919983455757dc4c7b82500ab (diff) | |
download | frameworks_base-ab8a501f255b272af887acb0e66eb71cdf24c755.zip frameworks_base-ab8a501f255b272af887acb0e66eb71cdf24c755.tar.gz frameworks_base-ab8a501f255b272af887acb0e66eb71cdf24c755.tar.bz2 |
Expand install observer semantics
...and now fail conservatively when two apps both attempt to define
the same permission.
We also finally have a (hidden) interface class for observing package
installation so that we can now rev the interface without breaking
existing callers.
Bug 13551375
Change-Id: I3a286d024a30e812ee4b098f345401df3c00e178
Diffstat (limited to 'cmds')
-rw-r--r-- | cmds/pm/src/com/android/commands/pm/Pm.java | 32 |
1 files changed, 25 insertions, 7 deletions
diff --git a/cmds/pm/src/com/android/commands/pm/Pm.java b/cmds/pm/src/com/android/commands/pm/Pm.java index d513a10..f92bed2 100644 --- a/cmds/pm/src/com/android/commands/pm/Pm.java +++ b/cmds/pm/src/com/android/commands/pm/Pm.java @@ -25,7 +25,7 @@ import android.content.pm.ContainerEncryptionParams; import android.content.pm.FeatureInfo; import android.content.pm.IPackageDataObserver; import android.content.pm.IPackageDeleteObserver; -import android.content.pm.IPackageInstallObserver; +import android.content.pm.IPackageInstallObserver2; import android.content.pm.IPackageManager; import android.content.pm.InstrumentationInfo; import android.content.pm.PackageInfo; @@ -39,6 +39,7 @@ import android.content.pm.VerificationParams; import android.content.res.AssetManager; import android.content.res.Resources; import android.net.Uri; +import android.os.Bundle; import android.os.IUserManager; import android.os.Process; import android.os.RemoteException; @@ -700,14 +701,21 @@ public final class Pm { ActivityManager.dumpPackageStateStatic(FileDescriptor.out, pkg); } - class PackageInstallObserver extends IPackageInstallObserver.Stub { + class PackageInstallObserver extends IPackageInstallObserver2.Stub { boolean finished; int result; + String extraPermission; + String extraPackage; - public void packageInstalled(String name, int status) { + @Override + public void packageInstalled(String name, Bundle extras, int status) { synchronized( this) { finished = true; result = status; + if (status == PackageManager.INSTALL_FAILED_DUPLICATE_PERMISSION) { + extraPermission = extras.getString(PackageManager.EXTRA_EXISTING_PERMISSION); + extraPackage = extras.getString(PackageManager.EXTRA_EXISTING_PACKAGE); + } notifyAll(); } } @@ -717,7 +725,8 @@ public final class Pm { * Converts a failure code into a string by using reflection to find a matching constant * in PackageManager. */ - private String installFailureToString(int result) { + private String installFailureToString(PackageInstallObserver obs) { + final int result = obs.result; Field[] fields = PackageManager.class.getFields(); for (Field f: fields) { if (f.getType() == int.class) { @@ -732,7 +741,16 @@ public final class Pm { // get the int value and compare it to result. try { if (result == f.getInt(null)) { - return fieldName; + StringBuilder sb = new StringBuilder(64); + sb.append(fieldName); + if (obs.extraPermission != null) { + sb.append(" perm="); + sb.append(obs.extraPermission); + } + if (obs.extraPackage != null) { + sb.append(" pkg=" + obs.extraPackage); + } + return sb.toString(); } } catch (IllegalAccessException e) { // this shouldn't happen since we only look for public static fields. @@ -956,7 +974,7 @@ public final class Pm { VerificationParams verificationParams = new VerificationParams(verificationURI, originatingURI, referrerURI, VerificationParams.NO_UID, null); - mPm.installPackageWithVerificationAndEncryption(apkURI, obs, installFlags, + mPm.installPackageWithVerificationAndEncryptionEtc(apkURI, null, obs, installFlags, installerPackageName, verificationParams, encryptionParams); synchronized (obs) { @@ -970,7 +988,7 @@ public final class Pm { System.out.println("Success"); } else { System.err.println("Failure [" - + installFailureToString(obs.result) + + installFailureToString(obs) + "]"); } } |