Merge "Fix PrivacyChip not visible issue" into udc-dev
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/events/StatusEvent.kt b/packages/SystemUI/src/com/android/systemui/statusbar/events/StatusEvent.kt
index 43f78c3..e5849c0 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/events/StatusEvent.kt
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/events/StatusEvent.kt
@@ -87,7 +87,8 @@
}
}
-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 @@
}
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 @@
privacyChip?.contentDescription = other.contentDescription
privacyChip?.privacyList = other.privacyItems
+
+ if (other.forceVisible) forceVisible = true
}
}
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 f7a4fea..0a18f2d 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/events/SystemStatusAnimationSchedulerImpl.kt
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/events/SystemStatusAnimationSchedulerImpl.kt
@@ -153,6 +153,7 @@
)
}
currentlyDisplayedEvent?.updateFromEvent(event)
+ if (event.forceVisible) hasPersistentDot = true
} else if (scheduledEvent.value?.shouldUpdateFromEvent(event) == true) {
if (DEBUG) {
Log.d(
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/events/FakeStatusEvent.kt b/packages/SystemUI/tests/src/com/android/systemui/statusbar/events/FakeStatusEvent.kt
index cd06465..8397702 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/events/FakeStatusEvent.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/events/FakeStatusEvent.kt
@@ -27,3 +27,9 @@
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()
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 08a9f31..39ed553 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
@@ -380,6 +380,53 @@
}
@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
initializeSystemStatusAnimationScheduler(testScope = this)
@@ -440,8 +487,7 @@
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
}