From 5f690e39191f7a2bca58c34728d544a23d918fd7 Mon Sep 17 00:00:00 2001 From: Julia Tuttle Date: Fri, 1 Apr 2022 14:23:56 -0400 Subject: [PATCH] Fix Conversation widget on new notif pipeline The Conversation widget stopped updating properly because it was updating on a background thread but it needed to get all active and pending notifications to do that, and the new pipeline (but not the old) only allows that on the main thread. This change gets the notifications on the main thread, then passes the list to the background thread to finish the task. Bug: 225795397 Test: manual Change-Id: If05edbfd1817e5e28dc5a18c892fdb52ef1075c1 --- .../widget/PeopleSpaceWidgetManager.java | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/people/widget/PeopleSpaceWidgetManager.java b/packages/SystemUI/src/com/android/systemui/people/widget/PeopleSpaceWidgetManager.java index f6e1cd49eb402..08249a3d493e1 100644 --- a/packages/SystemUI/src/com/android/systemui/people/widget/PeopleSpaceWidgetManager.java +++ b/packages/SystemUI/src/com/android/systemui/people/widget/PeopleSpaceWidgetManager.java @@ -441,12 +441,16 @@ public class PeopleSpaceWidgetManager { Log.d(TAG, "Notification removed, key: " + sbn.getKey()); } } + if (DEBUG) Log.d(TAG, "Fetching notifications"); + Collection notifications = mNotifCollection.getAllNotifs(); mBgExecutor.execute( - () -> updateWidgetsWithNotificationChangedInBackground(sbn, notificationAction)); + () -> updateWidgetsWithNotificationChangedInBackground( + sbn, notificationAction, notifications)); } private void updateWidgetsWithNotificationChangedInBackground(StatusBarNotification sbn, - PeopleSpaceUtils.NotificationAction action) { + PeopleSpaceUtils.NotificationAction action, + Collection notifications) { try { PeopleTileKey key = new PeopleTileKey( sbn.getShortcutId(), sbn.getUser().getIdentifier(), sbn.getPackageName()); @@ -469,7 +473,7 @@ public class PeopleSpaceWidgetManager { Log.d(TAG, "Widgets by URI to be updated:" + tilesUpdatedByUri.toString()); } tilesUpdated.addAll(tilesUpdatedByUri); - updateWidgetIdsBasedOnNotifications(tilesUpdated); + updateWidgetIdsBasedOnNotifications(tilesUpdated, notifications); } } catch (Exception e) { Log.e(TAG, "Throwing exception: " + e); @@ -477,15 +481,15 @@ public class PeopleSpaceWidgetManager { } /** Updates {@code widgetIdsToUpdate} with {@code action}. */ - private void updateWidgetIdsBasedOnNotifications(Set widgetIdsToUpdate) { + private void updateWidgetIdsBasedOnNotifications(Set widgetIdsToUpdate, + Collection ungroupedNotifications) { if (widgetIdsToUpdate.isEmpty()) { if (DEBUG) Log.d(TAG, "No widgets to update, returning."); return; } try { - if (DEBUG) Log.d(TAG, "Fetching grouped notifications"); Map> groupedNotifications = - getGroupedConversationNotifications(); + groupConversationNotifications(ungroupedNotifications); widgetIdsToUpdate .stream() @@ -510,7 +514,7 @@ public class PeopleSpaceWidgetManager { "Augmenting tile from NotificationEntryManager widget: " + key.toString()); } Map> notifications = - getGroupedConversationNotifications(); + groupConversationNotifications(mNotifCollection.getAllNotifs()); String contactUri = null; if (tile.getContactUri() != null) { contactUri = tile.getContactUri().toString(); @@ -518,9 +522,10 @@ public class PeopleSpaceWidgetManager { return augmentTileFromNotifications(tile, key, contactUri, notifications, appWidgetId); } - /** Returns active and pending notifications grouped by {@link PeopleTileKey}. */ - public Map> getGroupedConversationNotifications() { - Collection notifications = mNotifCollection.getAllNotifs(); + /** Groups active and pending notifications grouped by {@link PeopleTileKey}. */ + public Map> groupConversationNotifications( + Collection notifications + ) { if (DEBUG) Log.d(TAG, "Number of total notifications: " + notifications.size()); Map> groupedNotifications = notifications