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

Commit e95a3641 authored by Nikita Dubrovsky's avatar Nikita Dubrovsky
Browse files

Update ClipData.toString and related code to not leak common forms of PII

Bug: 171732792
Test: atest CtsContentTestCases:ClipDataTest
Change-Id: I530795fb8bf6d69e33c1122b1cf8b9e9e4c6aee4
parent 1086c93f
Loading
Loading
Loading
Loading
+58 −47
Original line number Diff line number Diff line
@@ -651,45 +651,57 @@ public class ClipData implements Parcelable {
            StringBuilder b = new StringBuilder(128);

            b.append("ClipData.Item { ");
            toShortString(b);
            toShortString(b, true);
            b.append(" }");

            return b.toString();
        }

        /** @hide */
        public void toShortString(StringBuilder b) {
        /**
         * Appends this item to the given builder.
         * @param redactContent If true, redacts common forms of PII; otherwise appends full
         *                      details.
         * @hide
         */
        public void toShortString(StringBuilder b, boolean redactContent) {
            boolean first = true;
            if (mHtmlText != null) {
                b.append("H:");
                b.append(mHtmlText);
            } else if (mText != null) {
                b.append("T:");
                b.append(mText);
            } else if (mUri != null) {
                b.append("U:");
                b.append(mUri);
            } else if (mIntent != null) {
                b.append("I:");
                mIntent.toShortString(b, true, true, true, true);
                first = false;
                if (redactContent) {
                    b.append("H(").append(mHtmlText.length()).append(')');
                } else {
                b.append("NULL");
                    b.append("H:").append(mHtmlText);
                }
            }

        /** @hide */
        public void toShortSummaryString(StringBuilder b) {
            if (mHtmlText != null) {
                b.append("HTML");
            } else if (mText != null) {
                b.append("TEXT");
            } else if (mUri != null) {
                b.append("U:");
                b.append(mUri);
            } else if (mIntent != null) {
                b.append("I:");
                mIntent.toShortString(b, true, true, true, true);
            if (mText != null) {
                if (!first) {
                    b.append(' ');
                }
                first = false;
                if (redactContent) {
                    b.append("T(").append(mText.length()).append(')');
                } else {
                    b.append("T:").append(mText);
                }
            }
            if (mUri != null) {
                if (!first) {
                    b.append(' ');
                }
                first = false;
                if (redactContent) {
                    b.append("U(").append(mUri.getScheme()).append(')');
                } else {
                b.append("NULL");
                    b.append("U:").append(mUri);
                }
            }
            if (mIntent != null) {
                if (!first) {
                    b.append(' ');
                }
                first = false;
                b.append("I:");
                mIntent.toShortString(b, redactContent, true, true, true);
            }
        }

@@ -1040,17 +1052,21 @@ public class ClipData implements Parcelable {
        StringBuilder b = new StringBuilder(128);

        b.append("ClipData { ");
        toShortString(b);
        toShortString(b, true);
        b.append(" }");

        return b.toString();
    }

    /** @hide */
    public void toShortString(StringBuilder b) {
    /**
     * Appends this clip to the given builder.
     * @param redactContent If true, redacts common forms of PII; otherwise appends full details.
     * @hide
     */
    public void toShortString(StringBuilder b, boolean redactContent) {
        boolean first;
        if (mClipDescription != null) {
            first = !mClipDescription.toShortString(b);
            first = !mClipDescription.toShortString(b, redactContent);
        } else {
            first = true;
        }
@@ -1064,26 +1080,21 @@ public class ClipData implements Parcelable {
            b.append('x');
            b.append(mIcon.getHeight());
        }
        for (int i=0; i<mItems.size(); i++) {
        if (mItems.size() != 1) {
            if (!first) {
                b.append(' ');
            }
            first = false;
            b.append('{');
            mItems.get(i).toShortString(b);
            b.append('}');
            b.append(mItems.size()).append(" items:");
        }
    }

    /** @hide */
    public void toShortStringShortItems(StringBuilder b, boolean first) {
        if (mItems.size() > 0) {
        for (int i = 0; i < mItems.size(); i++) {
            if (!first) {
                b.append(' ');
            }
            for (int i=0; i<mItems.size(); i++) {
                b.append("{...}");
            }
            first = false;
            b.append('{');
            mItems.get(i).toShortString(b, redactContent);
            b.append('}');
        }
    }

+22 −7
Original line number Diff line number Diff line
@@ -330,31 +330,46 @@ public class ClipDescription implements Parcelable {
        StringBuilder b = new StringBuilder(128);

        b.append("ClipDescription { ");
        toShortString(b);
        toShortString(b, true);
        b.append(" }");

        return b.toString();
    }

    /** @hide */
    public boolean toShortString(StringBuilder b) {
    /**
     * Appends this description to the given builder.
     * @param redactContent If true, redacts common forms of PII; otherwise appends full details.
     * @hide
     */
    public boolean toShortString(StringBuilder b, boolean redactContent) {
        boolean first = !toShortStringTypesOnly(b);
        if (mLabel != null) {
            if (!first) {
                b.append(' ');
            }
            first = false;
            b.append('"');
            b.append(mLabel);
            b.append('"');
            if (redactContent) {
                b.append("hasLabel(").append(mLabel.length()).append(')');
            } else {
                b.append('"').append(mLabel).append('"');
            }
        }
        if (mExtras != null) {
            if (!first) {
                b.append(' ');
            }
            first = false;
            if (redactContent) {
                if (mExtras.isParcelled()) {
                    // We don't want this toString function to trigger un-parcelling.
                    b.append("hasExtras");
                } else {
                    b.append("hasExtras(").append(mExtras.size()).append(')');
                }
            } else {
                b.append(mExtras.toString());
            }
        }
        if (mTimeStamp > 0) {
            if (!first) {
                b.append(' ');
+2 −26
Original line number Diff line number Diff line
@@ -10484,17 +10484,6 @@ public class Intent implements Parcelable, Cloneable {
        return b.toString();
    }

    /** @hide */
    public String toInsecureStringWithClip() {
        StringBuilder b = new StringBuilder(128);

        b.append("Intent { ");
        toShortString(b, false, true, true, true);
        b.append(" }");

        return b.toString();
    }

    /** @hide */
    public String toShortString(boolean secure, boolean comp, boolean extras, boolean clip) {
        StringBuilder b = new StringBuilder(128);
@@ -10581,16 +10570,7 @@ public class Intent implements Parcelable, Cloneable {
                b.append(' ');
            }
            b.append("clip={");
            if (clip) {
                mClipData.toShortString(b);
            } else {
                if (mClipData.getDescription() != null) {
                    first = !mClipData.getDescription().toShortStringTypesOnly(b);
                } else {
                    first = true;
                }
                mClipData.toShortStringShortItems(b, first);
            }
            mClipData.toShortString(b, !clip || secure);
            first = false;
            b.append('}');
        }
@@ -10668,11 +10648,7 @@ public class Intent implements Parcelable, Cloneable {
        }
        if (mClipData != null) {
            StringBuilder b = new StringBuilder();
            if (clip) {
                mClipData.toShortString(b);
            } else {
                mClipData.toShortStringShortItems(b, false);
            }
            mClipData.toShortString(b, !clip || secure);
            proto.write(IntentProto.CLIP_DATA, b.toString());
        }
        if (extras && mExtras != null) {