diff options
| author | 2020-11-10 17:24:55 +0000 | |
|---|---|---|
| committer | 2020-11-12 21:17:32 +0000 | |
| commit | 04ffb5128bff83e8efe7c8adc16d86a6fc0544a3 (patch) | |
| tree | 6c0bfc16481738967bf1172877033bc6c44c0349 | |
| parent | 5e687f45442ce9f42dfbf79d6b92cc7c742caf98 (diff) | |
Update People Space widget on channel modification
Test: Buld and run, and unit test.
Change-Id: I209c3a7ac12fa48f744d8f784c598ad359bf2de6
7 files changed, 147 insertions, 4 deletions
diff --git a/packages/SystemUI/plugin/src/com/android/systemui/plugins/NotificationListenerController.java b/packages/SystemUI/plugin/src/com/android/systemui/plugins/NotificationListenerController.java index fac9e98a6caf..6799450079af 100644 --- a/packages/SystemUI/plugin/src/com/android/systemui/plugins/NotificationListenerController.java +++ b/packages/SystemUI/plugin/src/com/android/systemui/plugins/NotificationListenerController.java @@ -14,6 +14,8 @@ package com.android.systemui.plugins; +import android.app.NotificationChannel; +import android.os.UserHandle; import android.service.notification.NotificationListenerService.RankingMap; import android.service.notification.StatusBarNotification; @@ -30,13 +32,32 @@ public interface NotificationListenerController extends Plugin { void onListenerConnected(NotificationProvider provider); + /** + * @return whether plugin wants to skip the default callbacks. + */ default boolean onNotificationPosted(StatusBarNotification sbn, RankingMap rankingMap) { return false; } + + /** + * @return whether plugin wants to skip the default callbacks. + */ default boolean onNotificationRemoved(StatusBarNotification sbn, RankingMap rankingMap) { return false; } + /** + * Called when a notification channel is modified. + * @param modificationType One of {@link #NOTIFICATION_CHANNEL_OR_GROUP_ADDED}, + * {@link #NOTIFICATION_CHANNEL_OR_GROUP_UPDATED}, + * {@link #NOTIFICATION_CHANNEL_OR_GROUP_DELETED}. + * @return whether a plugin wants to skip the default callbacks. + */ + default boolean onNotificationChannelModified( + String pkgName, UserHandle user, NotificationChannel channel, int modificationType) { + return false; + } + default StatusBarNotification[] getActiveNotifications( StatusBarNotification[] activeNotifications) { return activeNotifications; 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 8415368fe931..9b7cf6e85ada 100644 --- a/packages/SystemUI/src/com/android/systemui/people/widget/PeopleSpaceWidgetManager.java +++ b/packages/SystemUI/src/com/android/systemui/people/widget/PeopleSpaceWidgetManager.java @@ -16,9 +16,11 @@ package com.android.systemui.people.widget; +import android.app.NotificationChannel; import android.content.ComponentName; import android.content.Context; import android.os.ServiceManager; +import android.os.UserHandle; import android.service.notification.NotificationListenerService; import android.service.notification.StatusBarNotification; import android.util.Log; @@ -130,6 +132,18 @@ public class PeopleSpaceWidgetManager { if (DEBUG) Log.d(TAG, "onNotificationsInitialized"); updateWidgets(); } + + @Override + public void onNotificationChannelModified( + String pkgName, + UserHandle user, + NotificationChannel channel, + int modificationType) { + if (DEBUG) Log.d(TAG, "onNotificationChannelModified"); + if (channel.isConversation()) { + updateWidgets(); + } + } }; } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationListener.java b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationListener.java index f9d2d31dbfd4..7f31fddbfb6c 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationListener.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationListener.java @@ -22,6 +22,7 @@ import static com.android.systemui.statusbar.phone.StatusBar.DEBUG; import android.annotation.NonNull; import android.annotation.SuppressLint; +import android.app.NotificationChannel; import android.app.NotificationManager; import android.content.ComponentName; import android.content.Context; @@ -159,6 +160,19 @@ public class NotificationListener extends NotificationListenerWithPlugins { } @Override + public void onNotificationChannelModified( + String pkgName, UserHandle user, NotificationChannel channel, int modificationType) { + if (DEBUG) Log.d(TAG, "onNotificationChannelModified"); + if (!onPluginNotificationChannelModified(pkgName, user, channel, modificationType)) { + mMainHandler.post(() -> { + for (NotificationHandler handler : mNotificationHandlers) { + handler.onNotificationChannelModified(pkgName, user, channel, modificationType); + } + }); + } + } + + @Override public void onSilentStatusBarIconsVisibilityChanged(boolean hideSilentStatusIcons) { for (NotificationSettingsListener listener : mSettingsListeners) { listener.onStatusBarIconsBehaviorChanged(hideSilentStatusIcons); @@ -229,6 +243,14 @@ public class NotificationListener extends NotificationListenerWithPlugins { void onNotificationRemoved(StatusBarNotification sbn, RankingMap rankingMap, int reason); void onNotificationRankingUpdate(RankingMap rankingMap); + /** Called after a notification channel is modified. */ + default void onNotificationChannelModified( + String pkgName, + UserHandle user, + NotificationChannel channel, + int modificationType) { + } + /** * Called after the listener has connected to NoMan and posted any current notifications. */ diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/coalescer/GroupCoalescer.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/coalescer/GroupCoalescer.java index 1710daa16735..09ae7eb38a06 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/coalescer/GroupCoalescer.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/coalescer/GroupCoalescer.java @@ -19,6 +19,8 @@ package com.android.systemui.statusbar.notification.collection.coalescer; import static java.util.Objects.requireNonNull; import android.annotation.MainThread; +import android.app.NotificationChannel; +import android.os.UserHandle; import android.service.notification.NotificationListenerService.Ranking; import android.service.notification.NotificationListenerService.RankingMap; import android.service.notification.StatusBarNotification; @@ -158,6 +160,15 @@ public class GroupCoalescer implements Dumpable { public void onNotificationsInitialized() { mHandler.onNotificationsInitialized(); } + + @Override + public void onNotificationChannelModified( + String pkgName, + UserHandle user, + NotificationChannel channel, + int modificationType) { + mHandler.onNotificationChannelModified(pkgName, user, channel, modificationType); + } }; private void maybeEmitBatch(StatusBarNotification sbn) { diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationListenerWithPlugins.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationListenerWithPlugins.java index 9e561d13f347..4651e8446059 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationListenerWithPlugins.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationListenerWithPlugins.java @@ -14,9 +14,11 @@ package com.android.systemui.statusbar.phone; +import android.app.NotificationChannel; import android.content.ComponentName; import android.content.Context; import android.os.RemoteException; +import android.os.UserHandle; import android.service.notification.NotificationListenerService; import android.service.notification.StatusBarNotification; @@ -78,7 +80,7 @@ public class NotificationListenerWithPlugins extends NotificationListenerService /** * Called when listener receives a onNotificationPosted. - * Returns true to indicate this callback should be skipped. + * Returns true if there's a plugin determining to skip the default callbacks. */ public boolean onPluginNotificationPosted(StatusBarNotification sbn, final RankingMap rankingMap) { @@ -92,7 +94,7 @@ public class NotificationListenerWithPlugins extends NotificationListenerService /** * Called when listener receives a onNotificationRemoved. - * Returns true to indicate this callback should be skipped. + * Returns true if there's a plugin determining to skip the default callbacks. */ public boolean onPluginNotificationRemoved(StatusBarNotification sbn, final RankingMap rankingMap) { @@ -104,6 +106,20 @@ public class NotificationListenerWithPlugins extends NotificationListenerService return false; } + /** + * Called when listener receives a onNotificationChannelModified. + * Returns true if there's a plugin determining to skip the default callbacks. + */ + public boolean onPluginNotificationChannelModified( + String pkgName, UserHandle user, NotificationChannel channel, int modificationType) { + for (NotificationListenerController plugin : mPlugins) { + if (plugin.onNotificationChannelModified(pkgName, user, channel, modificationType)) { + return true; + } + } + return false; + } + public RankingMap onPluginRankingUpdate(RankingMap rankingMap) { return getCurrentRanking(); } diff --git a/packages/SystemUI/tests/src/com/android/systemui/people/widget/PeopleSpaceWidgetManagerTest.java b/packages/SystemUI/tests/src/com/android/systemui/people/widget/PeopleSpaceWidgetManagerTest.java index 8ceebebe9a5b..3e44fa4a9b2b 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/people/widget/PeopleSpaceWidgetManagerTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/people/widget/PeopleSpaceWidgetManagerTest.java @@ -16,6 +16,8 @@ package com.android.systemui.people.widget; +import static android.app.NotificationManager.IMPORTANCE_HIGH; + import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.eq; @@ -26,8 +28,10 @@ import static org.mockito.Mockito.when; import static java.util.Objects.requireNonNull; +import android.app.NotificationChannel; import android.content.Context; import android.os.RemoteException; +import android.os.UserHandle; import android.testing.AndroidTestingRunner; import androidx.test.filters.SmallTest; @@ -56,6 +60,10 @@ public class PeopleSpaceWidgetManagerTest extends SysuiTestCase { private static final String TEST_PACKAGE_A = "com.test.package_a"; private static final String TEST_PACKAGE_B = "com.test.package_b"; + private static final String TEST_CHANNEL_ID = "channel_id"; + private static final String TEST_CHANNEL_NAME = "channel_name"; + private static final String TEST_PARENT_CHANNEL_ID = "parent_channel_id"; + private static final String TEST_CONVERSATION_ID = "conversation_id"; private PeopleSpaceWidgetManager mManager; @@ -100,7 +108,7 @@ public class PeopleSpaceWidgetManagerTest extends SysuiTestCase { } @Test - public void testNotifyAppWidgetIfWidgets() throws RemoteException { + public void testNotifyAppWidgetIfNotificationPosted() throws RemoteException { int[] widgetIdsArray = {1}; when(mIAppWidgetService.getAppWidgetIds(any())).thenReturn(widgetIdsArray); @@ -117,7 +125,7 @@ public class PeopleSpaceWidgetManagerTest extends SysuiTestCase { } @Test - public void testNotifyAppWidgetTwiceIfTwoNotifications() throws RemoteException { + public void testNotifyAppWidgetTwiceIfTwoNotificationsPosted() throws RemoteException { int[] widgetIdsArray = {1, 2}; when(mIAppWidgetService.getAppWidgetIds(any())).thenReturn(widgetIdsArray); @@ -149,4 +157,40 @@ public class PeopleSpaceWidgetManagerTest extends SysuiTestCase { verify(mIAppWidgetService, times(2)) .notifyAppWidgetViewDataChanged(any(), eq(widgetIdsArray), anyInt()); } + + @Test + public void testDoNotNotifyAppWidgetIfNonConversationChannelModified() throws RemoteException { + int[] widgetIdsArray = {1}; + when(mIAppWidgetService.getAppWidgetIds(any())).thenReturn(widgetIdsArray); + + NotificationChannel channel = + mNoMan.createNotificationChannel(TEST_CHANNEL_ID, TEST_CHANNEL_NAME); + + mNoMan.issueChannelModification(TEST_PACKAGE_A, + UserHandle.getUserHandleForUid(0), channel, IMPORTANCE_HIGH); + mClock.advanceTime(MIN_LINGER_DURATION); + + verify(mIAppWidgetService, never()).getAppWidgetIds(any()); + verify(mIAppWidgetService, never()).notifyAppWidgetViewDataChanged(any(), any(), anyInt()); + + } + + @Test + public void testNotifyAppWidgetIfConversationChannelModified() throws RemoteException { + int[] widgetIdsArray = {1}; + when(mIAppWidgetService.getAppWidgetIds(any())).thenReturn(widgetIdsArray); + + NotificationChannel channel = + mNoMan.createNotificationChannel(TEST_CHANNEL_ID, TEST_CHANNEL_NAME); + channel.setConversationId(TEST_PARENT_CHANNEL_ID, TEST_CONVERSATION_ID); + + mNoMan.issueChannelModification(TEST_PACKAGE_A, + UserHandle.getUserHandleForUid(0), channel, IMPORTANCE_HIGH); + mClock.advanceTime(MIN_LINGER_DURATION); + + verify(mIAppWidgetService, times(1)).getAppWidgetIds(any()); + verify(mIAppWidgetService, times(1)) + .notifyAppWidgetViewDataChanged(any(), eq(widgetIdsArray), anyInt()); + + } } diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/collection/NoManSimulator.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/collection/NoManSimulator.java index c113df0b4ee7..1bfe10c5263b 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/collection/NoManSimulator.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/collection/NoManSimulator.java @@ -16,8 +16,12 @@ package com.android.systemui.statusbar.notification.collection; +import static android.app.NotificationManager.IMPORTANCE_DEFAULT; + import static org.junit.Assert.assertNotNull; +import android.app.NotificationChannel; +import android.os.UserHandle; import android.service.notification.NotificationListenerService.Ranking; import android.service.notification.NotificationListenerService.RankingMap; import android.service.notification.StatusBarNotification; @@ -72,6 +76,17 @@ public class NoManSimulator { } } + public NotificationChannel createNotificationChannel(String id, String name) { + return new NotificationChannel(id, name, IMPORTANCE_DEFAULT); + } + + public void issueChannelModification( + String pkg, UserHandle user, NotificationChannel channel, int modificationType) { + for (NotificationHandler listener : mListeners) { + listener.onNotificationChannelModified(pkg, user, channel, modificationType); + } + } + public void setRanking(String key, Ranking ranking) { mRankings.put(key, ranking); } |