Support title_with_entity and title_without_entity
1. Pull out TextClassifierImpl.LabeledIntent to LabeledIntent.
2. LabeledIntent.resolves takes a TitleChooser object, which
allow custom logic like "if the resolved app is a browser, use
title_with_entity. Otherwise, use title_without_entity".
If TitleChooser is not set, the default behavior is to use
title_with_entity if provided, use title_without_entity otherwise.
3. For classifyText, we use a TitleChooser that always return
title_without_entity. So no behavior change in classifyText.
4. If custom titleChooser returns null, fallback to use the default
titleChooser.
BUG: 124428508
BUG: 123946471
Test: atest framework/base/core/tests/coretests/src/android/view/textclassifier/
Change-Id: I7299c40ffc57deb9484d493f8c62b220a5a1e7d8
diff --git a/core/java/android/view/textclassifier/ActionsSuggestionsHelper.java b/core/java/android/view/textclassifier/ActionsSuggestionsHelper.java
index 4d917a1..efdc968 100644
--- a/core/java/android/view/textclassifier/ActionsSuggestionsHelper.java
+++ b/core/java/android/view/textclassifier/ActionsSuggestionsHelper.java
@@ -16,6 +16,7 @@
package android.view.textclassifier;
+import android.annotation.Nullable;
import android.app.Person;
import android.content.Context;
import android.text.TextUtils;
@@ -110,6 +111,19 @@
SelectionSessionLogger.CLASSIFIER_ID, modelName, hash);
}
+ /**
+ * Returns a {@link android.view.textclassifier.LabeledIntent.TitleChooser} for
+ * conversation actions use case.
+ */
+ @Nullable
+ public static LabeledIntent.TitleChooser createTitleChooser(String actionType) {
+ if (ConversationAction.TYPE_OPEN_URL.equals(actionType)) {
+ return (labeledIntent, resolveInfo) -> resolveInfo.handleAllWebDataURI
+ ? labeledIntent.titleWithEntity : labeledIntent.titleWithoutEntity;
+ }
+ return null;
+ }
+
private static final class PersonEncoder {
private final Map<Person, Integer> mMapping = new ArrayMap<>();
private int mNextUserId = FIRST_NON_LOCAL_USER;