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

Commit f95eaec6 authored by Anton Potapov's avatar Anton Potapov Committed by Android (Google) Code Review
Browse files

Merge "Pass target parameters to recording" into main

parents af8c054d abe94f4e
Loading
Loading
Loading
Loading
+2 −1
Original line number Original line Diff line number Diff line
@@ -16,6 +16,7 @@


package com.android.systemui.screencapture.record.domain.interactor
package com.android.systemui.screencapture.record.domain.interactor


import android.view.Display
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import androidx.test.filters.SmallTest
import com.android.systemui.SysuiTestCase
import com.android.systemui.SysuiTestCase
@@ -52,7 +53,7 @@ class ScreenCaptureRecordParametersModelInteractorTest : SysuiTestCase() {
    @Test
    @Test
    fun testChangingTarget() =
    fun testChangingTarget() =
        kosmos.runTest {
        kosmos.runTest {
            val newTarget = ScreenCaptureTarget.App(taskId = 1)
            val newTarget = ScreenCaptureTarget.App(displayId = Display.DEFAULT_DISPLAY, taskId = 1)
            val target by collectLastValue(underTest.parameters.map { it.target })
            val target by collectLastValue(underTest.parameters.map { it.target })
            assertThat(target).isNotEqualTo(newTarget)
            assertThat(target).isNotEqualTo(newTarget)


+1 −1
Original line number Original line Diff line number Diff line
@@ -27,7 +27,7 @@ sealed interface ScreenCaptureTarget {
    data class Region(val displayId: Int, val rect: Rect) : ScreenCaptureTarget
    data class Region(val displayId: Int, val rect: Rect) : ScreenCaptureTarget


    /** A full app. */
    /** A full app. */
    data class App(val taskId: Int) : ScreenCaptureTarget
    data class App(val displayId: Int, val taskId: Int) : ScreenCaptureTarget


    /** Content within an app. */
    /** Content within an app. */
    data class AppContent(val contentId: Int) : ScreenCaptureTarget
    data class AppContent(val contentId: Int) : ScreenCaptureTarget
+1 −1
Original line number Original line Diff line number Diff line
@@ -57,7 +57,7 @@ sealed interface RecordDetailsTargetItemViewModel {
        RecordDetailsTargetItemViewModel {
        RecordDetailsTargetItemViewModel {


        override val screenCaptureTarget: ScreenCaptureTarget? =
        override val screenCaptureTarget: ScreenCaptureTarget? =
            task?.taskId?.let(ScreenCaptureTarget::App)
            task?.run { ScreenCaptureTarget.App(displayId = displayId, taskId = taskId) }


        override val labelRes: Int = R.string.screen_record_single_app
        override val labelRes: Int = R.string.screen_record_single_app
        override val isSelectable: Boolean = true
        override val isSelectable: Boolean = true
+50 −11
Original line number Original line Diff line number Diff line
@@ -16,13 +16,19 @@


package com.android.systemui.screencapture.record.smallscreen.ui.viewmodel
package com.android.systemui.screencapture.record.smallscreen.ui.viewmodel


import android.app.ActivityOptions
import android.app.ActivityOptions.LaunchCookie
import android.app.ActivityOptions.MODE_BACKGROUND_ACTIVITY_START_ALLOW_ALWAYS
import android.app.IActivityTaskManager
import android.media.projection.StopReason
import android.media.projection.StopReason
import androidx.compose.runtime.getValue
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
import androidx.compose.runtime.setValue
import com.android.app.tracing.coroutines.launchTraced
import com.android.app.tracing.coroutines.launchTraced
import com.android.systemui.lifecycle.HydratedActivatable
import com.android.systemui.lifecycle.HydratedActivatable
import com.android.systemui.mediaprojection.MediaProjectionCaptureTarget
import com.android.systemui.screencapture.common.ScreenCaptureUiScope
import com.android.systemui.screencapture.common.ScreenCaptureUiScope
import com.android.systemui.screencapture.common.shared.model.ScreenCaptureTarget
import com.android.systemui.screencapture.common.shared.model.ScreenCaptureType
import com.android.systemui.screencapture.common.shared.model.ScreenCaptureType
import com.android.systemui.screencapture.common.ui.viewmodel.DrawableLoaderViewModel
import com.android.systemui.screencapture.common.ui.viewmodel.DrawableLoaderViewModel
import com.android.systemui.screencapture.common.ui.viewmodel.DrawableLoaderViewModelImpl
import com.android.systemui.screencapture.common.ui.viewmodel.DrawableLoaderViewModelImpl
@@ -45,6 +51,7 @@ constructor(
    recordDetailsTargetViewModelFactory: RecordDetailsTargetViewModel.Factory,
    recordDetailsTargetViewModelFactory: RecordDetailsTargetViewModel.Factory,
    private val drawableLoaderViewModelImpl: DrawableLoaderViewModelImpl,
    private val drawableLoaderViewModelImpl: DrawableLoaderViewModelImpl,
    private val screenCaptureUiInteractor: ScreenCaptureUiInteractor,
    private val screenCaptureUiInteractor: ScreenCaptureUiInteractor,
    private val activityTaskManager: IActivityTaskManager,
) : HydratedActivatable(), DrawableLoaderViewModel by drawableLoaderViewModelImpl {
) : HydratedActivatable(), DrawableLoaderViewModel by drawableLoaderViewModelImpl {


    val recordDetailsAppSelectorViewModel: RecordDetailsAppSelectorViewModel =
    val recordDetailsAppSelectorViewModel: RecordDetailsAppSelectorViewModel =
@@ -120,18 +127,50 @@ constructor(
        if (screenRecordingServiceInteractor.status.value.isRecording) {
        if (screenRecordingServiceInteractor.status.value.isRecording) {
            screenRecordingServiceInteractor.stopRecording(StopReason.STOP_HOST_APP)
            screenRecordingServiceInteractor.stopRecording(StopReason.STOP_HOST_APP)
        } else {
        } else {
            startRecording()
            dismiss()
        }
    }

    private fun startRecording() {
        val shouldShowTaps = recordDetailsParametersViewModel.shouldShowTaps ?: return
        val shouldShowTaps = recordDetailsParametersViewModel.shouldShowTaps ?: return
        val audioSource = recordDetailsParametersViewModel.audioSource ?: return
        val audioSource = recordDetailsParametersViewModel.audioSource ?: return
            // TODO(b/428686600) pass actual parameters
        when (val target = recordDetailsTargetViewModel.currentTarget?.screenCaptureTarget) {
            is ScreenCaptureTarget.Fullscreen ->
                screenRecordingServiceInteractor.startRecording(
                screenRecordingServiceInteractor.startRecording(
                    ScreenRecordingParameters(
                    ScreenRecordingParameters(
                        captureTarget = null,
                        captureTarget = null,
                    displayId = 0,
                        displayId = target.displayId,
                        shouldShowTaps = shouldShowTaps,
                        shouldShowTaps = shouldShowTaps,
                        audioSource = audioSource,
                        audioSource = audioSource,
                    )
                    )
                )
                )
            dismiss()
            is ScreenCaptureTarget.App -> {
                val cookie = LaunchCookie("screen_record")
                activityTaskManager.startActivityFromRecents(
                    target.taskId,
                    ActivityOptions.makeBasic()
                        .apply {
                            pendingIntentBackgroundActivityStartMode =
                                MODE_BACKGROUND_ACTIVITY_START_ALLOW_ALWAYS
                            setLaunchCookie(cookie)
                        }
                        .toBundle(),
                )
                screenRecordingServiceInteractor.startRecording(
                    ScreenRecordingParameters(
                        captureTarget =
                            MediaProjectionCaptureTarget(
                                launchCookie = cookie,
                                taskId = target.taskId,
                            ),
                        displayId = target.displayId,
                        shouldShowTaps = shouldShowTaps,
                        audioSource = audioSource,
                    )
                )
            }
            else -> error("Unsupported target=$target")
        }
        }
    }
    }