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

Commit c03cb625 authored by Kai Li's avatar Kai Li
Browse files

Ignore request with no valid SmartSpaceTargets.

When we receive an empty list of SmartSpaceTargets, it will cause that `rootViewAttached` to be `false`. This will cause the `AmbientCue` to be detached.

This can happen in some cases that other smartspace card requests updates from AiAi, which will occasionally clear the cue bar.

Bug: 425831320
Flag: com.android.systemui.enable_underlay
Test: atest AmbientCueRepositoryTest
Change-Id: Ib3fe868e9767c9332c0134f6c687df3b5f46e5fe
parent b0ae2973
Loading
Loading
Loading
Loading
+54 −0
Original line number Diff line number Diff line
@@ -145,6 +145,60 @@ class AmbientCueRepositoryTest : SysuiTestCase() {
            assertThat(isRootViewAttached).isFalse()
        }

    @Test
    fun isRootViewAttached_whenEmptySmartSpaceTargets_true() =
        kosmos.runTest {
            val actions by collectLastValue(underTest.actions)
            val isRootViewAttached by collectLastValue(underTest.isRootViewAttached)
            secureSettingsRepository.setInt(
                AmbientCueRepositoryImpl.AMBIENT_CUE_SETTING,
                AmbientCueRepositoryImpl.OPTED_IN,
            )
            runCurrent()
            verify(smartSpaceSession)
                .addOnTargetsAvailableListener(any(), onTargetsAvailableListenerCaptor.capture())

            taskStackChangeListeners.listenerImpl.onTaskMovedToFront(
                RunningTaskInfo().apply { taskId = TASK_ID }
            )
            advanceTimeBy(DEBOUNCE_DELAY_MS)
            // Attach the root view first.
            onTargetsAvailableListenerCaptor.firstValue.onTargetsAvailable(listOf(autofillTarget))
            advanceUntilIdle()
            onTargetsAvailableListenerCaptor.firstValue.onTargetsAvailable(emptyList())
            advanceUntilIdle()

            // Empty list won't cause the root view to be detached.
            assertThat(isRootViewAttached).isTrue()
        }

   @Test
    fun isRootViewAttached_whenNoValidSmartSpaceTargets_true() =
        kosmos.runTest {
            val actions by collectLastValue(underTest.actions)
            val isRootViewAttached by collectLastValue(underTest.isRootViewAttached)
            secureSettingsRepository.setInt(
                AmbientCueRepositoryImpl.AMBIENT_CUE_SETTING,
                AmbientCueRepositoryImpl.OPTED_IN,
            )
            runCurrent()
            verify(smartSpaceSession)
                .addOnTargetsAvailableListener(any(), onTargetsAvailableListenerCaptor.capture())

            taskStackChangeListeners.listenerImpl.onTaskMovedToFront(
                RunningTaskInfo().apply { taskId = TASK_ID }
            )
            advanceTimeBy(DEBOUNCE_DELAY_MS)
            // Attach the root view first.
            onTargetsAvailableListenerCaptor.firstValue.onTargetsAvailable(listOf(autofillTarget))
            advanceUntilIdle()
            onTargetsAvailableListenerCaptor.firstValue.onTargetsAvailable(listOf(invalidTarget1))
            advanceUntilIdle()

            // Invalid target won't cause the root view to be detached.
            assertThat(isRootViewAttached).isTrue()
        }

    @Test
    fun isRootViewAttached_deactivated_false() =
        kosmos.runTest {
+4 −0
Original line number Diff line number Diff line
@@ -145,6 +145,10 @@ constructor(
                Log.i(TAG, "SmartSpace session created")

                val smartSpaceListener = OnTargetsAvailableListener { targets ->
                    Log.i(TAG, "Receiving SmartSpace targets # ${targets.size}")
                    if (targets.none { it.smartspaceTargetId == AMBIENT_CUE_SURFACE }) {
                        return@OnTargetsAvailableListener
                    }
                    val actions =
                        targets
                            .filter { it.smartspaceTargetId == AMBIENT_CUE_SURFACE }