From bbb4b22f8b1dc19afd965ac2c9d0527d490fe264 Mon Sep 17 00:00:00 2001 From: Makoto Onuki Date: Mon, 25 Jun 2018 16:01:02 -0700 Subject: [PATCH] NotificationManager: clean calling identity in dump(). When a device has work profile, "dumpsys notifiaction" often crashes if the caller doesn't have the CROSS_USER permission. The dump() method is protected with checkDumpAndUsageStatsPermission(), and it won't need further permission check. Test: "dumpsys notification" Change-Id: Ief5269dec1e334bcd96013c349a468a0136a9551 --- .../notification/NotificationManagerService.java | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/services/core/java/com/android/server/notification/NotificationManagerService.java b/services/core/java/com/android/server/notification/NotificationManagerService.java index c45d8610fb19..6402b7b6586b 100644 --- a/services/core/java/com/android/server/notification/NotificationManagerService.java +++ b/services/core/java/com/android/server/notification/NotificationManagerService.java @@ -3125,14 +3125,19 @@ public class NotificationManagerService extends SystemService { protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) { if (!DumpUtils.checkDumpAndUsageStatsPermission(getContext(), TAG, pw)) return; final DumpFilter filter = DumpFilter.parseFromArguments(args); - if (filter.stats) { - dumpJson(pw, filter); - } else if (filter.proto) { - dumpProto(fd, filter); - } else if (filter.criticalPriority) { - dumpNotificationRecords(pw, filter); - } else { - dumpImpl(pw, filter); + final long token = Binder.clearCallingIdentity(); + try { + if (filter.stats) { + dumpJson(pw, filter); + } else if (filter.proto) { + dumpProto(fd, filter); + } else if (filter.criticalPriority) { + dumpNotificationRecords(pw, filter); + } else { + dumpImpl(pw, filter); + } + } finally { + Binder.restoreCallingIdentity(token); } } -- 2.11.0