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

Commit 71331b4a authored by Nicolo' Mazzucato's avatar Nicolo' Mazzucato
Browse files

Send sysui state for all display when launcher connects

Previosuly we were just sending the SysUI State for the default display. Now we're sending it for all displays (only if the flag is on).

I regret having to make "notifySysUiStateFlagsForAllDisplays" public, but it seems there is no resonable way to trigger onServiceConnected from tests.

+ renamed the SysUIState to "DefaultSysUIState", and getting it from the PerDisplayRepository (but it's exactly the same instance while the flag is off.

+ Make FakeDisplayRepository have the default display at first.

Bug: 362719719
Bug: 398011576
Test: LauncherProxyServiceTest
Flag: com.android.systemui.shade_window_goes_around
Change-Id: I2717ad32077412a88e5d0a45e4f206725a217c95
parent 1dd660e4
Loading
Loading
Loading
Loading
+41 −19
Original line number Diff line number Diff line
@@ -89,6 +89,8 @@ import com.android.systemui.broadcast.BroadcastDispatcher;
import com.android.systemui.contextualeducation.GestureType;
import com.android.systemui.dagger.SysUISingleton;
import com.android.systemui.dagger.qualifiers.Main;
import com.android.systemui.display.data.repository.DisplayRepository;
import com.android.systemui.display.data.repository.PerDisplayRepository;
import com.android.systemui.dump.DumpManager;
import com.android.systemui.keyguard.KeyguardUnlockAnimationController;
import com.android.systemui.keyguard.KeyguardWmStateRefactor;
@@ -109,6 +111,7 @@ import com.android.systemui.settings.DisplayTracker;
import com.android.systemui.settings.UserTracker;
import com.android.systemui.shade.ShadeViewController;
import com.android.systemui.shade.domain.interactor.ShadeInteractor;
import com.android.systemui.shade.shared.flag.ShadeWindowGoesAround;
import com.android.systemui.shared.recents.ILauncherProxy;
import com.android.systemui.shared.recents.ISystemUiProxy;
import com.android.systemui.shared.system.QuickStepContract;
@@ -156,7 +159,9 @@ public class LauncherProxyService implements CallbackController<LauncherProxyLis
    private final Executor mMainExecutor;
    private final ShellInterface mShellInterface;
    private final Lazy<ShadeViewController> mShadeViewControllerLazy;
    private SysUiState mSysUiState;
    private final PerDisplayRepository<SysUiState> mPerDisplaySysUiStateRepository;
    private final DisplayRepository mDisplayRepository;
    private SysUiState mDefaultDisplaySysUIState;
    private final Handler mHandler;
    private final Lazy<NavigationBarController> mNavBarControllerLazy;
    private final ScreenPinningRequest mScreenPinningRequest;
@@ -586,9 +591,12 @@ public class LauncherProxyService implements CallbackController<LauncherProxyLis

            // Force-update the systemui state flags
            updateSystemUiStateFlags();
            // TODO b/398011576 - send the state for all displays.
            notifySystemUiStateFlags(mSysUiState.getFlags(), Display.DEFAULT_DISPLAY);

            if (ShadeWindowGoesAround.isEnabled()) {
               notifySysUiStateFlagsForAllDisplays();
            } else {
                notifySystemUiStateFlags(mDefaultDisplaySysUIState.getFlags(),
                        Display.DEFAULT_DISPLAY);
            }
            notifyConnectionChanged();
        }

@@ -614,6 +622,18 @@ public class LauncherProxyService implements CallbackController<LauncherProxyLis
        }
    };

    /** Propagates the flags for all displays to be notified to Launcher. */
    @VisibleForTesting
    public void notifySysUiStateFlagsForAllDisplays() {
        var displays = mDisplayRepository.getDisplayIds().getValue();
        for (int displayId : displays) {
            var state = mPerDisplaySysUiStateRepository.get(displayId);
            if (state != null) {
                notifySystemUiStateFlags(state.getFlags(), displayId);
            }
        }
    }

    private final StatusBarWindowCallback mStatusBarWindowCallback = this::onStatusBarStateChanged;

    // This is the death handler for the binder from the launcher service
