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