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

Commit a3933a7d authored by Matt Pietal's avatar Matt Pietal
Browse files

Begin disconnecting KeyguardStatusViewController from NPVC

As the status view will (eventually) no longer be in the shade, begin
disconnecting it from NotificationPanelViewController piece by
piece. First, remove dozeTimeTick and onScreenTurningOn calls from
NPVC. This rewires the flow of events but does not change any functionality.

Also, refactor burn in to use KeyguardRepository as the source of
truth for dozeTimeTick information

Bug: 288242803
Test: atest KeyguardStatusViewControllerTest
KeyguardStatusViewControllerWithCoroutinesTest BurnInInteractorTest
UdfpsFingerprintViewModelTest UdfpsKeyguardInteractorTest

Change-Id: Ic9061bd67eb78995eb38ff88315dd9e0c4899e6b
parent b9520816
Loading
Loading
Loading
Loading
+32 −0
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import static androidx.constraintlayout.widget.ConstraintSet.END;
import static androidx.constraintlayout.widget.ConstraintSet.PARENT_ID;

import static com.android.internal.jank.InteractionJankMonitor.CUJ_LOCKSCREEN_CLOCK_MOVE_ANIMATION;
import static com.android.systemui.util.kotlin.JavaAdapterKt.collectFlow;

import android.animation.Animator;
import android.animation.ValueAnimator;
@@ -51,6 +52,10 @@ import com.android.systemui.Dumpable;
import com.android.systemui.R;
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.plugins.ClockController;
import com.android.systemui.statusbar.notification.AnimatableProperty;
import com.android.systemui.statusbar.notification.PropertyAnimator;
@@ -62,6 +67,9 @@ 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;
@@ -91,6 +99,7 @@ public class KeyguardStatusViewController extends ViewController<KeyguardStatusV
    private final FeatureFlags mFeatureFlags;
    private final InteractionJankMonitor mInteractionJankMonitor;
    private final Rect mClipBounds = new Rect();
    private final KeyguardInteractor mKeyguardInteractor;

    private Boolean mStatusViewCentered = true;

@@ -122,6 +131,7 @@ public class KeyguardStatusViewController extends ViewController<KeyguardStatusV
            KeyguardLogger logger,
            FeatureFlags featureFlags,
            InteractionJankMonitor interactionJankMonitor,
            KeyguardInteractor keyguardInteractor,
            DumpManager dumpManager) {
        super(keyguardStatusView);
        mKeyguardSliceViewController = keyguardSliceViewController;
@@ -134,12 +144,34 @@ public class KeyguardStatusViewController extends ViewController<KeyguardStatusV
        mInteractionJankMonitor = interactionJankMonitor;
        mFeatureFlags = featureFlags;
        mDumpManager = dumpManager;
        mKeyguardInteractor = keyguardInteractor;
    }

    @Override
    public void onInit() {
        mKeyguardClockSwitchController.init();
        mDumpManager.registerDumpable(this);
        if (mFeatureFlags.isEnabled(Flags.MIGRATE_KEYGUARD_STATUS_VIEW)) {
            startCoroutines(EmptyCoroutineContext.INSTANCE);
        }
    }

    void startCoroutines(CoroutineContext context) {
        collectFlow(mView, mKeyguardInteractor.getDozeTimeTick(),
                (Long millis) -> {
                        dozeTimeTick();
                }, context);

        collectFlow(mView, mKeyguardInteractor.getScreenModel(),
                (ScreenModel model) -> {
                    if (model.getState() == ScreenState.SCREEN_TURNING_ON) {
                        dozeTimeTick();
                    }
                }, context);
    }

    public KeyguardStatusView getView() {
        return mView;
    }

    @Override
