From 1a487d3582959b454c6a53e30c10466ed0751de7 Mon Sep 17 00:00:00 2001 From: Bryce Lee Date: Mon, 16 Aug 2021 17:34:04 -0700 Subject: [PATCH] Publish when communal view is occluded. This changelist pipes the proper signals through the CommunalHostViewController to notify the CommunalStateController when the communal view is occluded. Currently, this applies when the shade (notification or QS) is brought over the communal view. Bug: 196889682 Test: atest CommunalHostViewControllerTest#testReportOcclusion Change-Id: Ic0fbe837b0a2fdcad8dfcb13c83a7444542cd84a --- .../communal/CommunalHostViewController.java | 25 ++++++++++ .../communal/CommunalStateController.java | 46 ++++++++++++++++--- .../NotificationPanelViewController.java | 8 ++++ .../CommunalHostViewControllerTest.java | 21 +++++++++ 4 files changed, 94 insertions(+), 6 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/communal/CommunalHostViewController.java b/packages/SystemUI/src/com/android/systemui/communal/CommunalHostViewController.java index cb0c2827c7a53..320c2ea5ba78d 100644 --- a/packages/SystemUI/src/com/android/systemui/communal/CommunalHostViewController.java +++ b/packages/SystemUI/src/com/android/systemui/communal/CommunalHostViewController.java @@ -53,6 +53,8 @@ public class CommunalHostViewController 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/phone/NotificationPanelViewController.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelViewController.java index 08f0fd84b7053..e1dac45f97de4 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelViewController.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelViewController.java @@ -2414,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) { @@ -2752,6 +2756,10 @@ public class NotificationPanelViewController extends PanelViewController { } mTransitionToFullShadeQSPosition = position; updateQsExpansion(); + + if (mCommunalViewController != null) { + mCommunalViewController.updateShadeExpansion(mTransitioningToFullShadeProgress); + } } /** diff --git a/packages/SystemUI/tests/src/com/android/systemui/communal/CommunalHostViewControllerTest.java b/packages/SystemUI/tests/src/com/android/systemui/communal/CommunalHostViewControllerTest.java index 03d26bed725e0..990637955b248 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/communal/CommunalHostViewControllerTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/communal/CommunalHostViewControllerTest.java @@ -158,6 +158,27 @@ public class CommunalHostViewControllerTest extends SysuiTestCase { verify(mCommunalView).setVisibility(View.VISIBLE); } + @Test + public void testReportOcclusion() { + // Ensure CommunalHostViewController reports view occluded when either the QS or Shade is + // expanded. + mController.updateShadeExpansion(0); + verify(mCommunalStateController).setCommunalViewOccluded(false); + clearInvocations(mCommunalStateController); + mController.updateQsExpansion(.5f); + verify(mCommunalStateController).setCommunalViewOccluded(true); + clearInvocations(mCommunalStateController); + mController.updateShadeExpansion(.7f); + verify(mCommunalStateController).setCommunalViewOccluded(true); + clearInvocations(mCommunalStateController); + mController.updateShadeExpansion(0); + verify(mCommunalStateController).setCommunalViewOccluded(true); + clearInvocations(mCommunalStateController); + mController.updateQsExpansion(0f); + verify(mCommunalStateController).setCommunalViewOccluded(false); + clearInvocations(mCommunalStateController); + } + @Test public void testCommunalStateControllerHideNotified() { ArgumentCaptor callbackCapture =