Skip to content
Snippets Groups Projects
Commit a7db3c8e authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Add a flag to allow system health experiment for the behavior change...

Merge "Add a flag to allow system health experiment for the behavior change ... of getDefaultTextClassifierImplementation()"
parents 84f74893 df5d4bff
No related branches found
No related tags found
No related merge requests found
......@@ -41,6 +41,7 @@ import android.util.Slog;
import android.view.textclassifier.ConversationActions;
import android.view.textclassifier.SelectionEvent;
import android.view.textclassifier.TextClassification;
import android.view.textclassifier.TextClassificationConstants;
import android.view.textclassifier.TextClassificationContext;
import android.view.textclassifier.TextClassificationManager;
import android.view.textclassifier.TextClassificationSessionId;
......@@ -404,22 +405,27 @@ public abstract class TextClassifierService extends Service {
*/
@NonNull
public static TextClassifier getDefaultTextClassifierImplementation(@NonNull Context context) {
final String defaultTextClassifierPackageName =
context.getPackageManager().getDefaultTextClassifierPackageName();
if (TextUtils.isEmpty(defaultTextClassifierPackageName)) {
return TextClassifier.NO_OP;
}
if (defaultTextClassifierPackageName.equals(context.getPackageName())) {
throw new RuntimeException(
"The default text classifier itself should not call the"
+ "getDefaultTextClassifierImplementation() method.");
}
final TextClassificationManager tcm =
context.getSystemService(TextClassificationManager.class);
if (tcm != null) {
if (tcm == null) {
return TextClassifier.NO_OP;
}
TextClassificationConstants settings = new TextClassificationConstants();
if (settings.getUseDefaultTextClassifierAsDefaultImplementation()) {
final String defaultTextClassifierPackageName =
context.getPackageManager().getDefaultTextClassifierPackageName();
if (TextUtils.isEmpty(defaultTextClassifierPackageName)) {
return TextClassifier.NO_OP;
}
if (defaultTextClassifierPackageName.equals(context.getPackageName())) {
throw new RuntimeException(
"The default text classifier itself should not call the"
+ "getDefaultTextClassifierImplementation() method.");
}
return tcm.getTextClassifier(TextClassifier.DEFAULT_SERVICE);
} else {
return tcm.getTextClassifier(TextClassifier.LOCAL);
}
return TextClassifier.NO_OP;
}
/** @hide **/
......
......@@ -17,6 +17,7 @@
package android.view.textclassifier;
import android.annotation.Nullable;
import android.content.Context;
import android.provider.DeviceConfig;
import com.android.internal.annotations.VisibleForTesting;
......@@ -167,6 +168,16 @@ public final class TextClassificationConstants {
static final String TEXT_CLASSIFIER_SERVICE_PACKAGE_OVERRIDE =
"textclassifier_service_package_override";
/**
* Whether to use the default system text classifier as the default text classifier
* implementation. The local text classifier is used if it is {@code false}.
*
* @see android.service.textclassifier.TextClassifierService#getDefaultTextClassifierImplementation(Context)
*/
// TODO: Once the system health experiment is done, remove this together with local TC.
private static final String USE_DEFAULT_SYSTEM_TEXT_CLASSIFIER_AS_DEFAULT_IMPL =
"use_default_system_text_classifier_as_default_impl";
private static final String DEFAULT_TEXT_CLASSIFIER_SERVICE_PACKAGE_OVERRIDE = null;
private static final boolean LOCAL_TEXT_CLASSIFIER_ENABLED_DEFAULT = true;
private static final boolean SYSTEM_TEXT_CLASSIFIER_ENABLED_DEFAULT = true;
......@@ -209,7 +220,8 @@ public final class TextClassificationConstants {
private static final boolean TEMPLATE_INTENT_FACTORY_ENABLED_DEFAULT = true;
private static final boolean TRANSLATE_IN_CLASSIFICATION_ENABLED_DEFAULT = true;
private static final boolean DETECT_LANGUAGES_FROM_TEXT_ENABLED_DEFAULT = true;
private static final float[] LANG_ID_CONTEXT_SETTINGS_DEFAULT = new float[] {20f, 1.0f, 0.4f};
private static final float[] LANG_ID_CONTEXT_SETTINGS_DEFAULT = new float[]{20f, 1.0f, 0.4f};
private static final boolean USE_DEFAULT_SYSTEM_TEXT_CLASSIFIER_AS_DEFAULT_IMPL_DEFAULT = true;
@Nullable
public String getTextClassifierServicePackageOverride() {
......@@ -331,6 +343,13 @@ public final class TextClassificationConstants {
LANG_ID_CONTEXT_SETTINGS, LANG_ID_CONTEXT_SETTINGS_DEFAULT);
}
public boolean getUseDefaultTextClassifierAsDefaultImplementation() {
return DeviceConfig.getBoolean(
DeviceConfig.NAMESPACE_TEXTCLASSIFIER,
USE_DEFAULT_SYSTEM_TEXT_CLASSIFIER_AS_DEFAULT_IMPL,
USE_DEFAULT_SYSTEM_TEXT_CLASSIFIER_AS_DEFAULT_IMPL_DEFAULT);
}
void dump(IndentingPrintWriter pw) {
pw.println("TextClassificationConstants:");
pw.increaseIndent();
......@@ -378,6 +397,8 @@ public final class TextClassificationConstants {
.println();
pw.printPair("textclassifier_service_package_override",
getTextClassifierServicePackageOverride()).println();
pw.printPair("use_default_system_text_classifier_as_default_impl",
getUseDefaultTextClassifierAsDefaultImplementation()).println();
pw.decreaseIndent();
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment