Merge "Make addExpansionListener not send a change event on add" into udc-dev

This commit is contained in:
Justin Weir
2023-05-16 20:38:55 +00:00
committed by Android (Google) Code Review
12 changed files with 42 additions and 24 deletions

View File

@@ -21,7 +21,7 @@ constructor(
fun enable(onPanelInteraction: Runnable) { fun enable(onPanelInteraction: Runnable) {
if (action == null) { if (action == null) {
action = Action(onPanelInteraction) action = Action(onPanelInteraction)
shadeExpansionStateManager.addShadeExpansionListener(this::onPanelExpansionChanged) shadeExpansionStateManager.addExpansionListener(this::onPanelExpansionChanged)
} else { } else {
Log.e(TAG, "Already enabled") Log.e(TAG, "Already enabled")
} }

View File

@@ -108,7 +108,9 @@ abstract class UdfpsAnimationViewController<T : UdfpsAnimationView>(
} }
override fun onViewAttached() { override fun onViewAttached() {
shadeExpansionStateManager.addExpansionListener(shadeExpansionListener) val currentState =
shadeExpansionStateManager.addExpansionListener(shadeExpansionListener)
shadeExpansionListener.onPanelExpansionChanged(currentState)
dialogManager.registerListener(dialogListener) dialogManager.registerListener(dialogListener)
dumpManager.registerDumpable(dumpTag, this) dumpManager.registerDumpable(dumpTag, this)
} }

View File

@@ -290,7 +290,8 @@ constructor(
qsExpansion = keyguardViewManager.qsExpansion qsExpansion = keyguardViewManager.qsExpansion
keyguardViewManager.addCallback(statusBarKeyguardViewManagerCallback) keyguardViewManager.addCallback(statusBarKeyguardViewManagerCallback)
configurationController.addCallback(configurationListener) configurationController.addCallback(configurationListener)
shadeExpansionStateManager.addExpansionListener(shadeExpansionListener) val currentState = shadeExpansionStateManager.addExpansionListener(shadeExpansionListener)
shadeExpansionListener.onPanelExpansionChanged(currentState)
updateScaleFactor() updateScaleFactor()
view.updatePadding() view.updatePadding()
updateAlpha() updateAlpha()

View File

@@ -480,7 +480,9 @@ public class NotificationShadeWindowViewController {
setDragDownHelper(mLockscreenShadeTransitionController.getTouchHelper()); setDragDownHelper(mLockscreenShadeTransitionController.getTouchHelper());
mDepthController.setRoot(mView); mDepthController.setRoot(mView);
mShadeExpansionStateManager.addExpansionListener(mDepthController); ShadeExpansionChangeEvent currentState =
mShadeExpansionStateManager.addExpansionListener(mDepthController);
mDepthController.onPanelExpansionChanged(currentState);
} }
public NotificationShadeWindowView getView() { public NotificationShadeWindowView getView() {

View File

@@ -49,23 +49,14 @@ class ShadeExpansionStateManager @Inject constructor() : ShadeStateEvents {
private var dragDownPxAmount: Float = 0f 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 * @see #addExpansionListener
*/ */
fun addShadeExpansionListener(listener: ShadeExpansionListener) { fun addExpansionListener(listener: ShadeExpansionListener): ShadeExpansionChangeEvent {
expansionListeners.add(listener) expansionListeners.add(listener)
return ShadeExpansionChangeEvent(fraction, expanded, tracking, dragDownPxAmount)
} }
/** Removes an expansion listener. */ /** Removes an expansion listener. */

View File

@@ -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") trySendWithFailureLogging(ShadeModel(), TAG, "initial shade expansion info")
awaitClose { shadeExpansionStateManager.removeExpansionListener(callback) } awaitClose { shadeExpansionStateManager.removeExpansionListener(callback) }

View File

@@ -63,7 +63,9 @@ constructor(
updateResources() updateResources()
} }
}) })
shadeExpansionStateManager.addExpansionListener(this::onPanelExpansionChanged) val currentState =
shadeExpansionStateManager.addExpansionListener(this::onPanelExpansionChanged)
onPanelExpansionChanged(currentState)
shadeExpansionStateManager.addStateListener(this::onPanelStateChanged) shadeExpansionStateManager.addStateListener(this::onPanelStateChanged)
dumpManager.registerCriticalDumpable("ShadeTransitionController") { printWriter, _ -> dumpManager.registerCriticalDumpable("ShadeTransitionController") { printWriter, _ ->
dump(printWriter) dump(printWriter)

View File

@@ -192,6 +192,7 @@ import com.android.systemui.shade.NotificationShadeWindowViewController;
import com.android.systemui.shade.QuickSettingsController; import com.android.systemui.shade.QuickSettingsController;
import com.android.systemui.shade.ShadeController; import com.android.systemui.shade.ShadeController;
import com.android.systemui.shade.ShadeExpansionChangeEvent; import com.android.systemui.shade.ShadeExpansionChangeEvent;
import com.android.systemui.shade.ShadeExpansionListener;
import com.android.systemui.shade.ShadeExpansionStateManager; import com.android.systemui.shade.ShadeExpansionStateManager;
import com.android.systemui.shade.ShadeLogger; import com.android.systemui.shade.ShadeLogger;
import com.android.systemui.shade.ShadeSurface; import com.android.systemui.shade.ShadeSurface;
@@ -915,7 +916,11 @@ public class CentralSurfacesImpl implements CoreStartable, CentralSurfaces {
mScreenOffAnimationController = screenOffAnimationController; mScreenOffAnimationController = screenOffAnimationController;
mShadeExpansionStateManager.addExpansionListener(this::onPanelExpansionChanged); ShadeExpansionListener shadeExpansionListener = this::onPanelExpansionChanged;
ShadeExpansionChangeEvent currentState =
mShadeExpansionStateManager.addExpansionListener(shadeExpansionListener);
shadeExpansionListener.onPanelExpansionChanged(currentState);
mShadeExpansionStateManager.addFullExpansionListener(this::onShadeExpansionFullyChanged); mShadeExpansionStateManager.addFullExpansionListener(this::onShadeExpansionFullyChanged);
mActivityIntentHelper = new ActivityIntentHelper(mContext); mActivityIntentHelper = new ActivityIntentHelper(mContext);
@@ -1268,7 +1273,9 @@ public class CentralSurfacesImpl implements CoreStartable, CentralSurfaces {
if (!mFeatureFlags.isEnabled(Flags.NOTIFICATION_SHELF_REFACTOR)) { if (!mFeatureFlags.isEnabled(Flags.NOTIFICATION_SHELF_REFACTOR)) {
mNotificationIconAreaController.setupShelf(mNotificationShelfController); mNotificationIconAreaController.setupShelf(mNotificationShelfController);
} }
mShadeExpansionStateManager.addExpansionListener(mWakeUpCoordinator); ShadeExpansionChangeEvent currentState =
mShadeExpansionStateManager.addExpansionListener(mWakeUpCoordinator);
mWakeUpCoordinator.onPanelExpansionChanged(currentState);
// Allow plugins to reference DarkIconDispatcher and StatusBarStateController // Allow plugins to reference DarkIconDispatcher and StatusBarStateController
mPluginDependencyProvider.allowPluginDependency(DarkIconDispatcher.class); mPluginDependencyProvider.allowPluginDependency(DarkIconDispatcher.class);

View File

@@ -386,7 +386,9 @@ public class StatusBarKeyguardViewManager implements RemoteInputController.Callb
mPrimaryBouncerCallbackInteractor.addBouncerExpansionCallback(mExpansionCallback); mPrimaryBouncerCallbackInteractor.addBouncerExpansionCallback(mExpansionCallback);
mShadeViewController = shadeViewController; mShadeViewController = shadeViewController;
if (shadeExpansionStateManager != null) { if (shadeExpansionStateManager != null) {
shadeExpansionStateManager.addExpansionListener(this); ShadeExpansionChangeEvent currentState =
shadeExpansionStateManager.addExpansionListener(this);
onPanelExpansionChanged(currentState);
} }
mBypassController = bypassController; mBypassController = bypassController;
mNotificationContainer = notificationContainer; mNotificationContainer = notificationContainer;

View File

@@ -16,6 +16,7 @@
package com.android.systemui.biometrics; package com.android.systemui.biometrics;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Mockito.times; import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
@@ -100,6 +101,8 @@ public class UdfpsKeyguardViewLegacyControllerBaseTest extends SysuiTestCase {
when(mResourceContext.getString(anyInt())).thenReturn("test string"); when(mResourceContext.getString(anyInt())).thenReturn("test string");
when(mKeyguardViewMediator.isAnimatingScreenOff()).thenReturn(false); when(mKeyguardViewMediator.isAnimatingScreenOff()).thenReturn(false);
when(mView.getUnpausedAlpha()).thenReturn(255); when(mView.getUnpausedAlpha()).thenReturn(255);
when(mShadeExpansionStateManager.addExpansionListener(any())).thenReturn(
new ShadeExpansionChangeEvent(0, false, false, 0));
mController = createUdfpsKeyguardViewController(); mController = createUdfpsKeyguardViewController();
} }

View File

@@ -35,7 +35,8 @@ class ShadeExpansionStateManagerTest : SysuiTestCase() {
@Test @Test
fun onPanelExpansionChanged_listenerNotified() { fun onPanelExpansionChanged_listenerNotified() {
val listener = TestShadeExpansionListener() val listener = TestShadeExpansionListener()
shadeExpansionStateManager.addExpansionListener(listener) val currentState = shadeExpansionStateManager.addExpansionListener(listener)
listener.onPanelExpansionChanged(currentState)
val fraction = 0.6f val fraction = 0.6f
val expanded = true val expanded = true
val tracking = true val tracking = true
@@ -68,7 +69,8 @@ class ShadeExpansionStateManagerTest : SysuiTestCase() {
) )
val listener = TestShadeExpansionListener() val listener = TestShadeExpansionListener()
shadeExpansionStateManager.addExpansionListener(listener) val currentState = shadeExpansionStateManager.addExpansionListener(listener)
listener.onPanelExpansionChanged(currentState)
assertThat(listener.fraction).isEqualTo(fraction) assertThat(listener.fraction).isEqualTo(fraction)
assertThat(listener.expanded).isEqualTo(expanded) assertThat(listener.expanded).isEqualTo(expanded)

View File

@@ -23,6 +23,7 @@ import com.android.systemui.SysuiTestCase
import com.android.systemui.shade.ShadeExpansionChangeEvent import com.android.systemui.shade.ShadeExpansionChangeEvent
import com.android.systemui.shade.ShadeExpansionStateManager import com.android.systemui.shade.ShadeExpansionStateManager
import com.android.systemui.shade.domain.model.ShadeModel import com.android.systemui.shade.domain.model.ShadeModel
import com.android.systemui.util.mockito.any
import com.android.systemui.util.mockito.withArgCaptor import com.android.systemui.util.mockito.withArgCaptor
import com.google.common.truth.Truth.assertThat import com.google.common.truth.Truth.assertThat
import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.ExperimentalCoroutinesApi
@@ -37,6 +38,7 @@ import org.junit.Test
import org.junit.runner.RunWith import org.junit.runner.RunWith
import org.mockito.Mock import org.mockito.Mock
import org.mockito.Mockito.verify import org.mockito.Mockito.verify
import org.mockito.Mockito.`when`
import org.mockito.MockitoAnnotations import org.mockito.MockitoAnnotations
@OptIn(ExperimentalCoroutinesApi::class) @OptIn(ExperimentalCoroutinesApi::class)
@@ -56,6 +58,9 @@ class ShadeRepositoryImplTest : SysuiTestCase() {
MockitoAnnotations.initMocks(this) MockitoAnnotations.initMocks(this)
underTest = ShadeRepositoryImpl(shadeExpansionStateManager) underTest = ShadeRepositoryImpl(shadeExpansionStateManager)
`when`(shadeExpansionStateManager.addExpansionListener(any())).thenReturn(
ShadeExpansionChangeEvent(0f, false, false, 0f)
)
} }
@Test @Test