diff options
| author | Adam Bookatz <bookatz@google.com> | 2020-03-19 18:37:36 -0700 |
|---|---|---|
| committer | Adam Bookatz <bookatz@google.com> | 2020-03-28 00:19:37 +0000 |
| commit | 1efd27cde359a1ff71d88519dbbdc2f7f1f1d1a4 (patch) | |
| tree | 326866bb2e7abd030eb06e9a0bf75b4560c6b41d /core/java/android | |
| parent | f825133d014b0b83e3efaa04d813d7c80c4ec892 (diff) | |
UserSystemPackageInstaller only (un)installs when appropriate
The UserSystemPackageInstaller (USPI) uninstalls system
packages that are not needed, depending on the user type.
When that determination changes (or the feature is disabled)
it can also re-install those packages.
This cl specifies when it is appropriate for USPI to actually
perform the (un)installation.
1.
Introduces uninstallReason: records the reason why a package
was uninstalled from a given user. Right now, the only values
are UNKNOWN and USER_TYPE. The latter indicates that the USPI
system uninstalled the package. If the USPI whitelist changes
(or the USPI feature is disabled), uninstalled packages will
only be installed by USPI if the uninstallReason was USER_TYPE.
Any further uninstalls (e.g. by ManagedProvisioning) will reset
the uninstallReason to UNKNOWN, so USPI will no longer install
such packages in the future.
This prevents USPI from reinstalling system packages that other
mechanisms (such as ManagedProvisioning) uninstalled.
2.
USPI will uninstall a system package if it is blacklisted, but
only if that system package is new, i.e in two circumstances:
a. on first boot
b. on an OTA where the package was not present prior to the OTA
Bug: 143200798
Test: atest UserSystemPackageInstallerTest
Test: Confirmed (un)installations during manually simulated OTAs
Change-Id: Ia0714d1faa8f7c79082f2cc93a92ae36b9a4c918
Merged-In: Ia0714d1faa8f7c79082f2cc93a92ae36b9a4c918
Diffstat (limited to 'core/java/android')
| -rw-r--r-- | core/java/android/content/pm/PackageManager.java | 21 | ||||
| -rw-r--r-- | core/java/android/content/pm/PackageUserState.java | 7 |
2 files changed, 28 insertions, 0 deletions
diff --git a/core/java/android/content/pm/PackageManager.java b/core/java/android/content/pm/PackageManager.java index 370469ebe840..f48d78ac9cc3 100644 --- a/core/java/android/content/pm/PackageManager.java +++ b/core/java/android/content/pm/PackageManager.java @@ -1031,6 +1031,27 @@ public abstract class PackageManager { */ public static final int INSTALL_REASON_ROLLBACK = 5; + /** @hide */ + @IntDef(prefix = { "UNINSTALL_REASON_" }, value = { + UNINSTALL_REASON_UNKNOWN, + UNINSTALL_REASON_USER_TYPE, + }) + @Retention(RetentionPolicy.SOURCE) + public @interface UninstallReason {} + + /** + * Code indicating that the reason for uninstalling this package is unknown. + * @hide + */ + public static final int UNINSTALL_REASON_UNKNOWN = 0; + + /** + * Code indicating that this package was uninstalled due to the type of user. + * See UserSystemPackageInstaller + * @hide + */ + public static final int UNINSTALL_REASON_USER_TYPE = 1; + /** * @hide */ diff --git a/core/java/android/content/pm/PackageUserState.java b/core/java/android/content/pm/PackageUserState.java index 30cf4e76ba04..61b1553e28a8 100644 --- a/core/java/android/content/pm/PackageUserState.java +++ b/core/java/android/content/pm/PackageUserState.java @@ -74,6 +74,7 @@ public class PackageUserState { public int appLinkGeneration; public int categoryHint = ApplicationInfo.CATEGORY_UNDEFINED; public int installReason; + public @PackageManager.UninstallReason int uninstallReason; public String harmfulAppWarning; public ArraySet<String> disabledComponents; @@ -92,6 +93,7 @@ public class PackageUserState { domainVerificationStatus = PackageManager.INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_UNDEFINED; installReason = PackageManager.INSTALL_REASON_UNKNOWN; + uninstallReason = PackageManager.UNINSTALL_REASON_UNKNOWN; } @VisibleForTesting @@ -112,6 +114,7 @@ public class PackageUserState { appLinkGeneration = o.appLinkGeneration; categoryHint = o.categoryHint; installReason = o.installReason; + uninstallReason = o.uninstallReason; disabledComponents = ArrayUtils.cloneOrNull(o.disabledComponents); enabledComponents = ArrayUtils.cloneOrNull(o.enabledComponents); overlayPaths = @@ -353,6 +356,9 @@ public class PackageUserState { if (installReason != oldState.installReason) { return false; } + if (uninstallReason != oldState.uninstallReason) { + return false; + } if ((disabledComponents == null && oldState.disabledComponents != null) || (disabledComponents != null && oldState.disabledComponents == null)) { return false; @@ -407,6 +413,7 @@ public class PackageUserState { hashCode = 31 * hashCode + appLinkGeneration; hashCode = 31 * hashCode + categoryHint; hashCode = 31 * hashCode + installReason; + hashCode = 31 * hashCode + uninstallReason; hashCode = 31 * hashCode + Objects.hashCode(disabledComponents); hashCode = 31 * hashCode + Objects.hashCode(enabledComponents); hashCode = 31 * hashCode + Objects.hashCode(harmfulAppWarning); |
