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