From 207638e6b2b6ef0613c0cead768188df84541295 Mon Sep 17 00:00:00 2001 From: Jeff DeCew Date: Fri, 18 Jun 2021 10:33:00 -0400 Subject: [PATCH] Do not redact string extras which exclusively contain helpful system information. Also, include the length of redacted strings. Test: produce a bugreport and validate the expected strings are present Change-Id: Ib1e5e18290f4a4854b0594c7e939f9392b8ac4bb --- .../server/notification/NotificationRecord.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/services/core/java/com/android/server/notification/NotificationRecord.java b/services/core/java/com/android/server/notification/NotificationRecord.java index f66cfa99ce986..7a00b86cb1a35 100644 --- a/services/core/java/com/android/server/notification/NotificationRecord.java +++ b/services/core/java/com/android/server/notification/NotificationRecord.java @@ -585,7 +585,8 @@ public final class NotificationRecord { pw.println("null"); } else { pw.print(val.getClass().getSimpleName()); - if (redact && (val instanceof CharSequence || val instanceof String)) { + if (redact && (val instanceof CharSequence) && shouldRedactStringExtra(key)) { + pw.print(String.format(" [length=%d]", ((CharSequence) val).length())); // redact contents from bugreports } else if (val instanceof Bitmap) { pw.print(String.format(" (%dx%d)", @@ -611,6 +612,19 @@ public final class NotificationRecord { } } + private boolean shouldRedactStringExtra(String key) { + if (key == null) return true; + switch (key) { + // none of these keys contain user-related information; they do not need to be redacted + case Notification.EXTRA_SUBSTITUTE_APP_NAME: + case Notification.EXTRA_TEMPLATE: + case "android.support.v4.app.extra.COMPAT_TEMPLATE": + return false; + default: + return true; + } + } + @Override public final String toString() { return String.format(