blob: 57dcbf21e1473ce6ad2b9689127d14fc936d7341 [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;
Fabian Kozynskia9091992019-03-25 11:08:32 -040023import static org.mockito.Mockito.when;
Brett Chabot84151d92019-02-27 15:37:59 -080024
Leigh Anned0a62792014-11-13 14:27:10 -080025import android.content.Intent;
Jason Monke0cdb602014-11-05 12:39:45 -050026import android.net.ConnectivityManager;
Jason Monk33f8ae72015-05-08 10:45:15 -040027import android.net.NetworkCapabilities;
Jason Monk07b75fe2015-05-14 16:47:03 -040028import android.os.Looper;
Jason Monkb0808aa2015-07-22 16:34:36 -040029import android.telephony.ServiceState;
Jason Monke0cdb602014-11-05 12:39:45 -050030import android.telephony.SignalStrength;
Jason Monkc014dec2014-12-12 11:49:55 -050031import android.telephony.SubscriptionInfo;
Jason Monke0cdb602014-11-05 12:39:45 -050032import android.telephony.TelephonyManager;
Jason Monke427cb82015-07-28 09:18:08 -040033import android.test.suitebuilder.annotation.SmallTest;
Jason Monk2515f472017-09-19 09:52:43 -040034import android.testing.AndroidTestingRunner;
35import android.testing.TestableLooper.RunWithLooper;
Jason Monke0cdb602014-11-05 12:39:45 -050036
Jason Monk18985e02015-01-07 12:07:06 -050037import com.android.internal.telephony.PhoneConstants;
Leigh Anned0a62792014-11-13 14:27:10 -080038import com.android.internal.telephony.TelephonyIntents;
Evan Laird06e9fd82018-02-10 09:36:55 -080039import com.android.settingslib.graph.SignalDrawable;
Jason Monkf668d7c2016-01-14 10:38:41 -050040import com.android.settingslib.net.DataUsageController;
Jason Monkf13b4b32014-11-07 16:39:34 -050041import com.android.systemui.R;
Jason Monkda68f592015-01-07 10:55:58 -050042
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -040043import org.junit.Test;
44import org.junit.runner.RunWith;
Jason Monkc6cc6262015-06-11 11:10:15 -040045import org.mockito.ArgumentCaptor;
Jason Monkda68f592015-01-07 10:55:58 -050046import org.mockito.Mockito;
47
48import java.util.ArrayList;
49import java.util.List;
Jason Monkf13b4b32014-11-07 16:39:34 -050050
Jason Monke427cb82015-07-28 09:18:08 -040051@SmallTest
Jason Monk2515f472017-09-19 09:52:43 -040052@RunWith(AndroidTestingRunner.class)
53@RunWithLooper
Jason Monke0cdb602014-11-05 12:39:45 -050054public class NetworkControllerSignalTest extends NetworkControllerBaseTest {
55
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -040056 @Test
Jason Monkf13b4b32014-11-07 16:39:34 -050057 public void testNoIconWithoutMobile() {
58 // Turn off mobile network support.
Fabian Kozynskia9091992019-03-25 11:08:32 -040059 when(mMockCm.isNetworkSupported(ConnectivityManager.TYPE_MOBILE)).thenReturn(false);
Jason Monkf13b4b32014-11-07 16:39:34 -050060 // Create a new NetworkController as this is currently handled in constructor.
Sundeep Ghuman9d10a3c2017-06-16 00:05:16 +000061 mNetworkController = new NetworkControllerImpl(mContext, mMockCm, mMockTm, mMockWm, mMockSm,
Jason Monk07b75fe2015-05-14 16:47:03 -040062 mConfig, Looper.getMainLooper(), mCallbackHandler,
Jason Monkf668d7c2016-01-14 10:38:41 -050063 mock(AccessPointControllerImpl.class), mock(DataUsageController.class),
Fabian Kozynski5ca7a512019-10-16 19:56:11 +000064 mMockSubDefaults, mock(DeviceProvisionedController.class), mMockBd);
Jason Monkf13b4b32014-11-07 16:39:34 -050065 setupNetworkController();
Jason Monke0cdb602014-11-05 12:39:45 -050066
Jason Monk48edc0c2017-04-10 15:01:27 -040067 verifyLastMobileDataIndicators(false, -1, 0);
Jason Monkf13b4b32014-11-07 16:39:34 -050068 }
69
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -040070 @Test
Jason Monk21d05a02014-12-02 12:46:58 -050071 public void testNoSimsIconPresent() {
72 // No Subscriptions.
73 mNetworkController.mMobileSignalControllers.clear();
74 mNetworkController.updateNoSims();
75
76 verifyHasNoSims(true);
77 }
78
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -040079 @Test
Jason Monkc6cc6262015-06-11 11:10:15 -040080 public void testEmergencyOnly() {
81 setupDefaultSignal();
82 mNetworkController.recalculateEmergency();
83 verifyEmergencyOnly(false);
84
85 mMobileSignalController.getState().isEmergency = true;
86 mNetworkController.recalculateEmergency();
87 verifyEmergencyOnly(true);
88 }
89
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -040090 @Test
Jason Monkc6cc6262015-06-11 11:10:15 -040091 public void testEmergencyOnlyNoSubscriptions() {
92 setupDefaultSignal();
Jason Monkb0808aa2015-07-22 16:34:36 -040093 setSubscriptions();
94 mNetworkController.mLastServiceState = new ServiceState();
95 mNetworkController.mLastServiceState.setEmergencyOnly(true);
96 mNetworkController.recalculateEmergency();
97 verifyEmergencyOnly(true);
98 }
99
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -0400100 @Test
Jason Monk8996b942017-03-02 13:58:19 -0500101 public void testNoEmergencyOnlyWrongSubscription() {
102 setupDefaultSignal();
103 setDefaultSubId(42);
104 mNetworkController.recalculateEmergency();
105 verifyEmergencyOnly(false);
106 }
107
108 @Test
Jason Monkb0808aa2015-07-22 16:34:36 -0400109 public void testNoEmengencyNoSubscriptions() {
110 setupDefaultSignal();
111 setSubscriptions();
112 mNetworkController.mLastServiceState = new ServiceState();
113 mNetworkController.mLastServiceState.setEmergencyOnly(false);
Jason Monkc6cc6262015-06-11 11:10:15 -0400114 mNetworkController.recalculateEmergency();
115 verifyEmergencyOnly(false);
Jason Monkc6cc6262015-06-11 11:10:15 -0400116 }
117
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -0400118 @Test
Jason Monk21d05a02014-12-02 12:46:58 -0500119 public void testNoSimlessIconWithoutMobile() {
120 // Turn off mobile network support.
Fabian Kozynskia9091992019-03-25 11:08:32 -0400121 when(mMockCm.isNetworkSupported(ConnectivityManager.TYPE_MOBILE)).thenReturn(false);
Jason Monk21d05a02014-12-02 12:46:58 -0500122 // Create a new NetworkController as this is currently handled in constructor.
Sundeep Ghuman9d10a3c2017-06-16 00:05:16 +0000123 mNetworkController = new NetworkControllerImpl(mContext, mMockCm, mMockTm, mMockWm, mMockSm,
Jason Monk07b75fe2015-05-14 16:47:03 -0400124 mConfig, Looper.getMainLooper(), mCallbackHandler,
Jason Monkf668d7c2016-01-14 10:38:41 -0500125 mock(AccessPointControllerImpl.class), mock(DataUsageController.class),
Fabian Kozynski5ca7a512019-10-16 19:56:11 +0000126 mMockSubDefaults, mock(DeviceProvisionedController.class), mMockBd);
Jason Monk21d05a02014-12-02 12:46:58 -0500127 setupNetworkController();
128
129 // No Subscriptions.
130 mNetworkController.mMobileSignalControllers.clear();
131 mNetworkController.updateNoSims();
132
133 verifyHasNoSims(false);
134 }
135
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -0400136 @Test
Jason Monkf13b4b32014-11-07 16:39:34 -0500137 public void testSignalStrength() {
Jason Monk48edc0c2017-04-10 15:01:27 -0400138 for (int testStrength = 0;
139 testStrength < SignalStrength.NUM_SIGNAL_STRENGTH_BINS; testStrength++) {
Jason Monkf13b4b32014-11-07 16:39:34 -0500140 setupDefaultSignal();
141 setLevel(testStrength);
142
143 verifyLastMobileDataIndicators(true,
Jason Monk48edc0c2017-04-10 15:01:27 -0400144 testStrength, DEFAULT_ICON);
Jason Monkf13b4b32014-11-07 16:39:34 -0500145
146 // Verify low inet number indexing.
Anarghya Mitra678722f2018-05-11 14:29:54 -0700147 setConnectivityViaBroadcast(NetworkCapabilities.TRANSPORT_CELLULAR, false, true);
Jason Monkf13b4b32014-11-07 16:39:34 -0500148 verifyLastMobileDataIndicators(true,
Jason Monk48edc0c2017-04-10 15:01:27 -0400149 testStrength, DEFAULT_ICON, false, false);
Jason Monkf13b4b32014-11-07 16:39:34 -0500150 }
151 }
152
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -0400153 @Test
Jason Monkf13b4b32014-11-07 16:39:34 -0500154 public void testCdmaSignalStrength() {
Jason Monk48edc0c2017-04-10 15:01:27 -0400155 for (int testStrength = 0;
156 testStrength < SignalStrength.NUM_SIGNAL_STRENGTH_BINS; testStrength++) {
Jason Monkf13b4b32014-11-07 16:39:34 -0500157 setupDefaultSignal();
158 setCdma();
159 setLevel(testStrength);
160
161 verifyLastMobileDataIndicators(true,
Jason Monk48edc0c2017-04-10 15:01:27 -0400162 testStrength,
163 TelephonyIcons.ICON_1X);
Jason Monkf13b4b32014-11-07 16:39:34 -0500164 }
Jason Monke0cdb602014-11-05 12:39:45 -0500165 }
166
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -0400167 @Test
Jason Monke0cdb602014-11-05 12:39:45 -0500168 public void testSignalRoaming() {
Jason Monk48edc0c2017-04-10 15:01:27 -0400169 for (int testStrength = 0;
170 testStrength < SignalStrength.NUM_SIGNAL_STRENGTH_BINS; testStrength++) {
Jason Monkf13b4b32014-11-07 16:39:34 -0500171 setupDefaultSignal();
172 setGsmRoaming(true);
173 setLevel(testStrength);
Jason Monke0cdb602014-11-05 12:39:45 -0500174
Jason Monkf13b4b32014-11-07 16:39:34 -0500175 verifyLastMobileDataIndicators(true,
Jason Monk48edc0c2017-04-10 15:01:27 -0400176 testStrength,
Jason Monk0f0de132016-12-19 15:36:13 -0500177 DEFAULT_ICON, true);
Jason Monkf13b4b32014-11-07 16:39:34 -0500178 }
179 }
180
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -0400181 @Test
Jason Monkf13b4b32014-11-07 16:39:34 -0500182 public void testCdmaSignalRoaming() {
183 for (int testStrength = SignalStrength.SIGNAL_STRENGTH_NONE_OR_UNKNOWN;
184 testStrength <= SignalStrength.SIGNAL_STRENGTH_GREAT; testStrength++) {
185 setupDefaultSignal();
186 setCdma();
187 setCdmaRoaming(true);
188 setLevel(testStrength);
189
190 verifyLastMobileDataIndicators(true,
Jason Monk48edc0c2017-04-10 15:01:27 -0400191 testStrength,
192 TelephonyIcons.ICON_1X, true);
Jason Monkf13b4b32014-11-07 16:39:34 -0500193 }
194 }
195
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -0400196 @Test
Jason Monke1531982017-09-05 11:20:30 -0400197 public void testRoamingNoService_DoesNotCrash() {
198 setupDefaultSignal();
199 setCdma();
200 mServiceState = null;
201 updateServiceState();
202 }
203
204 @Test
Jason Monkf13b4b32014-11-07 16:39:34 -0500205 public void testQsSignalStrength() {
206 for (int testStrength = SignalStrength.SIGNAL_STRENGTH_NONE_OR_UNKNOWN;
207 testStrength <= SignalStrength.SIGNAL_STRENGTH_GREAT; testStrength++) {
208 setupDefaultSignal();
209 setLevel(testStrength);
210
211 verifyLastQsMobileDataIndicators(true,
Jason Monk48edc0c2017-04-10 15:01:27 -0400212 testStrength,
Jason Monkb5746272014-11-12 16:50:31 -0500213 DEFAULT_QS_ICON, false, false);
Jason Monkf13b4b32014-11-07 16:39:34 -0500214 }
215 }
216
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -0400217 @Test
Jason Monkf13b4b32014-11-07 16:39:34 -0500218 public void testCdmaQsSignalStrength() {
219 for (int testStrength = SignalStrength.SIGNAL_STRENGTH_NONE_OR_UNKNOWN;
220 testStrength <= SignalStrength.SIGNAL_STRENGTH_GREAT; testStrength++) {
221 setupDefaultSignal();
222 setCdma();
223 setLevel(testStrength);
224
225 verifyLastQsMobileDataIndicators(true,
Jason Monk48edc0c2017-04-10 15:01:27 -0400226 testStrength,
Amin Shaikhd64e6262018-03-08 10:08:13 -0500227 TelephonyIcons.ICON_1X, false, false);
Jason Monkf13b4b32014-11-07 16:39:34 -0500228 }
229 }
230
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -0400231 @Test
Jason Monk33f8ae72015-05-08 10:45:15 -0400232 public void testNoBangWithWifi() {
Jason Monkf13b4b32014-11-07 16:39:34 -0500233 setupDefaultSignal();
Anarghya Mitra678722f2018-05-11 14:29:54 -0700234 setConnectivityViaBroadcast(mMobileSignalController.mTransportType, false, false);
235 setConnectivityViaBroadcast(NetworkCapabilities.TRANSPORT_WIFI, true, true);
Jason Monkf13b4b32014-11-07 16:39:34 -0500236
Jason Monk48edc0c2017-04-10 15:01:27 -0400237 verifyLastMobileDataIndicators(true, DEFAULT_LEVEL, 0);
Jason Monkf13b4b32014-11-07 16:39:34 -0500238 }
239
Jason Monkc014dec2014-12-12 11:49:55 -0500240 // Some tests of actual NetworkController code, just internals not display stuff
241 // TODO: Put this somewhere else, maybe in its own file.
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -0400242 @Test
Jason Monkc014dec2014-12-12 11:49:55 -0500243 public void testHasCorrectMobileControllers() {
244 int[] testSubscriptions = new int[] { 1, 5, 3 };
245 int notTestSubscription = 0;
246 MobileSignalController mobileSignalController = Mockito.mock(MobileSignalController.class);
247
248 mNetworkController.mMobileSignalControllers.clear();
249 List<SubscriptionInfo> subscriptions = new ArrayList<>();
250 for (int i = 0; i < testSubscriptions.length; i++) {
251 // Force the test controllers into NetworkController.
252 mNetworkController.mMobileSignalControllers.put(testSubscriptions[i],
253 mobileSignalController);
254
255 // Generate a list of subscriptions we will tell the NetworkController to use.
256 SubscriptionInfo mockSubInfo = Mockito.mock(SubscriptionInfo.class);
Fabian Kozynskia9091992019-03-25 11:08:32 -0400257 when(mockSubInfo.getSubscriptionId()).thenReturn(testSubscriptions[i]);
Jason Monkc014dec2014-12-12 11:49:55 -0500258 subscriptions.add(mockSubInfo);
259 }
260 assertTrue(mNetworkController.hasCorrectMobileControllers(subscriptions));
261
262 // Add a subscription that the NetworkController doesn't know about.
263 SubscriptionInfo mockSubInfo = Mockito.mock(SubscriptionInfo.class);
Fabian Kozynskia9091992019-03-25 11:08:32 -0400264 when(mockSubInfo.getSubscriptionId()).thenReturn(notTestSubscription);
Jason Monkc014dec2014-12-12 11:49:55 -0500265 subscriptions.add(mockSubInfo);
266 assertFalse(mNetworkController.hasCorrectMobileControllers(subscriptions));
267 }
268
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -0400269 @Test
Jason Monkc014dec2014-12-12 11:49:55 -0500270 public void testSetCurrentSubscriptions() {
271 // We will not add one controller to make sure it gets created.
272 int indexToSkipController = 0;
273 // We will not add one subscription to make sure it's controller gets removed.
274 int indexToSkipSubscription = 1;
275
276 int[] testSubscriptions = new int[] { 1, 5, 3 };
277 MobileSignalController[] mobileSignalControllers = new MobileSignalController[] {
278 Mockito.mock(MobileSignalController.class),
279 Mockito.mock(MobileSignalController.class),
280 Mockito.mock(MobileSignalController.class),
281 };
282 mNetworkController.mMobileSignalControllers.clear();
283 List<SubscriptionInfo> subscriptions = new ArrayList<>();
284 for (int i = 0; i < testSubscriptions.length; i++) {
285 if (i != indexToSkipController) {
286 // Force the test controllers into NetworkController.
287 mNetworkController.mMobileSignalControllers.put(testSubscriptions[i],
288 mobileSignalControllers[i]);
289 }
290
291 if (i != indexToSkipSubscription) {
292 // Generate a list of subscriptions we will tell the NetworkController to use.
293 SubscriptionInfo mockSubInfo = Mockito.mock(SubscriptionInfo.class);
Fabian Kozynskia9091992019-03-25 11:08:32 -0400294 when(mockSubInfo.getSubscriptionId()).thenReturn(testSubscriptions[i]);
295 when(mockSubInfo.getSimSlotIndex()).thenReturn(testSubscriptions[i]);
Jason Monkc014dec2014-12-12 11:49:55 -0500296 subscriptions.add(mockSubInfo);
297 }
298 }
299
300 // We can only test whether unregister gets called if it thinks its in a listening
301 // state.
302 mNetworkController.mListening = true;
Evan Laird470ae842019-04-09 16:24:27 -0400303 mNetworkController.setCurrentSubscriptionsLocked(subscriptions);
Jason Monkc014dec2014-12-12 11:49:55 -0500304
305 for (int i = 0; i < testSubscriptions.length; i++) {
306 if (i == indexToSkipController) {
307 // Make sure a controller was created despite us not adding one.
Jason Monk8996b942017-03-02 13:58:19 -0500308 assertTrue(mNetworkController.mMobileSignalControllers.indexOfKey(
309 testSubscriptions[i]) >= 0);
Jason Monkc014dec2014-12-12 11:49:55 -0500310 } else if (i == indexToSkipSubscription) {
311 // Make sure the controller that did exist was removed
Jason Monk8996b942017-03-02 13:58:19 -0500312 assertFalse(mNetworkController.mMobileSignalControllers.indexOfKey(
313 testSubscriptions[i]) >= 0);
Jason Monkc014dec2014-12-12 11:49:55 -0500314 } else {
315 // If a MobileSignalController is around it needs to not be unregistered.
316 Mockito.verify(mobileSignalControllers[i], Mockito.never())
317 .unregisterListener();
318 }
319 }
320 }
321
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -0400322 @Test
Jason Monk7f9623f2015-02-11 09:03:02 -0500323 public void testHistorySize() {
324 // Verify valid history size, otherwise it gits printed out the wrong order and whatnot.
325 assertEquals(0, SignalController.HISTORY_SIZE & (SignalController.HISTORY_SIZE - 1));
326 }
327
Jason Monkf13b4b32014-11-07 16:39:34 -0500328 private void setCdma() {
329 setIsGsm(false);
330 updateDataConnectionState(TelephonyManager.DATA_CONNECTED,
331 TelephonyManager.NETWORK_TYPE_CDMA);
332 setCdmaRoaming(false);
Jason Monke0cdb602014-11-05 12:39:45 -0500333 }
Leigh Anned0a62792014-11-13 14:27:10 -0800334
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -0400335 @Test
Leigh Anned0a62792014-11-13 14:27:10 -0800336 public void testOnReceive_stringsUpdatedAction_spn() {
337 String expectedMNetworkName = "Test";
338 Intent intent = createStringsUpdatedIntent(true /* showSpn */,
339 expectedMNetworkName /* spn */,
340 false /* showPlmn */,
341 "NotTest" /* plmn */);
342
343 mNetworkController.onReceive(mContext, intent);
344
345 assertNetworkNameEquals(expectedMNetworkName);
346 }
347
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -0400348 @Test
Leigh Anned0a62792014-11-13 14:27:10 -0800349 public void testOnReceive_stringsUpdatedAction_plmn() {
350 String expectedMNetworkName = "Test";
351
352 Intent intent = createStringsUpdatedIntent(false /* showSpn */,
353 "NotTest" /* spn */,
354 true /* showPlmn */,
355 expectedMNetworkName /* plmn */);
356
357 mNetworkController.onReceive(mContext, intent);
358
359 assertNetworkNameEquals(expectedMNetworkName);
360 }
361
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -0400362 @Test
Leigh Anned0a62792014-11-13 14:27:10 -0800363 public void testOnReceive_stringsUpdatedAction_bothFalse() {
364 Intent intent = createStringsUpdatedIntent(false /* showSpn */,
365 "Irrelevant" /* spn */,
366 false /* showPlmn */,
367 "Irrelevant" /* plmn */);
368
369 mNetworkController.onReceive(mContext, intent);
370
371 String defaultNetworkName = mMobileSignalController
372 .getStringIfExists(
373 com.android.internal.R.string.lockscreen_carrier_default);
374 assertNetworkNameEquals(defaultNetworkName);
375 }
376
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -0400377 @Test
Leigh Anned0a62792014-11-13 14:27:10 -0800378 public void testOnReceive_stringsUpdatedAction_bothTrueAndNull() {
379 Intent intent = createStringsUpdatedIntent(true /* showSpn */,
380 null /* spn */,
381 true /* showPlmn */,
382 null /* plmn */);
383
384 mNetworkController.onReceive(mContext, intent);
385
386 String defaultNetworkName = mMobileSignalController.getStringIfExists(
387 com.android.internal.R.string.lockscreen_carrier_default);
388 assertNetworkNameEquals(defaultNetworkName);
389 }
390
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -0400391 @Test
Leigh Anned0a62792014-11-13 14:27:10 -0800392 public void testOnReceive_stringsUpdatedAction_bothTrueAndNonNull() {
393 String spn = "Test1";
394 String plmn = "Test2";
395
396 Intent intent = createStringsUpdatedIntent(true /* showSpn */,
397 spn /* spn */,
398 true /* showPlmn */,
399 plmn /* plmn */);
400
401 mNetworkController.onReceive(mContext, intent);
402
403 assertNetworkNameEquals(plmn
404 + mMobileSignalController.getStringIfExists(
405 R.string.status_bar_network_name_separator)
406 + spn);
407 }
408
409 private Intent createStringsUpdatedIntent(boolean showSpn, String spn,
410 boolean showPlmn, String plmn) {
411
412 Intent intent = new Intent();
413 intent.setAction(TelephonyIntents.SPN_STRINGS_UPDATED_ACTION);
414
415 intent.putExtra(TelephonyIntents.EXTRA_SHOW_SPN, showSpn);
416 intent.putExtra(TelephonyIntents.EXTRA_SPN, spn);
417
418 intent.putExtra(TelephonyIntents.EXTRA_SHOW_PLMN, showPlmn);
419 intent.putExtra(TelephonyIntents.EXTRA_PLMN, plmn);
Jason Monk18985e02015-01-07 12:07:06 -0500420 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, mSubId);
Leigh Anned0a62792014-11-13 14:27:10 -0800421
422 return intent;
423 }
424
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -0400425 @Test
Leigh Anned0a62792014-11-13 14:27:10 -0800426 public void testOnUpdateDataActivity_dataIn() {
427 setupDefaultSignal();
428
429 updateDataActivity(TelephonyManager.DATA_ACTIVITY_IN);
430
431 verifyLastQsMobileDataIndicators(true /* visible */,
Jason Monk48edc0c2017-04-10 15:01:27 -0400432 DEFAULT_LEVEL /* icon */,
Leigh Anned0a62792014-11-13 14:27:10 -0800433 DEFAULT_QS_ICON /* typeIcon */,
434 true /* dataIn */,
435 false /* dataOut */);
436
437 }
438
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -0400439 @Test
Leigh Anned0a62792014-11-13 14:27:10 -0800440 public void testOnUpdateDataActivity_dataOut() {
441 setupDefaultSignal();
442
443 updateDataActivity(TelephonyManager.DATA_ACTIVITY_OUT);
444
445 verifyLastQsMobileDataIndicators(true /* visible */,
Jason Monk48edc0c2017-04-10 15:01:27 -0400446 DEFAULT_LEVEL /* icon */,
Jason Monk7e6c83c2017-04-26 14:35:24 -0400447 DEFAULT_QS_ICON /* typeIcon */,
Leigh Anned0a62792014-11-13 14:27:10 -0800448 false /* dataIn */,
449 true /* dataOut */);
Leigh Anned0a62792014-11-13 14:27:10 -0800450 }
451
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -0400452 @Test
Leigh Anned0a62792014-11-13 14:27:10 -0800453 public void testOnUpdateDataActivity_dataInOut() {
454 setupDefaultSignal();
455
456 updateDataActivity(TelephonyManager.DATA_ACTIVITY_INOUT);
457
458 verifyLastQsMobileDataIndicators(true /* visible */,
Jason Monk48edc0c2017-04-10 15:01:27 -0400459 DEFAULT_LEVEL /* icon */,
Leigh Anned0a62792014-11-13 14:27:10 -0800460 DEFAULT_QS_ICON /* typeIcon */,
461 true /* dataIn */,
462 true /* dataOut */);
463
464 }
465
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -0400466 @Test
Leigh Anned0a62792014-11-13 14:27:10 -0800467 public void testOnUpdateDataActivity_dataActivityNone() {
468 setupDefaultSignal();
469
470 updateDataActivity(TelephonyManager.DATA_ACTIVITY_NONE);
471
472 verifyLastQsMobileDataIndicators(true /* visible */,
Jason Monk48edc0c2017-04-10 15:01:27 -0400473 DEFAULT_LEVEL /* icon */,
Leigh Anned0a62792014-11-13 14:27:10 -0800474 DEFAULT_QS_ICON /* typeIcon */,
475 false /* dataIn */,
476 false /* dataOut */);
477
478 }
Andrew Flynn5e751472015-05-01 11:50:07 -0400479
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -0400480 @Test
Andrew Flynn55fc8002015-05-29 08:33:46 -0400481 public void testCarrierNetworkChange_carrierNetworkChange() {
Andrew Flynn5e751472015-05-01 11:50:07 -0400482 int strength = SignalStrength.SIGNAL_STRENGTH_GREAT;
483
484 setupDefaultSignal();
485 setLevel(strength);
486
487 // Verify baseline
488 verifyLastMobileDataIndicators(true /* visible */,
Jason Monk48edc0c2017-04-10 15:01:27 -0400489 strength /* strengthIcon */,
Andrew Flynn5e751472015-05-01 11:50:07 -0400490 DEFAULT_ICON /* typeIcon */);
491
Andrew Flynn55fc8002015-05-29 08:33:46 -0400492 // API call is made
Andrew Flynn5e751472015-05-01 11:50:07 -0400493 setCarrierNetworkChange(true /* enabled */);
Andrew Flynn5e751472015-05-01 11:50:07 -0400494
Andrew Flynn55fc8002015-05-29 08:33:46 -0400495 // Carrier network change is true, show special indicator
Andrew Flynn5e751472015-05-01 11:50:07 -0400496 verifyLastMobileDataIndicators(true /* visible */,
Jason Monk48edc0c2017-04-10 15:01:27 -0400497 SignalDrawable.getCarrierChangeState(SignalStrength.NUM_SIGNAL_STRENGTH_BINS),
Andrew Flynn5e751472015-05-01 11:50:07 -0400498 0 /* typeIcon */);
499
500 // Revert back
501 setCarrierNetworkChange(false /* enabled */);
Andrew Flynn5e751472015-05-01 11:50:07 -0400502
503 // Verify back in previous state
504 verifyLastMobileDataIndicators(true /* visible */,
Jason Monk48edc0c2017-04-10 15:01:27 -0400505 strength /* strengthIcon */,
Andrew Flynn5e751472015-05-01 11:50:07 -0400506 DEFAULT_ICON /* typeIcon */);
507 }
Jason Monkc6cc6262015-06-11 11:10:15 -0400508
Shishir Agrawal7ef5b882017-06-26 12:06:03 -0700509 @Test
510 public void testCarrierNetworkChange_roamingBeforeNetworkChange() {
511 int strength = SignalStrength.SIGNAL_STRENGTH_GREAT;
512
513 setupDefaultSignal();
514 setLevel(strength);
515 setGsmRoaming(true);
516
517 // Verify baseline
518 verifyLastMobileDataIndicators(true /* visible */,
519 strength /* strengthIcon */,
520 DEFAULT_ICON /* typeIcon */,
521 true /* roaming */);
522
523 // API call is made
524 setCarrierNetworkChange(true /* enabled */);
525
526 // Carrier network change is true, show special indicator, no roaming.
527 verifyLastMobileDataIndicators(true /* visible */,
528 SignalDrawable.getCarrierChangeState(SignalStrength.NUM_SIGNAL_STRENGTH_BINS),
529 0 /* typeIcon */,
530 false /* roaming */);
531
532 // Revert back
533 setCarrierNetworkChange(false /* enabled */);
534
535 // Verify back in previous state
536 verifyLastMobileDataIndicators(true /* visible */,
537 strength /* strengthIcon */,
538 DEFAULT_ICON /* typeIcon */,
539 true /* roaming */);
540 }
541
542 @Test
543 public void testCarrierNetworkChange_roamingAfterNetworkChange() {
544 int strength = SignalStrength.SIGNAL_STRENGTH_GREAT;
545
546 setupDefaultSignal();
547 setLevel(strength);
548
549 // Verify baseline
550 verifyLastMobileDataIndicators(true /* visible */,
551 strength /* strengthIcon */,
552 DEFAULT_ICON /* typeIcon */,
553 false /* roaming */);
554
555 // API call is made
556 setCarrierNetworkChange(true /* enabled */);
557
558 // Carrier network change is true, show special indicator, no roaming.
559 verifyLastMobileDataIndicators(true /* visible */,
560 SignalDrawable.getCarrierChangeState(SignalStrength.NUM_SIGNAL_STRENGTH_BINS),
561 0 /* typeIcon */,
562 false /* roaming */);
563
564 setGsmRoaming(true);
565
566 // Roaming should not show.
567 verifyLastMobileDataIndicators(true /* visible */,
568 SignalDrawable.getCarrierChangeState(SignalStrength.NUM_SIGNAL_STRENGTH_BINS),
569 0 /* typeIcon */,
570 false /* roaming */);
571
572 // Revert back
573 setCarrierNetworkChange(false /* enabled */);
574
575 // Verify back in previous state
576 verifyLastMobileDataIndicators(true /* visible */,
577 strength /* strengthIcon */,
578 DEFAULT_ICON /* typeIcon */,
579 true /* roaming */);
580 }
581
Jason Monkc6cc6262015-06-11 11:10:15 -0400582 private void verifyEmergencyOnly(boolean isEmergencyOnly) {
583 ArgumentCaptor<Boolean> emergencyOnly = ArgumentCaptor.forClass(Boolean.class);
584 Mockito.verify(mCallbackHandler, Mockito.atLeastOnce()).setEmergencyCallsOnly(
585 emergencyOnly.capture());
586 assertEquals(isEmergencyOnly, (boolean) emergencyOnly.getValue());
587 }
Jason Monke0cdb602014-11-05 12:39:45 -0500588}