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

Commit 4d325552 authored by Hawkwood Glazier's avatar Hawkwood Glazier
Browse files

Trigger time update when screen state changes to SCREEN_ON

This is a broader version of I3a3329d9b9a29f5452572ec23812b3e4edd2a378.
While that change was targetted specifically to fix the time on AOD
clocks after the screen turns on, this change instead triggers all
regstered KeyguardUpdateMonitor.onTimeChanged callbacks. It has more
impact, and should include any component relying on TIME_TICK for up to
date AOD rendering. As a result, it includes smartspace by triggering
SmartspaceTimeChangedDelegate at the correct time. It also backs out
the code added by the previous change so as not to do redundant work.

Bug: 390191659
Test: Manually checked
Flag: None Low risk bugfix
Change-Id: Ie2e4311c7ab40b830f497c5e0eb251861223efe4
parent cdbd992d
Loading
Loading
Loading
Loading
+5 −20
Original line number Diff line number Diff line
@@ -61,8 +61,6 @@ import com.android.systemui.plugins.clocks.ClockTickRate
import com.android.systemui.plugins.clocks.WeatherData
import com.android.systemui.plugins.clocks.ZenData
import com.android.systemui.plugins.clocks.ZenData.ZenMode
import com.android.systemui.power.domain.interactor.PowerInteractor
import com.android.systemui.power.shared.model.ScreenPowerState
import com.android.systemui.res.R as SysuiR
import com.android.systemui.scene.shared.flag.SceneContainerFlag
import com.android.systemui.settings.UserTracker
@@ -108,7 +106,6 @@ constructor(
    private val zenModeController: ZenModeController,
    private val zenModeInteractor: ZenModeInteractor,
    private val userTracker: UserTracker,
    private val powerInteractor: PowerInteractor,
) {
    var loggers =
        listOf(
@@ -380,12 +377,12 @@ constructor(
            override fun onTimeChanged() {
                refreshTime()
            }
        }

            private fun refreshTime() {
                clock?.smallClock?.events?.onTimeTick()
                clock?.largeClock?.events?.onTimeTick()
            }
        }

    @VisibleForTesting
    internal fun listenForDnd(scope: CoroutineScope): Job {
@@ -477,7 +474,6 @@ constructor(
                    listenForAnyStateToAodTransition(this)
                    listenForAnyStateToLockscreenTransition(this)
                    listenForAnyStateToDozingTransition(this)
                    listenForScreenPowerOn(this)
                }
            }
        smallTimeListener?.update(shouldTimeListenerRun)
@@ -647,17 +643,6 @@ constructor(
        }
    }

    @VisibleForTesting
    internal fun listenForScreenPowerOn(scope: CoroutineScope): Job {
        return scope.launch {
            powerInteractor.screenPowerState.collect { powerState ->
                if (powerState != ScreenPowerState.SCREEN_OFF) {
                    refreshTime()
                }
            }
        }
    }

    class TimeListener(val clockFace: ClockFaceController, val executor: DelayableExecutor) {
        val predrawListener =
            ViewTreeObserver.OnPreDrawListener {
+5 −0
Original line number Diff line number Diff line
@@ -3328,6 +3328,11 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
        }
    }

    /** Triggers an out of band time update */
    public void triggerTimeUpdate() {
        mHandler.sendEmptyMessage(MSG_TIME_UPDATE);
    }

    /**
     * Handle {@link #MSG_TIME_UPDATE}
     */
