Merge changes Ia56f8ea6,I478d974f into main
* changes:
[sb] fix lint errors in SystemStatusAnimationSchedulerImplTest
[events] move SystemAnimationState to enum, expose flow
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/events/SystemStatusAnimationScheduler.kt b/packages/SystemUI/src/com/android/systemui/statusbar/events/SystemStatusAnimationScheduler.kt
index c6f3d7d..564d52a 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/events/SystemStatusAnimationScheduler.kt
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/events/SystemStatusAnimationScheduler.kt
@@ -16,17 +16,19 @@
package com.android.systemui.statusbar.events
-import android.annotation.IntDef
import androidx.core.animation.Animator
import androidx.core.animation.AnimatorSet
import androidx.core.animation.PathInterpolator
import com.android.systemui.Dumpable
+import com.android.systemui.statusbar.events.shared.model.SystemEventAnimationState
import com.android.systemui.statusbar.policy.CallbackController
+import kotlinx.coroutines.flow.StateFlow
interface SystemStatusAnimationScheduler :
CallbackController<SystemStatusAnimationCallback>, Dumpable {
- @SystemAnimationState fun getAnimationState(): Int
+ /** StateFlow holding the current [SystemEventAnimationState] at any time. */
+ val animationState: StateFlow<SystemEventAnimationState>
fun onStatusEvent(event: StatusEvent)
@@ -63,34 +65,6 @@
}
}
-/** Animation state IntDef */
-@Retention(AnnotationRetention.SOURCE)
-@IntDef(
- value =
- [
- IDLE,
- ANIMATION_QUEUED,
- ANIMATING_IN,
- RUNNING_CHIP_ANIM,
- ANIMATING_OUT,
- SHOWING_PERSISTENT_DOT,
- ]
-)
-annotation class SystemAnimationState
-
-/** No animation is in progress */
-@SystemAnimationState const val IDLE = 0
-/** An animation is queued, and awaiting the debounce period */
-const val ANIMATION_QUEUED = 1
-/** System is animating out, and chip is animating in */
-const val ANIMATING_IN = 2
-/** Chip has animated in and is awaiting exit animation, and optionally playing its own animation */
-const val RUNNING_CHIP_ANIM = 3
-/** Chip is animating away and system is animating back */
-const val ANIMATING_OUT = 4
-/** Chip has animated away, and the persistent dot is showing */
-const val SHOWING_PERSISTENT_DOT = 5
-
/** Commonly-needed interpolators can go here */
@JvmField val STATUS_BAR_X_MOVE_OUT = PathInterpolator(0.33f, 0f, 0f, 1f)
@JvmField val STATUS_BAR_X_MOVE_IN = PathInterpolator(0f, 0f, 0f, 1f)
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/events/SystemStatusAnimationSchedulerImpl.kt b/packages/SystemUI/src/com/android/systemui/statusbar/events/SystemStatusAnimationSchedulerImpl.kt
index 5f9e426..5ff4423 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/events/SystemStatusAnimationSchedulerImpl.kt
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/events/SystemStatusAnimationSchedulerImpl.kt
@@ -23,6 +23,12 @@
import androidx.core.animation.AnimatorSet
import com.android.systemui.dagger.qualifiers.Application
import com.android.systemui.dump.DumpManager
+import com.android.systemui.statusbar.events.shared.model.SystemEventAnimationState.AnimatingIn
+import com.android.systemui.statusbar.events.shared.model.SystemEventAnimationState.AnimatingOut
+import com.android.systemui.statusbar.events.shared.model.SystemEventAnimationState.AnimationQueued
+import com.android.systemui.statusbar.events.shared.model.SystemEventAnimationState.Idle
+import com.android.systemui.statusbar.events.shared.model.SystemEventAnimationState.RunningChipAnim
+import com.android.systemui.statusbar.events.shared.model.SystemEventAnimationState.ShowingPersistentDot
import com.android.systemui.statusbar.window.StatusBarWindowControllerStore
import com.android.systemui.util.Assert
import com.android.systemui.util.time.SystemClock
@@ -33,6 +39,7 @@
import kotlinx.coroutines.Job
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.MutableStateFlow
+import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.debounce
import kotlinx.coroutines.flow.first
@@ -85,8 +92,8 @@
*/
private var currentlyDisplayedEvent: StatusEvent? = null
- /** StateFlow holding the current [SystemAnimationState] at any time. */
- private var animationState = MutableStateFlow(IDLE)
+ private val _animationState = MutableStateFlow(Idle)
+ override val animationState = _animationState.asStateFlow()
/** True if the persistent privacy dot should be active */
var hasPersistentDot = false
@@ -109,24 +116,22 @@
// Wait for animationState to become ANIMATION_QUEUED and scheduledEvent to be non null.
// Once this combination is stable for at least DEBOUNCE_DELAY, then start a chip enter
// animation
- animationState
+ _animationState
.combine(scheduledEvent) { animationState, scheduledEvent ->
Pair(animationState, scheduledEvent)
}
.debounce(DEBOUNCE_DELAY)
.collect { (animationState, event) ->
- if (animationState == ANIMATION_QUEUED && event != null) {
+ if (animationState == AnimationQueued && event != null) {
startAnimationLifecycle(event)
scheduledEvent.value = null
}
}
}
- coroutineScope.launch { animationState.collect { logger?.logAnimationStateUpdate(it) } }
+ coroutineScope.launch { _animationState.collect { logger?.logAnimationStateUpdate(it) } }
}
- @SystemAnimationState override fun getAnimationState(): Int = animationState.value
-
override fun onStatusEvent(event: StatusEvent) {
Assert.isMainThread()
@@ -146,11 +151,11 @@
logger?.logScheduleEvent(event)
scheduleEvent(event)
} else if (currentlyDisplayedEvent?.shouldUpdateFromEvent(event) == true) {
- logger?.logUpdateEvent(event, animationState.value)
+ logger?.logUpdateEvent(event, _animationState.value)
currentlyDisplayedEvent?.updateFromEvent(event)
if (event.forceVisible) hasPersistentDot = true
} else if (scheduledEvent.value?.shouldUpdateFromEvent(event) == true) {
- logger?.logUpdateEvent(event, animationState.value)
+ logger?.logUpdateEvent(event, _animationState.value)
scheduledEvent.value?.updateFromEvent(event)
} else {
logger?.logIgnoreEvent(event)
@@ -170,15 +175,15 @@
// the disappear animation will not animate into a dot but remove the chip entirely
hasPersistentDot = false
- if (animationState.value == SHOWING_PERSISTENT_DOT) {
+ if (_animationState.value == ShowingPersistentDot) {
// if we are currently showing a persistent dot, hide it and update the animationState
notifyHidePersistentDot()
if (scheduledEvent.value != null) {
- animationState.value = ANIMATION_QUEUED
+ _animationState.value = AnimationQueued
} else {
- animationState.value = IDLE
+ _animationState.value = Idle
}
- } else if (animationState.value == ANIMATING_OUT) {
+ } else if (_animationState.value == AnimatingOut) {
// if we are currently animating out, hide the dot. The animationState will be updated
// once the animation has ended in the onAnimationEnd callback
notifyHidePersistentDot()
@@ -206,9 +211,9 @@
cancelCurrentlyDisplayedEvent()
return
}
- if (animationState.value == IDLE) {
+ if (_animationState.value == Idle) {
// If we are in IDLE state, set it to ANIMATION_QUEUED now
- animationState.value = ANIMATION_QUEUED
+ _animationState.value = AnimationQueued
}
}
@@ -223,7 +228,7 @@
withTimeout(APPEAR_ANIMATION_DURATION) {
// wait for animationState to become RUNNING_CHIP_ANIM, then cancel the running
// animation job and run the disappear animation immediately
- animationState.first { it == RUNNING_CHIP_ANIM }
+ _animationState.first { it == RunningChipAnim }
currentlyRunningAnimationJob?.cancel()
runChipDisappearAnimation()
}
@@ -241,7 +246,7 @@
if (!event.showAnimation && event.forceVisible) {
// If animations are turned off, we'll transition directly to the dot
- animationState.value = SHOWING_PERSISTENT_DOT
+ _animationState.value = ShowingPersistentDot
notifyTransitionToPersistentDot(event)
return
}
@@ -277,7 +282,7 @@
if (hasPersistentDot) {
statusBarWindowControllerStore.defaultDisplay.setForceStatusBarVisible(true)
}
- animationState.value = ANIMATING_IN
+ _animationState.value = AnimatingIn
val animSet = collectStartAnimations()
if (animSet.totalDuration > 500) {
@@ -289,7 +294,7 @@
animSet.addListener(
object : AnimatorListenerAdapter() {
override fun onAnimationEnd(animation: Animator) {
- animationState.value = RUNNING_CHIP_ANIM
+ _animationState.value = RunningChipAnim
}
}
)
@@ -299,15 +304,15 @@
private fun runChipDisappearAnimation() {
Assert.isMainThread()
val animSet2 = collectFinishAnimations()
- animationState.value = ANIMATING_OUT
+ _animationState.value = AnimatingOut
animSet2.addListener(
object : AnimatorListenerAdapter() {
override fun onAnimationEnd(animation: Animator) {
- animationState.value =
+ _animationState.value =
when {
- hasPersistentDot -> SHOWING_PERSISTENT_DOT
- scheduledEvent.value != null -> ANIMATION_QUEUED
- else -> IDLE
+ hasPersistentDot -> ShowingPersistentDot
+ scheduledEvent.value != null -> AnimationQueued
+ else -> Idle
}
statusBarWindowControllerStore.defaultDisplay.setForceStatusBarVisible(false)
}
@@ -401,7 +406,7 @@
pw.println("Scheduled event: ${scheduledEvent.value}")
pw.println("Currently displayed event: $currentlyDisplayedEvent")
pw.println("Has persistent privacy dot: $hasPersistentDot")
- pw.println("Animation state: ${animationState.value}")
+ pw.println("Animation state: ${_animationState.value}")
pw.println("Listeners:")
if (listeners.isEmpty()) {
pw.println("(none)")
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/events/SystemStatusAnimationSchedulerLogger.kt b/packages/SystemUI/src/com/android/systemui/statusbar/events/SystemStatusAnimationSchedulerLogger.kt
index 22b0b69..a1f7a9b 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/events/SystemStatusAnimationSchedulerLogger.kt
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/events/SystemStatusAnimationSchedulerLogger.kt
@@ -3,15 +3,14 @@
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.log.LogBuffer
import com.android.systemui.log.core.LogLevel
+import com.android.systemui.statusbar.events.shared.model.SystemEventAnimationState
import javax.inject.Inject
/** Logs for the SystemStatusAnimationScheduler. */
@SysUISingleton
class SystemStatusAnimationSchedulerLogger
@Inject
-constructor(
- @SystemStatusAnimationSchedulerLog private val logBuffer: LogBuffer,
-) {
+constructor(@SystemStatusAnimationSchedulerLog private val logBuffer: LogBuffer) {
fun logScheduleEvent(event: StatusEvent) {
logBuffer.log(
@@ -23,11 +22,11 @@
bool1 = event.forceVisible
bool2 = event.showAnimation
},
- { "Scheduling event: $str1(forceVisible=$bool1, priority=$int1, showAnimation=$bool2)" }
+ { "Scheduling event: $str1(forceVisible=$bool1, priority=$int1, showAnimation=$bool2)" },
)
}
- fun logUpdateEvent(event: StatusEvent, @SystemAnimationState animationState: Int) {
+ fun logUpdateEvent(event: StatusEvent, animationState: SystemEventAnimationState) {
logBuffer.log(
TAG,
LogLevel.DEBUG,
@@ -36,12 +35,12 @@
int1 = event.priority
bool1 = event.forceVisible
bool2 = event.showAnimation
- int2 = animationState
+ str2 = animationState.name
},
{
"Updating current event from: $str1(forceVisible=$bool1, priority=$int1, " +
- "showAnimation=$bool2), animationState=${animationState.name()}"
- }
+ "showAnimation=$bool2), animationState=$str2"
+ },
)
}
@@ -55,7 +54,7 @@
bool1 = event.forceVisible
bool2 = event.showAnimation
},
- { "Ignore event: $str1(forceVisible=$bool1, priority=$int1, showAnimation=$bool2)" }
+ { "Ignore event: $str1(forceVisible=$bool1, priority=$int1, showAnimation=$bool2)" },
)
}
@@ -67,26 +66,14 @@
logBuffer.log(TAG, LogLevel.DEBUG, "Transition to persistent dot callback invoked")
}
- fun logAnimationStateUpdate(@SystemAnimationState animationState: Int) {
+ fun logAnimationStateUpdate(animationState: SystemEventAnimationState) {
logBuffer.log(
TAG,
LogLevel.DEBUG,
- { int1 = animationState },
- { "AnimationState update: ${int1.name()}" }
+ { str1 = animationState.name },
+ { "AnimationState update: $str1" },
)
- animationState.name()
}
-
- private fun @receiver:SystemAnimationState Int.name() =
- when (this) {
- IDLE -> "IDLE"
- ANIMATION_QUEUED -> "ANIMATION_QUEUED"
- ANIMATING_IN -> "ANIMATING_IN"
- RUNNING_CHIP_ANIM -> "RUNNING_CHIP_ANIM"
- ANIMATING_OUT -> "ANIMATING_OUT"
- SHOWING_PERSISTENT_DOT -> "SHOWING_PERSISTENT_DOT"
- else -> "UNKNOWN_ANIMATION_STATE"
- }
}
private const val TAG = "SystemStatusAnimationSchedulerLog"
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/events/shared/model/SystemEventAnimationState.kt b/packages/SystemUI/src/com/android/systemui/statusbar/events/shared/model/SystemEventAnimationState.kt
new file mode 100644
index 0000000..2446b81
--- /dev/null
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/events/shared/model/SystemEventAnimationState.kt
@@ -0,0 +1,35 @@
+/*
+ * Copyright (C) 2024 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.systemui.statusbar.events.shared.model
+
+/** Direct representation of the system event animation scheduler's current state */
+enum class SystemEventAnimationState {
+ /** No animation is in progress */
+ Idle,
+ /** An animation is queued, and awaiting the debounce period */
+ AnimationQueued,
+ /** System is animating out, and chip is animating in */
+ AnimatingIn,
+ /**
+ * Chip has animated in and is awaiting exit animation, and optionally playing its own animation
+ */
+ RunningChipAnim,
+ /** Chip is animating away and system is animating back */
+ AnimatingOut,
+ /** Chip has animated away, and the persistent dot is showing */
+ ShowingPersistentDot,
+}
diff --git a/packages/SystemUI/tests/src/com/android/systemui/biometrics/AuthContainerViewTest.kt b/packages/SystemUI/tests/src/com/android/systemui/biometrics/AuthContainerViewTest.kt
index 7889b3c..61eeab3 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/biometrics/AuthContainerViewTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/biometrics/AuthContainerViewTest.kt
@@ -65,7 +65,6 @@
import com.android.systemui.keyguard.WakefulnessLifecycle
import com.android.systemui.res.R
import com.android.systemui.statusbar.VibratorHelper
-import com.android.systemui.statusbar.events.ANIMATING_OUT
import com.android.systemui.testKosmos
import com.android.systemui.user.domain.interactor.SelectedUserInteractor
import com.android.systemui.util.concurrency.FakeExecutor
@@ -176,7 +175,7 @@
BiometricStatusInteractorImpl(
activityTaskManager,
biometricStatusRepository,
- fingerprintRepository
+ fingerprintRepository,
)
iconProvider = IconProvider(context)
// Set up default logo icon
@@ -245,7 +244,7 @@
@Test
fun testIgnoresAnimatedInWhenDialogAnimatingOut() {
val container = initializeFingerprintContainer(addToView = false)
- container.mContainerState = ANIMATING_OUT
+ container.mContainerState = 4 // STATE_ANIMATING_OUT
container.addToView()
waitForIdleSync()
@@ -278,7 +277,7 @@
.onDismissed(
eq(AuthDialogCallback.DISMISSED_BIOMETRIC_AUTHENTICATED),
eq<ByteArray?>(null), /* credentialAttestation */
- eq(authContainer?.requestId ?: 0L)
+ eq(authContainer?.requestId ?: 0L),
)
assertThat(container.parent).isNull()
}
@@ -292,13 +291,13 @@
verify(callback)
.onSystemEvent(
eq(BiometricConstants.BIOMETRIC_SYSTEM_EVENT_EARLY_USER_CANCEL),
- eq(authContainer?.requestId ?: 0L)
+ eq(authContainer?.requestId ?: 0L),
)
verify(callback)
.onDismissed(
eq(AuthDialogCallback.DISMISSED_USER_CANCELED),
eq<ByteArray?>(null), /* credentialAttestation */
- eq(authContainer?.requestId ?: 0L)
+ eq(authContainer?.requestId ?: 0L),
)
assertThat(container.parent).isNull()
}
@@ -313,7 +312,7 @@
.onDismissed(
eq(AuthDialogCallback.DISMISSED_BUTTON_NEGATIVE),
eq<ByteArray?>(null), /* credentialAttestation */
- eq(authContainer?.requestId ?: 0L)
+ eq(authContainer?.requestId ?: 0L),
)
assertThat(container.parent).isNull()
}
@@ -340,7 +339,7 @@
.onDismissed(
eq(AuthDialogCallback.DISMISSED_ERROR),
eq<ByteArray?>(null), /* credentialAttestation */
- eq(authContainer?.requestId ?: 0L)
+ eq(authContainer?.requestId ?: 0L),
)
assertThat(authContainer!!.parent).isNull()
}
@@ -454,7 +453,7 @@
val container =
initializeFingerprintContainer(
authenticators = BiometricManager.Authenticators.DEVICE_CREDENTIAL,
- verticalListContentView = PromptVerticalListContentView.Builder().build()
+ verticalListContentView = PromptVerticalListContentView.Builder().build(),
)
// Two-step credential view should show -
// 1. biometric prompt without sensor 2. credential view ui
@@ -479,7 +478,7 @@
val container =
initializeFingerprintContainer(
authenticators = BiometricManager.Authenticators.DEVICE_CREDENTIAL,
- contentViewWithMoreOptionsButton = contentView
+ contentViewWithMoreOptionsButton = contentView,
)
waitForIdleSync()
@@ -565,7 +564,7 @@
}
private fun initializeCredentialPasswordContainer(
- addToView: Boolean = true,
+ addToView: Boolean = true
): TestAuthContainerView {
whenever(userManager.getCredentialOwnerProfile(anyInt())).thenReturn(20)
whenever(lockPatternUtils.getKeyguardStoredPasswordQuality(eq(20)))
@@ -597,25 +596,25 @@
fingerprintProps = fingerprintSensorPropertiesInternal(),
verticalListContentView = verticalListContentView,
),
- addToView
+ addToView,
)
private fun initializeCoexContainer(
authenticators: Int = BiometricManager.Authenticators.BIOMETRIC_WEAK,
- addToView: Boolean = true
+ addToView: Boolean = true,
) =
initializeContainer(
TestAuthContainerView(
authenticators = authenticators,
fingerprintProps = fingerprintSensorPropertiesInternal(),
- faceProps = faceSensorPropertiesInternal()
+ faceProps = faceSensorPropertiesInternal(),
),
- addToView
+ addToView,
)
private fun initializeContainer(
view: TestAuthContainerView,
- addToView: Boolean
+ addToView: Boolean,
): TestAuthContainerView {
authContainer = view
@@ -668,7 +667,7 @@
biometricStatusInteractor,
udfpsUtils,
iconProvider,
- activityTaskManager
+ activityTaskManager,
),
{ credentialViewModel },
fakeExecutor,
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/events/SystemStatusAnimationSchedulerImplTest.kt b/packages/SystemUI/tests/src/com/android/systemui/statusbar/events/SystemStatusAnimationSchedulerImplTest.kt
index 4e7de81..4cad5f7 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/events/SystemStatusAnimationSchedulerImplTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/events/SystemStatusAnimationSchedulerImplTest.kt
@@ -29,21 +29,24 @@
import com.android.systemui.dump.DumpManager
import com.android.systemui.privacy.OngoingPrivacyChip
import com.android.systemui.statusbar.BatteryStatusChip
+import com.android.systemui.statusbar.events.shared.model.SystemEventAnimationState
+import com.android.systemui.statusbar.events.shared.model.SystemEventAnimationState.AnimatingIn
+import com.android.systemui.statusbar.events.shared.model.SystemEventAnimationState.AnimatingOut
+import com.android.systemui.statusbar.events.shared.model.SystemEventAnimationState.AnimationQueued
+import com.android.systemui.statusbar.events.shared.model.SystemEventAnimationState.Idle
+import com.android.systemui.statusbar.events.shared.model.SystemEventAnimationState.RunningChipAnim
+import com.android.systemui.statusbar.events.shared.model.SystemEventAnimationState.ShowingPersistentDot
import com.android.systemui.statusbar.phone.StatusBarContentInsetsProvider
import com.android.systemui.statusbar.window.StatusBarWindowController
import com.android.systemui.statusbar.window.StatusBarWindowControllerStore
-import com.android.systemui.util.mockito.any
-import com.android.systemui.util.mockito.eq
-import com.android.systemui.util.mockito.mock
-import com.android.systemui.util.mockito.whenever
import com.android.systemui.util.time.FakeSystemClock
-import junit.framework.Assert.assertEquals
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.StandardTestDispatcher
import kotlinx.coroutines.test.TestScope
import kotlinx.coroutines.test.advanceTimeBy
import kotlinx.coroutines.test.runTest
+import org.junit.Assert.assertEquals
import org.junit.Before
import org.junit.Rule
import org.junit.Test
@@ -54,6 +57,10 @@
import org.mockito.Mockito.times
import org.mockito.Mockito.verify
import org.mockito.MockitoAnnotations
+import org.mockito.kotlin.any
+import org.mockito.kotlin.eq
+import org.mockito.kotlin.mock
+import org.mockito.kotlin.whenever
@RunWith(AndroidJUnit4::class)
@RunWithLooper(setAsMainLooper = true)
@@ -120,12 +127,12 @@
val batteryChip = createAndScheduleFakeBatteryEvent()
// assert that animation is queued
- assertEquals(ANIMATION_QUEUED, systemStatusAnimationScheduler.getAnimationState())
+ assertEquals(AnimationQueued, systemStatusAnimationScheduler.animationState.value)
// skip debounce delay
advanceTimeBy(DEBOUNCE_DELAY + 1)
// status chip starts animating in after debounce delay
- assertEquals(ANIMATING_IN, systemStatusAnimationScheduler.getAnimationState())
+ assertEquals(AnimatingIn, systemStatusAnimationScheduler.animationState.value)
assertEquals(0f, batteryChip.contentView.alpha)
assertEquals(0f, batteryChip.view.alpha)
verify(listener, times(1)).onSystemEventAnimationBegin()
@@ -134,14 +141,14 @@
animatorTestRule.advanceTimeBy(APPEAR_ANIMATION_DURATION)
advanceTimeBy(APPEAR_ANIMATION_DURATION)
// assert that status chip is visible
- assertEquals(RUNNING_CHIP_ANIM, systemStatusAnimationScheduler.getAnimationState())
+ assertEquals(RunningChipAnim, systemStatusAnimationScheduler.animationState.value)
assertEquals(1f, batteryChip.contentView.alpha)
assertEquals(1f, batteryChip.view.alpha)
// skip status chip display time
advanceTimeBy(DISPLAY_LENGTH + 1)
- // assert that it is still visible but switched to the ANIMATING_OUT state
- assertEquals(ANIMATING_OUT, systemStatusAnimationScheduler.getAnimationState())
+ // assert that it is still visible but switched to the AnimatingOut state
+ assertEquals(AnimatingOut, systemStatusAnimationScheduler.animationState.value)
assertEquals(1f, batteryChip.contentView.alpha)
assertEquals(1f, batteryChip.view.alpha)
verify(listener, times(1)).onSystemEventAnimationFinish(false)
@@ -149,7 +156,7 @@
// skip disappear animation
animatorTestRule.advanceTimeBy(DISAPPEAR_ANIMATION_DURATION)
// assert that it is not visible anymore
- assertEquals(IDLE, systemStatusAnimationScheduler.getAnimationState())
+ assertEquals(Idle, systemStatusAnimationScheduler.animationState.value)
assertEquals(0f, batteryChip.contentView.alpha)
assertEquals(0f, batteryChip.view.alpha)
}
@@ -166,7 +173,7 @@
createAndScheduleFakePrivacyEvent()
// THEN the privacy event still happens
- assertEquals(ANIMATION_QUEUED, systemStatusAnimationScheduler.getAnimationState())
+ assertEquals(AnimationQueued, systemStatusAnimationScheduler.animationState.value)
}
@Test
@@ -177,12 +184,12 @@
val privacyChip = createAndScheduleFakePrivacyEvent()
// assert that animation is queued
- assertEquals(ANIMATION_QUEUED, systemStatusAnimationScheduler.getAnimationState())
+ assertEquals(AnimationQueued, systemStatusAnimationScheduler.animationState.value)
// skip debounce delay
advanceTimeBy(DEBOUNCE_DELAY + 1)
// status chip starts animating in after debounce delay
- assertEquals(ANIMATING_IN, systemStatusAnimationScheduler.getAnimationState())
+ assertEquals(AnimatingIn, systemStatusAnimationScheduler.animationState.value)
assertEquals(0f, privacyChip.view.alpha)
verify(listener, times(1)).onSystemEventAnimationBegin()
@@ -190,13 +197,13 @@
animatorTestRule.advanceTimeBy(APPEAR_ANIMATION_DURATION)
advanceTimeBy(APPEAR_ANIMATION_DURATION + 1)
// assert that status chip is visible
- assertEquals(RUNNING_CHIP_ANIM, systemStatusAnimationScheduler.getAnimationState())
+ assertEquals(RunningChipAnim, systemStatusAnimationScheduler.animationState.value)
assertEquals(1f, privacyChip.view.alpha)
// skip status chip display time
advanceTimeBy(DISPLAY_LENGTH + 1)
- // assert that it is still visible but switched to the ANIMATING_OUT state
- assertEquals(ANIMATING_OUT, systemStatusAnimationScheduler.getAnimationState())
+ // assert that it is still visible but switched to the AnimatingOut state
+ assertEquals(AnimatingOut, systemStatusAnimationScheduler.animationState.value)
assertEquals(1f, privacyChip.view.alpha)
verify(listener, times(1)).onSystemEventAnimationFinish(true)
verify(listener, times(1)).onSystemStatusAnimationTransitionToPersistentDot(any())
@@ -205,13 +212,13 @@
advanceTimeBy(DISAPPEAR_ANIMATION_DURATION + 1)
animatorTestRule.advanceTimeBy(DISAPPEAR_ANIMATION_DURATION)
// assert that it the dot is now visible
- assertEquals(SHOWING_PERSISTENT_DOT, systemStatusAnimationScheduler.getAnimationState())
+ assertEquals(ShowingPersistentDot, systemStatusAnimationScheduler.animationState.value)
assertEquals(1f, privacyChip.view.alpha)
// notify SystemStatusAnimationScheduler to remove persistent dot
systemStatusAnimationScheduler.removePersistentDot()
- // assert that IDLE state is entered
- assertEquals(IDLE, systemStatusAnimationScheduler.getAnimationState())
+ // assert that Idle state is entered
+ assertEquals(Idle, systemStatusAnimationScheduler.animationState.value)
verify(listener, times(1)).onHidePersistentDot()
}
@@ -225,19 +232,19 @@
batteryChip.view.alpha = 0f
// assert that animation is queued
- assertEquals(ANIMATION_QUEUED, systemStatusAnimationScheduler.getAnimationState())
+ assertEquals(AnimationQueued, systemStatusAnimationScheduler.animationState.value)
// create and schedule high priority event
val privacyChip = createAndScheduleFakePrivacyEvent()
// assert that animation is queued
- assertEquals(ANIMATION_QUEUED, systemStatusAnimationScheduler.getAnimationState())
+ assertEquals(AnimationQueued, systemStatusAnimationScheduler.animationState.value)
// skip debounce delay and appear animation duration
- fastForwardAnimationToState(RUNNING_CHIP_ANIM)
+ fastForwardAnimationToState(RunningChipAnim)
// high priority status chip is visible while low priority status chip is not visible
- assertEquals(RUNNING_CHIP_ANIM, systemStatusAnimationScheduler.getAnimationState())
+ assertEquals(RunningChipAnim, systemStatusAnimationScheduler.animationState.value)
assertEquals(1f, privacyChip.view.alpha)
assertEquals(0f, batteryChip.view.alpha)
}
@@ -250,11 +257,11 @@
// create and schedule low priority event
val batteryChip = createAndScheduleFakeBatteryEvent()
- // fast forward to RUNNING_CHIP_ANIM state
- fastForwardAnimationToState(RUNNING_CHIP_ANIM)
+ // fast forward to RunningChipAnim state
+ fastForwardAnimationToState(RunningChipAnim)
// assert that chip is displayed
- assertEquals(RUNNING_CHIP_ANIM, systemStatusAnimationScheduler.getAnimationState())
+ assertEquals(RunningChipAnim, systemStatusAnimationScheduler.animationState.value)
assertEquals(1f, batteryChip.view.alpha)
// create and schedule high priority event
@@ -264,20 +271,20 @@
testScheduler.runCurrent()
// assert that currently displayed chip is immediately animated out
- assertEquals(ANIMATING_OUT, systemStatusAnimationScheduler.getAnimationState())
+ assertEquals(AnimatingOut, systemStatusAnimationScheduler.animationState.value)
// skip disappear animation
animatorTestRule.advanceTimeBy(DISAPPEAR_ANIMATION_DURATION)
// assert that high priority privacy chip animation is queued
- assertEquals(ANIMATION_QUEUED, systemStatusAnimationScheduler.getAnimationState())
+ assertEquals(AnimationQueued, systemStatusAnimationScheduler.animationState.value)
// skip debounce delay and appear animation
advanceTimeBy(DEBOUNCE_DELAY + APPEAR_ANIMATION_DURATION + 1)
animatorTestRule.advanceTimeBy(APPEAR_ANIMATION_DURATION)
// high priority status chip is visible while low priority status chip is not visible
- assertEquals(RUNNING_CHIP_ANIM, systemStatusAnimationScheduler.getAnimationState())
+ assertEquals(RunningChipAnim, systemStatusAnimationScheduler.animationState.value)
assertEquals(1f, privacyChip.view.alpha)
assertEquals(0f, batteryChip.view.alpha)
}
@@ -294,7 +301,7 @@
advanceTimeBy(DEBOUNCE_DELAY + 1)
// assert that chip is animated in
- assertEquals(ANIMATING_IN, systemStatusAnimationScheduler.getAnimationState())
+ assertEquals(AnimatingIn, systemStatusAnimationScheduler.animationState.value)
// create and schedule high priority event
val privacyChip = createAndScheduleFakePrivacyEvent()
@@ -303,7 +310,7 @@
testScheduler.runCurrent()
// assert that currently animated chip keeps animating
- assertEquals(ANIMATING_IN, systemStatusAnimationScheduler.getAnimationState())
+ assertEquals(AnimatingIn, systemStatusAnimationScheduler.animationState.value)
// skip appear animation
animatorTestRule.advanceTimeBy(APPEAR_ANIMATION_DURATION)
@@ -311,20 +318,20 @@
// assert that low priority chip is animated out immediately after finishing the appear
// animation
- assertEquals(ANIMATING_OUT, systemStatusAnimationScheduler.getAnimationState())
+ assertEquals(AnimatingOut, systemStatusAnimationScheduler.animationState.value)
// skip disappear animation
animatorTestRule.advanceTimeBy(DISAPPEAR_ANIMATION_DURATION)
// assert that high priority privacy chip animation is queued
- assertEquals(ANIMATION_QUEUED, systemStatusAnimationScheduler.getAnimationState())
+ assertEquals(AnimationQueued, systemStatusAnimationScheduler.animationState.value)
// skip debounce delay and appear animation
advanceTimeBy(DEBOUNCE_DELAY + APPEAR_ANIMATION_DURATION + 1)
animatorTestRule.advanceTimeBy(APPEAR_ANIMATION_DURATION)
// high priority status chip is visible while low priority status chip is not visible
- assertEquals(RUNNING_CHIP_ANIM, systemStatusAnimationScheduler.getAnimationState())
+ assertEquals(RunningChipAnim, systemStatusAnimationScheduler.animationState.value)
assertEquals(1f, privacyChip.view.alpha)
assertEquals(0f, batteryChip.view.alpha)
}
@@ -346,7 +353,7 @@
animatorTestRule.advanceTimeBy(APPEAR_ANIMATION_DURATION)
// high priority status chip is visible while low priority status chip is not visible
- assertEquals(RUNNING_CHIP_ANIM, systemStatusAnimationScheduler.getAnimationState())
+ assertEquals(RunningChipAnim, systemStatusAnimationScheduler.animationState.value)
assertEquals(1f, privacyChip.view.alpha)
assertEquals(0f, batteryChip.view.alpha)
}
@@ -359,14 +366,14 @@
// create and schedule high priority event
createAndScheduleFakePrivacyEvent()
- // skip chip animation lifecycle and fast forward to SHOWING_PERSISTENT_DOT state
- fastForwardAnimationToState(SHOWING_PERSISTENT_DOT)
- assertEquals(SHOWING_PERSISTENT_DOT, systemStatusAnimationScheduler.getAnimationState())
+ // skip chip animation lifecycle and fast forward to ShowingPersistentDot state
+ fastForwardAnimationToState(ShowingPersistentDot)
+ assertEquals(ShowingPersistentDot, systemStatusAnimationScheduler.animationState.value)
verify(listener, times(1)).onSystemStatusAnimationTransitionToPersistentDot(any())
- // remove persistent dot and verify that animationState changes to IDLE
+ // remove persistent dot and verify that animationState changes to Idle
systemStatusAnimationScheduler.removePersistentDot()
- assertEquals(IDLE, systemStatusAnimationScheduler.getAnimationState())
+ assertEquals(Idle, systemStatusAnimationScheduler.animationState.value)
verify(listener, times(1)).onHidePersistentDot()
}
@@ -377,14 +384,14 @@
val accessibilityDesc = "Some desc"
val mockView = mock<View>()
val mockAnimatableView =
- mock<BackgroundAnimatableView> { whenever(view).thenReturn(mockView) }
+ mock<BackgroundAnimatableView> { whenever(it.view).thenReturn(mockView) }
scheduleFakeEventWithView(
accessibilityDesc,
mockAnimatableView,
shouldAnnounceAccessibilityEvent = true,
)
- fastForwardAnimationToState(ANIMATING_OUT)
+ fastForwardAnimationToState(AnimatingOut)
verify(mockView).announceForAccessibility(eq(accessibilityDesc))
}
@@ -396,14 +403,14 @@
val accessibilityDesc = null
val mockView = mock<View>()
val mockAnimatableView =
- mock<BackgroundAnimatableView> { whenever(view).thenReturn(mockView) }
+ mock<BackgroundAnimatableView> { whenever(it.view).thenReturn(mockView) }
scheduleFakeEventWithView(
accessibilityDesc,
mockAnimatableView,
shouldAnnounceAccessibilityEvent = true,
)
- fastForwardAnimationToState(ANIMATING_OUT)
+ fastForwardAnimationToState(AnimatingOut)
verify(mockView, never()).announceForAccessibility(any())
}
@@ -415,14 +422,14 @@
val accessibilityDesc = "something"
val mockView = mock<View>()
val mockAnimatableView =
- mock<BackgroundAnimatableView> { whenever(view).thenReturn(mockView) }
+ mock<BackgroundAnimatableView> { whenever(it.view).thenReturn(mockView) }
scheduleFakeEventWithView(
accessibilityDesc,
mockAnimatableView,
shouldAnnounceAccessibilityEvent = false,
)
- fastForwardAnimationToState(ANIMATING_OUT)
+ fastForwardAnimationToState(AnimatingOut)
verify(mockView, never()).announceForAccessibility(any())
}
@@ -435,21 +442,21 @@
// create and schedule high priority event
createAndScheduleFakePrivacyEvent()
- // skip chip animation lifecycle and fast forward to RUNNING_CHIP_ANIM state
- fastForwardAnimationToState(RUNNING_CHIP_ANIM)
- assertEquals(RUNNING_CHIP_ANIM, systemStatusAnimationScheduler.getAnimationState())
+ // skip chip animation lifecycle and fast forward to RunningChipAnim state
+ fastForwardAnimationToState(RunningChipAnim)
+ assertEquals(RunningChipAnim, systemStatusAnimationScheduler.animationState.value)
// request removal of persistent dot
systemStatusAnimationScheduler.removePersistentDot()
// skip display time and verify that disappear animation is run
advanceTimeBy(DISPLAY_LENGTH + 1)
- assertEquals(ANIMATING_OUT, systemStatusAnimationScheduler.getAnimationState())
+ assertEquals(AnimatingOut, systemStatusAnimationScheduler.animationState.value)
- // skip disappear animation and verify that animationState changes to IDLE instead of
- // SHOWING_PERSISTENT_DOT
+ // skip disappear animation and verify that animationState changes to Idle instead of
+ // ShowingPersistentDot
animatorTestRule.advanceTimeBy(DISAPPEAR_ANIMATION_DURATION)
- assertEquals(IDLE, systemStatusAnimationScheduler.getAnimationState())
+ assertEquals(Idle, systemStatusAnimationScheduler.animationState.value)
// verify that the persistent dot callbacks are not invoked
verify(listener, never()).onSystemStatusAnimationTransitionToPersistentDot(any())
verify(listener, never()).onHidePersistentDot()
@@ -463,9 +470,9 @@
// create and schedule high priority event
createAndScheduleFakePrivacyEvent()
- // fast forward to ANIMATING_OUT state
- fastForwardAnimationToState(ANIMATING_OUT)
- assertEquals(ANIMATING_OUT, systemStatusAnimationScheduler.getAnimationState())
+ // fast forward to AnimatingOut state
+ fastForwardAnimationToState(AnimatingOut)
+ assertEquals(AnimatingOut, systemStatusAnimationScheduler.animationState.value)
verify(listener, times(1)).onSystemStatusAnimationTransitionToPersistentDot(any())
// remove persistent dot
@@ -478,8 +485,8 @@
animatorTestRule.advanceTimeBy(DISAPPEAR_ANIMATION_DURATION)
testScheduler.runCurrent()
- // verify that animationState changes to IDLE
- assertEquals(IDLE, systemStatusAnimationScheduler.getAnimationState())
+ // verify that animationState changes to Idle
+ assertEquals(Idle, systemStatusAnimationScheduler.animationState.value)
}
@Test
@@ -494,11 +501,11 @@
// create and schedule a privacy event again (resets forceVisible to true)
createAndScheduleFakePrivacyEvent()
- // skip chip animation lifecycle and fast forward to SHOWING_PERSISTENT_DOT state
- fastForwardAnimationToState(SHOWING_PERSISTENT_DOT)
+ // skip chip animation lifecycle and fast forward to ShowingPersistentDot state
+ fastForwardAnimationToState(ShowingPersistentDot)
- // verify that we reach SHOWING_PERSISTENT_DOT and that listener callback is invoked
- assertEquals(SHOWING_PERSISTENT_DOT, systemStatusAnimationScheduler.getAnimationState())
+ // verify that we reach ShowingPersistentDot and that listener callback is invoked
+ assertEquals(ShowingPersistentDot, systemStatusAnimationScheduler.animationState.value)
verify(listener, times(1)).onSystemStatusAnimationTransitionToPersistentDot(any())
}
@@ -511,21 +518,21 @@
createAndScheduleFakePrivacyEvent()
// request removal of persistent dot (sets forceVisible to false)
systemStatusAnimationScheduler.removePersistentDot()
- fastForwardAnimationToState(RUNNING_CHIP_ANIM)
+ fastForwardAnimationToState(RunningChipAnim)
// create and schedule a privacy event again (resets forceVisible to true)
createAndScheduleFakePrivacyEvent()
// skip status chip display time
advanceTimeBy(DISPLAY_LENGTH + 1)
- assertEquals(ANIMATING_OUT, systemStatusAnimationScheduler.getAnimationState())
+ assertEquals(AnimatingOut, systemStatusAnimationScheduler.animationState.value)
verify(listener, times(1)).onSystemEventAnimationFinish(anyBoolean())
// skip disappear animation
animatorTestRule.advanceTimeBy(DISAPPEAR_ANIMATION_DURATION)
- // verify that we reach SHOWING_PERSISTENT_DOT and that listener callback is invoked
- assertEquals(SHOWING_PERSISTENT_DOT, systemStatusAnimationScheduler.getAnimationState())
+ // verify that we reach ShowingPersistentDot and that listener callback is invoked
+ assertEquals(ShowingPersistentDot, systemStatusAnimationScheduler.animationState.value)
verify(listener, times(1)).onSystemStatusAnimationTransitionToPersistentDot(any())
}
@@ -537,9 +544,9 @@
// create and schedule high priority event
createAndScheduleFakePrivacyEvent()
- // skip chip animation lifecycle and fast forward to ANIMATING_OUT state
- fastForwardAnimationToState(ANIMATING_OUT)
- assertEquals(ANIMATING_OUT, systemStatusAnimationScheduler.getAnimationState())
+ // skip chip animation lifecycle and fast forward to AnimatingOut state
+ fastForwardAnimationToState(AnimatingOut)
+ assertEquals(AnimatingOut, systemStatusAnimationScheduler.animationState.value)
verify(listener, times(1)).onSystemStatusAnimationTransitionToPersistentDot(any())
// request removal of persistent dot
@@ -548,13 +555,13 @@
// schedule another high priority event while the event is animating out
createAndScheduleFakePrivacyEvent()
- // verify that the state is still ANIMATING_OUT
- assertEquals(ANIMATING_OUT, systemStatusAnimationScheduler.getAnimationState())
+ // verify that the state is still AnimatingOut
+ assertEquals(AnimatingOut, systemStatusAnimationScheduler.animationState.value)
- // skip disappear animation duration and verify that new state is ANIMATION_QUEUED
+ // skip disappear animation duration and verify that new state is AnimationQueued
animatorTestRule.advanceTimeBy(DISAPPEAR_ANIMATION_DURATION)
testScheduler.runCurrent()
- assertEquals(ANIMATION_QUEUED, systemStatusAnimationScheduler.getAnimationState())
+ assertEquals(AnimationQueued, systemStatusAnimationScheduler.animationState.value)
// also verify that onHidePersistentDot callback is called
verify(listener, times(1)).onHidePersistentDot()
}
@@ -567,16 +574,16 @@
// create and schedule high priority event
createAndScheduleFakePrivacyEvent()
- // skip chip animation lifecycle and fast forward to ANIMATING_OUT state
- fastForwardAnimationToState(ANIMATING_OUT)
- assertEquals(ANIMATING_OUT, systemStatusAnimationScheduler.getAnimationState())
+ // skip chip animation lifecycle and fast forward to AnimatingOut state
+ fastForwardAnimationToState(AnimatingOut)
+ assertEquals(AnimatingOut, systemStatusAnimationScheduler.animationState.value)
verify(listener, times(1)).onSystemStatusAnimationTransitionToPersistentDot(any())
// request removal of persistent dot
systemStatusAnimationScheduler.removePersistentDot()
- // verify that the state is still ANIMATING_OUT
- assertEquals(ANIMATING_OUT, systemStatusAnimationScheduler.getAnimationState())
+ // verify that the state is still AnimatingOut
+ assertEquals(AnimatingOut, systemStatusAnimationScheduler.animationState.value)
// skip disappear animation duration
testScheduler.advanceTimeBy(DISAPPEAR_ANIMATION_DURATION + 1)
@@ -591,33 +598,33 @@
// verify that onHidePersistentDot is invoked despite the animator callback being delayed
// (it's invoked more than DISAPPEAR_ANIMATION_DURATION after the dot removal was requested)
verify(listener, times(1)).onHidePersistentDot()
- // verify that animationState is IDLE
- assertEquals(IDLE, systemStatusAnimationScheduler.getAnimationState())
+ // verify that animationState is Idle
+ assertEquals(Idle, systemStatusAnimationScheduler.animationState.value)
}
- private fun TestScope.fastForwardAnimationToState(@SystemAnimationState animationState: Int) {
+ private fun TestScope.fastForwardAnimationToState(animationState: SystemEventAnimationState) {
// this function should only be called directly after posting a status event
- assertEquals(ANIMATION_QUEUED, systemStatusAnimationScheduler.getAnimationState())
- if (animationState == IDLE || animationState == ANIMATION_QUEUED) return
+ assertEquals(AnimationQueued, systemStatusAnimationScheduler.animationState.value)
+ if (animationState == Idle || animationState == AnimationQueued) return
// skip debounce delay
advanceTimeBy(DEBOUNCE_DELAY + 1)
// status chip starts animating in after debounce delay
- assertEquals(ANIMATING_IN, systemStatusAnimationScheduler.getAnimationState())
+ assertEquals(AnimatingIn, systemStatusAnimationScheduler.animationState.value)
verify(listener, times(1)).onSystemEventAnimationBegin()
- if (animationState == ANIMATING_IN) return
+ if (animationState == AnimatingIn) return
// skip appear animation
animatorTestRule.advanceTimeBy(APPEAR_ANIMATION_DURATION)
advanceTimeBy(APPEAR_ANIMATION_DURATION)
- assertEquals(RUNNING_CHIP_ANIM, systemStatusAnimationScheduler.getAnimationState())
- if (animationState == RUNNING_CHIP_ANIM) return
+ assertEquals(RunningChipAnim, systemStatusAnimationScheduler.animationState.value)
+ if (animationState == RunningChipAnim) return
// skip status chip display time
advanceTimeBy(DISPLAY_LENGTH + 1)
- assertEquals(ANIMATING_OUT, systemStatusAnimationScheduler.getAnimationState())
+ assertEquals(AnimatingOut, systemStatusAnimationScheduler.animationState.value)
verify(listener, times(1)).onSystemEventAnimationFinish(anyBoolean())
- if (animationState == ANIMATING_OUT) return
+ if (animationState == AnimatingOut) return
// skip disappear animation
animatorTestRule.advanceTimeBy(DISAPPEAR_ANIMATION_DURATION)