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

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

Merge changes I01bf143b,I00ca53cd,Iee34f197,I1087f07b,I25d8cdbd, ... into main

* changes:
  [sb] icon allow/block lists for HomeStatusBarInteractor
  [sb] s/Collapsed/Home/ for statusbar interactor
  [sb] operator name view model for home status bar
  [sb] add areaTint function to home status bar view model
  [mobile] add CarrierConfigInteractor to track default data subId carrier configs
  [mobile] split out CarrierConfigRepository interface for testing
  [sb] expose `defaultDataSubId` from MobileIconsInteractor
parents da304d82 bffd0c88
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -270,7 +270,7 @@ filegroup {
        "tests/src/**/systemui/stylus/StylusManagerTest.kt",
        "tests/src/**/systemui/recents/OverviewProxyServiceTest.kt",
        "tests/src/**/systemui/DisplayCutoutBaseViewTest.kt",
        "tests/src/**/systemui/statusbar/pipeline/mobile/data/repository/CarrierConfigRepositoryTest.kt",
        "tests/src/**/systemui/statusbar/pipeline/mobile/data/repository/CarrierConfigRepositoryImplTest.kt",
        "tests/src/**/systemui/statusbar/policy/BatteryControllerTest.java",
        "tests/src/**/systemui/statusbar/policy/SensitiveNotificationProtectionControllerTest.kt",
        "tests/src/**/systemui/statusbar/KeyboardShortcutsReceiverTest.java",
+14 −0
Original line number Diff line number Diff line
@@ -885,6 +885,20 @@ class MobileIconsInteractorTest : SysuiTestCase() {
            assertThat(latest).isFalse()
        }

    @Test
    fun defaultDataSubId_tracksRepo() =
        kosmos.runTest {
            val latest by collectLastValue(underTest.defaultDataSubId)

            connectionsRepository.defaultDataSubId.value = 1

            assertThat(latest).isEqualTo(1)

            connectionsRepository.defaultDataSubId.value = 2

            assertThat(latest).isEqualTo(2)
        }

    /**
     * Convenience method for creating a pair of subscriptions to test the filteredSubscriptions
     * flow.
+103 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 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.pipeline.shared.domain.interactor

import android.provider.Settings
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.collectLastValue
import com.android.systemui.kosmos.runTest
import com.android.systemui.res.R
import com.android.systemui.shared.settings.data.repository.fakeSecureSettingsRepository
import com.android.systemui.testKosmos
import com.google.common.truth.Truth.assertThat
import org.junit.Test
import org.junit.runner.RunWith

@SmallTest
@RunWith(AndroidJUnit4::class)
class HomeStatusBarIconBlockListInteractorTest : SysuiTestCase() {
    val kosmos = testKosmos()
    private val Kosmos.underTest by Kosmos.Fixture { kosmos.homeStatusBarIconBlockListInteractor }

    @Test
    fun iconBlockList_containsResources() =
        kosmos.runTest {
            // GIVEN a list of blocked icons
            overrideResource(
                R.array.config_collapsed_statusbar_icon_blocklist,
                arrayOf("test1", "test2"),
            )

            // GIVEN the vibrate is set to show (not blocked)
            fakeSecureSettingsRepository.setInt(Settings.Secure.STATUS_BAR_SHOW_VIBRATE_ICON, 1)

            val latest by collectLastValue(underTest.iconBlockList)

            // THEN the volume is not the blocklist
            assertThat(latest).containsExactly("test1", "test2")
        }

    @Test
    fun iconBlockList_checksVolumeSetting() =
        kosmos.runTest {
            // GIVEN a list of blocked icons
            overrideResource(
                R.array.config_collapsed_statusbar_icon_blocklist,
                arrayOf("test1", "test2"),
            )

            // GIVEN the vibrate icon is set to be hidden
            fakeSecureSettingsRepository.setInt(Settings.Secure.STATUS_BAR_SHOW_VIBRATE_ICON, 0)

            val latest by collectLastValue(underTest.iconBlockList)

            // THEN the volume is in the blocklist
            assertThat(latest).containsExactly("test1", "test2", "volume")
        }

    @Test
    fun iconBlockList_updatesWithVolumeSetting() =
        kosmos.runTest {
            // GIVEN a list of blocked icons
            overrideResource(
                R.array.config_collapsed_statusbar_icon_blocklist,
                arrayOf("test1", "test2"),
            )

            fakeSecureSettingsRepository.setInt(Settings.Secure.STATUS_BAR_SHOW_VIBRATE_ICON, 0)

            val latest by collectLastValue(underTest.iconBlockList)

            // Initially blocked
            assertThat(latest).containsExactly("test1", "test2", "volume")

            // Setting updates
            fakeSecureSettingsRepository.setInt(Settings.Secure.STATUS_BAR_SHOW_VIBRATE_ICON, 1)

            // Not blocked
            assertThat(latest).containsExactly("test1", "test2")

            // Setting updates again
            fakeSecureSettingsRepository.setInt(Settings.Secure.STATUS_BAR_SHOW_VIBRATE_ICON, 0)

            // ... blocked
            assertThat(latest).containsExactly("test1", "test2", "volume")
        }
}
+209 −0
Original line number Diff line number Diff line
@@ -21,31 +21,41 @@ import android.app.StatusBarManager.DISABLE_CLOCK
import android.app.StatusBarManager.DISABLE_NONE
import android.app.StatusBarManager.DISABLE_NOTIFICATION_ICONS
import android.app.StatusBarManager.DISABLE_SYSTEM_INFO
import android.telephony.CarrierConfigManager
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.systemui.SysuiTestCase
import com.android.systemui.coroutines.collectLastValue
import com.android.systemui.kosmos.collectLastValue
import com.android.systemui.kosmos.runTest
import com.android.systemui.kosmos.testScope
import com.android.systemui.statusbar.disableflags.data.repository.fakeDisableFlagsRepository
import com.android.systemui.statusbar.disableflags.shared.model.DisableFlagsModel
import com.android.systemui.statusbar.pipeline.airplane.data.repository.airplaneModeRepository
import com.android.systemui.statusbar.pipeline.airplane.data.repository.fake
import com.android.systemui.statusbar.pipeline.mobile.data.model.SystemUiCarrierConfig
import com.android.systemui.statusbar.pipeline.mobile.data.repository.carrierConfigRepository
import com.android.systemui.statusbar.pipeline.mobile.data.repository.configWithOverride
import com.android.systemui.statusbar.pipeline.mobile.data.repository.fake
import com.android.systemui.statusbar.pipeline.mobile.domain.interactor.fakeMobileIconsInteractor
import com.android.systemui.statusbar.pipeline.shared.connectivityConstants
import com.android.systemui.statusbar.pipeline.shared.fake
import com.android.systemui.testKosmos
import com.google.common.truth.Truth.assertThat
import kotlin.test.Test
import kotlinx.coroutines.test.runTest
import org.junit.runner.RunWith

@SmallTest
@RunWith(AndroidJUnit4::class)
class CollapsedStatusBarInteractorTest : SysuiTestCase() {
class HomeStatusBarInteractorTest : SysuiTestCase() {
    val kosmos = testKosmos()
    val testScope = kosmos.testScope
    val disableFlagsRepo = kosmos.fakeDisableFlagsRepository

    val underTest = kosmos.collapsedStatusBarInteractor
    val underTest = kosmos.homeStatusBarInteractor

    @Test
    fun visibilityViaDisableFlags_allDisabled() =
        testScope.runTest {
        kosmos.runTest {
            val latest by collectLastValue(underTest.visibilityViaDisableFlags)

            disableFlagsRepo.disableFlags.value =
@@ -62,7 +72,7 @@ class CollapsedStatusBarInteractorTest : SysuiTestCase() {

    @Test
    fun visibilityViaDisableFlags_allEnabled() =
        testScope.runTest {
        kosmos.runTest {
            val latest by collectLastValue(underTest.visibilityViaDisableFlags)

            disableFlagsRepo.disableFlags.value =
@@ -75,7 +85,7 @@ class CollapsedStatusBarInteractorTest : SysuiTestCase() {

    @Test
    fun visibilityViaDisableFlags_animateFalse() =
        testScope.runTest {
        kosmos.runTest {
            val latest by collectLastValue(underTest.visibilityViaDisableFlags)

            disableFlagsRepo.disableFlags.value =
@@ -86,7 +96,7 @@ class CollapsedStatusBarInteractorTest : SysuiTestCase() {

    @Test
    fun visibilityViaDisableFlags_animateTrue() =
        testScope.runTest {
        kosmos.runTest {
            val latest by collectLastValue(underTest.visibilityViaDisableFlags)

            disableFlagsRepo.disableFlags.value =
@@ -94,4 +104,106 @@ class CollapsedStatusBarInteractorTest : SysuiTestCase() {

            assertThat(latest!!.animate).isTrue()
        }

    @Test
    fun shouldShowOperatorName_trueIfCarrierConfigSaysSoAndDeviceHasData() =
        kosmos.runTest {
            // GIVEN default data subId is 1
            fakeMobileIconsInteractor.defaultDataSubId.value = 1
            // GIVEN Config is enabled
            carrierConfigRepository.fake.configsById[1] =
                SystemUiCarrierConfig(
                    1,
                    configWithOverride(
                        CarrierConfigManager.KEY_SHOW_OPERATOR_NAME_IN_STATUSBAR_BOOL,
                        true,
                    ),
                )

            // GIVEN airplane mode is off
            airplaneModeRepository.fake.isAirplaneMode.value = false

            // GIVEN hasDataCapabilities is true
            connectivityConstants.fake.hasDataCapabilities = true

            val latest by collectLastValue(underTest.shouldShowOperatorName)

            // THEN we should show the operator name
            assertThat(latest).isTrue()
        }

    @Test
    fun shouldShowOperatorName_falseNoDataCapabilities() =
        kosmos.runTest {
            // GIVEN default data subId is 1
            fakeMobileIconsInteractor.defaultDataSubId.value = 1
            // GIVEN Config is enabled
            carrierConfigRepository.fake.configsById[1] =
                SystemUiCarrierConfig(
                    1,
                    configWithOverride(
                        CarrierConfigManager.KEY_SHOW_OPERATOR_NAME_IN_STATUSBAR_BOOL,
                        true,
                    ),
                )

            // GIVEN airplane mode is off
            airplaneModeRepository.fake.isAirplaneMode.value = true

            // WHEN hasDataCapabilities is false
            connectivityConstants.fake.hasDataCapabilities = false

            val latest by collectLastValue(underTest.shouldShowOperatorName)

            // THEN we should not show the operator name
            assertThat(latest).isFalse()
        }

    @Test
    fun shouldShowOperatorName_falseWhenConfigIsOff() =
        kosmos.runTest {
            // GIVEN default data subId is 1
            fakeMobileIconsInteractor.defaultDataSubId.value = 1
            // GIVEN airplane mode is off
            airplaneModeRepository.fake.isAirplaneMode.value = false

            // WHEN Config is disabled
            carrierConfigRepository.fake.configsById[1] =
                SystemUiCarrierConfig(
                    1,
                    configWithOverride(
                        CarrierConfigManager.KEY_SHOW_OPERATOR_NAME_IN_STATUSBAR_BOOL,
                        false,
                    ),
                )

            val latest by collectLastValue(underTest.shouldShowOperatorName)

            // THEN we should not show the operator name
            assertThat(latest).isFalse()
        }

    @Test
    fun shouldShowOperatorName_falseIfAirplaneMode() =
        kosmos.runTest {
            // GIVEN default data subId is 1
            fakeMobileIconsInteractor.defaultDataSubId.value = 1
            // GIVEN Config is enabled
            carrierConfigRepository.fake.configsById[1] =
                SystemUiCarrierConfig(
                    1,
                    configWithOverride(
                        CarrierConfigManager.KEY_SHOW_OPERATOR_NAME_IN_STATUSBAR_BOOL,
                        true,
                    ),
                )

            // WHEN airplane mode is on
            airplaneModeRepository.fake.isAirplaneMode.value = true

            val latest by collectLastValue(underTest.shouldShowOperatorName)

            // THEN we should not show the operator name
            assertThat(latest).isFalse()
        }
}
+27 −2
Original line number Diff line number Diff line
/*
 * Copyright (C) 2023 The Android Open Source Project
 * Copyright (C) 2024 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.
@@ -16,7 +16,10 @@

package com.android.systemui.statusbar.pipeline.shared.ui.viewmodel

import android.graphics.Color
import android.graphics.Rect
import android.view.View
import com.android.systemui.plugins.DarkIconDispatcher
import com.android.systemui.statusbar.chips.ui.model.MultipleOngoingActivityChipsModel
import com.android.systemui.statusbar.chips.ui.model.OngoingActivityChipModel
import com.android.systemui.statusbar.events.shared.model.SystemEventAnimationState.Idle
@@ -24,7 +27,9 @@ import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.MutableStateFlow

class FakeHomeStatusBarViewModel : HomeStatusBarViewModel {
class FakeHomeStatusBarViewModel(
    override val operatorNameViewModel: StatusBarOperatorNameViewModel
) : HomeStatusBarViewModel {
    private val areNotificationLightsOut = MutableStateFlow(false)

    override val isTransitioningFromLockscreenToOccluded = MutableStateFlow(false)
@@ -38,6 +43,8 @@ class FakeHomeStatusBarViewModel : HomeStatusBarViewModel {

    override val isHomeStatusBarAllowedByScene = MutableStateFlow(false)

    override val shouldShowOperatorNameView = MutableStateFlow(false)

    override val isClockVisible =
        MutableStateFlow(
            HomeStatusBarViewModel.VisibilityModel(
@@ -65,5 +72,23 @@ class FakeHomeStatusBarViewModel : HomeStatusBarViewModel {
            )
        )

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

    override fun areNotificationsLightsOut(displayId: Int): Flow<Boolean> = areNotificationLightsOut

    val darkRegions = mutableListOf<Rect>()

    var darkIconTint = Color.BLACK
    var lightIconTint = Color.WHITE

    override fun areaTint(displayId: Int): Flow<StatusBarTintColor> =
        MutableStateFlow(
            StatusBarTintColor { viewBounds ->
                if (DarkIconDispatcher.isInAreas(darkRegions, viewBounds)) {
                    lightIconTint
                } else {
                    darkIconTint
                }
            }
        )
}
Loading