Loading core/tests/coretests/src/android/provider/DeviceConfigTest.java +24 −28 Original line number Diff line number Diff line Loading @@ -16,12 +16,10 @@ package android.provider; import static android.provider.DeviceConfig.OnPropertiesChangedListener; import static android.provider.DeviceConfig.Properties; import static com.google.common.truth.Truth.assertThat; import android.app.ActivityThread; import android.content.ContentResolver; import android.os.Bundle; import android.platform.test.annotations.Presubmit; Loading @@ -35,9 +33,6 @@ import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; /** Tests that ensure appropriate settings are backed up. */ @Presubmit @RunWith(AndroidJUnit4.class) Loading Loading @@ -482,29 +477,30 @@ public class DeviceConfigTest { assertThat(properties.getString(KEY3, DEFAULT_VALUE)).isEqualTo(DEFAULT_VALUE); } @Test public void testOnPropertiesChangedListener() throws InterruptedException { final CountDownLatch countDownLatch = new CountDownLatch(1); OnPropertiesChangedListener changeListener = (properties) -> { assertThat(properties.getNamespace()).isEqualTo(NAMESPACE); assertThat(properties.getKeyset()).contains(KEY); assertThat(properties.getString(KEY, "default_value")).isEqualTo(VALUE); countDownLatch.countDown(); }; try { DeviceConfig.addOnPropertiesChangedListener(NAMESPACE, ActivityThread.currentApplication().getMainExecutor(), changeListener); DeviceConfig.setProperty(NAMESPACE, KEY, VALUE, false); assertThat(countDownLatch.await( WAIT_FOR_PROPERTY_CHANGE_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS)).isTrue(); } catch (InterruptedException e) { Assert.fail(e.getMessage()); } finally { DeviceConfig.removeOnPropertiesChangedListener(changeListener); } } // TODO(mpape): resolve b/142727848 and re-enable this test // @Test // public void testOnPropertiesChangedListener() throws InterruptedException { // final CountDownLatch countDownLatch = new CountDownLatch(1); // // OnPropertiesChangedListener changeListener = (properties) -> { // assertThat(properties.getNamespace()).isEqualTo(NAMESPACE); // assertThat(properties.getKeyset()).contains(KEY); // assertThat(properties.getString(KEY, "default_value")).isEqualTo(VALUE); // countDownLatch.countDown(); // }; // // try { // DeviceConfig.addOnPropertiesChangedListener(NAMESPACE, // ActivityThread.currentApplication().getMainExecutor(), changeListener); // DeviceConfig.setProperty(NAMESPACE, KEY, VALUE, false); // assertThat(countDownLatch.await( // WAIT_FOR_PROPERTY_CHANGE_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS)).isTrue(); // } catch (InterruptedException e) { // Assert.fail(e.getMessage()); // } finally { // DeviceConfig.removeOnPropertiesChangedListener(changeListener); // } // } private static boolean deleteViaContentProvider(String namespace, String key) { ContentResolver resolver = InstrumentationRegistry.getContext().getContentResolver(); Loading Loading
core/tests/coretests/src/android/provider/DeviceConfigTest.java +24 −28 Original line number Diff line number Diff line Loading @@ -16,12 +16,10 @@ package android.provider; import static android.provider.DeviceConfig.OnPropertiesChangedListener; import static android.provider.DeviceConfig.Properties; import static com.google.common.truth.Truth.assertThat; import android.app.ActivityThread; import android.content.ContentResolver; import android.os.Bundle; import android.platform.test.annotations.Presubmit; Loading @@ -35,9 +33,6 @@ import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; /** Tests that ensure appropriate settings are backed up. */ @Presubmit @RunWith(AndroidJUnit4.class) Loading Loading @@ -482,29 +477,30 @@ public class DeviceConfigTest { assertThat(properties.getString(KEY3, DEFAULT_VALUE)).isEqualTo(DEFAULT_VALUE); } @Test public void testOnPropertiesChangedListener() throws InterruptedException { final CountDownLatch countDownLatch = new CountDownLatch(1); OnPropertiesChangedListener changeListener = (properties) -> { assertThat(properties.getNamespace()).isEqualTo(NAMESPACE); assertThat(properties.getKeyset()).contains(KEY); assertThat(properties.getString(KEY, "default_value")).isEqualTo(VALUE); countDownLatch.countDown(); }; try { DeviceConfig.addOnPropertiesChangedListener(NAMESPACE, ActivityThread.currentApplication().getMainExecutor(), changeListener); DeviceConfig.setProperty(NAMESPACE, KEY, VALUE, false); assertThat(countDownLatch.await( WAIT_FOR_PROPERTY_CHANGE_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS)).isTrue(); } catch (InterruptedException e) { Assert.fail(e.getMessage()); } finally { DeviceConfig.removeOnPropertiesChangedListener(changeListener); } } // TODO(mpape): resolve b/142727848 and re-enable this test // @Test // public void testOnPropertiesChangedListener() throws InterruptedException { // final CountDownLatch countDownLatch = new CountDownLatch(1); // // OnPropertiesChangedListener changeListener = (properties) -> { // assertThat(properties.getNamespace()).isEqualTo(NAMESPACE); // assertThat(properties.getKeyset()).contains(KEY); // assertThat(properties.getString(KEY, "default_value")).isEqualTo(VALUE); // countDownLatch.countDown(); // }; // // try { // DeviceConfig.addOnPropertiesChangedListener(NAMESPACE, // ActivityThread.currentApplication().getMainExecutor(), changeListener); // DeviceConfig.setProperty(NAMESPACE, KEY, VALUE, false); // assertThat(countDownLatch.await( // WAIT_FOR_PROPERTY_CHANGE_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS)).isTrue(); // } catch (InterruptedException e) { // Assert.fail(e.getMessage()); // } finally { // DeviceConfig.removeOnPropertiesChangedListener(changeListener); // } // } private static boolean deleteViaContentProvider(String namespace, String key) { ContentResolver resolver = InstrumentationRegistry.getContext().getContentResolver(); Loading