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

Commit 1aaf541b authored by Android Build Coastguard Worker's avatar Android Build Coastguard Worker
Browse files

Merge cherrypicks of ['googleplex-android-review.googlesource.com/27427958']...

Merge cherrypicks of ['googleplex-android-review.googlesource.com/27427958'] into sparse-11864929-L87100030003938367.
SPARSE_CHANGE: Ib39ef7bc94cd487a2c36247853ab5b529469aff4

Change-Id: I4178da827f273f71a89c4070036b682eb269d1e1
parents 0b657087 bd5f0c4c
Loading
Loading
Loading
Loading
+0 −18
Original line number Diff line number Diff line
@@ -34,7 +34,6 @@ import java.util.UUID
import javax.inject.Inject
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.channels.BufferOverflow
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.MutableStateFlow
@@ -43,7 +42,6 @@ import kotlinx.coroutines.flow.asSharedFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.filter
import kotlinx.coroutines.sync.Mutex

/**
 * The source of truth for all keyguard transitions.
@@ -131,7 +129,6 @@ constructor(
    private var lastStep: TransitionStep = TransitionStep()
    private var lastAnimator: ValueAnimator? = null

    private val _currentTransitionMutex = Mutex()
    private val _currentTransitionInfo: MutableStateFlow<TransitionInfo> =
        MutableStateFlow(
            TransitionInfo(
@@ -149,9 +146,6 @@ constructor(
     */
    private var updateTransitionId: UUID? = null

    // Only used in a test environment
    var forceDelayForRaceConditionTest = false

    init {
        // Start with a FINISHED transition in OFF. KeyguardBootInteractor will transition from OFF
        // to either GONE or LOCKSCREEN once we're booted up and can determine which state we should
@@ -168,21 +162,9 @@ constructor(

    override suspend fun startTransition(info: TransitionInfo): UUID? {
        _currentTransitionInfo.value = info
        Log.d(TAG, "(Internal) Setting current transition info: $info")

        // There is no fairness guarantee with 'withContext', which means that transitions could
        // be processed out of order. Use a Mutex to guarantee ordering.
        _currentTransitionMutex.lock()

        // Only used in a test environment
        if (forceDelayForRaceConditionTest) {
            delay(50L)
        }

        // Animators must be started on the main thread.
        return withContext("$TAG#startTransition", mainDispatcher) {
            _currentTransitionMutex.unlock()

            if (lastStep.from == info.from && lastStep.to == info.to) {
                Log.i(TAG, "Duplicate call to start the transition, rejecting: $info")
                return@withContext null
+6 −0
Original line number Diff line number Diff line
@@ -55,6 +55,12 @@ constructor(
            }
        }

        scope.launch {
            sharedNotificationContainerViewModel
                .getMaxNotifications { height, useExtraShelfSpace -> height.toInt() }
                .collect { logger.log(TAG, VERBOSE, "Notif: max height in px", it) }
        }

        scope.launch {
            sharedNotificationContainerViewModel.isOnLockscreen.collect {
                logger.log(TAG, VERBOSE, "Notif: isOnLockscreen", it)
+0 −1
Original line number Diff line number Diff line
@@ -229,7 +229,6 @@ sealed class TransitionInteractor(
                        startTransitionTo(
                            toState = KeyguardState.OCCLUDED,
                            modeOnCanceled = TransitionModeOnCanceled.RESET,
                            ownerReason = "keyguardInteractor.onCameraLaunchDetected",
                        )
                    }
                }
+0 −42
Original line number Diff line number Diff line
@@ -25,19 +25,16 @@ import androidx.test.filters.FlakyTest
import androidx.test.filters.SmallTest
import com.android.app.animation.Interpolators
import com.android.systemui.SysuiTestCase
import com.android.systemui.coroutines.collectValues
import com.android.systemui.keyguard.shared.model.KeyguardState
import com.android.systemui.keyguard.shared.model.KeyguardState.AOD
import com.android.systemui.keyguard.shared.model.KeyguardState.DREAMING
import com.android.systemui.keyguard.shared.model.KeyguardState.LOCKSCREEN
import com.android.systemui.keyguard.shared.model.KeyguardState.OCCLUDED
import com.android.systemui.keyguard.shared.model.KeyguardState.OFF
import com.android.systemui.keyguard.shared.model.TransitionInfo
import com.android.systemui.keyguard.shared.model.TransitionModeOnCanceled
import com.android.systemui.keyguard.shared.model.TransitionState
import com.android.systemui.keyguard.shared.model.TransitionStep
import com.android.systemui.keyguard.util.KeyguardTransitionRunner
import com.android.systemui.kosmos.testDispatcher
import com.android.systemui.kosmos.testScope
import com.android.systemui.testKosmos
import com.google.common.truth.Truth.assertThat
@@ -48,8 +45,6 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.dropWhile
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.launch
import kotlinx.coroutines.test.advanceTimeBy
import kotlinx.coroutines.test.runCurrent
import kotlinx.coroutines.test.runTest
import org.junit.After
@@ -377,43 +372,6 @@ class KeyguardTransitionRepositoryTest : SysuiTestCase() {
            assertThat(wtfHandler.failed).isTrue()
        }

    @Test
    fun simulateRaceConditionIsProcessedInOrder() =
        testScope.runTest {
            val ktr = KeyguardTransitionRepositoryImpl(kosmos.testDispatcher)
            val steps by collectValues(ktr.transitions.dropWhile { step -> step.from == OFF })

            // Add a delay to the first transition in order to attempt to have the second transition
            // be processed first
            val info1 = TransitionInfo(OWNER_NAME, AOD, LOCKSCREEN, animator = null)
            launch {
                ktr.forceDelayForRaceConditionTest = true
                ktr.startTransition(info1)
            }
            val info2 = TransitionInfo(OWNER_NAME, LOCKSCREEN, OCCLUDED, animator = null)
            launch {
                ktr.forceDelayForRaceConditionTest = false
                ktr.startTransition(info2)
            }

            runCurrent()
            assertThat(steps.isEmpty()).isTrue()

            advanceTimeBy(60L)
            assertThat(steps[0])
                .isEqualTo(
                    TransitionStep(info1.from, info1.to, 0f, TransitionState.STARTED, OWNER_NAME)
                )
            assertThat(steps[1])
                .isEqualTo(
                    TransitionStep(info1.from, info1.to, 0f, TransitionState.CANCELED, OWNER_NAME)
                )
            assertThat(steps[2])
                .isEqualTo(
                    TransitionStep(info2.from, info2.to, 0f, TransitionState.STARTED, OWNER_NAME)
                )
        }

    private fun listWithStep(
        step: BigDecimal,
        start: BigDecimal = BigDecimal.ZERO,
+1 −3
Original line number Diff line number Diff line
@@ -1669,9 +1669,7 @@ class KeyguardTransitionScenariosTest(flags: FlagsParameterization?) : SysuiTest
            // THEN a transition from DOZING => OCCLUDED should occur
            assertThat(transitionRepository)
                .startedTransition(
                    ownerName =
                        "FromDozingTransitionInteractor" +
                            "(keyguardInteractor.onCameraLaunchDetected)",
                    ownerName = "FromDozingTransitionInteractor",
                    from = KeyguardState.DOZING,
                    to = KeyguardState.OCCLUDED,
                    animatorAssertion = { it.isNotNull() },