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 satelliteLevel = MutableStateFlow(0)
45     override val dataConnectionState = MutableStateFlow(DataConnectionState.Disconnected)
46     override val dataActivityDirection =
47         MutableStateFlow(DataActivityModel(hasActivityIn = false, hasActivityOut = false))
48     override val carrierNetworkChangeActive = MutableStateFlow(false)
49     override val resolvedNetworkType: MutableStateFlow<ResolvedNetworkType> =
50         MutableStateFlow(ResolvedNetworkType.UnknownNetworkType)
51 
52     override val numberOfLevels = MutableStateFlow(DEFAULT_NUM_LEVELS)
53 
54     private val _dataEnabled = MutableStateFlow(true)
55     override val dataEnabled = _dataEnabled
56 
57     override val cdmaRoaming = MutableStateFlow(false)
58 
59     override val networkName: MutableStateFlow<NetworkNameModel> =
60         MutableStateFlow(NetworkNameModel.Default(DEFAULT_NETWORK_NAME))
61 
62     override val carrierName: MutableStateFlow<NetworkNameModel> =
63         MutableStateFlow(NetworkNameModel.Default(DEFAULT_NETWORK_NAME))
64 
65     override val isAllowedDuringAirplaneMode = MutableStateFlow(false)
66 
67     override val hasPrioritizedNetworkCapabilities = MutableStateFlow(false)
68 
69     private var isInEcmMode: Boolean = false
70 
isInEcmModenull71     override suspend fun isInEcmMode(): Boolean = isInEcmMode
72 
73     fun setDataEnabled(enabled: Boolean) {
74         _dataEnabled.value = enabled
75     }
76 
77     /**
78      * Set [primaryLevel] and [cdmaLevel]. Convenient when you don't care about the connection type
79      */
setAllLevelsnull80     fun setAllLevels(level: Int) {
81         cdmaLevel.value = level
82         primaryLevel.value = level
83     }
84 
85     /**
86      * Set both [isRoaming] and [cdmaRoaming] properties, in the event that you don't care about the
87      * connection type
88      */
setAllRoamingnull89     fun setAllRoaming(roaming: Boolean) {
90         isRoaming.value = roaming
91         cdmaRoaming.value = roaming
92     }
93 
94     /** Set the correct [resolvedNetworkType] for the given group via its lookup key */
setNetworkTypeKeynull95     fun setNetworkTypeKey(key: String) {
96         resolvedNetworkType.value = ResolvedNetworkType.DefaultNetworkType(key)
97     }
98 
setIsInEcmModenull99     fun setIsInEcmMode(isInEcmMode: Boolean) {
100         this.isInEcmMode = isInEcmMode
101     }
102 
103     companion object {
104         const val DEFAULT_NETWORK_NAME = "default name"
105     }
106 }
107