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