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

Commit 31d917a5 authored by Chris Göllner's avatar Chris Göllner Committed by Android (Google) Code Review
Browse files

Merge "[Partial Screen Sharing] Log APP_SELECTOR_DISPLAYED atom" into main

parents bf54cbc7 709f6391
Loading
Loading
Loading
Loading
+4 −3
Original line number Diff line number Diff line
@@ -87,14 +87,15 @@ class MediaProjectionAppSelectorActivity(

    override fun getLayoutResource() = R.layout.media_projection_app_selector

    public override fun onCreate(bundle: Bundle?) {
    public override fun onCreate(savedInstanceState: Bundle?) {
        lifecycleRegistry.handleLifecycleEvent(Lifecycle.Event.ON_CREATE)
        component =
            componentFactory.create(
                hostUserHandle = hostUserHandle,
                callingPackage = callingPackage,
                view = this,
                resultHandler = this
                resultHandler = this,
                isFirstStart = savedInstanceState == null
            )
        component.lifecycleObservers.forEach { lifecycle.addObserver(it) }

@@ -113,7 +114,7 @@ class MediaProjectionAppSelectorActivity(
        reviewGrantedConsentRequired =
            intent.getBooleanExtra(EXTRA_USER_REVIEW_GRANTED_CONSENT, false)

        super.onCreate(bundle)
        super.onCreate(savedInstanceState)
        controller.init()
        // we override AppList's AccessibilityDelegate set in ResolverActivity.onCreate because in
        // our case this delegate must extend RecyclerViewAccessibilityDelegate, otherwise
+3 −0
Original line number Diff line number Diff line
@@ -146,6 +146,9 @@ interface MediaProjectionAppSelectorComponent {
            @BindsInstance @MediaProjectionAppSelector callingPackage: String?,
            @BindsInstance view: MediaProjectionAppSelectorView,
            @BindsInstance resultHandler: MediaProjectionAppSelectorResultHandler,
            // Whether the app selector is starting for the first time. False when it is re-starting
            // due to a config change.
            @BindsInstance @MediaProjectionAppSelector isFirstStart: Boolean,
        ): MediaProjectionAppSelectorComponent
    }

+10 −0
Original line number Diff line number Diff line
@@ -18,6 +18,8 @@ package com.android.systemui.mediaprojection.appselector

import android.content.ComponentName
import android.os.UserHandle
import com.android.internal.util.FrameworkStatsLog.MEDIA_PROJECTION_STATE_CHANGED__STATE__MEDIA_PROJECTION_STATE_APP_SELECTOR_DISPLAYED as STATE_APP_SELECTOR_DISPLAYED
import com.android.systemui.mediaprojection.MediaProjectionMetricsLogger
import com.android.systemui.mediaprojection.appselector.data.RecentTask
import com.android.systemui.mediaprojection.appselector.data.RecentTaskListProvider
import com.android.systemui.mediaprojection.appselector.data.RecentTaskThumbnailLoader
@@ -43,9 +45,17 @@ constructor(
    @MediaProjectionAppSelector private val appSelectorComponentName: ComponentName,
    @MediaProjectionAppSelector private val callerPackageName: String?,
    private val thumbnailLoader: RecentTaskThumbnailLoader,
    @MediaProjectionAppSelector private val isFirstStart: Boolean,
    private val logger: MediaProjectionMetricsLogger,
) {

    fun init() {
        // Only log during the first start of the app selector.
        // Don't log when the app selector restarts due to a config change.
        if (isFirstStart) {
            logger.notifyPermissionProgress(STATE_APP_SELECTOR_DISPLAYED)
        }

        scope.launch {
            val recentTasks = recentTaskListProvider.loadRecentTasks()

+33 −9
Original line number Diff line number Diff line
@@ -4,7 +4,9 @@ import android.content.ComponentName
import android.os.UserHandle
import android.testing.AndroidTestingRunner
import androidx.test.filters.SmallTest
import com.android.internal.util.FrameworkStatsLog.MEDIA_PROJECTION_STATE_CHANGED__STATE__MEDIA_PROJECTION_STATE_APP_SELECTOR_DISPLAYED as STATE_APP_SELECTOR_DISPLAYED
import com.android.systemui.SysuiTestCase
import com.android.systemui.mediaprojection.MediaProjectionMetricsLogger
import com.android.systemui.mediaprojection.appselector.data.RecentTask
import com.android.systemui.mediaprojection.appselector.data.RecentTaskListProvider
import com.android.systemui.mediaprojection.appselector.data.RecentTaskThumbnailLoader
@@ -20,6 +22,7 @@ import kotlinx.coroutines.test.runTest
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.Mockito.never
import org.mockito.Mockito.verify

@RunWith(AndroidTestingRunner::class)
@@ -37,10 +40,11 @@ class MediaProjectionAppSelectorControllerTest : SysuiTestCase() {

    private val view: MediaProjectionAppSelectorView = mock()
    private val policyResolver: ScreenCaptureDevicePolicyResolver = mock()
    private val logger = mock<MediaProjectionMetricsLogger>()

    private val thumbnailLoader = FakeThumbnailLoader()

    private val controller =
    private fun createController(isFirstStart: Boolean = true) =
        MediaProjectionAppSelectorController(
            taskListProvider,
            view,
@@ -50,6 +54,8 @@ class MediaProjectionAppSelectorControllerTest : SysuiTestCase() {
            appSelectorComponentName,
            callerPackageName,
            thumbnailLoader,
            isFirstStart,
            logger
        )

    @Before
@@ -61,7 +67,7 @@ class MediaProjectionAppSelectorControllerTest : SysuiTestCase() {
    fun initNoRecentTasks_bindsEmptyList() {
        taskListProvider.tasks = emptyList()

        controller.init()
        createController().init()

        verify(view).bind(emptyList())
    }
@@ -70,7 +76,7 @@ class MediaProjectionAppSelectorControllerTest : SysuiTestCase() {
    fun initOneRecentTask_bindsList() {
        taskListProvider.tasks = listOf(createRecentTask(taskId = 1))

        controller.init()
        createController().init()

        verify(view).bind(listOf(createRecentTask(taskId = 1)))
    }
@@ -86,7 +92,7 @@ class MediaProjectionAppSelectorControllerTest : SysuiTestCase() {
            )
        taskListProvider.tasks = tasks

        controller.init()
        createController().init()

        assertThat(thumbnailLoader.capturedTaskIds).containsExactly(2, 3)
    }
@@ -101,7 +107,7 @@ class MediaProjectionAppSelectorControllerTest : SysuiTestCase() {
            )
        taskListProvider.tasks = tasks

        controller.init()
        createController().init()

        verify(view)
            .bind(
@@ -124,7 +130,7 @@ class MediaProjectionAppSelectorControllerTest : SysuiTestCase() {
            )
        taskListProvider.tasks = tasks

        controller.init()
        createController().init()

        verify(view)
            .bind(
@@ -147,7 +153,7 @@ class MediaProjectionAppSelectorControllerTest : SysuiTestCase() {
            )
        taskListProvider.tasks = tasks

        controller.init()
        createController().init()

        verify(view)
            .bind(
@@ -172,7 +178,7 @@ class MediaProjectionAppSelectorControllerTest : SysuiTestCase() {
            )
        taskListProvider.tasks = tasks

        controller.init()
        createController().init()

        verify(view)
            .bind(
@@ -199,11 +205,29 @@ class MediaProjectionAppSelectorControllerTest : SysuiTestCase() {
        taskListProvider.tasks = tasks

        givenCaptureAllowed(isAllow = false)
        controller.init()
        createController().init()

        verify(view).bind(emptyList())
    }

    @Test
    fun init_firstStart_logsAppSelectorDisplayed() {
        val controller = createController(isFirstStart = true)

        controller.init()

        verify(logger).notifyPermissionProgress(STATE_APP_SELECTOR_DISPLAYED)
    }

    @Test
    fun init_notFirstStart_doesNotLogAppSelectorDisplayed() {
        val controller = createController(isFirstStart = false)

        controller.init()

        verify(logger, never()).notifyPermissionProgress(STATE_APP_SELECTOR_DISPLAYED)
    }

    private fun givenCaptureAllowed(isAllow: Boolean) {
        whenever(policyResolver.isScreenCaptureAllowed(any(), any())).thenReturn(isAllow)
    }