From 2491ee93bbc745b616ad6bf1645a5b1c4bc15947 Mon Sep 17 00:00:00 2001 From: Patrick Baumann Date: Tue, 20 Apr 2021 14:01:30 -0700 Subject: [PATCH] Addresses setRequireUserAction API feedback This change modifies the signature of SessionParams#setRequireUserAction to take an int instead of a bool to match the return of SessionInfo#getRequireUserAction. Fixes: 184890429 Test: atest CtsSilentUpdateHostTestCases Change-Id: I5868f9dadaf10bda1524446d3ad755cb69be73a5 --- core/api/current.txt | 8 +- .../android/content/pm/PackageInstaller.java | 93 +++++++++++-------- core/res/AndroidManifest.xml | 2 +- .../server/pm/PackageInstallerSession.java | 4 +- 4 files changed, 60 insertions(+), 47 deletions(-) diff --git a/core/api/current.txt b/core/api/current.txt index 0639d7273dda7..9528e7380acc3 100644 --- a/core/api/current.txt +++ b/core/api/current.txt @@ -12415,9 +12415,6 @@ package android.content.pm { field public static final int STAGED_SESSION_NO_ERROR = 0; // 0x0 field public static final int STAGED_SESSION_UNKNOWN = 3; // 0x3 field public static final int STAGED_SESSION_VERIFICATION_FAILED = 1; // 0x1 - field public static final int USER_ACTION_NOT_REQUIRED = 2; // 0x2 - field public static final int USER_ACTION_REQUIRED = 1; // 0x1 - field public static final int USER_ACTION_UNSPECIFIED = 0; // 0x0 } public static class PackageInstaller.SessionParams implements android.os.Parcelable { @@ -12434,7 +12431,7 @@ package android.content.pm { method public void setOriginatingUid(int); method public void setOriginatingUri(@Nullable android.net.Uri); method public void setReferrerUri(@Nullable android.net.Uri); - method public void setRequireUserAction(boolean); + method public void setRequireUserAction(int); method public void setSize(long); method public void setWhitelistedRestrictedPermissions(@Nullable java.util.Set); method public void writeToParcel(android.os.Parcel, int); @@ -12442,6 +12439,9 @@ package android.content.pm { field public static final int MODE_FULL_INSTALL = 1; // 0x1 field public static final int MODE_INHERIT_EXISTING = 2; // 0x2 field @NonNull public static final java.util.Set RESTRICTED_PERMISSIONS_ALL; + field public static final int USER_ACTION_NOT_REQUIRED = 2; // 0x2 + field public static final int USER_ACTION_REQUIRED = 1; // 0x1 + field public static final int USER_ACTION_UNSPECIFIED = 0; // 0x0 } public class PackageItemInfo { diff --git a/core/java/android/content/pm/PackageInstaller.java b/core/java/android/content/pm/PackageInstaller.java index 5157e08deb346..f54dbf9cab4c2 100644 --- a/core/java/android/content/pm/PackageInstaller.java +++ b/core/java/android/content/pm/PackageInstaller.java @@ -1529,6 +1529,33 @@ public class PackageInstaller { */ public static final int MAX_PACKAGE_NAME_LENGTH = 255; + /** @hide */ + @IntDef(prefix = {"USER_ACTION_"}, value = { + USER_ACTION_UNSPECIFIED, + USER_ACTION_REQUIRED, + USER_ACTION_NOT_REQUIRED + }) + @Retention(RetentionPolicy.SOURCE) + public @interface UserActionRequirement {} + + /** + * The installer did not call {@link SessionParams#setRequireUserAction(int)} to + * specify whether user action should be required for the install. + */ + public static final int USER_ACTION_UNSPECIFIED = 0; + + /** + * The installer called {@link SessionParams#setRequireUserAction(int)} with + * {@code true} to require user action for the install to complete. + */ + public static final int USER_ACTION_REQUIRED = 1; + + /** + * The installer called {@link SessionParams#setRequireUserAction(int)} with + * {@code false} to request that user action not be required for this install. + */ + public static final int USER_ACTION_NOT_REQUIRED = 2; + /** {@hide} */ @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) public int mode = MODE_INVALID; @@ -1593,7 +1620,7 @@ public class PackageInstaller { /** {@hide} */ public boolean forceQueryableOverride; /** {@hide} */ - public int requireUserAction = SessionInfo.USER_ACTION_UNSPECIFIED; + public int requireUserAction = USER_ACTION_UNSPECIFIED; /** * Construct parameters for a new package install session. @@ -2074,11 +2101,14 @@ public class PackageInstaller { * Optionally indicate whether user action should be required when the session is * committed. *

