Remove OnPropertyChangedListener.
This listener was @removed in Q, and is removed entirely after this.
Test: atest SettingsProviderTest:DeviceConfigServiceTest
atest FrameworksCoreTests:DeviceConfigTest
Bug: 128902955
Change-Id: I5021dfcd05118598cd6fb0a9c9724834de9c4ae0
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -309,9 +309,6 @@ public final class DeviceConfig {
|
||||
|
||||
private static final Object sLock = new Object();
|
||||
@GuardedBy("sLock")
|
||||
private static ArrayMap<OnPropertyChangedListener, Pair<String, Executor>> sSingleListeners =
|
||||
new ArrayMap<>();
|
||||
@GuardedBy("sLock")
|
||||
private static ArrayMap<OnPropertiesChangedListener, Pair<String, Executor>> 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.
|
||||
* <p>
|
||||
* 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<String, Executor> 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.
|
||||
* <p>
|
||||
@@ -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.
|
||||
* <p>
|
||||
* 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.
|
||||
* <p>
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -62,8 +62,6 @@ import java.util.concurrent.Executor;
|
||||
public final class TestableDeviceConfig implements TestRule {
|
||||
|
||||
private StaticMockitoSession mMockitoSession;
|
||||
private Map<DeviceConfig.OnPropertyChangedListener, Pair<String, Executor>>
|
||||
mOnPropertyChangedListenerMap = new HashMap<>();
|
||||
private Map<DeviceConfig.OnPropertiesChangedListener, Pair<String, Executor>>
|
||||
mOnPropertiesChangedListenerMap = new HashMap<>();
|
||||
private Map<String, String> mKeyValueMap = new ConcurrentHashMap<>();
|
||||
@@ -95,18 +93,6 @@ public final class TestableDeviceConfig implements TestRule {
|
||||
anyString(), any(Executor.class),
|
||||
any(DeviceConfig.OnPropertiesChangedListener.class)));
|
||||
|
||||
doAnswer((Answer<Void>) 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<Boolean>) 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);
|
||||
|
||||
Reference in New Issue
Block a user