Loading packages/SystemUI/src/com/android/systemui/statusbar/events/StatusEvent.kt +7 −4 Original line number Diff line number Diff line Loading @@ -87,7 +87,8 @@ class BatteryEvent(@IntRange(from = 0, to = 100) val batteryLevel: Int) : Status } } class PrivacyEvent(override val showAnimation: Boolean = true) : StatusEvent { /** open only for testing purposes. (See [FakeStatusEvent.kt]) */ open class PrivacyEvent(override val showAnimation: Boolean = true) : StatusEvent { override var contentDescription: String? = null override val priority = 100 override var forceVisible = true Loading @@ -107,9 +108,9 @@ class PrivacyEvent(override val showAnimation: Boolean = true) : StatusEvent { } override fun shouldUpdateFromEvent(other: StatusEvent?): Boolean { return other is PrivacyEvent && (other.privacyItems != privacyItems || other.contentDescription != contentDescription) return other is PrivacyEvent && (other.privacyItems != privacyItems || other.contentDescription != contentDescription || (other.forceVisible && !forceVisible)) } override fun updateFromEvent(other: StatusEvent?) { Loading @@ -122,5 +123,7 @@ class PrivacyEvent(override val showAnimation: Boolean = true) : StatusEvent { privacyChip?.contentDescription = other.contentDescription privacyChip?.privacyList = other.privacyItems if (other.forceVisible) forceVisible = true } } packages/SystemUI/src/com/android/systemui/statusbar/events/SystemStatusAnimationSchedulerImpl.kt +1 −0 Original line number Diff line number Diff line Loading @@ -153,6 +153,7 @@ constructor( ) } currentlyDisplayedEvent?.updateFromEvent(event) if (event.forceVisible) hasPersistentDot = true } else if (scheduledEvent.value?.shouldUpdateFromEvent(event) == true) { if (DEBUG) { Log.d( Loading packages/SystemUI/tests/src/com/android/systemui/statusbar/events/FakeStatusEvent.kt +6 −0 Original line number Diff line number Diff line Loading @@ -27,3 +27,9 @@ class FakeStatusEvent( override val showAnimation: Boolean = true, override var contentDescription: String? = "", ) : StatusEvent class FakePrivacyStatusEvent( override val viewCreator: ViewCreator, override val showAnimation: Boolean = true, override var contentDescription: String? = "", ) : PrivacyEvent() packages/SystemUI/tests/src/com/android/systemui/statusbar/events/SystemStatusAnimationSchedulerImplTest.kt +48 −2 Original line number Diff line number Diff line Loading @@ -379,6 +379,53 @@ class SystemStatusAnimationSchedulerImplTest : SysuiTestCase() { verify(listener, never()).onHidePersistentDot() } @Test fun testPrivacyEvent_forceVisibleIsUpdated_whenRescheduledDuringQueuedState() = runTest { // Instantiate class under test with TestScope from runTest initializeSystemStatusAnimationScheduler(testScope = this) // create and schedule privacy event createAndScheduleFakePrivacyEvent() // request removal of persistent dot (sets forceVisible to false) systemStatusAnimationScheduler.removePersistentDot() // 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) // verify that we reach SHOWING_PERSISTENT_DOT and that listener callback is invoked assertEquals(SHOWING_PERSISTENT_DOT, systemStatusAnimationScheduler.getAnimationState()) verify(listener, times(1)).onSystemStatusAnimationTransitionToPersistentDot(any()) } @Test fun testPrivacyEvent_forceVisibleIsUpdated_whenRescheduledDuringAnimatingState() = runTest { // Instantiate class under test with TestScope from runTest initializeSystemStatusAnimationScheduler(testScope = this) // create and schedule privacy event createAndScheduleFakePrivacyEvent() // request removal of persistent dot (sets forceVisible to false) systemStatusAnimationScheduler.removePersistentDot() fastForwardAnimationToState(RUNNING_CHIP_ANIM) // 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()) 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(listener, times(1)).onSystemStatusAnimationTransitionToPersistentDot(any()) } @Test fun testNewEvent_isScheduled_whenPostedDuringRemovalAnimation() = runTest { // Instantiate class under test with TestScope from runTest Loading Loading @@ -440,8 +487,7 @@ class SystemStatusAnimationSchedulerImplTest : SysuiTestCase() { private fun createAndScheduleFakePrivacyEvent(): OngoingPrivacyChip { val privacyChip = OngoingPrivacyChip(mContext) val fakePrivacyStatusEvent = FakeStatusEvent(viewCreator = { privacyChip }, priority = 100, forceVisible = true) val fakePrivacyStatusEvent = FakePrivacyStatusEvent(viewCreator = { privacyChip }) systemStatusAnimationScheduler.onStatusEvent(fakePrivacyStatusEvent) return privacyChip } Loading Loading
packages/SystemUI/src/com/android/systemui/statusbar/events/StatusEvent.kt +7 −4 Original line number Diff line number Diff line Loading @@ -87,7 +87,8 @@ class BatteryEvent(@IntRange(from = 0, to = 100) val batteryLevel: Int) : Status } } class PrivacyEvent(override val showAnimation: Boolean = true) : StatusEvent { /** open only for testing purposes. (See [FakeStatusEvent.kt]) */ open class PrivacyEvent(override val showAnimation: Boolean = true) : StatusEvent { override var contentDescription: String? = null override val priority = 100 override var forceVisible = true Loading @@ -107,9 +108,9 @@ class PrivacyEvent(override val showAnimation: Boolean = true) : StatusEvent { } override fun shouldUpdateFromEvent(other: StatusEvent?): Boolean { return other is PrivacyEvent && (other.privacyItems != privacyItems || other.contentDescription != contentDescription) return other is PrivacyEvent && (other.privacyItems != privacyItems || other.contentDescription != contentDescription || (other.forceVisible && !forceVisible)) } override fun updateFromEvent(other: StatusEvent?) { Loading @@ -122,5 +123,7 @@ class PrivacyEvent(override val showAnimation: Boolean = true) : StatusEvent { privacyChip?.contentDescription = other.contentDescription privacyChip?.privacyList = other.privacyItems if (other.forceVisible) forceVisible = true } }
packages/SystemUI/src/com/android/systemui/statusbar/events/SystemStatusAnimationSchedulerImpl.kt +1 −0 Original line number Diff line number Diff line Loading @@ -153,6 +153,7 @@ constructor( ) } currentlyDisplayedEvent?.updateFromEvent(event) if (event.forceVisible) hasPersistentDot = true } else if (scheduledEvent.value?.shouldUpdateFromEvent(event) == true) { if (DEBUG) { Log.d( Loading
packages/SystemUI/tests/src/com/android/systemui/statusbar/events/FakeStatusEvent.kt +6 −0 Original line number Diff line number Diff line Loading @@ -27,3 +27,9 @@ class FakeStatusEvent( override val showAnimation: Boolean = true, override var contentDescription: String? = "", ) : StatusEvent class FakePrivacyStatusEvent( override val viewCreator: ViewCreator, override val showAnimation: Boolean = true, override var contentDescription: String? = "", ) : PrivacyEvent()
packages/SystemUI/tests/src/com/android/systemui/statusbar/events/SystemStatusAnimationSchedulerImplTest.kt +48 −2 Original line number Diff line number Diff line Loading @@ -379,6 +379,53 @@ class SystemStatusAnimationSchedulerImplTest : SysuiTestCase() { verify(listener, never()).onHidePersistentDot() } @Test fun testPrivacyEvent_forceVisibleIsUpdated_whenRescheduledDuringQueuedState() = runTest { // Instantiate class under test with TestScope from runTest initializeSystemStatusAnimationScheduler(testScope = this) // create and schedule privacy event createAndScheduleFakePrivacyEvent() // request removal of persistent dot (sets forceVisible to false) systemStatusAnimationScheduler.removePersistentDot() // 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) // verify that we reach SHOWING_PERSISTENT_DOT and that listener callback is invoked assertEquals(SHOWING_PERSISTENT_DOT, systemStatusAnimationScheduler.getAnimationState()) verify(listener, times(1)).onSystemStatusAnimationTransitionToPersistentDot(any()) } @Test fun testPrivacyEvent_forceVisibleIsUpdated_whenRescheduledDuringAnimatingState() = runTest { // Instantiate class under test with TestScope from runTest initializeSystemStatusAnimationScheduler(testScope = this) // create and schedule privacy event createAndScheduleFakePrivacyEvent() // request removal of persistent dot (sets forceVisible to false) systemStatusAnimationScheduler.removePersistentDot() fastForwardAnimationToState(RUNNING_CHIP_ANIM) // 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()) 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(listener, times(1)).onSystemStatusAnimationTransitionToPersistentDot(any()) } @Test fun testNewEvent_isScheduled_whenPostedDuringRemovalAnimation() = runTest { // Instantiate class under test with TestScope from runTest Loading Loading @@ -440,8 +487,7 @@ class SystemStatusAnimationSchedulerImplTest : SysuiTestCase() { private fun createAndScheduleFakePrivacyEvent(): OngoingPrivacyChip { val privacyChip = OngoingPrivacyChip(mContext) val fakePrivacyStatusEvent = FakeStatusEvent(viewCreator = { privacyChip }, priority = 100, forceVisible = true) val fakePrivacyStatusEvent = FakePrivacyStatusEvent(viewCreator = { privacyChip }) systemStatusAnimationScheduler.onStatusEvent(fakePrivacyStatusEvent) return privacyChip } Loading