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

Commit 5dc1f3a0 authored by Evan Laird's avatar Evan Laird Committed by Android (Google) Code Review
Browse files

Merge changes Ib8251e7b,I22e56b3b,I1f6301f9 into main

* changes:
  [sb] s/Collapsed/Home/ on the view binder and model
  [sb] Rename *Fragment* dagger components to Home*
  [sb] Basic compose replacement of the fragment
parents bbc7ae07 13f7e97f
Loading
Loading
Loading
Loading
+22 −4
Original line number Diff line number Diff line
@@ -20,12 +20,15 @@ import android.app.FragmentManager
import android.app.FragmentTransaction
import android.platform.test.annotations.DisableFlags
import android.platform.test.annotations.EnableFlags
import android.view.ViewGroup
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.fragments.FragmentHostManager
import com.android.systemui.statusbar.phone.fragment.CollapsedStatusBarFragment
import com.android.systemui.statusbar.phone.fragment.dagger.HomeStatusBarComponent
import com.android.systemui.statusbar.pipeline.shared.ui.composable.StatusBarRootFactory
import com.android.systemui.statusbar.window.StatusBarWindowController
import com.android.systemui.statusbar.window.StatusBarWindowControllerStore
import com.google.common.truth.Truth.assertThat
@@ -35,6 +38,8 @@ import org.junit.Before
import org.junit.runner.RunWith
import org.mockito.Mockito.mock
import org.mockito.kotlin.any
import org.mockito.kotlin.never
import org.mockito.kotlin.verify
import org.mockito.kotlin.whenever

@SmallTest
@@ -42,27 +47,31 @@ import org.mockito.kotlin.whenever
class StatusBarInitializerTest : SysuiTestCase() {
    private val windowController = mock(StatusBarWindowController::class.java)
    private val windowControllerStore = mock(StatusBarWindowControllerStore::class.java)
    private val transaction = mock(FragmentTransaction::class.java)
    private val fragmentManager = mock(FragmentManager::class.java)
    private val fragmentHostManager = mock(FragmentHostManager::class.java)
    private val backgroundView = mock(ViewGroup::class.java)

    @Before
    fun setup() {
        // TODO(b/364360986) this will go away once the fragment is deprecated. Hence, there is no
        // need right now for moving this to kosmos
        val transaction = mock(FragmentTransaction::class.java)
        val fragmentManager = mock(FragmentManager::class.java)
        val fragmentHostManager = mock(FragmentHostManager::class.java)
        whenever(fragmentHostManager.addTagListener(any(), any())).thenReturn(fragmentHostManager)
        whenever(fragmentHostManager.fragmentManager).thenReturn(fragmentManager)
        whenever(fragmentManager.beginTransaction()).thenReturn(transaction)
        whenever(transaction.replace(any(), any(), any())).thenReturn(transaction)
        whenever(windowControllerStore.defaultDisplay).thenReturn(windowController)
        whenever(windowController.fragmentHostManager).thenReturn(fragmentHostManager)
        whenever(windowController.backgroundView).thenReturn(backgroundView)
    }

    val underTest =
        StatusBarInitializerImpl(
            statusBarWindowController = windowController,
            collapsedStatusBarFragmentProvider = { mock(CollapsedStatusBarFragment::class.java) },
            statusBarRootFactory = mock(StatusBarRootFactory::class.java),
            componentFactory = mock(HomeStatusBarComponent.Factory::class.java),
            creationListeners = setOf(),
            statusBarWindowController = windowController,
        )

    @Test
@@ -78,6 +87,15 @@ class StatusBarInitializerTest : SysuiTestCase() {
        assertThrows(IllegalStateException::class.java) { underTest.initializeStatusBar() }
    }

    @Test
    @EnableFlags(Flags.FLAG_STATUS_BAR_SIMPLE_FRAGMENT)
    fun simpleFragment_flagEnabled_doesNotCreateFragment() {
        underTest.start()

        verify(fragmentManager, never()).beginTransaction()
        verify(transaction, never()).replace(any(), any(), any())
    }

