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

Commit 85a7408c authored by Mike Schneider's avatar Mike Schneider Committed by Automerger Merge Worker
Browse files

Merge "Change the use of ScreenLifecycle to WakefulnessLifecycle." into...

Merge "Change the use of ScreenLifecycle to WakefulnessLifecycle." into tm-qpr-dev am: 83623aaa am: 89e911fc am: 4b34b707

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



Change-Id: I0047723894bd3f8b0191c522b53eacc3abdbe850
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 8bc9b232 4b34b707
Loading
Loading
Loading
Loading
+27 −26
Original line number Diff line number Diff line
@@ -116,28 +116,25 @@ public class QuickStepContract {
    public static final int SYSUI_STATE_FREEFORM_ACTIVE_IN_DESKTOP_MODE = 1 << 26;
    // Device dreaming state
    public static final int SYSUI_STATE_DEVICE_DREAMING = 1 << 27;
    // Whether the screen is currently on. Note that the screen is considered on while turning on,
    // but not while turning off.
    public static final int SYSUI_STATE_SCREEN_ON = 1 << 28;
    // Whether the screen is currently transitioning into the state indicated by
    // SYSUI_STATE_SCREEN_ON.
    public static final int SYSUI_STATE_SCREEN_TRANSITION = 1 << 29;
    // Whether the device is currently awake (as opposed to asleep, see WakefulnessLifecycle).
    // Note that the device is awake on while waking up on, but not while going to sleep.
    public static final int SYSUI_STATE_AWAKE = 1 << 28;
    // Whether the device is currently transitioning between awake/asleep indicated by
    // SYSUI_STATE_AWAKE.
    public static final int SYSUI_STATE_WAKEFULNESS_TRANSITION = 1 << 29;
    // The notification panel expansion fraction is > 0
    public static final int SYSUI_STATE_NOTIFICATION_PANEL_VISIBLE = 1 << 30;

    // Mask for SystemUiStateFlags to isolate SYSUI_STATE_SCREEN_ON and
    // SYSUI_STATE_SCREEN_TRANSITION, to match SCREEN_STATE_*
    public static final int SYSUI_STATE_SCREEN_STATE_MASK =
            SYSUI_STATE_SCREEN_ON | SYSUI_STATE_SCREEN_TRANSITION;
    // Screen is off.
    public static final int SCREEN_STATE_OFF = 0;
    // Screen is on.
    public static final int SCREEN_STATE_ON = SYSUI_STATE_SCREEN_ON;
    // Screen is still on, but transitioning to turn off.
    public static final int SCREEN_STATE_TURNING_OFF = SYSUI_STATE_SCREEN_TRANSITION;
    // Screen was off and is now turning on.
    public static final int SCREEN_STATE_TURNING_ON =
            SYSUI_STATE_SCREEN_TRANSITION | SYSUI_STATE_SCREEN_ON;
    // Mask for SystemUiStateFlags to isolate SYSUI_STATE_AWAKE and
    // SYSUI_STATE_WAKEFULNESS_TRANSITION, to match WAKEFULNESS_* constants
    public static final int SYSUI_STATE_WAKEFULNESS_MASK =
            SYSUI_STATE_AWAKE | SYSUI_STATE_WAKEFULNESS_TRANSITION;
    // Mirroring the WakefulnessLifecycle#Wakefulness states
    public static final int WAKEFULNESS_ASLEEP = 0;
    public static final int WAKEFULNESS_AWAKE = SYSUI_STATE_AWAKE;
    public static final int WAKEFULNESS_GOING_TO_SLEEP = SYSUI_STATE_WAKEFULNESS_TRANSITION;
    public static final int WAKEFULNESS_WAKING =
            SYSUI_STATE_WAKEFULNESS_TRANSITION | SYSUI_STATE_AWAKE;

    // Whether the back gesture is allowed (or ignored) by the Shade
    public static final boolean ALLOW_BACK_GESTURE_IN_SHADE = SystemProperties.getBoolean(
@@ -172,8 +169,9 @@ public class QuickStepContract {
            SYSUI_STATE_VOICE_INTERACTION_WINDOW_SHOWING,
            SYSUI_STATE_FREEFORM_ACTIVE_IN_DESKTOP_MODE,
            SYSUI_STATE_DEVICE_DREAMING,
            SYSUI_STATE_SCREEN_ON,
            SYSUI_STATE_SCREEN_TRANSITION,
            SYSUI_STATE_AWAKE,
            SYSUI_STATE_WAKEFULNESS_TRANSITION,
            SYSUI_STATE_NOTIFICATION_PANEL_VISIBLE,
    })
    public @interface SystemUiStateFlags {}

@@ -195,7 +193,7 @@ public class QuickStepContract {
            str.add("navbar_hidden");
        }
        if ((flags & SYSUI_STATE_NOTIFICATION_PANEL_EXPANDED) != 0) {
            str.add("notif_visible");
            str.add("notif_expanded");
        }
        if ((flags & SYSUI_STATE_QUICK_SETTINGS_EXPANDED) != 0) {
            str.add("qs_visible");
@@ -263,11 +261,14 @@ public class QuickStepContract {
        if ((flags & SYSUI_STATE_DEVICE_DREAMING) != 0) {
            str.add("device_dreaming");
        }
        if ((flags & SYSUI_STATE_SCREEN_TRANSITION) != 0) {
            str.add("screen_transition");
        if ((flags & SYSUI_STATE_WAKEFULNESS_TRANSITION) != 0) {
            str.add("wakefulness_transition");
        }
        if ((flags & SYSUI_STATE_AWAKE) != 0) {
            str.add("awake");
        }
        if ((flags & SYSUI_STATE_SCREEN_ON) != 0) {
            str.add("screen_on");
        if ((flags & SYSUI_STATE_NOTIFICATION_PANEL_VISIBLE) != 0) {
            str.add("notif_visible");
        }

        return str.toString();
+85 −70
Original line number Diff line number Diff line
@@ -28,15 +28,15 @@ import static com.android.systemui.shared.system.QuickStepContract.KEY_EXTRA_SYS
import static com.android.systemui.shared.system.QuickStepContract.KEY_EXTRA_UNFOLD_ANIMATION_FORWARDER;
import static com.android.systemui.shared.system.QuickStepContract.KEY_EXTRA_UNLOCK_ANIMATION_CONTROLLER;
import static com.android.systemui.shared.system.QuickStepContract.KEY_EXTRA_WINDOW_CORNER_RADIUS;
import static com.android.systemui.shared.system.QuickStepContract.SYSUI_STATE_AWAKE;
import static com.android.systemui.shared.system.QuickStepContract.SYSUI_STATE_BOUNCER_SHOWING;
import static com.android.systemui.shared.system.QuickStepContract.SYSUI_STATE_DEVICE_DOZING;
import static com.android.systemui.shared.system.QuickStepContract.SYSUI_STATE_DEVICE_DREAMING;
import static com.android.systemui.shared.system.QuickStepContract.SYSUI_STATE_SCREEN_ON;
import static com.android.systemui.shared.system.QuickStepContract.SYSUI_STATE_SCREEN_TRANSITION;
import static com.android.systemui.shared.system.QuickStepContract.SYSUI_STATE_STATUS_BAR_KEYGUARD_SHOWING;
import static com.android.systemui.shared.system.QuickStepContract.SYSUI_STATE_STATUS_BAR_KEYGUARD_SHOWING_OCCLUDED;
import static com.android.systemui.shared.system.QuickStepContract.SYSUI_STATE_TRACING_ENABLED;
import static com.android.systemui.shared.system.QuickStepContract.SYSUI_STATE_VOICE_INTERACTION_WINDOW_SHOWING;
import static com.android.systemui.shared.system.QuickStepContract.SYSUI_STATE_WAKEFULNESS_TRANSITION;

import android.annotation.FloatRange;
import android.app.ActivityTaskManager;
@@ -85,6 +85,7 @@ import com.android.systemui.dagger.qualifiers.Main;
import com.android.systemui.dump.DumpManager;
import com.android.systemui.keyguard.KeyguardUnlockAnimationController;
import com.android.systemui.keyguard.ScreenLifecycle;
import com.android.systemui.keyguard.WakefulnessLifecycle;
import com.android.systemui.model.SysUiState;
import com.android.systemui.navigationbar.NavigationBar;
import com.android.systemui.navigationbar.NavigationBarController;
@@ -521,6 +522,7 @@ public class OverviewProxyService implements CallbackController<OverviewProxyLis
            NotificationShadeWindowController statusBarWinController, SysUiState sysUiState,
            UserTracker userTracker,
            ScreenLifecycle screenLifecycle,
            WakefulnessLifecycle wakefulnessLifecycle,
            UiEventLogger uiEventLogger,
            DisplayTracker displayTracker,
            KeyguardUnlockAnimationController sysuiUnlockAnimationController,
@@ -598,8 +600,8 @@ public class OverviewProxyService implements CallbackController<OverviewProxyLis
        // Listen for user setup
        mUserTracker.addCallback(mUserChangedCallback, mMainExecutor);

        screenLifecycle.addObserver(mLifecycleObserver);

        screenLifecycle.addObserver(mScreenLifecycleObserver);
        wakefulnessLifecycle.addObserver(mWakefulnessLifecycleObserver);
        // Connect to the service
        updateEnabledState();
        startConnectionToCurrentUser();
@@ -864,54 +866,36 @@ public class OverviewProxyService implements CallbackController<OverviewProxyLis
        }
    }

    private final ScreenLifecycle.Observer mLifecycleObserver = new ScreenLifecycle.Observer() {
    private final ScreenLifecycle.Observer mScreenLifecycleObserver =
            new ScreenLifecycle.Observer() {
                /**
                 * Notifies the Launcher that screen turned on and ready to use
                 */
                @Override
                public void onScreenTurnedOn() {
            mSysUiState
                .setFlag(SYSUI_STATE_SCREEN_ON, true)
                .setFlag(SYSUI_STATE_SCREEN_TRANSITION, false)
                .commitUpdate(mContext.getDisplayId());

                    try {
                        if (mOverviewProxy != null) {
                            mOverviewProxy.onScreenTurnedOn();
                        } else {
                    Log.e(TAG_OPS, "Failed to get overview proxy for screen turned on event.");
                            Log.e(TAG_OPS,
                                    "Failed to get overview proxy for screen turned on event.");
                        }
                    } catch (RemoteException e) {
                        Log.e(TAG_OPS, "Failed to call onScreenTurnedOn()", e);
                    }
                }

        /**
         * Notifies the Launcher that screen turned off.
         */
        @Override
        public void onScreenTurnedOff() {
            mSysUiState
                .setFlag(SYSUI_STATE_SCREEN_ON, false)
                .setFlag(SYSUI_STATE_SCREEN_TRANSITION, false)
                .commitUpdate(mContext.getDisplayId());
        }

                /**
                 * Notifies the Launcher that screen is starting to turn on.
                 */
                @Override
                public void onScreenTurningOff() {
            mSysUiState
                .setFlag(SYSUI_STATE_SCREEN_ON, false)
                .setFlag(SYSUI_STATE_SCREEN_TRANSITION, true)
                .commitUpdate(mContext.getDisplayId());

                    try {
                        if (mOverviewProxy != null) {
                            mOverviewProxy.onScreenTurningOff();
                        } else {
                    Log.e(TAG_OPS, "Failed to get overview proxy for screen turning off event.");
                            Log.e(TAG_OPS,
                                    "Failed to get overview proxy for screen turning off event.");
                        }
                    } catch (RemoteException e) {
                        Log.e(TAG_OPS, "Failed to call onScreenTurningOff()", e);
@@ -923,16 +907,12 @@ public class OverviewProxyService implements CallbackController<OverviewProxyLis
                 */
                @Override
                public void onScreenTurningOn() {
            mSysUiState
                .setFlag(SYSUI_STATE_SCREEN_ON, true)
                .setFlag(SYSUI_STATE_SCREEN_TRANSITION, true)
                .commitUpdate(mContext.getDisplayId());

                    try {
                        if (mOverviewProxy != null) {
                            mOverviewProxy.onScreenTurningOn();
                        } else {
                    Log.e(TAG_OPS, "Failed to get overview proxy for screen turning on event.");
                            Log.e(TAG_OPS,
                                    "Failed to get overview proxy for screen turning on event.");
                        }
                    } catch (RemoteException e) {
                        Log.e(TAG_OPS, "Failed to call onScreenTurningOn()", e);
@@ -940,6 +920,41 @@ public class OverviewProxyService implements CallbackController<OverviewProxyLis
                }
            };

    private final WakefulnessLifecycle.Observer mWakefulnessLifecycleObserver =
            new WakefulnessLifecycle.Observer() {
                @Override
                public void onStartedWakingUp() {
                    mSysUiState
                            .setFlag(SYSUI_STATE_AWAKE, true)
                            .setFlag(SYSUI_STATE_WAKEFULNESS_TRANSITION, true)
                            .commitUpdate(mContext.getDisplayId());
                }

                @Override
                public void onFinishedWakingUp() {
                    mSysUiState
                            .setFlag(SYSUI_STATE_AWAKE, true)
                            .setFlag(SYSUI_STATE_WAKEFULNESS_TRANSITION, false)
                            .commitUpdate(mContext.getDisplayId());
                }

                @Override
                public void onStartedGoingToSleep() {
                    mSysUiState
                            .setFlag(SYSUI_STATE_AWAKE, false)
                            .setFlag(SYSUI_STATE_WAKEFULNESS_TRANSITION, true)
                            .commitUpdate(mContext.getDisplayId());
                }

                @Override
                public void onFinishedGoingToSleep() {
                    mSysUiState
                            .setFlag(SYSUI_STATE_AWAKE, false)
                            .setFlag(SYSUI_STATE_WAKEFULNESS_TRANSITION, false)
                            .commitUpdate(mContext.getDisplayId());
                }
            };

    void notifyToggleRecentApps() {
        for (int i = mConnectionCallbacks.size() - 1; i >= 0; --i) {
            mConnectionCallbacks.get(i).onToggleRecentApps();
+31 −17
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package com.android.systemui.recents
import android.content.ComponentName
import android.content.pm.PackageManager
import android.content.pm.ResolveInfo
import android.os.PowerManager
import android.testing.AndroidTestingRunner
import android.testing.TestableContext
import android.testing.TestableLooper
@@ -30,6 +31,7 @@ import com.android.systemui.dagger.qualifiers.Main
import com.android.systemui.dump.DumpManager
import com.android.systemui.keyguard.KeyguardUnlockAnimationController
import com.android.systemui.keyguard.ScreenLifecycle
import com.android.systemui.keyguard.WakefulnessLifecycle
import com.android.systemui.model.SysUiState
import com.android.systemui.navigationbar.NavigationBarController
import com.android.systemui.navigationbar.NavigationModeController
@@ -37,16 +39,17 @@ import com.android.systemui.recents.OverviewProxyService.ACTION_QUICKSTEP
import com.android.systemui.settings.FakeDisplayTracker
import com.android.systemui.settings.UserTracker
import com.android.systemui.shared.recents.IOverviewProxy
import com.android.systemui.shared.system.QuickStepContract.SCREEN_STATE_OFF
import com.android.systemui.shared.system.QuickStepContract.SCREEN_STATE_ON
import com.android.systemui.shared.system.QuickStepContract.SCREEN_STATE_TURNING_OFF
import com.android.systemui.shared.system.QuickStepContract.SCREEN_STATE_TURNING_ON
import com.android.systemui.shared.system.QuickStepContract.SYSUI_STATE_SCREEN_STATE_MASK
import com.android.systemui.shared.system.QuickStepContract.SYSUI_STATE_WAKEFULNESS_MASK
import com.android.systemui.shared.system.QuickStepContract.WAKEFULNESS_ASLEEP
import com.android.systemui.shared.system.QuickStepContract.WAKEFULNESS_AWAKE
import com.android.systemui.shared.system.QuickStepContract.WAKEFULNESS_GOING_TO_SLEEP
import com.android.systemui.shared.system.QuickStepContract.WAKEFULNESS_WAKING
import com.android.systemui.statusbar.CommandQueue
import com.android.systemui.statusbar.NotificationShadeWindowController
import com.android.systemui.statusbar.phone.CentralSurfaces
import com.android.systemui.unfold.progress.UnfoldTransitionProgressForwarder
import com.android.systemui.util.mockito.whenever
import com.android.systemui.util.time.FakeSystemClock
import com.android.wm.shell.sysui.ShellInterface
import com.google.common.util.concurrent.MoreExecutors
import dagger.Lazy
@@ -60,6 +63,7 @@ import org.mockito.ArgumentMatchers
import org.mockito.Mock
import org.mockito.Mockito.any
import org.mockito.Mockito.anyInt
import org.mockito.Mockito.clearInvocations
import org.mockito.Mockito.intThat
import org.mockito.Mockito.mock
import org.mockito.Mockito.verify
@@ -75,8 +79,11 @@ class OverviewProxyServiceTest : SysuiTestCase() {
    private lateinit var subject: OverviewProxyService
    private val dumpManager = DumpManager()
    private val displayTracker = FakeDisplayTracker(mContext)
    private val fakeSystemClock = FakeSystemClock()
    private val sysUiState = SysUiState(displayTracker)
    private val screenLifecycle = ScreenLifecycle(dumpManager)
    private val wakefulnessLifecycle =
        WakefulnessLifecycle(mContext, null, fakeSystemClock, dumpManager)

    @Mock private lateinit var overviewProxy: IOverviewProxy.Stub
    @Mock private lateinit var packageManager: PackageManager
@@ -130,6 +137,7 @@ class OverviewProxyServiceTest : SysuiTestCase() {
                sysUiState,
                userTracker,
                screenLifecycle,
                wakefulnessLifecycle,
                uiEventLogger,
                displayTracker,
                sysuiUnlockAnimationController,
@@ -145,42 +153,48 @@ class OverviewProxyServiceTest : SysuiTestCase() {
    }

    @Test
    fun `ScreenLifecycle - screenTurnedOn triggers SysUI state flag changes `() {
        screenLifecycle.dispatchScreenTurnedOn()
    fun `WakefulnessLifecycle - dispatchFinishedWakingUp sets SysUI flag to AWAKE`() {
        // WakefulnessLifecycle is initialized to AWAKE initially, and won't emit a noop.
        wakefulnessLifecycle.dispatchFinishedGoingToSleep()
        clearInvocations(overviewProxy)

        wakefulnessLifecycle.dispatchFinishedWakingUp()

        verify(overviewProxy)
            .onSystemUiStateChanged(
                intThat { it and SYSUI_STATE_SCREEN_STATE_MASK == SCREEN_STATE_ON }
                intThat { it and SYSUI_STATE_WAKEFULNESS_MASK == WAKEFULNESS_AWAKE }
            )
    }

    @Test
    fun `ScreenLifecycle - screenTurningOn triggers SysUI state flag changes `() {
        screenLifecycle.dispatchScreenTurningOn()
    fun `WakefulnessLifecycle - dispatchStartedWakingUp sets SysUI flag to WAKING`() {
        wakefulnessLifecycle.dispatchStartedWakingUp(PowerManager.WAKE_REASON_UNKNOWN)

        verify(overviewProxy)
            .onSystemUiStateChanged(
                intThat { it and SYSUI_STATE_SCREEN_STATE_MASK == SCREEN_STATE_TURNING_ON }
                intThat { it and SYSUI_STATE_WAKEFULNESS_MASK == WAKEFULNESS_WAKING }
            )
    }

    @Test
    fun `ScreenLifecycle - screenTurnedOff triggers SysUI state flag changes `() {
        screenLifecycle.dispatchScreenTurnedOff()
    fun `WakefulnessLifecycle - dispatchFinishedGoingToSleep sets SysUI flag to ASLEEP`() {
        wakefulnessLifecycle.dispatchFinishedGoingToSleep()

        verify(overviewProxy)
            .onSystemUiStateChanged(
                intThat { it and SYSUI_STATE_SCREEN_STATE_MASK == SCREEN_STATE_OFF }
                intThat { it and SYSUI_STATE_WAKEFULNESS_MASK == WAKEFULNESS_ASLEEP }
            )
    }

    @Test
    fun `ScreenLifecycle - screenTurningOff triggers SysUI state flag changes `() {
        screenLifecycle.dispatchScreenTurningOff()
    fun `WakefulnessLifecycle - dispatchStartedGoingToSleep sets SysUI flag to GOING_TO_SLEEP`() {
        wakefulnessLifecycle.dispatchStartedGoingToSleep(
            PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON
        )

        verify(overviewProxy)
            .onSystemUiStateChanged(
                intThat { it and SYSUI_STATE_SCREEN_STATE_MASK == SCREEN_STATE_TURNING_OFF }
                intThat { it and SYSUI_STATE_WAKEFULNESS_MASK == WAKEFULNESS_GOING_TO_SLEEP }
            )
    }
}