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

Commit 8ca9b44f authored by Lucas Dupin's avatar Lucas Dupin Committed by Android (Google) Code Review
Browse files

Merge "Add handling of PendingIntent to AmbientCue" into main

parents ea3f0599 0ca22d02
Loading
Loading
Loading
Loading
+31 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.systemui.ambientcue.data.repository

import android.app.ActivityManager.RunningTaskInfo
import android.app.PendingIntent
import android.app.assist.ActivityId
import android.app.smartspace.SmartspaceAction
import android.app.smartspace.SmartspaceManager
@@ -219,6 +220,23 @@ class AmbientCueRepositoryTest : SysuiTestCase() {
            verify(activityStarter).startActivity(launchIntent, false)
        }

    @Test
    fun action_performPendingIntent() =
        kosmos.runTest {
            val actions by collectLastValue(underTest.actions)
            runCurrent()
            verify(smartSpaceSession)
                .addOnTargetsAvailableListener(any(), onTargetsAvailableListenerCaptor.capture())
            onTargetsAvailableListenerCaptor.firstValue.onTargetsAvailable(
                listOf(pendingIntentTarget)
            )

            val action: ActionModel = actions!!.first()
            action.onPerformAction()
            runCurrent()
            verify(pendingIntent).send()
        }

    @Test
    fun targetTaskId_updatedWithAction() =
        kosmos.runTest {
@@ -287,6 +305,19 @@ class AmbientCueRepositoryTest : SysuiTestCase() {
                    )
            }

        private val pendingIntent = mock<PendingIntent>()
        private val pendingIntentTarget =
            mock<SmartspaceTarget> {
                on { smartspaceTargetId } doReturn AMBIENT_CUE_SURFACE
                on { actionChips } doReturn
                    listOf(
                        SmartspaceAction.Builder("action1-id", "title 1")
                            .setSubtitle("subtitle 1")
                            .setPendingIntent(pendingIntent)
                            .build()
                    )
            }

        private val invalidTarget1 =
            mock<SmartspaceTarget> {
                on { smartspaceTargetId } doReturn "home"
+9 −1
Original line number Diff line number Diff line
@@ -113,6 +113,11 @@ constructor(
                                    attribution = chip.subtitle.toString(),
                                    onPerformAction = {
                                        val intent = chip.intent
                                        val pendingIntent = chip.pendingIntent
                                        val activityId =
                                            chip.extras?.getParcelable<ActivityId>(
                                                EXTRA_ACTIVITY_ID
                                            )
                                        val autofillId =
                                            chip.extras?.getParcelable<AutofillId>(
                                                EXTRA_AUTOFILL_ID
@@ -120,7 +125,8 @@ constructor(
                                        val token = activityId?.token
                                        Log.v(
                                            TAG,
                                            "Performing action: $activityId, $autofillId, $intent",
                                            "Performing action: $activityId, $autofillId, " +
                                                "$pendingIntent, $intent",
                                        )
                                        if (token != null && autofillId != null) {
                                            autofillManager?.autofillRemoteApp(
@@ -129,6 +135,8 @@ constructor(
                                                token,
                                                activityId.taskId,
                                            )
                                        } else if (pendingIntent != null) {
                                            pendingIntent.send()
                                        } else if (intent != null) {
                                            activityStarter.startActivity(intent, false)
                                        }