Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1a487d35 authored by Bryce Lee's avatar Bryce Lee
Browse files

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
parent aad7248b
Loading
Loading
Loading
Loading
+25 −0
Original line number Diff line number Diff line
@@ -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);
    }
}
+40 −6
Original line number Diff line number Diff line
@@ -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,7 +64,10 @@ public class CommunalStateController implements
     * @param communalViewShowing {@code true} if the view is showing, {@code false} otherwise.
     */
    public void setCommunalViewShowing(boolean communalViewShowing) {
        if (mCommunalViewShowing != communalViewShowing) {
        if (mCommunalViewShowing == communalViewShowing) {
            return;
        }

        mCommunalViewShowing = communalViewShowing;

        final ArrayList<Callback> callbacks = new ArrayList<>(mCallbacks);
@@ -65,6 +75,22 @@ public class CommunalStateController implements
            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");
+8 −0
Original line number Diff line number Diff line
@@ -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);
        }
    }

    /**
+21 −0
Original line number Diff line number Diff line
@@ -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<KeyguardUpdateMonitorCallback> callbackCapture =