summaryrefslogtreecommitdiff
path: root/core/java/android
diff options
context:
space:
mode:
authorTom Natan <tomnatan@google.com>2021-05-05 16:13:03 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2021-05-05 16:13:03 +0000
commit65654644bcdc01f0e1615f5b9c56ea29dd7e63a7 (patch)
treefefe7078476bd6bf067b21c3ae4ac4d9b48ed6f9 /core/java/android
parent8bf15714d552ef91b907c8d5e2ed62645d3c1f00 (diff)
parent9e9e1c4af500a7eb3449463ca688826356920871 (diff)
Merge "Add an API method for clearing compat overrides on release builds" am: b9680bac79 am: 9e9e1c4af5
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1688626 Change-Id: Ic1b9bb5b3f6cfba5192838020fc1b9770715f80a
Diffstat (limited to 'core/java/android')
-rw-r--r--core/java/android/app/compat/CompatChanges.java37
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();
+ }
+ }
}