diff options
| author | 2021-08-16 17:34:04 -0700 | |
|---|---|---|
| committer | 2021-08-20 11:33:18 -0700 | |
| commit | 1a487d3582959b454c6a53e30c10466ed0751de7 (patch) | |
| tree | 463354157297661972d2eba6595753cbb2bf0716 | |
| parent | aad7248b33886291f591b89085b0dc54b66bb6c4 (diff) | |
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
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 cb0c2827c7a5..320c2ea5ba78 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<CommunalHostView> private final StatusBarStateController mStatusBarStateController; private WeakReference<CommunalSource> 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<CommunalHostView> 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 e5385ec1543f..c72f5422b1f5 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<CommunalStateController.Callback> { private final ArrayList<Callback> 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; + } + + mCommunalViewShowing = communalViewShowing; + + final ArrayList<Callback> callbacks = new ArrayList<>(mCallbacks); + for (Callback callback : callbacks) { + callback.onCommunalViewShowingChanged(); + } + } - final ArrayList<Callback> 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<Callback> 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 08f0fd84b705..e1dac45f97de 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 03d26bed725e..990637955b24 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/communal/CommunalHostViewControllerTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/communal/CommunalHostViewControllerTest.java @@ -159,6 +159,27 @@ public class CommunalHostViewControllerTest extends SysuiTestCase { } @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<KeyguardUpdateMonitorCallback> callbackCapture = ArgumentCaptor.forClass(KeyguardUpdateMonitorCallback.class); |