Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1e1fc24f authored by Johannes Gallmann's avatar Johannes Gallmann Committed by Automerger Merge Worker
Browse files

Merge "Fix PrivacyChip not visible issue" into udc-dev am: 7a84a295 am: f811714e am: b5e54e2f

parents 11e28f14 b5e54e2f
Loading
Loading
Loading
Loading
+7 −4
Original line number Diff line number Diff line
@@ -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
    }
}
+1 −0
Original line number Diff line number Diff line
@@ -153,6 +153,7 @@ constructor(
                )
            }
            currentlyDisplayedEvent?.updateFromEvent(event)
            if (event.forceVisible) hasPersistentDot = true
        } else if (scheduledEvent.value?.shouldUpdateFromEvent(event) == true) {
            if (DEBUG) {
                Log.d(
+6 −0
Original line number Diff line number Diff line
@@ -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()
+48 −2
Original line number Diff line number Diff line
@@ -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
    }