+6 −6
Original line number Diff line number Diff line
@@ -47,16 +47,15 @@ import com.android.systemui.statusbar.phone.BiometricUnlockController.WakeAndUnl
import com.android.systemui.statusbar.phone.DozeParameters
import com.android.systemui.statusbar.phone.KeyguardBypassController
import com.android.systemui.statusbar.policy.KeyguardStateController
import com.android.systemui.util.time.SystemClock
import javax.inject.Inject
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.channels.awaitClose
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asSharedFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.flowOn
@@ -177,7 +176,7 @@ interface KeyguardRepository {
    val keyguardRootViewVisibility: Flow<KeyguardRootViewVisibilityState>

    /** Receive an event for doze time tick */
    val dozeTimeTick: Flow<Unit>
    val dozeTimeTick: Flow<Long>

    /**
     * Returns `true` if the keyguard is showing; `false` otherwise.
@@ -248,6 +247,7 @@ constructor(
    private val dreamOverlayCallbackController: DreamOverlayCallbackController,
    @Main private val mainDispatcher: CoroutineDispatcher,
    @Application private val scope: CoroutineScope,
    private val systemClock: SystemClock,
) : KeyguardRepository {
    private val _animateBottomAreaDozingTransitions = MutableStateFlow(false)
    override val animateBottomAreaDozingTransitions =
@@ -398,11 +398,11 @@ constructor(
        _isDozing.value = isDozing
    }

    private val _dozeTimeTick = MutableSharedFlow<Unit>()
    override val dozeTimeTick = _dozeTimeTick.asSharedFlow()
    private val _dozeTimeTick = MutableStateFlow<Long>(0)
    override val dozeTimeTick = _dozeTimeTick.asStateFlow()

    override fun dozeTimeTick() {
        _dozeTimeTick.tryEmit(Unit)
        _dozeTimeTick.value = systemClock.uptimeMillis()
    }

    private val _lastDozeTapToWakePosition = MutableStateFlow<Point?>(null)
+8 −14
Original line number Diff line number Diff line
@@ -24,14 +24,11 @@ import com.android.systemui.common.ui.data.repository.ConfigurationRepository
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.qualifiers.Application
import com.android.systemui.doze.util.BurnInHelperWrapper
import com.android.systemui.util.time.SystemClock
import javax.inject.Inject
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.flatMapLatest
import kotlinx.coroutines.flow.mapLatest
import kotlinx.coroutines.flow.stateIn
@@ -46,24 +43,17 @@ constructor(
    private val burnInHelperWrapper: BurnInHelperWrapper,
    @Application private val scope: CoroutineScope,
    private val configurationRepository: ConfigurationRepository,
    private val systemClock: SystemClock,
    private val keyguardInteractor: KeyguardInteractor,
) {
    private val _dozeTimeTick = MutableStateFlow<Long>(0)
    val dozeTimeTick: StateFlow<Long> = _dozeTimeTick.asStateFlow()

    val udfpsBurnInXOffset: StateFlow<Int> =
        burnInOffsetDefinedInPixels(R.dimen.udfps_burn_in_offset_x, isXAxis = true)
    val udfpsBurnInYOffset: StateFlow<Int> =
        burnInOffsetDefinedInPixels(R.dimen.udfps_burn_in_offset_y, isXAxis = false)
    val udfpsBurnInProgress: StateFlow<Float> =
        dozeTimeTick
        keyguardInteractor.dozeTimeTick
            .mapLatest { burnInHelperWrapper.burnInProgressOffset() }
            .stateIn(scope, SharingStarted.Lazily, burnInHelperWrapper.burnInProgressOffset())

    fun dozeTimeTick() {
        _dozeTimeTick.value = systemClock.uptimeMillis()
    }

    /**
     * Use for max burn-in offsets that are NOT specified in pixels. This flow will recalculate the
     * max burn-in offset on any configuration changes. If the max burn-in offset is specified in
@@ -77,7 +67,9 @@ constructor(
            .flatMapLatest {
                val maxBurnInOffsetPixels =
                    context.resources.getDimensionPixelSize(maxBurnInOffsetResourceId)
                dozeTimeTick.mapLatest { calculateOffset(maxBurnInOffsetPixels, isXAxis) }
                keyguardInteractor.dozeTimeTick.mapLatest {
                    calculateOffset(maxBurnInOffsetPixels, isXAxis)
                }
            }
            .stateIn(
                scope,
@@ -102,7 +94,9 @@ constructor(
            .flatMapLatest { scale ->
                val maxBurnInOffsetPixels =
                    context.resources.getDimensionPixelSize(maxBurnInOffsetResourceId)
                dozeTimeTick.mapLatest { calculateOffset(maxBurnInOffsetPixels, isXAxis, scale) }
                keyguardInteractor.dozeTimeTick.mapLatest {
                    calculateOffset(maxBurnInOffsetPixels, isXAxis, scale)
                }
            }
            .stateIn(
                scope,
+5 −1
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@ import com.android.systemui.keyguard.shared.model.DozeStateModel
import com.android.systemui.keyguard.shared.model.DozeStateModel.Companion.isDozeOff
import com.android.systemui.keyguard.shared.model.DozeTransitionModel
import com.android.systemui.keyguard.shared.model.KeyguardRootViewVisibilityState
import com.android.systemui.keyguard.shared.model.ScreenModel
import com.android.systemui.keyguard.shared.model.StatusBarState
import com.android.systemui.keyguard.shared.model.WakefulnessModel
import com.android.systemui.keyguard.ui.viewmodel.KeyguardRootViewModel
@@ -87,7 +88,7 @@ constructor(
    /** Whether the system is in doze mode. */
    val isDozing: Flow<Boolean> = repository.isDozing
    /** Receive an event for doze time tick */
    val dozeTimeTick: Flow<Unit> = repository.dozeTimeTick
    val dozeTimeTick: Flow<Long> = repository.dozeTimeTick
    /** Whether Always-on Display mode is available. */
    val isAodAvailable: Flow<Boolean> = repository.isAodAvailable
    /** Doze transition information. */
@@ -122,6 +123,9 @@ constructor(
    /** The device wake/sleep state */
    val wakefulnessModel: StateFlow<WakefulnessModel> = repository.wakefulness

    /** The device screen state */
    val screenModel: StateFlow<ScreenModel> = repository.screenModel

    /**
     * Dozing and dreaming have overlapping events. If the doze state remains in FINISH, it means
     * that doze mode is not running and DREAMING is ok to commence.
+6 −3
Original line number Diff line number Diff line
@@ -2820,8 +2820,10 @@ public final class NotificationPanelViewController implements ShadeSurface, Dump

    @Override
    public void onScreenTurningOn() {
        if (!mFeatureFlags.isEnabled(Flags.MIGRATE_KEYGUARD_STATUS_VIEW)) {
            mKeyguardStatusViewController.dozeTimeTick();
        }
    }

    private void onMiddleClicked() {
        switch (mBarState) {
@@ -3070,10 +3072,11 @@ public final class NotificationPanelViewController implements ShadeSurface, Dump
        }
    }

    @Override
    public void dozeTimeTick() {
        mLockIconViewController.dozeTimeTick();
        if (!mFeatureFlags.isEnabled(Flags.MIGRATE_KEYGUARD_STATUS_VIEW)) {
            mKeyguardStatusViewController.dozeTimeTick();
        }
        if (mInterpolatedDarkAmount > 0) {
            positionClockAndNotifications();
        }
Loading