Make addExpansionListener not send a change event on add
Sending an event immediately on add causes problems like b/278455611. The method now returns the event to preserve the old behavior. Test: manually verified Test: atest SystemUITests SystemUIGoogleTests Fixes: 281038056 Change-Id: I17979637f14edaca4df1d8235845036e0d781257
This commit is contained in:
@@ -21,7 +21,7 @@ constructor(
|
||||
fun enable(onPanelInteraction: Runnable) {
|
||||
if (action == null) {
|
||||
action = Action(onPanelInteraction)
|
||||
shadeExpansionStateManager.addShadeExpansionListener(this::onPanelExpansionChanged)
|
||||
shadeExpansionStateManager.addExpansionListener(this::onPanelExpansionChanged)
|
||||
} else {
|
||||
Log.e(TAG, "Already enabled")
|
||||
}
|
||||
|
||||
@@ -108,7 +108,9 @@ abstract class UdfpsAnimationViewController<T : UdfpsAnimationView>(
|
||||
}
|
||||
|
||||
override fun onViewAttached() {
|
||||
shadeExpansionStateManager.addExpansionListener(shadeExpansionListener)
|
||||
val currentState =
|
||||
shadeExpansionStateManager.addExpansionListener(shadeExpansionListener)
|
||||
shadeExpansionListener.onPanelExpansionChanged(currentState)
|
||||
dialogManager.registerListener(dialogListener)
|
||||
dumpManager.registerDumpable(dumpTag, this)
|
||||
}
|
||||
|
||||
@@ -290,7 +290,8 @@ constructor(
|
||||
qsExpansion = keyguardViewManager.qsExpansion
|
||||
keyguardViewManager.addCallback(statusBarKeyguardViewManagerCallback)
|
||||
configurationController.addCallback(configurationListener)
|
||||
shadeExpansionStateManager.addExpansionListener(shadeExpansionListener)
|
||||
val currentState = shadeExpansionStateManager.addExpansionListener(shadeExpansionListener)
|
||||
shadeExpansionListener.onPanelExpansionChanged(currentState)
|
||||
updateScaleFactor()
|
||||
view.updatePadding()
|
||||
updateAlpha()
|
||||
|
||||
@@ -480,7 +480,9 @@ public class NotificationShadeWindowViewController {
|
||||
setDragDownHelper(mLockscreenShadeTransitionController.getTouchHelper());
|
||||
|
||||
mDepthController.setRoot(mView);
|
||||
mShadeExpansionStateManager.addExpansionListener(mDepthController);
|
||||
ShadeExpansionChangeEvent currentState =
|
||||
mShadeExpansionStateManager.addExpansionListener(mDepthController);
|
||||
mDepthController.onPanelExpansionChanged(currentState);
|
||||
}
|
||||
|
||||
public NotificationShadeWindowView getView() {
|
||||
|
||||
@@ -49,23 +49,14 @@ class ShadeExpansionStateManager @Inject constructor() : ShadeStateEvents {
|
||||
private var dragDownPxAmount: Float = 0f
|
||||
|
||||
/**
|
||||
* Adds a listener that will be notified when the panel expansion fraction has changed.
|
||||
* Adds a listener that will be notified when the panel expansion fraction has changed and
|
||||
* returns the current state in a ShadeExpansionChangeEvent for legacy purposes (b/23035507).
|
||||
*
|
||||
* Listener will also be immediately notified with the current values.
|
||||
*/
|
||||
fun addExpansionListener(listener: ShadeExpansionListener) {
|
||||
addShadeExpansionListener(listener)
|
||||
listener.onPanelExpansionChanged(
|
||||
ShadeExpansionChangeEvent(fraction, expanded, tracking, dragDownPxAmount)
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a listener that will be notified when the panel expansion fraction has changed.
|
||||
* @see #addExpansionListener
|
||||
*/
|
||||
fun addShadeExpansionListener(listener: ShadeExpansionListener) {
|
||||
fun addExpansionListener(listener: ShadeExpansionListener): ShadeExpansionChangeEvent {
|
||||
expansionListeners.add(listener)
|
||||
return ShadeExpansionChangeEvent(fraction, expanded, tracking, dragDownPxAmount)
|
||||
}
|
||||
|
||||
/** Removes an expansion listener. */
|
||||
|
||||
@@ -67,7 +67,8 @@ constructor(shadeExpansionStateManager: ShadeExpansionStateManager) : ShadeRepos
|
||||
}
|
||||
}
|
||||
|
||||
shadeExpansionStateManager.addExpansionListener(callback)
|
||||
val currentState = shadeExpansionStateManager.addExpansionListener(callback)
|
||||
callback.onPanelExpansionChanged(currentState)
|
||||
trySendWithFailureLogging(ShadeModel(), TAG, "initial shade expansion info")
|
||||
|
||||
awaitClose { shadeExpansionStateManager.removeExpansionListener(callback) }
|
||||
|
||||
@@ -63,7 +63,9 @@ constructor(
|
||||
updateResources()
|
||||
}
|
||||
})
|
||||
shadeExpansionStateManager.addExpansionListener(this::onPanelExpansionChanged)
|
||||
val currentState =
|
||||
shadeExpansionStateManager.addExpansionListener(this::onPanelExpansionChanged)
|
||||
onPanelExpansionChanged(currentState)
|
||||
shadeExpansionStateManager.addStateListener(this::onPanelStateChanged)
|
||||
dumpManager.registerCriticalDumpable("ShadeTransitionController") { printWriter, _ ->
|
||||
dump(printWriter)
|
||||
|
||||
@@ -192,6 +192,7 @@ import com.android.systemui.shade.NotificationShadeWindowViewController;
|
||||
import com.android.systemui.shade.QuickSettingsController;
|
||||
import com.android.systemui.shade.ShadeController;
|
||||
import com.android.systemui.shade.ShadeExpansionChangeEvent;
|
||||
import com.android.systemui.shade.ShadeExpansionListener;
|
||||
import com.android.systemui.shade.ShadeExpansionStateManager;
|
||||
import com.android.systemui.shade.ShadeLogger;
|
||||
import com.android.systemui.shade.ShadeSurface;
|
||||
@@ -915,7 +916,11 @@ public class CentralSurfacesImpl implements CoreStartable, CentralSurfaces {
|
||||
|
||||
mScreenOffAnimationController = screenOffAnimationController;
|
||||
|
||||
mShadeExpansionStateManager.addExpansionListener(this::onPanelExpansionChanged);
|
||||
ShadeExpansionListener shadeExpansionListener = this::onPanelExpansionChanged;
|
||||
ShadeExpansionChangeEvent currentState =
|
||||
mShadeExpansionStateManager.addExpansionListener(shadeExpansionListener);
|
||||
shadeExpansionListener.onPanelExpansionChanged(currentState);
|
||||
|
||||
mShadeExpansionStateManager.addFullExpansionListener(this::onShadeExpansionFullyChanged);
|
||||
|
||||
mActivityIntentHelper = new ActivityIntentHelper(mContext);
|
||||
@@ -1266,7 +1271,9 @@ public class CentralSurfacesImpl implements CoreStartable, CentralSurfaces {
|
||||
if (!mFeatureFlags.isEnabled(Flags.NOTIFICATION_SHELF_REFACTOR)) {
|
||||
mNotificationIconAreaController.setupShelf(mNotificationShelfController);
|
||||
}
|
||||
mShadeExpansionStateManager.addExpansionListener(mWakeUpCoordinator);
|
||||
ShadeExpansionChangeEvent currentState =
|
||||
mShadeExpansionStateManager.addExpansionListener(mWakeUpCoordinator);
|
||||
mWakeUpCoordinator.onPanelExpansionChanged(currentState);
|
||||
|
||||
// Allow plugins to reference DarkIconDispatcher and StatusBarStateController
|
||||
mPluginDependencyProvider.allowPluginDependency(DarkIconDispatcher.class);
|
||||
|
||||
@@ -386,7 +386,9 @@ public class StatusBarKeyguardViewManager implements RemoteInputController.Callb
|
||||
mPrimaryBouncerCallbackInteractor.addBouncerExpansionCallback(mExpansionCallback);
|
||||
mShadeViewController = shadeViewController;
|
||||
if (shadeExpansionStateManager != null) {
|
||||
shadeExpansionStateManager.addExpansionListener(this);
|
||||
ShadeExpansionChangeEvent currentState =
|
||||
shadeExpansionStateManager.addExpansionListener(this);
|
||||
onPanelExpansionChanged(currentState);
|
||||
}
|
||||
mBypassController = bypassController;
|
||||
mNotificationContainer = notificationContainer;
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package com.android.systemui.biometrics;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
@@ -100,6 +101,8 @@ public class UdfpsKeyguardViewLegacyControllerBaseTest extends SysuiTestCase {
|
||||
when(mResourceContext.getString(anyInt())).thenReturn("test string");
|
||||
when(mKeyguardViewMediator.isAnimatingScreenOff()).thenReturn(false);
|
||||
when(mView.getUnpausedAlpha()).thenReturn(255);
|
||||
when(mShadeExpansionStateManager.addExpansionListener(any())).thenReturn(
|
||||
new ShadeExpansionChangeEvent(0, false, false, 0));
|
||||
mController = createUdfpsKeyguardViewController();
|
||||
}
|
||||
|
||||
|
||||
@@ -35,7 +35,8 @@ class ShadeExpansionStateManagerTest : SysuiTestCase() {
|
||||
@Test
|
||||
fun onPanelExpansionChanged_listenerNotified() {
|
||||
val listener = TestShadeExpansionListener()
|
||||
shadeExpansionStateManager.addExpansionListener(listener)
|
||||
val currentState = shadeExpansionStateManager.addExpansionListener(listener)
|
||||
listener.onPanelExpansionChanged(currentState)
|
||||
val fraction = 0.6f
|
||||
val expanded = true
|
||||
val tracking = true
|
||||
@@ -68,7 +69,8 @@ class ShadeExpansionStateManagerTest : SysuiTestCase() {
|
||||
)
|
||||
val listener = TestShadeExpansionListener()
|
||||
|
||||
shadeExpansionStateManager.addExpansionListener(listener)
|
||||
val currentState = shadeExpansionStateManager.addExpansionListener(listener)
|
||||
listener.onPanelExpansionChanged(currentState)
|
||||
|
||||
assertThat(listener.fraction).isEqualTo(fraction)
|
||||
assertThat(listener.expanded).isEqualTo(expanded)
|
||||
|
||||
@@ -23,6 +23,7 @@ import com.android.systemui.SysuiTestCase
|
||||
import com.android.systemui.shade.ShadeExpansionChangeEvent
|
||||
import com.android.systemui.shade.ShadeExpansionStateManager
|
||||
import com.android.systemui.shade.domain.model.ShadeModel
|
||||
import com.android.systemui.util.mockito.any
|
||||
import com.android.systemui.util.mockito.withArgCaptor
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||
@@ -37,6 +38,7 @@ import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.mockito.Mock
|
||||
import org.mockito.Mockito.verify
|
||||
import org.mockito.Mockito.`when`
|
||||
import org.mockito.MockitoAnnotations
|
||||
|
||||
@OptIn(ExperimentalCoroutinesApi::class)
|
||||
@@ -56,6 +58,9 @@ class ShadeRepositoryImplTest : SysuiTestCase() {
|
||||
MockitoAnnotations.initMocks(this)
|
||||
|
||||
underTest = ShadeRepositoryImpl(shadeExpansionStateManager)
|
||||
`when`(shadeExpansionStateManager.addExpansionListener(any())).thenReturn(
|
||||
ShadeExpansionChangeEvent(0f, false, false, 0f)
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user