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
18 
19 import android.content.Intent
20 import android.telephony.ServiceState
21 import android.telephony.SignalStrength
22 import android.telephony.TelephonyDisplayInfo
23 import android.telephony.TelephonyManager
24 import com.android.settingslib.SignalIcon
25 import com.android.settingslib.mobile.MobileMappings
26 import com.android.systemui.dagger.SysUISingleton
27 import com.android.systemui.log.LogBuffer
28 import com.android.systemui.log.core.LogLevel
29 import com.android.systemui.statusbar.pipeline.dagger.MobileInputLog
30 import javax.inject.Inject
31 
32 /** Logs for inputs into the mobile pipeline. */
33 @SysUISingleton
34 class MobileInputLogger
35 @Inject
36 constructor(
37     @MobileInputLog private val buffer: LogBuffer,
38 ) {
logOnServiceStateChangednull39     fun logOnServiceStateChanged(serviceState: ServiceState, subId: Int) {
40         buffer.log(
41             TAG,
42             LogLevel.INFO,
43             {
44                 int1 = subId
45                 bool1 = serviceState.isEmergencyOnly
46                 bool2 = serviceState.roaming
47                 str1 = serviceState.operatorAlphaShort
48             },
49             {
50                 "onServiceStateChanged: subId=$int1 emergencyOnly=$bool1 roaming=$bool2" +
51                     " operator=$str1"
52             }
53         )
54     }
55 
logTopLevelServiceStateBroadcastEmergencyOnlynull56     fun logTopLevelServiceStateBroadcastEmergencyOnly(subId: Int, serviceState: ServiceState) {
57         buffer.log(
58             TAG,
59             LogLevel.INFO,
60             {
61                 int1 = subId
62                 bool1 = serviceState.isEmergencyOnly
63             },
64             { "ACTION_SERVICE_STATE for subId=$int1. ServiceState.isEmergencyOnly=$bool1" }
65         )
66     }
67 
logTopLevelServiceStateBroadcastMissingExtrasnull68     fun logTopLevelServiceStateBroadcastMissingExtras(subId: Int) {
69         buffer.log(
70             TAG,
71             LogLevel.INFO,
72             { int1 = subId },
73             { "ACTION_SERVICE_STATE for subId=$int1. Intent is missing extras. Ignoring" }
74         )
75     }
76 
logOnSignalStrengthsChangednull77     fun logOnSignalStrengthsChanged(signalStrength: SignalStrength, subId: Int) {
78         buffer.log(
79             TAG,
80             LogLevel.INFO,
81             {
82                 int1 = subId
83                 str1 = signalStrength.toString()
84             },
85             { "onSignalStrengthsChanged: subId=$int1 strengths=$str1" }
86         )
87     }
88 
logOnDataConnectionStateChangednull89     fun logOnDataConnectionStateChanged(dataState: Int, networkType: Int, subId: Int) {
90         buffer.log(
91             TAG,
92             LogLevel.INFO,
93             {
94                 int1 = subId
95                 int2 = dataState
96                 str1 = networkType.toString()
97             },
98             { "onDataConnectionStateChanged: subId=$int1 dataState=$int2 networkType=$str1" },
99         )
100     }
101 
logOnDataActivitynull102     fun logOnDataActivity(direction: Int, subId: Int) {
103         buffer.log(
104             TAG,
105             LogLevel.INFO,
106             {
107                 int1 = subId
108                 int2 = direction
109             },
110             { "onDataActivity: subId=$int1 direction=$int2" },
111         )
112     }
113 
logOnCarrierNetworkChangenull114     fun logOnCarrierNetworkChange(active: Boolean, subId: Int) {
115         buffer.log(
116             TAG,
117             LogLevel.INFO,
118             {
119                 int1 = subId
120                 bool1 = active
121             },
122             { "onCarrierNetworkChange: subId=$int1 active=$bool1" },
123         )
124     }
125 
logOnCarrierRoamingNtnModeChangednull126     fun logOnCarrierRoamingNtnModeChanged(active: Boolean) {
127         buffer.log(
128             TAG,
129             LogLevel.INFO,
130             { bool1 = active },
131             { "onCarrierRoamingNtnModeChanged: $bool1" }
132         )
133     }
134 
logOnDisplayInfoChangednull135     fun logOnDisplayInfoChanged(displayInfo: TelephonyDisplayInfo, subId: Int) {
136         buffer.log(
137             TAG,
138             LogLevel.INFO,
139             {
140                 int1 = subId
141                 str1 = displayInfo.toString()
142                 bool1 = displayInfo.isRoaming
143             },
144             { "onDisplayInfoChanged: subId=$int1 displayInfo=$str1 isRoaming=$bool1" },
145         )
146     }
147 
logCarrierConfigChangednull148     fun logCarrierConfigChanged(subId: Int) {
149         buffer.log(
150             TAG,
151             LogLevel.INFO,
152             { int1 = subId },
153             { "onCarrierConfigChanged: subId=$int1" },
154         )
155     }
156 
logOnDataEnabledChangednull157     fun logOnDataEnabledChanged(enabled: Boolean, subId: Int) {
158         buffer.log(
159             TAG,
160             LogLevel.INFO,
161             {
162                 int1 = subId
163                 bool1 = enabled
164             },
165             { "onDataEnabledChanged: subId=$int1 enabled=$bool1" },
166         )
167     }
168 
logActionCarrierConfigChangednull169     fun logActionCarrierConfigChanged() {
170         buffer.log(TAG, LogLevel.INFO, {}, { "Intent received: ACTION_CARRIER_CONFIG_CHANGED" })
171     }
172 
logDefaultDataSubRatConfignull173     fun logDefaultDataSubRatConfig(config: MobileMappings.Config) {
174         buffer.log(
175             TAG,
176             LogLevel.INFO,
177             { str1 = config.toString() },
178             { "defaultDataSubRatConfig: $str1" }
179         )
180     }
181 
logDefaultMobileIconMappingnull182     fun logDefaultMobileIconMapping(mapping: Map<String, SignalIcon.MobileIconGroup>) {
183         buffer.log(
184             TAG,
185             LogLevel.INFO,
186             { str1 = mapping.toString() },
187             { "defaultMobileIconMapping: $str1" }
188         )
189     }
190 
logDefaultMobileIconGroupnull191     fun logDefaultMobileIconGroup(group: SignalIcon.MobileIconGroup) {
192         buffer.log(TAG, LogLevel.INFO, { str1 = group.name }, { "defaultMobileIconGroup: $str1" })
193     }
194 
logOnSubscriptionsChangednull195     fun logOnSubscriptionsChanged() {
196         buffer.log(TAG, LogLevel.INFO, {}, { "onSubscriptionsChanged" })
197     }
198 
logServiceProvidersUpdatedBroadcastnull199     fun logServiceProvidersUpdatedBroadcast(intent: Intent) {
200         val showSpn = intent.getBooleanExtra(TelephonyManager.EXTRA_SHOW_SPN, false)
201         val spn = intent.getStringExtra(TelephonyManager.EXTRA_DATA_SPN)
202         val showPlmn = intent.getBooleanExtra(TelephonyManager.EXTRA_SHOW_PLMN, false)
203         val plmn = intent.getStringExtra(TelephonyManager.EXTRA_PLMN)
204 
205         buffer.log(
206             TAG,
207             LogLevel.INFO,
208             {
209                 bool1 = showSpn
210                 str1 = spn
211                 bool2 = showPlmn
212                 str2 = plmn
213             },
214             {
215                 "Intent: ACTION_SERVICE_PROVIDERS_UPDATED." +
216                     " showSpn=$bool1 spn=$str1 showPlmn=$bool2 plmn=$str2"
217             }
218         )
219     }
220 
logOnSimStateChangednull221     fun logOnSimStateChanged() {
222         buffer.log(TAG, LogLevel.INFO, "onSimStateChanged")
223     }
224 
logPrioritizedNetworkAvailablenull225     fun logPrioritizedNetworkAvailable(netId: Int) {
226         buffer.log(
227             TAG,
228             LogLevel.INFO,
229             { int1 = netId },
230             { "Found prioritized network (nedId=$int1)" },
231         )
232     }
233 
logPrioritizedNetworkLostnull234     fun logPrioritizedNetworkLost(netId: Int) {
235         buffer.log(
236             TAG,
237             LogLevel.INFO,
238             { int1 = netId },
239             { "Lost prioritized network (nedId=$int1)" },
240         )
241     }
242 }
243 
244 private const val TAG = "MobileInputLog"
245