diff options
author | Jeff Sharkey <jsharkey@android.com> | 2014-08-07 17:31:53 -0700 |
---|---|---|
committer | Jeff Sharkey <jsharkey@google.com> | 2014-08-08 00:45:20 +0000 |
commit | f06009542390472872da986486d385001e91a2a7 (patch) | |
tree | f1006709381288cf2271f1e7eac9ee655ea1c6c5 /core/java/android/content | |
parent | cd5e3f95bfcc6039aa048b7f3141f265de02d114 (diff) | |
download | frameworks_base-f06009542390472872da986486d385001e91a2a7.zip frameworks_base-f06009542390472872da986486d385001e91a2a7.tar.gz frameworks_base-f06009542390472872da986486d385001e91a2a7.tar.bz2 |
Logic to confirm uninstalls.
Prompt user for confirmation when caller doesn't have DELETE_PACKAGES
permission. Also extend uninstall events to return failure codes.
Bug: 16515814
Change-Id: I15b52190ff02dbeaaf038b92364264f64c57ba89
Diffstat (limited to 'core/java/android/content')
-rw-r--r-- | core/java/android/content/pm/PackageInstaller.java | 36 | ||||
-rw-r--r-- | core/java/android/content/pm/PackageManager.java | 29 |
2 files changed, 53 insertions, 12 deletions
diff --git a/core/java/android/content/pm/PackageInstaller.java b/core/java/android/content/pm/PackageInstaller.java index 525142b..d70e22c 100644 --- a/core/java/android/content/pm/PackageInstaller.java +++ b/core/java/android/content/pm/PackageInstaller.java @@ -92,6 +92,9 @@ public class PackageInstaller { */ public static final String EXTRA_SESSION_ID = "android.content.pm.extra.SESSION_ID"; + /** {@hide} */ + public static final String EXTRA_CALLBACK = "android.content.pm.extra.CALLBACK"; + private final PackageManager mPm; private final IPackageInstaller mInstaller; private final int mUserId; @@ -554,6 +557,26 @@ public class PackageInstaller { */ public static abstract class UninstallCallback { /** + * Generic unknown failure. The system will always try to provide a more + * specific failure reason, but in some rare cases this may be + * delivered. + */ + public static final int FAILURE_UNKNOWN = 0; + + /** + * This uninstall was blocked. The package may be required for core + * system operation, or the user may be restricted. Attempting to + * uninstall again will have the same result. + */ + public static final int FAILURE_BLOCKED = 1; + + /** + * This uninstall was actively aborted. For example, the user declined + * to uninstall. You may try to uninstall again. + */ + public static final int FAILURE_ABORTED = 2; + + /** * User action is required to proceed. You can start the given intent * activity to involve the user and continue. * <p> @@ -564,7 +587,7 @@ public class PackageInstaller { public abstract void onUserActionRequired(Intent intent); public abstract void onSuccess(); - public abstract void onFailure(String msg); + public abstract void onFailure(int failureReason, String msg, Bundle extras); } /** {@hide} */ @@ -585,8 +608,9 @@ public class PackageInstaller { if (returnCode == PackageManager.DELETE_SUCCEEDED) { target.onSuccess(); } else { + final int failureReason = PackageManager.deleteStatusToFailureReason(returnCode); msg = PackageManager.deleteStatusToString(returnCode) + ": " + msg; - target.onFailure(msg); + target.onFailure(failureReason, msg, null); } } } @@ -639,13 +663,13 @@ public class PackageInstaller { public static final int FAILURE_INCOMPATIBLE = 4; /** - * This install session failed because it was rejected. For example, the - * user declined requested permissions, or a package verifier rejected - * the session. + * This install session failed because it was actively aborted. For + * example, the user declined requested permissions, or a verifier + * rejected the session. * * @see PackageManager#VERIFICATION_REJECT */ - public static final int FAILURE_REJECTED = 5; + public static final int FAILURE_ABORTED = 5; public static final String EXTRA_PACKAGE_NAME = "android.content.pm.extra.PACKAGE_NAME"; diff --git a/core/java/android/content/pm/PackageManager.java b/core/java/android/content/pm/PackageManager.java index d5604cb..7dad367 100644 --- a/core/java/android/content/pm/PackageManager.java +++ b/core/java/android/content/pm/PackageManager.java @@ -28,6 +28,7 @@ import android.content.Intent; import android.content.IntentFilter; import android.content.IntentSender; import android.content.pm.PackageInstaller.CommitCallback; +import android.content.pm.PackageInstaller.UninstallCallback; import android.content.pm.PackageParser.PackageParserException; import android.content.res.Resources; import android.content.res.XmlResourceParser; @@ -771,7 +772,7 @@ public abstract class PackageManager { public static final int NO_NATIVE_LIBRARIES = -114; /** {@hide} */ - public static final int INSTALL_FAILED_REJECTED = -115; + public static final int INSTALL_FAILED_ABORTED = -115; /** * Flag parameter for {@link #deletePackage} to indicate that you don't want to delete the @@ -845,7 +846,10 @@ public abstract class PackageManager { * * @hide */ - public static final int DELETE_FAILED_OWNER_BLOCKED= -4; + public static final int DELETE_FAILED_OWNER_BLOCKED = -4; + + /** {@hide} */ + public static final int DELETE_FAILED_ABORTED = -5; /** * Return code that is passed to the {@link IPackageMoveObserver} by @@ -3833,7 +3837,7 @@ public abstract class PackageManager { case INSTALL_FAILED_USER_RESTRICTED: return "INSTALL_FAILED_USER_RESTRICTED"; case INSTALL_FAILED_DUPLICATE_PERMISSION: return "INSTALL_FAILED_DUPLICATE_PERMISSION"; case INSTALL_FAILED_NO_MATCHING_ABIS: return "INSTALL_FAILED_NO_MATCHING_ABIS"; - case INSTALL_FAILED_REJECTED: return "INSTALL_FAILED_REJECTED"; + case INSTALL_FAILED_ABORTED: return "INSTALL_FAILED_ABORTED"; default: return Integer.toString(status); } } @@ -3861,8 +3865,8 @@ public abstract class PackageManager { case INSTALL_FAILED_CONTAINER_ERROR: return CommitCallback.FAILURE_STORAGE; case INSTALL_FAILED_INVALID_INSTALL_LOCATION: return CommitCallback.FAILURE_STORAGE; case INSTALL_FAILED_MEDIA_UNAVAILABLE: return CommitCallback.FAILURE_STORAGE; - case INSTALL_FAILED_VERIFICATION_TIMEOUT: return CommitCallback.FAILURE_REJECTED; - case INSTALL_FAILED_VERIFICATION_FAILURE: return CommitCallback.FAILURE_REJECTED; + case INSTALL_FAILED_VERIFICATION_TIMEOUT: return CommitCallback.FAILURE_ABORTED; + case INSTALL_FAILED_VERIFICATION_FAILURE: return CommitCallback.FAILURE_ABORTED; case INSTALL_FAILED_PACKAGE_CHANGED: return CommitCallback.FAILURE_INVALID; case INSTALL_FAILED_UID_CHANGED: return CommitCallback.FAILURE_INVALID; case INSTALL_FAILED_VERSION_DOWNGRADE: return CommitCallback.FAILURE_INVALID; @@ -3880,7 +3884,7 @@ public abstract class PackageManager { case INSTALL_FAILED_USER_RESTRICTED: return CommitCallback.FAILURE_INCOMPATIBLE; case INSTALL_FAILED_DUPLICATE_PERMISSION: return CommitCallback.FAILURE_CONFLICT; case INSTALL_FAILED_NO_MATCHING_ABIS: return CommitCallback.FAILURE_INCOMPATIBLE; - case INSTALL_FAILED_REJECTED: return CommitCallback.FAILURE_REJECTED; + case INSTALL_FAILED_ABORTED: return CommitCallback.FAILURE_ABORTED; default: return CommitCallback.FAILURE_UNKNOWN; } } @@ -3893,7 +3897,20 @@ public abstract class PackageManager { case DELETE_FAILED_DEVICE_POLICY_MANAGER: return "DELETE_FAILED_DEVICE_POLICY_MANAGER"; case DELETE_FAILED_USER_RESTRICTED: return "DELETE_FAILED_USER_RESTRICTED"; case DELETE_FAILED_OWNER_BLOCKED: return "DELETE_FAILED_OWNER_BLOCKED"; + case DELETE_FAILED_ABORTED: return "DELETE_FAILED_ABORTED"; default: return Integer.toString(status); } } + + /** {@hide} */ + public static int deleteStatusToFailureReason(int status) { + switch (status) { + case DELETE_FAILED_INTERNAL_ERROR: return UninstallCallback.FAILURE_UNKNOWN; + case DELETE_FAILED_DEVICE_POLICY_MANAGER: return UninstallCallback.FAILURE_BLOCKED; + case DELETE_FAILED_USER_RESTRICTED: return UninstallCallback.FAILURE_BLOCKED; + case DELETE_FAILED_OWNER_BLOCKED: return UninstallCallback.FAILURE_BLOCKED; + case DELETE_FAILED_ABORTED: return UninstallCallback.FAILURE_ABORTED; + default: return UninstallCallback.FAILURE_UNKNOWN; + } + } } |