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