Update ClipData.toString and related code to not leak common forms of PII
Bug: 171732792 Test: atest CtsContentTestCases:ClipDataTest Change-Id: I530795fb8bf6d69e33c1122b1cf8b9e9e4c6aee4
This commit is contained in:
@@ -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);
|
||||
} else {
|
||||
b.append("NULL");
|
||||
first = false;
|
||||
if (redactContent) {
|
||||
b.append("H(").append(mHtmlText.length()).append(')');
|
||||
} else {
|
||||
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) {
|
||||
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("U:").append(mUri);
|
||||
}
|
||||
}
|
||||
if (mIntent != null) {
|
||||
if (!first) {
|
||||
b.append(' ');
|
||||
}
|
||||
first = false;
|
||||
b.append("I:");
|
||||
mIntent.toShortString(b, true, true, true, true);
|
||||
} else {
|
||||
b.append("NULL");
|
||||
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,29 +1080,24 @@ 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.size()).append(" items:");
|
||||
}
|
||||
for (int i = 0; i < mItems.size(); i++) {
|
||||
if (!first) {
|
||||
b.append(' ');
|
||||
}
|
||||
first = false;
|
||||
b.append('{');
|
||||
mItems.get(i).toShortString(b);
|
||||
mItems.get(i).toShortString(b, redactContent);
|
||||
b.append('}');
|
||||
}
|
||||
}
|
||||
|
||||
/** @hide */
|
||||
public void toShortStringShortItems(StringBuilder b, boolean first) {
|
||||
if (mItems.size() > 0) {
|
||||
if (!first) {
|
||||
b.append(' ');
|
||||
}
|
||||
for (int i=0; i<mItems.size(); i++) {
|
||||
b.append("{...}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** @hide */
|
||||
public void dumpDebug(ProtoOutputStream proto, long fieldId) {
|
||||
final long token = proto.start(fieldId);
|
||||
|
||||
@@ -330,30 +330,45 @@ 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;
|
||||
b.append(mExtras.toString());
|
||||
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) {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user