From 4d9919f48043b3b89a8d09824ecda949a2292a36 Mon Sep 17 00:00:00 2001 From: woongki min Date: Wed, 25 Sep 2019 11:50:48 +0900 Subject: [PATCH] Reduce unnecessary NotificationListener binder transaction. When package suspend occurs, API calls are made as many as the number of changed packages, resulting in unnecessary binder transactions. This can rapidly consume the async space on the NotificationListener side, such as the SystemUI. JavaBinder: !!! FAILED BINDER TRANSACTION !!! (parcel size = 8844) NotificationListeners: unable to notify listener (posted): android.service.notification.INotificationListener$Stub$Proxy@8ed47e2 NotificationListeners: android.os.DeadObjectException: Transaction failed on small parcel; remote process probably died Test: Occurs ACTION_PACKAGES_UNSUSPENDED/SUSPENDED with a pkgList size of 50 or more Test: Async space of SystemUI(NotificationListener) decreases and binder transaction fails. Change-Id: I58d42ecf39e13b3adce7652ae72147de0be00e89 --- .../notification/NotificationManagerService.java | 13 ++++++------- .../NotificationManagerServiceTest.java | 8 ++++++-- 2 files changed, 12 insertions(+), 9 deletions(-) mode change 100644 => 100755 services/core/java/com/android/server/notification/NotificationManagerService.java mode change 100644 => 100755 services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java diff --git a/services/core/java/com/android/server/notification/NotificationManagerService.java b/services/core/java/com/android/server/notification/NotificationManagerService.java old mode 100644 new mode 100755 index d480cb6e98007..a8ba82a740657 --- a/services/core/java/com/android/server/notification/NotificationManagerService.java +++ b/services/core/java/com/android/server/notification/NotificationManagerService.java @@ -1331,16 +1331,15 @@ public class NotificationManagerService extends SystemService { uidList = new int[] {intent.getIntExtra(Intent.EXTRA_UID, -1)}; } if (pkgList != null && (pkgList.length > 0)) { - for (String pkgName : pkgList) { - if (cancelNotifications) { + if (cancelNotifications) { + for (String pkgName : pkgList) { cancelAllNotificationsInt(MY_UID, MY_PID, pkgName, null, 0, 0, !queryRestart, changeUserId, reason, null); - } else if (hideNotifications) { - hideNotificationsForPackages(pkgList); - } else if (unhideNotifications) { - unhideNotificationsForPackages(pkgList); } - + } else if (hideNotifications) { + hideNotificationsForPackages(pkgList); + } else if (unhideNotifications) { + unhideNotificationsForPackages(pkgList); } } diff --git a/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java b/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java old mode 100644 new mode 100755 index 2de8d0579ec4b..e80c6291b42a5 --- a/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java +++ b/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java @@ -3864,7 +3864,9 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { mService.simulatePackageDistractionBroadcast( PackageManager.RESTRICTION_HIDE_NOTIFICATIONS, new String[] {"a", "b"}); ArgumentCaptor> captorHide = ArgumentCaptor.forClass(List.class); - verify(mListeners, times(2)).notifyHiddenLocked(captorHide.capture()); + + // should be called only once. + verify(mListeners, times(1)).notifyHiddenLocked(captorHide.capture()); assertEquals(2, captorHide.getValue().size()); assertEquals("a", captorHide.getValue().get(0).sbn.getPackageName()); assertEquals("b", captorHide.getValue().get(1).sbn.getPackageName()); @@ -3873,7 +3875,9 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { mService.simulatePackageDistractionBroadcast( PackageManager.RESTRICTION_HIDE_FROM_SUGGESTIONS, new String[] {"a", "b"}); ArgumentCaptor> captorUnhide = ArgumentCaptor.forClass(List.class); - verify(mListeners, times(2)).notifyUnhiddenLocked(captorUnhide.capture()); + + // should be called only once. + verify(mListeners, times(1)).notifyUnhiddenLocked(captorUnhide.capture()); assertEquals(2, captorUnhide.getValue().size()); assertEquals("a", captorUnhide.getValue().get(0).sbn.getPackageName()); assertEquals("b", captorUnhide.getValue().get(1).sbn.getPackageName());