summaryrefslogtreecommitdiff
path: root/core/java
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
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')
-rw-r--r--core/java/android/app/compat/CompatChanges.java37
-rw-r--r--core/java/com/android/internal/compat/CompatibilityOverridesToRemoveConfig.aidl19
-rw-r--r--core/java/com/android/internal/compat/CompatibilityOverridesToRemoveConfig.java72
-rw-r--r--core/java/com/android/internal/compat/IPlatformCompat.aidl22
4 files changed, 147 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();
+ }
+ }
}
diff --git a/core/java/com/android/internal/compat/CompatibilityOverridesToRemoveConfig.aidl b/core/java/com/android/internal/compat/CompatibilityOverridesToRemoveConfig.aidl
new file mode 100644
index 000000000000..441e553e4d88
--- /dev/null
+++ b/core/java/com/android/internal/compat/CompatibilityOverridesToRemoveConfig.aidl
@@ -0,0 +1,19 @@
+/*
+ * Copyright (C) 2021 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.internal.compat;
+
+parcelable CompatibilityOverridesToRemoveConfig;
diff --git a/core/java/com/android/internal/compat/CompatibilityOverridesToRemoveConfig.java b/core/java/com/android/internal/compat/CompatibilityOverridesToRemoveConfig.java
new file mode 100644
index 000000000000..642f79ca7afa
--- /dev/null
+++ b/core/java/com/android/internal/compat/CompatibilityOverridesToRemoveConfig.java
@@ -0,0 +1,72 @@
+/*
+ * Copyright (C) 2021 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.internal.compat;
+
+
+import android.os.Parcel;
+import android.os.Parcelable;
+
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * Parcelable containing compat config change IDs for which to remove overrides for a given
+ * application.
+ * @hide
+ */
+public final class CompatibilityOverridesToRemoveConfig implements Parcelable {
+ public final Set<Long> changeIds;
+
+ public CompatibilityOverridesToRemoveConfig(Set<Long> changeIds) {
+ this.changeIds = changeIds;
+ }
+
+ private CompatibilityOverridesToRemoveConfig(Parcel in) {
+ int keyCount = in.readInt();
+ changeIds = new HashSet<>();
+ for (int i = 0; i < keyCount; i++) {
+ changeIds.add(in.readLong());
+ }
+ }
+
+ @Override
+ public int describeContents() {
+ return 0;
+ }
+
+ @Override
+ public void writeToParcel(Parcel dest, int flags) {
+ dest.writeInt(changeIds.size());
+ for (Long changeId : changeIds) {
+ dest.writeLong(changeId);
+ }
+ }
+
+ public static final Creator<CompatibilityOverridesToRemoveConfig> CREATOR =
+ new Creator<CompatibilityOverridesToRemoveConfig>() {
+
+ @Override
+ public CompatibilityOverridesToRemoveConfig createFromParcel(Parcel in) {
+ return new CompatibilityOverridesToRemoveConfig(in);
+ }
+
+ @Override
+ public CompatibilityOverridesToRemoveConfig[] newArray(int size) {
+ return new CompatibilityOverridesToRemoveConfig[size];
+ }
+ };
+}
diff --git a/core/java/com/android/internal/compat/IPlatformCompat.aidl b/core/java/com/android/internal/compat/IPlatformCompat.aidl
index 78d1d22c401e..c9f170421e7b 100644
--- a/core/java/com/android/internal/compat/IPlatformCompat.aidl
+++ b/core/java/com/android/internal/compat/IPlatformCompat.aidl
@@ -22,6 +22,7 @@ import java.util.Map;
parcelable CompatibilityChangeConfig;
parcelable CompatibilityOverrideConfig;
+parcelable CompatibilityOverridesToRemoveConfig;
parcelable CompatibilityChangeInfo;
/**
* Platform private API for talking with the PlatformCompat service.
@@ -204,6 +205,27 @@ interface IPlatformCompat {
void clearOverrideForTest(long changeId, String packageName);
/**
+ * Restores the default behaviour for compatibility changes on release builds.
+ *
+ * <p>The caller to this API needs to hold
+ * {@code android.permission.OVERRIDE_COMPAT_CHANGE_CONFIG_ON_RELEASE_BUILD} and all change ids
+ * in {@code overridesToRemove} need to annotated with
+ * {@link android.compat.annotation.Overridable}.
+ *
+ * A release build in this definition means that {@link android.os.Build#IS_DEBUGGABLE} needs to
+ * be {@code false}.
+ *
+ * <p>Note that this does not kill the app, and therefore overrides read from the app process
+ * will not be updated. Overrides read from the system process do take effect.
+ *
+ * @param overridesToRemove parcelable containing the compat change overrides to be removed
+ * @param packageName the package name of the app whose changes will be restored to the
+ * default behaviour
+ * @throws SecurityException if overriding changes is not permitted
+ */
+ void removeOverridesOnReleaseBuilds(in CompatibilityOverridesToRemoveConfig overridesToRemove, in String packageName);
+
+ /**
* Enables all compatibility changes that have enabledSinceTargetSdk ==
* {@param targetSdkVersion} for an app, subject to the policy.
*