blob: ba2099928d96ada599925175218dacf51c3fcddc [file] [log] [blame]
Jason Monkf13b4b32014-11-07 16:39:34 -05001package com.android.systemui.statusbar.policy;
2
Jason Monk0288de02017-02-23 14:48:05 -05003import static org.mockito.Matchers.anyInt;
Jason Monk9c7844c2017-01-18 15:21:53 -05004import static org.mockito.Mockito.mock;
Jason Monk0288de02017-02-23 14:48:05 -05005import static org.mockito.Mockito.when;
Jason Monk9c7844c2017-01-18 15:21:53 -05006
Jason Monkfd57ea72016-04-29 13:37:58 -04007import android.net.NetworkCapabilities;
Jason Monk07b75fe2015-05-14 16:47:03 -04008import android.os.Looper;
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -04009import android.support.test.runner.AndroidJUnit4;
Jason Monkf13b4b32014-11-07 16:39:34 -050010import android.telephony.TelephonyManager;
Jason Monke427cb82015-07-28 09:18:08 -040011import android.test.suitebuilder.annotation.SmallTest;
Jason Monk0288de02017-02-23 14:48:05 -050012
Jason Monkf668d7c2016-01-14 10:38:41 -050013import com.android.settingslib.net.DataUsageController;
Jason Monk0288de02017-02-23 14:48:05 -050014
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -040015import org.junit.Test;
16import org.junit.runner.RunWith;
Jason Monk33f8ae72015-05-08 10:45:15 -040017
Jason Monke427cb82015-07-28 09:18:08 -040018@SmallTest
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -040019@RunWith(AndroidJUnit4.class)
Jason Monkf13b4b32014-11-07 16:39:34 -050020public class NetworkControllerDataTest extends NetworkControllerBaseTest {
21
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -040022 @Test
Jason Monkf13b4b32014-11-07 16:39:34 -050023 public void test3gDataIcon() {
24 setupDefaultSignal();
25
26 verifyDataIndicators(TelephonyIcons.DATA_3G[1][0 /* No direction */],
Jason Monk33f8ae72015-05-08 10:45:15 -040027 TelephonyIcons.QS_DATA_3G);
Jason Monkf13b4b32014-11-07 16:39:34 -050028 }
29
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -040030 @Test
Jason Monkf13b4b32014-11-07 16:39:34 -050031 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 Monk33f8ae72015-05-08 10:45:15 -040037 TelephonyIcons.QS_DATA_G);
Jason Monkf13b4b32014-11-07 16:39:34 -050038 }
39
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -040040 @Test
Jason Monkf13b4b32014-11-07 16:39:34 -050041 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 Monk33f8ae72015-05-08 10:45:15 -040047 TelephonyIcons.QS_DATA_1X);
Jason Monkf13b4b32014-11-07 16:39:34 -050048 }
49
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -040050 @Test
Jason Monkf13b4b32014-11-07 16:39:34 -050051 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 Monk33f8ae72015-05-08 10:45:15 -040057 TelephonyIcons.QS_DATA_E);
Jason Monkf13b4b32014-11-07 16:39:34 -050058 }
59
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -040060 @Test
Jason Monkf13b4b32014-11-07 16:39:34 -050061 public void testLteDataIcon() {
62 setupDefaultSignal();
63 updateDataConnectionState(TelephonyManager.DATA_CONNECTED,
64 TelephonyManager.NETWORK_TYPE_LTE);
65
Jason Monkf13b4b32014-11-07 16:39:34 -050066 verifyDataIndicators(TelephonyIcons.DATA_LTE[1][0 /* No direction */],
Jason Monk33f8ae72015-05-08 10:45:15 -040067 TelephonyIcons.QS_DATA_LTE);
Jason Monkf13b4b32014-11-07 16:39:34 -050068 }
69
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -040070 @Test
Jason Monkf13b4b32014-11-07 16:39:34 -050071 public void testHspaDataIcon() {
72 setupDefaultSignal();
73 updateDataConnectionState(TelephonyManager.DATA_CONNECTED,
74 TelephonyManager.NETWORK_TYPE_HSPA);
75
Jason Monkf13b4b32014-11-07 16:39:34 -050076 verifyDataIndicators(TelephonyIcons.DATA_H[1][0 /* No direction */],
Jason Monk33f8ae72015-05-08 10:45:15 -040077 TelephonyIcons.QS_DATA_H);
Jason Monkf13b4b32014-11-07 16:39:34 -050078 }
79
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -040080 @Test
Jason Monk7150d7f2015-07-09 10:14:12 -040081 public void testWfcNoDataIcon() {
82 setupDefaultSignal();
83 updateDataConnectionState(TelephonyManager.DATA_CONNECTED,
84 TelephonyManager.NETWORK_TYPE_IWLAN);
85
86 verifyDataIndicators(0, 0);
87 }
88
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -040089 @Test
Jason Monk3aaabd72014-12-12 11:11:44 -050090 public void test4gDataIcon() {
91 // Switch to showing 4g icon and re-initialize the NetworkController.
92 mConfig.show4gForLte = true;
Sundeep Ghumand57f3242017-01-13 15:31:48 -080093 mNetworkController = new NetworkControllerImpl(mContext, mMockCm, mMockNetworkScoreManager,
94 mMockTm, mMockWm, mMockSm,
Jason Monk07b75fe2015-05-14 16:47:03 -040095 mConfig, Looper.getMainLooper(), mCallbackHandler,
Jason Monk9c7844c2017-01-18 15:21:53 -050096 mock(AccessPointControllerImpl.class),
97 mock(DataUsageController.class), mMockSubDefaults,
98 mock(DeviceProvisionedController.class));
Jason Monk3aaabd72014-12-12 11:11:44 -050099 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 Monk33f8ae72015-05-08 10:45:15 -0400106 TelephonyIcons.QS_DATA_4G);
Jason Monk3aaabd72014-12-12 11:11:44 -0500107 }
108
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -0400109 @Test
Jason Monkfd57ea72016-04-29 13:37:58 -0400110 public void testDataDisabledIcon() {
111 setupNetworkController();
Jason Monk0288de02017-02-23 14:48:05 -0500112 when(mMockTm.getDataEnabled(mSubId)).thenReturn(false);
Jason Monkfd57ea72016-04-29 13:37:58 -0400113 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 Pitsch2c403db2016-08-26 09:09:39 -0400121 @Test
Jason Monkfd57ea72016-04-29 13:37:58 -0400122 public void testDataDisabledIcon_UserNotSetup() {
123 setupNetworkController();
Jason Monk0288de02017-02-23 14:48:05 -0500124 when(mMockTm.getDataEnabled(mSubId)).thenReturn(false);
Jason Monkfd57ea72016-04-29 13:37:58 -0400125 setupDefaultSignal();
126 updateDataConnectionState(TelephonyManager.DATA_DISCONNECTED, 0);
127 setConnectivity(NetworkCapabilities.TRANSPORT_CELLULAR, false, false);
Jason Monk0288de02017-02-23 14:48:05 -0500128 when(mMockProvisionController.isUserSetup(anyInt())).thenReturn(false);
129 mUserCallback.onUserSetupChanged();
Jason Monkfd57ea72016-04-29 13:37:58 -0400130
131 // Don't show the X until the device is setup.
132 verifyDataIndicators(0, 0);
133 }
134
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -0400135 @Test
Jason Monk3aaabd72014-12-12 11:11:44 -0500136 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 Monk33f8ae72015-05-08 10:45:15 -0400149 TelephonyIcons.QS_DATA_4G);
Jason Monk3aaabd72014-12-12 11:11:44 -0500150 }
151
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -0400152 @Test
Jason Monk67b2c162016-01-12 10:24:09 -0500153 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 Monk0288de02017-02-23 14:48:05 -0500161 when(mServiceState.getDataNetworkType())
Jason Monk67b2c162016-01-12 10:24:09 -0500162 .thenReturn(TelephonyManager.NETWORK_TYPE_HSPA);
163 updateServiceState();
164 verifyDataIndicators(TelephonyIcons.DATA_H[1][0 /* No direction */],
165 TelephonyIcons.QS_DATA_H);
166 }
167
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -0400168 @Test
Jason Monkf13b4b32014-11-07 16:39:34 -0500169 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 Monk26ad85a2016-12-08 14:45:42 -0500181 verifyLastMobileDataIndicators(true, DEFAULT_SIGNAL_STRENGTH, DEFAULT_ICON, true,
182 DEFAULT_QS_SIGNAL_STRENGTH, DEFAULT_QS_ICON, in, out);
Jason Monkf13b4b32014-11-07 16:39:34 -0500183 }
184
185 private void verifyDataIndicators(int dataIcon, int qsDataIcon) {
Jason Monk26ad85a2016-12-08 14:45:42 -0500186 verifyLastMobileDataIndicators(true, DEFAULT_SIGNAL_STRENGTH, dataIcon,
187 true, DEFAULT_QS_SIGNAL_STRENGTH, qsDataIcon, false,
Jason Monkb5746272014-11-12 16:50:31 -0500188 false);
Jason Monkf13b4b32014-11-07 16:39:34 -0500189 }
190
191}