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

Commit f120014b authored by Caitlin Shkuratov's avatar Caitlin Shkuratov Committed by Android (Google) Code Review
Browse files

Merge changes from topic "caitlinshk-reset-chip-width" into main

* changes:
  [SB] Reset chip width calculations on rotation or unfold.
  [SB] Add multi-display store for StatusBarContentInsetsViewModel.
  [SB] Add StatusBarContentInsetsViewModel.
parents afe1f74c 33db676d
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -45,7 +45,7 @@ import com.google.common.truth.Truth.assertWithMessage
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.ArgumentMatchers.any
import org.mockito.kotlin.any
import org.mockito.kotlin.doReturn
import org.mockito.kotlin.mock
import org.mockito.kotlin.whenever
+77 −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.statusbar.layout.ui.viewmodel

import android.content.res.Configuration
import android.platform.test.annotations.EnableFlags
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.systemui.SysuiTestCase
import com.android.systemui.kosmos.Kosmos
import com.android.systemui.kosmos.collectValues
import com.android.systemui.kosmos.runTest
import com.android.systemui.kosmos.useUnconfinedTestDispatcher
import com.android.systemui.statusbar.core.StatusBarConnectedDisplays
import com.android.systemui.statusbar.layout.statusBarContentInsetsProvider
import com.android.systemui.statusbar.policy.configurationController
import com.android.systemui.statusbar.policy.fake
import com.android.systemui.testKosmos
import com.google.common.truth.Truth.assertThat
import org.junit.Test
import org.junit.runner.RunWith

@RunWith(AndroidJUnit4::class)
@SmallTest
@EnableFlags(StatusBarConnectedDisplays.FLAG_NAME)
class StatusBarContentInsetsViewModelTest : SysuiTestCase() {
    private val kosmos = testKosmos().useUnconfinedTestDispatcher()
    private val configuration = Configuration()

    private val Kosmos.underTest by Kosmos.Fixture { statusBarContentInsetsViewModel }

    @Test
    fun contentArea_onMaxBoundsChanged_emitsNewValue() =
        kosmos.runTest {
            statusBarContentInsetsProvider.start()

            val values by collectValues(underTest.contentArea)

            // WHEN the content area changes
            configurationController.fake.notifyLayoutDirectionChanged(isRtl = true)
            configurationController.fake.notifyDensityOrFontScaleChanged()

            // THEN the flow emits the new bounds
            assertThat(values[0]).isNotEqualTo(values[1])
        }

    @Test
    fun contentArea_onDensityOrFontScaleChanged_emitsLastBounds() =
        kosmos.runTest {
            configuration.densityDpi = 12
            statusBarContentInsetsProvider.start()

            val values by collectValues(underTest.contentArea)

            // WHEN a change happens but it doesn't affect content area
            configuration.densityDpi = 20
            configurationController.onConfigurationChanged(configuration)
            configurationController.fake.notifyDensityOrFontScaleChanged()

            // THEN it still has the last bounds
            assertThat(values).hasSize(1)
        }
}
+4 −3
Original line number Diff line number Diff line
@@ -53,7 +53,7 @@ import com.android.systemui.statusbar.CommandQueue
import com.android.systemui.statusbar.StatusBarState
import com.android.systemui.statusbar.data.repository.StatusBarContentInsetsProviderStore
import com.android.systemui.statusbar.events.SystemStatusAnimationScheduler
import com.android.systemui.statusbar.layout.statusBarContentInsetsProvider
import com.android.systemui.statusbar.layout.mockStatusBarContentInsetsProvider
import com.android.systemui.statusbar.phone.ui.StatusBarIconController
import com.android.systemui.statusbar.phone.ui.TintedIconManager
import com.android.systemui.statusbar.policy.BatteryController
@@ -153,7 +153,8 @@ class KeyguardStatusBarViewControllerTest : SysuiTestCase() {
        shadeViewStateProvider = TestShadeViewStateProvider()

        Mockito.`when`(
                kosmos.statusBarContentInsetsProvider.getStatusBarContentInsetsForCurrentRotation()
                kosmos.mockStatusBarContentInsetsProvider
                    .getStatusBarContentInsetsForCurrentRotation()
            )
            .thenReturn(Insets.of(0, 0, 0, 0))

@@ -162,7 +163,7 @@ class KeyguardStatusBarViewControllerTest : SysuiTestCase() {
        Mockito.`when`(iconManagerFactory.create(ArgumentMatchers.any(), ArgumentMatchers.any()))
            .thenReturn(iconManager)
        Mockito.`when`(statusBarContentInsetsProviderStore.defaultDisplay)
            .thenReturn(kosmos.statusBarContentInsetsProvider)
            .thenReturn(kosmos.mockStatusBarContentInsetsProvider)
        allowTestableLooperAsMainThread()
        looper.runWithLooper {
            keyguardStatusBarView =
+2 −0
Original line number Diff line number Diff line
@@ -77,6 +77,8 @@ class FakeHomeStatusBarViewModel(

    override val iconBlockList: MutableStateFlow<List<String>> = MutableStateFlow(listOf())

    override val contentArea = MutableStateFlow(Rect(0, 0, 1, 1))

    val darkRegions = mutableListOf<Rect>()

    var darkIconTint = Color.BLACK
+7 −0
Original line number Diff line number Diff line
@@ -26,10 +26,13 @@ import android.content.testableContext
import android.graphics.Rect
import android.platform.test.annotations.DisableFlags
import android.platform.test.annotations.EnableFlags
import android.view.Display.DEFAULT_DISPLAY
import android.view.View
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.systemui.SysuiTestCase
import com.android.systemui.display.data.repository.displayRepository
import com.android.systemui.display.data.repository.fake
import com.android.systemui.flags.DisableSceneContainer
import com.android.systemui.flags.EnableSceneContainer
import com.android.systemui.keyguard.data.repository.fakeKeyguardTransitionRepository
@@ -85,6 +88,7 @@ import com.google.common.truth.Truth.assertThat
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.emptyFlow
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.test.UnconfinedTestDispatcher
import org.junit.Before
import org.junit.Test
@@ -104,6 +108,9 @@ class HomeStatusBarViewModelImplTest : SysuiTestCase() {
        setUpPackageManagerForMediaProjection(kosmos)
    }

    @Before
    fun addDisplays() = runBlocking { kosmos.displayRepository.fake.addDisplay(DEFAULT_DISPLAY) }

    @Test
    fun isTransitioningFromLockscreenToOccluded_started_isTrue() =
        kosmos.runTest {
Loading