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

Commit edcc80f4 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "[Media TTT] Add analytics logs for the receiver chip." into tm-dev

parents d120ca75 01a2ae47
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -17,8 +17,7 @@
package com.android.systemui.media.taptotransfer.receiver

import android.app.StatusBarManager
import com.android.systemui.media.taptotransfer.common.DEFAULT_TIMEOUT_MILLIS
import com.android.systemui.media.taptotransfer.common.ChipInfoCommon
import com.android.internal.logging.UiEventLogger

/**
 * A class that stores all the information necessary to display the media tap-to-transfer chip on
@@ -26,12 +25,15 @@ import com.android.systemui.media.taptotransfer.common.ChipInfoCommon
 */
enum class ChipStateReceiver(
    @StatusBarManager.MediaTransferSenderState val stateInt: Int,
    val uiEvent: UiEventLogger.UiEventEnum,
) {
    CLOSE_TO_SENDER(
        StatusBarManager.MEDIA_TRANSFER_RECEIVER_STATE_CLOSE_TO_SENDER,
        MediaTttReceiverUiEvents.MEDIA_TTT_RECEIVER_CLOSE_TO_SENDER,
    ),
    FAR_FROM_SENDER(
        StatusBarManager.MEDIA_TRANSFER_RECEIVER_STATE_FAR_FROM_SENDER,
        MediaTttReceiverUiEvents.MEDIA_TTT_RECEIVER_FAR_FROM_SENDER,
    );

    companion object {
+3 −0
Original line number Diff line number Diff line
@@ -53,6 +53,7 @@ class MediaTttChipControllerReceiver @Inject constructor(
    mainExecutor: DelayableExecutor,
    tapGestureDetector: TapGestureDetector,
    @Main private val mainHandler: Handler,
    private val uiEventLogger: MediaTttReceiverUiEventLogger,
) : MediaTttChipControllerCommon<ChipReceiverInfo>(
    context,
    logger,
@@ -93,6 +94,8 @@ class MediaTttChipControllerReceiver @Inject constructor(
            Log.e(RECEIVER_TAG, "Unhandled MediaTransferReceiverState $displayState")
            return
        }
        uiEventLogger.logReceiverStateChange(chipState)

        if (chipState == ChipStateReceiver.FAR_FROM_SENDER) {
            removeChip(removalReason = ChipStateReceiver.FAR_FROM_SENDER::class.simpleName!!)
            return
+40 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2022 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.systemui.media.taptotransfer.receiver

import com.android.internal.logging.UiEvent
import com.android.internal.logging.UiEventLogger
import com.android.systemui.dagger.SysUISingleton
import javax.inject.Inject

/** A class for analytics logging for the media tap-to-transfer chip on the receiver device. */
@SysUISingleton
class MediaTttReceiverUiEventLogger @Inject constructor(private val logger: UiEventLogger) {
    /** Logs that the receiver chip has changed states. */
    fun logReceiverStateChange(chipState: ChipStateReceiver) {
        logger.log(chipState.uiEvent)
    }
}

enum class MediaTttReceiverUiEvents(val metricId: Int) : UiEventLogger.UiEventEnum {
    @UiEvent(doc = "See android.app.StatusBarManager.MEDIA_TRANSFER_RECEIVER_* docs")
    MEDIA_TTT_RECEIVER_CLOSE_TO_SENDER(982),
    @UiEvent(doc = "See android.app.StatusBarManager.MEDIA_TRANSFER_RECEIVER_* docs")
    MEDIA_TTT_RECEIVER_FAR_FROM_SENDER(983);

    override fun getId() = metricId
}
+13 −0
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ import android.view.ViewGroup
import android.view.WindowManager
import android.widget.ImageView
import androidx.test.filters.SmallTest
import com.android.internal.logging.testing.UiEventLoggerFake
import com.android.systemui.R
import com.android.systemui.SysuiTestCase
import com.android.systemui.media.taptotransfer.common.MediaTttLogger
@@ -70,6 +71,8 @@ class MediaTttChipControllerReceiverTest : SysuiTestCase() {
    private lateinit var commandQueue: CommandQueue
    private lateinit var commandQueueCallback: CommandQueue.Callbacks
    private lateinit var fakeAppIconDrawable: Drawable
    private lateinit var uiEventLoggerFake: UiEventLoggerFake
    private lateinit var receiverUiEventLogger: MediaTttReceiverUiEventLogger

    @Before
    fun setUp() {
@@ -83,6 +86,9 @@ class MediaTttChipControllerReceiverTest : SysuiTestCase() {
        )).thenReturn(applicationInfo)
        context.setMockPackageManager(packageManager)

        uiEventLoggerFake = UiEventLoggerFake()
        receiverUiEventLogger = MediaTttReceiverUiEventLogger(uiEventLoggerFake)

        controllerReceiver = MediaTttChipControllerReceiver(
            commandQueue,
            context,
@@ -92,6 +98,7 @@ class MediaTttChipControllerReceiverTest : SysuiTestCase() {
            FakeExecutor(FakeSystemClock()),
            TapGestureDetector(context),
            Handler.getMain(),
            receiverUiEventLogger,
        )

        val callbackCaptor = ArgumentCaptor.forClass(CommandQueue.Callbacks::class.java)
@@ -110,6 +117,9 @@ class MediaTttChipControllerReceiverTest : SysuiTestCase() {
        )

        assertThat(getChipView().getAppIconView().contentDescription).isEqualTo(appName)
        assertThat(uiEventLoggerFake.eventId(0)).isEqualTo(
            MediaTttReceiverUiEvents.MEDIA_TTT_RECEIVER_CLOSE_TO_SENDER.id
        )
    }

    @Test
@@ -122,6 +132,9 @@ class MediaTttChipControllerReceiverTest : SysuiTestCase() {
        )

        verify(windowManager, never()).addView(any(), any())
        assertThat(uiEventLoggerFake.eventId(0)).isEqualTo(
            MediaTttReceiverUiEvents.MEDIA_TTT_RECEIVER_FAR_FROM_SENDER.id
        )
    }

    @Test
+30 −0
Original line number Diff line number Diff line
package com.android.systemui.media.taptotransfer.receiver

import androidx.test.filters.SmallTest
import com.android.internal.logging.testing.UiEventLoggerFake
import com.android.systemui.SysuiTestCase
import com.google.common.truth.Truth.assertThat
import org.junit.Before
import org.junit.Test

@SmallTest
class MediaTttReceiverUiEventLoggerTest : SysuiTestCase() {
    private lateinit var uiEventLoggerFake: UiEventLoggerFake
    private lateinit var logger: MediaTttReceiverUiEventLogger

    @Before
    fun setUp() {
        uiEventLoggerFake = UiEventLoggerFake()
        logger = MediaTttReceiverUiEventLogger(uiEventLoggerFake)
    }

    @Test
    fun logReceiverStateChange_eventAssociatedWithStateIsLogged() {
        val state = ChipStateReceiver.CLOSE_TO_SENDER

        logger.logReceiverStateChange(state)

        assertThat(uiEventLoggerFake.numLogs()).isEqualTo(1)
        assertThat(uiEventLoggerFake.eventId(0)).isEqualTo(state.uiEvent.id)
    }
}