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

Commit c5a4612f authored by Tony Mak's avatar Tony Mak
Browse files

Introduce EXTRA_FROM_TEXT_CLASSIFIER

To indicate the intent is from text classifier, so apps can log
the traffic from text classifier.

Test: atest IntentFactoryTest
Test: atest TextClassifierTest
BUG: 120944241

Change-Id: I6584504a39c0db3c1de1eaab6915b26b30adadcd
parent 0f856197
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -52603,6 +52603,7 @@ package android.view.textclassifier {
    method public default android.view.textclassifier.ConversationActions suggestConversationActions(android.view.textclassifier.ConversationActions.Request);
    method public default android.view.textclassifier.TextSelection suggestSelection(android.view.textclassifier.TextSelection.Request);
    method public default android.view.textclassifier.TextSelection suggestSelection(java.lang.CharSequence, int, int, android.os.LocaleList);
    field public static final java.lang.String EXTRA_FROM_TEXT_CLASSIFIER = "android.view.textclassifier.extra.FROM_TEXT_CLASSIFIER";
    field public static final java.lang.String HINT_TEXT_IS_EDITABLE = "android.text_is_editable";
    field public static final java.lang.String HINT_TEXT_IS_NOT_EDITABLE = "android.text_is_not_editable";
    field public static final android.view.textclassifier.TextClassifier NO_OP;
+8 −0
Original line number Diff line number Diff line
@@ -161,6 +161,14 @@ public interface TextClassifier {
     */
    TextClassifier NO_OP = new TextClassifier() {};

    /**
     * Used as a boolean value to indicate the intent is generated by TextClassifier.
     * <p>
     * All {@link TextClassifier} implementations should set this boolean extra to be true in their
     * generated intents.
     */
    String EXTRA_FROM_TEXT_CLASSIFIER = "android.view.textclassifier.extra.FROM_TEXT_CLASSIFIER";

    /**
     * Returns suggested text selection start and end indices, recognized entity types, and their
     * associated confidence scores. The entity types are ordered from highest to lowest scoring.
+4 −1
Original line number Diff line number Diff line
@@ -139,7 +139,7 @@ public final class TextClassifierImpl implements TextClassifier {
                        FACTORY_MODEL_DIR,
                        LANG_ID_FACTORY_MODEL_FILENAME_REGEX,
                        UPDATED_LANG_ID_MODEL_FILE,
                        fd -> -1, // TODO: Replace this with LangIdModel.getVersion(fd)
                        LangIdModel::getVersion,
                        fd -> ModelFileManager.ModelFile.LANGUAGE_INDEPENDENT));
        mActionsModelFileManager = new ModelFileManager(
                new ModelFileManager.ModelFileSupplierImpl(
@@ -777,6 +777,9 @@ public final class TextClassifierImpl implements TextClassifier {
            if (foreignText) {
                insertTranslateAction(actions, context, text);
            }
            actions.forEach(
                    action -> action.getIntent()
                            .putExtra(TextClassifier.EXTRA_FROM_TEXT_CLASSIFIER, true));
            return actions;
        }

+2 −0
Original line number Diff line number Diff line
@@ -56,5 +56,7 @@ public class IntentFactoryTest {
        Intent intent = labeledIntent.getIntent();
        assertThat(intent.getAction()).isEqualTo(Intent.ACTION_DEFINE);
        assertThat(intent.getStringExtra(Intent.EXTRA_TEXT)).isEqualTo(TEXT);
        assertThat(
                intent.getBooleanExtra(TextClassifier.EXTRA_FROM_TEXT_CLASSIFIER, false)).isTrue();
    }
}