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; |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 4 | import static org.mockito.Mockito.mock; |
Jason Monk | 0288de0 | 2017-02-23 14:48:05 -0500 | [diff] [blame] | 5 | import static org.mockito.Mockito.when; |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 6 | |
Jason Monk | fd57ea7 | 2016-04-29 13:37:58 -0400 | [diff] [blame] | 7 | import android.net.NetworkCapabilities; |
Jason Monk | 07b75fe | 2015-05-14 16:47:03 -0400 | [diff] [blame] | 8 | import android.os.Looper; |
Geoffrey Pitsch | 2c403db | 2016-08-26 09:09:39 -0400 | [diff] [blame] | 9 | import android.support.test.runner.AndroidJUnit4; |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 10 | import android.telephony.TelephonyManager; |
Jason Monk | e427cb8 | 2015-07-28 09:18:08 -0400 | [diff] [blame] | 11 | import android.test.suitebuilder.annotation.SmallTest; |
Jason Monk | 2515f47 | 2017-09-19 09:52:43 -0400 | [diff] [blame] | 12 | import android.testing.AndroidTestingRunner; |
| 13 | import android.testing.TestableLooper; |
| 14 | import android.testing.TestableLooper.RunWithLooper; |
Jason Monk | 0288de0 | 2017-02-23 14:48:05 -0500 | [diff] [blame] | 15 | |
Jason Monk | f668d7cc | 2016-01-14 10:38:41 -0500 | [diff] [blame] | 16 | import com.android.settingslib.net.DataUsageController; |
Jason Monk | 0288de0 | 2017-02-23 14:48:05 -0500 | [diff] [blame] | 17 | |
Jason Monk | 28cc166 | 2017-03-02 10:57:36 -0500 | [diff] [blame] | 18 | import org.junit.Ignore; |
Geoffrey Pitsch | 2c403db | 2016-08-26 09:09:39 -0400 | [diff] [blame] | 19 | import org.junit.Test; |
| 20 | import org.junit.runner.RunWith; |
Jason Monk | 33f8ae7 | 2015-05-08 10:45:15 -0400 | [diff] [blame] | 21 | |
Jason Monk | e427cb8 | 2015-07-28 09:18:08 -0400 | [diff] [blame] | 22 | @SmallTest |
Jason Monk | 2515f47 | 2017-09-19 09:52:43 -0400 | [diff] [blame] | 23 | @RunWith(AndroidTestingRunner.class) |
| 24 | @RunWithLooper |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 25 | public class NetworkControllerDataTest extends NetworkControllerBaseTest { |
| 26 | |
Geoffrey Pitsch | 2c403db | 2016-08-26 09:09:39 -0400 | [diff] [blame] | 27 | @Test |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 28 | public void test3gDataIcon() { |
| 29 | setupDefaultSignal(); |
| 30 | |
Jason Monk | 48edc0c | 2017-04-10 15:01:27 -0400 | [diff] [blame] | 31 | verifyDataIndicators(TelephonyIcons.ICON_3G, |
Jason Monk | 01df36f | 2017-06-07 13:02:47 -0400 | [diff] [blame] | 32 | TelephonyIcons.QS_DATA_3G); |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 33 | } |
| 34 | |
Geoffrey Pitsch | 2c403db | 2016-08-26 09:09:39 -0400 | [diff] [blame] | 35 | @Test |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 36 | public void test2gDataIcon() { |
| 37 | setupDefaultSignal(); |
| 38 | updateDataConnectionState(TelephonyManager.DATA_CONNECTED, |
| 39 | TelephonyManager.NETWORK_TYPE_GSM); |
| 40 | |
Jason Monk | 48edc0c | 2017-04-10 15:01:27 -0400 | [diff] [blame] | 41 | verifyDataIndicators(TelephonyIcons.ICON_G, |
Jason Monk | 01df36f | 2017-06-07 13:02:47 -0400 | [diff] [blame] | 42 | TelephonyIcons.QS_DATA_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 | |
Jason Monk | 48edc0c | 2017-04-10 15:01:27 -0400 | [diff] [blame] | 51 | verifyDataIndicators(TelephonyIcons.ICON_1X, |
Jason Monk | 01df36f | 2017-06-07 13:02:47 -0400 | [diff] [blame] | 52 | TelephonyIcons.QS_DATA_1X); |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 53 | } |
| 54 | |
Geoffrey Pitsch | 2c403db | 2016-08-26 09:09:39 -0400 | [diff] [blame] | 55 | @Test |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 56 | public void testEdgeDataIcon() { |
| 57 | setupDefaultSignal(); |
| 58 | updateDataConnectionState(TelephonyManager.DATA_CONNECTED, |
| 59 | TelephonyManager.NETWORK_TYPE_EDGE); |
| 60 | |
Jason Monk | 48edc0c | 2017-04-10 15:01:27 -0400 | [diff] [blame] | 61 | verifyDataIndicators(TelephonyIcons.ICON_E, |
Jason Monk | 01df36f | 2017-06-07 13:02:47 -0400 | [diff] [blame] | 62 | TelephonyIcons.QS_DATA_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 | |
Jason Monk | 48edc0c | 2017-04-10 15:01:27 -0400 | [diff] [blame] | 71 | verifyDataIndicators(TelephonyIcons.ICON_LTE, |
Jason Monk | 01df36f | 2017-06-07 13:02:47 -0400 | [diff] [blame] | 72 | TelephonyIcons.QS_DATA_LTE); |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 73 | } |
| 74 | |
Geoffrey Pitsch | 2c403db | 2016-08-26 09:09:39 -0400 | [diff] [blame] | 75 | @Test |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 76 | public void testHspaDataIcon() { |
| 77 | setupDefaultSignal(); |
| 78 | updateDataConnectionState(TelephonyManager.DATA_CONNECTED, |
| 79 | TelephonyManager.NETWORK_TYPE_HSPA); |
| 80 | |
Jason Monk | 48edc0c | 2017-04-10 15:01:27 -0400 | [diff] [blame] | 81 | verifyDataIndicators(TelephonyIcons.ICON_H, |
Jason Monk | 01df36f | 2017-06-07 13:02:47 -0400 | [diff] [blame] | 82 | TelephonyIcons.QS_DATA_H); |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 83 | } |
| 84 | |
Geoffrey Pitsch | 2c403db | 2016-08-26 09:09:39 -0400 | [diff] [blame] | 85 | @Test |
Jason Monk | 7150d7f | 2015-07-09 10:14:12 -0400 | [diff] [blame] | 86 | public void testWfcNoDataIcon() { |
| 87 | setupDefaultSignal(); |
| 88 | updateDataConnectionState(TelephonyManager.DATA_CONNECTED, |
| 89 | TelephonyManager.NETWORK_TYPE_IWLAN); |
| 90 | |
| 91 | verifyDataIndicators(0, 0); |
| 92 | } |
| 93 | |
Geoffrey Pitsch | 2c403db | 2016-08-26 09:09:39 -0400 | [diff] [blame] | 94 | @Test |
Jason Monk | 3aaabd7 | 2014-12-12 11:11:44 -0500 | [diff] [blame] | 95 | public void test4gDataIcon() { |
| 96 | // Switch to showing 4g icon and re-initialize the NetworkController. |
| 97 | mConfig.show4gForLte = true; |
Sundeep Ghuman | 9d10a3c | 2017-06-16 00:05:16 +0000 | [diff] [blame] | 98 | mNetworkController = new NetworkControllerImpl(mContext, mMockCm, mMockTm, mMockWm, mMockSm, |
Jason Monk | 07b75fe | 2015-05-14 16:47:03 -0400 | [diff] [blame] | 99 | mConfig, Looper.getMainLooper(), mCallbackHandler, |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 100 | mock(AccessPointControllerImpl.class), |
| 101 | mock(DataUsageController.class), mMockSubDefaults, |
| 102 | mock(DeviceProvisionedController.class)); |
Jason Monk | 3aaabd7 | 2014-12-12 11:11:44 -0500 | [diff] [blame] | 103 | setupNetworkController(); |
| 104 | |
| 105 | setupDefaultSignal(); |
| 106 | updateDataConnectionState(TelephonyManager.DATA_CONNECTED, |
| 107 | TelephonyManager.NETWORK_TYPE_LTE); |
| 108 | |
Jason Monk | 48edc0c | 2017-04-10 15:01:27 -0400 | [diff] [blame] | 109 | verifyDataIndicators(TelephonyIcons.ICON_4G, |
Jason Monk | 01df36f | 2017-06-07 13:02:47 -0400 | [diff] [blame] | 110 | TelephonyIcons.QS_DATA_4G); |
Jason Monk | 3aaabd7 | 2014-12-12 11:11:44 -0500 | [diff] [blame] | 111 | } |
| 112 | |
Geoffrey Pitsch | 2c403db | 2016-08-26 09:09:39 -0400 | [diff] [blame] | 113 | @Test |
Amin Shaikh | af4c193 | 2018-03-08 10:29:56 -0500 | [diff] [blame^] | 114 | public void testNoInternetIcon() { |
| 115 | setupNetworkController(); |
| 116 | when(mMockTm.getDataEnabled(mSubId)).thenReturn(false); |
| 117 | setupDefaultSignal(); |
| 118 | updateDataConnectionState(TelephonyManager.DATA_CONNECTED, 0); |
| 119 | setConnectivity(NetworkCapabilities.TRANSPORT_CELLULAR, false, false); |
| 120 | |
| 121 | // Verify that a SignalDrawable with a cut out is used to display data disabled. |
| 122 | verifyLastMobileDataIndicators(true, DEFAULT_SIGNAL_STRENGTH, 0, |
| 123 | true, DEFAULT_QS_SIGNAL_STRENGTH, 0, false, |
| 124 | false, true); |
| 125 | } |
| 126 | |
| 127 | @Test |
Jason Monk | fd57ea7 | 2016-04-29 13:37:58 -0400 | [diff] [blame] | 128 | public void testDataDisabledIcon() { |
| 129 | setupNetworkController(); |
Jason Monk | 0288de0 | 2017-02-23 14:48:05 -0500 | [diff] [blame] | 130 | when(mMockTm.getDataEnabled(mSubId)).thenReturn(false); |
Jason Monk | fd57ea7 | 2016-04-29 13:37:58 -0400 | [diff] [blame] | 131 | setupDefaultSignal(); |
| 132 | updateDataConnectionState(TelephonyManager.DATA_DISCONNECTED, 0); |
| 133 | setConnectivity(NetworkCapabilities.TRANSPORT_CELLULAR, false, false); |
| 134 | |
Amin Shaikh | af4c193 | 2018-03-08 10:29:56 -0500 | [diff] [blame^] | 135 | // Verify that a SignalDrawable with a cut out is used to display data disabled. |
| 136 | verifyLastMobileDataIndicators(true, DEFAULT_SIGNAL_STRENGTH, 0, |
| 137 | true, DEFAULT_QS_SIGNAL_STRENGTH, 0, false, |
| 138 | false, true); |
Jason Monk | fd57ea7 | 2016-04-29 13:37:58 -0400 | [diff] [blame] | 139 | } |
| 140 | |
Geoffrey Pitsch | 2c403db | 2016-08-26 09:09:39 -0400 | [diff] [blame] | 141 | @Test |
Jason Monk | fd57ea7 | 2016-04-29 13:37:58 -0400 | [diff] [blame] | 142 | public void testDataDisabledIcon_UserNotSetup() { |
| 143 | setupNetworkController(); |
Jason Monk | 0288de0 | 2017-02-23 14:48:05 -0500 | [diff] [blame] | 144 | when(mMockTm.getDataEnabled(mSubId)).thenReturn(false); |
Jason Monk | fd57ea7 | 2016-04-29 13:37:58 -0400 | [diff] [blame] | 145 | setupDefaultSignal(); |
| 146 | updateDataConnectionState(TelephonyManager.DATA_DISCONNECTED, 0); |
| 147 | setConnectivity(NetworkCapabilities.TRANSPORT_CELLULAR, false, false); |
Jason Monk | 0288de0 | 2017-02-23 14:48:05 -0500 | [diff] [blame] | 148 | when(mMockProvisionController.isUserSetup(anyInt())).thenReturn(false); |
| 149 | mUserCallback.onUserSetupChanged(); |
Jason Monk | 2515f47 | 2017-09-19 09:52:43 -0400 | [diff] [blame] | 150 | TestableLooper.get(this).processAllMessages(); |
Jason Monk | fd57ea7 | 2016-04-29 13:37:58 -0400 | [diff] [blame] | 151 | |
| 152 | // Don't show the X until the device is setup. |
Jason Monk | 7e6c83c | 2017-04-26 14:35:24 -0400 | [diff] [blame] | 153 | verifyDataIndicators(0, 0); |
Jason Monk | fd57ea7 | 2016-04-29 13:37:58 -0400 | [diff] [blame] | 154 | } |
| 155 | |
Geoffrey Pitsch | 2c403db | 2016-08-26 09:09:39 -0400 | [diff] [blame] | 156 | @Test |
Wenting Xiong | 63364fe | 2017-02-07 19:12:27 +0800 | [diff] [blame] | 157 | public void testAlwaysShowDataRatIcon() { |
| 158 | setupDefaultSignal(); |
| 159 | when(mMockTm.getDataEnabled(mSubId)).thenReturn(false); |
| 160 | updateDataConnectionState(TelephonyManager.DATA_DISCONNECTED, |
| 161 | TelephonyManager.NETWORK_TYPE_GSM); |
| 162 | |
| 163 | // Switch to showing data RAT icon when data is disconnected |
| 164 | // and re-initialize the NetworkController. |
| 165 | mConfig.alwaysShowDataRatIcon = true; |
| 166 | mNetworkController.handleConfigurationChanged(); |
| 167 | |
| 168 | verifyDataIndicators(TelephonyIcons.ICON_G, |
| 169 | TelephonyIcons.QS_DATA_G); |
| 170 | } |
| 171 | |
| 172 | @Test |
Jason Monk | 3aaabd7 | 2014-12-12 11:11:44 -0500 | [diff] [blame] | 173 | public void test4gDataIconConfigChange() { |
| 174 | setupDefaultSignal(); |
| 175 | updateDataConnectionState(TelephonyManager.DATA_CONNECTED, |
| 176 | TelephonyManager.NETWORK_TYPE_LTE); |
| 177 | |
| 178 | // Switch to showing 4g icon and re-initialize the NetworkController. |
| 179 | mConfig.show4gForLte = true; |
| 180 | // Can't send the broadcast as that would actually read the config from |
| 181 | // the context. Instead we'll just poke at a function that does all of |
| 182 | // the after work. |
| 183 | mNetworkController.handleConfigurationChanged(); |
| 184 | |
Jason Monk | 48edc0c | 2017-04-10 15:01:27 -0400 | [diff] [blame] | 185 | verifyDataIndicators(TelephonyIcons.ICON_4G, |
Jason Monk | 01df36f | 2017-06-07 13:02:47 -0400 | [diff] [blame] | 186 | TelephonyIcons.QS_DATA_4G); |
Jason Monk | 3aaabd7 | 2014-12-12 11:11:44 -0500 | [diff] [blame] | 187 | } |
| 188 | |
Geoffrey Pitsch | 2c403db | 2016-08-26 09:09:39 -0400 | [diff] [blame] | 189 | @Test |
Jason Monk | 67b2c16 | 2016-01-12 10:24:09 -0500 | [diff] [blame] | 190 | public void testDataChangeWithoutConnectionState() { |
| 191 | setupDefaultSignal(); |
| 192 | updateDataConnectionState(TelephonyManager.DATA_CONNECTED, |
| 193 | TelephonyManager.NETWORK_TYPE_LTE); |
| 194 | |
Jason Monk | 48edc0c | 2017-04-10 15:01:27 -0400 | [diff] [blame] | 195 | verifyDataIndicators(TelephonyIcons.ICON_LTE, |
Jason Monk | 01df36f | 2017-06-07 13:02:47 -0400 | [diff] [blame] | 196 | TelephonyIcons.QS_DATA_LTE); |
Jason Monk | 67b2c16 | 2016-01-12 10:24:09 -0500 | [diff] [blame] | 197 | |
Jason Monk | 0288de0 | 2017-02-23 14:48:05 -0500 | [diff] [blame] | 198 | when(mServiceState.getDataNetworkType()) |
Jason Monk | 67b2c16 | 2016-01-12 10:24:09 -0500 | [diff] [blame] | 199 | .thenReturn(TelephonyManager.NETWORK_TYPE_HSPA); |
| 200 | updateServiceState(); |
Jason Monk | 48edc0c | 2017-04-10 15:01:27 -0400 | [diff] [blame] | 201 | verifyDataIndicators(TelephonyIcons.ICON_H, |
Jason Monk | 01df36f | 2017-06-07 13:02:47 -0400 | [diff] [blame] | 202 | TelephonyIcons.QS_DATA_H); |
Jason Monk | 67b2c16 | 2016-01-12 10:24:09 -0500 | [diff] [blame] | 203 | } |
| 204 | |
Geoffrey Pitsch | 2c403db | 2016-08-26 09:09:39 -0400 | [diff] [blame] | 205 | @Test |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 206 | public void testDataActivity() { |
| 207 | setupDefaultSignal(); |
| 208 | |
| 209 | testDataActivity(TelephonyManager.DATA_ACTIVITY_NONE, false, false); |
| 210 | testDataActivity(TelephonyManager.DATA_ACTIVITY_IN, true, false); |
| 211 | testDataActivity(TelephonyManager.DATA_ACTIVITY_OUT, false, true); |
| 212 | testDataActivity(TelephonyManager.DATA_ACTIVITY_INOUT, true, true); |
| 213 | } |
| 214 | |
| 215 | private void testDataActivity(int direction, boolean in, boolean out) { |
| 216 | updateDataActivity(direction); |
| 217 | |
Jason Monk | 26ad85a | 2016-12-08 14:45:42 -0500 | [diff] [blame] | 218 | verifyLastMobileDataIndicators(true, DEFAULT_SIGNAL_STRENGTH, DEFAULT_ICON, true, |
Jason Monk | 7e6c83c | 2017-04-26 14:35:24 -0400 | [diff] [blame] | 219 | DEFAULT_QS_SIGNAL_STRENGTH, DEFAULT_QS_ICON, in, out); |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 220 | } |
| 221 | |
| 222 | private void verifyDataIndicators(int dataIcon, int qsDataIcon) { |
Jason Monk | 26ad85a | 2016-12-08 14:45:42 -0500 | [diff] [blame] | 223 | verifyLastMobileDataIndicators(true, DEFAULT_SIGNAL_STRENGTH, dataIcon, |
Jason Monk | 7e6c83c | 2017-04-26 14:35:24 -0400 | [diff] [blame] | 224 | true, DEFAULT_QS_SIGNAL_STRENGTH, qsDataIcon, false, |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 225 | false); |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 226 | } |
| 227 | |
| 228 | } |