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 | f668d7c | 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 |
Jason Monk | fd57ea7 | 2016-04-29 13:37:58 -0400 | [diff] [blame] | 114 | public void testDataDisabledIcon() { |
| 115 | setupNetworkController(); |
Jason Monk | 0288de0 | 2017-02-23 14:48:05 -0500 | [diff] [blame] | 116 | when(mMockTm.getDataEnabled(mSubId)).thenReturn(false); |
Jason Monk | fd57ea7 | 2016-04-29 13:37:58 -0400 | [diff] [blame] | 117 | setupDefaultSignal(); |
| 118 | updateDataConnectionState(TelephonyManager.DATA_DISCONNECTED, 0); |
| 119 | setConnectivity(NetworkCapabilities.TRANSPORT_CELLULAR, false, false); |
| 120 | |
Jason Monk | 7e6c83c | 2017-04-26 14:35:24 -0400 | [diff] [blame] | 121 | verifyDataIndicators(TelephonyIcons.ICON_DATA_DISABLED, |
Jason Monk | 01df36f | 2017-06-07 13:02:47 -0400 | [diff] [blame] | 122 | TelephonyIcons.QS_ICON_DATA_DISABLED); |
Jason Monk | fd57ea7 | 2016-04-29 13:37:58 -0400 | [diff] [blame] | 123 | } |
| 124 | |
Geoffrey Pitsch | 2c403db | 2016-08-26 09:09:39 -0400 | [diff] [blame] | 125 | @Test |
Jason Monk | fd57ea7 | 2016-04-29 13:37:58 -0400 | [diff] [blame] | 126 | public void testDataDisabledIcon_UserNotSetup() { |
| 127 | setupNetworkController(); |
Jason Monk | 0288de0 | 2017-02-23 14:48:05 -0500 | [diff] [blame] | 128 | when(mMockTm.getDataEnabled(mSubId)).thenReturn(false); |
Jason Monk | fd57ea7 | 2016-04-29 13:37:58 -0400 | [diff] [blame] | 129 | setupDefaultSignal(); |
| 130 | updateDataConnectionState(TelephonyManager.DATA_DISCONNECTED, 0); |
| 131 | setConnectivity(NetworkCapabilities.TRANSPORT_CELLULAR, false, false); |
Jason Monk | 0288de0 | 2017-02-23 14:48:05 -0500 | [diff] [blame] | 132 | when(mMockProvisionController.isUserSetup(anyInt())).thenReturn(false); |
| 133 | mUserCallback.onUserSetupChanged(); |
Jason Monk | 2515f47 | 2017-09-19 09:52:43 -0400 | [diff] [blame] | 134 | TestableLooper.get(this).processAllMessages(); |
Jason Monk | fd57ea7 | 2016-04-29 13:37:58 -0400 | [diff] [blame] | 135 | |
| 136 | // Don't show the X until the device is setup. |
Jason Monk | 7e6c83c | 2017-04-26 14:35:24 -0400 | [diff] [blame] | 137 | verifyDataIndicators(0, 0); |
Jason Monk | fd57ea7 | 2016-04-29 13:37:58 -0400 | [diff] [blame] | 138 | } |
| 139 | |
Geoffrey Pitsch | 2c403db | 2016-08-26 09:09:39 -0400 | [diff] [blame] | 140 | @Test |
Wenting Xiong | 63364fe | 2017-02-07 19:12:27 +0800 | [diff] [blame] | 141 | public void testAlwaysShowDataRatIcon() { |
| 142 | setupDefaultSignal(); |
| 143 | when(mMockTm.getDataEnabled(mSubId)).thenReturn(false); |
| 144 | updateDataConnectionState(TelephonyManager.DATA_DISCONNECTED, |
| 145 | TelephonyManager.NETWORK_TYPE_GSM); |
| 146 | |
| 147 | // Switch to showing data RAT icon when data is disconnected |
| 148 | // and re-initialize the NetworkController. |
| 149 | mConfig.alwaysShowDataRatIcon = true; |
| 150 | mNetworkController.handleConfigurationChanged(); |
| 151 | |
| 152 | verifyDataIndicators(TelephonyIcons.ICON_G, |
| 153 | TelephonyIcons.QS_DATA_G); |
| 154 | } |
| 155 | |
| 156 | @Test |
Jason Monk | 3aaabd7 | 2014-12-12 11:11:44 -0500 | [diff] [blame] | 157 | public void test4gDataIconConfigChange() { |
| 158 | setupDefaultSignal(); |
| 159 | updateDataConnectionState(TelephonyManager.DATA_CONNECTED, |
| 160 | TelephonyManager.NETWORK_TYPE_LTE); |
| 161 | |
| 162 | // Switch to showing 4g icon and re-initialize the NetworkController. |
| 163 | mConfig.show4gForLte = true; |
| 164 | // Can't send the broadcast as that would actually read the config from |
| 165 | // the context. Instead we'll just poke at a function that does all of |
| 166 | // the after work. |
| 167 | mNetworkController.handleConfigurationChanged(); |
| 168 | |
Jason Monk | 48edc0c | 2017-04-10 15:01:27 -0400 | [diff] [blame] | 169 | verifyDataIndicators(TelephonyIcons.ICON_4G, |
Jason Monk | 01df36f | 2017-06-07 13:02:47 -0400 | [diff] [blame] | 170 | TelephonyIcons.QS_DATA_4G); |
Jason Monk | 3aaabd7 | 2014-12-12 11:11:44 -0500 | [diff] [blame] | 171 | } |
| 172 | |
Geoffrey Pitsch | 2c403db | 2016-08-26 09:09:39 -0400 | [diff] [blame] | 173 | @Test |
Jason Monk | 67b2c16 | 2016-01-12 10:24:09 -0500 | [diff] [blame] | 174 | public void testDataChangeWithoutConnectionState() { |
| 175 | setupDefaultSignal(); |
| 176 | updateDataConnectionState(TelephonyManager.DATA_CONNECTED, |
| 177 | TelephonyManager.NETWORK_TYPE_LTE); |
| 178 | |
Jason Monk | 48edc0c | 2017-04-10 15:01:27 -0400 | [diff] [blame] | 179 | verifyDataIndicators(TelephonyIcons.ICON_LTE, |
Jason Monk | 01df36f | 2017-06-07 13:02:47 -0400 | [diff] [blame] | 180 | TelephonyIcons.QS_DATA_LTE); |
Jason Monk | 67b2c16 | 2016-01-12 10:24:09 -0500 | [diff] [blame] | 181 | |
Jason Monk | 0288de0 | 2017-02-23 14:48:05 -0500 | [diff] [blame] | 182 | when(mServiceState.getDataNetworkType()) |
Jason Monk | 67b2c16 | 2016-01-12 10:24:09 -0500 | [diff] [blame] | 183 | .thenReturn(TelephonyManager.NETWORK_TYPE_HSPA); |
| 184 | updateServiceState(); |
Jason Monk | 48edc0c | 2017-04-10 15:01:27 -0400 | [diff] [blame] | 185 | verifyDataIndicators(TelephonyIcons.ICON_H, |
Jason Monk | 01df36f | 2017-06-07 13:02:47 -0400 | [diff] [blame] | 186 | TelephonyIcons.QS_DATA_H); |
Jason Monk | 67b2c16 | 2016-01-12 10:24:09 -0500 | [diff] [blame] | 187 | } |
| 188 | |
Geoffrey Pitsch | 2c403db | 2016-08-26 09:09:39 -0400 | [diff] [blame] | 189 | @Test |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 190 | public void testDataActivity() { |
| 191 | setupDefaultSignal(); |
| 192 | |
| 193 | testDataActivity(TelephonyManager.DATA_ACTIVITY_NONE, false, false); |
| 194 | testDataActivity(TelephonyManager.DATA_ACTIVITY_IN, true, false); |
| 195 | testDataActivity(TelephonyManager.DATA_ACTIVITY_OUT, false, true); |
| 196 | testDataActivity(TelephonyManager.DATA_ACTIVITY_INOUT, true, true); |
| 197 | } |
| 198 | |
| 199 | private void testDataActivity(int direction, boolean in, boolean out) { |
| 200 | updateDataActivity(direction); |
| 201 | |
Jason Monk | 26ad85a | 2016-12-08 14:45:42 -0500 | [diff] [blame] | 202 | verifyLastMobileDataIndicators(true, DEFAULT_SIGNAL_STRENGTH, DEFAULT_ICON, true, |
Jason Monk | 7e6c83c | 2017-04-26 14:35:24 -0400 | [diff] [blame] | 203 | DEFAULT_QS_SIGNAL_STRENGTH, DEFAULT_QS_ICON, in, out); |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 204 | } |
| 205 | |
| 206 | private void verifyDataIndicators(int dataIcon, int qsDataIcon) { |
Jason Monk | 26ad85a | 2016-12-08 14:45:42 -0500 | [diff] [blame] | 207 | verifyLastMobileDataIndicators(true, DEFAULT_SIGNAL_STRENGTH, dataIcon, |
Jason Monk | 7e6c83c | 2017-04-26 14:35:24 -0400 | [diff] [blame] | 208 | true, DEFAULT_QS_SIGNAL_STRENGTH, qsDataIcon, false, |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 209 | false); |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 210 | } |
| 211 | |
| 212 | } |