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

Commit bed22940 authored by Nikita Dubrovsky's avatar Nikita Dubrovsky Committed by Android (Google) Code Review
Browse files

Merge "Add debug logging for RichContentReceiver"

parents e0dac877 d3adf5e5
Loading
Loading
Loading
Loading
+28 −0
Original line number Diff line number Diff line
@@ -203,4 +203,32 @@ public interface RichContentReceiver<T extends View> {
        }
        return false;
    }

    /**
     * Returns the symbolic name of the given source.
     *
     * @hide
     */
    static String sourceToString(@Source int source) {
        switch (source) {
            case SOURCE_CLIPBOARD: return "SOURCE_CLIPBOARD";
            case SOURCE_INPUT_METHOD: return "SOURCE_INPUT_METHOD";
            case SOURCE_DRAG_AND_DROP: return "SOURCE_DRAG_AND_DROP";
            case SOURCE_AUTOFILL: return "SOURCE_AUTOFILL";
            case SOURCE_PROCESS_TEXT: return "SOURCE_PROCESS_TEXT";
        }
        return String.valueOf(source);
    }

    /**
     * Returns the symbolic names of the set flags or {@code "0"} if no flags are set.
     *
     * @hide
     */
    static String flagsToString(@Flags int flags) {
        if ((flags & FLAG_CONVERT_TO_PLAIN_TEXT) != 0) {
            return "FLAG_CONVERT_TO_PLAIN_TEXT";
        }
        return String.valueOf(flags);
    }
}
+14 −0
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import android.text.Editable;
import android.text.Selection;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.util.Log;

import java.util.Collections;
import java.util.Set;
@@ -40,6 +41,8 @@ import java.util.Set;
final class TextViewRichContentReceiver implements RichContentReceiver<TextView> {
    static final TextViewRichContentReceiver INSTANCE = new TextViewRichContentReceiver();

    private static final String LOG_TAG = "RichContentReceiver";

    private static final Set<String> MIME_TYPES_ALL_TEXT = Collections.singleton("text/*");

    @Override
@@ -50,6 +53,17 @@ final class TextViewRichContentReceiver implements RichContentReceiver<TextView>
    @Override
    public boolean onReceive(@NonNull TextView textView, @NonNull ClipData clip,
            @Source int source, @Flags int flags) {
        if (Log.isLoggable(LOG_TAG, Log.DEBUG)) {
            StringBuilder sb = new StringBuilder("onReceive: clip=");
            if (clip.getDescription() == null) {
                sb.append("null");
            } else {
                clip.getDescription().toShortStringTypesOnly(sb);
            }
            sb.append(", source=").append(RichContentReceiver.sourceToString(source));
            sb.append(", flags=").append(RichContentReceiver.flagsToString(flags));
            Log.d(LOG_TAG, sb.toString());
        }
        if (source == SOURCE_AUTOFILL) {
            return onReceiveForAutofill(textView, clip, flags);
        }