diff options
author | Daniel Peykov <peykov@google.com> | 2023-06-29 19:42:19 +0000 |
---|---|---|
committer | Daniel Peykov <peykov@google.com> | 2023-06-29 19:53:07 +0000 |
commit | 78e4846376d3e2c8178a22f1e82941f7ad1f6f0d (patch) | |
tree | 9fec04a8ebc8c9c78eac6bccefe98234fe454cb6 | |
parent | 0c255e1ffc250034eb444c9ba8697788fba69c4d (diff) | |
download | libtextclassifier-78e4846376d3e2c8178a22f1e82941f7ad1f6f0d.tar.gz |
Remove dependence on sync mode from textclassifier tests
Some tests (e.g. ModelDownloaderIntegrationTest) required DeviceConfig
syncing to be enabled. This is fixed using DeviceConfigStateHelper to
enable/revert syncing when necessary, and allows syncs to be disabled by
default during testing to ensure deterministic platform flags.
Bug: 283536230
Bug: 289277724
Test: atest TextClassifierServiceTest
Test: atest TCSModelDownloaderIntegrationTest
Change-Id: Ia04b5267e9394703c176c3f0935563ed6ee45f91
-rw-r--r-- | java/tests/instrumentation/Android.bp | 1 | ||||
-rw-r--r-- | java/tests/instrumentation/src/com/android/textclassifier/testing/ExtServicesTextClassifierRule.java | 7 |
2 files changed, 6 insertions, 2 deletions
diff --git a/java/tests/instrumentation/Android.bp b/java/tests/instrumentation/Android.bp index 775f9f9..02757b8 100644 --- a/java/tests/instrumentation/Android.bp +++ b/java/tests/instrumentation/Android.bp @@ -36,6 +36,7 @@ java_library { "TextClassifierServiceLib", "androidx.test.espresso.core", "mockito-target-minus-junit4", + "compatibility-device-util-axt", ], } diff --git a/java/tests/instrumentation/src/com/android/textclassifier/testing/ExtServicesTextClassifierRule.java b/java/tests/instrumentation/src/com/android/textclassifier/testing/ExtServicesTextClassifierRule.java index 5f8247d..1b6405a 100644 --- a/java/tests/instrumentation/src/com/android/textclassifier/testing/ExtServicesTextClassifierRule.java +++ b/java/tests/instrumentation/src/com/android/textclassifier/testing/ExtServicesTextClassifierRule.java @@ -25,6 +25,7 @@ import android.view.textclassifier.TextClassificationManager; import android.view.textclassifier.TextClassifier; import androidx.test.core.app.ApplicationProvider; import androidx.test.platform.app.InstrumentationRegistry; +import com.android.compatibility.common.util.DeviceConfigStateHelper; import com.google.common.io.ByteStreams; import java.io.FileInputStream; import java.io.IOException; @@ -57,7 +58,8 @@ public final class ExtServicesTextClassifierRule extends ExternalResource { @Override protected void after() { try { - DeviceConfig.setProperties(originalProperties); + DeviceConfigStateHelper.callWithSyncEnabledWithShellPermissions(() -> + DeviceConfig.setProperties(originalProperties)); } catch (Throwable t) { Log.e(TAG, "Failed to reset DeviceConfig", t); } finally { @@ -79,7 +81,8 @@ public final class ExtServicesTextClassifierRule extends ExternalResource { * hidden API. */ public void overrideDeviceConfig() throws Exception { - DeviceConfig.setProperties(newPropertiesBuilder.build()); + DeviceConfigStateHelper.callWithSyncEnabledWithShellPermissions(() -> + DeviceConfig.setProperties(newPropertiesBuilder.build())); } /** Force stop ExtServices. Force-stop-and-start can be helpful to reload some states. */ |