Fix PrivacyChip not visible issue

Bug: 281807669
Test: atest SysteMStatusAnimationSchedulerImplTest
Change-Id: I9851e6ed4cb956d0459ef56251eb0ef3210764b8
This commit is contained in:
Johannes Gallmann
2023-05-11 12:59:24 +02:00
parent ac8d23d973
commit 8ec552f492
4 changed files with 62 additions and 6 deletions

View File

@@ -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
@@ -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?) {
@@ -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
}
}

View File

@@ -153,6 +153,7 @@ constructor(
)
}
currentlyDisplayedEvent?.updateFromEvent(event)
if (event.forceVisible) hasPersistentDot = true
} else if (scheduledEvent.value?.shouldUpdateFromEvent(event) == true) {
if (DEBUG) {
Log.d(

View File

@@ -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()

View File

@@ -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
@@ -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
}