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

Commit 948af2a3 authored by Lucas Silva's avatar Lucas Silva
Browse files

Add interaction logging to widgets.

Log the type of intent triggered by the widget as well as the package
name.

Bug: 350468769
Test: atest SmartspaceInteractionHandlerTest
Test: atest WidgetInteractionHandlerTest
Flag: com.android.systemui.communal_hub
Change-Id: Id8b4bd5b5004010e462ad5d2b306c0bdf78f7ab4
parent 31a1125d
Loading
Loading
Loading
Loading
+8 −2
Original line number 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.coroutines.collectLastValue
import com.android.systemui.kosmos.testScope
import com.android.systemui.log.logcatLogBuffer
import com.android.systemui.plugins.ActivityStarter
import com.android.systemui.testKosmos
import kotlinx.coroutines.test.runTest
@@ -66,7 +67,12 @@ class SmartspaceInteractionHandlerTest : SysuiTestCase() {
    @Before
    fun setUp() {
        with(kosmos) {
            underTest = SmartspaceInteractionHandler(activityStarter, communalSceneInteractor)
            underTest =
                SmartspaceInteractionHandler(
                    activityStarter = activityStarter,
                    communalSceneInteractor = communalSceneInteractor,
                    logBuffer = logcatLogBuffer(),
                )
        }
    }

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

+10 −0
Original line number 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.util.InteractionHandlerDelegate
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 javax.inject.Inject

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

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

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

    override fun onInteraction(
+15 −0
Original line number Diff line number Diff line
@@ -26,12 +26,14 @@ import androidx.core.util.component2
import com.android.systemui.animation.ActivityTransitionAnimator
import com.android.systemui.communal.domain.interactor.CommunalSceneInteractor
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] */
class InteractionHandlerDelegate(
    private val communalSceneInteractor: CommunalSceneInteractor,
    private val findViewToAnimate: (View) -> Boolean,
    private val intentStarter: IntentStarter,
    private val logger: Logger,
) : RemoteViews.InteractionHandler {

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

private fun PendingIntent.toLoggingString() =
    when {
        isActivity -> "activity"
        isBroadcast -> "broadcast"
        isForegroundService -> "fgService"
        isService -> "service"
        else -> "unknown"
    }
+10 −1
Original line number 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.util.InteractionHandlerDelegate
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 javax.inject.Inject

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

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

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

    override fun onInteraction(