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

Commit 101eac7a authored by Josh Tsuji's avatar Josh Tsuji Committed by Android (Google) Code Review
Browse files

Merge "(1/x) Consolidate Screen/Wakefulness lifecycle state into PowerRepository." into main

parents 16c234b5 d5f31bc7
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -24,7 +24,7 @@ import com.android.systemui.res.R
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.qualifiers.Main
import com.android.systemui.dump.DumpManager
import com.android.systemui.keyguard.shared.model.WakeSleepReason
import com.android.systemui.power.shared.model.WakeSleepReason
import com.android.systemui.util.settings.GlobalSettings
import java.io.PrintWriter
import java.util.stream.Collectors
+12 −9
Original line number Diff line number Diff line
@@ -55,9 +55,9 @@ import com.android.systemui.dump.DumpManager;
import com.android.systemui.flags.FeatureFlags;
import com.android.systemui.flags.Flags;
import com.android.systemui.keyguard.domain.interactor.KeyguardInteractor;
import com.android.systemui.keyguard.shared.model.ScreenModel;
import com.android.systemui.keyguard.shared.model.ScreenState;
import com.android.systemui.power.shared.model.ScreenPowerState;
import com.android.systemui.plugins.ClockController;
import com.android.systemui.power.domain.interactor.PowerInteractor;
import com.android.systemui.statusbar.notification.AnimatableProperty;
import com.android.systemui.statusbar.notification.PropertyAnimator;
import com.android.systemui.statusbar.notification.stack.AnimationProperties;
@@ -68,13 +68,13 @@ import com.android.systemui.statusbar.policy.ConfigurationController;
import com.android.systemui.statusbar.policy.KeyguardStateController;
import com.android.systemui.util.ViewController;

import kotlin.coroutines.CoroutineContext;
import kotlin.coroutines.EmptyCoroutineContext;

import java.io.PrintWriter;

import javax.inject.Inject;

import kotlin.coroutines.CoroutineContext;
import kotlin.coroutines.EmptyCoroutineContext;

/**
 * Injectable controller for {@link KeyguardStatusView}.
 */
@@ -101,6 +101,7 @@ public class KeyguardStatusViewController extends ViewController<KeyguardStatusV
    private final InteractionJankMonitor mInteractionJankMonitor;
    private final Rect mClipBounds = new Rect();
    private final KeyguardInteractor mKeyguardInteractor;
    private final PowerInteractor mPowerInteractor;

    private Boolean mSplitShadeEnabled = false;
    private Boolean mStatusViewCentered = true;
@@ -134,7 +135,8 @@ public class KeyguardStatusViewController extends ViewController<KeyguardStatusV
            FeatureFlags featureFlags,
            InteractionJankMonitor interactionJankMonitor,
            KeyguardInteractor keyguardInteractor,
            DumpManager dumpManager) {
            DumpManager dumpManager,
            PowerInteractor powerInteractor) {
        super(keyguardStatusView);
        mKeyguardSliceViewController = keyguardSliceViewController;
        mKeyguardClockSwitchController = keyguardClockSwitchController;
@@ -147,6 +149,7 @@ public class KeyguardStatusViewController extends ViewController<KeyguardStatusV
        mFeatureFlags = featureFlags;
        mDumpManager = dumpManager;
        mKeyguardInteractor = keyguardInteractor;
        mPowerInteractor = powerInteractor;
    }

    @Override
