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 private final StatusBarStateController mStatusBarStateController; private WeakReference mLastSource; private int mState; + private float mQsExpansion; + private float mShadeExpansion; @Retention(RetentionPolicy.RUNTIME) @IntDef({STATE_KEYGUARD_SHOWING, STATE_DOZING, STATE_BOUNCER_SHOWING, STATE_KEYGUARD_OCCLUDED}) @@ -264,4 +266,27 @@ public class CommunalHostViewController extends ViewController mLastSource = source; showSource(); } + + /** + * Invoked when the quick settings is expanded. + * @param expansionFraction the percentage the QS shade has been expanded. + */ + public void updateQsExpansion(float expansionFraction) { + mQsExpansion = expansionFraction; + updateCommunalViewOccluded(); + } + + /** + * Invoked when the main shade is expanded. + * @param shadeExpansion the percentage the main shade has expanded. + */ + public void updateShadeExpansion(float shadeExpansion) { + mShadeExpansion = shadeExpansion; + updateCommunalViewOccluded(); + } + + private void updateCommunalViewOccluded() { + mCommunalStateController.setCommunalViewOccluded( + mQsExpansion > 0.0f || mShadeExpansion > 0.0f); + } } diff --git a/packages/SystemUI/src/com/android/systemui/communal/CommunalStateController.java b/packages/SystemUI/src/com/android/systemui/communal/CommunalStateController.java index e5385ec1543fc..c72f5422b1f54 100644 --- a/packages/SystemUI/src/com/android/systemui/communal/CommunalStateController.java +++ b/packages/SystemUI/src/com/android/systemui/communal/CommunalStateController.java @@ -34,6 +34,7 @@ import javax.inject.Inject; public class CommunalStateController implements CallbackController { private final ArrayList mCallbacks = new ArrayList<>(); + private boolean mCommunalViewOccluded; private boolean mCommunalViewShowing; /** @@ -45,6 +46,12 @@ public class CommunalStateController implements */ default void onCommunalViewShowingChanged() { } + + /** + * Called when the occlusion of the communal view changes. + */ + default void onCommunalViewOccludedChanged() { + } } @VisibleForTesting @@ -57,13 +64,32 @@ public class CommunalStateController implements * @param communalViewShowing {@code true} if the view is showing, {@code false} otherwise. */ public void setCommunalViewShowing(boolean communalViewShowing) { - if (mCommunalViewShowing != communalViewShowing) { - mCommunalViewShowing = communalViewShowing; + if (mCommunalViewShowing == communalViewShowing) { + return; + } - final ArrayList callbacks = new ArrayList<>(mCallbacks); - for (Callback callback : callbacks) { - callback.onCommunalViewShowingChanged(); - } + mCommunalViewShowing = communalViewShowing; + + final ArrayList callbacks = new ArrayList<>(mCallbacks); + for (Callback callback : callbacks) { + callback.onCommunalViewShowingChanged(); + } + } + + /** + * Sets whether the communal view is occluded (but otherwise still showing). + * @param communalViewOccluded {@code true} if the view is occluded, {@code false} otherwise. + */ + public void setCommunalViewOccluded(boolean communalViewOccluded) { + if (mCommunalViewOccluded == communalViewOccluded) { + return; + } + + mCommunalViewOccluded = communalViewOccluded; + + ArrayList callbacks = new ArrayList<>(mCallbacks); + for (int i = 0; i < callbacks.size(); i++) { + callbacks.get(i).onCommunalViewOccludedChanged(); } } @@ -75,6 +101,14 @@ public class CommunalStateController implements return mCommunalViewShowing; } + /** + * Returns whether the communal view is occluded. + * @return {@code true} if the view is occluded, {@code false} otherwise. + */ + public boolean getCommunalViewOccluded() { + return mCommunalViewOccluded; + } + @Override public void addCallback(@NonNull Callback callback) { Objects.requireNonNull(callback, "Callback must not be null. b/128895449"); 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/src/com/android/systemui/statusbar/phone/NotificationPanelViewController.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelViewController.java index b8bef5592a715..e1dac45f97de4 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelViewController.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelViewController.java @@ -109,6 +109,7 @@ import com.android.systemui.communal.CommunalHostView; import com.android.systemui.communal.CommunalHostViewController; import com.android.systemui.communal.CommunalSource; import com.android.systemui.communal.CommunalSourceMonitor; +import com.android.systemui.communal.CommunalStateController; import com.android.systemui.communal.dagger.CommunalViewComponent; import com.android.systemui.controls.dagger.ControlsComponent; import com.android.systemui.dagger.qualifiers.DisplayId; @@ -327,6 +328,7 @@ public class NotificationPanelViewController extends PanelViewController { private final KeyguardBypassController mKeyguardBypassController; private final KeyguardUpdateMonitor mUpdateMonitor; private final CommunalSourceMonitor mCommunalSourceMonitor; + private final CommunalStateController mCommunalStateController; private final ConversationNotificationManager mConversationNotificationManager; private final AuthController mAuthController; private final MediaHierarchyManager mMediaHierarchyManager; @@ -711,6 +713,32 @@ public class NotificationPanelViewController extends PanelViewController { } }; + private final CommunalStateController.Callback mCommunalStateCallback = + new CommunalStateController.Callback() { + @Override + public void onCommunalViewShowingChanged() { + mKeyguardStatusViewController.setKeyguardStatusViewVisibility( + mBarState, + mKeyguardStateController.isKeyguardFadingAway(), + mStatusBarStateController.goingToFullShade(), + mBarState); + if (mKeyguardUserSwitcherController != null) { + mKeyguardUserSwitcherController.setKeyguardUserSwitcherVisibility( + mBarState, + mKeyguardStateController.isKeyguardFadingAway(), + mStatusBarStateController.goingToFullShade(), + mBarState); + } + if (mKeyguardQsUserSwitchController != null) { + mKeyguardQsUserSwitchController.setKeyguardQsUserSwitchVisibility( + mBarState, + mKeyguardStateController.isKeyguardFadingAway(), + mStatusBarStateController.goingToFullShade(), + mBarState); + } + } + }; + private final FalsingTapListener mFalsingTapListener = new FalsingTapListener() { @Override public void onDoubleTapRequired() { @@ -735,6 +763,7 @@ public class NotificationPanelViewController extends PanelViewController { FalsingCollector falsingCollector, NotificationLockscreenUserManager notificationLockscreenUserManager, NotificationEntryManager notificationEntryManager, + CommunalStateController communalStateController, KeyguardStateController keyguardStateController, StatusBarStateController statusBarStateController, DozeLog dozeLog, DozeParameters dozeParameters, CommandQueue commandQueue, VibratorHelper vibratorHelper, @@ -811,6 +840,7 @@ public class NotificationPanelViewController extends PanelViewController { mNotificationStackScrollLayoutController = notificationStackScrollLayoutController; mGroupManager = groupManager; mNotificationIconAreaController = notificationIconAreaController; + mCommunalStateController = communalStateController; mCommunalViewComponentFactory = communalViewComponentFactory; mKeyguardStatusViewComponentFactory = keyguardStatusViewComponentFactory; mKeyguardStatusBarViewComponentFactory = keyguardStatusBarViewComponentFactory; @@ -2384,6 +2414,10 @@ public class NotificationPanelViewController extends PanelViewController { setQSClippingBounds(); mNotificationStackScrollLayoutController.setQsExpansionFraction(qsExpansionFraction); mDepthController.setQsPanelExpansion(qsExpansionFraction); + + if (mCommunalViewController != null) { + mCommunalViewController.updateQsExpansion(qsExpansionFraction); + } } private void onStackYChanged(boolean shouldAnimate) { @@ -2722,6 +2756,10 @@ public class NotificationPanelViewController extends PanelViewController { } mTransitionToFullShadeQSPosition = position; updateQsExpansion(); + + if (mCommunalViewController != null) { + mCommunalViewController.updateShadeExpansion(mTransitioningToFullShadeProgress); + } } /** @@ -4660,6 +4698,7 @@ public class NotificationPanelViewController extends PanelViewController { mFalsingManager.addTapListener(mFalsingTapListener); mKeyguardIndicationController.init(); registerSettingsChangeListener(); + mCommunalStateController.addCallback(mCommunalStateCallback); } @Override @@ -4674,6 +4713,7 @@ public class NotificationPanelViewController extends PanelViewController { // Clear source when detached. setCommunalSource(null /*source*/); mFalsingManager.removeTapListener(mFalsingTapListener); + mCommunalStateController.removeCallback(mCommunalStateCallback); } } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/KeyguardQsUserSwitchController.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/KeyguardQsUserSwitchController.java index 5e70d0dbc4181..dd38f9826731d 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/KeyguardQsUserSwitchController.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/KeyguardQsUserSwitchController.java @@ -33,6 +33,7 @@ import com.android.keyguard.KeyguardVisibilityHelper; import com.android.keyguard.dagger.KeyguardUserSwitcherScope; import com.android.settingslib.drawable.CircleFramedDrawable; import com.android.systemui.R; +import com.android.systemui.communal.CommunalStateController; import com.android.systemui.dagger.qualifiers.Main; import com.android.systemui.keyguard.ScreenLifecycle; import com.android.systemui.plugins.FalsingManager; @@ -116,6 +117,7 @@ public class KeyguardQsUserSwitchController extends ViewController