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

Commit 6d063371 authored by Abodunrinwa Toki's avatar Abodunrinwa Toki Committed by Tony Mak
Browse files

Split TextClassifierEvent into multiple subclasses

As per the suggestion from API council, we now have a subclass for event
of each category.

Bug: 129344540

Test: atest frameworks/base/core/tests/coretests/src/android/view/textclassifier/
Test: atest cts/tests/tests/view/src/android/view/textclassifier/cts/
Test: atest frameworks/base/packages/ExtServices/tests/src/android/ext/services/notification/SmartActionsHelperTest.java

Change-Id: Ic43b33c2176447c40e64bd0e410e906d5fb9c4cc
parent 9214de57
Loading
Loading
Loading
Loading
+60 −28
Original line number Diff line number Diff line
@@ -53863,29 +53863,23 @@ package android.view.textclassifier {
    method @NonNull public android.view.textclassifier.TextClassifier.EntityConfig.Builder setIncludedTypes(@Nullable java.util.Collection<java.lang.String>);
  }
  public final class TextClassifierEvent implements android.os.Parcelable {
  public abstract class TextClassifierEvent implements android.os.Parcelable {
    method public int describeContents();
    method @NonNull public int[] getActionIndices();
    method @NonNull public String[] getEntityTypes();
    method public int getEventCategory();
    method @Nullable public android.view.textclassifier.TextClassificationContext getEventContext();
    method public int getEventIndex();
    method public long getEventTime();
    method public int getEventType();
    method @NonNull public android.os.Bundle getExtras();
    method @Nullable public String getLanguage();
    method public int getRelativeSuggestedWordEndIndex();
    method public int getRelativeSuggestedWordStartIndex();
    method public int getRelativeWordEndIndex();
    method public int getRelativeWordStartIndex();
    method @Nullable public String getModelName();
    method @Nullable public String getResultId();
    method public float getScore();
    method @NonNull public float[] getScores();
    method public void writeToParcel(android.os.Parcel, int);
    field public static final int CATEGORY_CONVERSATION_ACTIONS = 3; // 0x3
    field public static final int CATEGORY_LANGUAGE_DETECTION = 4; // 0x4
    field public static final int CATEGORY_LINKIFY = 2; // 0x2
    field public static final int CATEGORY_SELECTION = 1; // 0x1
    field public static final int CATEGORY_UNDEFINED = 0; // 0x0
    field @NonNull public static final android.os.Parcelable.Creator<android.view.textclassifier.TextClassifierEvent> CREATOR;
    field public static final int TYPE_ACTIONS_GENERATED = 20; // 0x14
    field public static final int TYPE_ACTIONS_SHOWN = 6; // 0x6
@@ -53907,25 +53901,63 @@ package android.view.textclassifier {
    field public static final int TYPE_SMART_ACTION = 13; // 0xd
    field public static final int TYPE_SMART_SELECTION_MULTI = 4; // 0x4
    field public static final int TYPE_SMART_SELECTION_SINGLE = 3; // 0x3
    field public static final int TYPE_UNDEFINED = 0; // 0x0
  }
  public static final class TextClassifierEvent.Builder {
    ctor public TextClassifierEvent.Builder(int, int);
    method @NonNull public android.view.textclassifier.TextClassifierEvent build();
    method @NonNull public android.view.textclassifier.TextClassifierEvent.Builder setActionIndices(@NonNull int...);
    method @NonNull public android.view.textclassifier.TextClassifierEvent.Builder setEntityTypes(@NonNull java.lang.String...);
    method @NonNull public android.view.textclassifier.TextClassifierEvent.Builder setEventContext(@Nullable android.view.textclassifier.TextClassificationContext);
    method @NonNull public android.view.textclassifier.TextClassifierEvent.Builder setEventIndex(int);
    method @NonNull public android.view.textclassifier.TextClassifierEvent.Builder setEventTime(long);
    method @NonNull public android.view.textclassifier.TextClassifierEvent.Builder setExtras(@NonNull android.os.Bundle);
    method @NonNull public android.view.textclassifier.TextClassifierEvent.Builder setLanguage(@Nullable String);
    method @NonNull public android.view.textclassifier.TextClassifierEvent.Builder setRelativeSuggestedWordEndIndex(int);
    method @NonNull public android.view.textclassifier.TextClassifierEvent.Builder setRelativeSuggestedWordStartIndex(int);
    method @NonNull public android.view.textclassifier.TextClassifierEvent.Builder setRelativeWordEndIndex(int);
    method @NonNull public android.view.textclassifier.TextClassifierEvent.Builder setRelativeWordStartIndex(int);
    method @NonNull public android.view.textclassifier.TextClassifierEvent.Builder setResultId(@Nullable String);
    method @NonNull public android.view.textclassifier.TextClassifierEvent.Builder setScore(float);
  }
  public abstract static class TextClassifierEvent.Builder<T extends android.view.textclassifier.TextClassifierEvent.Builder<T>> {
    method @NonNull public T setActionIndices(@NonNull int...);
    method @NonNull public T setEntityTypes(@NonNull java.lang.String...);
    method @NonNull public T setEventContext(@Nullable android.view.textclassifier.TextClassificationContext);
    method @NonNull public T setEventIndex(int);
    method @NonNull public T setExtras(@NonNull android.os.Bundle);
    method @NonNull public T setModelName(@Nullable String);
    method @NonNull public T setResultId(@Nullable String);
    method @NonNull public T setScores(@NonNull float...);
  }
  public static final class TextClassifierEvent.ConversationActionsEvent extends android.view.textclassifier.TextClassifierEvent implements android.os.Parcelable {
    field @NonNull public static final android.os.Parcelable.Creator<android.view.textclassifier.TextClassifierEvent.ConversationActionsEvent> CREATOR;
  }
  public static final class TextClassifierEvent.ConversationActionsEvent.Builder extends android.view.textclassifier.TextClassifierEvent.Builder<android.view.textclassifier.TextClassifierEvent.ConversationActionsEvent.Builder> {
    ctor public TextClassifierEvent.ConversationActionsEvent.Builder(int);
    method @NonNull public android.view.textclassifier.TextClassifierEvent.ConversationActionsEvent build();
  }
  public static final class TextClassifierEvent.LanguageDetectionEvent extends android.view.textclassifier.TextClassifierEvent implements android.os.Parcelable {
    method @Nullable public android.icu.util.ULocale getLocale();
    field @NonNull public static final android.os.Parcelable.Creator<android.view.textclassifier.TextClassifierEvent.LanguageDetectionEvent> CREATOR;
  }
  public static final class TextClassifierEvent.LanguageDetectionEvent.Builder extends android.view.textclassifier.TextClassifierEvent.Builder<android.view.textclassifier.TextClassifierEvent.LanguageDetectionEvent.Builder> {
    ctor public TextClassifierEvent.LanguageDetectionEvent.Builder(int);
    method @NonNull public android.view.textclassifier.TextClassifierEvent.LanguageDetectionEvent build();
    method @NonNull public android.view.textclassifier.TextClassifierEvent.LanguageDetectionEvent.Builder setLocale(@Nullable android.icu.util.ULocale);
  }
  public static final class TextClassifierEvent.TextLinkifyEvent extends android.view.textclassifier.TextClassifierEvent implements android.os.Parcelable {
    field @NonNull public static final android.os.Parcelable.Creator<android.view.textclassifier.TextClassifierEvent.TextLinkifyEvent> CREATOR;
  }
  public static final class TextClassifierEvent.TextLinkifyEvent.Builder extends android.view.textclassifier.TextClassifierEvent.Builder<android.view.textclassifier.TextClassifierEvent.TextLinkifyEvent.Builder> {
    ctor public TextClassifierEvent.TextLinkifyEvent.Builder(int);
    method @NonNull public android.view.textclassifier.TextClassifierEvent.TextLinkifyEvent build();
  }
  public static final class TextClassifierEvent.TextSelectionEvent extends android.view.textclassifier.TextClassifierEvent implements android.os.Parcelable {
    method public int getRelativeSuggestedWordEndIndex();
    method public int getRelativeSuggestedWordStartIndex();
    method public int getRelativeWordEndIndex();
    method public int getRelativeWordStartIndex();
    field @NonNull public static final android.os.Parcelable.Creator<android.view.textclassifier.TextClassifierEvent.TextSelectionEvent> CREATOR;
  }
  public static final class TextClassifierEvent.TextSelectionEvent.Builder extends android.view.textclassifier.TextClassifierEvent.Builder<android.view.textclassifier.TextClassifierEvent.TextSelectionEvent.Builder> {
    ctor public TextClassifierEvent.TextSelectionEvent.Builder(int);
    method @NonNull public android.view.textclassifier.TextClassifierEvent.TextSelectionEvent build();
    method @NonNull public android.view.textclassifier.TextClassifierEvent.TextSelectionEvent.Builder setRelativeSuggestedWordEndIndex(int);
    method @NonNull public android.view.textclassifier.TextClassifierEvent.TextSelectionEvent.Builder setRelativeSuggestedWordStartIndex(int);
    method @NonNull public android.view.textclassifier.TextClassifierEvent.TextSelectionEvent.Builder setRelativeWordEndIndex(int);
    method @NonNull public android.view.textclassifier.TextClassifierEvent.TextSelectionEvent.Builder setRelativeWordStartIndex(int);
  }
  public final class TextLanguage implements android.os.Parcelable {
+732 −287

File changed.

Preview size limit exceeded, changes collapsed.

+4 −3
Original line number Diff line number Diff line
@@ -65,9 +65,10 @@ public final class TextClassifierEventTronLogger {
        final LogMaker log = new LogMaker(category)
                .setSubtype(getLogType(event))
                .addTaggedData(FIELD_TEXT_CLASSIFIER_SESSION_ID, event.getResultId())
                .addTaggedData(FIELD_TEXTCLASSIFIER_MODEL, getModelName(event))
                .addTaggedData(FIELD_TEXT_CLASSIFIER_SCORE, event.getScore());

                .addTaggedData(FIELD_TEXTCLASSIFIER_MODEL, getModelName(event));
        if (event.getScores().length >= 1) {
            log.addTaggedData(FIELD_TEXT_CLASSIFIER_SCORE, event.getScores()[0]);
        }
        String[] entityTypes = event.getEntityTypes();
        // The old logger does not support a field of list type, and thus workaround by store them
        // in three separate fields. This is not an issue with the new logger.
+2 −3
Original line number Diff line number Diff line
@@ -933,12 +933,11 @@ public final class SelectionActionModeHelper {
            final String language = ExtrasUtils.getEntityType(foreignLanguageExtra);
            final float score = ExtrasUtils.getScore(foreignLanguageExtra);
            final String model = ExtrasUtils.getModelName(foreignLanguageExtra);
            return new TextClassifierEvent.Builder(
                    TextClassifierEvent.CATEGORY_LANGUAGE_DETECTION, eventType)
            return new TextClassifierEvent.LanguageDetectionEvent.Builder(eventType)
                    .setEventContext(classificationContext)
                    .setResultId(classification.getId())
                    .setEntityTypes(language)
                    .setScore(score)
                    .setScores(score)
                    .setActionIndices(classification.getActions().indexOf(translateAction))
                    .setModelName(model)
                    .build();
+7 −14
Original line number Diff line number Diff line
@@ -49,8 +49,6 @@ import org.mockito.MockitoAnnotations;
public class TextClassifierEventTronLoggerTest {
    private static final String WIDGET_TYPE = "notification";
    private static final String PACKAGE_NAME = "pkg";
    private static final long EVENT_TIME = System.currentTimeMillis();


    @Mock
    private MetricsLogger mMetricsLogger;
@@ -68,13 +66,11 @@ public class TextClassifierEventTronLoggerTest {
        TextClassificationContext textClassificationContext =
                new TextClassificationContext.Builder(PACKAGE_NAME, WIDGET_TYPE)
                        .build();
        TextClassifierEvent textClassifierEvent =
                new TextClassifierEvent.Builder(
                        TextClassifierEvent.CATEGORY_CONVERSATION_ACTIONS,
        TextClassifierEvent.ConversationActionsEvent textClassifierEvent =
                new TextClassifierEvent.ConversationActionsEvent.Builder(
                        TextClassifierEvent.TYPE_SMART_ACTION)
                        .setEntityTypes(ConversationAction.TYPE_CALL_PHONE)
                        .setScore(0.5f)
                        .setEventTime(EVENT_TIME)
                        .setScores(0.5f)
                        .setEventContext(textClassificationContext)
                        .build();

@@ -83,10 +79,8 @@ public class TextClassifierEventTronLoggerTest {
        ArgumentCaptor<LogMaker> captor = ArgumentCaptor.forClass(LogMaker.class);
        Mockito.verify(mMetricsLogger).write(captor.capture());
        LogMaker logMaker = captor.getValue();
        assertThat(logMaker.getCategory()).isEqualTo(
                CONVERSATION_ACTIONS);
        assertThat(logMaker.getSubtype()).isEqualTo(
                ACTION_TEXT_SELECTION_SMART_SHARE);
        assertThat(logMaker.getCategory()).isEqualTo(CONVERSATION_ACTIONS);
        assertThat(logMaker.getSubtype()).isEqualTo(ACTION_TEXT_SELECTION_SMART_SHARE);
        assertThat(logMaker.getTaggedData(FIELD_TEXT_CLASSIFIER_FIRST_ENTITY_TYPE))
                .isEqualTo(ConversationAction.TYPE_CALL_PHONE);
        assertThat((float) logMaker.getTaggedData(FIELD_TEXT_CLASSIFIER_SCORE))
@@ -101,9 +95,8 @@ public class TextClassifierEventTronLoggerTest {

    @Test
    public void testWriteEvent_unsupportedCategory() {
        TextClassifierEvent textClassifierEvent =
                new TextClassifierEvent.Builder(
                        TextClassifierEvent.CATEGORY_SELECTION,
        TextClassifierEvent.TextSelectionEvent textClassifierEvent =
                new TextClassifierEvent.TextSelectionEvent.Builder(
                        TextClassifierEvent.TYPE_SMART_ACTION)
                        .build();

Loading