    @Test
    @DisableFlags(Flags.FLAG_STATUS_BAR_SIMPLE_FRAGMENT)
    fun flagOff_doesNotInitializeViaCoreStartable() {
+17 −35
Original line number Diff line number Diff line
@@ -36,7 +36,7 @@ import com.android.systemui.statusbar.phone.BoundsPair
import com.android.systemui.statusbar.phone.LetterboxAppearance
import com.android.systemui.statusbar.phone.LetterboxAppearanceCalculator
import com.android.systemui.statusbar.phone.StatusBarBoundsProvider
import com.android.systemui.statusbar.phone.fragment.dagger.StatusBarFragmentComponent
import com.android.systemui.statusbar.phone.fragment.dagger.HomeStatusBarComponent
import com.android.systemui.statusbar.phone.ongoingcall.data.repository.ongoingCallRepository
import com.android.systemui.statusbar.phone.ongoingcall.shared.model.OngoingCallModel
import com.android.systemui.statusbar.phone.ongoingcall.shared.model.inCallModel
@@ -62,8 +62,8 @@ class StatusBarModeRepositoryImplTest : SysuiTestCase() {
    private val commandQueue = mock<CommandQueue>()
    private val letterboxAppearanceCalculator = mock<LetterboxAppearanceCalculator>()
    private val statusBarBoundsProvider = mock<StatusBarBoundsProvider>()
    private val statusBarFragmentComponent =
        mock<StatusBarFragmentComponent>().also {
    private val homeStatusBarComponent =
        mock<HomeStatusBarComponent>().also {
            whenever(it.boundsProvider).thenReturn(statusBarBoundsProvider)
        }
    private val ongoingCallRepository = kosmos.ongoingCallRepository
@@ -78,7 +78,7 @@ class StatusBarModeRepositoryImplTest : SysuiTestCase() {
            )
            .apply {
                this.start()
                this.onStatusBarViewInitialized(statusBarFragmentComponent)
                this.onStatusBarViewInitialized(homeStatusBarComponent)
            }

    private val commandQueueCallback: CommandQueue.Callbacks
@@ -235,9 +235,7 @@ class StatusBarModeRepositoryImplTest : SysuiTestCase() {
        testScope.runTest {
            val latest by collectLastValue(underTest.isInFullscreenMode)

            onSystemBarAttributesChanged(
                requestedVisibleTypes = WindowInsets.Type.statusBars(),
            )
            onSystemBarAttributesChanged(requestedVisibleTypes = WindowInsets.Type.statusBars())

            assertThat(latest).isFalse()
        }
@@ -247,9 +245,7 @@ class StatusBarModeRepositoryImplTest : SysuiTestCase() {
        testScope.runTest {
            val latest by collectLastValue(underTest.isInFullscreenMode)

            onSystemBarAttributesChanged(
                requestedVisibleTypes = WindowInsets.Type.navigationBars(),
            )
            onSystemBarAttributesChanged(requestedVisibleTypes = WindowInsets.Type.navigationBars())

            assertThat(latest).isTrue()
        }
@@ -259,9 +255,7 @@ class StatusBarModeRepositoryImplTest : SysuiTestCase() {
        testScope.runTest {
            val latest by collectLastValue(underTest.isInFullscreenMode)

            onSystemBarAttributesChanged(
                requestedVisibleTypes = WindowInsets.Type.navigationBars(),
            )
            onSystemBarAttributesChanged(requestedVisibleTypes = WindowInsets.Type.navigationBars())
            assertThat(latest).isTrue()

            onSystemBarAttributesChanged(
@@ -347,7 +341,7 @@ class StatusBarModeRepositoryImplTest : SysuiTestCase() {
            val startingLetterboxAppearance =
                LetterboxAppearance(
                    APPEARANCE_LIGHT_STATUS_BARS,
                    listOf(AppearanceRegion(APPEARANCE_LIGHT_STATUS_BARS, Rect(0, 0, 1, 1)))
                    listOf(AppearanceRegion(APPEARANCE_LIGHT_STATUS_BARS, Rect(0, 0, 1, 1))),
                )
            whenever(
                    letterboxAppearanceCalculator.getLetterboxAppearance(
@@ -371,7 +365,7 @@ class StatusBarModeRepositoryImplTest : SysuiTestCase() {
            val newLetterboxAppearance =
                LetterboxAppearance(
                    APPEARANCE_LOW_PROFILE_BARS,
                    listOf(AppearanceRegion(APPEARANCE_LOW_PROFILE_BARS, Rect(10, 20, 30, 40)))
                    listOf(AppearanceRegion(APPEARANCE_LOW_PROFILE_BARS, Rect(10, 20, 30, 40))),
                )
            whenever(
                    letterboxAppearanceCalculator.getLetterboxAppearance(
@@ -398,9 +392,7 @@ class StatusBarModeRepositoryImplTest : SysuiTestCase() {
            val latest by collectLastValue(underTest.statusBarAppearance)

            ongoingCallRepository.setOngoingCallState(inCallModel(startTimeMs = 34))
            onSystemBarAttributesChanged(
                requestedVisibleTypes = WindowInsets.Type.navigationBars(),
            )
            onSystemBarAttributesChanged(requestedVisibleTypes = WindowInsets.Type.navigationBars())

            assertThat(latest!!.mode).isEqualTo(StatusBarMode.SEMI_TRANSPARENT)
        }
@@ -438,9 +430,7 @@ class StatusBarModeRepositoryImplTest : SysuiTestCase() {
    fun statusBarMode_transientShown_semiTransparent() =
        testScope.runTest {
            val latest by collectLastValue(underTest.statusBarAppearance)
            onSystemBarAttributesChanged(
                appearance = APPEARANCE_OPAQUE_STATUS_BARS,
            )
            onSystemBarAttributesChanged(appearance = APPEARANCE_OPAQUE_STATUS_BARS)

            underTest.showTransient()

@@ -453,7 +443,7 @@ class StatusBarModeRepositoryImplTest : SysuiTestCase() {
            val latest by collectLastValue(underTest.statusBarAppearance)

            onSystemBarAttributesChanged(
                appearance = APPEARANCE_LOW_PROFILE_BARS or APPEARANCE_OPAQUE_STATUS_BARS,
                appearance = APPEARANCE_LOW_PROFILE_BARS or APPEARANCE_OPAQUE_STATUS_BARS
            )

            assertThat(latest!!.mode).isEqualTo(StatusBarMode.LIGHTS_OUT)
@@ -464,9 +454,7 @@ class StatusBarModeRepositoryImplTest : SysuiTestCase() {
        testScope.runTest {
            val latest by collectLastValue(underTest.statusBarAppearance)

            onSystemBarAttributesChanged(
                appearance = APPEARANCE_LOW_PROFILE_BARS,
            )
            onSystemBarAttributesChanged(appearance = APPEARANCE_LOW_PROFILE_BARS)

            assertThat(latest!!.mode).isEqualTo(StatusBarMode.LIGHTS_OUT_TRANSPARENT)
        }
@@ -476,9 +464,7 @@ class StatusBarModeRepositoryImplTest : SysuiTestCase() {
        testScope.runTest {
            val latest by collectLastValue(underTest.statusBarAppearance)

            onSystemBarAttributesChanged(
                appearance = APPEARANCE_OPAQUE_STATUS_BARS,
            )
            onSystemBarAttributesChanged(appearance = APPEARANCE_OPAQUE_STATUS_BARS)

            assertThat(latest!!.mode).isEqualTo(StatusBarMode.OPAQUE)
        }
@@ -488,9 +474,7 @@ class StatusBarModeRepositoryImplTest : SysuiTestCase() {
        testScope.runTest {
            val latest by collectLastValue(underTest.statusBarAppearance)

            onSystemBarAttributesChanged(
                appearance = APPEARANCE_SEMI_TRANSPARENT_STATUS_BARS,
            )
            onSystemBarAttributesChanged(appearance = APPEARANCE_SEMI_TRANSPARENT_STATUS_BARS)

            assertThat(latest!!.mode).isEqualTo(StatusBarMode.SEMI_TRANSPARENT)
        }
@@ -500,9 +484,7 @@ class StatusBarModeRepositoryImplTest : SysuiTestCase() {
        testScope.runTest {
            val latest by collectLastValue(underTest.statusBarAppearance)

            onSystemBarAttributesChanged(
                appearance = 0,
            )
            onSystemBarAttributesChanged(appearance = 0)

            assertThat(latest!!.mode).isEqualTo(StatusBarMode.TRANSPARENT)
        }
@@ -540,7 +522,7 @@ class StatusBarModeRepositoryImplTest : SysuiTestCase() {
                LetterboxDetails(
                    /* letterboxInnerBounds= */ Rect(0, 0, 10, 10),
                    /* letterboxFullBounds= */ Rect(0, 0, 20, 20),
                    /* appAppearance= */ 0
                    /* appAppearance= */ 0,
                )
            )
        private val REGIONS_FROM_LETTERBOX_CALCULATOR =
+4 −4
Original line number Diff line number Diff line
@@ -17,21 +17,21 @@
package com.android.systemui.statusbar.pipeline.shared.ui.viewmodel

import android.view.View
import com.android.systemui.statusbar.pipeline.shared.ui.binder.CollapsedStatusBarViewBinder
import com.android.systemui.statusbar.pipeline.shared.ui.binder.HomeStatusBarViewBinder
import com.android.systemui.statusbar.pipeline.shared.ui.binder.StatusBarVisibilityChangeListener

/**
 * A fake view binder that can be used from Java tests.
 *
 * Since Java tests can't run tests within test scopes, we need to bypass the flows from
 * [CollapsedStatusBarViewModel] and just trigger the listener directly.
 * [HomeStatusBarViewModel] and just trigger the listener directly.
 */
class FakeCollapsedStatusBarViewBinder : CollapsedStatusBarViewBinder {
class FakeHomeStatusBarViewBinder : HomeStatusBarViewBinder {
    var listener: StatusBarVisibilityChangeListener? = null

    override fun bind(
        view: View,
        viewModel: CollapsedStatusBarViewModel,
        viewModel: HomeStatusBarViewModel,
        listener: StatusBarVisibilityChangeListener,
    ) {
        this.listener = listener
+4 −4
Original line number Diff line number Diff line
@@ -23,7 +23,7 @@ import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.MutableStateFlow

class FakeCollapsedStatusBarViewModel : CollapsedStatusBarViewModel {
class FakeHomeStatusBarViewModel : HomeStatusBarViewModel {
    private val areNotificationLightsOut = MutableStateFlow(false)

    override val isTransitioningFromLockscreenToOccluded = MutableStateFlow(false)
@@ -39,7 +39,7 @@ class FakeCollapsedStatusBarViewModel : CollapsedStatusBarViewModel {

    override val isClockVisible =
        MutableStateFlow(
            CollapsedStatusBarViewModel.VisibilityModel(
            HomeStatusBarViewModel.VisibilityModel(
                visibility = View.GONE,
                shouldAnimateChange = false,
            )
@@ -47,7 +47,7 @@ class FakeCollapsedStatusBarViewModel : CollapsedStatusBarViewModel {

    override val isNotificationIconContainerVisible =
        MutableStateFlow(
            CollapsedStatusBarViewModel.VisibilityModel(
            HomeStatusBarViewModel.VisibilityModel(
                visibility = View.GONE,
                shouldAnimateChange = false,
            )
@@ -55,7 +55,7 @@ class FakeCollapsedStatusBarViewModel : CollapsedStatusBarViewModel {

    override val isSystemInfoVisible =
        MutableStateFlow(
            CollapsedStatusBarViewModel.VisibilityModel(
            HomeStatusBarViewModel.VisibilityModel(
                visibility = View.GONE,
                shouldAnimateChange = false,
            )
+3 −3
Original line number Diff line number Diff line
@@ -75,7 +75,7 @@ import org.junit.runner.RunWith
@SmallTest
@OptIn(ExperimentalCoroutinesApi::class)
@RunWith(AndroidJUnit4::class)
class CollapsedStatusBarViewModelImplTest : SysuiTestCase() {
class HomeStatusBarViewModelImplTest : SysuiTestCase() {
    private val kosmos =
        Kosmos().also {
            it.testCase = this
@@ -89,13 +89,13 @@ class CollapsedStatusBarViewModelImplTest : SysuiTestCase() {
    private val keyguardTransitionRepository = kosmos.fakeKeyguardTransitionRepository
    private val disableFlagsRepository = kosmos.fakeDisableFlagsRepository

    private lateinit var underTest: CollapsedStatusBarViewModel
    private lateinit var underTest: HomeStatusBarViewModel

    @Before
    fun setUp() {
        setUpPackageManagerForMediaProjection(kosmos)
        // Initialize here because some flags are checked when this class is constructed
        underTest = kosmos.collapsedStatusBarViewModel
        underTest = kosmos.homeStatusBarViewModel
    }

    @Test
Loading