- * Defaults to {@code true} for installers using the + * Defaults to {@link #USER_ACTION_UNSPECIFIED} unless otherwise set. When unspecified for + * installers using the * {@link android.Manifest.permission#REQUEST_INSTALL_PACKAGES android.permission - * #REQUEST_INSTALL_PACKAGES} permission, and {@code false} otherwise. When {@code true}, - * installers will receive a {@link #STATUS_PENDING_USER_ACTION} callback once the - * session is committed, indicating that user action is required for the install to proceed. + * #REQUEST_INSTALL_PACKAGES} permission will behave as if set to + * {@link #USER_ACTION_REQUIRED}, and {@link #USER_ACTION_NOT_REQUIRED} otherwise. + * When {@code requireUserAction} is set to {@link #USER_ACTION_REQUIRED}, installers will + * receive a {@link #STATUS_PENDING_USER_ACTION} callback once the session is committed, + * indicating that user action is required for the install to proceed. *

* For installers that have been granted the * {@link android.Manifest.permission#REQUEST_INSTALL_PACKAGES android.permission @@ -2086,7 +2116,7 @@ public class PackageInstaller { * the following conditions are met: * *

    - *
  • {@code requireUserAction} is set to {@code false}.
  • + *
  • {@code requireUserAction} is set to {@link #USER_ACTION_NOT_REQUIRED}.
  • *
  • The app being installed targets {@link android.os.Build.VERSION_CODES#Q API 29} * or higher.
  • *
  • The installer is the {@link InstallSourceInfo#getInstallingPackageName() @@ -2102,10 +2132,17 @@ public class PackageInstaller { * * @param requireUserAction whether user action should be required. */ - public void setRequireUserAction(boolean requireUserAction) { - this.requireUserAction = requireUserAction - ? SessionInfo.USER_ACTION_REQUIRED - : SessionInfo.USER_ACTION_NOT_REQUIRED; + public void setRequireUserAction( + @SessionParams.UserActionRequirement int requireUserAction) { + if (requireUserAction != USER_ACTION_UNSPECIFIED + && requireUserAction != USER_ACTION_REQUIRED + && requireUserAction != USER_ACTION_NOT_REQUIRED) { + throw new IllegalArgumentException("requireUserAction set as invalid value of " + + requireUserAction + ", but must be one of [" + + "USER_ACTION_UNSPECIFIED, USER_ACTION_REQUIRED, USER_ACTION_NOT_REQUIRED" + + "]"); + } + this.requireUserAction = requireUserAction; } /** @@ -2247,36 +2284,11 @@ public class PackageInstaller { */ public static final int STAGED_SESSION_CONFLICT = 4; - /** @hide */ - @IntDef(prefix = {"USER_ACTION"}, value = { - USER_ACTION_UNSPECIFIED, - USER_ACTION_REQUIRED, - USER_ACTION_NOT_REQUIRED - }) - @Retention(RetentionPolicy.SOURCE) - public @interface UserActionRequirement {} - - /** - * The installer did not call {@link SessionParams#setRequireUserAction(boolean)} to - * specify whether user action should be required for the install. - */ - public static final int USER_ACTION_UNSPECIFIED = 0; - /** - * The installer called {@link SessionParams#setRequireUserAction(boolean)} with - * {@code true} to require user action for the install to complete. - */ - public static final int USER_ACTION_REQUIRED = 1; - /** - * The installer called {@link SessionParams#setRequireUserAction(boolean)} with - * {@code false} to request that user action not be required for this install. - */ - public static final int USER_ACTION_NOT_REQUIRED = 2; - private static String userActionToString(int requireUserAction) { switch(requireUserAction) { - case SessionInfo.USER_ACTION_REQUIRED: + case SessionParams.USER_ACTION_REQUIRED: return "REQUIRED"; - case SessionInfo.USER_ACTION_NOT_REQUIRED: + case SessionParams.USER_ACTION_NOT_REQUIRED: return "NOT_REQUIRED"; default: return "UNSPECIFIED"; @@ -2933,10 +2945,11 @@ public class PackageInstaller { * Note: a return value of {@code USER_ACTION_NOT_REQUIRED} does not guarantee that the * install will not result in user action. * - * @return {@link #USER_ACTION_NOT_REQUIRED}, {@link #USER_ACTION_REQUIRED} or - * {@link #USER_ACTION_UNSPECIFIED} + * @return {@link SessionParams#USER_ACTION_NOT_REQUIRED}, + * {@link SessionParams#USER_ACTION_REQUIRED} or + * {@link SessionParams#USER_ACTION_UNSPECIFIED} */ - @UserActionRequirement + @SessionParams.UserActionRequirement public int getRequireUserAction() { return requireUserAction; } diff --git a/core/res/AndroidManifest.xml b/core/res/AndroidManifest.xml index f9945c70efd71..81f534414de73 100644 --- a/core/res/AndroidManifest.xml +++ b/core/res/AndroidManifest.xml @@ -5735,7 +5735,7 @@ android:protectionLevel="signature|recents" /> diff --git a/services/core/java/com/android/server/pm/PackageInstallerSession.java b/services/core/java/com/android/server/pm/PackageInstallerSession.java index b6a65ddb5ec27..ee41f3f5d9a08 100644 --- a/services/core/java/com/android/server/pm/PackageInstallerSession.java +++ b/services/core/java/com/android/server/pm/PackageInstallerSession.java @@ -928,7 +928,7 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub { final boolean forcePermissionPrompt = (params.installFlags & PackageManager.INSTALL_FORCE_PERMISSION_PROMPT) != 0 - || params.requireUserAction == SessionInfo.USER_ACTION_REQUIRED; + || params.requireUserAction == SessionParams.USER_ACTION_REQUIRED; if (forcePermissionPrompt) { return USER_ACTION_REQUIRED; } @@ -977,7 +977,7 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub { return USER_ACTION_REQUIRED; } - if (params.requireUserAction == SessionInfo.USER_ACTION_NOT_REQUIRED + if (params.requireUserAction == SessionParams.USER_ACTION_NOT_REQUIRED && isUpdateWithoutUserActionPermissionGranted && (isInstallerOfRecord || isSelfUpdate)) { return USER_ACTION_PENDING_APK_PARSING;