Loading core/java/android/view/textclassifier/ActionsSuggestionsHelper.java +31 −2 Original line number Diff line number Diff line Loading @@ -23,10 +23,13 @@ import android.content.Context; import android.text.TextUtils; import android.util.ArrayMap; import android.util.Pair; import android.view.textclassifier.intent.LabeledIntent; import android.view.textclassifier.intent.TemplateIntentFactory; import com.android.internal.annotations.VisibleForTesting; import com.google.android.textclassifier.ActionsSuggestionsModel; import com.google.android.textclassifier.RemoteActionTemplate; import java.util.ArrayDeque; import java.util.ArrayList; Loading @@ -46,6 +49,7 @@ import java.util.stream.Collectors; */ @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE) public final class ActionsSuggestionsHelper { private static final String TAG = "ActionsSuggestions"; private static final int USER_LOCAL = 0; private static final int FIRST_NON_LOCAL_USER = 1; Loading Loading @@ -117,8 +121,33 @@ public final class ActionsSuggestionsHelper { } /** * Returns a {@link android.view.textclassifier.LabeledIntent.TitleChooser} for * conversation actions use case. * Generated labeled intent from an action suggestion and return the resolved result. */ @Nullable public static LabeledIntent.Result createLabeledIntentResult( Context context, TemplateIntentFactory templateIntentFactory, ActionsSuggestionsModel.ActionSuggestion nativeSuggestion) { RemoteActionTemplate[] remoteActionTemplates = nativeSuggestion.getRemoteActionTemplates(); if (remoteActionTemplates == null) { Log.w(TAG, "createRemoteAction: Missing template for type " + nativeSuggestion.getActionType()); return null; } List<LabeledIntent> labeledIntents = templateIntentFactory.create(remoteActionTemplates); if (labeledIntents.isEmpty()) { return null; } // Given that we only support implicit intent here, we should expect there is just one // intent for each action type. LabeledIntent.TitleChooser titleChooser = ActionsSuggestionsHelper.createTitleChooser(nativeSuggestion.getActionType()); return labeledIntents.get(0).resolve(context, titleChooser); } /** * Returns a {@link LabeledIntent.TitleChooser} for conversation actions use case. */ @Nullable public static LabeledIntent.TitleChooser createTitleChooser(String actionType) { Loading core/java/android/view/textclassifier/Log.java +3 −1 Original line number Diff line number Diff line Loading @@ -22,8 +22,10 @@ package android.view.textclassifier; * To enable full log: * 1. adb shell setprop log.tag.androidtc VERBOSE * 2. adb shell stop && adb shell start * * @hide */ final class Log { public final class Log { /** * true: Enables full logging. Loading core/java/android/view/textclassifier/TextClassifierImpl.java +19 −18 Original line number Diff line number Diff line Loading @@ -25,6 +25,11 @@ import android.icu.util.ULocale; import android.os.Bundle; import android.os.LocaleList; import android.os.ParcelFileDescriptor; import android.view.textclassifier.intent.ClassificationIntentFactory; import android.view.textclassifier.intent.LabeledIntent; import android.view.textclassifier.intent.LegacyClassificationIntentFactory; import android.view.textclassifier.intent.TemplateClassificationIntentFactory; import android.view.textclassifier.intent.TemplateIntentFactory; import com.android.internal.annotations.GuardedBy; import com.android.internal.util.IndentingPrintWriter; Loading Loading @@ -110,7 +115,7 @@ public final class TextClassifierImpl implements TextClassifier { private final ModelFileManager mLangIdModelFileManager; private final ModelFileManager mActionsModelFileManager; private final IntentFactory mIntentFactory; private final ClassificationIntentFactory mClassificationIntentFactory; private final TemplateIntentFactory mTemplateIntentFactory; public TextClassifierImpl( Loading Loading @@ -142,10 +147,10 @@ public final class TextClassifierImpl implements TextClassifier { ActionsSuggestionsModel::getLocales)); mTemplateIntentFactory = new TemplateIntentFactory(); mIntentFactory = mSettings.isTemplateIntentFactoryEnabled() mClassificationIntentFactory = mSettings.isTemplateIntentFactoryEnabled() ? new TemplateClassificationIntentFactory( mTemplateIntentFactory, new LegacyIntentFactory()) : new LegacyIntentFactory(); mTemplateIntentFactory, new LegacyClassificationIntentFactory()) : new LegacyClassificationIntentFactory(); } public TextClassifierImpl(Context context, TextClassificationConstants settings) { Loading Loading @@ -435,20 +440,16 @@ public final class TextClassifierImpl implements TextClassifier { if (!expectedTypes.contains(actionType)) { continue; } List<LabeledIntent> labeledIntents = mTemplateIntentFactory.create(nativeSuggestion.getRemoteActionTemplates()); Bundle extras = new Bundle(); LabeledIntent.Result labeledIntentResult = ActionsSuggestionsHelper.createLabeledIntentResult( mContext, mTemplateIntentFactory, nativeSuggestion); RemoteAction remoteAction = null; // Given that we only support implicit intent here, we should expect there is just one // intent for each action type. if (!labeledIntents.isEmpty()) { LabeledIntent.TitleChooser titleChooser = ActionsSuggestionsHelper.createTitleChooser(actionType); LabeledIntent.Result result = labeledIntents.get(0).resolve(mContext, titleChooser); if (result != null) { remoteAction = result.remoteAction; ExtrasUtils.putActionIntent(extras, result.resolvedIntent); } Bundle extras = new Bundle(); if (labeledIntentResult != null) { remoteAction = labeledIntentResult.remoteAction; ExtrasUtils.putActionIntent(extras, labeledIntentResult.resolvedIntent); } conversationActions.add( new ConversationAction.Builder(actionType) Loading Loading @@ -620,7 +621,7 @@ public final class TextClassifierImpl implements TextClassifier { builder.setForeignLanguageExtra(foreignLanguageBundle); boolean isPrimaryAction = true; List<LabeledIntent> labeledIntents = mIntentFactory.create( List<LabeledIntent> labeledIntents = mClassificationIntentFactory.create( mContext, classifiedText, foreignLanguageBundle != null, Loading core/java/android/view/textclassifier/IntentFactory.java→core/java/android/view/textclassifier/intent/ClassificationIntentFactory.java +3 −2 Original line number Diff line number Diff line Loading @@ -13,11 +13,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ package android.view.textclassifier; package android.view.textclassifier.intent; import android.annotation.Nullable; import android.content.Context; import android.content.Intent; import android.view.textclassifier.TextClassifier; import com.google.android.textclassifier.AnnotatorModel; Loading @@ -27,7 +28,7 @@ import java.util.List; /** * @hide */ public interface IntentFactory { public interface ClassificationIntentFactory { /** * Return a list of LabeledIntent from the classification result. Loading core/java/android/view/textclassifier/LabeledIntent.java→core/java/android/view/textclassifier/intent/LabeledIntent.java +3 −1 Original line number Diff line number Diff line Loading @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ package android.view.textclassifier; package android.view.textclassifier.intent; import android.annotation.Nullable; import android.app.PendingIntent; Loading @@ -25,6 +25,8 @@ import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; import android.graphics.drawable.Icon; import android.text.TextUtils; import android.view.textclassifier.Log; import android.view.textclassifier.TextClassification; import com.android.internal.annotations.VisibleForTesting; import com.android.internal.util.Preconditions; Loading Loading
core/java/android/view/textclassifier/ActionsSuggestionsHelper.java +31 −2 Original line number Diff line number Diff line Loading @@ -23,10 +23,13 @@ import android.content.Context; import android.text.TextUtils; import android.util.ArrayMap; import android.util.Pair; import android.view.textclassifier.intent.LabeledIntent; import android.view.textclassifier.intent.TemplateIntentFactory; import com.android.internal.annotations.VisibleForTesting; import com.google.android.textclassifier.ActionsSuggestionsModel; import com.google.android.textclassifier.RemoteActionTemplate; import java.util.ArrayDeque; import java.util.ArrayList; Loading @@ -46,6 +49,7 @@ import java.util.stream.Collectors; */ @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE) public final class ActionsSuggestionsHelper { private static final String TAG = "ActionsSuggestions"; private static final int USER_LOCAL = 0; private static final int FIRST_NON_LOCAL_USER = 1; Loading Loading @@ -117,8 +121,33 @@ public final class ActionsSuggestionsHelper { } /** * Returns a {@link android.view.textclassifier.LabeledIntent.TitleChooser} for * conversation actions use case. * Generated labeled intent from an action suggestion and return the resolved result. */ @Nullable public static LabeledIntent.Result createLabeledIntentResult( Context context, TemplateIntentFactory templateIntentFactory, ActionsSuggestionsModel.ActionSuggestion nativeSuggestion) { RemoteActionTemplate[] remoteActionTemplates = nativeSuggestion.getRemoteActionTemplates(); if (remoteActionTemplates == null) { Log.w(TAG, "createRemoteAction: Missing template for type " + nativeSuggestion.getActionType()); return null; } List<LabeledIntent> labeledIntents = templateIntentFactory.create(remoteActionTemplates); if (labeledIntents.isEmpty()) { return null; } // Given that we only support implicit intent here, we should expect there is just one // intent for each action type. LabeledIntent.TitleChooser titleChooser = ActionsSuggestionsHelper.createTitleChooser(nativeSuggestion.getActionType()); return labeledIntents.get(0).resolve(context, titleChooser); } /** * Returns a {@link LabeledIntent.TitleChooser} for conversation actions use case. */ @Nullable public static LabeledIntent.TitleChooser createTitleChooser(String actionType) { Loading
core/java/android/view/textclassifier/Log.java +3 −1 Original line number Diff line number Diff line Loading @@ -22,8 +22,10 @@ package android.view.textclassifier; * To enable full log: * 1. adb shell setprop log.tag.androidtc VERBOSE * 2. adb shell stop && adb shell start * * @hide */ final class Log { public final class Log { /** * true: Enables full logging. Loading
core/java/android/view/textclassifier/TextClassifierImpl.java +19 −18 Original line number Diff line number Diff line Loading @@ -25,6 +25,11 @@ import android.icu.util.ULocale; import android.os.Bundle; import android.os.LocaleList; import android.os.ParcelFileDescriptor; import android.view.textclassifier.intent.ClassificationIntentFactory; import android.view.textclassifier.intent.LabeledIntent; import android.view.textclassifier.intent.LegacyClassificationIntentFactory; import android.view.textclassifier.intent.TemplateClassificationIntentFactory; import android.view.textclassifier.intent.TemplateIntentFactory; import com.android.internal.annotations.GuardedBy; import com.android.internal.util.IndentingPrintWriter; Loading Loading @@ -110,7 +115,7 @@ public final class TextClassifierImpl implements TextClassifier { private final ModelFileManager mLangIdModelFileManager; private final ModelFileManager mActionsModelFileManager; private final IntentFactory mIntentFactory; private final ClassificationIntentFactory mClassificationIntentFactory; private final TemplateIntentFactory mTemplateIntentFactory; public TextClassifierImpl( Loading Loading @@ -142,10 +147,10 @@ public final class TextClassifierImpl implements TextClassifier { ActionsSuggestionsModel::getLocales)); mTemplateIntentFactory = new TemplateIntentFactory(); mIntentFactory = mSettings.isTemplateIntentFactoryEnabled() mClassificationIntentFactory = mSettings.isTemplateIntentFactoryEnabled() ? new TemplateClassificationIntentFactory( mTemplateIntentFactory, new LegacyIntentFactory()) : new LegacyIntentFactory(); mTemplateIntentFactory, new LegacyClassificationIntentFactory()) : new LegacyClassificationIntentFactory(); } public TextClassifierImpl(Context context, TextClassificationConstants settings) { Loading Loading @@ -435,20 +440,16 @@ public final class TextClassifierImpl implements TextClassifier { if (!expectedTypes.contains(actionType)) { continue; } List<LabeledIntent> labeledIntents = mTemplateIntentFactory.create(nativeSuggestion.getRemoteActionTemplates()); Bundle extras = new Bundle(); LabeledIntent.Result labeledIntentResult = ActionsSuggestionsHelper.createLabeledIntentResult( mContext, mTemplateIntentFactory, nativeSuggestion); RemoteAction remoteAction = null; // Given that we only support implicit intent here, we should expect there is just one // intent for each action type. if (!labeledIntents.isEmpty()) { LabeledIntent.TitleChooser titleChooser = ActionsSuggestionsHelper.createTitleChooser(actionType); LabeledIntent.Result result = labeledIntents.get(0).resolve(mContext, titleChooser); if (result != null) { remoteAction = result.remoteAction; ExtrasUtils.putActionIntent(extras, result.resolvedIntent); } Bundle extras = new Bundle(); if (labeledIntentResult != null) { remoteAction = labeledIntentResult.remoteAction; ExtrasUtils.putActionIntent(extras, labeledIntentResult.resolvedIntent); } conversationActions.add( new ConversationAction.Builder(actionType) Loading Loading @@ -620,7 +621,7 @@ public final class TextClassifierImpl implements TextClassifier { builder.setForeignLanguageExtra(foreignLanguageBundle); boolean isPrimaryAction = true; List<LabeledIntent> labeledIntents = mIntentFactory.create( List<LabeledIntent> labeledIntents = mClassificationIntentFactory.create( mContext, classifiedText, foreignLanguageBundle != null, Loading
core/java/android/view/textclassifier/IntentFactory.java→core/java/android/view/textclassifier/intent/ClassificationIntentFactory.java +3 −2 Original line number Diff line number Diff line Loading @@ -13,11 +13,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ package android.view.textclassifier; package android.view.textclassifier.intent; import android.annotation.Nullable; import android.content.Context; import android.content.Intent; import android.view.textclassifier.TextClassifier; import com.google.android.textclassifier.AnnotatorModel; Loading @@ -27,7 +28,7 @@ import java.util.List; /** * @hide */ public interface IntentFactory { public interface ClassificationIntentFactory { /** * Return a list of LabeledIntent from the classification result. Loading
core/java/android/view/textclassifier/LabeledIntent.java→core/java/android/view/textclassifier/intent/LabeledIntent.java +3 −1 Original line number Diff line number Diff line Loading @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ package android.view.textclassifier; package android.view.textclassifier.intent; import android.annotation.Nullable; import android.app.PendingIntent; Loading @@ -25,6 +25,8 @@ import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; import android.graphics.drawable.Icon; import android.text.TextUtils; import android.view.textclassifier.Log; import android.view.textclassifier.TextClassification; import com.android.internal.annotations.VisibleForTesting; import com.android.internal.util.Preconditions; Loading