From 74d8c09b8aee9c0866664c85f69d698f98661838 Mon Sep 17 00:00:00 2001 From: Agatha Man Date: Thu, 28 May 2020 09:30:47 -0700 Subject: [PATCH] Ignore public volume state change event of removed user in Automotive Volume state change event may come from removed user, in this case, mountedUserId will equal to UserHandle.USER_NULL (-10000) which will do nothing when call cancelAsUser(), but cauase crash when call notifyAsUser(). Here we return directly for USER_NULL, and leave all notifications belong to removed user to NotificationmanagerService, the latter will remove all notifications of the removed user when handles user stopped broadcast. Bug: 156667908 Test: manual - remove user while usb plugged in Change-Id: I23670e070a17b6da8bdd9eb336aa053e3b799b16 --- .../com/android/systemui/usb/StorageNotification.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/packages/SystemUI/src/com/android/systemui/usb/StorageNotification.java b/packages/SystemUI/src/com/android/systemui/usb/StorageNotification.java index b6e722266bd6d..b36b53125f2f4 100644 --- a/packages/SystemUI/src/com/android/systemui/usb/StorageNotification.java +++ b/packages/SystemUI/src/com/android/systemui/usb/StorageNotification.java @@ -294,6 +294,16 @@ public class StorageNotification extends SystemUI { private void onPublicVolumeStateChangedInternal(VolumeInfo vol) { Log.d(TAG, "Notifying about public volume: " + vol.toString()); + // Volume state change event may come from removed user, in this case, mountedUserId will + // equals to UserHandle.USER_NULL (-10000) which will do nothing when call cancelAsUser(), + // but cause crash when call notifyAsUser(). Here we return directly for USER_NULL, and + // leave all notifications belong to removed user to NotificationManagerService, the latter + // will remove all notifications of the removed user when handles user stopped broadcast. + if (isAutomotive() && vol.getMountUserId() == UserHandle.USER_NULL) { + Log.d(TAG, "Ignore public volume state change event of removed user"); + return; + } + final Notification notif; switch (vol.getState()) { case VolumeInfo.STATE_UNMOUNTED: