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.CellSignalStrength 20 import android.telephony.SubscriptionInfo 21 import android.telephony.TelephonyManager 22 import com.android.systemui.log.table.TableLogBuffer 23 import com.android.systemui.statusbar.pipeline.mobile.data.model.DataConnectionState 24 import com.android.systemui.statusbar.pipeline.mobile.data.model.NetworkNameModel 25 import com.android.systemui.statusbar.pipeline.mobile.data.model.ResolvedNetworkType 26 import com.android.systemui.statusbar.pipeline.mobile.data.model.SubscriptionModel 27 import com.android.systemui.statusbar.pipeline.shared.data.model.DataActivityModel 28 import kotlinx.coroutines.flow.StateFlow 29 30 /** 31 * Every mobile line of service can be identified via a [SubscriptionInfo] object. We set up a 32 * repository for each individual, tracked subscription via [MobileConnectionsRepository], and this 33 * repository is responsible for setting up a [TelephonyManager] object tied to its subscriptionId 34 * 35 * There should only ever be one [MobileConnectionRepository] per subscription, since 36 * [TelephonyManager] limits the number of callbacks that can be registered per process. 37 * 38 * This repository should have all of the relevant information for a single line of service, which 39 * eventually becomes a single icon in the status bar. 40 */ 41 interface MobileConnectionRepository { 42 /** The subscriptionId that this connection represents */ 43 val subId: Int 44 45 /** The carrierId for this connection. See [TelephonyManager.getSimCarrierId] */ 46 val carrierId: StateFlow<Int> 47 48 /** Reflects the value from the carrier config INFLATE_SIGNAL_STRENGTH for this connection */ 49 val inflateSignalStrength: StateFlow<Boolean> 50 51 /** Carrier config KEY_SHOW_5G_SLICE_ICON_BOOL for this connection */ 52 val allowNetworkSliceIndicator: StateFlow<Boolean> 53 54 /** 55 * The table log buffer created for this connection. Will have the name "MobileConnectionLog 56 * [subId]" 57 */ 58 val tableLogBuffer: TableLogBuffer 59 60 /** True if the [android.telephony.ServiceState] says this connection is emergency calls only */ 61 val isEmergencyOnly: StateFlow<Boolean> 62 63 /** True if [android.telephony.ServiceState] says we are roaming */ 64 val isRoaming: StateFlow<Boolean> 65 66 /** 67 * See [android.telephony.ServiceState.getOperatorAlphaShort], this value is defined as the 68 * current registered operator name in short alphanumeric format. In some cases this name might 69 * be preferred over other methods of calculating the network name 70 */ 71 val operatorAlphaShort: StateFlow<String?> 72 73 /** 74 * TODO (b/263167683): Clarify this field 75 * 76 * This check comes from [com.android.settingslib.Utils.isInService]. It is intended to be a 77 * mapping from a ServiceState to a notion of connectivity. Notably, it will consider a 78 * connection to be in-service if either the voice registration state is IN_SERVICE or the data 79 * registration state is IN_SERVICE and NOT IWLAN. 80 */ 81 val isInService: StateFlow<Boolean> 82 83 /** 84 * True if this subscription is actively connected to a non-terrestrial network and false 85 * otherwise. Reflects [android.telephony.ServiceState.isUsingNonTerrestrialNetwork]. 86 * 87 * Notably: This value reflects that this subscription is **currently** using a non-terrestrial 88 * network, because some subscriptions can switch between terrestrial and non-terrestrial 89 * networks. [SubscriptionModel.isExclusivelyNonTerrestrial] reflects whether a subscription is 90 * configured to exclusively connect to non-terrestrial networks. [isNonTerrestrial] can change 91 * during the lifetime of a subscription but [SubscriptionModel.isExclusivelyNonTerrestrial] 92 * will stay constant. 93 */ 94 val isNonTerrestrial: StateFlow<Boolean> 95 96 /** True if [android.telephony.SignalStrength] told us that this connection is using GSM */ 97 val isGsm: StateFlow<Boolean> 98 99 /** 100 * There is still specific logic in the pipeline that calls out CDMA level explicitly. This 101 * field is not completely orthogonal to [primaryLevel], because CDMA could be primary. 102 */ 103 // @IntRange(from = 0, to = 4) 104 val cdmaLevel: StateFlow<Int> 105 106 /** [android.telephony.SignalStrength]'s concept of the overall signal level */ 107 // @IntRange(from = 0, to = 4) 108 val primaryLevel: StateFlow<Int> 109 110 /** The current data connection state. See [DataConnectionState] */ 111 val dataConnectionState: StateFlow<DataConnectionState> 112 113 /** The current data activity direction. See [DataActivityModel] */ 114 val dataActivityDirection: StateFlow<DataActivityModel> 115 116 /** True if there is currently a carrier network change in process */ 117 val carrierNetworkChangeActive: StateFlow<Boolean> 118 119 /** 120 * [resolvedNetworkType] is the [TelephonyDisplayInfo.getOverrideNetworkType] if it exists or 121 * [TelephonyDisplayInfo.getNetworkType]. This is used to look up the proper network type icon 122 */ 123 val resolvedNetworkType: StateFlow<ResolvedNetworkType> 124 125 /** The total number of levels. Used with [SignalDrawable]. */ 126 val numberOfLevels: StateFlow<Int> 127 128 /** Observable tracking [TelephonyManager.isDataConnectionAllowed] */ 129 val dataEnabled: StateFlow<Boolean> 130 131 /** 132 * See [TelephonyManager.getCdmaEnhancedRoamingIndicatorDisplayNumber]. This bit only matters if 133 * the connection type is CDMA. 134 * 135 * True if the Enhanced Roaming Indicator (ERI) display number is not [TelephonyManager.ERI_OFF] 136 */ 137 val cdmaRoaming: StateFlow<Boolean> 138 139 /** The service provider name for this network connection, or the default name. */ 140 val networkName: StateFlow<NetworkNameModel> 141 142 /** 143 * The service provider name for this network connection, or the default name. 144 * 145 * TODO(b/296600321): De-duplicate this field with [networkName] after determining the data 146 * provided is identical 147 */ 148 val carrierName: StateFlow<NetworkNameModel> 149 150 /** 151 * True if this type of connection is allowed while airplane mode is on, and false otherwise. 152 */ 153 val isAllowedDuringAirplaneMode: StateFlow<Boolean> 154 155 /** 156 * True if this network has NET_CAPABILITIY_PRIORITIZE_LATENCY, and can be considered to be a 157 * network slice 158 */ 159 val hasPrioritizedNetworkCapabilities: StateFlow<Boolean> 160 161 /** 162 * True if this connection is in emergency callback mode. 163 * 164 * @see [TelephonyManager.getEmergencyCallbackMode] 165 */ isInEcmModenull166 suspend fun isInEcmMode(): Boolean 167 168 companion object { 169 /** The default number of levels to use for [numberOfLevels]. */ 170 val DEFAULT_NUM_LEVELS = CellSignalStrength.getNumSignalStrengthLevels() 171 } 172 } 173