diff options
| author | tomnatan <tomnatan@google.com> | 2021-04-27 15:45:13 +0000 |
|---|---|---|
| committer | tomnatan <tomnatan@google.com> | 2021-05-05 07:10:41 +0000 |
| commit | 2697018f703ffd52f601aa7dcd01efd0d4dd28f8 (patch) | |
| tree | 3858049449596f9c22f899a3dfcc55989b85cf55 /core/java/android | |
| parent | bef2f5be9465c3441750f38f0c8b08256f97a0d4 (diff) | |
Add an API method for clearing compat overrides on release builds
This will be useful when we want to clear overrides for apps that are no longer needed regardless of the version that is installed on device, e.g., when an app is being uninstalled, when we want to rollback an override, or when we deprecate a change-id.
In addition, rename CompatChanges#setPackageOverride to
addPackageOverrides.
Bug: 183183372
Test: atest FrameworksServicesTests:CompatConfigTest
Test: atest FrameworksServicesTests:PlatformCompatTest
Change-Id: Iff416c8b4c88b5eddc9e21c73219198d23266fa1
Diffstat (limited to 'core/java/android')
| -rw-r--r-- | core/java/android/app/compat/CompatChanges.java | 37 |
1 files changed, 34 insertions, 3 deletions
diff --git a/core/java/android/app/compat/CompatChanges.java b/core/java/android/app/compat/CompatChanges.java index 74e1ece3fa89..8ca43c4a8e70 100644 --- a/core/java/android/app/compat/CompatChanges.java +++ b/core/java/android/app/compat/CompatChanges.java @@ -26,9 +26,11 @@ import android.os.ServiceManager; import android.os.UserHandle; import com.android.internal.compat.CompatibilityOverrideConfig; +import com.android.internal.compat.CompatibilityOverridesToRemoveConfig; import com.android.internal.compat.IPlatformCompat; import java.util.Map; +import java.util.Set; /** * CompatChanges APIs - to be used by platform code only (including mainline @@ -98,15 +100,19 @@ public final class CompatChanges { } /** - * Set an app compat override for a given package. This will check whether the caller is allowed + * Adds app compat overrides for a given package. This will check whether the caller is allowed * to perform this operation on the given apk and build. Only the installer package is allowed * to set overrides on a non-debuggable final build and a non-test apk. * + * <p>Note that calling this method doesn't remove previously added overrides for the given + * package if their change ID isn't in the given map, only replaces those that have the same + * change ID. + * * @param packageName The package name of the app in question. - * @param overrides A map from changeId to the override applied for this change id. + * @param overrides A map from change ID to the override applied for this change ID. */ @RequiresPermission(android.Manifest.permission.OVERRIDE_COMPAT_CHANGE_CONFIG_ON_RELEASE_BUILD) - public static void setPackageOverride(@NonNull String packageName, + public static void addPackageOverrides(@NonNull String packageName, @NonNull Map<Long, PackageOverride> overrides) { IPlatformCompat platformCompat = IPlatformCompat.Stub.asInterface( ServiceManager.getService(Context.PLATFORM_COMPAT_SERVICE)); @@ -117,4 +123,29 @@ public final class CompatChanges { e.rethrowFromSystemServer(); } } + + /** + * Removes app compat overrides for a given package. This will check whether the caller is + * allowed to perform this operation on the given apk and build. Only the installer package is + * allowed to clear overrides on a non-debuggable final build and a non-test apk. + * + * <p>Note that calling this method with an empty set is a no-op and no overrides will be + * removed for the given package. + * + * @param packageName The package name of the app in question. + * @param overridesToRemove A set of change IDs for which to remove overrides. + */ + @RequiresPermission(android.Manifest.permission.OVERRIDE_COMPAT_CHANGE_CONFIG_ON_RELEASE_BUILD) + public static void removePackageOverrides(@NonNull String packageName, + @NonNull Set<Long> overridesToRemove) { + IPlatformCompat platformCompat = IPlatformCompat.Stub.asInterface( + ServiceManager.getService(Context.PLATFORM_COMPAT_SERVICE)); + CompatibilityOverridesToRemoveConfig config = new CompatibilityOverridesToRemoveConfig( + overridesToRemove); + try { + platformCompat.removeOverridesOnReleaseBuilds(config, packageName); + } catch (RemoteException e) { + e.rethrowFromSystemServer(); + } + } } |
