Merge "[Status Bar Refactor] 2.2/N: Migrate StatusBar's panelExpansionChanged callback to the correct listener interface." into sc-v2-dev am: 56b6645afb am: 4817ba36f8

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/16092653

Change-Id: Iad2f1ab8fc867e35d8fe19e52a7740fc38e44440
This commit is contained in:
Caitlin Cassidy
2021-11-03 19:36:52 +00:00
committed by Automerger Merge Worker
11 changed files with 120 additions and 64 deletions

View File

@@ -329,7 +329,9 @@ class NotificationShadeDepthController @Inject constructor(
/**
* Update blurs when pulling down the shade
*/
override fun onPanelExpansionChanged(rawFraction: Float, tracking: Boolean) {
override fun onPanelExpansionChanged(
rawFraction: Float, expanded: Boolean, tracking: Boolean
) {
val timestamp = SystemClock.elapsedRealtimeNanos()
val expansion = MathUtils.saturate(
(rawFraction - panelPullDownMinFraction) / (1f - panelPullDownMinFraction))

View File

@@ -294,7 +294,7 @@ class NotificationWakeUpCoordinator @Inject constructor(
this.state = newState
}
override fun onPanelExpansionChanged(fraction: Float, tracking: Boolean) {
override fun onPanelExpansionChanged(fraction: Float, expanded: Boolean, tracking: Boolean) {
val collapsedEnough = fraction <= 0.9f
if (collapsedEnough != this.collapsedEnoughToHide) {
val couldShowPulsingHuns = canShowPulsingHuns

View File

@@ -1093,7 +1093,8 @@ public abstract class PanelViewController {
mBar.panelExpansionChanged(mExpandedFraction, isExpanded());
}
updateVisibility();
mPanelExpansionStateManager.onPanelExpansionChanged(mExpandedFraction, mTracking);
mPanelExpansionStateManager.onPanelExpansionChanged(
mExpandedFraction, isExpanded(), mTracking);
}
public boolean isExpanded() {

View File

@@ -272,7 +272,7 @@ public class ScrimController implements ViewTreeObserver.OnPreDrawListener, Dump
}
});
panelExpansionStateManager.addListener(
(fraction, tracking) -> setRawPanelExpansionFraction(fraction)
(fraction, expanded, tracking) -> setRawPanelExpansionFraction(fraction)
);
mColors = new GradientColors();

View File

@@ -909,7 +909,7 @@ public class StatusBar extends SystemUI implements
lockscreenShadeTransitionController.setStatusbar(this);
mExpansionChangedListeners = new ArrayList<>();
addExpansionChangedListener(this::onPanelExpansionChanged);
mPanelExpansionStateManager.addListener(this::onPanelExpansionChanged);
mBubbleExpandListener =
(isExpanding, key) -> mContext.getMainExecutor().execute(() -> {
@@ -1158,8 +1158,6 @@ public class StatusBar extends SystemUI implements
mNotificationIconAreaController.setupShelf(mNotificationShelfController);
mPanelExpansionStateManager.addListener(mWakeUpCoordinator);
mPanelExpansionStateManager.addListener(
this::dispatchPanelExpansionForKeyguardDismiss);
mUserSwitcherController.init(mNotificationShadeWindowView);
@@ -1424,15 +1422,15 @@ public class StatusBar extends SystemUI implements
/**
* When swiping up to dismiss the lock screen, the panel expansion goes from 1f to 0f. This
* results in the clock/notifications/other content disappearing off the top of the screen.
* When swiping up to dismiss the lock screen, the panel expansion fraction goes from 1f to 0f.
* This results in the clock/notifications/other content disappearing off the top of the screen.
*
* We also use the expansion amount to animate in the app/launcher surface from the bottom of
* We also use the expansion fraction to animate in the app/launcher surface from the bottom of
* the screen, 'pushing' off the notifications and other content. To do this, we dispatch the
* expansion amount to the KeyguardViewMediator if we're in the process of dismissing the
* expansion fraction to the KeyguardViewMediator if we're in the process of dismissing the
* keyguard.
*/
private void dispatchPanelExpansionForKeyguardDismiss(float expansion, boolean trackingTouch) {
private void dispatchPanelExpansionForKeyguardDismiss(float fraction, boolean trackingTouch) {
// Things that mean we're not dismissing the keyguard, and should ignore this expansion:
// - Keyguard isn't even visible.
// - Keyguard is visible, but can't be dismissed (swiping up will show PIN/password prompt).
@@ -1451,12 +1449,14 @@ public class StatusBar extends SystemUI implements
|| mKeyguardViewMediator.isAnimatingBetweenKeyguardAndSurfaceBehindOrWillBe()
|| mKeyguardUnlockAnimationController.isUnlockingWithSmartSpaceTransition()) {
mKeyguardStateController.notifyKeyguardDismissAmountChanged(
1f - expansion, trackingTouch);
1f - fraction, trackingTouch);
}
}
private void onPanelExpansionChanged(float frac, boolean expanded) {
if (frac == 0 || frac == 1) {
private void onPanelExpansionChanged(float fraction, boolean expanded, boolean tracking) {
dispatchPanelExpansionForKeyguardDismiss(fraction, tracking);
if (fraction == 0 || fraction == 1) {
if (getNavigationBarView() != null) {
getNavigationBarView().onStatusBarPanelStateChanged();
}

View File

@@ -328,7 +328,7 @@ public class StatusBarKeyguardViewManager implements RemoteInputController.Callb
}
@Override
public void onPanelExpansionChanged(float fraction, boolean tracking) {
public void onPanelExpansionChanged(float fraction, boolean expanded, boolean tracking) {
// We don't want to translate the bounce when:
// • Keyguard is occluded, because we're in a FLAG_SHOW_WHEN_LOCKED activity and need to
// conserve the original animation.

View File

@@ -24,7 +24,8 @@ public interface PanelExpansionListener {
* lock screen and swiping to pull down the notification shade.
*
* @param fraction 0 when collapsed, 1 when fully expanded.
* @param expanded true if the panel should be considered expanded.
* @param tracking {@code true} when the user is actively dragging the panel.
*/
void onPanelExpansionChanged(float fraction, boolean tracking);
void onPanelExpansionChanged(float fraction, boolean expanded, boolean tracking);
}

View File

@@ -32,6 +32,7 @@ class PanelExpansionStateManager @Inject constructor() {
private val listeners: MutableList<PanelExpansionListener> = mutableListOf()
@FloatRange(from = 0.0, to = 1.0) private var fraction: Float = 0f
private var expanded: Boolean = false
private var tracking: Boolean = false
/**
@@ -41,16 +42,18 @@ class PanelExpansionStateManager @Inject constructor() {
*/
fun addListener(listener: PanelExpansionListener) {
listeners.add(listener)
listener.onPanelExpansionChanged(fraction, tracking)
listener.onPanelExpansionChanged(fraction, expanded, tracking)
}
/** Called when the panel expansion has changed. Notifies all listeners of change. */
fun onPanelExpansionChanged(
@FloatRange(from = 0.0, to = 1.0) fraction: Float,
expanded: Boolean,
tracking: Boolean
) {
this.fraction = fraction
this.expanded = expanded
this.tracking = tracking
listeners.forEach { it.onPanelExpansionChanged(fraction, tracking) }
listeners.forEach { it.onPanelExpansionChanged(fraction, expanded, tracking) }
}
}

View File

@@ -119,15 +119,17 @@ class NotificationShadeDepthControllerTest : SysuiTestCase() {
@Test
fun onPanelExpansionChanged_apliesBlur_ifShade() {
notificationShadeDepthController.onPanelExpansionChanged(1f /* expansion */,
false /* tracking */)
notificationShadeDepthController.onPanelExpansionChanged(
rawFraction = 1f, expanded = true, tracking = false
)
verify(shadeAnimation).animateTo(eq(maxBlur), any())
}
@Test
fun onPanelExpansionChanged_animatesBlurIn_ifShade() {
notificationShadeDepthController.onPanelExpansionChanged(0.01f /* expansion */,
false /* tracking */)
notificationShadeDepthController.onPanelExpansionChanged(
rawFraction = 0.01f, expanded = false, tracking = false
)
verify(shadeAnimation).animateTo(eq(maxBlur), any())
}
@@ -135,8 +137,9 @@ class NotificationShadeDepthControllerTest : SysuiTestCase() {
fun onPanelExpansionChanged_animatesBlurOut_ifShade() {
onPanelExpansionChanged_animatesBlurIn_ifShade()
clearInvocations(shadeAnimation)
notificationShadeDepthController.onPanelExpansionChanged(0f /* expansion */,
false /* tracking */)
notificationShadeDepthController.onPanelExpansionChanged(
rawFraction = 0f, expanded = false, tracking = false
)
verify(shadeAnimation).animateTo(eq(0), any())
}
@@ -144,16 +147,19 @@ class NotificationShadeDepthControllerTest : SysuiTestCase() {
fun onPanelExpansionChanged_animatesBlurOut_ifFlick() {
onPanelExpansionChanged_apliesBlur_ifShade()
clearInvocations(shadeAnimation)
notificationShadeDepthController.onPanelExpansionChanged(1f /* expansion */,
true /* tracking */)
notificationShadeDepthController.onPanelExpansionChanged(
rawFraction = 1f, expanded = true, tracking = true
)
verify(shadeAnimation, never()).animateTo(anyInt(), any())
notificationShadeDepthController.onPanelExpansionChanged(0.9f /* expansion */,
true /* tracking */)
notificationShadeDepthController.onPanelExpansionChanged(
rawFraction = 0.9f, expanded = true, tracking = true
)
verify(shadeAnimation, never()).animateTo(anyInt(), any())
notificationShadeDepthController.onPanelExpansionChanged(0.8f /* expansion */,
false /* tracking */)
notificationShadeDepthController.onPanelExpansionChanged(
rawFraction = 0.8f, expanded = true, tracking = false
)
verify(shadeAnimation).animateTo(eq(0), any())
}
@@ -161,24 +167,28 @@ class NotificationShadeDepthControllerTest : SysuiTestCase() {
fun onPanelExpansionChanged_animatesBlurIn_ifFlickCancelled() {
onPanelExpansionChanged_animatesBlurOut_ifFlick()
clearInvocations(shadeAnimation)
notificationShadeDepthController.onPanelExpansionChanged(0.6f /* expansion */,
true /* tracking */)
notificationShadeDepthController.onPanelExpansionChanged(
rawFraction = 0.6f, expanded = true, tracking = true
)
verify(shadeAnimation).animateTo(eq(maxBlur), any())
}
@Test
fun onPanelExpansionChanged_respectsMinPanelPullDownFraction() {
notificationShadeDepthController.panelPullDownMinFraction = 0.5f
notificationShadeDepthController.onPanelExpansionChanged(0.5f /* expansion */,
true /* tracking */)
notificationShadeDepthController.onPanelExpansionChanged(
rawFraction = 0.5f, expanded = true, tracking = true
)
assertThat(notificationShadeDepthController.shadeExpansion).isEqualTo(0f)
notificationShadeDepthController.onPanelExpansionChanged(0.75f /* expansion */,
true /* tracking */)
notificationShadeDepthController.onPanelExpansionChanged(
rawFraction = 0.75f, expanded = true, tracking = true
)
assertThat(notificationShadeDepthController.shadeExpansion).isEqualTo(0.5f)
notificationShadeDepthController.onPanelExpansionChanged(1f /* expansion */,
true /* tracking */)
notificationShadeDepthController.onPanelExpansionChanged(
rawFraction = 1f, expanded = true, tracking = true
)
assertThat(notificationShadeDepthController.shadeExpansion).isEqualTo(1f)
}
@@ -196,7 +206,9 @@ class NotificationShadeDepthControllerTest : SysuiTestCase() {
fun setQsPanelExpansion_appliesBlur() {
statusBarState = StatusBarState.KEYGUARD
notificationShadeDepthController.qsPanelExpansion = 1f
notificationShadeDepthController.onPanelExpansionChanged(1f, tracking = false)
notificationShadeDepthController.onPanelExpansionChanged(
rawFraction = 1f, expanded = true, tracking = false
)
notificationShadeDepthController.updateBlurCallback.doFrame(0)
verify(blurUtils).applyBlur(any(), eq(maxBlur), eq(false))
}
@@ -205,7 +217,9 @@ class NotificationShadeDepthControllerTest : SysuiTestCase() {
fun setQsPanelExpansion_easing() {
statusBarState = StatusBarState.KEYGUARD
notificationShadeDepthController.qsPanelExpansion = 0.25f
notificationShadeDepthController.onPanelExpansionChanged(1f, tracking = false)
notificationShadeDepthController.onPanelExpansionChanged(
rawFraction = 1f, expanded = true, tracking = false
)
notificationShadeDepthController.updateBlurCallback.doFrame(0)
verify(wallpaperController).setNotificationShadeZoom(
eq(ShadeInterpolation.getNotificationScrimAlpha(0.25f)))
@@ -261,7 +275,9 @@ class NotificationShadeDepthControllerTest : SysuiTestCase() {
@Test
fun updateBlurCallback_setsBlur_whenExpanded() {
notificationShadeDepthController.onPanelExpansionChanged(1f, false)
notificationShadeDepthController.onPanelExpansionChanged(
rawFraction = 1f, expanded = true, tracking = false
)
`when`(shadeAnimation.radius).thenReturn(maxBlur.toFloat())
notificationShadeDepthController.updateBlurCallback.doFrame(0)
verify(blurUtils).applyBlur(any(), eq(maxBlur), eq(false))
@@ -269,7 +285,9 @@ class NotificationShadeDepthControllerTest : SysuiTestCase() {
@Test
fun updateBlurCallback_ignoreShadeBlurUntilHidden_overridesZoom() {
notificationShadeDepthController.onPanelExpansionChanged(1f, false)
notificationShadeDepthController.onPanelExpansionChanged(
rawFraction = 1f, expanded = true, tracking = false
)
`when`(shadeAnimation.radius).thenReturn(maxBlur.toFloat())
notificationShadeDepthController.blursDisabledForAppLaunch = true
notificationShadeDepthController.updateBlurCallback.doFrame(0)
@@ -300,7 +318,9 @@ class NotificationShadeDepthControllerTest : SysuiTestCase() {
// Brightness mirror is fully visible
`when`(brightnessSpring.ratio).thenReturn(1f)
// And shade is blurred
notificationShadeDepthController.onPanelExpansionChanged(1f, false)
notificationShadeDepthController.onPanelExpansionChanged(
rawFraction = 1f, expanded = true, tracking = false
)
`when`(shadeAnimation.radius).thenReturn(maxBlur.toFloat())
notificationShadeDepthController.updateBlurCallback.doFrame(0)

View File

@@ -184,8 +184,10 @@ public class StatusBarKeyguardViewManagerTest extends SysuiTestCase {
public void onPanelExpansionChanged_neverHidesFullscreenBouncer() {
// TODO: StatusBar should not be here, mBouncer.isFullscreenBouncer() should do the same.
when(mStatusBar.isFullScreenUserSwitcherState()).thenReturn(true);
mStatusBarKeyguardViewManager.onPanelExpansionChanged(0.5f /* expansion */,
true /* tracking */);
mStatusBarKeyguardViewManager.onPanelExpansionChanged(
/* fraction= */ 0.5f,
/* expanded= */ false,
/* tracking= */ true);
verify(mBouncer).setExpansion(eq(KeyguardBouncer.EXPANSION_VISIBLE));
}
@@ -193,51 +195,67 @@ public class StatusBarKeyguardViewManagerTest extends SysuiTestCase {
public void onPanelExpansionChanged_neverHidesScrimmedBouncer() {
when(mBouncer.isShowing()).thenReturn(true);
when(mBouncer.isScrimmed()).thenReturn(true);
mStatusBarKeyguardViewManager.onPanelExpansionChanged(0.5f /* expansion */,
true /* tracking */);
mStatusBarKeyguardViewManager.onPanelExpansionChanged(
/* fraction= */ 0.5f,
/* expanded= */ false,
/* tracking= */ true);
verify(mBouncer).setExpansion(eq(KeyguardBouncer.EXPANSION_VISIBLE));
}
@Test
public void onPanelExpansionChanged_neverShowsDuringHintAnimation() {
when(mNotificationPanelView.isUnlockHintRunning()).thenReturn(true);
mStatusBarKeyguardViewManager.onPanelExpansionChanged(0.5f /* expansion */,
true /* tracking */);
mStatusBarKeyguardViewManager.onPanelExpansionChanged(
/* fraction= */ 0.5f,
/* expanded= */ false,
/* tracking= */ true);
verify(mBouncer).setExpansion(eq(KeyguardBouncer.EXPANSION_HIDDEN));
}
@Test
public void onPanelExpansionChanged_propagatesToBouncer() {
mStatusBarKeyguardViewManager.onPanelExpansionChanged(0.5f /* expansion */,
true /* tracking */);
mStatusBarKeyguardViewManager.onPanelExpansionChanged(
/* fraction= */ 0.5f,
/* expanded= */ false,
/* tracking= */ true);
verify(mBouncer).setExpansion(eq(0.5f));
}
@Test
public void onPanelExpansionChanged_showsBouncerWhenSwiping() {
when(mKeyguardStateController.canDismissLockScreen()).thenReturn(false);
mStatusBarKeyguardViewManager.onPanelExpansionChanged(0.5f /* expansion */,
true /* tracking */);
mStatusBarKeyguardViewManager.onPanelExpansionChanged(
/* fraction= */ 0.5f,
/* expanded= */ false,
/* tracking= */ true);
verify(mBouncer).show(eq(false), eq(false));
// But not when it's already visible
reset(mBouncer);
when(mBouncer.isShowing()).thenReturn(true);
mStatusBarKeyguardViewManager.onPanelExpansionChanged(0.5f /* expansion */, true /* tracking */);
mStatusBarKeyguardViewManager.onPanelExpansionChanged(
/* fraction= */ 0.5f,
/* expanded= */ false,
/* tracking= */ true);
verify(mBouncer, never()).show(eq(false), eq(false));
// Or animating away
reset(mBouncer);
when(mBouncer.isAnimatingAway()).thenReturn(true);
mStatusBarKeyguardViewManager.onPanelExpansionChanged(0.5f /* expansion */, true /* tracking */);
mStatusBarKeyguardViewManager.onPanelExpansionChanged(
/* fraction= */ 0.5f,
/* expanded= */ false,
/* tracking= */ true);
verify(mBouncer, never()).show(eq(false), eq(false));
}
@Test
public void onPanelExpansionChanged_neverTranslatesBouncerWhenOccluded() {
mStatusBarKeyguardViewManager.setOccluded(true /* occluded */, false /* animate */);
mStatusBarKeyguardViewManager.onPanelExpansionChanged(0.5f /* expansion */,
true /* tracking */);
mStatusBarKeyguardViewManager.onPanelExpansionChanged(
/* fraction= */ 0.5f,
/* expanded= */ false,
/* tracking= */ true);
verify(mBouncer, never()).setExpansion(eq(0.5f));
}
@@ -245,16 +263,20 @@ public class StatusBarKeyguardViewManagerTest extends SysuiTestCase {
public void onPanelExpansionChanged_neverTranslatesBouncerWhenWakeAndUnlock() {
when(mBiometrucUnlockController.getMode())
.thenReturn(BiometricUnlockController.MODE_WAKE_AND_UNLOCK);
mStatusBarKeyguardViewManager.onPanelExpansionChanged(KeyguardBouncer.EXPANSION_VISIBLE,
false /* tracking */);
mStatusBarKeyguardViewManager.onPanelExpansionChanged(
/* fraction= */ KeyguardBouncer.EXPANSION_VISIBLE,
/* expanded= */ true,
/* tracking= */ false);
verify(mBouncer, never()).setExpansion(anyFloat());
}
@Test
public void onPanelExpansionChanged_neverTranslatesBouncerWhenLaunchingApp() {
when(mStatusBar.isInLaunchTransition()).thenReturn(true);
mStatusBarKeyguardViewManager.onPanelExpansionChanged(KeyguardBouncer.EXPANSION_VISIBLE,
false /* tracking */);
mStatusBarKeyguardViewManager.onPanelExpansionChanged(
/* fraction= */ KeyguardBouncer.EXPANSION_VISIBLE,
/* expanded= */ true,
/* tracking= */ false);
verify(mBouncer, never()).setExpansion(anyFloat());
}

View File

@@ -37,36 +37,43 @@ class PanelExpansionStateManagerTest : SysuiTestCase() {
val listener = TestPanelExpansionListener()
panelExpansionStateManager.addListener(listener)
val fraction = 0.6f
val expanded = true
val tracking = true
panelExpansionStateManager.onPanelExpansionChanged(fraction, tracking)
panelExpansionStateManager.onPanelExpansionChanged(fraction, expanded, tracking)
assertThat(listener.fraction).isEqualTo(fraction)
assertThat(listener.expanded).isEqualTo(expanded)
assertThat(listener.tracking).isEqualTo(tracking)
}
@Test
fun addPanelExpansionListener_listenerNotifiedOfCurrentValues() {
val fraction = 0.6f
val expanded = true
val tracking = true
panelExpansionStateManager.onPanelExpansionChanged(fraction, tracking)
panelExpansionStateManager.onPanelExpansionChanged(fraction, expanded, tracking)
val listener = TestPanelExpansionListener()
panelExpansionStateManager.addListener(listener)
assertThat(listener.fraction).isEqualTo(fraction)
assertThat(listener.expanded).isEqualTo(expanded)
assertThat(listener.tracking).isEqualTo(tracking)
}
class TestPanelExpansionListener : PanelExpansionListener {
var fraction: Float = 0f
var expanded: Boolean = false
var tracking: Boolean = false
override fun onPanelExpansionChanged(
fraction: Float,
expanded: Boolean,
tracking: Boolean
) {
this.fraction = fraction
this.expanded = expanded
this.tracking = tracking
}
}