Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 1 | package com.android.systemui.statusbar.policy; |
| 2 | |
Jason Monk | 0288de0 | 2017-02-23 14:48:05 -0500 | [diff] [blame] | 3 | import static org.mockito.Matchers.anyInt; |
Pengquan Meng | a62d32b | 2018-12-06 17:38:38 -0800 | [diff] [blame] | 4 | import static org.mockito.Mockito.doReturn; |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 5 | import static org.mockito.Mockito.mock; |
Jason Monk | 0288de0 | 2017-02-23 14:48:05 -0500 | [diff] [blame] | 6 | import static org.mockito.Mockito.when; |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 7 | |
Jason Monk | fd57ea7 | 2016-04-29 13:37:58 -0400 | [diff] [blame] | 8 | import android.net.NetworkCapabilities; |
Jason Monk | 07b75fe | 2015-05-14 16:47:03 -0400 | [diff] [blame] | 9 | import android.os.Looper; |
Jack Yu | e27d3fd | 2019-03-15 14:49:53 -0700 | [diff] [blame] | 10 | import android.telephony.NetworkRegistrationInfo; |
Pengquan Meng | a62d32b | 2018-12-06 17:38:38 -0800 | [diff] [blame] | 11 | import android.telephony.ServiceState; |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 12 | import android.telephony.TelephonyManager; |
Jason Monk | e427cb8 | 2015-07-28 09:18:08 -0400 | [diff] [blame] | 13 | import android.test.suitebuilder.annotation.SmallTest; |
Jason Monk | 2515f47 | 2017-09-19 09:52:43 -0400 | [diff] [blame] | 14 | import android.testing.AndroidTestingRunner; |
| 15 | import android.testing.TestableLooper; |
| 16 | import android.testing.TestableLooper.RunWithLooper; |
Jason Monk | 0288de0 | 2017-02-23 14:48:05 -0500 | [diff] [blame] | 17 | |
Jason Monk | f668d7cc | 2016-01-14 10:38:41 -0500 | [diff] [blame] | 18 | import com.android.settingslib.net.DataUsageController; |
Jason Monk | 0288de0 | 2017-02-23 14:48:05 -0500 | [diff] [blame] | 19 | |
Geoffrey Pitsch | 2c403db | 2016-08-26 09:09:39 -0400 | [diff] [blame] | 20 | import org.junit.Test; |
| 21 | import org.junit.runner.RunWith; |
Pengquan Meng | a62d32b | 2018-12-06 17:38:38 -0800 | [diff] [blame] | 22 | import org.mockito.Mockito; |
Jason Monk | 33f8ae7 | 2015-05-08 10:45:15 -0400 | [diff] [blame] | 23 | |
Jason Monk | e427cb8 | 2015-07-28 09:18:08 -0400 | [diff] [blame] | 24 | @SmallTest |
Jason Monk | 2515f47 | 2017-09-19 09:52:43 -0400 | [diff] [blame] | 25 | @RunWith(AndroidTestingRunner.class) |
| 26 | @RunWithLooper |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 27 | public class NetworkControllerDataTest extends NetworkControllerBaseTest { |
| 28 | |
Geoffrey Pitsch | 2c403db | 2016-08-26 09:09:39 -0400 | [diff] [blame] | 29 | @Test |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 30 | public void test3gDataIcon() { |
| 31 | setupDefaultSignal(); |
| 32 | |
Amin Shaikh | d64e626 | 2018-03-08 10:08:13 -0500 | [diff] [blame] | 33 | verifyDataIndicators(TelephonyIcons.ICON_3G); |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 34 | } |
| 35 | |
Geoffrey Pitsch | 2c403db | 2016-08-26 09:09:39 -0400 | [diff] [blame] | 36 | @Test |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 37 | public void test2gDataIcon() { |
| 38 | setupDefaultSignal(); |
| 39 | updateDataConnectionState(TelephonyManager.DATA_CONNECTED, |
| 40 | TelephonyManager.NETWORK_TYPE_GSM); |
| 41 | |
Amin Shaikh | d64e626 | 2018-03-08 10:08:13 -0500 | [diff] [blame] | 42 | verifyDataIndicators(TelephonyIcons.ICON_G); |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 43 | } |
| 44 | |
Geoffrey Pitsch | 2c403db | 2016-08-26 09:09:39 -0400 | [diff] [blame] | 45 | @Test |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 46 | public void testCdmaDataIcon() { |
| 47 | setupDefaultSignal(); |
| 48 | updateDataConnectionState(TelephonyManager.DATA_CONNECTED, |
| 49 | TelephonyManager.NETWORK_TYPE_CDMA); |
| 50 | |
Amin Shaikh | d64e626 | 2018-03-08 10:08:13 -0500 | [diff] [blame] | 51 | verifyDataIndicators(TelephonyIcons.ICON_1X); |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 52 | } |
| 53 | |
Geoffrey Pitsch | 2c403db | 2016-08-26 09:09:39 -0400 | [diff] [blame] | 54 | @Test |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 55 | public void testEdgeDataIcon() { |
| 56 | setupDefaultSignal(); |
| 57 | updateDataConnectionState(TelephonyManager.DATA_CONNECTED, |
| 58 | TelephonyManager.NETWORK_TYPE_EDGE); |
| 59 | |
Amin Shaikh | d64e626 | 2018-03-08 10:08:13 -0500 | [diff] [blame] | 60 | verifyDataIndicators(TelephonyIcons.ICON_E); |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 61 | } |
| 62 | |
Geoffrey Pitsch | 2c403db | 2016-08-26 09:09:39 -0400 | [diff] [blame] | 63 | @Test |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 64 | public void testLteDataIcon() { |
| 65 | setupDefaultSignal(); |
| 66 | updateDataConnectionState(TelephonyManager.DATA_CONNECTED, |
| 67 | TelephonyManager.NETWORK_TYPE_LTE); |
| 68 | |
Amin Shaikh | d64e626 | 2018-03-08 10:08:13 -0500 | [diff] [blame] | 69 | verifyDataIndicators(TelephonyIcons.ICON_LTE); |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 70 | } |
| 71 | |
Geoffrey Pitsch | 2c403db | 2016-08-26 09:09:39 -0400 | [diff] [blame] | 72 | @Test |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 73 | public void testHspaDataIcon() { |
| 74 | setupDefaultSignal(); |
| 75 | updateDataConnectionState(TelephonyManager.DATA_CONNECTED, |
| 76 | TelephonyManager.NETWORK_TYPE_HSPA); |
| 77 | |
Amin Shaikh | d64e626 | 2018-03-08 10:08:13 -0500 | [diff] [blame] | 78 | verifyDataIndicators(TelephonyIcons.ICON_H); |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 79 | } |
| 80 | |
Amin Shaikh | f5830ca | 2018-03-09 14:06:50 -0500 | [diff] [blame] | 81 | |
| 82 | @Test |
| 83 | public void testHspaPlusDataIcon() { |
| 84 | setupDefaultSignal(); |
| 85 | updateDataConnectionState(TelephonyManager.DATA_CONNECTED, |
| 86 | TelephonyManager.NETWORK_TYPE_HSPAP); |
| 87 | |
| 88 | verifyDataIndicators(TelephonyIcons.ICON_H_PLUS); |
| 89 | } |
| 90 | |
| 91 | |
Geoffrey Pitsch | 2c403db | 2016-08-26 09:09:39 -0400 | [diff] [blame] | 92 | @Test |
Jason Monk | 7150d7f | 2015-07-09 10:14:12 -0400 | [diff] [blame] | 93 | public void testWfcNoDataIcon() { |
| 94 | setupDefaultSignal(); |
| 95 | updateDataConnectionState(TelephonyManager.DATA_CONNECTED, |
| 96 | TelephonyManager.NETWORK_TYPE_IWLAN); |
| 97 | |
Amin Shaikh | d64e626 | 2018-03-08 10:08:13 -0500 | [diff] [blame] | 98 | verifyDataIndicators(0); |
Jason Monk | 7150d7f | 2015-07-09 10:14:12 -0400 | [diff] [blame] | 99 | } |
| 100 | |
Geoffrey Pitsch | 2c403db | 2016-08-26 09:09:39 -0400 | [diff] [blame] | 101 | @Test |
Jason Monk | 3aaabd7 | 2014-12-12 11:11:44 -0500 | [diff] [blame] | 102 | public void test4gDataIcon() { |
| 103 | // Switch to showing 4g icon and re-initialize the NetworkController. |
| 104 | mConfig.show4gForLte = true; |
Sundeep Ghuman | 9d10a3c | 2017-06-16 00:05:16 +0000 | [diff] [blame] | 105 | mNetworkController = new NetworkControllerImpl(mContext, mMockCm, mMockTm, mMockWm, mMockSm, |
Jason Monk | 07b75fe | 2015-05-14 16:47:03 -0400 | [diff] [blame] | 106 | mConfig, Looper.getMainLooper(), mCallbackHandler, |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 107 | mock(AccessPointControllerImpl.class), |
| 108 | mock(DataUsageController.class), mMockSubDefaults, |
| 109 | mock(DeviceProvisionedController.class)); |
Jason Monk | 3aaabd7 | 2014-12-12 11:11:44 -0500 | [diff] [blame] | 110 | setupNetworkController(); |
| 111 | |
| 112 | setupDefaultSignal(); |
| 113 | updateDataConnectionState(TelephonyManager.DATA_CONNECTED, |
| 114 | TelephonyManager.NETWORK_TYPE_LTE); |
| 115 | |
Amin Shaikh | d64e626 | 2018-03-08 10:08:13 -0500 | [diff] [blame] | 116 | verifyDataIndicators(TelephonyIcons.ICON_4G); |
Jason Monk | 3aaabd7 | 2014-12-12 11:11:44 -0500 | [diff] [blame] | 117 | } |
| 118 | |
Geoffrey Pitsch | 2c403db | 2016-08-26 09:09:39 -0400 | [diff] [blame] | 119 | @Test |
Fabian Kozynski | c7bc84b | 2019-03-11 13:57:31 -0400 | [diff] [blame] | 120 | public void testNoInternetIcon_withDefaultSub() { |
Amin Shaikh | af4c193 | 2018-03-08 10:29:56 -0500 | [diff] [blame] | 121 | setupNetworkController(); |
Malcolm Chen | 04be9d1 | 2019-06-11 19:48:38 -0700 | [diff] [blame] | 122 | when(mMockTm.isDataCapable()).thenReturn(false); |
Amin Shaikh | af4c193 | 2018-03-08 10:29:56 -0500 | [diff] [blame] | 123 | setupDefaultSignal(); |
| 124 | updateDataConnectionState(TelephonyManager.DATA_CONNECTED, 0); |
Anarghya Mitra | 678722f | 2018-05-11 14:29:54 -0700 | [diff] [blame] | 125 | setConnectivityViaBroadcast(NetworkCapabilities.TRANSPORT_CELLULAR, false, false); |
Amin Shaikh | af4c193 | 2018-03-08 10:29:56 -0500 | [diff] [blame] | 126 | |
| 127 | // Verify that a SignalDrawable with a cut out is used to display data disabled. |
| 128 | verifyLastMobileDataIndicators(true, DEFAULT_SIGNAL_STRENGTH, 0, |
| 129 | true, DEFAULT_QS_SIGNAL_STRENGTH, 0, false, |
Fabian Kozynski | c7bc84b | 2019-03-11 13:57:31 -0400 | [diff] [blame] | 130 | false, true, NO_DATA_STRING); |
Amin Shaikh | af4c193 | 2018-03-08 10:29:56 -0500 | [diff] [blame] | 131 | } |
| 132 | |
| 133 | @Test |
Fabian Kozynski | c7bc84b | 2019-03-11 13:57:31 -0400 | [diff] [blame] | 134 | public void testDataDisabledIcon_withDefaultSub() { |
Jason Monk | fd57ea7 | 2016-04-29 13:37:58 -0400 | [diff] [blame] | 135 | setupNetworkController(); |
Malcolm Chen | 04be9d1 | 2019-06-11 19:48:38 -0700 | [diff] [blame] | 136 | when(mMockTm.isDataCapable()).thenReturn(false); |
Jason Monk | fd57ea7 | 2016-04-29 13:37:58 -0400 | [diff] [blame] | 137 | setupDefaultSignal(); |
| 138 | updateDataConnectionState(TelephonyManager.DATA_DISCONNECTED, 0); |
Anarghya Mitra | 678722f | 2018-05-11 14:29:54 -0700 | [diff] [blame] | 139 | setConnectivityViaBroadcast(NetworkCapabilities.TRANSPORT_CELLULAR, false, false); |
Jason Monk | fd57ea7 | 2016-04-29 13:37:58 -0400 | [diff] [blame] | 140 | |
Amin Shaikh | af4c193 | 2018-03-08 10:29:56 -0500 | [diff] [blame] | 141 | // Verify that a SignalDrawable with a cut out is used to display data disabled. |
| 142 | verifyLastMobileDataIndicators(true, DEFAULT_SIGNAL_STRENGTH, 0, |
| 143 | true, DEFAULT_QS_SIGNAL_STRENGTH, 0, false, |
Fabian Kozynski | c7bc84b | 2019-03-11 13:57:31 -0400 | [diff] [blame] | 144 | false, true, NO_DATA_STRING); |
| 145 | } |
| 146 | |
| 147 | @Test |
| 148 | public void testNoInternetIcon_withoutDefaultSub() { |
| 149 | setupNetworkController(); |
Malcolm Chen | 04be9d1 | 2019-06-11 19:48:38 -0700 | [diff] [blame] | 150 | when(mMockTm.isDataCapable()).thenReturn(false); |
Fabian Kozynski | c7bc84b | 2019-03-11 13:57:31 -0400 | [diff] [blame] | 151 | setupDefaultSignal(); |
| 152 | setDefaultSubId(mSubId + 1); |
| 153 | updateDataConnectionState(TelephonyManager.DATA_CONNECTED, 0); |
| 154 | setConnectivityViaBroadcast(NetworkCapabilities.TRANSPORT_CELLULAR, false, false); |
| 155 | |
| 156 | // Verify that a SignalDrawable with a cut out is used to display data disabled. |
| 157 | verifyLastMobileDataIndicators(true, DEFAULT_SIGNAL_STRENGTH, 0, |
| 158 | true, DEFAULT_QS_SIGNAL_STRENGTH, 0, false, |
| 159 | false, true, NOT_DEFAULT_DATA_STRING); |
| 160 | } |
| 161 | |
| 162 | @Test |
| 163 | public void testDataDisabledIcon_withoutDefaultSub() { |
| 164 | setupNetworkController(); |
Malcolm Chen | 04be9d1 | 2019-06-11 19:48:38 -0700 | [diff] [blame] | 165 | when(mMockTm.isDataCapable()).thenReturn(false); |
Fabian Kozynski | c7bc84b | 2019-03-11 13:57:31 -0400 | [diff] [blame] | 166 | setupDefaultSignal(); |
| 167 | setDefaultSubId(mSubId + 1); |
| 168 | updateDataConnectionState(TelephonyManager.DATA_DISCONNECTED, 0); |
| 169 | setConnectivityViaBroadcast(NetworkCapabilities.TRANSPORT_CELLULAR, false, false); |
| 170 | |
| 171 | // Verify that a SignalDrawable with a cut out is used to display data disabled. |
| 172 | verifyLastMobileDataIndicators(true, DEFAULT_SIGNAL_STRENGTH, 0, |
| 173 | true, DEFAULT_QS_SIGNAL_STRENGTH, 0, false, |
| 174 | false, true, NOT_DEFAULT_DATA_STRING); |
Jason Monk | fd57ea7 | 2016-04-29 13:37:58 -0400 | [diff] [blame] | 175 | } |
| 176 | |
Geoffrey Pitsch | 2c403db | 2016-08-26 09:09:39 -0400 | [diff] [blame] | 177 | @Test |
SongFerngWang | 52dada7 | 2019-08-14 16:59:29 +0800 | [diff] [blame^] | 178 | public void testNr5GIcon_NrNotRestrictedRrcCon_show5GIcon() { |
| 179 | setupNr5GIconConfigurationForNotRestrictedRrcCon(); |
| 180 | setupDefaultSignal(); |
| 181 | updateDataConnectionState(TelephonyManager.DATA_CONNECTED, |
| 182 | TelephonyManager.NETWORK_TYPE_LTE); |
| 183 | updateDataActivity(TelephonyManager.DATA_ACTIVITY_INOUT); |
| 184 | ServiceState ss = Mockito.mock(ServiceState.class); |
| 185 | doReturn(NetworkRegistrationInfo.NR_STATE_NOT_RESTRICTED).when(ss).getNrState(); |
| 186 | mPhoneStateListener.onServiceStateChanged(ss); |
| 187 | |
| 188 | verifyLastMobileDataIndicators(true, DEFAULT_SIGNAL_STRENGTH, TelephonyIcons.ICON_5G, |
| 189 | true, DEFAULT_QS_SIGNAL_STRENGTH, TelephonyIcons.ICON_5G, true, true); |
| 190 | } |
| 191 | |
| 192 | @Test |
| 193 | public void testNr5GIcon_NrNotRestrictedRrcIdle_show5GIcon() { |
| 194 | setupNr5GIconConfigurationForNotRestrictedRrcIdle(); |
| 195 | setupDefaultSignal(); |
| 196 | updateDataConnectionState(TelephonyManager.DATA_CONNECTED, |
| 197 | TelephonyManager.NETWORK_TYPE_LTE); |
| 198 | updateDataActivity(TelephonyManager.DATA_ACTIVITY_DORMANT); |
| 199 | ServiceState ss = Mockito.mock(ServiceState.class); |
| 200 | doReturn(NetworkRegistrationInfo.NR_STATE_NOT_RESTRICTED).when(ss).getNrState(); |
| 201 | mPhoneStateListener.onServiceStateChanged(ss); |
| 202 | |
| 203 | verifyDataIndicators(TelephonyIcons.ICON_5G); |
| 204 | } |
| 205 | |
| 206 | @Test |
Pengquan Meng | a62d32b | 2018-12-06 17:38:38 -0800 | [diff] [blame] | 207 | public void testNr5GIcon_NrConnectedWithoutMMWave_show5GIcon() { |
| 208 | setupDefaultNr5GIconConfiguration(); |
| 209 | setupDefaultSignal(); |
| 210 | updateDataConnectionState(TelephonyManager.DATA_CONNECTED, |
| 211 | TelephonyManager.NETWORK_TYPE_LTE); |
| 212 | ServiceState ss = Mockito.mock(ServiceState.class); |
Jack Yu | 20d7140 | 2019-03-16 23:00:35 -0700 | [diff] [blame] | 213 | doReturn(NetworkRegistrationInfo.NR_STATE_CONNECTED).when(ss).getNrState(); |
Pengquan Meng | a62d32b | 2018-12-06 17:38:38 -0800 | [diff] [blame] | 214 | doReturn(ServiceState.FREQUENCY_RANGE_HIGH).when(ss).getNrFrequencyRange(); |
| 215 | mPhoneStateListener.onServiceStateChanged(ss); |
| 216 | |
| 217 | verifyDataIndicators(TelephonyIcons.ICON_5G); |
| 218 | } |
| 219 | |
| 220 | @Test |
| 221 | public void testNr5GIcon_NrConnectedWithMMWave_show5GPlusIcon() { |
| 222 | setupDefaultNr5GIconConfiguration(); |
| 223 | setupDefaultSignal(); |
| 224 | updateDataConnectionState(TelephonyManager.DATA_CONNECTED, |
| 225 | TelephonyManager.NETWORK_TYPE_LTE); |
| 226 | ServiceState ss = Mockito.mock(ServiceState.class); |
Jack Yu | 20d7140 | 2019-03-16 23:00:35 -0700 | [diff] [blame] | 227 | doReturn(NetworkRegistrationInfo.NR_STATE_CONNECTED).when(ss).getNrState(); |
Pengquan Meng | a62d32b | 2018-12-06 17:38:38 -0800 | [diff] [blame] | 228 | doReturn(ServiceState.FREQUENCY_RANGE_MMWAVE).when(ss).getNrFrequencyRange(); |
| 229 | mPhoneStateListener.onServiceStateChanged(ss); |
| 230 | |
| 231 | verifyDataIndicators(TelephonyIcons.ICON_5G_PLUS); |
| 232 | } |
| 233 | |
| 234 | @Test |
| 235 | public void testNr5GIcon_NrRestricted_showLteIcon() { |
| 236 | setupDefaultNr5GIconConfiguration(); |
| 237 | setupDefaultSignal(); |
| 238 | updateDataConnectionState(TelephonyManager.DATA_CONNECTED, |
| 239 | TelephonyManager.NETWORK_TYPE_LTE); |
| 240 | ServiceState ss = Mockito.mock(ServiceState.class); |
Jack Yu | 20d7140 | 2019-03-16 23:00:35 -0700 | [diff] [blame] | 241 | doReturn(NetworkRegistrationInfo.NR_STATE_RESTRICTED).when(ss).getNrState(); |
Pengquan Meng | a62d32b | 2018-12-06 17:38:38 -0800 | [diff] [blame] | 242 | mPhoneStateListener.onServiceStateChanged(mServiceState); |
| 243 | |
| 244 | verifyDataIndicators(TelephonyIcons.ICON_LTE); |
| 245 | } |
| 246 | |
| 247 | @Test |
Jason Monk | fd57ea7 | 2016-04-29 13:37:58 -0400 | [diff] [blame] | 248 | public void testDataDisabledIcon_UserNotSetup() { |
| 249 | setupNetworkController(); |
Malcolm Chen | 04be9d1 | 2019-06-11 19:48:38 -0700 | [diff] [blame] | 250 | when(mMockTm.isDataCapable()).thenReturn(false); |
Jason Monk | fd57ea7 | 2016-04-29 13:37:58 -0400 | [diff] [blame] | 251 | setupDefaultSignal(); |
| 252 | updateDataConnectionState(TelephonyManager.DATA_DISCONNECTED, 0); |
Anarghya Mitra | 678722f | 2018-05-11 14:29:54 -0700 | [diff] [blame] | 253 | setConnectivityViaBroadcast(NetworkCapabilities.TRANSPORT_CELLULAR, false, false); |
Jason Monk | 0288de0 | 2017-02-23 14:48:05 -0500 | [diff] [blame] | 254 | when(mMockProvisionController.isUserSetup(anyInt())).thenReturn(false); |
| 255 | mUserCallback.onUserSetupChanged(); |
Jason Monk | 2515f47 | 2017-09-19 09:52:43 -0400 | [diff] [blame] | 256 | TestableLooper.get(this).processAllMessages(); |
Jason Monk | fd57ea7 | 2016-04-29 13:37:58 -0400 | [diff] [blame] | 257 | |
| 258 | // Don't show the X until the device is setup. |
Amin Shaikh | d64e626 | 2018-03-08 10:08:13 -0500 | [diff] [blame] | 259 | verifyDataIndicators(0); |
Jason Monk | fd57ea7 | 2016-04-29 13:37:58 -0400 | [diff] [blame] | 260 | } |
| 261 | |
Geoffrey Pitsch | 2c403db | 2016-08-26 09:09:39 -0400 | [diff] [blame] | 262 | @Test |
Wenting Xiong | 63364fe | 2017-02-07 19:12:27 +0800 | [diff] [blame] | 263 | public void testAlwaysShowDataRatIcon() { |
| 264 | setupDefaultSignal(); |
Malcolm Chen | 04be9d1 | 2019-06-11 19:48:38 -0700 | [diff] [blame] | 265 | when(mMockTm.isDataCapable()).thenReturn(false); |
Wenting Xiong | 63364fe | 2017-02-07 19:12:27 +0800 | [diff] [blame] | 266 | updateDataConnectionState(TelephonyManager.DATA_DISCONNECTED, |
| 267 | TelephonyManager.NETWORK_TYPE_GSM); |
| 268 | |
| 269 | // Switch to showing data RAT icon when data is disconnected |
| 270 | // and re-initialize the NetworkController. |
| 271 | mConfig.alwaysShowDataRatIcon = true; |
| 272 | mNetworkController.handleConfigurationChanged(); |
| 273 | |
Amin Shaikh | d64e626 | 2018-03-08 10:08:13 -0500 | [diff] [blame] | 274 | verifyDataIndicators(TelephonyIcons.ICON_G); |
Wenting Xiong | 63364fe | 2017-02-07 19:12:27 +0800 | [diff] [blame] | 275 | } |
| 276 | |
| 277 | @Test |
Jason Monk | 3aaabd7 | 2014-12-12 11:11:44 -0500 | [diff] [blame] | 278 | public void test4gDataIconConfigChange() { |
| 279 | setupDefaultSignal(); |
| 280 | updateDataConnectionState(TelephonyManager.DATA_CONNECTED, |
| 281 | TelephonyManager.NETWORK_TYPE_LTE); |
| 282 | |
| 283 | // Switch to showing 4g icon and re-initialize the NetworkController. |
| 284 | mConfig.show4gForLte = true; |
| 285 | // Can't send the broadcast as that would actually read the config from |
| 286 | // the context. Instead we'll just poke at a function that does all of |
| 287 | // the after work. |
| 288 | mNetworkController.handleConfigurationChanged(); |
| 289 | |
Amin Shaikh | d64e626 | 2018-03-08 10:08:13 -0500 | [diff] [blame] | 290 | verifyDataIndicators(TelephonyIcons.ICON_4G); |
Jason Monk | 3aaabd7 | 2014-12-12 11:11:44 -0500 | [diff] [blame] | 291 | } |
| 292 | |
Geoffrey Pitsch | 2c403db | 2016-08-26 09:09:39 -0400 | [diff] [blame] | 293 | @Test |
Jason Monk | 67b2c16 | 2016-01-12 10:24:09 -0500 | [diff] [blame] | 294 | public void testDataChangeWithoutConnectionState() { |
| 295 | setupDefaultSignal(); |
| 296 | updateDataConnectionState(TelephonyManager.DATA_CONNECTED, |
| 297 | TelephonyManager.NETWORK_TYPE_LTE); |
| 298 | |
Amin Shaikh | d64e626 | 2018-03-08 10:08:13 -0500 | [diff] [blame] | 299 | verifyDataIndicators(TelephonyIcons.ICON_LTE); |
Jason Monk | 67b2c16 | 2016-01-12 10:24:09 -0500 | [diff] [blame] | 300 | |
Jason Monk | 0288de0 | 2017-02-23 14:48:05 -0500 | [diff] [blame] | 301 | when(mServiceState.getDataNetworkType()) |
Jason Monk | 67b2c16 | 2016-01-12 10:24:09 -0500 | [diff] [blame] | 302 | .thenReturn(TelephonyManager.NETWORK_TYPE_HSPA); |
| 303 | updateServiceState(); |
Amin Shaikh | d64e626 | 2018-03-08 10:08:13 -0500 | [diff] [blame] | 304 | verifyDataIndicators(TelephonyIcons.ICON_H); |
Jason Monk | 67b2c16 | 2016-01-12 10:24:09 -0500 | [diff] [blame] | 305 | } |
| 306 | |
Geoffrey Pitsch | 2c403db | 2016-08-26 09:09:39 -0400 | [diff] [blame] | 307 | @Test |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 308 | public void testDataActivity() { |
| 309 | setupDefaultSignal(); |
| 310 | |
| 311 | testDataActivity(TelephonyManager.DATA_ACTIVITY_NONE, false, false); |
| 312 | testDataActivity(TelephonyManager.DATA_ACTIVITY_IN, true, false); |
| 313 | testDataActivity(TelephonyManager.DATA_ACTIVITY_OUT, false, true); |
| 314 | testDataActivity(TelephonyManager.DATA_ACTIVITY_INOUT, true, true); |
| 315 | } |
| 316 | |
Fabian Kozynski | a909199 | 2019-03-25 11:08:32 -0400 | [diff] [blame] | 317 | @Test |
| 318 | public void testUpdateDataNetworkName() { |
| 319 | setupDefaultSignal(); |
| 320 | String newDataName = "TestDataName"; |
| 321 | when(mServiceState.getDataOperatorAlphaShort()).thenReturn(newDataName); |
| 322 | updateServiceState(); |
| 323 | assertDataNetworkNameEquals(newDataName); |
| 324 | } |
| 325 | |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 326 | private void testDataActivity(int direction, boolean in, boolean out) { |
| 327 | updateDataActivity(direction); |
| 328 | |
Jason Monk | 26ad85a | 2016-12-08 14:45:42 -0500 | [diff] [blame] | 329 | verifyLastMobileDataIndicators(true, DEFAULT_SIGNAL_STRENGTH, DEFAULT_ICON, true, |
Jason Monk | 7e6c83c | 2017-04-26 14:35:24 -0400 | [diff] [blame] | 330 | DEFAULT_QS_SIGNAL_STRENGTH, DEFAULT_QS_ICON, in, out); |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 331 | } |
| 332 | |
Amin Shaikh | d64e626 | 2018-03-08 10:08:13 -0500 | [diff] [blame] | 333 | private void verifyDataIndicators(int dataIcon) { |
Jason Monk | 26ad85a | 2016-12-08 14:45:42 -0500 | [diff] [blame] | 334 | verifyLastMobileDataIndicators(true, DEFAULT_SIGNAL_STRENGTH, dataIcon, |
Amin Shaikh | d64e626 | 2018-03-08 10:08:13 -0500 | [diff] [blame] | 335 | true, DEFAULT_QS_SIGNAL_STRENGTH, dataIcon, false, |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 336 | false); |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 337 | } |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 338 | } |