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

Commit 91f02d46 authored by Evan Laird's avatar Evan Laird
Browse files

[mobile] add CarrierConfigInteractor to track default data subId carrier configs

Test: CarrierConfigInteractorTest
Bug: 364360986
Flag: com.android.systemui.status_bar_root_modernization
Change-Id: I25d8cdbdc324f5356292c4c34a901eedb84fb2ce
parent e03d1c36
Loading
Loading
Loading
Loading
+43 −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.mobile.domain.interactor

import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.qualifiers.Application
import com.android.systemui.statusbar.pipeline.mobile.data.model.SystemUiCarrierConfig
import com.android.systemui.statusbar.pipeline.mobile.data.repository.CarrierConfigRepository
import javax.inject.Inject
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.stateIn

/** Business logic for [CarrierConfigRepository] */
@SysUISingleton
class CarrierConfigInteractor
@Inject
constructor(
    repo: CarrierConfigRepository,
    iconsInteractor: MobileIconsInteractor,
    @Application scope: CoroutineScope,
) {
    val defaultDataSubscriptionCarrierConfig: StateFlow<SystemUiCarrierConfig?> =
        iconsInteractor.defaultDataSubId
            .map { repo.getOrCreateConfigForSubId(it) }
            .stateIn(scope, SharingStarted.WhileSubscribed(), null)
}
+60 −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.mobile.domain.interactor

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.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.createDefaultTestConfig
import com.android.systemui.statusbar.pipeline.mobile.data.repository.fake
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 CarrierConfigInteractorTest : SysuiTestCase() {
    val kosmos = testKosmos()
    private val Kosmos.underTest by Kosmos.Fixture { kosmos.carrierConfigInteractor }

    @Test
    fun defaultDataSubscriptionCarrierConfig_tracksDefaultSubId() =
        kosmos.runTest {
            val carrierConfig1 = SystemUiCarrierConfig(1, createDefaultTestConfig())
            val carrierConfig2 = SystemUiCarrierConfig(2, createDefaultTestConfig())

            // Put some configs in so we can check by identity
            carrierConfigRepository.fake.configsById[1] = carrierConfig1
            carrierConfigRepository.fake.configsById[2] = carrierConfig2

            val latest by collectLastValue(underTest.defaultDataSubscriptionCarrierConfig)

            fakeMobileIconsInteractor.defaultDataSubId.value = 1

            assertThat(latest).isEqualTo(carrierConfig1)

            fakeMobileIconsInteractor.defaultDataSubId.value = 2

            assertThat(latest).isEqualTo(carrierConfig2)
        }
}
+3 −0
Original line number Diff line number Diff line
@@ -28,6 +28,9 @@ class FakeCarrierConfigRepository : CarrierConfigRepository {
        configsById.getOrPut(subId) { SystemUiCarrierConfig(subId, createDefaultTestConfig()) }
}

val CarrierConfigRepository.fake
    get() = this as FakeCarrierConfigRepository

fun createDefaultTestConfig() =
    PersistableBundle().also {
        it.putBoolean(
+30 −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.mobile.domain.interactor

import com.android.systemui.kosmos.Kosmos
import com.android.systemui.kosmos.applicationCoroutineScope
import com.android.systemui.statusbar.pipeline.mobile.data.repository.carrierConfigRepository

val Kosmos.carrierConfigInteractor by
    Kosmos.Fixture {
        CarrierConfigInteractor(
            carrierConfigRepository,
            mobileIconsInteractor,
            applicationCoroutineScope,
        )
    }