Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 89f4c802 authored by Tony Mak's avatar Tony Mak Committed by android-build-merger
Browse files

Merge "Add getTextClassifier perf test" into qt-dev am: 08f58417

am: d28876a3

Change-Id: I1fe3ac533577461053ce218ca875855bbe1a58d0
parents c2168e8d d28876a3
Loading
Loading
Loading
Loading
+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
+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();
        }
    }
}
+3 −3
Original line number Original line Diff line number Diff line
@@ -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;


+4 −1
Original line number Original line Diff line number Diff line
@@ -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;


@@ -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;