summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoanne Chung <joannechung@google.com>2020-02-05 16:50:17 +0800
committerJoanne Chung <joannechung@google.com>2020-02-06 11:21:07 +0800
commitff33c168ec8ee2190999d0091dd1e8cd0a2ce509 (patch)
tree0fe52d65d7e8bcf661e9c743973e1a92797ec0aa
parentfa96ad19c7dddd6e8e9ee142ca61274702822653 (diff)
Ported TextClassificationManagerPerfTest from Settings to DeviceConfig.
We dropped legacy Settings after ag/9852595, we should change to use DeviceConfig here. No performance issue observed after appling change. Bug: 148831327 Test: frameworks/base/apct-tests/perftests/textclassifier/run.sh and make sure the config is set to default after test. Change-Id: I2c95d12561373f8711fc548a4a9050a0bc5a0377
-rw-r--r--apct-tests/perftests/textclassifier/src/android/view/textclassifier/TextClassificationManagerPerfTest.java51
1 files changed, 39 insertions, 12 deletions
diff --git a/apct-tests/perftests/textclassifier/src/android/view/textclassifier/TextClassificationManagerPerfTest.java b/apct-tests/perftests/textclassifier/src/android/view/textclassifier/TextClassificationManagerPerfTest.java
index bd3b6737f505..f61ea8549236 100644
--- a/apct-tests/perftests/textclassifier/src/android/view/textclassifier/TextClassificationManagerPerfTest.java
+++ b/apct-tests/perftests/textclassifier/src/android/view/textclassifier/TextClassificationManagerPerfTest.java
@@ -18,35 +18,60 @@ package android.view.textclassifier;
import android.content.Context;
import android.perftests.utils.BenchmarkState;
import android.perftests.utils.PerfStatusReporter;
-import android.perftests.utils.SettingsHelper;
-import android.provider.Settings;
+import android.provider.DeviceConfig;
import androidx.test.InstrumentationRegistry;
import androidx.test.filters.LargeTest;
import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
@LargeTest
public class TextClassificationManagerPerfTest {
+ private static final String WRITE_DEVICE_CONFIG_PERMISSION =
+ "android.permission.WRITE_DEVICE_CONFIG";
@Rule
public PerfStatusReporter mPerfStatusReporter = new PerfStatusReporter();
+ private String mOriginalSystemTextclassifierStatus;
+
+ @BeforeClass
+ public static void setUpClass() {
+ InstrumentationRegistry.getInstrumentation().getUiAutomation()
+ .adoptShellPermissionIdentity(
+ WRITE_DEVICE_CONFIG_PERMISSION);
+ }
+
+ @AfterClass
+ public static void tearDownClass() {
+ InstrumentationRegistry
+ .getInstrumentation()
+ .getUiAutomation()
+ .dropShellPermissionIdentity();
+ }
+
+ @Before
+ public void setUp() {
+ // Saves config original value.
+ mOriginalSystemTextclassifierStatus = DeviceConfig.getProperty(
+ DeviceConfig.NAMESPACE_TEXTCLASSIFIER, "system_textclassifier_enabled");
+ }
+
@After
public void tearDown() {
- SettingsHelper.delete(
- SettingsHelper.NAMESPACE_GLOBAL, Settings.Global.TEXT_CLASSIFIER_CONSTANTS);
+ // Restores config original value.
+ enableSystemTextclassifier(mOriginalSystemTextclassifierStatus);
}
@Test
public void testGetTextClassifier_systemTextClassifierDisabled() {
Context context = InstrumentationRegistry.getTargetContext();
- SettingsHelper.set(
- SettingsHelper.NAMESPACE_GLOBAL,
- Settings.Global.TEXT_CLASSIFIER_CONSTANTS,
- "system_textclassifier_enabled=false");
+ enableSystemTextclassifier(String.valueOf(false));
TextClassificationManager textClassificationManager =
context.getSystemService(TextClassificationManager.class);
BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
@@ -59,10 +84,7 @@ public class TextClassificationManagerPerfTest {
@Test
public void testGetTextClassifier_systemTextClassifierEnabled() {
Context context = InstrumentationRegistry.getTargetContext();
- SettingsHelper.set(
- SettingsHelper.NAMESPACE_GLOBAL,
- Settings.Global.TEXT_CLASSIFIER_CONSTANTS,
- "system_textclassifier_enabled=true");
+ enableSystemTextclassifier(String.valueOf(true));
TextClassificationManager textClassificationManager =
context.getSystemService(TextClassificationManager.class);
BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
@@ -71,4 +93,9 @@ public class TextClassificationManagerPerfTest {
textClassificationManager.invalidateForTesting();
}
}
+
+ private void enableSystemTextclassifier(String enabled) {
+ DeviceConfig.setProperty(DeviceConfig.NAMESPACE_TEXTCLASSIFIER,
+ "system_textclassifier_enabled", enabled, /* makeDefault */ false);
+ }
}