diff options
| author | 2024-08-22 16:28:14 +0000 | |
|---|---|---|
| committer | 2024-08-22 16:28:14 +0000 | |
| commit | 192b6f9cec46074859a20aa4deb277a54bbbfda5 (patch) | |
| tree | 12b4af5f83b8f8e903cc19c5be315e21e9b3cf20 | |
| parent | 607432e7485d0e9bca6566110711d86808775425 (diff) | |
| parent | 363e84537d6982f3acd3855324f9d773ee42fe55 (diff) | |
Merge "Create smartspace session when precondition is met" into main
2 files changed, 30 insertions, 6 deletions
diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/smartspace/CommunalSmartspaceControllerTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/smartspace/CommunalSmartspaceControllerTest.kt index eac86e55763a..ce9b3beeec9e 100644 --- a/packages/SystemUI/multivalentTests/src/com/android/systemui/smartspace/CommunalSmartspaceControllerTest.kt +++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/smartspace/CommunalSmartspaceControllerTest.kt @@ -23,7 +23,6 @@ import android.graphics.drawable.Drawable import android.os.Handler import android.testing.TestableLooper import android.view.View -import android.widget.FrameLayout import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.filters.SmallTest import com.android.systemui.SysuiTestCase @@ -46,6 +45,8 @@ import org.mockito.Mockito import org.mockito.Mockito.verify import org.mockito.Mockito.`when` import org.mockito.MockitoAnnotations +import org.mockito.kotlin.argumentCaptor +import org.mockito.kotlin.never @SmallTest @RunWith(AndroidJUnit4::class) @@ -67,12 +68,9 @@ class CommunalSmartspaceControllerTest : SysuiTestCase() { @Mock private lateinit var session: SmartspaceSession - private lateinit var controller: CommunalSmartspaceController + private val preconditionListenerCaptor = argumentCaptor<SmartspacePrecondition.Listener>() - // TODO(b/272811280): Remove usage of real view - private val fakeParent by lazy { - FrameLayout(context) - } + private lateinit var controller: CommunalSmartspaceController /** * A class which implements SmartspaceView and extends View. This is mocked to provide the right @@ -155,6 +153,26 @@ class CommunalSmartspaceControllerTest : SysuiTestCase() { verify(session).close() } + /** Ensures smartspace session begins when precondition is met if there is any listener. */ + @Test + fun testConnectOnPreconditionMet() { + // Precondition not met + `when`(precondition.conditionsMet()).thenReturn(false) + controller.addListener(listener) + + // Verify session not created because precondition not met + verify(smartspaceManager, never()).createSmartspaceSession(any()) + + // Precondition met + `when`(precondition.conditionsMet()).thenReturn(true) + verify(precondition).addListener(preconditionListenerCaptor.capture()) + val preconditionListener = preconditionListenerCaptor.firstValue + preconditionListener.onCriteriaChanged() + + // Verify session created + verify(smartspaceManager).createSmartspaceSession(any()) + } + /** * Ensures session is closed and weather plugin unregisters the notifier when weather smartspace * view is detached. diff --git a/packages/SystemUI/src/com/android/systemui/communal/smartspace/CommunalSmartspaceController.kt b/packages/SystemUI/src/com/android/systemui/communal/smartspace/CommunalSmartspaceController.kt index 80db5353893f..012c844586bc 100644 --- a/packages/SystemUI/src/com/android/systemui/communal/smartspace/CommunalSmartspaceController.kt +++ b/packages/SystemUI/src/com/android/systemui/communal/smartspace/CommunalSmartspaceController.kt @@ -65,6 +65,12 @@ constructor( var preconditionListener = object : SmartspacePrecondition.Listener { override fun onCriteriaChanged() { + if (session == null && hasActiveSessionListeners()) { + Log.d(TAG, "Precondition criteria changed. Attempting to connect session.") + connectSession() + return + } + reloadSmartspace() } } |