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

Commit 58098d7b authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Add interaction logging to widgets." into main

parents b85fe140 948af2a3
Loading
Loading
Loading
Loading
+8 −2
Original line number Original line Diff line number Diff line
@@ -31,6 +31,7 @@ import com.android.systemui.communal.widgets.CommunalTransitionAnimatorControlle
import com.android.systemui.communal.widgets.SmartspaceAppWidgetHostView
import com.android.systemui.communal.widgets.SmartspaceAppWidgetHostView
import com.android.systemui.coroutines.collectLastValue
import com.android.systemui.coroutines.collectLastValue
import com.android.systemui.kosmos.testScope
import com.android.systemui.kosmos.testScope
import com.android.systemui.log.logcatLogBuffer
import com.android.systemui.plugins.ActivityStarter
import com.android.systemui.plugins.ActivityStarter
import com.android.systemui.testKosmos
import com.android.systemui.testKosmos
import kotlinx.coroutines.test.runTest
import kotlinx.coroutines.test.runTest
@@ -66,7 +67,12 @@ class SmartspaceInteractionHandlerTest : SysuiTestCase() {
    @Before
    @Before
    fun setUp() {
    fun setUp() {
        with(kosmos) {
        with(kosmos) {
            underTest = SmartspaceInteractionHandler(activityStarter, communalSceneInteractor)
            underTest =
                SmartspaceInteractionHandler(
                    activityStarter = activityStarter,
                    communalSceneInteractor = communalSceneInteractor,
                    logBuffer = logcatLogBuffer(),
                )
        }
        }
    }
    }


+8 −2
Original line number Original line Diff line number Diff line
@@ -29,6 +29,7 @@ import com.android.systemui.SysuiTestCase
import com.android.systemui.communal.domain.interactor.communalSceneInteractor
import com.android.systemui.communal.domain.interactor.communalSceneInteractor
import com.android.systemui.coroutines.collectLastValue
import com.android.systemui.coroutines.collectLastValue
import com.android.systemui.kosmos.testScope
import com.android.systemui.kosmos.testScope
import com.android.systemui.log.logcatLogBuffer
import com.android.systemui.plugins.ActivityStarter
import com.android.systemui.plugins.ActivityStarter
import com.android.systemui.testKosmos
import com.android.systemui.testKosmos
import kotlinx.coroutines.test.runTest
import kotlinx.coroutines.test.runTest
@@ -64,7 +65,12 @@ class WidgetInteractionHandlerTest : SysuiTestCase() {
    @Before
    @Before
    fun setUp() {
    fun setUp() {
        with(kosmos) {
        with(kosmos) {
            underTest = WidgetInteractionHandler(activityStarter, communalSceneInteractor)
            underTest =
                WidgetInteractionHandler(
                    activityStarter = activityStarter,
                    communalSceneInteractor = communalSceneInteractor,
                    logBuffer = logcatLogBuffer(),
                )
        }
        }
    }
    }


+10 −0
Original line number Original line Diff line number Diff line
@@ -25,6 +25,9 @@ import com.android.systemui.animation.ActivityTransitionAnimator
import com.android.systemui.communal.domain.interactor.CommunalSceneInteractor
import com.android.systemui.communal.domain.interactor.CommunalSceneInteractor
import com.android.systemui.communal.util.InteractionHandlerDelegate
import com.android.systemui.communal.util.InteractionHandlerDelegate
import com.android.systemui.communal.widgets.SmartspaceAppWidgetHostView
import com.android.systemui.communal.widgets.SmartspaceAppWidgetHostView
import com.android.systemui.log.LogBuffer
import com.android.systemui.log.core.Logger
import com.android.systemui.log.dagger.CommunalLog
import com.android.systemui.plugins.ActivityStarter
import com.android.systemui.plugins.ActivityStarter
import javax.inject.Inject
import javax.inject.Inject


@@ -34,12 +37,19 @@ class SmartspaceInteractionHandler
constructor(
constructor(
    private val activityStarter: ActivityStarter,
    private val activityStarter: ActivityStarter,
    communalSceneInteractor: CommunalSceneInteractor,
    communalSceneInteractor: CommunalSceneInteractor,
    @CommunalLog val logBuffer: LogBuffer,
) : RemoteViews.InteractionHandler {
) : RemoteViews.InteractionHandler {

    private companion object {
        const val TAG = "SmartspaceInteractionHandler"
    }

    private val delegate =
    private val delegate =
        InteractionHandlerDelegate(
        InteractionHandlerDelegate(
            communalSceneInteractor,
            communalSceneInteractor,
            findViewToAnimate = { view -> view is SmartspaceAppWidgetHostView },
            findViewToAnimate = { view -> view is SmartspaceAppWidgetHostView },
            intentStarter = this::startIntent,
            intentStarter = this::startIntent,
            logger = Logger(logBuffer, TAG),
        )
        )


    override fun onInteraction(
    override fun onInteraction(
+15 −0
Original line number Original line Diff line number Diff line
@@ -26,12 +26,14 @@ import androidx.core.util.component2
import com.android.systemui.animation.ActivityTransitionAnimator
import com.android.systemui.animation.ActivityTransitionAnimator
import com.android.systemui.communal.domain.interactor.CommunalSceneInteractor
import com.android.systemui.communal.domain.interactor.CommunalSceneInteractor
import com.android.systemui.communal.widgets.CommunalTransitionAnimatorController
import com.android.systemui.communal.widgets.CommunalTransitionAnimatorController
import com.android.systemui.log.core.Logger


/** A delegate that can be used to launch activities from [RemoteViews] */
/** A delegate that can be used to launch activities from [RemoteViews] */
class InteractionHandlerDelegate(
class InteractionHandlerDelegate(
    private val communalSceneInteractor: CommunalSceneInteractor,
    private val communalSceneInteractor: CommunalSceneInteractor,
    private val findViewToAnimate: (View) -> Boolean,
    private val findViewToAnimate: (View) -> Boolean,
    private val intentStarter: IntentStarter,
    private val intentStarter: IntentStarter,
    private val logger: Logger,
) : RemoteViews.InteractionHandler {
) : RemoteViews.InteractionHandler {


    /** Responsible for starting the pending intent for launching activities. */
    /** Responsible for starting the pending intent for launching activities. */
@@ -49,6 +51,10 @@ class InteractionHandlerDelegate(
        pendingIntent: PendingIntent,
        pendingIntent: PendingIntent,
        response: RemoteViews.RemoteResponse
        response: RemoteViews.RemoteResponse
    ): Boolean {
    ): Boolean {
        logger.i({ "Starting $str1 ($str2)" }) {
            str1 = pendingIntent.toLoggingString()
            str2 = pendingIntent.creatorPackage
        }
        val launchOptions = response.getLaunchOptions(view)
        val launchOptions = response.getLaunchOptions(view)
        return when {
        return when {
            pendingIntent.isActivity -> {
            pendingIntent.isActivity -> {
@@ -82,3 +88,12 @@ class InteractionHandlerDelegate(
        return null
        return null
    }
    }
}
}

private fun PendingIntent.toLoggingString() =
    when {
        isActivity -> "activity"
        isBroadcast -> "broadcast"
        isForegroundService -> "fgService"
        isService -> "service"
        else -> "unknown"
    }
+10 −1
Original line number Original line Diff line number Diff line
@@ -25,6 +25,9 @@ import com.android.systemui.animation.ActivityTransitionAnimator
import com.android.systemui.communal.domain.interactor.CommunalSceneInteractor
import com.android.systemui.communal.domain.interactor.CommunalSceneInteractor
import com.android.systemui.communal.util.InteractionHandlerDelegate
import com.android.systemui.communal.util.InteractionHandlerDelegate
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.log.LogBuffer
import com.android.systemui.log.core.Logger
import com.android.systemui.log.dagger.CommunalLog
import com.android.systemui.plugins.ActivityStarter
import com.android.systemui.plugins.ActivityStarter
import javax.inject.Inject
import javax.inject.Inject


@@ -33,14 +36,20 @@ class WidgetInteractionHandler
@Inject
@Inject
constructor(
constructor(
    private val activityStarter: ActivityStarter,
    private val activityStarter: ActivityStarter,
    private val communalSceneInteractor: CommunalSceneInteractor
    communalSceneInteractor: CommunalSceneInteractor,
    @CommunalLog val logBuffer: LogBuffer,
) : RemoteViews.InteractionHandler {
) : RemoteViews.InteractionHandler {


    private companion object {
        const val TAG = "WidgetInteractionHandler"
    }

    private val delegate =
    private val delegate =
        InteractionHandlerDelegate(
        InteractionHandlerDelegate(
            communalSceneInteractor,
            communalSceneInteractor,
            findViewToAnimate = { view -> view is CommunalAppWidgetHostView },
            findViewToAnimate = { view -> view is CommunalAppWidgetHostView },
            intentStarter = this::startIntent,
            intentStarter = this::startIntent,
            logger = Logger(logBuffer, TAG),
        )
        )


    override fun onInteraction(
    override fun onInteraction(