blob: 9055022df261ef509548cd7725951606ce8cf948 [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
Jason Monkca8d3d72017-07-06 12:36:32 -040035import org.junit.Ignore;
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -040036import org.junit.Test;
37import org.junit.runner.RunWith;
Jason Monkc6cc6262015-06-11 11:10:15 -040038import org.mockito.ArgumentCaptor;
Jason Monkda68f592015-01-07 10:55:58 -050039import org.mockito.Mockito;
40
41import java.util.ArrayList;
42import java.util.List;
Jason Monkf13b4b32014-11-07 16:39:34 -050043
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -040044import static junit.framework.Assert.assertEquals;
45import static junit.framework.Assert.assertTrue;
46import static junit.framework.Assert.assertFalse;
47import static org.mockito.Mockito.mock;
48
Jason Monke427cb82015-07-28 09:18:08 -040049@SmallTest
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -040050@RunWith(AndroidJUnit4.class)
Jason Monke0cdb602014-11-05 12:39:45 -050051public class NetworkControllerSignalTest extends NetworkControllerBaseTest {
52
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -040053 @Test
Geoffrey Pitschba918db2017-07-12 11:40:32 -040054 @Ignore("Flaky")
Jason Monkf13b4b32014-11-07 16:39:34 -050055 public void testNoIconWithoutMobile() {
56 // Turn off mobile network support.
57 Mockito.when(mMockCm.isNetworkSupported(ConnectivityManager.TYPE_MOBILE)).thenReturn(false);
58 // Create a new NetworkController as this is currently handled in constructor.
Sundeep Ghuman9d10a3c2017-06-16 00:05:16 +000059 mNetworkController = new NetworkControllerImpl(mContext, mMockCm, mMockTm, mMockWm, mMockSm,
Jason Monk07b75fe2015-05-14 16:47:03 -040060 mConfig, Looper.getMainLooper(), mCallbackHandler,
Jason Monkf668d7c2016-01-14 10:38:41 -050061 mock(AccessPointControllerImpl.class), mock(DataUsageController.class),
Jason Monk9c7844c2017-01-18 15:21:53 -050062 mMockSubDefaults, mock(DeviceProvisionedController.class));
Jason Monkf13b4b32014-11-07 16:39:34 -050063 setupNetworkController();
Jason Monke0cdb602014-11-05 12:39:45 -050064
Jason Monk48edc0c2017-04-10 15:01:27 -040065 verifyLastMobileDataIndicators(false, -1, 0);
Jason Monkf13b4b32014-11-07 16:39:34 -050066 }
67
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -040068 @Test
Geoffrey Pitschba918db2017-07-12 11:40:32 -040069 @Ignore("Flaky")
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
Geoffrey Pitschba918db2017-07-12 11:40:32 -040079 @Ignore("Flaky")
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
Geoffrey Pitschba918db2017-07-12 11:40:32 -040091 @Ignore("Flaky")
Jason Monkc6cc6262015-06-11 11:10:15 -040092 public void testEmergencyOnlyNoSubscriptions() {
93 setupDefaultSignal();
Jason Monkb0808aa2015-07-22 16:34:36 -040094 setSubscriptions();
95 mNetworkController.mLastServiceState = new ServiceState();
96 mNetworkController.mLastServiceState.setEmergencyOnly(true);
97 mNetworkController.recalculateEmergency();
98 verifyEmergencyOnly(true);
99 }
100
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -0400101 @Test
Geoffrey Pitschba918db2017-07-12 11:40:32 -0400102 @Ignore("Flaky")
Jason Monk8996b942017-03-02 13:58:19 -0500103 public void testNoEmergencyOnlyWrongSubscription() {
104 setupDefaultSignal();
105 setDefaultSubId(42);
106 mNetworkController.recalculateEmergency();
107 verifyEmergencyOnly(false);
108 }
109
110 @Test
Geoffrey Pitschba918db2017-07-12 11:40:32 -0400111 @Ignore("Flaky")
Jason Monkb0808aa2015-07-22 16:34:36 -0400112 public void testNoEmengencyNoSubscriptions() {
113 setupDefaultSignal();
114 setSubscriptions();
115 mNetworkController.mLastServiceState = new ServiceState();
116 mNetworkController.mLastServiceState.setEmergencyOnly(false);
Jason Monkc6cc6262015-06-11 11:10:15 -0400117 mNetworkController.recalculateEmergency();
118 verifyEmergencyOnly(false);
Jason Monkc6cc6262015-06-11 11:10:15 -0400119 }
120
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -0400121 @Test
Geoffrey Pitschba918db2017-07-12 11:40:32 -0400122 @Ignore("Flaky")
Jason Monk21d05a02014-12-02 12:46:58 -0500123 public void testNoSimlessIconWithoutMobile() {
124 // Turn off mobile network support.
125 Mockito.when(mMockCm.isNetworkSupported(ConnectivityManager.TYPE_MOBILE)).thenReturn(false);
126 // Create a new NetworkController as this is currently handled in constructor.
Sundeep Ghuman9d10a3c2017-06-16 00:05:16 +0000127 mNetworkController = new NetworkControllerImpl(mContext, mMockCm, mMockTm, mMockWm, mMockSm,
Jason Monk07b75fe2015-05-14 16:47:03 -0400128 mConfig, Looper.getMainLooper(), mCallbackHandler,
Jason Monkf668d7c2016-01-14 10:38:41 -0500129 mock(AccessPointControllerImpl.class), mock(DataUsageController.class),
Jason Monk9c7844c2017-01-18 15:21:53 -0500130 mMockSubDefaults, mock(DeviceProvisionedController.class));
Jason Monk21d05a02014-12-02 12:46:58 -0500131 setupNetworkController();
132
133 // No Subscriptions.
134 mNetworkController.mMobileSignalControllers.clear();
135 mNetworkController.updateNoSims();
136
137 verifyHasNoSims(false);
138 }
139
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -0400140 @Test
Geoffrey Pitschba918db2017-07-12 11:40:32 -0400141 @Ignore("Flaky")
Jason Monkf13b4b32014-11-07 16:39:34 -0500142 public void testSignalStrength() {
Jason Monk48edc0c2017-04-10 15:01:27 -0400143 for (int testStrength = 0;
144 testStrength < SignalStrength.NUM_SIGNAL_STRENGTH_BINS; testStrength++) {
Jason Monkf13b4b32014-11-07 16:39:34 -0500145 setupDefaultSignal();
146 setLevel(testStrength);
147
148 verifyLastMobileDataIndicators(true,
Jason Monk48edc0c2017-04-10 15:01:27 -0400149 testStrength, DEFAULT_ICON);
Jason Monkf13b4b32014-11-07 16:39:34 -0500150
151 // Verify low inet number indexing.
Jason Monk33f8ae72015-05-08 10:45:15 -0400152 setConnectivity(NetworkCapabilities.TRANSPORT_CELLULAR, false, true);
Jason Monkf13b4b32014-11-07 16:39:34 -0500153 verifyLastMobileDataIndicators(true,
Jason Monk48edc0c2017-04-10 15:01:27 -0400154 testStrength, DEFAULT_ICON, false, false);
Jason Monkf13b4b32014-11-07 16:39:34 -0500155 }
156 }
157
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -0400158 @Test
Geoffrey Pitschba918db2017-07-12 11:40:32 -0400159 @Ignore("Flaky")
Jason Monkf13b4b32014-11-07 16:39:34 -0500160 public void testCdmaSignalStrength() {
Jason Monk48edc0c2017-04-10 15:01:27 -0400161 for (int testStrength = 0;
162 testStrength < SignalStrength.NUM_SIGNAL_STRENGTH_BINS; testStrength++) {
Jason Monkf13b4b32014-11-07 16:39:34 -0500163 setupDefaultSignal();
164 setCdma();
165 setLevel(testStrength);
166
167 verifyLastMobileDataIndicators(true,
Jason Monk48edc0c2017-04-10 15:01:27 -0400168 testStrength,
169 TelephonyIcons.ICON_1X);
Jason Monkf13b4b32014-11-07 16:39:34 -0500170 }
Jason Monke0cdb602014-11-05 12:39:45 -0500171 }
172
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -0400173 @Test
Geoffrey Pitschba918db2017-07-12 11:40:32 -0400174 @Ignore("Flaky")
Jason Monke0cdb602014-11-05 12:39:45 -0500175 public void testSignalRoaming() {
Jason Monk48edc0c2017-04-10 15:01:27 -0400176 for (int testStrength = 0;
177 testStrength < SignalStrength.NUM_SIGNAL_STRENGTH_BINS; testStrength++) {
Jason Monkf13b4b32014-11-07 16:39:34 -0500178 setupDefaultSignal();
179 setGsmRoaming(true);
180 setLevel(testStrength);
Jason Monke0cdb602014-11-05 12:39:45 -0500181
Jason Monkf13b4b32014-11-07 16:39:34 -0500182 verifyLastMobileDataIndicators(true,
Jason Monk48edc0c2017-04-10 15:01:27 -0400183 testStrength,
Jason Monk0f0de132016-12-19 15:36:13 -0500184 DEFAULT_ICON, true);
Jason Monkf13b4b32014-11-07 16:39:34 -0500185 }
186 }
187
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -0400188 @Test
Geoffrey Pitschba918db2017-07-12 11:40:32 -0400189 @Ignore("Flaky")
Jason Monkf13b4b32014-11-07 16:39:34 -0500190 public void testCdmaSignalRoaming() {
191 for (int testStrength = SignalStrength.SIGNAL_STRENGTH_NONE_OR_UNKNOWN;
192 testStrength <= SignalStrength.SIGNAL_STRENGTH_GREAT; testStrength++) {
193 setupDefaultSignal();
194 setCdma();
195 setCdmaRoaming(true);
196 setLevel(testStrength);
197
198 verifyLastMobileDataIndicators(true,
Jason Monk48edc0c2017-04-10 15:01:27 -0400199 testStrength,
200 TelephonyIcons.ICON_1X, true);
Jason Monkf13b4b32014-11-07 16:39:34 -0500201 }
202 }
203
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -0400204 @Test
Geoffrey Pitschba918db2017-07-12 11:40:32 -0400205 @Ignore("Flaky")
Jason Monkf13b4b32014-11-07 16:39:34 -0500206 public void testQsSignalStrength() {
207 for (int testStrength = SignalStrength.SIGNAL_STRENGTH_NONE_OR_UNKNOWN;
208 testStrength <= SignalStrength.SIGNAL_STRENGTH_GREAT; testStrength++) {
209 setupDefaultSignal();
210 setLevel(testStrength);
211
212 verifyLastQsMobileDataIndicators(true,
Jason Monk48edc0c2017-04-10 15:01:27 -0400213 testStrength,
Jason Monkb5746272014-11-12 16:50:31 -0500214 DEFAULT_QS_ICON, false, false);
Jason Monkf13b4b32014-11-07 16:39:34 -0500215 }
216 }
217
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -0400218 @Test
Geoffrey Pitschba918db2017-07-12 11:40:32 -0400219 @Ignore("Flaky")
Jason Monkf13b4b32014-11-07 16:39:34 -0500220 public void testCdmaQsSignalStrength() {
221 for (int testStrength = SignalStrength.SIGNAL_STRENGTH_NONE_OR_UNKNOWN;
222 testStrength <= SignalStrength.SIGNAL_STRENGTH_GREAT; testStrength++) {
223 setupDefaultSignal();
224 setCdma();
225 setLevel(testStrength);
226
227 verifyLastQsMobileDataIndicators(true,
Jason Monk48edc0c2017-04-10 15:01:27 -0400228 testStrength,
Jason Monk01df36f2017-06-07 13:02:47 -0400229 TelephonyIcons.QS_DATA_1X, false, false);
Jason Monkf13b4b32014-11-07 16:39:34 -0500230 }
231 }
232
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -0400233 @Test
Geoffrey Pitschba918db2017-07-12 11:40:32 -0400234 @Ignore("Flaky")
Jason Monk33f8ae72015-05-08 10:45:15 -0400235 public void testNoBangWithWifi() {
Jason Monkf13b4b32014-11-07 16:39:34 -0500236 setupDefaultSignal();
Jason Monk33f8ae72015-05-08 10:45:15 -0400237 setConnectivity(mMobileSignalController.mTransportType, false, false);
238 setConnectivity(NetworkCapabilities.TRANSPORT_WIFI, true, true);
Jason Monkf13b4b32014-11-07 16:39:34 -0500239
Jason Monk48edc0c2017-04-10 15:01:27 -0400240 verifyLastMobileDataIndicators(true, DEFAULT_LEVEL, 0);
Jason Monkf13b4b32014-11-07 16:39:34 -0500241 }
242
Jason Monkc014dec2014-12-12 11:49:55 -0500243 // Some tests of actual NetworkController code, just internals not display stuff
244 // TODO: Put this somewhere else, maybe in its own file.
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -0400245 @Test
Geoffrey Pitschba918db2017-07-12 11:40:32 -0400246 @Ignore("Flaky")
Jason Monkc014dec2014-12-12 11:49:55 -0500247 public void testHasCorrectMobileControllers() {
248 int[] testSubscriptions = new int[] { 1, 5, 3 };
249 int notTestSubscription = 0;
250 MobileSignalController mobileSignalController = Mockito.mock(MobileSignalController.class);
251
252 mNetworkController.mMobileSignalControllers.clear();
253 List<SubscriptionInfo> subscriptions = new ArrayList<>();
254 for (int i = 0; i < testSubscriptions.length; i++) {
255 // Force the test controllers into NetworkController.
256 mNetworkController.mMobileSignalControllers.put(testSubscriptions[i],
257 mobileSignalController);
258
259 // Generate a list of subscriptions we will tell the NetworkController to use.
260 SubscriptionInfo mockSubInfo = Mockito.mock(SubscriptionInfo.class);
261 Mockito.when(mockSubInfo.getSubscriptionId()).thenReturn(testSubscriptions[i]);
262 subscriptions.add(mockSubInfo);
263 }
264 assertTrue(mNetworkController.hasCorrectMobileControllers(subscriptions));
265
266 // Add a subscription that the NetworkController doesn't know about.
267 SubscriptionInfo mockSubInfo = Mockito.mock(SubscriptionInfo.class);
268 Mockito.when(mockSubInfo.getSubscriptionId()).thenReturn(notTestSubscription);
269 subscriptions.add(mockSubInfo);
270 assertFalse(mNetworkController.hasCorrectMobileControllers(subscriptions));
271 }
272
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -0400273 @Test
Geoffrey Pitschba918db2017-07-12 11:40:32 -0400274 @Ignore("Flaky")
Jason Monkc014dec2014-12-12 11:49:55 -0500275 public void testSetCurrentSubscriptions() {
276 // We will not add one controller to make sure it gets created.
277 int indexToSkipController = 0;
278 // We will not add one subscription to make sure it's controller gets removed.
279 int indexToSkipSubscription = 1;
280
281 int[] testSubscriptions = new int[] { 1, 5, 3 };
282 MobileSignalController[] mobileSignalControllers = new MobileSignalController[] {
283 Mockito.mock(MobileSignalController.class),
284 Mockito.mock(MobileSignalController.class),
285 Mockito.mock(MobileSignalController.class),
286 };
287 mNetworkController.mMobileSignalControllers.clear();
288 List<SubscriptionInfo> subscriptions = new ArrayList<>();
289 for (int i = 0; i < testSubscriptions.length; i++) {
290 if (i != indexToSkipController) {
291 // Force the test controllers into NetworkController.
292 mNetworkController.mMobileSignalControllers.put(testSubscriptions[i],
293 mobileSignalControllers[i]);
294 }
295
296 if (i != indexToSkipSubscription) {
297 // Generate a list of subscriptions we will tell the NetworkController to use.
298 SubscriptionInfo mockSubInfo = Mockito.mock(SubscriptionInfo.class);
299 Mockito.when(mockSubInfo.getSubscriptionId()).thenReturn(testSubscriptions[i]);
300 Mockito.when(mockSubInfo.getSimSlotIndex()).thenReturn(testSubscriptions[i]);
301 subscriptions.add(mockSubInfo);
302 }
303 }
304
305 // We can only test whether unregister gets called if it thinks its in a listening
306 // state.
307 mNetworkController.mListening = true;
308 mNetworkController.setCurrentSubscriptions(subscriptions);
309
310 for (int i = 0; i < testSubscriptions.length; i++) {
311 if (i == indexToSkipController) {
312 // Make sure a controller was created despite us not adding one.
Jason Monk8996b942017-03-02 13:58:19 -0500313 assertTrue(mNetworkController.mMobileSignalControllers.indexOfKey(
314 testSubscriptions[i]) >= 0);
Jason Monkc014dec2014-12-12 11:49:55 -0500315 } else if (i == indexToSkipSubscription) {
316 // Make sure the controller that did exist was removed
Jason Monk8996b942017-03-02 13:58:19 -0500317 assertFalse(mNetworkController.mMobileSignalControllers.indexOfKey(
318 testSubscriptions[i]) >= 0);
Jason Monkc014dec2014-12-12 11:49:55 -0500319 } else {
320 // If a MobileSignalController is around it needs to not be unregistered.
321 Mockito.verify(mobileSignalControllers[i], Mockito.never())
322 .unregisterListener();
323 }
324 }
325 }
326
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -0400327 @Test
Geoffrey Pitschba918db2017-07-12 11:40:32 -0400328 @Ignore("Flaky")
Jason Monk7f9623f2015-02-11 09:03:02 -0500329 public void testHistorySize() {
330 // Verify valid history size, otherwise it gits printed out the wrong order and whatnot.
331 assertEquals(0, SignalController.HISTORY_SIZE & (SignalController.HISTORY_SIZE - 1));
332 }
333
Jason Monkf13b4b32014-11-07 16:39:34 -0500334 private void setCdma() {
335 setIsGsm(false);
336 updateDataConnectionState(TelephonyManager.DATA_CONNECTED,
337 TelephonyManager.NETWORK_TYPE_CDMA);
338 setCdmaRoaming(false);
Jason Monke0cdb602014-11-05 12:39:45 -0500339 }
Leigh Anned0a62792014-11-13 14:27:10 -0800340
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -0400341 @Test
Geoffrey Pitschba918db2017-07-12 11:40:32 -0400342 @Ignore("Flaky")
Leigh Anned0a62792014-11-13 14:27:10 -0800343 public void testOnReceive_stringsUpdatedAction_spn() {
344 String expectedMNetworkName = "Test";
345 Intent intent = createStringsUpdatedIntent(true /* showSpn */,
346 expectedMNetworkName /* spn */,
347 false /* showPlmn */,
348 "NotTest" /* plmn */);
349
350 mNetworkController.onReceive(mContext, intent);
351
352 assertNetworkNameEquals(expectedMNetworkName);
353 }
354
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -0400355 @Test
Geoffrey Pitschba918db2017-07-12 11:40:32 -0400356 @Ignore("Flaky")
Leigh Anned0a62792014-11-13 14:27:10 -0800357 public void testOnReceive_stringsUpdatedAction_plmn() {
358 String expectedMNetworkName = "Test";
359
360 Intent intent = createStringsUpdatedIntent(false /* showSpn */,
361 "NotTest" /* spn */,
362 true /* showPlmn */,
363 expectedMNetworkName /* plmn */);
364
365 mNetworkController.onReceive(mContext, intent);
366
367 assertNetworkNameEquals(expectedMNetworkName);
368 }
369
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -0400370 @Test
Geoffrey Pitschba918db2017-07-12 11:40:32 -0400371 @Ignore("Flaky")
Leigh Anned0a62792014-11-13 14:27:10 -0800372 public void testOnReceive_stringsUpdatedAction_bothFalse() {
373 Intent intent = createStringsUpdatedIntent(false /* showSpn */,
374 "Irrelevant" /* spn */,
375 false /* showPlmn */,
376 "Irrelevant" /* plmn */);
377
378 mNetworkController.onReceive(mContext, intent);
379
380 String defaultNetworkName = mMobileSignalController
381 .getStringIfExists(
382 com.android.internal.R.string.lockscreen_carrier_default);
383 assertNetworkNameEquals(defaultNetworkName);
384 }
385
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -0400386 @Test
Geoffrey Pitschba918db2017-07-12 11:40:32 -0400387 @Ignore("Flaky")
Leigh Anned0a62792014-11-13 14:27:10 -0800388 public void testOnReceive_stringsUpdatedAction_bothTrueAndNull() {
389 Intent intent = createStringsUpdatedIntent(true /* showSpn */,
390 null /* spn */,
391 true /* showPlmn */,
392 null /* plmn */);
393
394 mNetworkController.onReceive(mContext, intent);
395
396 String defaultNetworkName = mMobileSignalController.getStringIfExists(
397 com.android.internal.R.string.lockscreen_carrier_default);
398 assertNetworkNameEquals(defaultNetworkName);
399 }
400
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -0400401 @Test
Geoffrey Pitschba918db2017-07-12 11:40:32 -0400402 @Ignore("Flaky")
Leigh Anned0a62792014-11-13 14:27:10 -0800403 public void testOnReceive_stringsUpdatedAction_bothTrueAndNonNull() {
404 String spn = "Test1";
405 String plmn = "Test2";
406
407 Intent intent = createStringsUpdatedIntent(true /* showSpn */,
408 spn /* spn */,
409 true /* showPlmn */,
410 plmn /* plmn */);
411
412 mNetworkController.onReceive(mContext, intent);
413
414 assertNetworkNameEquals(plmn
415 + mMobileSignalController.getStringIfExists(
416 R.string.status_bar_network_name_separator)
417 + spn);
418 }
419
420 private Intent createStringsUpdatedIntent(boolean showSpn, String spn,
421 boolean showPlmn, String plmn) {
422
423 Intent intent = new Intent();
424 intent.setAction(TelephonyIntents.SPN_STRINGS_UPDATED_ACTION);
425
426 intent.putExtra(TelephonyIntents.EXTRA_SHOW_SPN, showSpn);
427 intent.putExtra(TelephonyIntents.EXTRA_SPN, spn);
428
429 intent.putExtra(TelephonyIntents.EXTRA_SHOW_PLMN, showPlmn);
430 intent.putExtra(TelephonyIntents.EXTRA_PLMN, plmn);
Jason Monk18985e02015-01-07 12:07:06 -0500431 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, mSubId);
Leigh Anned0a62792014-11-13 14:27:10 -0800432
433 return intent;
434 }
435
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -0400436 @Test
Geoffrey Pitschba918db2017-07-12 11:40:32 -0400437 @Ignore("Flaky")
Leigh Anned0a62792014-11-13 14:27:10 -0800438 public void testOnUpdateDataActivity_dataIn() {
439 setupDefaultSignal();
440
441 updateDataActivity(TelephonyManager.DATA_ACTIVITY_IN);
442
443 verifyLastQsMobileDataIndicators(true /* visible */,
Jason Monk48edc0c2017-04-10 15:01:27 -0400444 DEFAULT_LEVEL /* icon */,
Leigh Anned0a62792014-11-13 14:27:10 -0800445 DEFAULT_QS_ICON /* typeIcon */,
446 true /* dataIn */,
447 false /* dataOut */);
448
449 }
450
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -0400451 @Test
Geoffrey Pitschba918db2017-07-12 11:40:32 -0400452 @Ignore("Flaky")
Leigh Anned0a62792014-11-13 14:27:10 -0800453 public void testOnUpdateDataActivity_dataOut() {
454 setupDefaultSignal();
455
456 updateDataActivity(TelephonyManager.DATA_ACTIVITY_OUT);
457
458 verifyLastQsMobileDataIndicators(true /* visible */,
Jason Monk48edc0c2017-04-10 15:01:27 -0400459 DEFAULT_LEVEL /* icon */,
Jason Monk7e6c83c2017-04-26 14:35:24 -0400460 DEFAULT_QS_ICON /* typeIcon */,
Leigh Anned0a62792014-11-13 14:27:10 -0800461 false /* dataIn */,
462 true /* dataOut */);
Leigh Anned0a62792014-11-13 14:27:10 -0800463 }
464
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -0400465 @Test
Geoffrey Pitschba918db2017-07-12 11:40:32 -0400466 @Ignore("Flaky")
Leigh Anned0a62792014-11-13 14:27:10 -0800467 public void testOnUpdateDataActivity_dataInOut() {
468 setupDefaultSignal();
469
470 updateDataActivity(TelephonyManager.DATA_ACTIVITY_INOUT);
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 true /* dataIn */,
476 true /* dataOut */);
477
478 }
479
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -0400480 @Test
Geoffrey Pitschba918db2017-07-12 11:40:32 -0400481 @Ignore("Flaky")
Leigh Anned0a62792014-11-13 14:27:10 -0800482 public void testOnUpdateDataActivity_dataActivityNone() {
483 setupDefaultSignal();
484
485 updateDataActivity(TelephonyManager.DATA_ACTIVITY_NONE);
486
487 verifyLastQsMobileDataIndicators(true /* visible */,
Jason Monk48edc0c2017-04-10 15:01:27 -0400488 DEFAULT_LEVEL /* icon */,
Leigh Anned0a62792014-11-13 14:27:10 -0800489 DEFAULT_QS_ICON /* typeIcon */,
490 false /* dataIn */,
491 false /* dataOut */);
492
493 }
Andrew Flynn5e751472015-05-01 11:50:07 -0400494
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -0400495 @Test
Geoffrey Pitschba918db2017-07-12 11:40:32 -0400496 @Ignore("Flaky")
Andrew Flynn55fc8002015-05-29 08:33:46 -0400497 public void testCarrierNetworkChange_carrierNetworkChange() {
Andrew Flynn5e751472015-05-01 11:50:07 -0400498 int strength = SignalStrength.SIGNAL_STRENGTH_GREAT;
499
500 setupDefaultSignal();
501 setLevel(strength);
502
503 // Verify baseline
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
Andrew Flynn55fc8002015-05-29 08:33:46 -0400508 // API call is made
Andrew Flynn5e751472015-05-01 11:50:07 -0400509 setCarrierNetworkChange(true /* enabled */);
Andrew Flynn5e751472015-05-01 11:50:07 -0400510
Andrew Flynn55fc8002015-05-29 08:33:46 -0400511 // Carrier network change is true, show special indicator
Andrew Flynn5e751472015-05-01 11:50:07 -0400512 verifyLastMobileDataIndicators(true /* visible */,
Jason Monk48edc0c2017-04-10 15:01:27 -0400513 SignalDrawable.getCarrierChangeState(SignalStrength.NUM_SIGNAL_STRENGTH_BINS),
Andrew Flynn5e751472015-05-01 11:50:07 -0400514 0 /* typeIcon */);
515
516 // Revert back
517 setCarrierNetworkChange(false /* enabled */);
Andrew Flynn5e751472015-05-01 11:50:07 -0400518
519 // Verify back in previous state
520 verifyLastMobileDataIndicators(true /* visible */,
Jason Monk48edc0c2017-04-10 15:01:27 -0400521 strength /* strengthIcon */,
Andrew Flynn5e751472015-05-01 11:50:07 -0400522 DEFAULT_ICON /* typeIcon */);
523 }
Jason Monkc6cc6262015-06-11 11:10:15 -0400524
Shishir Agrawal7ef5b882017-06-26 12:06:03 -0700525 @Test
Geoffrey Pitschba918db2017-07-12 11:40:32 -0400526 @Ignore("Flaky")
Shishir Agrawal7ef5b882017-06-26 12:06:03 -0700527 public void testCarrierNetworkChange_roamingBeforeNetworkChange() {
528 int strength = SignalStrength.SIGNAL_STRENGTH_GREAT;
529
530 setupDefaultSignal();
531 setLevel(strength);
532 setGsmRoaming(true);
533
534 // Verify baseline
535 verifyLastMobileDataIndicators(true /* visible */,
536 strength /* strengthIcon */,
537 DEFAULT_ICON /* typeIcon */,
538 true /* roaming */);
539
540 // API call is made
541 setCarrierNetworkChange(true /* enabled */);
542
543 // Carrier network change is true, show special indicator, no roaming.
544 verifyLastMobileDataIndicators(true /* visible */,
545 SignalDrawable.getCarrierChangeState(SignalStrength.NUM_SIGNAL_STRENGTH_BINS),
546 0 /* typeIcon */,
547 false /* roaming */);
548
549 // Revert back
550 setCarrierNetworkChange(false /* enabled */);
551
552 // Verify back in previous state
553 verifyLastMobileDataIndicators(true /* visible */,
554 strength /* strengthIcon */,
555 DEFAULT_ICON /* typeIcon */,
556 true /* roaming */);
557 }
558
559 @Test
Geoffrey Pitschba918db2017-07-12 11:40:32 -0400560 @Ignore("Flaky")
Shishir Agrawal7ef5b882017-06-26 12:06:03 -0700561 public void testCarrierNetworkChange_roamingAfterNetworkChange() {
562 int strength = SignalStrength.SIGNAL_STRENGTH_GREAT;
563
564 setupDefaultSignal();
565 setLevel(strength);
566
567 // Verify baseline
568 verifyLastMobileDataIndicators(true /* visible */,
569 strength /* strengthIcon */,
570 DEFAULT_ICON /* typeIcon */,
571 false /* roaming */);
572
573 // API call is made
574 setCarrierNetworkChange(true /* enabled */);
575
576 // Carrier network change is true, show special indicator, no roaming.
577 verifyLastMobileDataIndicators(true /* visible */,
578 SignalDrawable.getCarrierChangeState(SignalStrength.NUM_SIGNAL_STRENGTH_BINS),
579 0 /* typeIcon */,
580 false /* roaming */);
581
582 setGsmRoaming(true);
583
584 // Roaming should not show.
585 verifyLastMobileDataIndicators(true /* visible */,
586 SignalDrawable.getCarrierChangeState(SignalStrength.NUM_SIGNAL_STRENGTH_BINS),
587 0 /* typeIcon */,
588 false /* roaming */);
589
590 // Revert back
591 setCarrierNetworkChange(false /* enabled */);
592
593 // Verify back in previous state
594 verifyLastMobileDataIndicators(true /* visible */,
595 strength /* strengthIcon */,
596 DEFAULT_ICON /* typeIcon */,
597 true /* roaming */);
598 }
599
Jason Monkc6cc6262015-06-11 11:10:15 -0400600 private void verifyEmergencyOnly(boolean isEmergencyOnly) {
601 ArgumentCaptor<Boolean> emergencyOnly = ArgumentCaptor.forClass(Boolean.class);
602 Mockito.verify(mCallbackHandler, Mockito.atLeastOnce()).setEmergencyCallsOnly(
603 emergencyOnly.capture());
604 assertEquals(isEmergencyOnly, (boolean) emergencyOnly.getValue());
605 }
Jason Monke0cdb602014-11-05 12:39:45 -0500606}