blob: c1491956c798a1fc8ac4efdb97eb799562f98d94 [file] [log] [blame]
Tony Mak751afc92019-04-02 18:23:54 +01001/*
2 * Copyright (C) 2018 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package android.view.textclassifier;
17
18import android.content.Context;
19import android.perftests.utils.BenchmarkState;
20import android.perftests.utils.PerfStatusReporter;
21import android.perftests.utils.SettingsHelper;
22import android.provider.Settings;
23
24import androidx.test.InstrumentationRegistry;
25import androidx.test.filters.LargeTest;
26
27import org.junit.After;
28import org.junit.Rule;
29import org.junit.Test;
30
31@LargeTest
32public class TextClassificationManagerPerfTest {
33
34 @Rule
35 public PerfStatusReporter mPerfStatusReporter = new PerfStatusReporter();
36
37 @After
38 public void tearDown() {
39 SettingsHelper.delete(
40 SettingsHelper.NAMESPACE_GLOBAL, Settings.Global.TEXT_CLASSIFIER_CONSTANTS);
41 }
42
43 @Test
44 public void testGetTextClassifier_systemTextClassifierDisabled() {
45 Context context = InstrumentationRegistry.getTargetContext();
46 SettingsHelper.set(
47 SettingsHelper.NAMESPACE_GLOBAL,
48 Settings.Global.TEXT_CLASSIFIER_CONSTANTS,
49 "system_textclassifier_enabled=false");
50 TextClassificationManager textClassificationManager =
51 context.getSystemService(TextClassificationManager.class);
52 BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
53 while (state.keepRunning()) {
54 textClassificationManager.getTextClassifier();
55 textClassificationManager.invalidate();
56 }
57 }
58
59 @Test
60 public void testGetTextClassifier_systemTextClassifierEnabled() {
61 Context context = InstrumentationRegistry.getTargetContext();
62 SettingsHelper.set(
63 SettingsHelper.NAMESPACE_GLOBAL,
64 Settings.Global.TEXT_CLASSIFIER_CONSTANTS,
65 "system_textclassifier_enabled=true");
66 TextClassificationManager textClassificationManager =
67 context.getSystemService(TextClassificationManager.class);
68 BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
69 while (state.keepRunning()) {
70 textClassificationManager.getTextClassifier();
71 textClassificationManager.invalidate();
72 }
73 }
74}