Merge "Revert "API changes as requested by API council.""
diff --git a/luni/src/main/java/android/compat/Compatibility.java b/luni/src/main/java/android/compat/Compatibility.java
index cf9f770..5d472bb 100644
--- a/luni/src/main/java/android/compat/Compatibility.java
+++ b/luni/src/main/java/android/compat/Compatibility.java
@@ -55,8 +55,8 @@
*/
@CorePlatformApi(status = CorePlatformApi.Status.STABLE)
@IntraCoreApi
- public static void reportUnconditionalChange(@ChangeId long changeId) {
- sCallbacks.onChangeReported(changeId);
+ public static void reportChange(@ChangeId long changeId) {
+ sCallbacks.reportChange(changeId);
}
/**
@@ -68,7 +68,7 @@
* {@code false}, the calling code should behave as it did in earlier releases.
*
* <p>When this method returns {@code true}, it will also report the change as
- * {@link #reportUnconditionalChange(long)} would, so there is no need to call that method directly.
+ * {@link #reportChange(long)} would, so there is no need to call that method directly.
*
* @param changeId The ID of the compatibility change in question.
* @return {@code true} if the change is enabled for the current app.
@@ -79,32 +79,13 @@
return sCallbacks.isChangeEnabled(changeId);
}
- private static final BehaviorChangeDelegate DEFAULT_CALLBACKS = new BehaviorChangeDelegate(){};
+ private volatile static Callbacks sCallbacks = new Callbacks();
- private volatile static BehaviorChangeDelegate sCallbacks = DEFAULT_CALLBACKS;
-
- /**
- * Sets the behavior change delegate.
- *
- * All changes reported via the {@link Compatibility} class will be forwarded to this class.
- */
@CorePlatformApi(status = CorePlatformApi.Status.STABLE)
- public static void setBehaviorChangeDelegate(BehaviorChangeDelegate callbacks) {
+ public static void setCallbacks(Callbacks callbacks) {
sCallbacks = Objects.requireNonNull(callbacks);
}
- /**
- * Removes a behavior change delegate previously set via {@link #setBehaviorChangeDelegate}.
- */
- @CorePlatformApi(status = CorePlatformApi.Status.STABLE)
- public static void clearBehaviorChangeDelegate() {
- sCallbacks = DEFAULT_CALLBACKS;
- }
-
- /**
- * For use by tests only. Causes values from {@code overrides} to be returned instead of the
- * real value.
- */
@CorePlatformApi(status = CorePlatformApi.Status.STABLE)
public static void setOverrides(ChangeConfig overrides) {
// Setting overrides twice in a row does not need to be supported because
@@ -118,9 +99,6 @@
sCallbacks = new OverrideCallbacks(sCallbacks, overrides);
}
- /**
- * For use by tests only. Removes overrides set by {@link #setOverrides}.
- */
@CorePlatformApi(status = CorePlatformApi.Status.STABLE)
public static void clearOverrides() {
if (!(sCallbacks instanceof OverrideCallbacks)) {
@@ -137,21 +115,17 @@
* breaking @CorePlatformApi binary compatibility.
*/
@CorePlatformApi(status = CorePlatformApi.Status.STABLE)
- public interface BehaviorChangeDelegate {
- /**
- * Called when a change is reported via {@link Compatibility#reportUnconditionalChange}
- */
+ public static class Callbacks {
@CorePlatformApi(status = CorePlatformApi.Status.STABLE)
- default void onChangeReported(long changeId) {
+ protected Callbacks() {
+ }
+ @CorePlatformApi(status = CorePlatformApi.Status.STABLE)
+ protected void reportChange(long changeId) {
// Do not use String.format here (b/160912695)
System.logW("No Compatibility callbacks set! Reporting change " + changeId);
}
-
- /**
- * Called when a change is queried via {@link Compatibility#isChangeEnabled}
- */
@CorePlatformApi(status = CorePlatformApi.Status.STABLE)
- default boolean isChangeEnabled(long changeId) {
+ protected boolean isChangeEnabled(long changeId) {
// Do not use String.format here (b/160912695)
System.logW("No Compatibility callbacks set! Querying change " + changeId);
return true;
@@ -240,16 +214,16 @@
}
}
- private static class OverrideCallbacks implements BehaviorChangeDelegate {
- private final BehaviorChangeDelegate delegate;
+ private static class OverrideCallbacks extends Callbacks {
+ private final Callbacks delegate;
private final ChangeConfig changeConfig;
- private OverrideCallbacks(BehaviorChangeDelegate delegate, ChangeConfig changeConfig) {
+ private OverrideCallbacks(Callbacks delegate, ChangeConfig changeConfig) {
this.delegate = Objects.requireNonNull(delegate);
this.changeConfig = Objects.requireNonNull(changeConfig);
}
@Override
- public boolean isChangeEnabled(long changeId) {
+ protected boolean isChangeEnabled(long changeId) {
if (changeConfig.isForceEnabled(changeId)) {
return true;
}
diff --git a/mmodules/core_platform_api/api/legacy_platform/current.txt b/mmodules/core_platform_api/api/legacy_platform/current.txt
index 19a63b9..e54cac4 100644
--- a/mmodules/core_platform_api/api/legacy_platform/current.txt
+++ b/mmodules/core_platform_api/api/legacy_platform/current.txt
@@ -2,17 +2,17 @@
package android.compat {
public final class Compatibility {
- method public static void clearBehaviorChangeDelegate();
method public static void clearOverrides();
method public static boolean isChangeEnabled(long);
- method public static void reportUnconditionalChange(long);
- method public static void setBehaviorChangeDelegate(android.compat.Compatibility.BehaviorChangeDelegate);
+ method public static void reportChange(long);
+ method public static void setCallbacks(android.compat.Compatibility.Callbacks);
method public static void setOverrides(android.compat.Compatibility.ChangeConfig);
}
- public static interface Compatibility.BehaviorChangeDelegate {
- method public default boolean isChangeEnabled(long);
- method public default void onChangeReported(long);
+ public static class Compatibility.Callbacks {
+ ctor protected Compatibility.Callbacks();
+ method protected boolean isChangeEnabled(long);
+ method protected void reportChange(long);
}
public static final class Compatibility.ChangeConfig {
diff --git a/mmodules/core_platform_api/api/stable_platform/current.txt b/mmodules/core_platform_api/api/stable_platform/current.txt
index e8ebeb3..dffea52 100644
--- a/mmodules/core_platform_api/api/stable_platform/current.txt
+++ b/mmodules/core_platform_api/api/stable_platform/current.txt
@@ -2,17 +2,17 @@
package android.compat {
public final class Compatibility {
- method public static void clearBehaviorChangeDelegate();
method public static void clearOverrides();
method public static boolean isChangeEnabled(long);
- method public static void reportUnconditionalChange(long);
- method public static void setBehaviorChangeDelegate(android.compat.Compatibility.BehaviorChangeDelegate);
+ method public static void reportChange(long);
+ method public static void setCallbacks(android.compat.Compatibility.Callbacks);
method public static void setOverrides(android.compat.Compatibility.ChangeConfig);
}
- public static interface Compatibility.BehaviorChangeDelegate {
- method public default boolean isChangeEnabled(long);
- method public default void onChangeReported(long);
+ public static class Compatibility.Callbacks {
+ ctor protected Compatibility.Callbacks();
+ method protected boolean isChangeEnabled(long);
+ method protected void reportChange(long);
}
public static final class Compatibility.ChangeConfig {
diff --git a/mmodules/intracoreapi/api/intra/current.txt b/mmodules/intracoreapi/api/intra/current.txt
index 2e1e6e8..fab4f37 100644
--- a/mmodules/intracoreapi/api/intra/current.txt
+++ b/mmodules/intracoreapi/api/intra/current.txt
@@ -3,7 +3,7 @@
@libcore.api.CorePlatformApi(status=libcore.api.CorePlatformApi.Status.STABLE) @libcore.api.IntraCoreApi public final class Compatibility {
method @libcore.api.CorePlatformApi(status=libcore.api.CorePlatformApi.Status.STABLE) @libcore.api.IntraCoreApi public static boolean isChangeEnabled(long);
- method @libcore.api.CorePlatformApi(status=libcore.api.CorePlatformApi.Status.STABLE) @libcore.api.IntraCoreApi public static void reportUnconditionalChange(long);
+ method @libcore.api.CorePlatformApi(status=libcore.api.CorePlatformApi.Status.STABLE) @libcore.api.IntraCoreApi public static void reportChange(long);
}
@libcore.api.CorePlatformApi(status=libcore.api.CorePlatformApi.Status.STABLE) @libcore.api.IntraCoreApi public static final class Compatibility.ChangeConfig {
diff --git a/test-rules/src/platform_compat/java/libcore/junit/util/CoreCompatChangeRule.java b/test-rules/src/platform_compat/java/libcore/junit/util/CoreCompatChangeRule.java
index 4fd3208..b526707 100644
--- a/test-rules/src/platform_compat/java/libcore/junit/util/CoreCompatChangeRule.java
+++ b/test-rules/src/platform_compat/java/libcore/junit/util/CoreCompatChangeRule.java
@@ -17,6 +17,7 @@
package libcore.junit.util.compat;
import android.compat.Compatibility;
+import android.compat.Compatibility.Callbacks;
import android.compat.Compatibility.ChangeConfig;
import org.junit.rules.TestRule;