From a7651690fd39529613d0289426953c8827d3c663 Mon Sep 17 00:00:00 2001 From: Jackal Guo Date: Tue, 13 Dec 2022 10:21:16 +0800 Subject: [PATCH] Revise the logic of computing user intervention (2/n) In computeUserActionRequirement(), it now honors update ownership enforcement. If the app being installed has the update owner, the user intervention will be required once the update isn't performed by the update owner. In this Cl, we also revise the PackageInstaler app to reflect the result to users. Bug: 244413073 Test: atest CtsPackageInstallTestCases:UpdateOwnershipEnforcementTest Change-Id: Ie620013a4adf861956226d34637dbd3a0dd9a3ea --- core/api/system-current.txt | 4 + .../android/content/pm/PackageInstaller.java | 69 ++++++++++++++++- .../PackageInstaller/res/values/strings.xml | 5 ++ .../PackageInstallerActivity.java | 48 +++++++++++- .../server/pm/PackageInstallerSession.java | 74 +++++++++++++++++-- 5 files changed, 188 insertions(+), 12 deletions(-) diff --git a/core/api/system-current.txt b/core/api/system-current.txt index 137751b175086..ceed59f794642 100644 --- a/core/api/system-current.txt +++ b/core/api/system-current.txt @@ -3592,6 +3592,9 @@ package android.content.pm { field public static final int LOCATION_DATA_APP = 0; // 0x0 field public static final int LOCATION_MEDIA_DATA = 2; // 0x2 field public static final int LOCATION_MEDIA_OBB = 1; // 0x1 + field public static final int REASON_CONFIRM_PACKAGE_CHANGE = 0; // 0x0 + field public static final int REASON_OWNERSHIP_CHANGED = 1; // 0x1 + field public static final int REASON_REMIND_OWNERSHIP = 2; // 0x2 } public static class PackageInstaller.InstallInfo { @@ -3621,6 +3624,7 @@ package android.content.pm { method public boolean getInstallAsFullApp(boolean); method public boolean getInstallAsInstantApp(boolean); method public boolean getInstallAsVirtualPreload(); + method public int getPendingUserActionReason(); method public boolean getRequestDowngrade(); method public int getRollbackDataPolicy(); method @NonNull public java.util.Set getWhitelistedRestrictedPermissions(); diff --git a/core/java/android/content/pm/PackageInstaller.java b/core/java/android/content/pm/PackageInstaller.java index 8f295633e01ab..812b5b3145828 100644 --- a/core/java/android/content/pm/PackageInstaller.java +++ b/core/java/android/content/pm/PackageInstaller.java @@ -544,6 +544,46 @@ public class PackageInstaller { @Retention(RetentionPolicy.SOURCE) @interface PackageSourceType{} + /** + * Indicate the user intervention is required when the installer attempts to commit the session. + * This is the default case. + * + * @hide + */ + @SystemApi + public static final int REASON_CONFIRM_PACKAGE_CHANGE = 0; + + /** + * Indicate the user intervention is required because the update ownership enforcement is + * enabled, and the update owner will change. + * + * @see PackageInstaller.SessionParams#setRequestUpdateOwnership + * @see InstallSourceInfo#getUpdateOwnerPackageName + * @hide + */ + @SystemApi + public static final int REASON_OWNERSHIP_CHANGED = 1; + + /** + * Indicate the user intervention is required because the update ownership enforcement is + * enabled, and remind the update owner will retain. + * + * @see PackageInstaller.SessionParams#setRequestUpdateOwnership + * @see InstallSourceInfo#getUpdateOwnerPackageName + * @hide + */ + @SystemApi + public static final int REASON_REMIND_OWNERSHIP = 2; + + /** @hide */ + @IntDef(prefix = { "REASON_" }, value = { + REASON_CONFIRM_PACKAGE_CHANGE, + REASON_OWNERSHIP_CHANGED, + REASON_REMIND_OWNERSHIP, + }) + @Retention(RetentionPolicy.SOURCE) + public @interface UserActionReason {} + /** Default set of checksums - includes all available checksums. * @see Session#requestChecksums */ private static final int DEFAULT_CHECKSUMS = @@ -2686,9 +2726,18 @@ public class PackageInstaller { * Android S ({@link android.os.Build.VERSION_CODES#S API 31}) * * - *
  • The installer is the {@link InstallSourceInfo#getInstallingPackageName() - * installer of record} of an existing version of the app (in other words, this install - * session is an app update) or the installer is updating itself.
  • + *
  • The installer is: + *
      + *
    • The {@link InstallSourceInfo#getUpdateOwnerPackageName() update owner} + * of an existing version of the app (in other words, this install session is + * an app update) if the update ownership enforcement is enabled.
    • + *
    • The {@link InstallSourceInfo#getInstallingPackageName() installer of + * record} of an existing version of the app (in other words, this install + * session is an app update) if the update ownership enforcement isn't + * enabled.
    • + *
    • Updating itself.
    • + *
    + *
  • > *
  • The installer declares the * {@link android.Manifest.permission#UPDATE_PACKAGES_WITHOUT_USER_ACTION * UPDATE_PACKAGES_WITHOUT_USER_ACTION} permission.
  • @@ -3025,6 +3074,9 @@ public class PackageInstaller { /** @hide */ public boolean keepApplicationEnabledSetting; + /** @hide */ + public int pendingUserActionReason; + /** {@hide} */ @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) public SessionInfo() { @@ -3079,6 +3131,7 @@ public class PackageInstaller { installerUid = source.readInt(); packageSource = source.readInt(); keepApplicationEnabledSetting = source.readBoolean(); + pendingUserActionReason = source.readInt(); } /** @@ -3633,6 +3686,15 @@ public class PackageInstaller { return (installFlags & PackageManager.INSTALL_REQUEST_UPDATE_OWNERSHIP) != 0; } + /** + * Return the reason for requiring the user action. + * @hide + */ + @SystemApi + public @UserActionReason int getPendingUserActionReason() { + return pendingUserActionReason; + } + @Override public int describeContents() { return 0; @@ -3683,6 +3745,7 @@ public class PackageInstaller { dest.writeInt(installerUid); dest.writeInt(packageSource); dest.writeBoolean(keepApplicationEnabledSetting); + dest.writeInt(pendingUserActionReason); } public static final Parcelable.Creator diff --git a/packages/PackageInstaller/res/values/strings.xml b/packages/PackageInstaller/res/values/strings.xml index b713c1420928b..cb2baa974b0c2 100644 --- a/packages/PackageInstaller/res/values/strings.xml +++ b/packages/PackageInstaller/res/values/strings.xml @@ -37,6 +37,11 @@ Do you want to install this app? Do you want to update this app? + + + Updates to this app are currently managed by %1$s.\n\nBy updating, you\'ll get future updates from %2$s instead. + + Updates to this app are currently managed by %1$s.\n\nDo you want to install this update from %2$s. App not installed.