From 248e431587499cc8072f7ee8a70b37f7b84822fd Mon Sep 17 00:00:00 2001 From: Bryce Lee Date: Wed, 18 Aug 2021 16:44:24 -0700 Subject: [PATCH 1/3] Do not show notifications on keyguard with communal. This changelist suppressed notifications through a coordinator when the communal view is present on keyguard. Bug: 196867633 Test: atest CommunalCoordinatorTest Change-Id: Ib76ec1ecd14cc46e4ef9a8d25b30ec843d793ff5 --- .../coordinator/CommunalCoordinator.java | 70 ++++++++++++++ .../coordinator/NotifCoordinators.java | 4 +- .../coordinator/CommunalCoordinatorTest.java | 92 +++++++++++++++++++ 3 files changed, 165 insertions(+), 1 deletion(-) create mode 100644 packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/coordinator/CommunalCoordinator.java create mode 100644 packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/collection/coordinator/CommunalCoordinatorTest.java diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/coordinator/CommunalCoordinator.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/coordinator/CommunalCoordinator.java new file mode 100644 index 0000000000000..369e52f552785 --- /dev/null +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/coordinator/CommunalCoordinator.java @@ -0,0 +1,70 @@ +/* + * Copyright (C) 2021 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.systemui.statusbar.notification.collection.coordinator; + +import androidx.annotation.NonNull; + +import com.android.systemui.communal.CommunalStateController; +import com.android.systemui.statusbar.NotificationLockscreenUserManager; +import com.android.systemui.statusbar.notification.NotificationEntryManager; +import com.android.systemui.statusbar.notification.collection.NotifPipeline; +import com.android.systemui.statusbar.notification.collection.NotificationEntry; +import com.android.systemui.statusbar.notification.collection.listbuilder.pluggable.NotifFilter; + +import javax.inject.Inject; + +/** + * {@link CommunalCoordinator} prevents notifications from showing on the keyguard when the communal + * view is present. + */ +public class CommunalCoordinator implements Coordinator { + final CommunalStateController mCommunalStateController; + final NotificationEntryManager mNotificationEntryManager; + final NotificationLockscreenUserManager mNotificationLockscreenUserManager; + + @Inject + public CommunalCoordinator(NotificationEntryManager notificationEntryManager, + NotificationLockscreenUserManager notificationLockscreenUserManager, + CommunalStateController communalStateController) { + mNotificationEntryManager = notificationEntryManager; + mNotificationLockscreenUserManager = notificationLockscreenUserManager; + mCommunalStateController = communalStateController; + } + + final NotifFilter mFilter = new NotifFilter("CommunalCoordinator") { + @Override + public boolean shouldFilterOut(@NonNull NotificationEntry entry, long now) { + return mCommunalStateController.getCommunalViewShowing(); + } + }; + + final CommunalStateController.Callback mStateCallback = new CommunalStateController.Callback() { + @Override + public void onCommunalViewShowingChanged() { + mFilter.invalidateList(); + mNotificationEntryManager.updateNotifications("Communal mode state changed"); + } + }; + + @Override + public void attach(@NonNull NotifPipeline pipeline) { + pipeline.addPreGroupFilter(mFilter); + mCommunalStateController.addCallback(mStateCallback); + mNotificationLockscreenUserManager.addKeyguardNotificationSuppressor( + entry -> mCommunalStateController.getCommunalViewShowing()); + } +} diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/coordinator/NotifCoordinators.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/coordinator/NotifCoordinators.java index 25b2019262395..47bc444396b98 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/coordinator/NotifCoordinators.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/coordinator/NotifCoordinators.java @@ -61,7 +61,8 @@ public class NotifCoordinators implements Dumpable { PreparationCoordinator preparationCoordinator, MediaCoordinator mediaCoordinator, SmartspaceDedupingCoordinator smartspaceDedupingCoordinator, - VisualStabilityCoordinator visualStabilityCoordinator) { + VisualStabilityCoordinator visualStabilityCoordinator, + CommunalCoordinator communalCoordinator) { dumpManager.registerDumpable(TAG, this); mCoordinators.add(new HideLocallyDismissedNotifsCoordinator()); @@ -74,6 +75,7 @@ public class NotifCoordinators implements Dumpable { mCoordinators.add(conversationCoordinator); mCoordinators.add(mediaCoordinator); mCoordinators.add(visualStabilityCoordinator); + mCoordinators.add(communalCoordinator); if (featureFlags.isSmartspaceDedupingEnabled()) { mCoordinators.add(smartspaceDedupingCoordinator); diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/collection/coordinator/CommunalCoordinatorTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/collection/coordinator/CommunalCoordinatorTest.java new file mode 100644 index 0000000000000..01e4cce0cc304 --- /dev/null +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/collection/coordinator/CommunalCoordinatorTest.java @@ -0,0 +1,92 @@ +/* + * Copyright (C) 2021 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.systemui.statusbar.notification.collection.coordinator; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.verify; + +import android.test.suitebuilder.annotation.SmallTest; + +import com.android.systemui.SysuiTestCase; +import com.android.systemui.communal.CommunalStateController; +import com.android.systemui.statusbar.NotificationLockscreenUserManager; +import com.android.systemui.statusbar.notification.NotificationEntryManager; +import com.android.systemui.statusbar.notification.collection.NotifPipeline; +import com.android.systemui.statusbar.notification.collection.NotificationEntry; +import com.android.systemui.statusbar.notification.collection.listbuilder.pluggable.NotifFilter; +import com.android.systemui.statusbar.notification.collection.listbuilder.pluggable.Pluggable; + +import org.junit.Before; +import org.junit.Test; +import org.mockito.ArgumentCaptor; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; + + +@SmallTest +public class CommunalCoordinatorTest extends SysuiTestCase { + @Mock + CommunalStateController mCommunalStateController; + @Mock + NotificationEntryManager mNotificationEntryManager; + @Mock + NotificationLockscreenUserManager mNotificationLockscreenUserManager; + @Mock + NotifPipeline mNotifPipeline; + @Mock + NotificationEntry mNotificationEntry; + @Mock + Pluggable.PluggableListener mFilterListener; + + CommunalCoordinator mCoordinator; + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + mCoordinator = new CommunalCoordinator(mNotificationEntryManager, + mNotificationLockscreenUserManager, mCommunalStateController); + } + + @Test + public void testNotificationSuppressionInCommunal() { + mCoordinator.attach(mNotifPipeline); + final ArgumentCaptor stateCallbackCaptor = + ArgumentCaptor.forClass(CommunalStateController.Callback.class); + verify(mCommunalStateController).addCallback(stateCallbackCaptor.capture()); + + final CommunalStateController.Callback stateCallback = stateCallbackCaptor.getValue(); + + final ArgumentCaptor filterCaptor = + ArgumentCaptor.forClass(NotifFilter.class); + verify(mNotifPipeline).addPreGroupFilter(filterCaptor.capture()); + + final NotifFilter filter = filterCaptor.getValue(); + + // Verify that notifications are not filtered out by default. + assert (!filter.shouldFilterOut(mNotificationEntry, 0)); + + filter.setInvalidationListener(mFilterListener); + + // Verify that notifications are filtered out when communal is showing and that the filter + // pipeline is notified. + stateCallback.onCommunalViewShowingChanged(); + verify(mFilterListener).onPluggableInvalidated(any()); + verify(mNotificationEntryManager).updateNotifications(any()); + assert (filter.shouldFilterOut(mNotificationEntry, 0)); + + } +} From aad7248b33886291f591b89085b0dc54b66bb6c4 Mon Sep 17 00:00:00 2001 From: Bryce Lee Date: Mon, 16 Aug 2021 16:44:11 -0700 Subject: [PATCH 2/3] Do not show keyguard clock when communal mode is active. This changelist hides the clock (part of the KeyguardStatusView) when communal mode is shown on the keyguard. Bug: 196885298 Test: atest KeyguardVisibilityHelperTest Test: atest NotificationPanelViewTest#testKeyguardStatusViewUpdatedWithCommunalPresence Change-Id: I488f51526babb5bc404a1dea1572ed43cd28372c --- .../KeyguardStatusViewController.java | 7 +- .../keyguard/KeyguardVisibilityHelper.java | 12 +++ .../NotificationPanelViewController.java | 32 ++++++++ .../KeyguardQsUserSwitchController.java | 4 +- .../KeyguardUserSwitcherController.java | 4 +- .../KeyguardStatusViewControllerTest.java | 4 + .../KeyguardVisibilityHelperTest.java | 77 +++++++++++++++++++ .../phone/NotificationPanelViewTest.java | 55 ++++++++++++- 8 files changed, 188 insertions(+), 7 deletions(-) create mode 100644 packages/SystemUI/tests/src/com/android/keyguard/KeyguardVisibilityHelperTest.java diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardStatusViewController.java b/packages/SystemUI/src/com/android/keyguard/KeyguardStatusViewController.java index 8bf8e09260950..867f1178c3f82 100644 --- a/packages/SystemUI/src/com/android/keyguard/KeyguardStatusViewController.java +++ b/packages/SystemUI/src/com/android/keyguard/KeyguardStatusViewController.java @@ -20,6 +20,7 @@ import android.graphics.Rect; import android.util.Slog; import com.android.keyguard.KeyguardClockSwitch.ClockSize; +import com.android.systemui.communal.CommunalStateController; import com.android.systemui.keyguard.KeyguardUnlockAnimationController; import com.android.systemui.shared.system.smartspace.SmartspaceTransitionController; import com.android.systemui.statusbar.notification.AnimatableProperty; @@ -64,6 +65,7 @@ public class KeyguardStatusViewController extends ViewController