blob: f91deeadba7bd20e7029eef5b2b5018237628515 [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;
Peter Wang98598bf2019-11-19 16:08:46 -080029import android.telephony.CellSignalStrength;
Jason Monkb0808aa2015-07-22 16:34:36 -040030import android.telephony.ServiceState;
Jason Monke0cdb602014-11-05 12:39:45 -050031import android.telephony.SignalStrength;
Jason Monkc014dec2014-12-12 11:49:55 -050032import android.telephony.SubscriptionInfo;
Jason Monke0cdb602014-11-05 12:39:45 -050033import android.telephony.TelephonyManager;
Jason Monke427cb82015-07-28 09:18:08 -040034import android.test.suitebuilder.annotation.SmallTest;
Jason Monk2515f472017-09-19 09:52:43 -040035import android.testing.AndroidTestingRunner;
36import android.testing.TestableLooper.RunWithLooper;
Jason Monke0cdb602014-11-05 12:39:45 -050037
Jason Monk18985e02015-01-07 12:07:06 -050038import com.android.internal.telephony.PhoneConstants;
Leigh Anned0a62792014-11-13 14:27:10 -080039import com.android.internal.telephony.TelephonyIntents;
Evan Laird06e9fd82018-02-10 09:36:55 -080040import com.android.settingslib.graph.SignalDrawable;
Jason Monkf668d7c2016-01-14 10:38:41 -050041import com.android.settingslib.net.DataUsageController;
Jason Monkf13b4b32014-11-07 16:39:34 -050042import com.android.systemui.R;
Jason Monkda68f592015-01-07 10:55:58 -050043
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -040044import org.junit.Test;
45import org.junit.runner.RunWith;
Jason Monkc6cc6262015-06-11 11:10:15 -040046import org.mockito.ArgumentCaptor;
Jason Monkda68f592015-01-07 10:55:58 -050047import org.mockito.Mockito;
48
49import java.util.ArrayList;
50import java.util.List;
Jason Monkf13b4b32014-11-07 16:39:34 -050051
Jason Monke427cb82015-07-28 09:18:08 -040052@SmallTest
Jason Monk2515f472017-09-19 09:52:43 -040053@RunWith(AndroidTestingRunner.class)
54@RunWithLooper
Jason Monke0cdb602014-11-05 12:39:45 -050055public class NetworkControllerSignalTest extends NetworkControllerBaseTest {
56
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -040057 @Test
Jason Monkf13b4b32014-11-07 16:39:34 -050058 public void testNoIconWithoutMobile() {
59 // Turn off mobile network support.
Fabian Kozynskia9091992019-03-25 11:08:32 -040060 when(mMockCm.isNetworkSupported(ConnectivityManager.TYPE_MOBILE)).thenReturn(false);
Jason Monkf13b4b32014-11-07 16:39:34 -050061 // Create a new NetworkController as this is currently handled in constructor.
Sundeep Ghuman9d10a3c2017-06-16 00:05:16 +000062 mNetworkController = new NetworkControllerImpl(mContext, mMockCm, mMockTm, mMockWm, mMockSm,
Jason Monk07b75fe2015-05-14 16:47:03 -040063 mConfig, Looper.getMainLooper(), mCallbackHandler,
Jason Monkf668d7c2016-01-14 10:38:41 -050064 mock(AccessPointControllerImpl.class), mock(DataUsageController.class),
Jason Monk9c7844c2017-01-18 15:21:53 -050065 mMockSubDefaults, mock(DeviceProvisionedController.class));
Jason Monkf13b4b32014-11-07 16:39:34 -050066 setupNetworkController();
Jason Monke0cdb602014-11-05 12:39:45 -050067
Jason Monk48edc0c2017-04-10 15:01:27 -040068 verifyLastMobileDataIndicators(false, -1, 0);
Jason Monkf13b4b32014-11-07 16:39:34 -050069 }
70
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -040071 @Test
Jason Monk21d05a02014-12-02 12:46:58 -050072 public void testNoSimsIconPresent() {
73 // No Subscriptions.
74 mNetworkController.mMobileSignalControllers.clear();
75 mNetworkController.updateNoSims();
76
77 verifyHasNoSims(true);
78 }
79
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -040080 @Test
Jason Monkc6cc6262015-06-11 11:10:15 -040081 public void testEmergencyOnly() {
82 setupDefaultSignal();
83 mNetworkController.recalculateEmergency();
84 verifyEmergencyOnly(false);
85
86 mMobileSignalController.getState().isEmergency = true;
87 mNetworkController.recalculateEmergency();
88 verifyEmergencyOnly(true);
89 }
90
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -040091 @Test
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
Jason Monk8996b942017-03-02 13:58:19 -0500102 public void testNoEmergencyOnlyWrongSubscription() {
103 setupDefaultSignal();
104 setDefaultSubId(42);
105 mNetworkController.recalculateEmergency();
106 verifyEmergencyOnly(false);
107 }
108
109 @Test
Jason Monkb0808aa2015-07-22 16:34:36 -0400110 public void testNoEmengencyNoSubscriptions() {
111 setupDefaultSignal();
112 setSubscriptions();
113 mNetworkController.mLastServiceState = new ServiceState();
114 mNetworkController.mLastServiceState.setEmergencyOnly(false);
Jason Monkc6cc6262015-06-11 11:10:15 -0400115 mNetworkController.recalculateEmergency();
116 verifyEmergencyOnly(false);
Jason Monkc6cc6262015-06-11 11:10:15 -0400117 }
118
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -0400119 @Test
Jason Monk21d05a02014-12-02 12:46:58 -0500120 public void testNoSimlessIconWithoutMobile() {
121 // Turn off mobile network support.
Fabian Kozynskia9091992019-03-25 11:08:32 -0400122 when(mMockCm.isNetworkSupported(ConnectivityManager.TYPE_MOBILE)).thenReturn(false);
Jason Monk21d05a02014-12-02 12:46:58 -0500123 // Create a new NetworkController as this is currently handled in constructor.
Sundeep Ghuman9d10a3c2017-06-16 00:05:16 +0000124 mNetworkController = new NetworkControllerImpl(mContext, mMockCm, mMockTm, mMockWm, mMockSm,
Jason Monk07b75fe2015-05-14 16:47:03 -0400125 mConfig, Looper.getMainLooper(), mCallbackHandler,
Jason Monkf668d7c2016-01-14 10:38:41 -0500126 mock(AccessPointControllerImpl.class), mock(DataUsageController.class),
Jason Monk9c7844c2017-01-18 15:21:53 -0500127 mMockSubDefaults, mock(DeviceProvisionedController.class));
Jason Monk21d05a02014-12-02 12:46:58 -0500128 setupNetworkController();
129
130 // No Subscriptions.
131 mNetworkController.mMobileSignalControllers.clear();
132 mNetworkController.updateNoSims();
133
134 verifyHasNoSims(false);
135 }
136
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -0400137 @Test
Jason Monkf13b4b32014-11-07 16:39:34 -0500138 public void testSignalStrength() {
Jason Monk48edc0c2017-04-10 15:01:27 -0400139 for (int testStrength = 0;
140 testStrength < SignalStrength.NUM_SIGNAL_STRENGTH_BINS; testStrength++) {
Jason Monkf13b4b32014-11-07 16:39:34 -0500141 setupDefaultSignal();
142 setLevel(testStrength);
143
144 verifyLastMobileDataIndicators(true,
Jason Monk48edc0c2017-04-10 15:01:27 -0400145 testStrength, DEFAULT_ICON);
Jason Monkf13b4b32014-11-07 16:39:34 -0500146
147 // Verify low inet number indexing.
Anarghya Mitra678722f2018-05-11 14:29:54 -0700148 setConnectivityViaBroadcast(NetworkCapabilities.TRANSPORT_CELLULAR, false, true);
Jason Monkf13b4b32014-11-07 16:39:34 -0500149 verifyLastMobileDataIndicators(true,
Jason Monk48edc0c2017-04-10 15:01:27 -0400150 testStrength, DEFAULT_ICON, false, false);
Jason Monkf13b4b32014-11-07 16:39:34 -0500151 }
152 }
153
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -0400154 @Test
Jason Monkf13b4b32014-11-07 16:39:34 -0500155 public void testCdmaSignalStrength() {
Jason Monk48edc0c2017-04-10 15:01:27 -0400156 for (int testStrength = 0;
157 testStrength < SignalStrength.NUM_SIGNAL_STRENGTH_BINS; testStrength++) {
Jason Monkf13b4b32014-11-07 16:39:34 -0500158 setupDefaultSignal();
159 setCdma();
160 setLevel(testStrength);
161
162 verifyLastMobileDataIndicators(true,
Jason Monk48edc0c2017-04-10 15:01:27 -0400163 testStrength,
164 TelephonyIcons.ICON_1X);
Jason Monkf13b4b32014-11-07 16:39:34 -0500165 }
Jason Monke0cdb602014-11-05 12:39:45 -0500166 }
167
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -0400168 @Test
Jason Monke0cdb602014-11-05 12:39:45 -0500169 public void testSignalRoaming() {
Jason Monk48edc0c2017-04-10 15:01:27 -0400170 for (int testStrength = 0;
171 testStrength < SignalStrength.NUM_SIGNAL_STRENGTH_BINS; testStrength++) {
Jason Monkf13b4b32014-11-07 16:39:34 -0500172 setupDefaultSignal();
173 setGsmRoaming(true);
174 setLevel(testStrength);
Jason Monke0cdb602014-11-05 12:39:45 -0500175
Jason Monkf13b4b32014-11-07 16:39:34 -0500176 verifyLastMobileDataIndicators(true,
Jason Monk48edc0c2017-04-10 15:01:27 -0400177 testStrength,
Jason Monk0f0de132016-12-19 15:36:13 -0500178 DEFAULT_ICON, true);
Jason Monkf13b4b32014-11-07 16:39:34 -0500179 }
180 }
181
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -0400182 @Test
Jason Monkf13b4b32014-11-07 16:39:34 -0500183 public void testCdmaSignalRoaming() {
Peter Wang98598bf2019-11-19 16:08:46 -0800184 for (int testStrength = CellSignalStrength.SIGNAL_STRENGTH_NONE_OR_UNKNOWN;
Jason Monkf13b4b32014-11-07 16:39:34 -0500185 testStrength <= SignalStrength.SIGNAL_STRENGTH_GREAT; testStrength++) {
186 setupDefaultSignal();
187 setCdma();
188 setCdmaRoaming(true);
189 setLevel(testStrength);
190
191 verifyLastMobileDataIndicators(true,
Jason Monk48edc0c2017-04-10 15:01:27 -0400192 testStrength,
193 TelephonyIcons.ICON_1X, true);
Jason Monkf13b4b32014-11-07 16:39:34 -0500194 }
195 }
196
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -0400197 @Test
Jason Monke1531982017-09-05 11:20:30 -0400198 public void testRoamingNoService_DoesNotCrash() {
199 setupDefaultSignal();
200 setCdma();
201 mServiceState = null;
202 updateServiceState();
203 }
204
205 @Test
Jason Monkf13b4b32014-11-07 16:39:34 -0500206 public void testQsSignalStrength() {
Peter Wang98598bf2019-11-19 16:08:46 -0800207 for (int testStrength = CellSignalStrength.SIGNAL_STRENGTH_NONE_OR_UNKNOWN;
Jason Monkf13b4b32014-11-07 16:39:34 -0500208 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
Jason Monkf13b4b32014-11-07 16:39:34 -0500219 public void testCdmaQsSignalStrength() {
Peter Wang98598bf2019-11-19 16:08:46 -0800220 for (int testStrength = CellSignalStrength.SIGNAL_STRENGTH_NONE_OR_UNKNOWN;
Jason Monkf13b4b32014-11-07 16:39:34 -0500221 testStrength <= SignalStrength.SIGNAL_STRENGTH_GREAT; testStrength++) {
222 setupDefaultSignal();
223 setCdma();
224 setLevel(testStrength);
225
226 verifyLastQsMobileDataIndicators(true,
Jason Monk48edc0c2017-04-10 15:01:27 -0400227 testStrength,
Amin Shaikhd64e6262018-03-08 10:08:13 -0500228 TelephonyIcons.ICON_1X, false, false);
Jason Monkf13b4b32014-11-07 16:39:34 -0500229 }
230 }
231
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -0400232 @Test
Jason Monk33f8ae72015-05-08 10:45:15 -0400233 public void testNoBangWithWifi() {
Jason Monkf13b4b32014-11-07 16:39:34 -0500234 setupDefaultSignal();
Anarghya Mitra678722f2018-05-11 14:29:54 -0700235 setConnectivityViaBroadcast(mMobileSignalController.mTransportType, false, false);
236 setConnectivityViaBroadcast(NetworkCapabilities.TRANSPORT_WIFI, true, true);
Jason Monkf13b4b32014-11-07 16:39:34 -0500237
Jason Monk48edc0c2017-04-10 15:01:27 -0400238 verifyLastMobileDataIndicators(true, DEFAULT_LEVEL, 0);
Jason Monkf13b4b32014-11-07 16:39:34 -0500239 }
240
Jason Monkc014dec2014-12-12 11:49:55 -0500241 // Some tests of actual NetworkController code, just internals not display stuff
242 // TODO: Put this somewhere else, maybe in its own file.
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -0400243 @Test
Jason Monkc014dec2014-12-12 11:49:55 -0500244 public void testHasCorrectMobileControllers() {
245 int[] testSubscriptions = new int[] { 1, 5, 3 };
246 int notTestSubscription = 0;
247 MobileSignalController mobileSignalController = Mockito.mock(MobileSignalController.class);
248
249 mNetworkController.mMobileSignalControllers.clear();
250 List<SubscriptionInfo> subscriptions = new ArrayList<>();
251 for (int i = 0; i < testSubscriptions.length; i++) {
252 // Force the test controllers into NetworkController.
253 mNetworkController.mMobileSignalControllers.put(testSubscriptions[i],
254 mobileSignalController);
255
256 // Generate a list of subscriptions we will tell the NetworkController to use.
257 SubscriptionInfo mockSubInfo = Mockito.mock(SubscriptionInfo.class);
Fabian Kozynskia9091992019-03-25 11:08:32 -0400258 when(mockSubInfo.getSubscriptionId()).thenReturn(testSubscriptions[i]);
Jason Monkc014dec2014-12-12 11:49:55 -0500259 subscriptions.add(mockSubInfo);
260 }
261 assertTrue(mNetworkController.hasCorrectMobileControllers(subscriptions));
262
263 // Add a subscription that the NetworkController doesn't know about.
264 SubscriptionInfo mockSubInfo = Mockito.mock(SubscriptionInfo.class);
Fabian Kozynskia9091992019-03-25 11:08:32 -0400265 when(mockSubInfo.getSubscriptionId()).thenReturn(notTestSubscription);
Jason Monkc014dec2014-12-12 11:49:55 -0500266 subscriptions.add(mockSubInfo);
267 assertFalse(mNetworkController.hasCorrectMobileControllers(subscriptions));
268 }
269
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -0400270 @Test
Jason Monkc014dec2014-12-12 11:49:55 -0500271 public void testSetCurrentSubscriptions() {
272 // We will not add one controller to make sure it gets created.
273 int indexToSkipController = 0;
274 // We will not add one subscription to make sure it's controller gets removed.
275 int indexToSkipSubscription = 1;
276
277 int[] testSubscriptions = new int[] { 1, 5, 3 };
278 MobileSignalController[] mobileSignalControllers = new MobileSignalController[] {
279 Mockito.mock(MobileSignalController.class),
280 Mockito.mock(MobileSignalController.class),
281 Mockito.mock(MobileSignalController.class),
282 };
283 mNetworkController.mMobileSignalControllers.clear();
284 List<SubscriptionInfo> subscriptions = new ArrayList<>();
285 for (int i = 0; i < testSubscriptions.length; i++) {
286 if (i != indexToSkipController) {
287 // Force the test controllers into NetworkController.
288 mNetworkController.mMobileSignalControllers.put(testSubscriptions[i],
289 mobileSignalControllers[i]);
290 }
291
292 if (i != indexToSkipSubscription) {
293 // Generate a list of subscriptions we will tell the NetworkController to use.
294 SubscriptionInfo mockSubInfo = Mockito.mock(SubscriptionInfo.class);
Fabian Kozynskia9091992019-03-25 11:08:32 -0400295 when(mockSubInfo.getSubscriptionId()).thenReturn(testSubscriptions[i]);
296 when(mockSubInfo.getSimSlotIndex()).thenReturn(testSubscriptions[i]);
Jason Monkc014dec2014-12-12 11:49:55 -0500297 subscriptions.add(mockSubInfo);
298 }
299 }
300
301 // We can only test whether unregister gets called if it thinks its in a listening
302 // state.
303 mNetworkController.mListening = true;
Evan Laird470ae842019-04-09 16:24:27 -0400304 mNetworkController.setCurrentSubscriptionsLocked(subscriptions);
Jason Monkc014dec2014-12-12 11:49:55 -0500305
306 for (int i = 0; i < testSubscriptions.length; i++) {
307 if (i == indexToSkipController) {
308 // Make sure a controller was created despite us not adding one.
Jason Monk8996b942017-03-02 13:58:19 -0500309 assertTrue(mNetworkController.mMobileSignalControllers.indexOfKey(
310 testSubscriptions[i]) >= 0);
Jason Monkc014dec2014-12-12 11:49:55 -0500311 } else if (i == indexToSkipSubscription) {
312 // Make sure the controller that did exist was removed
Jason Monk8996b942017-03-02 13:58:19 -0500313 assertFalse(mNetworkController.mMobileSignalControllers.indexOfKey(
314 testSubscriptions[i]) >= 0);
Jason Monkc014dec2014-12-12 11:49:55 -0500315 } else {
316 // If a MobileSignalController is around it needs to not be unregistered.
317 Mockito.verify(mobileSignalControllers[i], Mockito.never())
318 .unregisterListener();
319 }
320 }
321 }
322
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -0400323 @Test
Jason Monk7f9623f2015-02-11 09:03:02 -0500324 public void testHistorySize() {
325 // Verify valid history size, otherwise it gits printed out the wrong order and whatnot.
326 assertEquals(0, SignalController.HISTORY_SIZE & (SignalController.HISTORY_SIZE - 1));
327 }
328
Jason Monkf13b4b32014-11-07 16:39:34 -0500329 private void setCdma() {
330 setIsGsm(false);
331 updateDataConnectionState(TelephonyManager.DATA_CONNECTED,
332 TelephonyManager.NETWORK_TYPE_CDMA);
333 setCdmaRoaming(false);
Jason Monke0cdb602014-11-05 12:39:45 -0500334 }
Leigh Anned0a62792014-11-13 14:27:10 -0800335
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -0400336 @Test
Leigh Anned0a62792014-11-13 14:27:10 -0800337 public void testOnReceive_stringsUpdatedAction_spn() {
338 String expectedMNetworkName = "Test";
339 Intent intent = createStringsUpdatedIntent(true /* showSpn */,
340 expectedMNetworkName /* spn */,
341 false /* showPlmn */,
342 "NotTest" /* plmn */);
343
344 mNetworkController.onReceive(mContext, intent);
345
346 assertNetworkNameEquals(expectedMNetworkName);
347 }
348
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -0400349 @Test
Leigh Anned0a62792014-11-13 14:27:10 -0800350 public void testOnReceive_stringsUpdatedAction_plmn() {
351 String expectedMNetworkName = "Test";
352
353 Intent intent = createStringsUpdatedIntent(false /* showSpn */,
354 "NotTest" /* spn */,
355 true /* showPlmn */,
356 expectedMNetworkName /* plmn */);
357
358 mNetworkController.onReceive(mContext, intent);
359
360 assertNetworkNameEquals(expectedMNetworkName);
361 }
362
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -0400363 @Test
Leigh Anned0a62792014-11-13 14:27:10 -0800364 public void testOnReceive_stringsUpdatedAction_bothFalse() {
365 Intent intent = createStringsUpdatedIntent(false /* showSpn */,
366 "Irrelevant" /* spn */,
367 false /* showPlmn */,
368 "Irrelevant" /* plmn */);
369
370 mNetworkController.onReceive(mContext, intent);
371
372 String defaultNetworkName = mMobileSignalController
373 .getStringIfExists(
Evan Laird83c87e52019-09-24 19:14:05 -0400374 com.android.internal.R.string.lockscreen_carrier_default).toString();
Leigh Anned0a62792014-11-13 14:27:10 -0800375 assertNetworkNameEquals(defaultNetworkName);
376 }
377
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -0400378 @Test
Leigh Anned0a62792014-11-13 14:27:10 -0800379 public void testOnReceive_stringsUpdatedAction_bothTrueAndNull() {
380 Intent intent = createStringsUpdatedIntent(true /* showSpn */,
381 null /* spn */,
382 true /* showPlmn */,
383 null /* plmn */);
384
385 mNetworkController.onReceive(mContext, intent);
386
387 String defaultNetworkName = mMobileSignalController.getStringIfExists(
Evan Laird83c87e52019-09-24 19:14:05 -0400388 com.android.internal.R.string.lockscreen_carrier_default).toString();
Leigh Anned0a62792014-11-13 14:27:10 -0800389 assertNetworkNameEquals(defaultNetworkName);
390 }
391
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -0400392 @Test
Leigh Anned0a62792014-11-13 14:27:10 -0800393 public void testOnReceive_stringsUpdatedAction_bothTrueAndNonNull() {
394 String spn = "Test1";
395 String plmn = "Test2";
396
397 Intent intent = createStringsUpdatedIntent(true /* showSpn */,
398 spn /* spn */,
399 true /* showPlmn */,
400 plmn /* plmn */);
401
402 mNetworkController.onReceive(mContext, intent);
403
404 assertNetworkNameEquals(plmn
405 + mMobileSignalController.getStringIfExists(
Evan Laird83c87e52019-09-24 19:14:05 -0400406 R.string.status_bar_network_name_separator).toString()
Leigh Anned0a62792014-11-13 14:27:10 -0800407 + spn);
408 }
409
410 private Intent createStringsUpdatedIntent(boolean showSpn, String spn,
411 boolean showPlmn, String plmn) {
412
413 Intent intent = new Intent();
414 intent.setAction(TelephonyIntents.SPN_STRINGS_UPDATED_ACTION);
415
416 intent.putExtra(TelephonyIntents.EXTRA_SHOW_SPN, showSpn);
417 intent.putExtra(TelephonyIntents.EXTRA_SPN, spn);
418
419 intent.putExtra(TelephonyIntents.EXTRA_SHOW_PLMN, showPlmn);
420 intent.putExtra(TelephonyIntents.EXTRA_PLMN, plmn);
Jason Monk18985e02015-01-07 12:07:06 -0500421 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, mSubId);
Leigh Anned0a62792014-11-13 14:27:10 -0800422
423 return intent;
424 }
425
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -0400426 @Test
Leigh Anned0a62792014-11-13 14:27:10 -0800427 public void testOnUpdateDataActivity_dataIn() {
428 setupDefaultSignal();
429
430 updateDataActivity(TelephonyManager.DATA_ACTIVITY_IN);
431
432 verifyLastQsMobileDataIndicators(true /* visible */,
Jason Monk48edc0c2017-04-10 15:01:27 -0400433 DEFAULT_LEVEL /* icon */,
Leigh Anned0a62792014-11-13 14:27:10 -0800434 DEFAULT_QS_ICON /* typeIcon */,
435 true /* dataIn */,
436 false /* dataOut */);
437
438 }
439
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -0400440 @Test
Leigh Anned0a62792014-11-13 14:27:10 -0800441 public void testOnUpdateDataActivity_dataOut() {
442 setupDefaultSignal();
443
444 updateDataActivity(TelephonyManager.DATA_ACTIVITY_OUT);
445
446 verifyLastQsMobileDataIndicators(true /* visible */,
Jason Monk48edc0c2017-04-10 15:01:27 -0400447 DEFAULT_LEVEL /* icon */,
Jason Monk7e6c83c2017-04-26 14:35:24 -0400448 DEFAULT_QS_ICON /* typeIcon */,
Leigh Anned0a62792014-11-13 14:27:10 -0800449 false /* dataIn */,
450 true /* dataOut */);
Leigh Anned0a62792014-11-13 14:27:10 -0800451 }
452
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -0400453 @Test
Leigh Anned0a62792014-11-13 14:27:10 -0800454 public void testOnUpdateDataActivity_dataInOut() {
455 setupDefaultSignal();
456
457 updateDataActivity(TelephonyManager.DATA_ACTIVITY_INOUT);
458
459 verifyLastQsMobileDataIndicators(true /* visible */,
Jason Monk48edc0c2017-04-10 15:01:27 -0400460 DEFAULT_LEVEL /* icon */,
Leigh Anned0a62792014-11-13 14:27:10 -0800461 DEFAULT_QS_ICON /* typeIcon */,
462 true /* dataIn */,
463 true /* dataOut */);
464
465 }
466
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -0400467 @Test
Leigh Anned0a62792014-11-13 14:27:10 -0800468 public void testOnUpdateDataActivity_dataActivityNone() {
469 setupDefaultSignal();
470
471 updateDataActivity(TelephonyManager.DATA_ACTIVITY_NONE);
472
473 verifyLastQsMobileDataIndicators(true /* visible */,
Jason Monk48edc0c2017-04-10 15:01:27 -0400474 DEFAULT_LEVEL /* icon */,
Leigh Anned0a62792014-11-13 14:27:10 -0800475 DEFAULT_QS_ICON /* typeIcon */,
476 false /* dataIn */,
477 false /* dataOut */);
478
479 }
Andrew Flynn5e751472015-05-01 11:50:07 -0400480
Geoffrey Pitsch2c403db2016-08-26 09:09:39 -0400481 @Test
Andrew Flynn55fc8002015-05-29 08:33:46 -0400482 public void testCarrierNetworkChange_carrierNetworkChange() {
Andrew Flynn5e751472015-05-01 11:50:07 -0400483 int strength = SignalStrength.SIGNAL_STRENGTH_GREAT;
484
485 setupDefaultSignal();
486 setLevel(strength);
487
488 // Verify baseline
489 verifyLastMobileDataIndicators(true /* visible */,
Jason Monk48edc0c2017-04-10 15:01:27 -0400490 strength /* strengthIcon */,
Andrew Flynn5e751472015-05-01 11:50:07 -0400491 DEFAULT_ICON /* typeIcon */);
492
Andrew Flynn55fc8002015-05-29 08:33:46 -0400493 // API call is made
Andrew Flynn5e751472015-05-01 11:50:07 -0400494 setCarrierNetworkChange(true /* enabled */);
Andrew Flynn5e751472015-05-01 11:50:07 -0400495
Andrew Flynn55fc8002015-05-29 08:33:46 -0400496 // Carrier network change is true, show special indicator
Andrew Flynn5e751472015-05-01 11:50:07 -0400497 verifyLastMobileDataIndicators(true /* visible */,
Jason Monk48edc0c2017-04-10 15:01:27 -0400498 SignalDrawable.getCarrierChangeState(SignalStrength.NUM_SIGNAL_STRENGTH_BINS),
Andrew Flynn5e751472015-05-01 11:50:07 -0400499 0 /* typeIcon */);
500
501 // Revert back
502 setCarrierNetworkChange(false /* enabled */);
Andrew Flynn5e751472015-05-01 11:50:07 -0400503
504 // Verify back in previous state
505 verifyLastMobileDataIndicators(true /* visible */,
Jason Monk48edc0c2017-04-10 15:01:27 -0400506 strength /* strengthIcon */,
Andrew Flynn5e751472015-05-01 11:50:07 -0400507 DEFAULT_ICON /* typeIcon */);
508 }
Jason Monkc6cc6262015-06-11 11:10:15 -0400509
Shishir Agrawal7ef5b882017-06-26 12:06:03 -0700510 @Test
511 public void testCarrierNetworkChange_roamingBeforeNetworkChange() {
512 int strength = SignalStrength.SIGNAL_STRENGTH_GREAT;
513
514 setupDefaultSignal();
515 setLevel(strength);
516 setGsmRoaming(true);
517
518 // Verify baseline
519 verifyLastMobileDataIndicators(true /* visible */,
520 strength /* strengthIcon */,
521 DEFAULT_ICON /* typeIcon */,
522 true /* roaming */);
523
524 // API call is made
525 setCarrierNetworkChange(true /* enabled */);
526
527 // Carrier network change is true, show special indicator, no roaming.
528 verifyLastMobileDataIndicators(true /* visible */,
529 SignalDrawable.getCarrierChangeState(SignalStrength.NUM_SIGNAL_STRENGTH_BINS),
530 0 /* typeIcon */,
531 false /* roaming */);
532
533 // Revert back
534 setCarrierNetworkChange(false /* enabled */);
535
536 // Verify back in previous state
537 verifyLastMobileDataIndicators(true /* visible */,
538 strength /* strengthIcon */,
539 DEFAULT_ICON /* typeIcon */,
540 true /* roaming */);
541 }
542
543 @Test
544 public void testCarrierNetworkChange_roamingAfterNetworkChange() {
545 int strength = SignalStrength.SIGNAL_STRENGTH_GREAT;
546
547 setupDefaultSignal();
548 setLevel(strength);
549
550 // Verify baseline
551 verifyLastMobileDataIndicators(true /* visible */,
552 strength /* strengthIcon */,
553 DEFAULT_ICON /* typeIcon */,
554 false /* roaming */);
555
556 // API call is made
557 setCarrierNetworkChange(true /* enabled */);
558
559 // Carrier network change is true, show special indicator, no roaming.
560 verifyLastMobileDataIndicators(true /* visible */,
561 SignalDrawable.getCarrierChangeState(SignalStrength.NUM_SIGNAL_STRENGTH_BINS),
562 0 /* typeIcon */,
563 false /* roaming */);
564
565 setGsmRoaming(true);
566
567 // Roaming should not show.
568 verifyLastMobileDataIndicators(true /* visible */,
569 SignalDrawable.getCarrierChangeState(SignalStrength.NUM_SIGNAL_STRENGTH_BINS),
570 0 /* typeIcon */,
571 false /* roaming */);
572
573 // Revert back
574 setCarrierNetworkChange(false /* enabled */);
575
576 // Verify back in previous state
577 verifyLastMobileDataIndicators(true /* visible */,
578 strength /* strengthIcon */,
579 DEFAULT_ICON /* typeIcon */,
580 true /* roaming */);
581 }
582
Jason Monkc6cc6262015-06-11 11:10:15 -0400583 private void verifyEmergencyOnly(boolean isEmergencyOnly) {
584 ArgumentCaptor<Boolean> emergencyOnly = ArgumentCaptor.forClass(Boolean.class);
585 Mockito.verify(mCallbackHandler, Mockito.atLeastOnce()).setEmergencyCallsOnly(
586 emergencyOnly.capture());
587 assertEquals(isEmergencyOnly, (boolean) emergencyOnly.getValue());
588 }
Jason Monke0cdb602014-11-05 12:39:45 -0500589}