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

Commit d462881e authored by burakov's avatar burakov
Browse files

[flexiglass] Part II: Use single shade on some large-screens.

This is a follow-up to ag/34844807.

Fix: 435145944
Test: Tested manually by rotating an unfolded foldable to portrait and
 observing that single shade is shown.
Test: Added a unit test for this specific case.
Flag: com.android.systemui.scene_container
Change-Id: Id7e5b783f188cae6b1f6ff194661647cd6cd874e
parent d5983e8b
Loading
Loading
Loading
Loading
+13 −12
Original line number Diff line number Diff line
@@ -70,6 +70,9 @@ interface ShadeModeInteractor {
    /** Convenience shortcut for querying whether the current [shadeMode] is [ShadeMode.Split]. */
    val isSplitShade: Boolean
        get() = shadeMode.value is ShadeMode.Split

    /** Whether the user has enabled the Dual Shade setting. */
    val isDualShadeSettingEnabled: Flow<Boolean>
}

class ShadeModeInteractorImpl
@@ -83,7 +86,7 @@ constructor(
    @SceneFrameworkTableLog private val tableLogBuffer: TableLogBuffer,
) : ShadeModeInteractor {

    private val isDualShadeEnabled: Flow<Boolean> =
    override val isDualShadeSettingEnabled: Flow<Boolean> =
        if (SceneContainerFlag.isEnabled) {
            secureSettingsRepository
                .boolSetting(Settings.Secure.DUAL_SHADE, defaultValue = DUAL_SHADE_ENABLED_DEFAULT)
@@ -109,7 +112,7 @@ constructor(
            )

    override val shadeMode: StateFlow<ShadeMode> =
        combine(isDualShadeEnabled, isShadeLayoutWide, isLargeScreen, ::determineShadeMode)
        combine(isDualShadeSettingEnabled, isShadeLayoutWide, isLargeScreen, ::determineShadeMode)
            .logDiffsForTable(tableLogBuffer = tableLogBuffer, initialValue = shadeModeInitialValue)
            .stateIn(applicationScope, SharingStarted.Eagerly, initialValue = shadeModeInitialValue)

@@ -126,17 +129,13 @@ constructor(
            // Case 2: The Dual Shade setting has been enabled by the user.
            isDualShadeEnabled -> ShadeMode.Dual

            // Case 3: Phone in portrait orientation, with Dual Shade setting disabled.
            !isShadeLayoutWide -> ShadeMode.Single

            // Case 4: Phone in landscape orientation, with Dual Shade setting disabled.
            !isLargeScreen -> ShadeMode.Single
            // Case 3: Large screen in landscape orientation, with Dual Shade setting disabled.
            isLargeScreen && isShadeLayoutWide ->
                if (isSplitShadeEnabled) ShadeMode.Split else ShadeMode.Dual

            // Case 5: Large screen with Split Shade enabled, Dual Shade setting disabled.
            isSplitShadeEnabled -> ShadeMode.Split

            // Case 6: Large screen with Split Shade disabled, Dual Shade setting disabled.
            else -> ShadeMode.Dual
            // Case 4: Phone (in any orientation) or large screen in portrait, with Dual Shade
            // setting disabled.
            else -> ShadeMode.Single
        }
    }

@@ -151,4 +150,6 @@ class ShadeModeInteractorEmptyImpl @Inject constructor() : ShadeModeInteractor {
    override val shadeMode: StateFlow<ShadeMode> = MutableStateFlow(ShadeMode.Single)

    override val isShadeLayoutWide: StateFlow<Boolean> = MutableStateFlow(false)

    override val isDualShadeSettingEnabled: Flow<Boolean> = flowOf(false)
}
+22 −14
Original line number Diff line number Diff line
@@ -46,6 +46,7 @@ import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.flatMapLatest
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.onStart
@@ -113,21 +114,28 @@ constructor(

    private fun hydrateShadeLayoutWidth() {
        applicationScope.launch {
            if (SceneContainerFlag.isEnabled) {
            // TODO(b/354926927): Move this decision to the shadeModeInteractor. It should expose
            //  isFullWidthShade instead of isShadeLayoutWide, and isDualShadeSettingEnabled()
            //  should become private again.
            val shadeModeInteractor = shadeModeInteractorProvider.get()
            shadeModeInteractor.isDualShadeSettingEnabled
                .flatMapLatest { isDualShadeEnabled ->
                    if (isDualShadeEnabled) {
                        shadeDisplayStateInteractor.isWideScreen
                    } else {
                        configurationRepository.onAnyConfigurationChange
                            // Force initial collection.
                            .onStart { emit(Unit) }
                            .map {
                            // The configuration for 'shouldUseSplitNotificationShade' dictates the
                            // width of the shade in split-shade mode.
                                // The configuration for 'shouldUseSplitNotificationShade' dictates
                                // the width of the shade in split-shade mode.
                                splitShadeStateController.shouldUseSplitNotificationShade(
                                    context.resources
                                )
                            }
                            .distinctUntilChanged()
                    }
                }
                .collect(shadeRepository::setShadeLayoutWide)
        }
    }