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