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

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

Merge "Introduce base components for the new screen recording flow" into main

parents 0c88200e 59d1cb34
Loading
Loading
Loading
Loading
+66 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2025 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.screencapture.record.domain.interactor

import android.content.testableContext
import android.platform.test.annotations.EnableFlags
import android.platform.test.flag.junit.SetFlagsRule
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.systemui.Flags
import com.android.systemui.SysuiTestCase
import com.android.systemui.kosmos.collectLastValue
import com.android.systemui.kosmos.runTest
import com.android.systemui.res.R
import com.android.systemui.statusbar.policy.configurationController
import com.android.systemui.testKosmos
import com.google.common.truth.Truth.assertThat
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith

@SmallTest
@RunWith(AndroidJUnit4::class)
class ScreenCaptureRecordFeaturesInteractorTest : SysuiTestCase() {

    @get:Rule val setFlagsRule = SetFlagsRule()

    private val kosmos = testKosmos()

    private val underTest by lazy { kosmos.screenCaptureRecordFeaturesInteractor }

    @Test
    @EnableFlags(Flags.FLAG_DESKTOP_SCREEN_CAPTURE)
    fun isLargeScreenReturnsConfigValue() =
        kosmos.runTest {
            val isLargeScreen by collectLastValue(underTest.isLargeScreen)

            testableContext.orCreateTestableResources.addOverride(
                R.bool.config_enableDesktopScreenCapture,
                true,
            )
            configurationController.onConfigurationChanged(testableContext.resources.configuration)
            assertThat(isLargeScreen).isTrue()

            testableContext.orCreateTestableResources.addOverride(
                R.bool.config_enableDesktopScreenCapture,
                false,
            )
            configurationController.onConfigurationChanged(testableContext.resources.configuration)
            assertThat(isLargeScreen).isFalse()
        }
}
+52 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2025 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.screencapture.record.domain.interactor

import android.content.res.Resources
import com.android.systemui.Flags
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.qualifiers.Background
import com.android.systemui.dagger.qualifiers.Main
import com.android.systemui.res.R
import com.android.systemui.statusbar.policy.ConfigurationController
import com.android.systemui.statusbar.policy.onConfigChanged
import javax.inject.Inject
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.onStart
import kotlinx.coroutines.flow.stateIn

@SysUISingleton
class ScreenCaptureRecordFeaturesInteractor
@Inject
constructor(
    @Main private val resources: Resources,
    @Background private val scope: CoroutineScope,
    configurationController: ConfigurationController,
) {

    val isLargeScreen: Flow<Boolean?> =
        configurationController.onConfigChanged
            .onStart { emit(resources.configuration) }
            .map {
                Flags.desktopScreenCapture() &&
                    resources.getBoolean(R.bool.config_enableDesktopScreenCapture)
            }
            .stateIn(scope, SharingStarted.WhileSubscribed(), null)
}
+30 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2025 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.screencapture.record.largescreen.ui.compose

import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import com.android.systemui.screencapture.common.ui.compose.ScreenCaptureContent
import javax.inject.Inject

class LargeScreenCaptureRecordContent @Inject constructor() : ScreenCaptureContent {

    @Composable
    override fun Content() {
        Text("Not yet implemented")
    }
}
+30 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2025 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.screencapture.record.smallscreen.ui.compose

import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import com.android.systemui.screencapture.common.ui.compose.ScreenCaptureContent
import javax.inject.Inject

class SmallScreenCaptureRecordContent @Inject constructor() : ScreenCaptureContent {

    @Composable
    override fun Content() {
        Text("Not yet implemented")
    }
}
+31 −3
Original line number Diff line number Diff line
@@ -16,15 +16,43 @@

package com.android.systemui.screencapture.record.ui.compose

import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.derivedStateOf
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import com.android.systemui.lifecycle.rememberViewModel
import com.android.systemui.screencapture.common.ui.compose.ScreenCaptureContent
import com.android.systemui.screencapture.record.largescreen.ui.compose.LargeScreenCaptureRecordContent
import com.android.systemui.screencapture.record.smallscreen.ui.compose.SmallScreenCaptureRecordContent
import com.android.systemui.screencapture.record.ui.viewmodel.ScreenCaptureRecordViewModel
import dagger.Lazy
import javax.inject.Inject

/** Entry point for Record composable content. */
class ScreenCaptureRecordContent @Inject constructor() : ScreenCaptureContent {
class ScreenCaptureRecordContent
@Inject
constructor(
    private val screenCaptureRecordViewModelFactory: ScreenCaptureRecordViewModel.Factory,
    private val largeScreenCaptureRecordContent: Lazy<LargeScreenCaptureRecordContent>,
    private val smallScreenCaptureRecordContent: Lazy<SmallScreenCaptureRecordContent>,
) : ScreenCaptureContent {

    @Composable
    override fun Content() {
        Text("Not yet implemented")
        val viewModel =
            rememberViewModel("ScreenCaptureRecordContent#ScreenCaptureRecordViewModel") {
                screenCaptureRecordViewModelFactory.create()
            }
        val content: ScreenCaptureContent? by
            remember(viewModel.isLargeScreen) {
                derivedStateOf {
                    when (viewModel.isLargeScreen) {
                        true -> largeScreenCaptureRecordContent.get()
                        false -> smallScreenCaptureRecordContent.get()
                        else -> null
                    }
                }
            }
        content?.Content()
    }
}
Loading