summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Johannes Gallmann <gallmann@google.com> 2023-05-12 10:17:37 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2023-05-12 10:17:37 +0000
commit7a84a295f41fa6f05b8ccf6a953d916f6d91c698 (patch)
tree92066531c5b150545d5369ffae867c031555d952
parent6c388bfda61ab461c2b5f853842476f362651840 (diff)
parent8ec552f492ae2be905e083e2c605f8d3bb601e76 (diff)
Merge "Fix PrivacyChip not visible issue" into udc-dev
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/events/StatusEvent.kt11
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/events/SystemStatusAnimationSchedulerImpl.kt1
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/statusbar/events/FakeStatusEvent.kt6
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/statusbar/events/SystemStatusAnimationSchedulerImplTest.kt50
4 files changed, 62 insertions, 6 deletions
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 43f78c3166e4..e5849c05a534 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 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
}
}
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 f7a4feafee25..0a18f2d89d87 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 @@ constructor(
)
}
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 cd0646543e69..839770267c74 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 @@ 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()
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 08a9f3139d71..39ed5535ff3b 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 @@ class SystemStatusAnimationSchedulerImplTest : SysuiTestCase() {
}
@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 @@ 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
}