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