Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 1 | package com.android.systemui.statusbar.policy; |
| 2 | |
Bill Lin | 767c0db | 2019-08-15 20:42:06 +0800 | [diff] [blame] | 3 | import static org.junit.Assert.assertFalse; |
| 4 | import static org.junit.Assert.assertTrue; |
Jason Monk | 0288de0 | 2017-02-23 14:48:05 -0500 | [diff] [blame] | 5 | import static org.mockito.Matchers.anyInt; |
Pengquan Meng | a62d32b | 2018-12-06 17:38:38 -0800 | [diff] [blame] | 6 | import static org.mockito.Mockito.doReturn; |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 7 | import static org.mockito.Mockito.mock; |
Jason Monk | 0288de0 | 2017-02-23 14:48:05 -0500 | [diff] [blame] | 8 | import static org.mockito.Mockito.when; |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 9 | |
Jason Monk | fd57ea7 | 2016-04-29 13:37:58 -0400 | [diff] [blame] | 10 | import android.net.NetworkCapabilities; |
Jason Monk | 07b75fe | 2015-05-14 16:47:03 -0400 | [diff] [blame] | 11 | import android.os.Looper; |
Jack Yu | e27d3fd | 2019-03-15 14:49:53 -0700 | [diff] [blame] | 12 | import android.telephony.NetworkRegistrationInfo; |
Pengquan Meng | a62d32b | 2018-12-06 17:38:38 -0800 | [diff] [blame] | 13 | import android.telephony.ServiceState; |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 14 | import android.telephony.TelephonyManager; |
Jason Monk | e427cb8 | 2015-07-28 09:18:08 -0400 | [diff] [blame] | 15 | import android.test.suitebuilder.annotation.SmallTest; |
Jason Monk | 2515f47 | 2017-09-19 09:52:43 -0400 | [diff] [blame] | 16 | import android.testing.AndroidTestingRunner; |
| 17 | import android.testing.TestableLooper; |
| 18 | import android.testing.TestableLooper.RunWithLooper; |
Jason Monk | 0288de0 | 2017-02-23 14:48:05 -0500 | [diff] [blame] | 19 | |
Jason Monk | f668d7c | 2016-01-14 10:38:41 -0500 | [diff] [blame] | 20 | import com.android.settingslib.net.DataUsageController; |
Jason Monk | 0288de0 | 2017-02-23 14:48:05 -0500 | [diff] [blame] | 21 | |
Geoffrey Pitsch | 2c403db | 2016-08-26 09:09:39 -0400 | [diff] [blame] | 22 | import org.junit.Test; |
| 23 | import org.junit.runner.RunWith; |
Pengquan Meng | a62d32b | 2018-12-06 17:38:38 -0800 | [diff] [blame] | 24 | import org.mockito.Mockito; |
Jason Monk | 33f8ae7 | 2015-05-08 10:45:15 -0400 | [diff] [blame] | 25 | |
Jason Monk | e427cb8 | 2015-07-28 09:18:08 -0400 | [diff] [blame] | 26 | @SmallTest |
Jason Monk | 2515f47 | 2017-09-19 09:52:43 -0400 | [diff] [blame] | 27 | @RunWith(AndroidTestingRunner.class) |
| 28 | @RunWithLooper |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 29 | public class NetworkControllerDataTest extends NetworkControllerBaseTest { |
| 30 | |
Geoffrey Pitsch | 2c403db | 2016-08-26 09:09:39 -0400 | [diff] [blame] | 31 | @Test |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 32 | public void test3gDataIcon() { |
| 33 | setupDefaultSignal(); |
| 34 | |
Amin Shaikh | d64e626 | 2018-03-08 10:08:13 -0500 | [diff] [blame] | 35 | verifyDataIndicators(TelephonyIcons.ICON_3G); |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 36 | } |
| 37 | |
Geoffrey Pitsch | 2c403db | 2016-08-26 09:09:39 -0400 | [diff] [blame] | 38 | @Test |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 39 | public void test2gDataIcon() { |
| 40 | setupDefaultSignal(); |
| 41 | updateDataConnectionState(TelephonyManager.DATA_CONNECTED, |
| 42 | TelephonyManager.NETWORK_TYPE_GSM); |
| 43 | |
Amin Shaikh | d64e626 | 2018-03-08 10:08:13 -0500 | [diff] [blame] | 44 | verifyDataIndicators(TelephonyIcons.ICON_G); |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 45 | } |
| 46 | |
Geoffrey Pitsch | 2c403db | 2016-08-26 09:09:39 -0400 | [diff] [blame] | 47 | @Test |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 48 | public void testCdmaDataIcon() { |
| 49 | setupDefaultSignal(); |
| 50 | updateDataConnectionState(TelephonyManager.DATA_CONNECTED, |
| 51 | TelephonyManager.NETWORK_TYPE_CDMA); |
| 52 | |
Amin Shaikh | d64e626 | 2018-03-08 10:08:13 -0500 | [diff] [blame] | 53 | verifyDataIndicators(TelephonyIcons.ICON_1X); |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 54 | } |
| 55 | |
Geoffrey Pitsch | 2c403db | 2016-08-26 09:09:39 -0400 | [diff] [blame] | 56 | @Test |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 57 | public void testEdgeDataIcon() { |
| 58 | setupDefaultSignal(); |
| 59 | updateDataConnectionState(TelephonyManager.DATA_CONNECTED, |
| 60 | TelephonyManager.NETWORK_TYPE_EDGE); |
| 61 | |
Amin Shaikh | d64e626 | 2018-03-08 10:08:13 -0500 | [diff] [blame] | 62 | verifyDataIndicators(TelephonyIcons.ICON_E); |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 63 | } |
| 64 | |
Geoffrey Pitsch | 2c403db | 2016-08-26 09:09:39 -0400 | [diff] [blame] | 65 | @Test |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 66 | public void testLteDataIcon() { |
| 67 | setupDefaultSignal(); |
| 68 | updateDataConnectionState(TelephonyManager.DATA_CONNECTED, |
| 69 | TelephonyManager.NETWORK_TYPE_LTE); |
| 70 | |
Amin Shaikh | d64e626 | 2018-03-08 10:08:13 -0500 | [diff] [blame] | 71 | verifyDataIndicators(TelephonyIcons.ICON_LTE); |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 72 | } |
| 73 | |
Geoffrey Pitsch | 2c403db | 2016-08-26 09:09:39 -0400 | [diff] [blame] | 74 | @Test |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 75 | public void testHspaDataIcon() { |
| 76 | setupDefaultSignal(); |
| 77 | updateDataConnectionState(TelephonyManager.DATA_CONNECTED, |
| 78 | TelephonyManager.NETWORK_TYPE_HSPA); |
| 79 | |
Amin Shaikh | d64e626 | 2018-03-08 10:08:13 -0500 | [diff] [blame] | 80 | verifyDataIndicators(TelephonyIcons.ICON_H); |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 81 | } |
| 82 | |
Amin Shaikh | f5830ca | 2018-03-09 14:06:50 -0500 | [diff] [blame] | 83 | |
| 84 | @Test |
| 85 | public void testHspaPlusDataIcon() { |
| 86 | setupDefaultSignal(); |
| 87 | updateDataConnectionState(TelephonyManager.DATA_CONNECTED, |
| 88 | TelephonyManager.NETWORK_TYPE_HSPAP); |
| 89 | |
| 90 | verifyDataIndicators(TelephonyIcons.ICON_H_PLUS); |
| 91 | } |
| 92 | |
| 93 | |
Geoffrey Pitsch | 2c403db | 2016-08-26 09:09:39 -0400 | [diff] [blame] | 94 | @Test |
Jason Monk | 7150d7f | 2015-07-09 10:14:12 -0400 | [diff] [blame] | 95 | public void testWfcNoDataIcon() { |
| 96 | setupDefaultSignal(); |
| 97 | updateDataConnectionState(TelephonyManager.DATA_CONNECTED, |
| 98 | TelephonyManager.NETWORK_TYPE_IWLAN); |
| 99 | |
Amin Shaikh | d64e626 | 2018-03-08 10:08:13 -0500 | [diff] [blame] | 100 | verifyDataIndicators(0); |
Jason Monk | 7150d7f | 2015-07-09 10:14:12 -0400 | [diff] [blame] | 101 | } |
| 102 | |
Geoffrey Pitsch | 2c403db | 2016-08-26 09:09:39 -0400 | [diff] [blame] | 103 | @Test |
Jason Monk | 3aaabd7 | 2014-12-12 11:11:44 -0500 | [diff] [blame] | 104 | public void test4gDataIcon() { |
| 105 | // Switch to showing 4g icon and re-initialize the NetworkController. |
| 106 | mConfig.show4gForLte = true; |
Sundeep Ghuman | 9d10a3c | 2017-06-16 00:05:16 +0000 | [diff] [blame] | 107 | mNetworkController = new NetworkControllerImpl(mContext, mMockCm, mMockTm, mMockWm, mMockSm, |
Jason Monk | 07b75fe | 2015-05-14 16:47:03 -0400 | [diff] [blame] | 108 | mConfig, Looper.getMainLooper(), mCallbackHandler, |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 109 | mock(AccessPointControllerImpl.class), |
| 110 | mock(DataUsageController.class), mMockSubDefaults, |
| 111 | mock(DeviceProvisionedController.class)); |
Jason Monk | 3aaabd7 | 2014-12-12 11:11:44 -0500 | [diff] [blame] | 112 | setupNetworkController(); |
| 113 | |
| 114 | setupDefaultSignal(); |
| 115 | updateDataConnectionState(TelephonyManager.DATA_CONNECTED, |
| 116 | TelephonyManager.NETWORK_TYPE_LTE); |
| 117 | |
Amin Shaikh | d64e626 | 2018-03-08 10:08:13 -0500 | [diff] [blame] | 118 | verifyDataIndicators(TelephonyIcons.ICON_4G); |
Jason Monk | 3aaabd7 | 2014-12-12 11:11:44 -0500 | [diff] [blame] | 119 | } |
| 120 | |
Geoffrey Pitsch | 2c403db | 2016-08-26 09:09:39 -0400 | [diff] [blame] | 121 | @Test |
Fabian Kozynski | c7bc84b | 2019-03-11 13:57:31 -0400 | [diff] [blame] | 122 | public void testNoInternetIcon_withDefaultSub() { |
Amin Shaikh | af4c193 | 2018-03-08 10:29:56 -0500 | [diff] [blame] | 123 | setupNetworkController(); |
Malcolm Chen | 04be9d1 | 2019-06-11 19:48:38 -0700 | [diff] [blame] | 124 | when(mMockTm.isDataCapable()).thenReturn(false); |
Amin Shaikh | af4c193 | 2018-03-08 10:29:56 -0500 | [diff] [blame] | 125 | setupDefaultSignal(); |
| 126 | updateDataConnectionState(TelephonyManager.DATA_CONNECTED, 0); |
Anarghya Mitra | 678722f | 2018-05-11 14:29:54 -0700 | [diff] [blame] | 127 | setConnectivityViaBroadcast(NetworkCapabilities.TRANSPORT_CELLULAR, false, false); |
Amin Shaikh | af4c193 | 2018-03-08 10:29:56 -0500 | [diff] [blame] | 128 | |
| 129 | // Verify that a SignalDrawable with a cut out is used to display data disabled. |
| 130 | verifyLastMobileDataIndicators(true, DEFAULT_SIGNAL_STRENGTH, 0, |
| 131 | true, DEFAULT_QS_SIGNAL_STRENGTH, 0, false, |
Fabian Kozynski | c7bc84b | 2019-03-11 13:57:31 -0400 | [diff] [blame] | 132 | false, true, NO_DATA_STRING); |
Amin Shaikh | af4c193 | 2018-03-08 10:29:56 -0500 | [diff] [blame] | 133 | } |
| 134 | |
| 135 | @Test |
Fabian Kozynski | c7bc84b | 2019-03-11 13:57:31 -0400 | [diff] [blame] | 136 | public void testDataDisabledIcon_withDefaultSub() { |
Jason Monk | fd57ea7 | 2016-04-29 13:37:58 -0400 | [diff] [blame] | 137 | setupNetworkController(); |
Malcolm Chen | 04be9d1 | 2019-06-11 19:48:38 -0700 | [diff] [blame] | 138 | when(mMockTm.isDataCapable()).thenReturn(false); |
Jason Monk | fd57ea7 | 2016-04-29 13:37:58 -0400 | [diff] [blame] | 139 | setupDefaultSignal(); |
| 140 | updateDataConnectionState(TelephonyManager.DATA_DISCONNECTED, 0); |
Anarghya Mitra | 678722f | 2018-05-11 14:29:54 -0700 | [diff] [blame] | 141 | setConnectivityViaBroadcast(NetworkCapabilities.TRANSPORT_CELLULAR, false, false); |
Jason Monk | fd57ea7 | 2016-04-29 13:37:58 -0400 | [diff] [blame] | 142 | |
Amin Shaikh | af4c193 | 2018-03-08 10:29:56 -0500 | [diff] [blame] | 143 | // Verify that a SignalDrawable with a cut out is used to display data disabled. |
| 144 | verifyLastMobileDataIndicators(true, DEFAULT_SIGNAL_STRENGTH, 0, |
| 145 | true, DEFAULT_QS_SIGNAL_STRENGTH, 0, false, |
Fabian Kozynski | c7bc84b | 2019-03-11 13:57:31 -0400 | [diff] [blame] | 146 | false, true, NO_DATA_STRING); |
| 147 | } |
| 148 | |
| 149 | @Test |
Evan Laird | 2ea99c1 | 2019-09-19 16:52:58 -0400 | [diff] [blame] | 150 | public void testNonDefaultSIM_showsFullSignal_connected() { |
Fabian Kozynski | c7bc84b | 2019-03-11 13:57:31 -0400 | [diff] [blame] | 151 | setupNetworkController(); |
Malcolm Chen | 04be9d1 | 2019-06-11 19:48:38 -0700 | [diff] [blame] | 152 | when(mMockTm.isDataCapable()).thenReturn(false); |
Fabian Kozynski | c7bc84b | 2019-03-11 13:57:31 -0400 | [diff] [blame] | 153 | setupDefaultSignal(); |
| 154 | setDefaultSubId(mSubId + 1); |
| 155 | updateDataConnectionState(TelephonyManager.DATA_CONNECTED, 0); |
| 156 | setConnectivityViaBroadcast(NetworkCapabilities.TRANSPORT_CELLULAR, false, false); |
| 157 | |
| 158 | // Verify that a SignalDrawable with a cut out is used to display data disabled. |
| 159 | verifyLastMobileDataIndicators(true, DEFAULT_SIGNAL_STRENGTH, 0, |
| 160 | true, DEFAULT_QS_SIGNAL_STRENGTH, 0, false, |
Evan Laird | 2ea99c1 | 2019-09-19 16:52:58 -0400 | [diff] [blame] | 161 | false, false, NOT_DEFAULT_DATA_STRING); |
Fabian Kozynski | c7bc84b | 2019-03-11 13:57:31 -0400 | [diff] [blame] | 162 | } |
| 163 | |
| 164 | @Test |
Evan Laird | 2ea99c1 | 2019-09-19 16:52:58 -0400 | [diff] [blame] | 165 | public void testNonDefaultSIM_showsFullSignal_disconnected() { |
Fabian Kozynski | c7bc84b | 2019-03-11 13:57:31 -0400 | [diff] [blame] | 166 | setupNetworkController(); |
Malcolm Chen | 04be9d1 | 2019-06-11 19:48:38 -0700 | [diff] [blame] | 167 | when(mMockTm.isDataCapable()).thenReturn(false); |
Fabian Kozynski | c7bc84b | 2019-03-11 13:57:31 -0400 | [diff] [blame] | 168 | setupDefaultSignal(); |
| 169 | setDefaultSubId(mSubId + 1); |
| 170 | updateDataConnectionState(TelephonyManager.DATA_DISCONNECTED, 0); |
| 171 | setConnectivityViaBroadcast(NetworkCapabilities.TRANSPORT_CELLULAR, false, false); |
| 172 | |
| 173 | // Verify that a SignalDrawable with a cut out is used to display data disabled. |
| 174 | verifyLastMobileDataIndicators(true, DEFAULT_SIGNAL_STRENGTH, 0, |
| 175 | true, DEFAULT_QS_SIGNAL_STRENGTH, 0, false, |
Evan Laird | 2ea99c1 | 2019-09-19 16:52:58 -0400 | [diff] [blame] | 176 | false, false, NOT_DEFAULT_DATA_STRING); |
Jason Monk | fd57ea7 | 2016-04-29 13:37:58 -0400 | [diff] [blame] | 177 | } |
| 178 | |
Geoffrey Pitsch | 2c403db | 2016-08-26 09:09:39 -0400 | [diff] [blame] | 179 | @Test |
SongFerngWang | 52dada7 | 2019-08-14 16:59:29 +0800 | [diff] [blame] | 180 | public void testNr5GIcon_NrNotRestrictedRrcCon_show5GIcon() { |
| 181 | setupNr5GIconConfigurationForNotRestrictedRrcCon(); |
| 182 | setupDefaultSignal(); |
| 183 | updateDataConnectionState(TelephonyManager.DATA_CONNECTED, |
| 184 | TelephonyManager.NETWORK_TYPE_LTE); |
| 185 | updateDataActivity(TelephonyManager.DATA_ACTIVITY_INOUT); |
| 186 | ServiceState ss = Mockito.mock(ServiceState.class); |
| 187 | doReturn(NetworkRegistrationInfo.NR_STATE_NOT_RESTRICTED).when(ss).getNrState(); |
| 188 | mPhoneStateListener.onServiceStateChanged(ss); |
| 189 | |
| 190 | verifyLastMobileDataIndicators(true, DEFAULT_SIGNAL_STRENGTH, TelephonyIcons.ICON_5G, |
| 191 | true, DEFAULT_QS_SIGNAL_STRENGTH, TelephonyIcons.ICON_5G, true, true); |
| 192 | } |
| 193 | |
| 194 | @Test |
| 195 | public void testNr5GIcon_NrNotRestrictedRrcIdle_show5GIcon() { |
| 196 | setupNr5GIconConfigurationForNotRestrictedRrcIdle(); |
| 197 | setupDefaultSignal(); |
| 198 | updateDataConnectionState(TelephonyManager.DATA_CONNECTED, |
| 199 | TelephonyManager.NETWORK_TYPE_LTE); |
| 200 | updateDataActivity(TelephonyManager.DATA_ACTIVITY_DORMANT); |
| 201 | ServiceState ss = Mockito.mock(ServiceState.class); |
| 202 | doReturn(NetworkRegistrationInfo.NR_STATE_NOT_RESTRICTED).when(ss).getNrState(); |
| 203 | mPhoneStateListener.onServiceStateChanged(ss); |
| 204 | |
| 205 | verifyDataIndicators(TelephonyIcons.ICON_5G); |
| 206 | } |
| 207 | |
| 208 | @Test |
Pengquan Meng | a62d32b | 2018-12-06 17:38:38 -0800 | [diff] [blame] | 209 | public void testNr5GIcon_NrConnectedWithoutMMWave_show5GIcon() { |
| 210 | setupDefaultNr5GIconConfiguration(); |
| 211 | setupDefaultSignal(); |
| 212 | updateDataConnectionState(TelephonyManager.DATA_CONNECTED, |
| 213 | TelephonyManager.NETWORK_TYPE_LTE); |
| 214 | ServiceState ss = Mockito.mock(ServiceState.class); |
Jack Yu | 20d7140 | 2019-03-16 23:00:35 -0700 | [diff] [blame] | 215 | doReturn(NetworkRegistrationInfo.NR_STATE_CONNECTED).when(ss).getNrState(); |
Pengquan Meng | a62d32b | 2018-12-06 17:38:38 -0800 | [diff] [blame] | 216 | doReturn(ServiceState.FREQUENCY_RANGE_HIGH).when(ss).getNrFrequencyRange(); |
| 217 | mPhoneStateListener.onServiceStateChanged(ss); |
| 218 | |
| 219 | verifyDataIndicators(TelephonyIcons.ICON_5G); |
| 220 | } |
| 221 | |
| 222 | @Test |
| 223 | public void testNr5GIcon_NrConnectedWithMMWave_show5GPlusIcon() { |
| 224 | setupDefaultNr5GIconConfiguration(); |
| 225 | setupDefaultSignal(); |
| 226 | updateDataConnectionState(TelephonyManager.DATA_CONNECTED, |
| 227 | TelephonyManager.NETWORK_TYPE_LTE); |
| 228 | ServiceState ss = Mockito.mock(ServiceState.class); |
Jack Yu | 20d7140 | 2019-03-16 23:00:35 -0700 | [diff] [blame] | 229 | doReturn(NetworkRegistrationInfo.NR_STATE_CONNECTED).when(ss).getNrState(); |
Pengquan Meng | a62d32b | 2018-12-06 17:38:38 -0800 | [diff] [blame] | 230 | doReturn(ServiceState.FREQUENCY_RANGE_MMWAVE).when(ss).getNrFrequencyRange(); |
| 231 | mPhoneStateListener.onServiceStateChanged(ss); |
| 232 | |
| 233 | verifyDataIndicators(TelephonyIcons.ICON_5G_PLUS); |
| 234 | } |
| 235 | |
| 236 | @Test |
| 237 | public void testNr5GIcon_NrRestricted_showLteIcon() { |
| 238 | setupDefaultNr5GIconConfiguration(); |
| 239 | setupDefaultSignal(); |
| 240 | updateDataConnectionState(TelephonyManager.DATA_CONNECTED, |
| 241 | TelephonyManager.NETWORK_TYPE_LTE); |
| 242 | ServiceState ss = Mockito.mock(ServiceState.class); |
Jack Yu | 20d7140 | 2019-03-16 23:00:35 -0700 | [diff] [blame] | 243 | doReturn(NetworkRegistrationInfo.NR_STATE_RESTRICTED).when(ss).getNrState(); |
Pengquan Meng | a62d32b | 2018-12-06 17:38:38 -0800 | [diff] [blame] | 244 | mPhoneStateListener.onServiceStateChanged(mServiceState); |
| 245 | |
| 246 | verifyDataIndicators(TelephonyIcons.ICON_LTE); |
| 247 | } |
| 248 | |
| 249 | @Test |
Bill Lin | 767c0db | 2019-08-15 20:42:06 +0800 | [diff] [blame] | 250 | public void testNr5GIcon_displayGracePeriodTime_enabled() { |
| 251 | setupDefaultNr5GIconConfiguration(); |
| 252 | setupDefaultNr5GIconDisplayGracePeriodTime_enableThirtySeconds(); |
| 253 | setupDefaultSignal(); |
| 254 | mNetworkController.handleConfigurationChanged(); |
| 255 | mPhoneStateListener.onServiceStateChanged(mServiceState); |
| 256 | |
| 257 | ServiceState ss = Mockito.mock(ServiceState.class); |
| 258 | // While nrIconDisplayGracePeriodMs > 0 & is Nr5G, mIsShowingIconGracefully should be true |
| 259 | doReturn(NetworkRegistrationInfo.NR_STATE_CONNECTED).when(ss).getNrState(); |
| 260 | doReturn(ServiceState.FREQUENCY_RANGE_HIGH).when(ss).getNrFrequencyRange(); |
| 261 | mPhoneStateListener.onDataConnectionStateChanged(TelephonyManager.DATA_CONNECTED, |
| 262 | TelephonyManager.NETWORK_TYPE_LTE); |
| 263 | mPhoneStateListener.onServiceStateChanged(ss); |
| 264 | |
| 265 | assertTrue(mConfig.nrIconDisplayGracePeriodMs > 0); |
| 266 | assertTrue(mMobileSignalController.mIsShowingIconGracefully); |
| 267 | } |
| 268 | |
| 269 | @Test |
| 270 | public void testNr5GIcon_displayGracePeriodTime_disabled() { |
| 271 | setupDefaultNr5GIconConfiguration(); |
| 272 | setupDefaultNr5GIconDisplayGracePeriodTime_disabled(); |
| 273 | setupDefaultSignal(); |
| 274 | |
| 275 | assertTrue(mConfig.nrIconDisplayGracePeriodMs == 0); |
| 276 | |
| 277 | // While nrIconDisplayGracePeriodMs <= 0, mIsShowingIconGracefully should be false |
| 278 | doReturn(NetworkRegistrationInfo.NR_STATE_CONNECTED).when(mServiceState).getNrState(); |
| 279 | doReturn(ServiceState.FREQUENCY_RANGE_HIGH).when(mServiceState).getNrFrequencyRange(); |
| 280 | mPhoneStateListener.onDataConnectionStateChanged(TelephonyManager.DATA_CONNECTED, |
| 281 | TelephonyManager.NETWORK_TYPE_LTE); |
| 282 | |
| 283 | assertFalse(mMobileSignalController.mIsShowingIconGracefully); |
| 284 | } |
| 285 | |
| 286 | @Test |
| 287 | public void testNr5GIcon_enableDisplayGracePeriodTime_showIconGracefully() { |
| 288 | setupDefaultNr5GIconConfiguration(); |
| 289 | setupDefaultNr5GIconDisplayGracePeriodTime_enableThirtySeconds(); |
| 290 | setupDefaultSignal(); |
| 291 | mNetworkController.handleConfigurationChanged(); |
| 292 | mPhoneStateListener.onServiceStateChanged(mServiceState); |
| 293 | |
| 294 | ServiceState ss = Mockito.mock(ServiceState.class); |
| 295 | doReturn(NetworkRegistrationInfo.NR_STATE_CONNECTED).when(ss).getNrState(); |
| 296 | doReturn(ServiceState.FREQUENCY_RANGE_HIGH).when(ss).getNrFrequencyRange(); |
| 297 | mPhoneStateListener.onDataConnectionStateChanged(TelephonyManager.DATA_CONNECTED, |
| 298 | TelephonyManager.NETWORK_TYPE_LTE); |
| 299 | mPhoneStateListener.onServiceStateChanged(ss); |
| 300 | |
| 301 | verifyDataIndicators(TelephonyIcons.ICON_5G); |
| 302 | |
| 303 | // Enabled timer Nr5G switch to None Nr5G, showing 5G icon gracefully |
| 304 | ServiceState ssLte = Mockito.mock(ServiceState.class); |
| 305 | doReturn(NetworkRegistrationInfo.NR_STATE_NONE).when(ssLte).getNrState(); |
| 306 | doReturn(ServiceState.FREQUENCY_RANGE_UNKNOWN).when(ssLte).getNrFrequencyRange(); |
| 307 | mPhoneStateListener.onDataConnectionStateChanged(TelephonyManager.DATA_CONNECTED, |
| 308 | TelephonyManager.NETWORK_TYPE_LTE); |
| 309 | mPhoneStateListener.onServiceStateChanged(ssLte); |
| 310 | |
| 311 | verifyDataIndicators(TelephonyIcons.ICON_5G); |
| 312 | } |
| 313 | |
| 314 | @Test |
| 315 | public void testNr5GIcon_disableDisplayGracePeriodTime_showLatestIconImmediately() { |
| 316 | setupDefaultNr5GIconConfiguration(); |
| 317 | setupDefaultNr5GIconDisplayGracePeriodTime_disabled(); |
| 318 | setupDefaultSignal(); |
| 319 | mNetworkController.handleConfigurationChanged(); |
| 320 | |
| 321 | doReturn(NetworkRegistrationInfo.NR_STATE_CONNECTED).when(mServiceState).getNrState(); |
| 322 | doReturn(ServiceState.FREQUENCY_RANGE_HIGH).when(mServiceState).getNrFrequencyRange(); |
| 323 | mPhoneStateListener.onDataConnectionStateChanged(TelephonyManager.DATA_CONNECTED, |
| 324 | TelephonyManager.NETWORK_TYPE_LTE); |
| 325 | |
| 326 | verifyDataIndicators(TelephonyIcons.ICON_5G); |
| 327 | |
| 328 | doReturn(NetworkRegistrationInfo.NR_STATE_NONE).when(mServiceState).getNrState(); |
| 329 | doReturn(ServiceState.FREQUENCY_RANGE_UNKNOWN).when(mServiceState).getNrFrequencyRange(); |
| 330 | mPhoneStateListener.onDataConnectionStateChanged(TelephonyManager.DATA_CONNECTED, |
| 331 | TelephonyManager.NETWORK_TYPE_LTE); |
| 332 | |
| 333 | verifyDataIndicators(TelephonyIcons.ICON_LTE); |
| 334 | } |
| 335 | |
| 336 | @Test |
| 337 | public void testNr5GIcon_resetDisplayGracePeriodTime_whenDataDisconnected() { |
| 338 | setupDefaultNr5GIconConfiguration(); |
| 339 | setupDefaultNr5GIconDisplayGracePeriodTime_enableThirtySeconds(); |
| 340 | setupDefaultSignal(); |
| 341 | mNetworkController.handleConfigurationChanged(); |
| 342 | doReturn(NetworkRegistrationInfo.NR_STATE_CONNECTED).when(mServiceState).getNrState(); |
| 343 | doReturn(ServiceState.FREQUENCY_RANGE_HIGH).when(mServiceState).getNrFrequencyRange(); |
| 344 | mPhoneStateListener.onDataConnectionStateChanged(TelephonyManager.DATA_CONNECTED, |
| 345 | TelephonyManager.NETWORK_TYPE_LTE); |
| 346 | |
| 347 | verifyDataIndicators(TelephonyIcons.ICON_5G); |
| 348 | |
| 349 | // Disabled timer, when out of service, reset timer to display latest state |
| 350 | updateDataConnectionState(TelephonyManager.DATA_CONNECTED, |
| 351 | TelephonyManager.NETWORK_TYPE_LTE); |
| 352 | doReturn(NetworkRegistrationInfo.NR_STATE_NONE).when(mServiceState).getNrState(); |
| 353 | doReturn(ServiceState.FREQUENCY_RANGE_UNKNOWN).when(mServiceState).getNrFrequencyRange(); |
| 354 | mPhoneStateListener.onDataConnectionStateChanged(TelephonyManager.DATA_DISCONNECTED, |
| 355 | TelephonyManager.NETWORK_TYPE_UMTS); |
| 356 | |
| 357 | verifyDataIndicators(0); |
| 358 | } |
| 359 | |
| 360 | @Test |
| 361 | public void testNr5GIcon_enableDisplayGracePeriodTime_show5G_switching_5GPlus() { |
| 362 | setupDefaultNr5GIconConfiguration(); |
| 363 | setupDefaultNr5GIconDisplayGracePeriodTime_enableThirtySeconds(); |
| 364 | setupDefaultSignal(); |
| 365 | mNetworkController.handleConfigurationChanged(); |
| 366 | mPhoneStateListener.onServiceStateChanged(mServiceState); |
| 367 | |
| 368 | ServiceState ss5G = Mockito.mock(ServiceState.class); |
| 369 | doReturn(NetworkRegistrationInfo.NR_STATE_CONNECTED).when(ss5G).getNrState(); |
| 370 | doReturn(ServiceState.FREQUENCY_RANGE_HIGH).when(ss5G).getNrFrequencyRange(); |
| 371 | mPhoneStateListener.onDataConnectionStateChanged(TelephonyManager.DATA_CONNECTED, |
| 372 | TelephonyManager.NETWORK_TYPE_LTE); |
| 373 | mPhoneStateListener.onServiceStateChanged(ss5G); |
| 374 | |
| 375 | verifyDataIndicators(TelephonyIcons.ICON_5G); |
| 376 | |
| 377 | // When timeout enabled, 5G/5G+ switching should be updated immediately |
| 378 | ServiceState ss5GPlus = Mockito.mock(ServiceState.class); |
| 379 | doReturn(NetworkRegistrationInfo.NR_STATE_CONNECTED).when(ss5GPlus).getNrState(); |
| 380 | doReturn(ServiceState.FREQUENCY_RANGE_MMWAVE).when(ss5GPlus).getNrFrequencyRange(); |
| 381 | mPhoneStateListener.onDataConnectionStateChanged(TelephonyManager.DATA_CONNECTED, |
| 382 | TelephonyManager.NETWORK_TYPE_LTE); |
| 383 | mPhoneStateListener.onServiceStateChanged(ss5GPlus); |
| 384 | |
| 385 | verifyDataIndicators(TelephonyIcons.ICON_5G_PLUS); |
| 386 | } |
| 387 | |
| 388 | @Test |
| 389 | public void testNr5GIcon_carrierDisabledDisplayGracePeriodTime_shouldUpdateIconImmediately() { |
| 390 | setupDefaultNr5GIconConfiguration(); |
| 391 | setupDefaultNr5GIconDisplayGracePeriodTime_enableThirtySeconds(); |
| 392 | setupDefaultSignal(); |
| 393 | mNetworkController.handleConfigurationChanged(); |
| 394 | mPhoneStateListener.onServiceStateChanged(mServiceState); |
| 395 | |
| 396 | ServiceState ss5G = Mockito.mock(ServiceState.class); |
| 397 | doReturn(NetworkRegistrationInfo.NR_STATE_CONNECTED).when(ss5G).getNrState(); |
| 398 | doReturn(ServiceState.FREQUENCY_RANGE_HIGH).when(ss5G).getNrFrequencyRange(); |
| 399 | mPhoneStateListener.onDataConnectionStateChanged(TelephonyManager.DATA_CONNECTED, |
| 400 | TelephonyManager.NETWORK_TYPE_LTE); |
| 401 | mPhoneStateListener.onServiceStateChanged(ss5G); |
| 402 | |
| 403 | verifyDataIndicators(TelephonyIcons.ICON_5G); |
| 404 | |
| 405 | // State from NR_5G to NONE NR_5G with timeout, should show previous 5G icon |
| 406 | ServiceState ssLte = Mockito.mock(ServiceState.class); |
| 407 | doReturn(NetworkRegistrationInfo.NR_STATE_NONE).when(ssLte).getNrState(); |
| 408 | doReturn(ServiceState.FREQUENCY_RANGE_UNKNOWN).when(ssLte).getNrFrequencyRange(); |
| 409 | mPhoneStateListener.onDataConnectionStateChanged(TelephonyManager.DATA_CONNECTED, |
| 410 | TelephonyManager.NETWORK_TYPE_LTE); |
| 411 | mPhoneStateListener.onServiceStateChanged(ssLte); |
| 412 | |
| 413 | verifyDataIndicators(TelephonyIcons.ICON_5G); |
| 414 | |
| 415 | // Update nrIconDisplayGracePeriodMs to 0 |
| 416 | setupDefaultNr5GIconDisplayGracePeriodTime_disabled(); |
| 417 | mNetworkController.handleConfigurationChanged(); |
| 418 | |
| 419 | // State from NR_5G to NONE NR_STATE_RESTRICTED, showing corresponding icon |
| 420 | doReturn(NetworkRegistrationInfo.NR_STATE_RESTRICTED).when(mServiceState).getNrState(); |
| 421 | doReturn(TelephonyManager.NETWORK_TYPE_LTE).when(mServiceState).getDataNetworkType(); |
| 422 | mPhoneStateListener.onDataConnectionStateChanged(TelephonyManager.DATA_CONNECTED, |
| 423 | TelephonyManager.NETWORK_TYPE_LTE); |
| 424 | |
| 425 | assertTrue(mConfig.nrIconDisplayGracePeriodMs == 0); |
| 426 | verifyDataIndicators(TelephonyIcons.ICON_LTE); |
| 427 | } |
| 428 | |
| 429 | @Test |
Jason Monk | fd57ea7 | 2016-04-29 13:37:58 -0400 | [diff] [blame] | 430 | public void testDataDisabledIcon_UserNotSetup() { |
| 431 | setupNetworkController(); |
Malcolm Chen | 04be9d1 | 2019-06-11 19:48:38 -0700 | [diff] [blame] | 432 | when(mMockTm.isDataCapable()).thenReturn(false); |
Jason Monk | fd57ea7 | 2016-04-29 13:37:58 -0400 | [diff] [blame] | 433 | setupDefaultSignal(); |
| 434 | updateDataConnectionState(TelephonyManager.DATA_DISCONNECTED, 0); |
Anarghya Mitra | 678722f | 2018-05-11 14:29:54 -0700 | [diff] [blame] | 435 | setConnectivityViaBroadcast(NetworkCapabilities.TRANSPORT_CELLULAR, false, false); |
Jason Monk | 0288de0 | 2017-02-23 14:48:05 -0500 | [diff] [blame] | 436 | when(mMockProvisionController.isUserSetup(anyInt())).thenReturn(false); |
| 437 | mUserCallback.onUserSetupChanged(); |
Jason Monk | 2515f47 | 2017-09-19 09:52:43 -0400 | [diff] [blame] | 438 | TestableLooper.get(this).processAllMessages(); |
Jason Monk | fd57ea7 | 2016-04-29 13:37:58 -0400 | [diff] [blame] | 439 | |
| 440 | // Don't show the X until the device is setup. |
Amin Shaikh | d64e626 | 2018-03-08 10:08:13 -0500 | [diff] [blame] | 441 | verifyDataIndicators(0); |
Jason Monk | fd57ea7 | 2016-04-29 13:37:58 -0400 | [diff] [blame] | 442 | } |
| 443 | |
Geoffrey Pitsch | 2c403db | 2016-08-26 09:09:39 -0400 | [diff] [blame] | 444 | @Test |
Wenting Xiong | 63364fe | 2017-02-07 19:12:27 +0800 | [diff] [blame] | 445 | public void testAlwaysShowDataRatIcon() { |
| 446 | setupDefaultSignal(); |
Malcolm Chen | 04be9d1 | 2019-06-11 19:48:38 -0700 | [diff] [blame] | 447 | when(mMockTm.isDataCapable()).thenReturn(false); |
Wenting Xiong | 63364fe | 2017-02-07 19:12:27 +0800 | [diff] [blame] | 448 | updateDataConnectionState(TelephonyManager.DATA_DISCONNECTED, |
| 449 | TelephonyManager.NETWORK_TYPE_GSM); |
| 450 | |
| 451 | // Switch to showing data RAT icon when data is disconnected |
| 452 | // and re-initialize the NetworkController. |
| 453 | mConfig.alwaysShowDataRatIcon = true; |
| 454 | mNetworkController.handleConfigurationChanged(); |
| 455 | |
Amin Shaikh | d64e626 | 2018-03-08 10:08:13 -0500 | [diff] [blame] | 456 | verifyDataIndicators(TelephonyIcons.ICON_G); |
Wenting Xiong | 63364fe | 2017-02-07 19:12:27 +0800 | [diff] [blame] | 457 | } |
| 458 | |
| 459 | @Test |
Jason Monk | 3aaabd7 | 2014-12-12 11:11:44 -0500 | [diff] [blame] | 460 | public void test4gDataIconConfigChange() { |
| 461 | setupDefaultSignal(); |
| 462 | updateDataConnectionState(TelephonyManager.DATA_CONNECTED, |
| 463 | TelephonyManager.NETWORK_TYPE_LTE); |
| 464 | |
| 465 | // Switch to showing 4g icon and re-initialize the NetworkController. |
| 466 | mConfig.show4gForLte = true; |
| 467 | // Can't send the broadcast as that would actually read the config from |
| 468 | // the context. Instead we'll just poke at a function that does all of |
| 469 | // the after work. |
| 470 | mNetworkController.handleConfigurationChanged(); |
| 471 | |
Amin Shaikh | d64e626 | 2018-03-08 10:08:13 -0500 | [diff] [blame] | 472 | verifyDataIndicators(TelephonyIcons.ICON_4G); |
Jason Monk | 3aaabd7 | 2014-12-12 11:11:44 -0500 | [diff] [blame] | 473 | } |
| 474 | |
Geoffrey Pitsch | 2c403db | 2016-08-26 09:09:39 -0400 | [diff] [blame] | 475 | @Test |
Jason Monk | 67b2c16 | 2016-01-12 10:24:09 -0500 | [diff] [blame] | 476 | public void testDataChangeWithoutConnectionState() { |
| 477 | setupDefaultSignal(); |
| 478 | updateDataConnectionState(TelephonyManager.DATA_CONNECTED, |
| 479 | TelephonyManager.NETWORK_TYPE_LTE); |
| 480 | |
Amin Shaikh | d64e626 | 2018-03-08 10:08:13 -0500 | [diff] [blame] | 481 | verifyDataIndicators(TelephonyIcons.ICON_LTE); |
Jason Monk | 67b2c16 | 2016-01-12 10:24:09 -0500 | [diff] [blame] | 482 | |
Jason Monk | 0288de0 | 2017-02-23 14:48:05 -0500 | [diff] [blame] | 483 | when(mServiceState.getDataNetworkType()) |
Jason Monk | 67b2c16 | 2016-01-12 10:24:09 -0500 | [diff] [blame] | 484 | .thenReturn(TelephonyManager.NETWORK_TYPE_HSPA); |
| 485 | updateServiceState(); |
Amin Shaikh | d64e626 | 2018-03-08 10:08:13 -0500 | [diff] [blame] | 486 | verifyDataIndicators(TelephonyIcons.ICON_H); |
Jason Monk | 67b2c16 | 2016-01-12 10:24:09 -0500 | [diff] [blame] | 487 | } |
| 488 | |
Geoffrey Pitsch | 2c403db | 2016-08-26 09:09:39 -0400 | [diff] [blame] | 489 | @Test |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 490 | public void testDataActivity() { |
| 491 | setupDefaultSignal(); |
| 492 | |
| 493 | testDataActivity(TelephonyManager.DATA_ACTIVITY_NONE, false, false); |
| 494 | testDataActivity(TelephonyManager.DATA_ACTIVITY_IN, true, false); |
| 495 | testDataActivity(TelephonyManager.DATA_ACTIVITY_OUT, false, true); |
| 496 | testDataActivity(TelephonyManager.DATA_ACTIVITY_INOUT, true, true); |
| 497 | } |
| 498 | |
Fabian Kozynski | a909199 | 2019-03-25 11:08:32 -0400 | [diff] [blame] | 499 | @Test |
| 500 | public void testUpdateDataNetworkName() { |
| 501 | setupDefaultSignal(); |
| 502 | String newDataName = "TestDataName"; |
SongFerngWang | afd025f | 2019-11-20 02:11:09 +0800 | [diff] [blame] | 503 | when(mServiceState.getOperatorAlphaShort()).thenReturn(newDataName); |
Fabian Kozynski | a909199 | 2019-03-25 11:08:32 -0400 | [diff] [blame] | 504 | updateServiceState(); |
| 505 | assertDataNetworkNameEquals(newDataName); |
| 506 | } |
| 507 | |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 508 | private void testDataActivity(int direction, boolean in, boolean out) { |
| 509 | updateDataActivity(direction); |
| 510 | |
Jason Monk | 26ad85a | 2016-12-08 14:45:42 -0500 | [diff] [blame] | 511 | verifyLastMobileDataIndicators(true, DEFAULT_SIGNAL_STRENGTH, DEFAULT_ICON, true, |
Jason Monk | 7e6c83c | 2017-04-26 14:35:24 -0400 | [diff] [blame] | 512 | DEFAULT_QS_SIGNAL_STRENGTH, DEFAULT_QS_ICON, in, out); |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 513 | } |
| 514 | |
Amin Shaikh | d64e626 | 2018-03-08 10:08:13 -0500 | [diff] [blame] | 515 | private void verifyDataIndicators(int dataIcon) { |
Jason Monk | 26ad85a | 2016-12-08 14:45:42 -0500 | [diff] [blame] | 516 | verifyLastMobileDataIndicators(true, DEFAULT_SIGNAL_STRENGTH, dataIcon, |
Amin Shaikh | d64e626 | 2018-03-08 10:08:13 -0500 | [diff] [blame] | 517 | true, DEFAULT_QS_SIGNAL_STRENGTH, dataIcon, false, |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 518 | false); |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 519 | } |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 520 | } |