+7 −1
Original line number Diff line number Diff line
@@ -72,6 +72,7 @@ import com.android.internal.policy.IKeyguardDrawnCallback;
import com.android.internal.policy.IKeyguardExitCallback;
import com.android.internal.policy.IKeyguardService;
import com.android.internal.policy.IKeyguardStateCallback;
import com.android.keyguard.KeyguardUpdateMonitor;
import com.android.keyguard.mediator.ScreenOnCoordinator;
import com.android.systemui.SystemUIApplication;
import com.android.systemui.dagger.qualifiers.Application;
@@ -331,6 +332,7 @@ public class KeyguardService extends Service {
        }
    };
    private final KeyguardServiceLockNowInteractor mKeyguardServiceLockNowInteractor;
    private final KeyguardUpdateMonitor mKeyguardUpdateMonitor;

    @Inject
    public KeyguardService(
@@ -356,7 +358,8 @@ public class KeyguardService extends Service {
            KeyguardDismissInteractor keyguardDismissInteractor,
            Lazy<DeviceEntryInteractor> deviceEntryInteractorLazy,
            KeyguardStateCallbackInteractor keyguardStateCallbackInteractor,
            KeyguardServiceLockNowInteractor keyguardServiceLockNowInteractor) {
            KeyguardServiceLockNowInteractor keyguardServiceLockNowInteractor,
            KeyguardUpdateMonitor keyguardUpdateMonitor) {
        super();
        mKeyguardViewMediator = keyguardViewMediator;
        mKeyguardLifecyclesDispatcher = keyguardLifecyclesDispatcher;
@@ -389,6 +392,7 @@ public class KeyguardService extends Service {
        mKeyguardWakeDirectlyToGoneInteractor = keyguardWakeDirectlyToGoneInteractor;
        mKeyguardDismissInteractor = keyguardDismissInteractor;
        mKeyguardServiceLockNowInteractor = keyguardServiceLockNowInteractor;
        mKeyguardUpdateMonitor = keyguardUpdateMonitor;
    }

    @Override
@@ -585,6 +589,7 @@ public class KeyguardService extends Service {
            mPowerInteractor.onScreenPowerStateUpdated(ScreenPowerState.SCREEN_TURNING_ON);
            mKeyguardLifecyclesDispatcher.dispatch(KeyguardLifecyclesDispatcher.SCREEN_TURNING_ON,
                    callback);
            mKeyguardUpdateMonitor.triggerTimeUpdate();

            final String onDrawWaitingTraceTag = "Waiting for KeyguardDrawnCallback#onDrawn";
            final int traceCookie = System.identityHashCode(callback);
@@ -620,6 +625,7 @@ public class KeyguardService extends Service {
            checkPermission();
            mPowerInteractor.onScreenPowerStateUpdated(ScreenPowerState.SCREEN_ON);
            mKeyguardLifecyclesDispatcher.dispatch(KeyguardLifecyclesDispatcher.SCREEN_TURNED_ON);
            mKeyguardUpdateMonitor.triggerTimeUpdate();
            mScreenOnCoordinator.onScreenTurnedOn();
            Trace.endSection();
        }
+0 −3
Original line number Diff line number Diff line
@@ -55,7 +55,6 @@ import com.android.systemui.plugins.clocks.ClockTickRate
import com.android.systemui.plugins.clocks.ThemeConfig
import com.android.systemui.plugins.clocks.ZenData
import com.android.systemui.plugins.clocks.ZenData.ZenMode
import com.android.systemui.power.domain.interactor.PowerInteractor
import com.android.systemui.res.R
import com.android.systemui.settings.UserTracker
import com.android.systemui.statusbar.policy.BatteryController
@@ -132,7 +131,6 @@ class ClockEventControllerTest : SysuiTestCase() {
    @Mock private lateinit var parentView: View
    @Mock private lateinit var keyguardTransitionInteractor: KeyguardTransitionInteractor
    @Mock private lateinit var userTracker: UserTracker
    @Mock private lateinit var powerInteractor: PowerInteractor

    @Mock private lateinit var zenModeController: ZenModeController
    private var zenModeControllerCallback: ZenModeController.Callback? = null
@@ -180,7 +178,6 @@ class ClockEventControllerTest : SysuiTestCase() {
                zenModeController,
                zenModeInteractor,
                userTracker,
                powerInteractor,
            )
        underTest.clock = clock