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
This commit is contained in:
Bryce Lee
2021-08-16 17:34:04 -07:00
parent aad7248b33
commit 1a487d3582
4 changed files with 94 additions and 6 deletions

View File

@@ -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);
}
}

View File

@@ -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;
}
final ArrayList<Callback> callbacks = new ArrayList<>(mCallbacks);
for (Callback callback : callbacks) {
callback.onCommunalViewShowingChanged();
}
mCommunalViewShowing = communalViewShowing;
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");

View File

@@ -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);
}
}
/**

View File

@@ -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 =