1 /*
2  * Copyright (C) 2022 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.systemui.statusbar.pipeline.mobile.data.repository
18 
19 import android.telephony.TelephonyManager.UNKNOWN_CARRIER_ID
20 import com.android.systemui.log.table.TableLogBuffer
21 import com.android.systemui.statusbar.pipeline.mobile.data.model.DataConnectionState
22 import com.android.systemui.statusbar.pipeline.mobile.data.model.NetworkNameModel
23 import com.android.systemui.statusbar.pipeline.mobile.data.model.ResolvedNetworkType
24 import com.android.systemui.statusbar.pipeline.mobile.data.repository.MobileConnectionRepository.Companion.DEFAULT_NUM_LEVELS
25 import com.android.systemui.statusbar.pipeline.shared.data.model.DataActivityModel
26 import kotlinx.coroutines.flow.MutableStateFlow
27 
28 // TODO(b/261632894): remove this in favor of the real impl or DemoMobileConnectionRepository
29 class FakeMobileConnectionRepository(
30     override val subId: Int,
31     override val tableLogBuffer: TableLogBuffer,
32 ) : MobileConnectionRepository {
33     override val carrierId = MutableStateFlow(UNKNOWN_CARRIER_ID)
34     override val inflateSignalStrength: MutableStateFlow<Boolean> = MutableStateFlow(false)
35     override val allowNetworkSliceIndicator: MutableStateFlow<Boolean> = MutableStateFlow(true)
36     override val isEmergencyOnly = MutableStateFlow(false)
37     override val isRoaming = MutableStateFlow(false)
38     override val operatorAlphaShort: MutableStateFlow<String?> = MutableStateFlow(null)
39     override val isInService = MutableStateFlow(false)
40     override val isNonTerrestrial = MutableStateFlow(false)
41     override val isGsm = MutableStateFlow(false)
42     override val cdmaLevel = MutableStateFlow(0)
43     override val primaryLevel = MutableStateFlow(0)
44     override val dataConnectionState = MutableStateFlow(DataConnectionState.Disconnected)
45     override val dataActivityDirection =
46         MutableStateFlow(DataActivityModel(hasActivityIn = false, hasActivityOut = false))
47     override val carrierNetworkChangeActive = MutableStateFlow(false)
48     override val resolvedNetworkType: MutableStateFlow<ResolvedNetworkType> =
49         MutableStateFlow(ResolvedNetworkType.UnknownNetworkType)
50 
51     override val numberOfLevels = MutableStateFlow(DEFAULT_NUM_LEVELS)
52 
53     private val _dataEnabled = MutableStateFlow(true)
54     override val dataEnabled = _dataEnabled
55 
56     override val cdmaRoaming = MutableStateFlow(false)
57 
58     override val networkName: MutableStateFlow<NetworkNameModel> =
59         MutableStateFlow(NetworkNameModel.Default(DEFAULT_NETWORK_NAME))
60 
61     override val carrierName: MutableStateFlow<NetworkNameModel> =
62         MutableStateFlow(NetworkNameModel.Default(DEFAULT_NETWORK_NAME))
63 
64     override val isAllowedDuringAirplaneMode = MutableStateFlow(false)
65 
66     override val hasPrioritizedNetworkCapabilities = MutableStateFlow(false)
67 
68     private var isInEcmMode: Boolean = false
69 
isInEcmModenull70     override suspend fun isInEcmMode(): Boolean = isInEcmMode
71 
72     fun setDataEnabled(enabled: Boolean) {
73         _dataEnabled.value = enabled
74     }
75 
76     /**
77      * Set [primaryLevel] and [cdmaLevel]. Convenient when you don't care about the connection type
78      */
setAllLevelsnull79     fun setAllLevels(level: Int) {
80         cdmaLevel.value = level
81         primaryLevel.value = level
82     }
83 
84     /**
85      * Set both [isRoaming] and [cdmaRoaming] properties, in the event that you don't care about the
86      * connection type
87      */
setAllRoamingnull88     fun setAllRoaming(roaming: Boolean) {
89         isRoaming.value = roaming
90         cdmaRoaming.value = roaming
91     }
92 
93     /** Set the correct [resolvedNetworkType] for the given group via its lookup key */
setNetworkTypeKeynull94     fun setNetworkTypeKey(key: String) {
95         resolvedNetworkType.value = ResolvedNetworkType.DefaultNetworkType(key)
96     }
97 
setIsInEcmModenull98     fun setIsInEcmMode(isInEcmMode: Boolean) {
99         this.isInEcmMode = isInEcmMode
100     }
101 
102     companion object {
103         const val DEFAULT_NETWORK_NAME = "default name"
104     }
105 }
106