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

Commit 834a2737 authored by Coco Duan's avatar Coco Duan
Browse files

Fix weather complication not showing after wipe flash

After a wipe install, the weather complication may not appear on the
dream overlay. It is due to the addListenerForWeatherPlugin call
occurring on system start and if the lockscreen smartspace precondition
isn't met (true before the device is set up), then the session to dream
surface is not created.

Fix is to create the session within the smartspace precondition changed
listener if one doesn't already exist.

Fixes: b/382757398
Flag: EXEMPT bugfix
Test: wipe install, finish SUW and verify weather showing on dream
Test: atest DreamSmartspaceControllerTest
Change-Id: I8ee86c565ec29566a3393e30e6d6ee95032e982e
parent 412ec48c
Loading
Loading
Loading
Loading
+27 −3
Original line number Diff line number Diff line
@@ -36,8 +36,6 @@ import com.android.systemui.plugins.FalsingManager
import com.android.systemui.settings.UserTracker
import com.android.systemui.smartspace.dagger.SmartspaceViewComponent
import com.android.systemui.util.concurrency.Execution
import com.android.systemui.util.mockito.any
import com.android.systemui.util.mockito.eq
import com.android.systemui.util.mockito.withArgCaptor
import com.google.common.truth.Truth.assertThat
import java.util.Optional
@@ -51,6 +49,11 @@ import org.mockito.Mockito.anyInt
import org.mockito.Mockito.verify
import org.mockito.Mockito.`when`
import org.mockito.MockitoAnnotations
import org.mockito.kotlin.any
import org.mockito.kotlin.anyOrNull
import org.mockito.kotlin.argumentCaptor
import org.mockito.kotlin.eq
import org.mockito.kotlin.never

@SmallTest
@RunWith(AndroidJUnit4::class)
@@ -82,6 +85,8 @@ class DreamSmartspaceControllerTest : SysuiTestCase() {

    @Mock private lateinit var precondition: SmartspacePrecondition

    private val preconditionListenerCaptor = argumentCaptor<SmartspacePrecondition.Listener>()

    private val smartspaceView: SmartspaceView by lazy { Mockito.spy(TestView(context)) }

    @Mock private lateinit var listener: BcSmartspaceDataPlugin.SmartspaceTargetListener
@@ -137,7 +142,7 @@ class DreamSmartspaceControllerTest : SysuiTestCase() {
        `when`(viewComponentFactory.create(any(), eq(plugin), any(), eq(null)))
            .thenReturn(viewComponent)
        `when`(viewComponent.getView()).thenReturn(smartspaceView)
        `when`(viewComponentFactory.create(any(), eq(weatherPlugin), any(), any()))
        `when`(viewComponentFactory.create(any(), eq(weatherPlugin), any(), anyOrNull()))
            .thenReturn(weatherViewComponent)
        `when`(weatherViewComponent.getView()).thenReturn(weatherSmartspaceView)
        `when`(smartspaceManager.createSmartspaceSession(any())).thenReturn(session)
@@ -187,6 +192,25 @@ class DreamSmartspaceControllerTest : SysuiTestCase() {
        verify(session).close()
    }

    /** Ensures smartspace session is created when smartspace precondition met. */
    @Test
    fun smartspaceSessionCreated_onSmartspacePreconditionMet() {
        // After init
        verify(precondition).addListener(preconditionListenerCaptor.capture())

        // Condition is not met
        `when`(precondition.conditionsMet()).thenReturn(false)
        controller.addListenerForWeatherPlugin(listener)

        verify(smartspaceManager, never()).createSmartspaceSession(any())

        // Condition is met
        `when`(precondition.conditionsMet()).thenReturn(true)
        preconditionListenerCaptor.lastValue.onCriteriaChanged()

        verify(smartspaceManager).createSmartspaceSession(any())
    }

    /** Ensures session begins when a view is attached. */
    @Test
    fun testConnectOnViewCreate() {
+4 −0
Original line number Diff line number Diff line
@@ -81,6 +81,10 @@ constructor(
    var preconditionListener =
        object : SmartspacePrecondition.Listener {
            override fun onCriteriaChanged() {
                if (session == null) {
                    connectSession()
                    return
                }
                reloadSmartspace()
            }
        }