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 isEmergencyOnly = MutableStateFlow(false)
35     override val isRoaming = MutableStateFlow(false)
36     override val operatorAlphaShort: MutableStateFlow<String?> = MutableStateFlow(null)
37     override val isInService = MutableStateFlow(false)
38     override val isGsm = MutableStateFlow(false)
39     override val cdmaLevel = MutableStateFlow(0)
40     override val primaryLevel = MutableStateFlow(0)
41     override val dataConnectionState = MutableStateFlow(DataConnectionState.Disconnected)
42     override val dataActivityDirection =
43         MutableStateFlow(DataActivityModel(hasActivityIn = false, hasActivityOut = false))
44     override val carrierNetworkChangeActive = MutableStateFlow(false)
45     override val resolvedNetworkType: MutableStateFlow<ResolvedNetworkType> =
46         MutableStateFlow(ResolvedNetworkType.UnknownNetworkType)
47 
48     override val numberOfLevels = MutableStateFlow(DEFAULT_NUM_LEVELS)
49 
50     private val _dataEnabled = MutableStateFlow(true)
51     override val dataEnabled = _dataEnabled
52 
53     override val cdmaRoaming = MutableStateFlow(false)
54 
55     override val networkName: MutableStateFlow<NetworkNameModel> =
56         MutableStateFlow(NetworkNameModel.Default(DEFAULT_NETWORK_NAME))
57 
58     override val carrierName: MutableStateFlow<NetworkNameModel> =
59         MutableStateFlow(NetworkNameModel.Default(DEFAULT_NETWORK_NAME))
60 
61     override val isAllowedDuringAirplaneMode = MutableStateFlow(false)
62 
63     fun setDataEnabled(enabled: Boolean) {
64         _dataEnabled.value = enabled
65     }
66 
67     /**
68      * Set [primaryLevel] and [cdmaLevel]. Convenient when you don't care about the connection type
69      */
70     fun setAllLevels(level: Int) {
71         cdmaLevel.value = level
72         primaryLevel.value = level
73     }
74 
75     /**
76      * Set both [isRoaming] and [cdmaRoaming] properties, in the event that you don't care about the
77      * connection type
78      */
79     fun setAllRoaming(roaming: Boolean) {
80         isRoaming.value = roaming
81         cdmaRoaming.value = roaming
82     }
83 
84     /** Set the correct [resolvedNetworkType] for the given group via its lookup key */
85     fun setNetworkTypeKey(key: String) {
86         resolvedNetworkType.value = ResolvedNetworkType.DefaultNetworkType(key)
87     }
88 
89     companion object {
90         const val DEFAULT_NETWORK_NAME = "default name"
91     }
92 }
93