@@ -207,9 +210,9 @@ public class KeyguardStatusViewController extends ViewController<KeyguardStatusV
                        dozeTimeTick();
                }, context);

        collectFlow(mView, mKeyguardInteractor.getScreenModel(),
                (ScreenModel model) -> {
                    if (model.getState() == ScreenState.SCREEN_TURNING_ON) {
        collectFlow(mView, mPowerInteractor.getScreenPowerState(),
                (ScreenPowerState powerState) -> {
                    if (powerState == ScreenPowerState.SCREEN_TURNING_ON) {
                        dozeTimeTick();
                    }
                }, context);
+14 −1
Original line number Diff line number Diff line
@@ -76,11 +76,13 @@ import com.android.systemui.SystemUIApplication;
import com.android.systemui.dagger.qualifiers.Application;
import com.android.systemui.flags.FeatureFlags;
import com.android.systemui.flags.Flags;
import com.android.systemui.power.shared.model.ScreenPowerState;
import com.android.systemui.keyguard.ui.binder.KeyguardSurfaceBehindParamsApplier;
import com.android.systemui.keyguard.ui.binder.KeyguardSurfaceBehindViewBinder;
import com.android.systemui.keyguard.ui.binder.WindowManagerLockscreenVisibilityViewBinder;
import com.android.systemui.keyguard.ui.viewmodel.KeyguardSurfaceBehindViewModel;
import com.android.systemui.keyguard.ui.viewmodel.WindowManagerLockscreenVisibilityViewModel;
import com.android.systemui.power.domain.interactor.PowerInteractor;
import com.android.systemui.settings.DisplayTracker;
import com.android.wm.shell.transition.ShellTransitions;
import com.android.wm.shell.transition.Transitions;
@@ -105,6 +107,7 @@ public class KeyguardService extends Service {
    private final ScreenOnCoordinator mScreenOnCoordinator;
    private final ShellTransitions mShellTransitions;
    private final DisplayTracker mDisplayTracker;
    private PowerInteractor mPowerInteractor;

    private static int newModeToLegacyMode(int newMode) {
        switch (newMode) {
@@ -309,7 +312,8 @@ public class KeyguardService extends Service {
            KeyguardSurfaceBehindViewModel keyguardSurfaceBehindViewModel,
            KeyguardSurfaceBehindParamsApplier keyguardSurfaceBehindAnimator,
            @Application CoroutineScope scope,
            FeatureFlags featureFlags) {
            FeatureFlags featureFlags,
            PowerInteractor powerInteractor) {
        super();
        mKeyguardViewMediator = keyguardViewMediator;
        mKeyguardLifecyclesDispatcher = keyguardLifecyclesDispatcher;
@@ -317,6 +321,7 @@ public class KeyguardService extends Service {
        mShellTransitions = shellTransitions;
        mDisplayTracker = displayTracker;
        mFlags = featureFlags;
        mPowerInteractor = powerInteractor;

        if (mFlags.isEnabled(Flags.KEYGUARD_WM_STATE_REFACTOR)) {
            WindowManagerLockscreenVisibilityViewBinder.bind(
@@ -451,6 +456,7 @@ public class KeyguardService extends Service {
            checkPermission();
            mKeyguardViewMediator.onStartedGoingToSleep(
                    WindowManagerPolicyConstants.translateSleepReasonToOffReason(pmSleepReason));
            mPowerInteractor.onStartedGoingToSleep(pmSleepReason);
            mKeyguardLifecyclesDispatcher.dispatch(
                    KeyguardLifecyclesDispatcher.STARTED_GOING_TO_SLEEP, pmSleepReason);
        }
@@ -464,6 +470,7 @@ public class KeyguardService extends Service {
            mKeyguardViewMediator.onFinishedGoingToSleep(
                    WindowManagerPolicyConstants.translateSleepReasonToOffReason(pmSleepReason),
                    cameraGestureTriggered);
            mPowerInteractor.onFinishedGoingToSleep(cameraGestureTriggered);
            mKeyguardLifecyclesDispatcher.dispatch(
                    KeyguardLifecyclesDispatcher.FINISHED_GOING_TO_SLEEP);
        }
@@ -476,6 +483,7 @@ public class KeyguardService extends Service {
            Trace.beginSection("KeyguardService.mBinder#onStartedWakingUp");
            checkPermission();
            mKeyguardViewMediator.onStartedWakingUp(pmWakeReason, cameraGestureTriggered);
            mPowerInteractor.onStartedWakingUp(pmWakeReason, cameraGestureTriggered);
            mKeyguardLifecyclesDispatcher.dispatch(
                    KeyguardLifecyclesDispatcher.STARTED_WAKING_UP, pmWakeReason);
            Trace.endSection();
@@ -486,6 +494,7 @@ public class KeyguardService extends Service {
            trace("onFinishedWakingUp");
            Trace.beginSection("KeyguardService.mBinder#onFinishedWakingUp");
            checkPermission();
            mPowerInteractor.onFinishedWakingUp();
            mKeyguardLifecyclesDispatcher.dispatch(KeyguardLifecyclesDispatcher.FINISHED_WAKING_UP);
            Trace.endSection();
        }
@@ -495,6 +504,7 @@ public class KeyguardService extends Service {
            trace("onScreenTurningOn");
            Trace.beginSection("KeyguardService.mBinder#onScreenTurningOn");
            checkPermission();
            mPowerInteractor.onScreenPowerStateUpdated(ScreenPowerState.SCREEN_TURNING_ON);
            mKeyguardLifecyclesDispatcher.dispatch(KeyguardLifecyclesDispatcher.SCREEN_TURNING_ON,
                    callback);

@@ -530,6 +540,7 @@ public class KeyguardService extends Service {
            trace("onScreenTurnedOn");
            Trace.beginSection("KeyguardService.mBinder#onScreenTurnedOn");
            checkPermission();
            mPowerInteractor.onScreenPowerStateUpdated(ScreenPowerState.SCREEN_ON);
            mKeyguardLifecyclesDispatcher.dispatch(KeyguardLifecyclesDispatcher.SCREEN_TURNED_ON);
            mScreenOnCoordinator.onScreenTurnedOn();
            Trace.endSection();
@@ -539,6 +550,7 @@ public class KeyguardService extends Service {
        public void onScreenTurningOff() {
            trace("onScreenTurningOff");
            checkPermission();
            mPowerInteractor.onScreenPowerStateUpdated(ScreenPowerState.SCREEN_TURNING_OFF);
            mKeyguardLifecyclesDispatcher.dispatch(KeyguardLifecyclesDispatcher.SCREEN_TURNING_OFF);
        }

@@ -546,6 +558,7 @@ public class KeyguardService extends Service {
        public void onScreenTurnedOff() {
            trace("onScreenTurnedOff");
            checkPermission();
            mPowerInteractor.onScreenPowerStateUpdated(ScreenPowerState.SCREEN_OFF);
            mKeyguardViewMediator.onScreenTurnedOff();
            mKeyguardLifecyclesDispatcher.dispatch(KeyguardLifecyclesDispatcher.SCREEN_TURNED_OFF);
            mScreenOnCoordinator.onScreenTurnedOff();
+10 −9
Original line number Diff line number Diff line
@@ -30,15 +30,15 @@ import com.android.systemui.flags.Flags
import com.android.systemui.keyguard.domain.interactor.KeyguardInteractor
import com.android.systemui.keyguard.domain.interactor.KeyguardTransitionInteractor
import com.android.systemui.keyguard.shared.model.TransitionState
import com.android.systemui.keyguard.shared.model.WakefulnessState
import com.android.systemui.power.domain.interactor.PowerInteractor
import com.android.systemui.utils.GlobalWindowManager
import javax.inject.Inject
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.launch
import javax.inject.Inject

/**
 * Releases cached resources on allocated by keyguard.
@@ -52,6 +52,7 @@ class ResourceTrimmer
@Inject
constructor(
    private val keyguardInteractor: KeyguardInteractor,
    private val powerInteractor: PowerInteractor,
    private val keyguardTransitionInteractor: KeyguardTransitionInteractor,
    private val globalWindowManager: GlobalWindowManager,
    @Application private val applicationScope: CoroutineScope,
@@ -70,7 +71,7 @@ constructor(
                val isDozingFully =
                    keyguardInteractor.dozeAmount.map { it == 1f }.distinctUntilChanged()
                combine(
                        keyguardInteractor.wakefulnessModel.map { it.state },
                        powerInteractor.isAsleep,
                        keyguardInteractor.isDreaming,
                        isDozingFully,
                        ::Triple
@@ -106,7 +107,7 @@ constructor(

    @WorkerThread
    private fun onWakefulnessUpdated(
        wakefulness: WakefulnessState,
            isAsleep: Boolean,
            isDreaming: Boolean,
            isDozingFully: Boolean
    ) {
@@ -117,7 +118,7 @@ constructor(
        if (DEBUG) {
            Log.d(
                LOG_TAG,
                "Wakefulness: $wakefulness Dreaming: $isDreaming DozeAmount: $isDozingFully"
                "isAsleep: $isAsleep Dreaming: $isDreaming DozeAmount: $isDozingFully"
            )
        }
        // There are three scenarios:
@@ -127,9 +128,9 @@ constructor(
        //      to 1f
        // * AoD - where we go to ASLEEP with iDreaming = true and dozeAmount slowly increases
        //      to 1f
        val dozeDisabledAndScreenOff = wakefulness == WakefulnessState.ASLEEP && !isDreaming
        val dozeDisabledAndScreenOff = isAsleep && !isDreaming
        val dozeEnabledAndDozeAnimationCompleted =
            wakefulness == WakefulnessState.ASLEEP && isDreaming && isDozingFully
                isAsleep && isDreaming && isDozingFully
        if (dozeDisabledAndScreenOff || dozeEnabledAndDozeAnimationCompleted) {
            Trace.beginSection("ResourceTrimmer#trimMemory")
            Log.d(LOG_TAG, "SysUI asleep, trimming memory.")
+4 −0
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import android.os.Trace;

import com.android.systemui.Dumpable;
import com.android.systemui.dump.DumpManager;
import com.android.systemui.power.domain.interactor.PowerInteractor;

import java.io.PrintWriter;

@@ -28,8 +29,11 @@ import javax.inject.Singleton;

/**
 * Tracks the screen lifecycle.
 *
 * @deprecated Collect flows from {@link PowerInteractor} instead.
 */
@Singleton
@Deprecated
public class ScreenLifecycle extends Lifecycle<ScreenLifecycle.Observer> implements Dumpable {

    public static final int SCREEN_OFF = 0;
Loading