Loading apct-tests/perftests/textclassifier/run.sh +6 −2 Original line number Original line Diff line number Diff line set -e set -e make TextClassifierPerfTests make TextClassifierPerfTests perf-setup.sh adb install ${OUT}/testcases/TextClassifierPerfTests/arm64/TextClassifierPerfTests.apk adb shell cmd package compile -m speed -f com.android.perftests.textclassifier adb shell cmd package compile -m speed -f com.android.perftests.textclassifier adb shell am instrument -w -e class android.view.textclassifier.TextClassifierPerfTest com.android.perftests.textclassifier/androidx.test.runner.AndroidJUnitRunner adb push ${OUT}/obj/EXECUTABLES/perf-setup.sh_intermediates/perf-setup.sh /data/local/tmp/ adb shell chmod +x /data/local/tmp/perf-setup.sh adb shell /data/local/tmp/perf-setup.sh adb shell am instrument -w -e package android.view.textclassifier com.android.perftests.textclassifier/androidx.test.runner.AndroidJUnitRunner No newline at end of file apct-tests/perftests/textclassifier/src/android/view/textclassifier/TextClassificationManagerPerfTest.java 0 → 100644 +74 −0 Original line number Original line Diff line number Diff line /* * Copyright (C) 2018 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ 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 androidx.test.InstrumentationRegistry; import androidx.test.filters.LargeTest; import org.junit.After; import org.junit.Rule; import org.junit.Test; @LargeTest public class TextClassificationManagerPerfTest { @Rule public PerfStatusReporter mPerfStatusReporter = new PerfStatusReporter(); @After public void tearDown() { SettingsHelper.delete( SettingsHelper.NAMESPACE_GLOBAL, Settings.Global.TEXT_CLASSIFIER_CONSTANTS); } @Test public void testGetTextClassifier_systemTextClassifierDisabled() { Context context = InstrumentationRegistry.getTargetContext(); SettingsHelper.set( SettingsHelper.NAMESPACE_GLOBAL, Settings.Global.TEXT_CLASSIFIER_CONSTANTS, "system_textclassifier_enabled=false"); TextClassificationManager textClassificationManager = context.getSystemService(TextClassificationManager.class); BenchmarkState state = mPerfStatusReporter.getBenchmarkState(); while (state.keepRunning()) { textClassificationManager.getTextClassifier(); textClassificationManager.invalidate(); } } @Test public void testGetTextClassifier_systemTextClassifierEnabled() { Context context = InstrumentationRegistry.getTargetContext(); SettingsHelper.set( SettingsHelper.NAMESPACE_GLOBAL, Settings.Global.TEXT_CLASSIFIER_CONSTANTS, "system_textclassifier_enabled=true"); TextClassificationManager textClassificationManager = context.getSystemService(TextClassificationManager.class); BenchmarkState state = mPerfStatusReporter.getBenchmarkState(); while (state.keepRunning()) { textClassificationManager.getTextClassifier(); textClassificationManager.invalidate(); } } } apct-tests/perftests/utils/src/android/perftests/utils/SettingsHelper.java +3 −3 Original line number Original line Diff line number Diff line Loading @@ -18,19 +18,19 @@ package android.perftests.utils; import android.content.Context; import android.content.Context; import android.provider.Settings; import android.provider.Settings; import android.text.TextUtils; import java.util.Objects; import androidx.annotation.NonNull; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.annotation.Nullable; import java.util.Objects; /** /** * Provides utilities to interact with the device's {@link Settings}. * Provides utilities to interact with the device's {@link Settings}. */ */ public final class SettingsHelper { public final class SettingsHelper { public static final String NAMESPACE_SECURE = "secure"; public static final String NAMESPACE_SECURE = "secure"; public static final String NAMESPACE_GLOBAL = "global"; private static int DEFAULT_TIMEOUT_MS = 5000; private static int DEFAULT_TIMEOUT_MS = 5000; Loading core/java/android/view/textclassifier/TextClassificationManager.java +4 −1 Original line number Original line Diff line number Diff line Loading @@ -30,6 +30,7 @@ import android.service.textclassifier.TextClassifierService; import android.view.textclassifier.TextClassifier.TextClassifierType; import android.view.textclassifier.TextClassifier.TextClassifierType; import com.android.internal.annotations.GuardedBy; import com.android.internal.annotations.GuardedBy; import com.android.internal.annotations.VisibleForTesting; import com.android.internal.util.IndentingPrintWriter; import com.android.internal.util.IndentingPrintWriter; import com.android.internal.util.Preconditions; import com.android.internal.util.Preconditions; Loading Loading @@ -247,7 +248,9 @@ public final class TextClassificationManager { && TextClassifierService.getServiceComponentName(mContext) != null; && TextClassifierService.getServiceComponentName(mContext) != null; } } private void invalidate() { /** @hide */ @VisibleForTesting public void invalidate() { synchronized (mLock) { synchronized (mLock) { mSettings = null; mSettings = null; mLocalTextClassifier = null; mLocalTextClassifier = null; Loading Loading
apct-tests/perftests/textclassifier/run.sh +6 −2 Original line number Original line Diff line number Diff line set -e set -e make TextClassifierPerfTests make TextClassifierPerfTests perf-setup.sh adb install ${OUT}/testcases/TextClassifierPerfTests/arm64/TextClassifierPerfTests.apk adb shell cmd package compile -m speed -f com.android.perftests.textclassifier adb shell cmd package compile -m speed -f com.android.perftests.textclassifier adb shell am instrument -w -e class android.view.textclassifier.TextClassifierPerfTest com.android.perftests.textclassifier/androidx.test.runner.AndroidJUnitRunner adb push ${OUT}/obj/EXECUTABLES/perf-setup.sh_intermediates/perf-setup.sh /data/local/tmp/ adb shell chmod +x /data/local/tmp/perf-setup.sh adb shell /data/local/tmp/perf-setup.sh adb shell am instrument -w -e package android.view.textclassifier com.android.perftests.textclassifier/androidx.test.runner.AndroidJUnitRunner No newline at end of file
apct-tests/perftests/textclassifier/src/android/view/textclassifier/TextClassificationManagerPerfTest.java 0 → 100644 +74 −0 Original line number Original line Diff line number Diff line /* * Copyright (C) 2018 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ 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 androidx.test.InstrumentationRegistry; import androidx.test.filters.LargeTest; import org.junit.After; import org.junit.Rule; import org.junit.Test; @LargeTest public class TextClassificationManagerPerfTest { @Rule public PerfStatusReporter mPerfStatusReporter = new PerfStatusReporter(); @After public void tearDown() { SettingsHelper.delete( SettingsHelper.NAMESPACE_GLOBAL, Settings.Global.TEXT_CLASSIFIER_CONSTANTS); } @Test public void testGetTextClassifier_systemTextClassifierDisabled() { Context context = InstrumentationRegistry.getTargetContext(); SettingsHelper.set( SettingsHelper.NAMESPACE_GLOBAL, Settings.Global.TEXT_CLASSIFIER_CONSTANTS, "system_textclassifier_enabled=false"); TextClassificationManager textClassificationManager = context.getSystemService(TextClassificationManager.class); BenchmarkState state = mPerfStatusReporter.getBenchmarkState(); while (state.keepRunning()) { textClassificationManager.getTextClassifier(); textClassificationManager.invalidate(); } } @Test public void testGetTextClassifier_systemTextClassifierEnabled() { Context context = InstrumentationRegistry.getTargetContext(); SettingsHelper.set( SettingsHelper.NAMESPACE_GLOBAL, Settings.Global.TEXT_CLASSIFIER_CONSTANTS, "system_textclassifier_enabled=true"); TextClassificationManager textClassificationManager = context.getSystemService(TextClassificationManager.class); BenchmarkState state = mPerfStatusReporter.getBenchmarkState(); while (state.keepRunning()) { textClassificationManager.getTextClassifier(); textClassificationManager.invalidate(); } } }
apct-tests/perftests/utils/src/android/perftests/utils/SettingsHelper.java +3 −3 Original line number Original line Diff line number Diff line Loading @@ -18,19 +18,19 @@ package android.perftests.utils; import android.content.Context; import android.content.Context; import android.provider.Settings; import android.provider.Settings; import android.text.TextUtils; import java.util.Objects; import androidx.annotation.NonNull; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.annotation.Nullable; import java.util.Objects; /** /** * Provides utilities to interact with the device's {@link Settings}. * Provides utilities to interact with the device's {@link Settings}. */ */ public final class SettingsHelper { public final class SettingsHelper { public static final String NAMESPACE_SECURE = "secure"; public static final String NAMESPACE_SECURE = "secure"; public static final String NAMESPACE_GLOBAL = "global"; private static int DEFAULT_TIMEOUT_MS = 5000; private static int DEFAULT_TIMEOUT_MS = 5000; Loading
core/java/android/view/textclassifier/TextClassificationManager.java +4 −1 Original line number Original line Diff line number Diff line Loading @@ -30,6 +30,7 @@ import android.service.textclassifier.TextClassifierService; import android.view.textclassifier.TextClassifier.TextClassifierType; import android.view.textclassifier.TextClassifier.TextClassifierType; import com.android.internal.annotations.GuardedBy; import com.android.internal.annotations.GuardedBy; import com.android.internal.annotations.VisibleForTesting; import com.android.internal.util.IndentingPrintWriter; import com.android.internal.util.IndentingPrintWriter; import com.android.internal.util.Preconditions; import com.android.internal.util.Preconditions; Loading Loading @@ -247,7 +248,9 @@ public final class TextClassificationManager { && TextClassifierService.getServiceComponentName(mContext) != null; && TextClassifierService.getServiceComponentName(mContext) != null; } } private void invalidate() { /** @hide */ @VisibleForTesting public void invalidate() { synchronized (mLock) { synchronized (mLock) { mSettings = null; mSettings = null; mLocalTextClassifier = null; mLocalTextClassifier = null; Loading