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

Commit 20d346ea authored by Jan Althaus's avatar Jan Althaus
Browse files

Change TextClassification to use RemoteActions

Behavioural changes:
- Every action now as an icon, and instead hints via RemoteAction whether
  the icon should be shown or not.
- Icons are now taken from the app default, not the activity.
  (That way, we can construct a lightweight resource backed Icon)
- Legacy intents are no longer parceled for security reasons.
  (TextClassificatio wasn't parcelable in O)
- TextClassifications built with the new API will always return null for
  getIntent, but provide a getOnClickListener.
- Accessibility descriptions are now provided for action mode items.

Testing changes:
- Removed URI checks from TCM test because PendingIntent hides this info.

Bug: 73950205
Test: atest FrameworksCoreTests:TextClassificationManagerTest
Test: atest FrameworksCoreTests:TextClassificationTest
Test: atest CtsViewTestCases:TextClassificationManagerTest
Test: atest CtsViewTestCases:TextClassifierValueObjectsTest
Test: atest CtsWidgetTestCases:TextViewTest
Test: atest CtsWidgetTestCases:EditTextTest
Change-Id: I6706d2c342a8bbb9de0146a48c8b8aac9d9c7d83
parent 0d5bbf77
Loading
Loading
Loading
Loading
+12 −15
Original line number Diff line number Diff line
@@ -5877,6 +5877,8 @@ package android.app {
    method public java.lang.CharSequence getTitle();
    method public boolean isEnabled();
    method public void setEnabled(boolean);
    method public void setShouldShowIcon(boolean);
    method public boolean shouldShowIcon();
    method public void writeToParcel(android.os.Parcel, int);
    field public static final android.os.Parcelable.Creator<android.app.RemoteAction> CREATOR;
  }
@@ -50342,17 +50344,14 @@ package android.view.textclassifier {
  public final class TextClassification implements android.os.Parcelable {
    method public int describeContents();
    method public java.util.List<android.app.RemoteAction> getActions();
    method public float getConfidenceScore(java.lang.String);
    method public java.lang.String getEntity(int);
    method public int getEntityCount();
    method public android.graphics.drawable.Drawable getIcon();
    method public android.content.Intent getIntent();
    method public java.lang.CharSequence getLabel();
    method public android.view.View.OnClickListener getOnClickListener();
    method public int getSecondaryActionsCount();
    method public android.graphics.drawable.Drawable getSecondaryIcon(int);
    method public android.content.Intent getSecondaryIntent(int);
    method public java.lang.CharSequence getSecondaryLabel(int);
    method public deprecated android.graphics.drawable.Drawable getIcon();
    method public deprecated android.content.Intent getIntent();
    method public deprecated java.lang.CharSequence getLabel();
    method public deprecated android.view.View.OnClickListener getOnClickListener();
    method public java.lang.String getSignature();
    method public java.lang.String getText();
    method public void writeToParcel(android.os.Parcel, int);
@@ -50361,15 +50360,13 @@ package android.view.textclassifier {
  public static final class TextClassification.Builder {
    ctor public TextClassification.Builder();
    method public android.view.textclassifier.TextClassification.Builder addSecondaryAction(android.content.Intent, java.lang.String, android.graphics.drawable.Drawable);
    method public android.view.textclassifier.TextClassification.Builder addAction(android.app.RemoteAction);
    method public android.view.textclassifier.TextClassification build();
    method public android.view.textclassifier.TextClassification.Builder clearSecondaryActions();
    method public android.view.textclassifier.TextClassification.Builder setEntityType(java.lang.String, float);
    method public android.view.textclassifier.TextClassification.Builder setIcon(android.graphics.drawable.Drawable);
    method public android.view.textclassifier.TextClassification.Builder setIntent(android.content.Intent);
    method public android.view.textclassifier.TextClassification.Builder setLabel(java.lang.String);
    method public android.view.textclassifier.TextClassification.Builder setOnClickListener(android.view.View.OnClickListener);
    method public android.view.textclassifier.TextClassification.Builder setPrimaryAction(android.content.Intent, java.lang.String, android.graphics.drawable.Drawable);
    method public deprecated android.view.textclassifier.TextClassification.Builder setIcon(android.graphics.drawable.Drawable);
    method public deprecated android.view.textclassifier.TextClassification.Builder setIntent(android.content.Intent);
    method public deprecated android.view.textclassifier.TextClassification.Builder setLabel(java.lang.String);
    method public deprecated android.view.textclassifier.TextClassification.Builder setOnClickListener(android.view.View.OnClickListener);
    method public android.view.textclassifier.TextClassification.Builder setSignature(java.lang.String);
    method public android.view.textclassifier.TextClassification.Builder setText(java.lang.String);
  }
+19 −5
Original line number Diff line number Diff line
@@ -18,14 +18,9 @@ package android.app;

import android.annotation.NonNull;
import android.graphics.drawable.Icon;
import android.os.Handler;
import android.os.Message;
import android.os.Messenger;
import android.os.Parcel;
import android.os.Parcelable;
import android.os.RemoteException;
import android.text.TextUtils;
import android.util.Log;

import java.io.PrintWriter;

@@ -42,6 +37,7 @@ public final class RemoteAction implements Parcelable {
    private final CharSequence mContentDescription;
    private final PendingIntent mActionIntent;
    private boolean mEnabled;
    private boolean mShouldShowIcon;

    RemoteAction(Parcel in) {
        mIcon = Icon.CREATOR.createFromParcel(in);
@@ -49,6 +45,7 @@ public final class RemoteAction implements Parcelable {
        mContentDescription = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in);
        mActionIntent = PendingIntent.CREATOR.createFromParcel(in);
        mEnabled = in.readBoolean();
        mShouldShowIcon = in.readBoolean();
    }

    public RemoteAction(@NonNull Icon icon, @NonNull CharSequence title,
@@ -62,6 +59,7 @@ public final class RemoteAction implements Parcelable {
        mContentDescription = contentDescription;
        mActionIntent = intent;
        mEnabled = true;
        mShouldShowIcon = true;
    }

    /**
@@ -78,6 +76,20 @@ public final class RemoteAction implements Parcelable {
        return mEnabled;
    }

    /**
     * Sets whether the icon should be shown.
     */
    public void setShouldShowIcon(boolean shouldShowIcon) {
        mShouldShowIcon = shouldShowIcon;
    }

    /**
     * Return whether the icon should be shown.
     */
    public boolean shouldShowIcon() {
        return mShouldShowIcon;
    }

    /**
     * Return an icon representing the action.
     */
@@ -125,6 +137,7 @@ public final class RemoteAction implements Parcelable {
        TextUtils.writeToParcel(mContentDescription, out, flags);
        mActionIntent.writeToParcel(out, flags);
        out.writeBoolean(mEnabled);
        out.writeBoolean(mShouldShowIcon);
    }

    public void dump(String prefix, PrintWriter pw) {
@@ -134,6 +147,7 @@ public final class RemoteAction implements Parcelable {
        pw.print(" contentDescription=" + mContentDescription);
        pw.print(" icon=" + mIcon);
        pw.print(" action=" + mActionIntent.getIntent());
        pw.print(" shouldShowIcon=" + mShouldShowIcon);
        pw.println();
    }

+119 −236

File changed.

Preview size limit exceeded, changes collapsed.

+153 −137

File changed.

Preview size limit exceeded, changes collapsed.

+38 −38

File changed.

Preview size limit exceeded, changes collapsed.

Loading