blob: cba9f77df2ff001894b95d318bfb6530db20686c [file] [log] [blame]
Jason Monkda68f592015-01-07 10:55:58 -05001/*
2 * Copyright (C) 2015 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
Jason Monke0cdb602014-11-05 12:39:45 -050016package com.android.systemui.statusbar.policy;
17
Leigh Anned0a62792014-11-13 14:27:10 -080018import android.content.Intent;
Jason Monke0cdb602014-11-05 12:39:45 -050019import android.net.ConnectivityManager;
Jason Monk33f8ae72015-05-08 10:45:15 -040020import android.net.NetworkCapabilities;
Jason Monk07b75fe2015-05-14 16:47:03 -040021import android.os.Looper;
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -040022import android.support.test.runner.AndroidJUnit4;
Jason Monkb0808aa2015-07-22 16:34:36 -040023import android.telephony.ServiceState;
Jason Monke0cdb602014-11-05 12:39:45 -050024import android.telephony.SignalStrength;
Jason Monkc014dec2014-12-12 11:49:55 -050025import android.telephony.SubscriptionInfo;
Jason Monke0cdb602014-11-05 12:39:45 -050026import android.telephony.TelephonyManager;
Jason Monke427cb82015-07-28 09:18:08 -040027import android.test.suitebuilder.annotation.SmallTest;
Jason Monke0cdb602014-11-05 12:39:45 -050028
Jason Monk18985e02015-01-07 12:07:06 -050029import com.android.internal.telephony.PhoneConstants;
Leigh Anned0a62792014-11-13 14:27:10 -080030import com.android.internal.telephony.TelephonyIntents;
Jason Monkf668d7c2016-01-14 10:38:41 -050031import com.android.settingslib.net.DataUsageController;
Jason Monkf13b4b32014-11-07 16:39:34 -050032import com.android.systemui.R;
Jason Monk48edc0c2017-04-10 15:01:27 -040033import com.android.systemui.statusbar.phone.SignalDrawable;
Jason Monkda68f592015-01-07 10:55:58 -050034
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -040035import org.junit.Test;
36import org.junit.runner.RunWith;
Jason Monkc6cc6262015-06-11 11:10:15 -040037import org.mockito.ArgumentCaptor;
Jason Monkda68f592015-01-07 10:55:58 -050038import org.mockito.Mockito;
39
40import java.util.ArrayList;
41import java.util.List;
Jason Monkf13b4b32014-11-07 16:39:34 -050042
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -040043import static junit.framework.Assert.assertEquals;
44import static junit.framework.Assert.assertTrue;
45import static junit.framework.Assert.assertFalse;
46import static org.mockito.Mockito.mock;
47
Jason Monke427cb82015-07-28 09:18:08 -040048@SmallTest
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -040049@RunWith(AndroidJUnit4.class)
Jason Monke0cdb602014-11-05 12:39:45 -050050public class NetworkControllerSignalTest extends NetworkControllerBaseTest {
51
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -040052 @Test
Jason Monkf13b4b32014-11-07 16:39:34 -050053 public void testNoIconWithoutMobile() {
54 // Turn off mobile network support.
55 Mockito.when(mMockCm.isNetworkSupported(ConnectivityManager.TYPE_MOBILE)).thenReturn(false);
56 // Create a new NetworkController as this is currently handled in constructor.
Sundeep Ghuman9d10a3c2017-06-16 00:05:16 +000057 mNetworkController = new NetworkControllerImpl(mContext, mMockCm, mMockTm, mMockWm, mMockSm,
Jason Monk07b75fe2015-05-14 16:47:03 -040058 mConfig, Looper.getMainLooper(), mCallbackHandler,
Jason Monkf668d7c2016-01-14 10:38:41 -050059 mock(AccessPointControllerImpl.class), mock(DataUsageController.class),
Jason Monk9c7844c2017-01-18 15:21:53 -050060 mMockSubDefaults, mock(DeviceProvisionedController.class));
Jason Monkf13b4b32014-11-07 16:39:34 -050061 setupNetworkController();
Jason Monke0cdb602014-11-05 12:39:45 -050062
Jason Monk48edc0c2017-04-10 15:01:27 -040063 verifyLastMobileDataIndicators(false, -1, 0);
Jason Monkf13b4b32014-11-07 16:39:34 -050064 }
65
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -040066 @Test
Jason Monk21d05a02014-12-02 12:46:58 -050067 public void testNoSimsIconPresent() {
68 // No Subscriptions.
69 mNetworkController.mMobileSignalControllers.clear();
70 mNetworkController.updateNoSims();
71
72 verifyHasNoSims(true);
73 }
74
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -040075 @Test
Jason Monkc6cc6262015-06-11 11:10:15 -040076 public void testEmergencyOnly() {
77 setupDefaultSignal();
78 mNetworkController.recalculateEmergency();
79 verifyEmergencyOnly(false);
80
81 mMobileSignalController.getState().isEmergency = true;
82 mNetworkController.recalculateEmergency();
83 verifyEmergencyOnly(true);
84 }
85
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -040086 @Test
Jason Monkc6cc6262015-06-11 11:10:15 -040087 public void testEmergencyOnlyNoSubscriptions() {
88 setupDefaultSignal();
Jason Monkb0808aa2015-07-22 16:34:36 -040089 setSubscriptions();
90 mNetworkController.mLastServiceState = new ServiceState();
91 mNetworkController.mLastServiceState.setEmergencyOnly(true);
92 mNetworkController.recalculateEmergency();
93 verifyEmergencyOnly(true);
94 }
95
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -040096 @Test
Jason Monk8996b942017-03-02 13:58:19 -050097 public void testNoEmergencyOnlyWrongSubscription() {
98 setupDefaultSignal();
99 setDefaultSubId(42);
100 mNetworkController.recalculateEmergency();
101 verifyEmergencyOnly(false);
102 }
103
104 @Test
Jason Monkb0808aa2015-07-22 16:34:36 -0400105 public void testNoEmengencyNoSubscriptions() {
106 setupDefaultSignal();
107 setSubscriptions();
108 mNetworkController.mLastServiceState = new ServiceState();
109 mNetworkController.mLastServiceState.setEmergencyOnly(false);
Jason Monkc6cc6262015-06-11 11:10:15 -0400110 mNetworkController.recalculateEmergency();
111 verifyEmergencyOnly(false);
Jason Monkc6cc6262015-06-11 11:10:15 -0400112 }
113
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -0400114 @Test
Jason Monk21d05a02014-12-02 12:46:58 -0500115 public void testNoSimlessIconWithoutMobile() {
116 // Turn off mobile network support.
117 Mockito.when(mMockCm.isNetworkSupported(ConnectivityManager.TYPE_MOBILE)).thenReturn(false);
118 // Create a new NetworkController as this is currently handled in constructor.
Sundeep Ghuman9d10a3c2017-06-16 00:05:16 +0000119 mNetworkController = new NetworkControllerImpl(mContext, mMockCm, mMockTm, mMockWm, mMockSm,
Jason Monk07b75fe2015-05-14 16:47:03 -0400120 mConfig, Looper.getMainLooper(), mCallbackHandler,
Jason Monkf668d7c2016-01-14 10:38:41 -0500121 mock(AccessPointControllerImpl.class), mock(DataUsageController.class),
Jason Monk9c7844c2017-01-18 15:21:53 -0500122 mMockSubDefaults, mock(DeviceProvisionedController.class));
Jason Monk21d05a02014-12-02 12:46:58 -0500123 setupNetworkController();
124
125 // No Subscriptions.
126 mNetworkController.mMobileSignalControllers.clear();
127 mNetworkController.updateNoSims();
128
129 verifyHasNoSims(false);
130 }
131
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -0400132 @Test
Jason Monkf13b4b32014-11-07 16:39:34 -0500133 public void testSignalStrength() {
Jason Monk48edc0c2017-04-10 15:01:27 -0400134 for (int testStrength = 0;
135 testStrength < SignalStrength.NUM_SIGNAL_STRENGTH_BINS; testStrength++) {
Jason Monkf13b4b32014-11-07 16:39:34 -0500136 setupDefaultSignal();
137 setLevel(testStrength);
138
139 verifyLastMobileDataIndicators(true,
Jason Monk48edc0c2017-04-10 15:01:27 -0400140 testStrength, DEFAULT_ICON);
Jason Monkf13b4b32014-11-07 16:39:34 -0500141
142 // Verify low inet number indexing.
Jason Monk33f8ae72015-05-08 10:45:15 -0400143 setConnectivity(NetworkCapabilities.TRANSPORT_CELLULAR, false, true);
Jason Monkf13b4b32014-11-07 16:39:34 -0500144 verifyLastMobileDataIndicators(true,
Jason Monk48edc0c2017-04-10 15:01:27 -0400145 testStrength, DEFAULT_ICON, false, false);
Jason Monkf13b4b32014-11-07 16:39:34 -0500146 }
147 }
148
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -0400149 @Test
Jason Monkf13b4b32014-11-07 16:39:34 -0500150 public void testCdmaSignalStrength() {
Jason Monk48edc0c2017-04-10 15:01:27 -0400151 for (int testStrength = 0;
152 testStrength < SignalStrength.NUM_SIGNAL_STRENGTH_BINS; testStrength++) {
Jason Monkf13b4b32014-11-07 16:39:34 -0500153 setupDefaultSignal();
154 setCdma();
155 setLevel(testStrength);
156
157 verifyLastMobileDataIndicators(true,
Jason Monk48edc0c2017-04-10 15:01:27 -0400158 testStrength,
159 TelephonyIcons.ICON_1X);
Jason Monkf13b4b32014-11-07 16:39:34 -0500160 }
Jason Monke0cdb602014-11-05 12:39:45 -0500161 }
162
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -0400163 @Test
Jason Monke0cdb602014-11-05 12:39:45 -0500164 public void testSignalRoaming() {
Jason Monk48edc0c2017-04-10 15:01:27 -0400165 for (int testStrength = 0;
166 testStrength < SignalStrength.NUM_SIGNAL_STRENGTH_BINS; testStrength++) {
Jason Monkf13b4b32014-11-07 16:39:34 -0500167 setupDefaultSignal();
168 setGsmRoaming(true);
169 setLevel(testStrength);
Jason Monke0cdb602014-11-05 12:39:45 -0500170
Jason Monkf13b4b32014-11-07 16:39:34 -0500171 verifyLastMobileDataIndicators(true,
Jason Monk48edc0c2017-04-10 15:01:27 -0400172 testStrength,
Jason Monk0f0de132016-12-19 15:36:13 -0500173 DEFAULT_ICON, true);
Jason Monkf13b4b32014-11-07 16:39:34 -0500174 }
175 }
176
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -0400177 @Test
Jason Monkf13b4b32014-11-07 16:39:34 -0500178 public void testCdmaSignalRoaming() {
179 for (int testStrength = SignalStrength.SIGNAL_STRENGTH_NONE_OR_UNKNOWN;
180 testStrength <= SignalStrength.SIGNAL_STRENGTH_GREAT; testStrength++) {
181 setupDefaultSignal();
182 setCdma();
183 setCdmaRoaming(true);
184 setLevel(testStrength);
185
186 verifyLastMobileDataIndicators(true,
Jason Monk48edc0c2017-04-10 15:01:27 -0400187 testStrength,
188 TelephonyIcons.ICON_1X, true);
Jason Monkf13b4b32014-11-07 16:39:34 -0500189 }
190 }
191
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -0400192 @Test
Jason Monkf13b4b32014-11-07 16:39:34 -0500193 public void testQsSignalStrength() {
194 for (int testStrength = SignalStrength.SIGNAL_STRENGTH_NONE_OR_UNKNOWN;
195 testStrength <= SignalStrength.SIGNAL_STRENGTH_GREAT; testStrength++) {
196 setupDefaultSignal();
197 setLevel(testStrength);
198
199 verifyLastQsMobileDataIndicators(true,
Jason Monk48edc0c2017-04-10 15:01:27 -0400200 testStrength,
Jason Monkb5746272014-11-12 16:50:31 -0500201 DEFAULT_QS_ICON, false, false);
Jason Monkf13b4b32014-11-07 16:39:34 -0500202 }
203 }
204
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -0400205 @Test
Jason Monkf13b4b32014-11-07 16:39:34 -0500206 public void testCdmaQsSignalStrength() {
207 for (int testStrength = SignalStrength.SIGNAL_STRENGTH_NONE_OR_UNKNOWN;
208 testStrength <= SignalStrength.SIGNAL_STRENGTH_GREAT; testStrength++) {
209 setupDefaultSignal();
210 setCdma();
211 setLevel(testStrength);
212
213 verifyLastQsMobileDataIndicators(true,
Jason Monk48edc0c2017-04-10 15:01:27 -0400214 testStrength,
Jason Monk01df36f2017-06-07 13:02:47 -0400215 TelephonyIcons.QS_DATA_1X, false, false);
Jason Monkf13b4b32014-11-07 16:39:34 -0500216 }
217 }
218
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -0400219 @Test
Jason Monk33f8ae72015-05-08 10:45:15 -0400220 public void testNoBangWithWifi() {
Jason Monkf13b4b32014-11-07 16:39:34 -0500221 setupDefaultSignal();
Jason Monk33f8ae72015-05-08 10:45:15 -0400222 setConnectivity(mMobileSignalController.mTransportType, false, false);
223 setConnectivity(NetworkCapabilities.TRANSPORT_WIFI, true, true);
Jason Monkf13b4b32014-11-07 16:39:34 -0500224
Jason Monk48edc0c2017-04-10 15:01:27 -0400225 verifyLastMobileDataIndicators(true, DEFAULT_LEVEL, 0);
Jason Monkf13b4b32014-11-07 16:39:34 -0500226 }
227
Jason Monkc014dec2014-12-12 11:49:55 -0500228 // Some tests of actual NetworkController code, just internals not display stuff
229 // TODO: Put this somewhere else, maybe in its own file.
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -0400230 @Test
Jason Monkc014dec2014-12-12 11:49:55 -0500231 public void testHasCorrectMobileControllers() {
232 int[] testSubscriptions = new int[] { 1, 5, 3 };
233 int notTestSubscription = 0;
234 MobileSignalController mobileSignalController = Mockito.mock(MobileSignalController.class);
235
236 mNetworkController.mMobileSignalControllers.clear();
237 List<SubscriptionInfo> subscriptions = new ArrayList<>();
238 for (int i = 0; i < testSubscriptions.length; i++) {
239 // Force the test controllers into NetworkController.
240 mNetworkController.mMobileSignalControllers.put(testSubscriptions[i],
241 mobileSignalController);
242
243 // Generate a list of subscriptions we will tell the NetworkController to use.
244 SubscriptionInfo mockSubInfo = Mockito.mock(SubscriptionInfo.class);
245 Mockito.when(mockSubInfo.getSubscriptionId()).thenReturn(testSubscriptions[i]);
246 subscriptions.add(mockSubInfo);
247 }
248 assertTrue(mNetworkController.hasCorrectMobileControllers(subscriptions));
249
250 // Add a subscription that the NetworkController doesn't know about.
251 SubscriptionInfo mockSubInfo = Mockito.mock(SubscriptionInfo.class);
252 Mockito.when(mockSubInfo.getSubscriptionId()).thenReturn(notTestSubscription);
253 subscriptions.add(mockSubInfo);
254 assertFalse(mNetworkController.hasCorrectMobileControllers(subscriptions));
255 }
256
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -0400257 @Test
Jason Monkc014dec2014-12-12 11:49:55 -0500258 public void testSetCurrentSubscriptions() {
259 // We will not add one controller to make sure it gets created.
260 int indexToSkipController = 0;
261 // We will not add one subscription to make sure it's controller gets removed.
262 int indexToSkipSubscription = 1;
263
264 int[] testSubscriptions = new int[] { 1, 5, 3 };
265 MobileSignalController[] mobileSignalControllers = new MobileSignalController[] {
266 Mockito.mock(MobileSignalController.class),
267 Mockito.mock(MobileSignalController.class),
268 Mockito.mock(MobileSignalController.class),
269 };
270 mNetworkController.mMobileSignalControllers.clear();
271 List<SubscriptionInfo> subscriptions = new ArrayList<>();
272 for (int i = 0; i < testSubscriptions.length; i++) {
273 if (i != indexToSkipController) {
274 // Force the test controllers into NetworkController.
275 mNetworkController.mMobileSignalControllers.put(testSubscriptions[i],
276 mobileSignalControllers[i]);
277 }
278
279 if (i != indexToSkipSubscription) {
280 // Generate a list of subscriptions we will tell the NetworkController to use.
281 SubscriptionInfo mockSubInfo = Mockito.mock(SubscriptionInfo.class);
282 Mockito.when(mockSubInfo.getSubscriptionId()).thenReturn(testSubscriptions[i]);
283 Mockito.when(mockSubInfo.getSimSlotIndex()).thenReturn(testSubscriptions[i]);
284 subscriptions.add(mockSubInfo);
285 }
286 }
287
288 // We can only test whether unregister gets called if it thinks its in a listening
289 // state.
290 mNetworkController.mListening = true;
291 mNetworkController.setCurrentSubscriptions(subscriptions);
292
293 for (int i = 0; i < testSubscriptions.length; i++) {
294 if (i == indexToSkipController) {
295 // Make sure a controller was created despite us not adding one.
Jason Monk8996b942017-03-02 13:58:19 -0500296 assertTrue(mNetworkController.mMobileSignalControllers.indexOfKey(
297 testSubscriptions[i]) >= 0);
Jason Monkc014dec2014-12-12 11:49:55 -0500298 } else if (i == indexToSkipSubscription) {
299 // Make sure the controller that did exist was removed
Jason Monk8996b942017-03-02 13:58:19 -0500300 assertFalse(mNetworkController.mMobileSignalControllers.indexOfKey(
301 testSubscriptions[i]) >= 0);
Jason Monkc014dec2014-12-12 11:49:55 -0500302 } else {
303 // If a MobileSignalController is around it needs to not be unregistered.
304 Mockito.verify(mobileSignalControllers[i], Mockito.never())
305 .unregisterListener();
306 }
307 }
308 }
309
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -0400310 @Test
Jason Monk7f9623f2015-02-11 09:03:02 -0500311 public void testHistorySize() {
312 // Verify valid history size, otherwise it gits printed out the wrong order and whatnot.
313 assertEquals(0, SignalController.HISTORY_SIZE & (SignalController.HISTORY_SIZE - 1));
314 }
315
Jason Monkf13b4b32014-11-07 16:39:34 -0500316 private void setCdma() {
317 setIsGsm(false);
318 updateDataConnectionState(TelephonyManager.DATA_CONNECTED,
319 TelephonyManager.NETWORK_TYPE_CDMA);
320 setCdmaRoaming(false);
Jason Monke0cdb602014-11-05 12:39:45 -0500321 }
Leigh Anned0a62792014-11-13 14:27:10 -0800322
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -0400323 @Test
Leigh Anned0a62792014-11-13 14:27:10 -0800324 public void testOnReceive_stringsUpdatedAction_spn() {
325 String expectedMNetworkName = "Test";
326 Intent intent = createStringsUpdatedIntent(true /* showSpn */,
327 expectedMNetworkName /* spn */,
328 false /* showPlmn */,
329 "NotTest" /* plmn */);
330
331 mNetworkController.onReceive(mContext, intent);
332
333 assertNetworkNameEquals(expectedMNetworkName);
334 }
335
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -0400336 @Test
Leigh Anned0a62792014-11-13 14:27:10 -0800337 public void testOnReceive_stringsUpdatedAction_plmn() {
338 String expectedMNetworkName = "Test";
339
340 Intent intent = createStringsUpdatedIntent(false /* showSpn */,
341 "NotTest" /* spn */,
342 true /* showPlmn */,
343 expectedMNetworkName /* plmn */);
344
345 mNetworkController.onReceive(mContext, intent);
346
347 assertNetworkNameEquals(expectedMNetworkName);
348 }
349
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -0400350 @Test
Leigh Anned0a62792014-11-13 14:27:10 -0800351 public void testOnReceive_stringsUpdatedAction_bothFalse() {
352 Intent intent = createStringsUpdatedIntent(false /* showSpn */,
353 "Irrelevant" /* spn */,
354 false /* showPlmn */,
355 "Irrelevant" /* plmn */);
356
357 mNetworkController.onReceive(mContext, intent);
358
359 String defaultNetworkName = mMobileSignalController
360 .getStringIfExists(
361 com.android.internal.R.string.lockscreen_carrier_default);
362 assertNetworkNameEquals(defaultNetworkName);
363 }
364
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -0400365 @Test
Leigh Anned0a62792014-11-13 14:27:10 -0800366 public void testOnReceive_stringsUpdatedAction_bothTrueAndNull() {
367 Intent intent = createStringsUpdatedIntent(true /* showSpn */,
368 null /* spn */,
369 true /* showPlmn */,
370 null /* plmn */);
371
372 mNetworkController.onReceive(mContext, intent);
373
374 String defaultNetworkName = mMobileSignalController.getStringIfExists(
375 com.android.internal.R.string.lockscreen_carrier_default);
376 assertNetworkNameEquals(defaultNetworkName);
377 }
378
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -0400379 @Test
Leigh Anned0a62792014-11-13 14:27:10 -0800380 public void testOnReceive_stringsUpdatedAction_bothTrueAndNonNull() {
381 String spn = "Test1";
382 String plmn = "Test2";
383
384 Intent intent = createStringsUpdatedIntent(true /* showSpn */,
385 spn /* spn */,
386 true /* showPlmn */,
387 plmn /* plmn */);
388
389 mNetworkController.onReceive(mContext, intent);
390
391 assertNetworkNameEquals(plmn
392 + mMobileSignalController.getStringIfExists(
393 R.string.status_bar_network_name_separator)
394 + spn);
395 }
396
397 private Intent createStringsUpdatedIntent(boolean showSpn, String spn,
398 boolean showPlmn, String plmn) {
399
400 Intent intent = new Intent();
401 intent.setAction(TelephonyIntents.SPN_STRINGS_UPDATED_ACTION);
402
403 intent.putExtra(TelephonyIntents.EXTRA_SHOW_SPN, showSpn);
404 intent.putExtra(TelephonyIntents.EXTRA_SPN, spn);
405
406 intent.putExtra(TelephonyIntents.EXTRA_SHOW_PLMN, showPlmn);
407 intent.putExtra(TelephonyIntents.EXTRA_PLMN, plmn);
Jason Monk18985e02015-01-07 12:07:06 -0500408 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, mSubId);
Leigh Anned0a62792014-11-13 14:27:10 -0800409
410 return intent;
411 }
412
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -0400413 @Test
Leigh Anned0a62792014-11-13 14:27:10 -0800414 public void testOnUpdateDataActivity_dataIn() {
415 setupDefaultSignal();
416
417 updateDataActivity(TelephonyManager.DATA_ACTIVITY_IN);
418
419 verifyLastQsMobileDataIndicators(true /* visible */,
Jason Monk48edc0c2017-04-10 15:01:27 -0400420 DEFAULT_LEVEL /* icon */,
Leigh Anned0a62792014-11-13 14:27:10 -0800421 DEFAULT_QS_ICON /* typeIcon */,
422 true /* dataIn */,
423 false /* dataOut */);
424
425 }
426
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -0400427 @Test
Leigh Anned0a62792014-11-13 14:27:10 -0800428 public void testOnUpdateDataActivity_dataOut() {
429 setupDefaultSignal();
430
431 updateDataActivity(TelephonyManager.DATA_ACTIVITY_OUT);
432
433 verifyLastQsMobileDataIndicators(true /* visible */,
Jason Monk48edc0c2017-04-10 15:01:27 -0400434 DEFAULT_LEVEL /* icon */,
Jason Monk7e6c83c2017-04-26 14:35:24 -0400435 DEFAULT_QS_ICON /* typeIcon */,
Leigh Anned0a62792014-11-13 14:27:10 -0800436 false /* dataIn */,
437 true /* dataOut */);
Leigh Anned0a62792014-11-13 14:27:10 -0800438 }
439
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -0400440 @Test
Leigh Anned0a62792014-11-13 14:27:10 -0800441 public void testOnUpdateDataActivity_dataInOut() {
442 setupDefaultSignal();
443
444 updateDataActivity(TelephonyManager.DATA_ACTIVITY_INOUT);
445
446 verifyLastQsMobileDataIndicators(true /* visible */,
Jason Monk48edc0c2017-04-10 15:01:27 -0400447 DEFAULT_LEVEL /* icon */,
Leigh Anned0a62792014-11-13 14:27:10 -0800448 DEFAULT_QS_ICON /* typeIcon */,
449 true /* dataIn */,
450 true /* dataOut */);
451
452 }
453
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -0400454 @Test
Leigh Anned0a62792014-11-13 14:27:10 -0800455 public void testOnUpdateDataActivity_dataActivityNone() {
456 setupDefaultSignal();
457
458 updateDataActivity(TelephonyManager.DATA_ACTIVITY_NONE);
459
460 verifyLastQsMobileDataIndicators(true /* visible */,
Jason Monk48edc0c2017-04-10 15:01:27 -0400461 DEFAULT_LEVEL /* icon */,
Leigh Anned0a62792014-11-13 14:27:10 -0800462 DEFAULT_QS_ICON /* typeIcon */,
463 false /* dataIn */,
464 false /* dataOut */);
465
466 }
Andrew Flynn5e751472015-05-01 11:50:07 -0400467
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -0400468 @Test
Andrew Flynn55fc8002015-05-29 08:33:46 -0400469 public void testCarrierNetworkChange_carrierNetworkChange() {
Andrew Flynn5e751472015-05-01 11:50:07 -0400470 int strength = SignalStrength.SIGNAL_STRENGTH_GREAT;
471
472 setupDefaultSignal();
473 setLevel(strength);
474
475 // Verify baseline
476 verifyLastMobileDataIndicators(true /* visible */,
Jason Monk48edc0c2017-04-10 15:01:27 -0400477 strength /* strengthIcon */,
Andrew Flynn5e751472015-05-01 11:50:07 -0400478 DEFAULT_ICON /* typeIcon */);
479
Andrew Flynn55fc8002015-05-29 08:33:46 -0400480 // API call is made
Andrew Flynn5e751472015-05-01 11:50:07 -0400481 setCarrierNetworkChange(true /* enabled */);
Andrew Flynn5e751472015-05-01 11:50:07 -0400482
Andrew Flynn55fc8002015-05-29 08:33:46 -0400483 // Carrier network change is true, show special indicator
Andrew Flynn5e751472015-05-01 11:50:07 -0400484 verifyLastMobileDataIndicators(true /* visible */,
Jason Monk48edc0c2017-04-10 15:01:27 -0400485 SignalDrawable.getCarrierChangeState(SignalStrength.NUM_SIGNAL_STRENGTH_BINS),
Andrew Flynn5e751472015-05-01 11:50:07 -0400486 0 /* typeIcon */);
487
488 // Revert back
489 setCarrierNetworkChange(false /* enabled */);
Andrew Flynn5e751472015-05-01 11:50:07 -0400490
491 // Verify back in previous state
492 verifyLastMobileDataIndicators(true /* visible */,
Jason Monk48edc0c2017-04-10 15:01:27 -0400493 strength /* strengthIcon */,
Andrew Flynn5e751472015-05-01 11:50:07 -0400494 DEFAULT_ICON /* typeIcon */);
495 }
Jason Monkc6cc6262015-06-11 11:10:15 -0400496
Shishir Agrawal7ef5b882017-06-26 12:06:03 -0700497 @Test
498 public void testCarrierNetworkChange_roamingBeforeNetworkChange() {
499 int strength = SignalStrength.SIGNAL_STRENGTH_GREAT;
500
501 setupDefaultSignal();
502 setLevel(strength);
503 setGsmRoaming(true);
504
505 // Verify baseline
506 verifyLastMobileDataIndicators(true /* visible */,
507 strength /* strengthIcon */,
508 DEFAULT_ICON /* typeIcon */,
509 true /* roaming */);
510
511 // API call is made
512 setCarrierNetworkChange(true /* enabled */);
513
514 // Carrier network change is true, show special indicator, no roaming.
515 verifyLastMobileDataIndicators(true /* visible */,
516 SignalDrawable.getCarrierChangeState(SignalStrength.NUM_SIGNAL_STRENGTH_BINS),
517 0 /* typeIcon */,
518 false /* roaming */);
519
520 // Revert back
521 setCarrierNetworkChange(false /* enabled */);
522
523 // Verify back in previous state
524 verifyLastMobileDataIndicators(true /* visible */,
525 strength /* strengthIcon */,
526 DEFAULT_ICON /* typeIcon */,
527 true /* roaming */);
528 }
529
530 @Test
531 public void testCarrierNetworkChange_roamingAfterNetworkChange() {
532 int strength = SignalStrength.SIGNAL_STRENGTH_GREAT;
533
534 setupDefaultSignal();
535 setLevel(strength);
536
537 // Verify baseline
538 verifyLastMobileDataIndicators(true /* visible */,
539 strength /* strengthIcon */,
540 DEFAULT_ICON /* typeIcon */,
541 false /* roaming */);
542
543 // API call is made
544 setCarrierNetworkChange(true /* enabled */);
545
546 // Carrier network change is true, show special indicator, no roaming.
547 verifyLastMobileDataIndicators(true /* visible */,
548 SignalDrawable.getCarrierChangeState(SignalStrength.NUM_SIGNAL_STRENGTH_BINS),
549 0 /* typeIcon */,
550 false /* roaming */);
551
552 setGsmRoaming(true);
553
554 // Roaming should not show.
555 verifyLastMobileDataIndicators(true /* visible */,
556 SignalDrawable.getCarrierChangeState(SignalStrength.NUM_SIGNAL_STRENGTH_BINS),
557 0 /* typeIcon */,
558 false /* roaming */);
559
560 // Revert back
561 setCarrierNetworkChange(false /* enabled */);
562
563 // Verify back in previous state
564 verifyLastMobileDataIndicators(true /* visible */,
565 strength /* strengthIcon */,
566 DEFAULT_ICON /* typeIcon */,
567 true /* roaming */);
568 }
569
Jason Monkc6cc6262015-06-11 11:10:15 -0400570 private void verifyEmergencyOnly(boolean isEmergencyOnly) {
571 ArgumentCaptor<Boolean> emergencyOnly = ArgumentCaptor.forClass(Boolean.class);
572 Mockito.verify(mCallbackHandler, Mockito.atLeastOnce()).setEmergencyCallsOnly(
573 emergencyOnly.capture());
574 assertEquals(isEmergencyOnly, (boolean) emergencyOnly.getValue());
575 }
Jason Monke0cdb602014-11-05 12:39:45 -0500576}