@@ -671,7 +691,7 @@ public class LauncherProxyService implements CallbackController<LauncherProxyLis
            ScreenPinningRequest screenPinningRequest,
            NavigationModeController navModeController,
            NotificationShadeWindowController statusBarWinController,
            SysUiState sysUiState,
            PerDisplayRepository<SysUiState> perDisplaySysUiStateRepository,
            Provider<SceneInteractor> sceneInteractor,
            Provider<ShadeInteractor> shadeInteractor,
            UserTracker userTracker,
@@ -686,7 +706,8 @@ public class LauncherProxyService implements CallbackController<LauncherProxyLis
            Optional<UnfoldTransitionProgressForwarder> unfoldTransitionProgressForwarder,
            BroadcastDispatcher broadcastDispatcher,
            Optional<BackAnimation> backAnimation,
            ProcessWrapper processWrapper
            ProcessWrapper processWrapper,
            DisplayRepository displayRepository
    ) {
        // b/241601880: This component should only be running for primary users or
        // secondaryUsers when visibleBackgroundUsers are supported.
@@ -718,10 +739,10 @@ public class LauncherProxyService implements CallbackController<LauncherProxyLis
                com.android.internal.R.string.config_recentsComponentName));
        mQuickStepIntent = new Intent(ACTION_QUICKSTEP)
                .setPackage(mRecentsComponentName.getPackageName());
        // TODO b/398011576 - Here we're still only handling the default display state. We should
        //  have a callback for any sysuiState change.
        mSysUiState = sysUiState;
        mSysUiState.addCallback(mSysUiStateCallback);
        mPerDisplaySysUiStateRepository = perDisplaySysUiStateRepository;
        mDisplayRepository = displayRepository;
        mDefaultDisplaySysUIState = perDisplaySysUiStateRepository.get(Display.DEFAULT_DISPLAY);
        mDefaultDisplaySysUIState.addCallback(mSysUiStateCallback);
        mUiEventLogger = uiEventLogger;
        mDisplayTracker = displayTracker;
        mUnfoldTransitionProgressForwarder = unfoldTransitionProgressForwarder;
