diff options
| author | 2022-03-29 17:22:09 -0700 | |
|---|---|---|
| committer | 2022-03-29 17:24:05 -0700 | |
| commit | d62f9fbcc5e9b018fce13b3ba6ec0af6f0983f2f (patch) | |
| tree | 38a6f0a1ff0eb8cf235df8b3dc2f6884aea52ff3 | |
| parent | 92ad3ae51303dae182ac484efacd83de8bb53c2c (diff) | |
Fetch active notifications on a background thread.
Avoid a potential ANR by moving a call to getActiveNotifications to a
background thread.
Test: atest DreamOverlayNotificationCountProviderTest
Bug: 227237503
Change-Id: I1fd0e110498fdb1d96cef018e6a2d5d6c362675e
2 files changed, 13 insertions, 4 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/dreams/DreamOverlayNotificationCountProvider.java b/packages/SystemUI/src/com/android/systemui/dreams/DreamOverlayNotificationCountProvider.java index aaa34ed32c7e..6589f26dbde2 100644 --- a/packages/SystemUI/src/com/android/systemui/dreams/DreamOverlayNotificationCountProvider.java +++ b/packages/SystemUI/src/com/android/systemui/dreams/DreamOverlayNotificationCountProvider.java @@ -21,6 +21,7 @@ import android.service.notification.NotificationListenerService; import android.service.notification.StatusBarNotification; import com.android.systemui.dagger.SysUISingleton; +import com.android.systemui.dagger.qualifiers.Background; import com.android.systemui.statusbar.NotificationListener; import com.android.systemui.statusbar.NotificationListener.NotificationHandler; import com.android.systemui.statusbar.policy.CallbackController; @@ -30,6 +31,7 @@ import java.util.Arrays; import java.util.HashSet; import java.util.List; import java.util.Set; +import java.util.concurrent.Executor; import javax.inject.Inject; @@ -78,10 +80,16 @@ public class DreamOverlayNotificationCountProvider @Inject public DreamOverlayNotificationCountProvider( - NotificationListener notificationListener) { + NotificationListener notificationListener, + @Background Executor bgExecutor) { notificationListener.addNotificationHandler(mNotificationHandler); - Arrays.stream(notificationListener.getActiveNotifications()) - .forEach(sbn -> mNotificationKeys.add(sbn.getKey())); + + bgExecutor.execute(() -> { + Arrays.stream(notificationListener.getActiveNotifications()) + .forEach(sbn -> mNotificationKeys.add(sbn.getKey())); + reportNotificationCountChanged(); + } + ); } @Override diff --git a/packages/SystemUI/tests/src/com/android/systemui/dreams/DreamOverlayNotificationCountProviderTest.java b/packages/SystemUI/tests/src/com/android/systemui/dreams/DreamOverlayNotificationCountProviderTest.java index c86122141c8f..b7de6c15459c 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/dreams/DreamOverlayNotificationCountProviderTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/dreams/DreamOverlayNotificationCountProviderTest.java @@ -61,7 +61,8 @@ public class DreamOverlayNotificationCountProviderTest extends SysuiTestCase { final StatusBarNotification[] notifications = {mNotification1}; when(mNotificationListener.getActiveNotifications()).thenReturn(notifications); - mProvider = new DreamOverlayNotificationCountProvider(mNotificationListener); + mProvider = new DreamOverlayNotificationCountProvider( + mNotificationListener, Runnable::run); mProvider.addCallback(mCallback); } |