diff --git a/api/system-removed.txt b/api/system-removed.txt index 5802f6cc09b6c..e3665f6476712 100644 --- a/api/system-removed.txt +++ b/api/system-removed.txt @@ -158,19 +158,6 @@ package android.os { } -package android.provider { - - public final class DeviceConfig { - method @RequiresPermission(android.Manifest.permission.READ_DEVICE_CONFIG) public static void addOnPropertyChangedListener(@NonNull String, @NonNull java.util.concurrent.Executor, @NonNull android.provider.DeviceConfig.OnPropertyChangedListener); - method public static void removeOnPropertyChangedListener(@NonNull android.provider.DeviceConfig.OnPropertyChangedListener); - } - - public static interface DeviceConfig.OnPropertyChangedListener { - method public void onPropertyChanged(@NonNull String, @NonNull String, @Nullable String); - } - -} - package android.service.notification { public abstract class NotificationListenerService extends android.app.Service { diff --git a/api/test-removed.txt b/api/test-removed.txt index ef0aac7eac9aa..e47f6edfbff1b 100644 --- a/api/test-removed.txt +++ b/api/test-removed.txt @@ -8,16 +8,3 @@ package android.app.prediction { } -package android.provider { - - public final class DeviceConfig { - method @RequiresPermission("android.permission.READ_DEVICE_CONFIG") public static void addOnPropertyChangedListener(@NonNull String, @NonNull java.util.concurrent.Executor, @NonNull android.provider.DeviceConfig.OnPropertyChangedListener); - method public static void removeOnPropertyChangedListener(@NonNull android.provider.DeviceConfig.OnPropertyChangedListener); - } - - public static interface DeviceConfig.OnPropertyChangedListener { - method public void onPropertyChanged(@NonNull String, @NonNull String, @Nullable String); - } - -} - diff --git a/core/java/android/provider/DeviceConfig.java b/core/java/android/provider/DeviceConfig.java index ea397cca98ac3..79ce34214d6b7 100644 --- a/core/java/android/provider/DeviceConfig.java +++ b/core/java/android/provider/DeviceConfig.java @@ -309,9 +309,6 @@ public final class DeviceConfig { private static final Object sLock = new Object(); @GuardedBy("sLock") - private static ArrayMap> sSingleListeners = - new ArrayMap<>(); - @GuardedBy("sLock") private static ArrayMap> sListeners = new ArrayMap<>(); @GuardedBy("sLock") @@ -504,48 +501,6 @@ public final class DeviceConfig { Settings.Config.resetToDefaults(contentResolver, resetMode, namespace); } - /** - * Add a listener for property changes. - *

- * This listener will be called whenever properties in the specified namespace change. Callbacks - * will be made on the specified executor. Future calls to this method with the same listener - * will replace the old namespace and executor. Remove the listener entirely by calling - * {@link #removeOnPropertyChangedListener(OnPropertyChangedListener)}. - * - * @param namespace The namespace containing properties to monitor. - * @param executor The executor which will be used to run callbacks. - * @param onPropertyChangedListener The listener to add. - * @hide - * @see #removeOnPropertyChangedListener(OnPropertyChangedListener) - * @removed - */ - @SystemApi - @TestApi - @RequiresPermission(READ_DEVICE_CONFIG) - public static void addOnPropertyChangedListener( - @NonNull String namespace, - @NonNull @CallbackExecutor Executor executor, - @NonNull OnPropertyChangedListener onPropertyChangedListener) { - enforceReadPermission(ActivityThread.currentApplication().getApplicationContext(), - namespace); - synchronized (sLock) { - Pair oldNamespace = sSingleListeners.get(onPropertyChangedListener); - if (oldNamespace == null) { - // Brand new listener, add it to the list. - sSingleListeners.put(onPropertyChangedListener, new Pair<>(namespace, executor)); - incrementNamespace(namespace); - } else if (namespace.equals(oldNamespace.first)) { - // Listener is already registered for this namespace, update executor just in case. - sSingleListeners.put(onPropertyChangedListener, new Pair<>(namespace, executor)); - } else { - // Update this listener from an old namespace to the new one. - decrementNamespace(sSingleListeners.get(onPropertyChangedListener).first); - sSingleListeners.put(onPropertyChangedListener, new Pair<>(namespace, executor)); - incrementNamespace(namespace); - } - } - } - /** * Add a listener for property changes. *

@@ -587,28 +542,6 @@ public final class DeviceConfig { } } - /** - * Remove a listener for property changes. The listener will receive no further notification of - * property changes. - * - * @param onPropertyChangedListener The listener to remove. - * @hide - * @see #addOnPropertyChangedListener(String, Executor, OnPropertyChangedListener) - * @removed - */ - @SystemApi - @TestApi - public static void removeOnPropertyChangedListener( - @NonNull OnPropertyChangedListener onPropertyChangedListener) { - Preconditions.checkNotNull(onPropertyChangedListener); - synchronized (sLock) { - if (sSingleListeners.containsKey(onPropertyChangedListener)) { - decrementNamespace(sSingleListeners.get(onPropertyChangedListener).first); - sSingleListeners.remove(onPropertyChangedListener); - } - } - } - /** * Remove a listener for property changes. The listener will receive no further notification of * property changes. @@ -709,7 +642,6 @@ public final class DeviceConfig { return; } synchronized (sLock) { - // OnPropertiesChangedListeners for (int i = 0; i < sListeners.size(); i++) { if (namespace.equals(sListeners.valueAt(i).first)) { final int j = i; @@ -725,23 +657,9 @@ public final class DeviceConfig { }); } } - // OnPropertyChangedListeners - for (int i = 0; i < sSingleListeners.size(); i++) { - if (namespace.equals(sSingleListeners.valueAt(i).first)) { - final int j = i; - sSingleListeners.valueAt(i).second.execute(new Runnable() { - @Override - public void run() { - sSingleListeners.keyAt(j).onPropertyChanged(namespace, name, value); - } - - }); - } - } } } - /** * Enforces READ_DEVICE_CONFIG permission if namespace is not one of public namespaces. * @hide @@ -756,29 +674,6 @@ public final class DeviceConfig { } } - - /** - * Interface for monitoring single property changes. - *

- * Override {@link #onPropertyChanged(String, String, String)} to handle callbacks for changes. - * - * @hide - * @removed - */ - @SystemApi - @TestApi - public interface OnPropertyChangedListener { - /** - * Called when a property has changed. - * - * @param namespace The namespace containing the property which has changed. - * @param name The name of the property which has changed. - * @param value The new value of the property which has changed. - */ - void onPropertyChanged(@NonNull String namespace, @NonNull String name, - @Nullable String value); - } - /** * Interface for monitoring changes to properties. *

diff --git a/core/tests/coretests/src/android/provider/DeviceConfigTest.java b/core/tests/coretests/src/android/provider/DeviceConfigTest.java index 7a4fa3ab4b631..23fabcec0c9b1 100644 --- a/core/tests/coretests/src/android/provider/DeviceConfigTest.java +++ b/core/tests/coretests/src/android/provider/DeviceConfigTest.java @@ -17,7 +17,6 @@ package android.provider; import static android.provider.DeviceConfig.OnPropertiesChangedListener; -import static android.provider.DeviceConfig.OnPropertyChangedListener; import static com.google.common.truth.Truth.assertThat; @@ -394,31 +393,6 @@ public class DeviceConfigTest { } } - @Test - public void testOnPropertyChangedListener() throws InterruptedException { - CountDownLatch countDownLatch = new CountDownLatch(1); - - OnPropertyChangedListener changeListener = (namespace, name, value) -> { - assertThat(namespace).isEqualTo(sNamespace); - assertThat(name).isEqualTo(sKey); - assertThat(value).isEqualTo(sValue); - countDownLatch.countDown(); - }; - - try { - DeviceConfig.addOnPropertyChangedListener(sNamespace, - ActivityThread.currentApplication().getMainExecutor(), changeListener); - DeviceConfig.setProperty(sNamespace, sKey, sValue, false); - assertThat(countDownLatch.await( - WAIT_FOR_PROPERTY_CHANGE_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS)).isTrue(); - } catch (InterruptedException e) { - Assert.fail(e.getMessage()); - } finally { - DeviceConfig.removeOnPropertyChangedListener(changeListener); - } - - } - private static boolean deleteViaContentProvider(String namespace, String key) { ContentResolver resolver = InstrumentationRegistry.getContext().getContentResolver(); String compositeName = namespace + "/" + key; diff --git a/services/tests/mockingservicestests/src/com/android/server/testables/TestableDeviceConfig.java b/services/tests/mockingservicestests/src/com/android/server/testables/TestableDeviceConfig.java index dae3d30c4fd19..6d8fb731df9ff 100644 --- a/services/tests/mockingservicestests/src/com/android/server/testables/TestableDeviceConfig.java +++ b/services/tests/mockingservicestests/src/com/android/server/testables/TestableDeviceConfig.java @@ -62,8 +62,6 @@ import java.util.concurrent.Executor; public final class TestableDeviceConfig implements TestRule { private StaticMockitoSession mMockitoSession; - private Map> - mOnPropertyChangedListenerMap = new HashMap<>(); private Map> mOnPropertiesChangedListenerMap = new HashMap<>(); private Map mKeyValueMap = new ConcurrentHashMap<>(); @@ -95,18 +93,6 @@ public final class TestableDeviceConfig implements TestRule { anyString(), any(Executor.class), any(DeviceConfig.OnPropertiesChangedListener.class))); - doAnswer((Answer) invocationOnMock -> { - String namespace = invocationOnMock.getArgument(0); - Executor executor = invocationOnMock.getArgument(1); - DeviceConfig.OnPropertyChangedListener onPropertyChangedListener = - invocationOnMock.getArgument(2); - mOnPropertyChangedListenerMap.put( - onPropertyChangedListener, new Pair<>(namespace, executor)); - return null; - }).when(() -> DeviceConfig.addOnPropertyChangedListener( - anyString(), any(Executor.class), - any(DeviceConfig.OnPropertyChangedListener.class))); - doAnswer((Answer) invocationOnMock -> { String namespace = invocationOnMock.getArgument(0); String name = invocationOnMock.getArgument(1); @@ -120,13 +106,6 @@ public final class TestableDeviceConfig implements TestRule { getProperties(namespace, name, value))); } } - for (DeviceConfig.OnPropertyChangedListener listener : - mOnPropertyChangedListenerMap.keySet()) { - if (namespace.equals(mOnPropertyChangedListenerMap.get(listener).first)) { - mOnPropertyChangedListenerMap.get(listener).second.execute( - () -> listener.onPropertyChanged(namespace, name, value)); - } - } return true; } ).when(() -> DeviceConfig.setProperty(anyString(), anyString(), anyString(), anyBoolean())); @@ -141,14 +120,12 @@ public final class TestableDeviceConfig implements TestRule { @Override protected void succeeded(Description description) { mMockitoSession.finishMocking(); - mOnPropertyChangedListenerMap.clear(); mOnPropertiesChangedListenerMap.clear(); } @Override protected void failed(Throwable e, Description description) { mMockitoSession.finishMocking(e); - mOnPropertyChangedListenerMap.clear(); mOnPropertiesChangedListenerMap.clear(); } }.apply(base, description);