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

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

Clean up AmbientStatusBarViewController's Status Bar Listener.

This changelist moves registration of AmbientStatusBarViewController's
StatusBarWindowStateListener from construction to initialization and
then adds unregistering to destroy.

Test: atest AmbientStatusBarViewControllerTest#testStatusBarWindowStateControllerListenerLifecycle
Bug: 360088321
Flag: EXEMPT bugfix
Change-Id: I67f7ba02620649ebdcce958bd37f3c39117eb46b
parent 71712222
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -148,6 +148,7 @@ public class AmbientStatusBarViewControllerTest extends SysuiTestCase {
                mKosmos.getWifiInteractor(),
                mKosmos.getCommunalSceneInteractor(),
                mLogBuffer);
        mController.onInit();
    }

    @Test
@@ -517,6 +518,15 @@ public class AmbientStatusBarViewControllerTest extends SysuiTestCase {
        verify(mDreamOverlayStateController).setDreamOverlayStatusBarVisible(false);
    }

    @Test
    public void testStatusBarWindowStateControllerListenerLifecycle() {
        ArgumentCaptor<StatusBarWindowStateListener> listenerCaptor =
                ArgumentCaptor.forClass(StatusBarWindowStateListener.class);
        verify(mStatusBarWindowStateController).addListener(listenerCaptor.capture());
        mController.destroy();
        verify(mStatusBarWindowStateController).removeListener(eq(listenerCaptor.getValue()));
    }

    private StatusBarWindowStateListener updateStatusBarWindowState(boolean show) {
        when(mStatusBarWindowStateController.windowIsShowing()).thenReturn(show);
        final ArgumentCaptor<StatusBarWindowStateListener>
+17 −1
Original line number Diff line number Diff line
@@ -48,6 +48,7 @@ import com.android.systemui.statusbar.policy.IndividualSensorPrivacyController;
import com.android.systemui.statusbar.policy.NextAlarmController;
import com.android.systemui.statusbar.policy.ZenModeController;
import com.android.systemui.statusbar.window.StatusBarWindowStateController;
import com.android.systemui.statusbar.window.StatusBarWindowStateListener;
import com.android.systemui.util.ViewController;
import com.android.systemui.util.time.DateFormatUtil;

@@ -127,6 +128,9 @@ public class AmbientStatusBarViewController extends ViewController<AmbientStatus
    private final DreamOverlayStatusBarItemsProvider.Callback mStatusBarItemsProviderCallback =
            this::onStatusBarItemsChanged;

    private final StatusBarWindowStateListener mStatusBarWindowStateListener =
            this::onSystemStatusBarStateChanged;

    @Inject
    public AmbientStatusBarViewController(
            AmbientStatusBarView view,
@@ -161,10 +165,22 @@ public class AmbientStatusBarViewController extends ViewController<AmbientStatus
        mWifiInteractor = wifiInteractor;
        mCommunalSceneInteractor = communalSceneInteractor;
        mLogger = new DreamLogger(logBuffer, TAG);
    }

    @Override
    protected void onInit() {
        super.onInit();

        // Register to receive show/hide updates for the system status bar. Our custom status bar
        // needs to hide when the system status bar is showing to ovoid overlapping status bars.
        statusBarWindowStateController.addListener(this::onSystemStatusBarStateChanged);
        mStatusBarWindowStateController.addListener(mStatusBarWindowStateListener);
    }

    @Override
    public void destroy() {
        mStatusBarWindowStateController.removeListener(mStatusBarWindowStateListener);

        super.destroy();
    }

    @Override