@@ -770,7 +791,7 @@ public class LauncherProxyService implements CallbackController<LauncherProxyLis
                if (mLauncherProxy != null) {
                    try {
                        if (DesktopModeStatus.canEnterDesktopMode(mContext)
                                && (sysUiState.getFlags()
                                && (mDefaultDisplaySysUIState.getFlags()
                                & SYSUI_STATE_FREEFORM_ACTIVE_IN_DESKTOP_MODE) != 0) {
                            return;
                        }
@@ -795,7 +816,7 @@ public class LauncherProxyService implements CallbackController<LauncherProxyLis
    }

    public void onVoiceSessionWindowVisibilityChanged(boolean visible) {
        mSysUiState.setFlag(SYSUI_STATE_VOICE_INTERACTION_WINDOW_SHOWING, visible)
        mDefaultDisplaySysUIState.setFlag(SYSUI_STATE_VOICE_INTERACTION_WINDOW_SHOWING, visible)
                .commitUpdate(mContext.getDisplayId());
    }

@@ -805,6 +826,7 @@ public class LauncherProxyService implements CallbackController<LauncherProxyLis
    }

    private void updateSystemUiStateFlags() {
        // TODO b/398011576 - We should update flags for all navigation bars.
        final NavigationBar navBarFragment =
                mNavBarControllerLazy.get().getDefaultNavigationBar();
        final NavigationBarView navBarView =
@@ -819,7 +841,7 @@ public class LauncherProxyService implements CallbackController<LauncherProxyLis
            navBarFragment.updateSystemUiStateFlags();
        }
        if (navBarView != null) {
            navBarView.updateDisabledSystemUiStateFlags(mSysUiState);
            navBarView.updateDisabledSystemUiStateFlags(mDefaultDisplaySysUIState);
        }
        mShadeViewControllerLazy.get().updateSystemUiStateFlags();
        if (mStatusBarWinController != null) {
@@ -845,7 +867,7 @@ public class LauncherProxyService implements CallbackController<LauncherProxyLis
    private void onStatusBarStateChanged(boolean keyguardShowing, boolean keyguardOccluded,
            boolean keyguardGoingAway, boolean bouncerShowing, boolean isDozing,
            boolean panelExpanded, boolean isDreaming, boolean communalShowing) {
        mSysUiState.setFlag(SYSUI_STATE_STATUS_BAR_KEYGUARD_SHOWING,
        mDefaultDisplaySysUIState.setFlag(SYSUI_STATE_STATUS_BAR_KEYGUARD_SHOWING,
                        keyguardShowing && !keyguardOccluded)
                .setFlag(SYSUI_STATE_STATUS_BAR_KEYGUARD_SHOWING_OCCLUDED,
                        keyguardShowing && keyguardOccluded)
@@ -1122,7 +1144,7 @@ public class LauncherProxyService implements CallbackController<LauncherProxyLis
            new WakefulnessLifecycle.Observer() {
                @Override
                public void onStartedWakingUp() {
                    mSysUiState
                    mDefaultDisplaySysUIState
                            .setFlag(SYSUI_STATE_AWAKE, true)
                            .setFlag(SYSUI_STATE_WAKEFULNESS_TRANSITION, true)
                            .commitUpdate(mContext.getDisplayId());
@@ -1130,7 +1152,7 @@ public class LauncherProxyService implements CallbackController<LauncherProxyLis

                @Override
                public void onFinishedWakingUp() {
                    mSysUiState
                    mDefaultDisplaySysUIState
                            .setFlag(SYSUI_STATE_AWAKE, true)
                            .setFlag(SYSUI_STATE_WAKEFULNESS_TRANSITION, false)
                            .commitUpdate(mContext.getDisplayId());
@@ -1138,7 +1160,7 @@ public class LauncherProxyService implements CallbackController<LauncherProxyLis

                @Override
                public void onStartedGoingToSleep() {
                    mSysUiState
                    mDefaultDisplaySysUIState
                            .setFlag(SYSUI_STATE_AWAKE, false)
                            .setFlag(SYSUI_STATE_WAKEFULNESS_TRANSITION, true)
                            .commitUpdate(mContext.getDisplayId());
@@ -1146,7 +1168,7 @@ public class LauncherProxyService implements CallbackController<LauncherProxyLis

                @Override
                public void onFinishedGoingToSleep() {
                    mSysUiState
                    mDefaultDisplaySysUIState
                            .setFlag(SYSUI_STATE_AWAKE, false)
                            .setFlag(SYSUI_STATE_WAKEFULNESS_TRANSITION, false)
                            .commitUpdate(mContext.getDisplayId());
@@ -1247,7 +1269,7 @@ public class LauncherProxyService implements CallbackController<LauncherProxyLis
        pw.print("  mActiveNavBarRegion="); pw.println(mActiveNavBarRegion);
        pw.print("  mNavBarMode="); pw.println(mNavBarMode);
        pw.print("  mIsPrevServiceCleanedUp="); pw.println(mIsPrevServiceCleanedUp);
        mSysUiState.dump(pw, args);
        mDefaultDisplaySysUIState.dump(pw, args);
    }

    public interface LauncherProxyListener {
+33 −1
Original line number Diff line number Diff line
@@ -32,12 +32,16 @@ import com.android.internal.logging.UiEventLogger
import com.android.systemui.SysuiTestCase
import com.android.systemui.broadcast.BroadcastDispatcher
import com.android.systemui.dagger.qualifiers.Main
import com.android.systemui.display.data.repository.displayRepository
import com.android.systemui.dump.DumpManager
import com.android.systemui.keyguard.KeyguardUnlockAnimationController
import com.android.systemui.keyguard.WakefulnessLifecycle
import com.android.systemui.keyguard.ui.view.InWindowLauncherUnlockAnimationManager
import com.android.systemui.kosmos.testScope
import com.android.systemui.log.assertLogsWtf
import com.android.systemui.model.fakeSysUIStatePerDisplayRepository
import com.android.systemui.model.sysUiState
import com.android.systemui.model.sysUiStateFactory
import com.android.systemui.navigationbar.NavigationBarController
import com.android.systemui.navigationbar.NavigationModeController
import com.android.systemui.process.ProcessWrapper
@@ -63,11 +67,14 @@ import com.android.wm.shell.sysui.ShellInterface
import com.google.common.util.concurrent.MoreExecutors
import java.util.Optional
import java.util.concurrent.Executor
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.test.runTest
import org.junit.After
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.ArgumentMatchers
import org.mockito.ArgumentMatchers.anyLong
import org.mockito.ArgumentMatchers.eq
import org.mockito.Mock
import org.mockito.Mockito.any
@@ -96,8 +103,10 @@ class LauncherProxyServiceTest : SysuiTestCase() {
    private val displayTracker = FakeDisplayTracker(mContext)
    private val fakeSystemClock = FakeSystemClock()
    private val sysUiState = kosmos.sysUiState
    private val sysUiStateFactory = kosmos.sysUiStateFactory
    private val wakefulnessLifecycle =
        WakefulnessLifecycle(mContext, null, fakeSystemClock, dumpManager)
    private val sysuiStatePerDisplayRepository = kosmos.fakeSysUIStatePerDisplayRepository

    @Mock private lateinit var launcherProxy: ILauncherProxy.Stub
    @Mock private lateinit var packageManager: PackageManager
@@ -149,6 +158,8 @@ class LauncherProxyServiceTest : SysuiTestCase() {

        // return isSystemUser as true by default.
        `when`(processWrapper.isSystemUser).thenReturn(true)
        sysuiStatePerDisplayRepository.add(Display.DEFAULT_DISPLAY, sysUiState)
        runBlocking { kosmos.displayRepository.apply { addDisplay(0) } }
        subject = createLauncherProxyService(context)
    }

@@ -249,6 +260,26 @@ class LauncherProxyServiceTest : SysuiTestCase() {
        verify(spyContext, times(0)).bindServiceAsUser(any(), any(), anyInt(), any())
    }

    @Test
    fun notifySysUiStateFlagsForAllDisplays_triggersUpdateInAllDisplays() =
        kosmos.testScope.runTest {
            kosmos.displayRepository.apply {
                addDisplay(0)
                addDisplay(1)
                addDisplay(2)
            }
            kosmos.fakeSysUIStatePerDisplayRepository.apply {
                add(1, sysUiStateFactory.create(1))
                add(2, sysUiStateFactory.create(2))
            }
            clearInvocations(launcherProxy)
            subject.notifySysUiStateFlagsForAllDisplays()

            verify(launcherProxy).onSystemUiStateChanged(anyLong(), eq(0))
            verify(launcherProxy).onSystemUiStateChanged(anyLong(), eq(1))
            verify(launcherProxy).onSystemUiStateChanged(anyLong(), eq(2))
        }

    private fun createLauncherProxyService(ctx: Context): LauncherProxyService {
        return LauncherProxyService(
            ctx,
@@ -260,7 +291,7 @@ class LauncherProxyServiceTest : SysuiTestCase() {
            screenPinningRequest,
            navModeController,
            statusBarWinController,
            sysUiState,
            kosmos.fakeSysUIStatePerDisplayRepository,
            mock(),
            mock(),
            userTracker,
@@ -276,6 +307,7 @@ class LauncherProxyServiceTest : SysuiTestCase() {
            broadcastDispatcher,
            backAnimation,
            processWrapper,
            kosmos.displayRepository,
        )
    }
}
+3 −1
Original line number Diff line number Diff line
@@ -38,7 +38,9 @@ val Kosmos.sysUiStateFactory by Fixture {
    }
}

val Kosmos.fakeSysUIStatePerDisplayRepository by Fixture { FakePerDisplayRepository<SysUiState>() }
val Kosmos.fakeSysUIStatePerDisplayRepository by Fixture {
    FakePerDisplayRepository<SysUiState>().apply { add(Display.DEFAULT_DISPLAY, sysUiState) }
}

val Kosmos.sysuiStateInteractor by Fixture {
    SysUIStateDisplaysInteractor(fakeSysUIStatePerDisplayRepository, displayRepository)