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

Commit 651a424a authored by Evan Laird's avatar Evan Laird
Browse files

[Sb refactor] Ensure config is fetched on flow start

In the case where the `CARRIER_CONFIG_CHANGED` broadcast is sent out
before the default data sub RAT config is read, it will read the
system-defined default carrier config instead of the appropriate one for
the current default data sub.

This change is simple: make sure to always fetch the system current
carrier config when the flow starts.

Bug: 280390475
Test: MobileConnectionsRepositoryTest
Change-Id: I868a840ee8465b0313bc85e5c35c0d40ca9d509a
parent b98c2ee5
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -233,6 +233,7 @@ constructor(

    override val defaultDataSubRatConfig: StateFlow<Config> =
        merge(defaultDataSubIdChangeEvent, carrierConfigChangedEvent)
            .onStart { emit(Unit) }
            .mapLatest { Config.readConfig(context) }
            .distinctUntilChanged()
            .onEach { logger.logDefaultDataSubRatConfig(it) }
+27 −0
Original line number Diff line number Diff line
@@ -1111,6 +1111,33 @@ class MobileConnectionsRepositoryTest : SysuiTestCase() {
            assertThat(latest!!.showAtLeast3G).isTrue()
        }

    @Test
    fun carrierConfig_initialValueIsFetched() =
        testScope.runTest {

            // Value starts out false
            assertThat(underTest.defaultDataSubRatConfig.value.showAtLeast3G).isFalse()

            overrideResource(R.bool.config_showMin3G, true)
            val configFromContext = MobileMappings.Config.readConfig(context)
            assertThat(configFromContext.showAtLeast3G).isTrue()

            // WHEN the change event is fired
            fakeBroadcastDispatcher.registeredReceivers.forEach { receiver ->
                receiver.onReceive(
                    context,
                    Intent(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED)
                )
            }

            // WHEN collection starts AFTER the broadcast is sent out
            val latest by collectLastValue(underTest.defaultDataSubRatConfig)

            // THEN the config has the updated value
            assertThat(latest!!.areEqual(configFromContext)).isTrue()
            assertThat(latest!!.showAtLeast3G).isTrue()
        }

    @Test
    fun activeDataChange_inSameGroup_emitsUnit() =
        testScope.runTest {