blob: bcbba8b163af0b0794a5ebef262ef5c6bbf9d98d [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
Brett Chabot84151d92019-02-27 15:37:59 -080018import static junit.framework.Assert.assertEquals;
19import static junit.framework.Assert.assertFalse;
20import static junit.framework.Assert.assertTrue;
21
22import static org.mockito.Mockito.mock;
23
Leigh Anned0a62792014-11-13 14:27:10 -080024import android.content.Intent;
Jason Monke0cdb602014-11-05 12:39:45 -050025import android.net.ConnectivityManager;
Jason Monk33f8ae72015-05-08 10:45:15 -040026import android.net.NetworkCapabilities;
Jason Monk07b75fe2015-05-14 16:47:03 -040027import android.os.Looper;
Jason Monkb0808aa2015-07-22 16:34:36 -040028import android.telephony.ServiceState;
Jason Monke0cdb602014-11-05 12:39:45 -050029import android.telephony.SignalStrength;
Jason Monkc014dec2014-12-12 11:49:55 -050030import android.telephony.SubscriptionInfo;
Jason Monke0cdb602014-11-05 12:39:45 -050031import android.telephony.TelephonyManager;
Jason Monke427cb82015-07-28 09:18:08 -040032import android.test.suitebuilder.annotation.SmallTest;
Jason Monk2515f472017-09-19 09:52:43 -040033import android.testing.AndroidTestingRunner;
34import android.testing.TestableLooper.RunWithLooper;
Jason Monke0cdb602014-11-05 12:39:45 -050035
Jason Monk18985e02015-01-07 12:07:06 -050036import com.android.internal.telephony.PhoneConstants;
Leigh Anned0a62792014-11-13 14:27:10 -080037import com.android.internal.telephony.TelephonyIntents;
Evan Laird06e9fd82018-02-10 09:36:55 -080038import com.android.settingslib.graph.SignalDrawable;
Jason Monkf668d7c2016-01-14 10:38:41 -050039import com.android.settingslib.net.DataUsageController;
Jason Monkf13b4b32014-11-07 16:39:34 -050040import com.android.systemui.R;
Jason Monkda68f592015-01-07 10:55:58 -050041
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -040042import org.junit.Test;
43import org.junit.runner.RunWith;
Jason Monkc6cc6262015-06-11 11:10:15 -040044import org.mockito.ArgumentCaptor;
Jason Monkda68f592015-01-07 10:55:58 -050045import org.mockito.Mockito;
46
47import java.util.ArrayList;
48import java.util.List;
Jason Monkf13b4b32014-11-07 16:39:34 -050049
Jason Monke427cb82015-07-28 09:18:08 -040050@SmallTest
Jason Monk2515f472017-09-19 09:52:43 -040051@RunWith(AndroidTestingRunner.class)
52@RunWithLooper
Jason Monke0cdb602014-11-05 12:39:45 -050053public class NetworkControllerSignalTest extends NetworkControllerBaseTest {
54
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -040055 @Test
Jason Monkf13b4b32014-11-07 16:39:34 -050056 public void testNoIconWithoutMobile() {
57 // Turn off mobile network support.
58 Mockito.when(mMockCm.isNetworkSupported(ConnectivityManager.TYPE_MOBILE)).thenReturn(false);
59 // Create a new NetworkController as this is currently handled in constructor.
Sundeep Ghuman9d10a3c2017-06-16 00:05:16 +000060 mNetworkController = new NetworkControllerImpl(mContext, mMockCm, mMockTm, mMockWm, mMockSm,
Jason Monk07b75fe2015-05-14 16:47:03 -040061 mConfig, Looper.getMainLooper(), mCallbackHandler,
Jason Monkf668d7c2016-01-14 10:38:41 -050062 mock(AccessPointControllerImpl.class), mock(DataUsageController.class),
Jason Monk9c7844c2017-01-18 15:21:53 -050063 mMockSubDefaults, mock(DeviceProvisionedController.class));
Jason Monkf13b4b32014-11-07 16:39:34 -050064 setupNetworkController();
Jason Monke0cdb602014-11-05 12:39:45 -050065
Jason Monk48edc0c2017-04-10 15:01:27 -040066 verifyLastMobileDataIndicators(false, -1, 0);
Jason Monkf13b4b32014-11-07 16:39:34 -050067 }
68
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -040069 @Test
Jason Monk21d05a02014-12-02 12:46:58 -050070 public void testNoSimsIconPresent() {
71 // No Subscriptions.
72 mNetworkController.mMobileSignalControllers.clear();
73 mNetworkController.updateNoSims();
74
75 verifyHasNoSims(true);
76 }
77
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -040078 @Test
Jason Monkc6cc6262015-06-11 11:10:15 -040079 public void testEmergencyOnly() {
80 setupDefaultSignal();
81 mNetworkController.recalculateEmergency();
82 verifyEmergencyOnly(false);
83
84 mMobileSignalController.getState().isEmergency = true;
85 mNetworkController.recalculateEmergency();
86 verifyEmergencyOnly(true);
87 }
88
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -040089 @Test
Jason Monkc6cc6262015-06-11 11:10:15 -040090 public void testEmergencyOnlyNoSubscriptions() {
91 setupDefaultSignal();
Jason Monkb0808aa2015-07-22 16:34:36 -040092 setSubscriptions();
93 mNetworkController.mLastServiceState = new ServiceState();
94 mNetworkController.mLastServiceState.setEmergencyOnly(true);
95 mNetworkController.recalculateEmergency();
96 verifyEmergencyOnly(true);
97 }
98
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -040099 @Test
Jason Monk8996b942017-03-02 13:58:19 -0500100 public void testNoEmergencyOnlyWrongSubscription() {
101 setupDefaultSignal();
102 setDefaultSubId(42);
103 mNetworkController.recalculateEmergency();
104 verifyEmergencyOnly(false);
105 }
106
107 @Test
Jason Monkb0808aa2015-07-22 16:34:36 -0400108 public void testNoEmengencyNoSubscriptions() {
109 setupDefaultSignal();
110 setSubscriptions();
111 mNetworkController.mLastServiceState = new ServiceState();
112 mNetworkController.mLastServiceState.setEmergencyOnly(false);
Jason Monkc6cc6262015-06-11 11:10:15 -0400113 mNetworkController.recalculateEmergency();
114 verifyEmergencyOnly(false);
Jason Monkc6cc6262015-06-11 11:10:15 -0400115 }
116
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -0400117 @Test
Jason Monk21d05a02014-12-02 12:46:58 -0500118 public void testNoSimlessIconWithoutMobile() {
119 // Turn off mobile network support.
120 Mockito.when(mMockCm.isNetworkSupported(ConnectivityManager.TYPE_MOBILE)).thenReturn(false);
121 // Create a new NetworkController as this is currently handled in constructor.
Sundeep Ghuman9d10a3c2017-06-16 00:05:16 +0000122 mNetworkController = new NetworkControllerImpl(mContext, mMockCm, mMockTm, mMockWm, mMockSm,
Jason Monk07b75fe2015-05-14 16:47:03 -0400123 mConfig, Looper.getMainLooper(), mCallbackHandler,
Jason Monkf668d7c2016-01-14 10:38:41 -0500124 mock(AccessPointControllerImpl.class), mock(DataUsageController.class),
Jason Monk9c7844c2017-01-18 15:21:53 -0500125 mMockSubDefaults, mock(DeviceProvisionedController.class));
Jason Monk21d05a02014-12-02 12:46:58 -0500126 setupNetworkController();
127
128 // No Subscriptions.
129 mNetworkController.mMobileSignalControllers.clear();
130 mNetworkController.updateNoSims();
131
132 verifyHasNoSims(false);
133 }
134
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -0400135 @Test
Jason Monkf13b4b32014-11-07 16:39:34 -0500136 public void testSignalStrength() {
Jason Monk48edc0c2017-04-10 15:01:27 -0400137 for (int testStrength = 0;
138 testStrength < SignalStrength.NUM_SIGNAL_STRENGTH_BINS; testStrength++) {
Jason Monkf13b4b32014-11-07 16:39:34 -0500139 setupDefaultSignal();
140 setLevel(testStrength);
141
142 verifyLastMobileDataIndicators(true,
Jason Monk48edc0c2017-04-10 15:01:27 -0400143 testStrength, DEFAULT_ICON);
Jason Monkf13b4b32014-11-07 16:39:34 -0500144
145 // Verify low inet number indexing.
Anarghya Mitra678722f2018-05-11 14:29:54 -0700146 setConnectivityViaBroadcast(NetworkCapabilities.TRANSPORT_CELLULAR, false, true);
Jason Monkf13b4b32014-11-07 16:39:34 -0500147 verifyLastMobileDataIndicators(true,
Jason Monk48edc0c2017-04-10 15:01:27 -0400148 testStrength, DEFAULT_ICON, false, false);
Jason Monkf13b4b32014-11-07 16:39:34 -0500149 }
150 }
151
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -0400152 @Test
Jason Monkf13b4b32014-11-07 16:39:34 -0500153 public void testCdmaSignalStrength() {
Jason Monk48edc0c2017-04-10 15:01:27 -0400154 for (int testStrength = 0;
155 testStrength < SignalStrength.NUM_SIGNAL_STRENGTH_BINS; testStrength++) {
Jason Monkf13b4b32014-11-07 16:39:34 -0500156 setupDefaultSignal();
157 setCdma();
158 setLevel(testStrength);
159
160 verifyLastMobileDataIndicators(true,
Jason Monk48edc0c2017-04-10 15:01:27 -0400161 testStrength,
162 TelephonyIcons.ICON_1X);
Jason Monkf13b4b32014-11-07 16:39:34 -0500163 }
Jason Monke0cdb602014-11-05 12:39:45 -0500164 }
165
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -0400166 @Test
Jason Monke0cdb602014-11-05 12:39:45 -0500167 public void testSignalRoaming() {
Jason Monk48edc0c2017-04-10 15:01:27 -0400168 for (int testStrength = 0;
169 testStrength < SignalStrength.NUM_SIGNAL_STRENGTH_BINS; testStrength++) {
Jason Monkf13b4b32014-11-07 16:39:34 -0500170 setupDefaultSignal();
171 setGsmRoaming(true);
172 setLevel(testStrength);
Jason Monke0cdb602014-11-05 12:39:45 -0500173
Jason Monkf13b4b32014-11-07 16:39:34 -0500174 verifyLastMobileDataIndicators(true,
Jason Monk48edc0c2017-04-10 15:01:27 -0400175 testStrength,
Jason Monk0f0de132016-12-19 15:36:13 -0500176 DEFAULT_ICON, true);
Jason Monkf13b4b32014-11-07 16:39:34 -0500177 }
178 }
179
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -0400180 @Test
Jason Monkf13b4b32014-11-07 16:39:34 -0500181 public void testCdmaSignalRoaming() {
182 for (int testStrength = SignalStrength.SIGNAL_STRENGTH_NONE_OR_UNKNOWN;
183 testStrength <= SignalStrength.SIGNAL_STRENGTH_GREAT; testStrength++) {
184 setupDefaultSignal();
185 setCdma();
186 setCdmaRoaming(true);
187 setLevel(testStrength);
188
189 verifyLastMobileDataIndicators(true,
Jason Monk48edc0c2017-04-10 15:01:27 -0400190 testStrength,
191 TelephonyIcons.ICON_1X, true);
Jason Monkf13b4b32014-11-07 16:39:34 -0500192 }
193 }
194
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -0400195 @Test
Jason Monke1531982017-09-05 11:20:30 -0400196 public void testRoamingNoService_DoesNotCrash() {
197 setupDefaultSignal();
198 setCdma();
199 mServiceState = null;
200 updateServiceState();
201 }
202
203 @Test
Jason Monkf13b4b32014-11-07 16:39:34 -0500204 public void testQsSignalStrength() {
205 for (int testStrength = SignalStrength.SIGNAL_STRENGTH_NONE_OR_UNKNOWN;
206 testStrength <= SignalStrength.SIGNAL_STRENGTH_GREAT; testStrength++) {
207 setupDefaultSignal();
208 setLevel(testStrength);
209
210 verifyLastQsMobileDataIndicators(true,
Jason Monk48edc0c2017-04-10 15:01:27 -0400211 testStrength,
Jason Monkb5746272014-11-12 16:50:31 -0500212 DEFAULT_QS_ICON, false, false);
Jason Monkf13b4b32014-11-07 16:39:34 -0500213 }
214 }
215
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -0400216 @Test
Jason Monkf13b4b32014-11-07 16:39:34 -0500217 public void testCdmaQsSignalStrength() {
218 for (int testStrength = SignalStrength.SIGNAL_STRENGTH_NONE_OR_UNKNOWN;
219 testStrength <= SignalStrength.SIGNAL_STRENGTH_GREAT; testStrength++) {
220 setupDefaultSignal();
221 setCdma();
222 setLevel(testStrength);
223
224 verifyLastQsMobileDataIndicators(true,
Jason Monk48edc0c2017-04-10 15:01:27 -0400225 testStrength,
Amin Shaikhd64e6262018-03-08 10:08:13 -0500226 TelephonyIcons.ICON_1X, false, false);
Jason Monkf13b4b32014-11-07 16:39:34 -0500227 }
228 }
229
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -0400230 @Test
Jason Monk33f8ae72015-05-08 10:45:15 -0400231 public void testNoBangWithWifi() {
Jason Monkf13b4b32014-11-07 16:39:34 -0500232 setupDefaultSignal();
Anarghya Mitra678722f2018-05-11 14:29:54 -0700233 setConnectivityViaBroadcast(mMobileSignalController.mTransportType, false, false);
234 setConnectivityViaBroadcast(NetworkCapabilities.TRANSPORT_WIFI, true, true);
Jason Monkf13b4b32014-11-07 16:39:34 -0500235
Jason Monk48edc0c2017-04-10 15:01:27 -0400236 verifyLastMobileDataIndicators(true, DEFAULT_LEVEL, 0);
Jason Monkf13b4b32014-11-07 16:39:34 -0500237 }
238
Jason Monkc014dec2014-12-12 11:49:55 -0500239 // Some tests of actual NetworkController code, just internals not display stuff
240 // TODO: Put this somewhere else, maybe in its own file.
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -0400241 @Test
Jason Monkc014dec2014-12-12 11:49:55 -0500242 public void testHasCorrectMobileControllers() {
243 int[] testSubscriptions = new int[] { 1, 5, 3 };
244 int notTestSubscription = 0;
245 MobileSignalController mobileSignalController = Mockito.mock(MobileSignalController.class);
246
247 mNetworkController.mMobileSignalControllers.clear();
248 List<SubscriptionInfo> subscriptions = new ArrayList<>();
249 for (int i = 0; i < testSubscriptions.length; i++) {
250 // Force the test controllers into NetworkController.
251 mNetworkController.mMobileSignalControllers.put(testSubscriptions[i],
252 mobileSignalController);
253
254 // Generate a list of subscriptions we will tell the NetworkController to use.
255 SubscriptionInfo mockSubInfo = Mockito.mock(SubscriptionInfo.class);
256 Mockito.when(mockSubInfo.getSubscriptionId()).thenReturn(testSubscriptions[i]);
257 subscriptions.add(mockSubInfo);
258 }
259 assertTrue(mNetworkController.hasCorrectMobileControllers(subscriptions));
260
261 // Add a subscription that the NetworkController doesn't know about.
262 SubscriptionInfo mockSubInfo = Mockito.mock(SubscriptionInfo.class);
263 Mockito.when(mockSubInfo.getSubscriptionId()).thenReturn(notTestSubscription);
264 subscriptions.add(mockSubInfo);
265 assertFalse(mNetworkController.hasCorrectMobileControllers(subscriptions));
266 }
267
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -0400268 @Test
Jason Monkc014dec2014-12-12 11:49:55 -0500269 public void testSetCurrentSubscriptions() {
270 // We will not add one controller to make sure it gets created.
271 int indexToSkipController = 0;
272 // We will not add one subscription to make sure it's controller gets removed.
273 int indexToSkipSubscription = 1;
274
275 int[] testSubscriptions = new int[] { 1, 5, 3 };
276 MobileSignalController[] mobileSignalControllers = new MobileSignalController[] {
277 Mockito.mock(MobileSignalController.class),
278 Mockito.mock(MobileSignalController.class),
279 Mockito.mock(MobileSignalController.class),
280 };
281 mNetworkController.mMobileSignalControllers.clear();
282 List<SubscriptionInfo> subscriptions = new ArrayList<>();
283 for (int i = 0; i < testSubscriptions.length; i++) {
284 if (i != indexToSkipController) {
285 // Force the test controllers into NetworkController.
286 mNetworkController.mMobileSignalControllers.put(testSubscriptions[i],
287 mobileSignalControllers[i]);
288 }
289
290 if (i != indexToSkipSubscription) {
291 // Generate a list of subscriptions we will tell the NetworkController to use.
292 SubscriptionInfo mockSubInfo = Mockito.mock(SubscriptionInfo.class);
293 Mockito.when(mockSubInfo.getSubscriptionId()).thenReturn(testSubscriptions[i]);
294 Mockito.when(mockSubInfo.getSimSlotIndex()).thenReturn(testSubscriptions[i]);
295 subscriptions.add(mockSubInfo);
296 }
297 }
298
299 // We can only test whether unregister gets called if it thinks its in a listening
300 // state.
301 mNetworkController.mListening = true;
302 mNetworkController.setCurrentSubscriptions(subscriptions);
303
304 for (int i = 0; i < testSubscriptions.length; i++) {
305 if (i == indexToSkipController) {
306 // Make sure a controller was created despite us not adding one.
Jason Monk8996b942017-03-02 13:58:19 -0500307 assertTrue(mNetworkController.mMobileSignalControllers.indexOfKey(
308 testSubscriptions[i]) >= 0);
Jason Monkc014dec2014-12-12 11:49:55 -0500309 } else if (i == indexToSkipSubscription) {
310 // Make sure the controller that did exist was removed
Jason Monk8996b942017-03-02 13:58:19 -0500311 assertFalse(mNetworkController.mMobileSignalControllers.indexOfKey(
312 testSubscriptions[i]) >= 0);
Jason Monkc014dec2014-12-12 11:49:55 -0500313 } else {
314 // If a MobileSignalController is around it needs to not be unregistered.
315 Mockito.verify(mobileSignalControllers[i], Mockito.never())
316 .unregisterListener();
317 }
318 }
319 }
320
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -0400321 @Test
Jason Monk7f9623f2015-02-11 09:03:02 -0500322 public void testHistorySize() {
323 // Verify valid history size, otherwise it gits printed out the wrong order and whatnot.
324 assertEquals(0, SignalController.HISTORY_SIZE & (SignalController.HISTORY_SIZE - 1));
325 }
326
Jason Monkf13b4b32014-11-07 16:39:34 -0500327 private void setCdma() {
328 setIsGsm(false);
329 updateDataConnectionState(TelephonyManager.DATA_CONNECTED,
330 TelephonyManager.NETWORK_TYPE_CDMA);
331 setCdmaRoaming(false);
Jason Monke0cdb602014-11-05 12:39:45 -0500332 }
Leigh Anned0a62792014-11-13 14:27:10 -0800333
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -0400334 @Test
Leigh Anned0a62792014-11-13 14:27:10 -0800335 public void testOnReceive_stringsUpdatedAction_spn() {
336 String expectedMNetworkName = "Test";
337 Intent intent = createStringsUpdatedIntent(true /* showSpn */,
338 expectedMNetworkName /* spn */,
339 false /* showPlmn */,
340 "NotTest" /* plmn */);
341
342 mNetworkController.onReceive(mContext, intent);
343
344 assertNetworkNameEquals(expectedMNetworkName);
345 }
346
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -0400347 @Test
Leigh Anned0a62792014-11-13 14:27:10 -0800348 public void testOnReceive_stringsUpdatedAction_plmn() {
349 String expectedMNetworkName = "Test";
350
351 Intent intent = createStringsUpdatedIntent(false /* showSpn */,
352 "NotTest" /* spn */,
353 true /* showPlmn */,
354 expectedMNetworkName /* plmn */);
355
356 mNetworkController.onReceive(mContext, intent);
357
358 assertNetworkNameEquals(expectedMNetworkName);
359 }
360
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -0400361 @Test
Leigh Anned0a62792014-11-13 14:27:10 -0800362 public void testOnReceive_stringsUpdatedAction_bothFalse() {
363 Intent intent = createStringsUpdatedIntent(false /* showSpn */,
364 "Irrelevant" /* spn */,
365 false /* showPlmn */,
366 "Irrelevant" /* plmn */);
367
368 mNetworkController.onReceive(mContext, intent);
369
370 String defaultNetworkName = mMobileSignalController
371 .getStringIfExists(
372 com.android.internal.R.string.lockscreen_carrier_default);
373 assertNetworkNameEquals(defaultNetworkName);
374 }
375
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -0400376 @Test
Leigh Anned0a62792014-11-13 14:27:10 -0800377 public void testOnReceive_stringsUpdatedAction_bothTrueAndNull() {
378 Intent intent = createStringsUpdatedIntent(true /* showSpn */,
379 null /* spn */,
380 true /* showPlmn */,
381 null /* plmn */);
382
383 mNetworkController.onReceive(mContext, intent);
384
385 String defaultNetworkName = mMobileSignalController.getStringIfExists(
386 com.android.internal.R.string.lockscreen_carrier_default);
387 assertNetworkNameEquals(defaultNetworkName);
388 }
389
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -0400390 @Test
Leigh Anned0a62792014-11-13 14:27:10 -0800391 public void testOnReceive_stringsUpdatedAction_bothTrueAndNonNull() {
392 String spn = "Test1";
393 String plmn = "Test2";
394
395 Intent intent = createStringsUpdatedIntent(true /* showSpn */,
396 spn /* spn */,
397 true /* showPlmn */,
398 plmn /* plmn */);
399
400 mNetworkController.onReceive(mContext, intent);
401
402 assertNetworkNameEquals(plmn
403 + mMobileSignalController.getStringIfExists(
404 R.string.status_bar_network_name_separator)
405 + spn);
406 }
407
408 private Intent createStringsUpdatedIntent(boolean showSpn, String spn,
409 boolean showPlmn, String plmn) {
410
411 Intent intent = new Intent();
412 intent.setAction(TelephonyIntents.SPN_STRINGS_UPDATED_ACTION);
413
414 intent.putExtra(TelephonyIntents.EXTRA_SHOW_SPN, showSpn);
415 intent.putExtra(TelephonyIntents.EXTRA_SPN, spn);
416
417 intent.putExtra(TelephonyIntents.EXTRA_SHOW_PLMN, showPlmn);
418 intent.putExtra(TelephonyIntents.EXTRA_PLMN, plmn);
Jason Monk18985e02015-01-07 12:07:06 -0500419 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, mSubId);
Leigh Anned0a62792014-11-13 14:27:10 -0800420
421 return intent;
422 }
423
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -0400424 @Test
Leigh Anned0a62792014-11-13 14:27:10 -0800425 public void testOnUpdateDataActivity_dataIn() {
426 setupDefaultSignal();
427
428 updateDataActivity(TelephonyManager.DATA_ACTIVITY_IN);
429
430 verifyLastQsMobileDataIndicators(true /* visible */,
Jason Monk48edc0c2017-04-10 15:01:27 -0400431 DEFAULT_LEVEL /* icon */,
Leigh Anned0a62792014-11-13 14:27:10 -0800432 DEFAULT_QS_ICON /* typeIcon */,
433 true /* dataIn */,
434 false /* dataOut */);
435
436 }
437
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -0400438 @Test
Leigh Anned0a62792014-11-13 14:27:10 -0800439 public void testOnUpdateDataActivity_dataOut() {
440 setupDefaultSignal();
441
442 updateDataActivity(TelephonyManager.DATA_ACTIVITY_OUT);
443
444 verifyLastQsMobileDataIndicators(true /* visible */,
Jason Monk48edc0c2017-04-10 15:01:27 -0400445 DEFAULT_LEVEL /* icon */,
Jason Monk7e6c83c2017-04-26 14:35:24 -0400446 DEFAULT_QS_ICON /* typeIcon */,
Leigh Anned0a62792014-11-13 14:27:10 -0800447 false /* dataIn */,
448 true /* dataOut */);
Leigh Anned0a62792014-11-13 14:27:10 -0800449 }
450
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -0400451 @Test
Leigh Anned0a62792014-11-13 14:27:10 -0800452 public void testOnUpdateDataActivity_dataInOut() {
453 setupDefaultSignal();
454
455 updateDataActivity(TelephonyManager.DATA_ACTIVITY_INOUT);
456
457 verifyLastQsMobileDataIndicators(true /* visible */,
Jason Monk48edc0c2017-04-10 15:01:27 -0400458 DEFAULT_LEVEL /* icon */,
Leigh Anned0a62792014-11-13 14:27:10 -0800459 DEFAULT_QS_ICON /* typeIcon */,
460 true /* dataIn */,
461 true /* dataOut */);
462
463 }
464
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -0400465 @Test
Leigh Anned0a62792014-11-13 14:27:10 -0800466 public void testOnUpdateDataActivity_dataActivityNone() {
467 setupDefaultSignal();
468
469 updateDataActivity(TelephonyManager.DATA_ACTIVITY_NONE);
470
471 verifyLastQsMobileDataIndicators(true /* visible */,
Jason Monk48edc0c2017-04-10 15:01:27 -0400472 DEFAULT_LEVEL /* icon */,
Leigh Anned0a62792014-11-13 14:27:10 -0800473 DEFAULT_QS_ICON /* typeIcon */,
474 false /* dataIn */,
475 false /* dataOut */);
476
477 }
Andrew Flynn5e751472015-05-01 11:50:07 -0400478
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -0400479 @Test
Andrew Flynn55fc8002015-05-29 08:33:46 -0400480 public void testCarrierNetworkChange_carrierNetworkChange() {
Andrew Flynn5e751472015-05-01 11:50:07 -0400481 int strength = SignalStrength.SIGNAL_STRENGTH_GREAT;
482
483 setupDefaultSignal();
484 setLevel(strength);
485
486 // Verify baseline
487 verifyLastMobileDataIndicators(true /* visible */,
Jason Monk48edc0c2017-04-10 15:01:27 -0400488 strength /* strengthIcon */,
Andrew Flynn5e751472015-05-01 11:50:07 -0400489 DEFAULT_ICON /* typeIcon */);
490
Andrew Flynn55fc8002015-05-29 08:33:46 -0400491 // API call is made
Andrew Flynn5e751472015-05-01 11:50:07 -0400492 setCarrierNetworkChange(true /* enabled */);
Andrew Flynn5e751472015-05-01 11:50:07 -0400493
Andrew Flynn55fc8002015-05-29 08:33:46 -0400494 // Carrier network change is true, show special indicator
Andrew Flynn5e751472015-05-01 11:50:07 -0400495 verifyLastMobileDataIndicators(true /* visible */,
Jason Monk48edc0c2017-04-10 15:01:27 -0400496 SignalDrawable.getCarrierChangeState(SignalStrength.NUM_SIGNAL_STRENGTH_BINS),
Andrew Flynn5e751472015-05-01 11:50:07 -0400497 0 /* typeIcon */);
498
499 // Revert back
500 setCarrierNetworkChange(false /* enabled */);
Andrew Flynn5e751472015-05-01 11:50:07 -0400501
502 // Verify back in previous state
503 verifyLastMobileDataIndicators(true /* visible */,
Jason Monk48edc0c2017-04-10 15:01:27 -0400504 strength /* strengthIcon */,
Andrew Flynn5e751472015-05-01 11:50:07 -0400505 DEFAULT_ICON /* typeIcon */);
506 }
Jason Monkc6cc6262015-06-11 11:10:15 -0400507
Shishir Agrawal7ef5b882017-06-26 12:06:03 -0700508 @Test
509 public void testCarrierNetworkChange_roamingBeforeNetworkChange() {
510 int strength = SignalStrength.SIGNAL_STRENGTH_GREAT;
511
512 setupDefaultSignal();
513 setLevel(strength);
514 setGsmRoaming(true);
515
516 // Verify baseline
517 verifyLastMobileDataIndicators(true /* visible */,
518 strength /* strengthIcon */,
519 DEFAULT_ICON /* typeIcon */,
520 true /* roaming */);
521
522 // API call is made
523 setCarrierNetworkChange(true /* enabled */);
524
525 // Carrier network change is true, show special indicator, no roaming.
526 verifyLastMobileDataIndicators(true /* visible */,
527 SignalDrawable.getCarrierChangeState(SignalStrength.NUM_SIGNAL_STRENGTH_BINS),
528 0 /* typeIcon */,
529 false /* roaming */);
530
531 // Revert back
532 setCarrierNetworkChange(false /* enabled */);
533
534 // Verify back in previous state
535 verifyLastMobileDataIndicators(true /* visible */,
536 strength /* strengthIcon */,
537 DEFAULT_ICON /* typeIcon */,
538 true /* roaming */);
539 }
540
541 @Test
542 public void testCarrierNetworkChange_roamingAfterNetworkChange() {
543 int strength = SignalStrength.SIGNAL_STRENGTH_GREAT;
544
545 setupDefaultSignal();
546 setLevel(strength);
547
548 // Verify baseline
549 verifyLastMobileDataIndicators(true /* visible */,
550 strength /* strengthIcon */,
551 DEFAULT_ICON /* typeIcon */,
552 false /* roaming */);
553
554 // API call is made
555 setCarrierNetworkChange(true /* enabled */);
556
557 // Carrier network change is true, show special indicator, no roaming.
558 verifyLastMobileDataIndicators(true /* visible */,
559 SignalDrawable.getCarrierChangeState(SignalStrength.NUM_SIGNAL_STRENGTH_BINS),
560 0 /* typeIcon */,
561 false /* roaming */);
562
563 setGsmRoaming(true);
564
565 // Roaming should not show.
566 verifyLastMobileDataIndicators(true /* visible */,
567 SignalDrawable.getCarrierChangeState(SignalStrength.NUM_SIGNAL_STRENGTH_BINS),
568 0 /* typeIcon */,
569 false /* roaming */);
570
571 // Revert back
572 setCarrierNetworkChange(false /* enabled */);
573
574 // Verify back in previous state
575 verifyLastMobileDataIndicators(true /* visible */,
576 strength /* strengthIcon */,
577 DEFAULT_ICON /* typeIcon */,
578 true /* roaming */);
579 }
580
Jason Monkc6cc6262015-06-11 11:10:15 -0400581 private void verifyEmergencyOnly(boolean isEmergencyOnly) {
582 ArgumentCaptor<Boolean> emergencyOnly = ArgumentCaptor.forClass(Boolean.class);
583 Mockito.verify(mCallbackHandler, Mockito.atLeastOnce()).setEmergencyCallsOnly(
584 emergencyOnly.capture());
585 assertEquals(isEmergencyOnly, (boolean) emergencyOnly.getValue());
586 }
Jason Monke0cdb602014-11-05 12:39:45 -0500587}