1 /* 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 */ 16 package com.android.systemui.statusbar.connectivity; 17 18 import static junit.framework.Assert.assertEquals; 19 import static junit.framework.Assert.assertFalse; 20 import static junit.framework.Assert.assertTrue; 21 22 import static org.mockito.Mockito.mock; 23 import static org.mockito.Mockito.when; 24 25 import android.content.Intent; 26 import android.net.NetworkCapabilities; 27 import android.net.wifi.WifiInfo; 28 import android.os.Handler; 29 import android.os.Looper; 30 import android.telephony.CellSignalStrength; 31 import android.telephony.ServiceState; 32 import android.telephony.SignalStrength; 33 import android.telephony.SubscriptionInfo; 34 import android.telephony.SubscriptionManager; 35 import android.telephony.TelephonyManager; 36 import android.testing.TestableLooper; 37 import android.testing.TestableLooper.RunWithLooper; 38 39 import androidx.test.ext.junit.runners.AndroidJUnit4; 40 import androidx.test.filters.SmallTest; 41 42 import com.android.settingslib.graph.SignalDrawable; 43 import com.android.settingslib.mobile.TelephonyIcons; 44 import com.android.settingslib.net.DataUsageController; 45 import com.android.systemui.dump.DumpManager; 46 import com.android.systemui.log.LogBuffer; 47 import com.android.systemui.res.R; 48 import com.android.systemui.statusbar.pipeline.StatusBarPipelineFlags; 49 import com.android.systemui.statusbar.policy.DeviceProvisionedController; 50 import com.android.systemui.util.CarrierConfigTracker; 51 52 import org.junit.Test; 53 import org.junit.runner.RunWith; 54 import org.mockito.ArgumentCaptor; 55 import org.mockito.Mockito; 56 57 import java.util.ArrayList; 58 import java.util.Collections; 59 import java.util.List; 60 61 @SmallTest 62 @RunWith(AndroidJUnit4.class) 63 @RunWithLooper 64 public class NetworkControllerSignalTest extends NetworkControllerBaseTest { 65 66 @Test testDeviceProvisioned_userNotSetUp()67 public void testDeviceProvisioned_userNotSetUp() { 68 // GIVEN - user is not setup 69 when(mMockProvisionController.isCurrentUserSetup()).thenReturn(false); 70 71 // WHEN - a NetworkController is created 72 mNetworkController = new NetworkControllerImpl(mContext, 73 mMockCm, 74 mMockTm, 75 mTelephonyListenerManager, 76 mMockWm, 77 mMockSm, 78 mConfig, 79 TestableLooper.get(this).getLooper(), 80 mFakeExecutor, 81 mCallbackHandler, 82 mock(AccessPointControllerImpl.class), 83 mock(StatusBarPipelineFlags.class), 84 mock(DataUsageController.class), 85 mMockSubDefaults, 86 mMockProvisionController, 87 mMockBd, 88 mUserTracker, 89 mDemoModeController, 90 mCarrierConfigTracker, 91 mWifiStatusTrackerFactory, 92 mMobileFactory, 93 mMainHandler, 94 mock(DumpManager.class), 95 mock(LogBuffer.class) 96 ); 97 TestableLooper.get(this).processAllMessages(); 98 99 // THEN - NetworkController claims the user is not setup 100 assertFalse("User has not been set up", mNetworkController.isUserSetup()); 101 } 102 103 @Test testDeviceProvisioned_userSetUp()104 public void testDeviceProvisioned_userSetUp() { 105 // GIVEN - user is not setup 106 when(mMockProvisionController.isCurrentUserSetup()).thenReturn(true); 107 108 // WHEN - a NetworkController is created 109 mNetworkController = new NetworkControllerImpl( 110 mContext, 111 mMockCm, 112 mMockTm, 113 mTelephonyListenerManager, 114 mMockWm, 115 mMockSm, 116 mConfig, 117 TestableLooper.get(this).getLooper(), 118 mFakeExecutor, 119 mCallbackHandler, 120 mock(AccessPointControllerImpl.class), 121 mock(StatusBarPipelineFlags.class), 122 mock(DataUsageController.class), 123 mMockSubDefaults, 124 mMockProvisionController, 125 mMockBd, 126 mUserTracker, 127 mDemoModeController, 128 mCarrierConfigTracker, 129 mWifiStatusTrackerFactory, 130 mMobileFactory, 131 mMainHandler, 132 mock(DumpManager.class), 133 mock(LogBuffer.class)); 134 TestableLooper.get(this).processAllMessages(); 135 136 // THEN - NetworkController claims the user is not setup 137 assertTrue("User has been set up", mNetworkController.isUserSetup()); 138 } 139 140 @Test testNoIconWithoutMobile()141 public void testNoIconWithoutMobile() { 142 // Turn off mobile network support. 143 when(mMockTm.isDataCapable()).thenReturn(false); 144 // Create a new NetworkController as this is currently handled in constructor. 145 mNetworkController = new NetworkControllerImpl( 146 mContext, 147 mMockCm, 148 mMockTm, 149 mTelephonyListenerManager, 150 mMockWm, 151 mMockSm, 152 mConfig, 153 Looper.getMainLooper(), 154 mFakeExecutor, 155 mCallbackHandler, 156 mock(AccessPointControllerImpl.class), 157 mock(StatusBarPipelineFlags.class), 158 mock(DataUsageController.class), 159 mMockSubDefaults, 160 mock(DeviceProvisionedController.class), 161 mMockBd, 162 mUserTracker, 163 mDemoModeController, 164 mock(CarrierConfigTracker.class), 165 mWifiStatusTrackerFactory, 166 mMobileFactory, 167 mMainHandler, 168 mock(DumpManager.class), 169 mock(LogBuffer.class)); 170 setupNetworkController(); 171 172 verifyLastMobileDataIndicators(false, -1, 0); 173 } 174 175 @Test testServiceStateInitialState()176 public void testServiceStateInitialState() throws Exception { 177 // Verify that NetworkControllerImpl pulls the service state from Telephony upon 178 // initialization rather than relying on the sticky behavior of ACTION_SERVICE_STATE 179 180 when(mServiceState.isEmergencyOnly()).thenReturn(true); 181 when(mMockTm.getServiceState()).thenReturn(mServiceState); 182 when(mMockSm.getCompleteActiveSubscriptionInfoList()).thenReturn(Collections.emptyList()); 183 184 mNetworkController = new NetworkControllerImpl( 185 mContext, 186 mMockCm, 187 mMockTm, 188 mTelephonyListenerManager, 189 mMockWm, 190 mMockSm, 191 mConfig, 192 Looper.getMainLooper(), 193 mFakeExecutor, 194 mCallbackHandler, 195 mock(AccessPointControllerImpl.class), 196 mock(StatusBarPipelineFlags.class), 197 mock(DataUsageController.class), 198 mMockSubDefaults, 199 mock(DeviceProvisionedController.class), 200 mMockBd, 201 mUserTracker, 202 mDemoModeController, 203 mock(CarrierConfigTracker.class), 204 mWifiStatusTrackerFactory, 205 mMobileFactory, 206 mMainHandler, 207 mock(DumpManager.class), 208 mock(LogBuffer.class)); 209 mNetworkController.registerListeners(); 210 211 // Wait for the main looper to execute the previous command 212 Handler mainThreadHandler = new Handler(Looper.getMainLooper()); 213 waitForIdleSync(mainThreadHandler); 214 215 verifyEmergencyOnly(true); 216 } 217 218 @Test testNoSimsIconPresent()219 public void testNoSimsIconPresent() { 220 // No Subscriptions. 221 mNetworkController.mMobileSignalControllers.clear(); 222 mNetworkController.updateNoSims(); 223 224 verifyHasNoSims(true); 225 } 226 227 @Test testEmergencyOnly()228 public void testEmergencyOnly() { 229 setupDefaultSignal(); 230 mNetworkController.recalculateEmergency(); 231 verifyEmergencyOnly(false); 232 233 mMobileSignalController.getState().isEmergency = true; 234 mNetworkController.recalculateEmergency(); 235 verifyEmergencyOnly(true); 236 } 237 238 @Test testEmergencyOnlyNoSubscriptions()239 public void testEmergencyOnlyNoSubscriptions() { 240 setupDefaultSignal(); 241 setSubscriptions(); 242 mNetworkController.mLastServiceState = new ServiceState(); 243 mNetworkController.mLastServiceState.setEmergencyOnly(true); 244 mNetworkController.recalculateEmergency(); 245 verifyEmergencyOnly(true); 246 } 247 248 @Test testNoEmergencyOnlyWrongSubscription()249 public void testNoEmergencyOnlyWrongSubscription() { 250 setupDefaultSignal(); 251 setDefaultSubId(42); 252 mNetworkController.recalculateEmergency(); 253 verifyEmergencyOnly(false); 254 } 255 256 @Test testNoEmengencyNoSubscriptions()257 public void testNoEmengencyNoSubscriptions() { 258 setupDefaultSignal(); 259 setSubscriptions(); 260 mNetworkController.mLastServiceState = new ServiceState(); 261 mNetworkController.mLastServiceState.setEmergencyOnly(false); 262 mNetworkController.recalculateEmergency(); 263 verifyEmergencyOnly(false); 264 } 265 266 @Test testNoSimlessIconWithoutMobile()267 public void testNoSimlessIconWithoutMobile() { 268 // Turn off mobile network support. 269 when(mMockTm.isDataCapable()).thenReturn(false); 270 // Create a new NetworkController as this is currently handled in constructor. 271 mNetworkController = new NetworkControllerImpl( 272 mContext, 273 mMockCm, 274 mMockTm, 275 mTelephonyListenerManager, 276 mMockWm, 277 mMockSm, 278 mConfig, 279 Looper.getMainLooper(), 280 mFakeExecutor, 281 mCallbackHandler, 282 mock(AccessPointControllerImpl.class), 283 mock(StatusBarPipelineFlags.class), 284 mock(DataUsageController.class), 285 mMockSubDefaults, 286 mock(DeviceProvisionedController.class), 287 mMockBd, 288 mUserTracker, 289 mDemoModeController, 290 mock(CarrierConfigTracker.class), 291 mWifiStatusTrackerFactory, 292 mMobileFactory, 293 mMainHandler, 294 mock(DumpManager.class), 295 mock(LogBuffer.class)); 296 setupNetworkController(); 297 298 // No Subscriptions. 299 mNetworkController.mMobileSignalControllers.clear(); 300 mNetworkController.updateNoSims(); 301 302 verifyHasNoSims(false); 303 } 304 305 @Test testSignalStrength()306 public void testSignalStrength() { 307 for (int testStrength = 0; 308 testStrength < CellSignalStrength.getNumSignalStrengthLevels(); testStrength++) { 309 setupDefaultSignal(); 310 setLevel(testStrength); 311 312 verifyLastMobileDataIndicators(true, 313 testStrength, DEFAULT_ICON); 314 315 // Verify low inet number indexing. 316 setConnectivityViaCallbackInNetworkController( 317 NetworkCapabilities.TRANSPORT_CELLULAR, false, true, null); 318 verifyLastMobileDataIndicators(true, 319 testStrength, DEFAULT_ICON, false, false); 320 } 321 } 322 323 @Test testCdmaSignalStrength()324 public void testCdmaSignalStrength() { 325 for (int testStrength = 0; 326 testStrength < CellSignalStrength.getNumSignalStrengthLevels(); testStrength++) { 327 setupDefaultSignal(); 328 setCdma(); 329 setLevel(testStrength); 330 331 verifyLastMobileDataIndicators(true, 332 testStrength, 333 TelephonyIcons.ICON_1X); 334 } 335 } 336 337 @Test testSignalRoaming()338 public void testSignalRoaming() { 339 for (int testStrength = 0; 340 testStrength < CellSignalStrength.getNumSignalStrengthLevels(); testStrength++) { 341 setupDefaultSignal(); 342 setGsmRoaming(true); 343 setLevel(testStrength); 344 345 verifyLastMobileDataIndicators(true, 346 testStrength, 347 DEFAULT_ICON, true); 348 } 349 } 350 351 @Test testCdmaSignalRoaming()352 public void testCdmaSignalRoaming() { 353 for (int testStrength = CellSignalStrength.SIGNAL_STRENGTH_NONE_OR_UNKNOWN; 354 testStrength <= SignalStrength.SIGNAL_STRENGTH_GREAT; testStrength++) { 355 setupDefaultSignal(); 356 setCdma(); 357 setCdmaRoaming(true); 358 setLevel(testStrength); 359 360 verifyLastMobileDataIndicators(true, 361 testStrength, 362 TelephonyIcons.ICON_1X, true); 363 } 364 } 365 366 @Test testRoamingNoService_DoesNotCrash()367 public void testRoamingNoService_DoesNotCrash() { 368 setupDefaultSignal(); 369 setCdma(); 370 mServiceState = null; 371 updateServiceState(); 372 } 373 374 @Test testQsSignalStrength()375 public void testQsSignalStrength() { 376 for (int testStrength = CellSignalStrength.SIGNAL_STRENGTH_NONE_OR_UNKNOWN; 377 testStrength <= SignalStrength.SIGNAL_STRENGTH_GREAT; testStrength++) { 378 setupDefaultSignal(); 379 setLevel(testStrength); 380 381 verifyLastQsMobileDataIndicators(true, 382 testStrength, 383 DEFAULT_QS_ICON, false, false); 384 } 385 } 386 387 @Test testCdmaQsSignalStrength()388 public void testCdmaQsSignalStrength() { 389 for (int testStrength = CellSignalStrength.SIGNAL_STRENGTH_NONE_OR_UNKNOWN; 390 testStrength <= SignalStrength.SIGNAL_STRENGTH_GREAT; testStrength++) { 391 setupDefaultSignal(); 392 setCdma(); 393 setLevel(testStrength); 394 395 verifyLastQsMobileDataIndicators(true, 396 testStrength, 397 TelephonyIcons.ICON_1X, false, false); 398 } 399 } 400 401 @Test testNoBangWithWifi()402 public void testNoBangWithWifi() { 403 setupDefaultSignal(); 404 setConnectivityViaCallbackInNetworkController( 405 mMobileSignalController.mTransportType, false, false, null); 406 setConnectivityViaCallbackInNetworkController( 407 NetworkCapabilities.TRANSPORT_WIFI, true, true, mock(WifiInfo.class)); 408 409 verifyLastMobileDataIndicators(true, DEFAULT_LEVEL, 0); 410 } 411 412 // Some tests of actual NetworkController code, just internals not display stuff 413 // TODO: Put this somewhere else, maybe in its own file. 414 @Test testHasCorrectMobileControllers()415 public void testHasCorrectMobileControllers() { 416 int[] testSubscriptions = new int[]{1, 5, 3}; 417 int notTestSubscription = 0; 418 MobileSignalController mobileSignalController = Mockito.mock(MobileSignalController.class); 419 420 mNetworkController.mMobileSignalControllers.clear(); 421 List<SubscriptionInfo> subscriptions = new ArrayList<>(); 422 for (int i = 0; i < testSubscriptions.length; i++) { 423 // Force the test controllers into NetworkController. 424 mNetworkController.mMobileSignalControllers.put(testSubscriptions[i], 425 mobileSignalController); 426 427 // Generate a list of subscriptions we will tell the NetworkController to use. 428 SubscriptionInfo mockSubInfo = Mockito.mock(SubscriptionInfo.class); 429 when(mockSubInfo.getSubscriptionId()).thenReturn(testSubscriptions[i]); 430 subscriptions.add(mockSubInfo); 431 } 432 assertTrue(mNetworkController.hasCorrectMobileControllers(subscriptions)); 433 434 // Add a subscription that the NetworkController doesn't know about. 435 SubscriptionInfo mockSubInfo = Mockito.mock(SubscriptionInfo.class); 436 when(mockSubInfo.getSubscriptionId()).thenReturn(notTestSubscription); 437 subscriptions.add(mockSubInfo); 438 assertFalse(mNetworkController.hasCorrectMobileControllers(subscriptions)); 439 } 440 441 @Test testSetCurrentSubscriptions()442 public void testSetCurrentSubscriptions() { 443 // We will not add one controller to make sure it gets created. 444 int indexToSkipController = 0; 445 // We will not add one subscription to make sure it's controller gets removed. 446 int indexToSkipSubscription = 1; 447 448 int[] testSubscriptions = new int[]{1, 5, 3}; 449 MobileSignalController[] mobileSignalControllers = new MobileSignalController[]{ 450 Mockito.mock(MobileSignalController.class), 451 Mockito.mock(MobileSignalController.class), 452 Mockito.mock(MobileSignalController.class), 453 }; 454 mNetworkController.mMobileSignalControllers.clear(); 455 List<SubscriptionInfo> subscriptions = new ArrayList<>(); 456 for (int i = 0; i < testSubscriptions.length; i++) { 457 if (i != indexToSkipController) { 458 // Force the test controllers into NetworkController. 459 mNetworkController.mMobileSignalControllers.put(testSubscriptions[i], 460 mobileSignalControllers[i]); 461 } 462 463 if (i != indexToSkipSubscription) { 464 // Generate a list of subscriptions we will tell the NetworkController to use. 465 SubscriptionInfo mockSubInfo = Mockito.mock(SubscriptionInfo.class); 466 when(mockSubInfo.getSubscriptionId()).thenReturn(testSubscriptions[i]); 467 when(mockSubInfo.getSimSlotIndex()).thenReturn(testSubscriptions[i]); 468 subscriptions.add(mockSubInfo); 469 } 470 } 471 472 // We can only test whether unregister gets called if it thinks its in a listening 473 // state. 474 mNetworkController.mListening = true; 475 mNetworkController.setCurrentSubscriptionsLocked(subscriptions); 476 477 for (int i = 0; i < testSubscriptions.length; i++) { 478 if (i == indexToSkipController) { 479 // Make sure a controller was created despite us not adding one. 480 assertTrue(mNetworkController.mMobileSignalControllers.indexOfKey( 481 testSubscriptions[i]) >= 0); 482 } else if (i == indexToSkipSubscription) { 483 // Make sure the controller that did exist was removed 484 assertFalse(mNetworkController.mMobileSignalControllers.indexOfKey( 485 testSubscriptions[i]) >= 0); 486 } else { 487 // If a MobileSignalController is around it needs to not be unregistered. 488 Mockito.verify(mobileSignalControllers[i], Mockito.never()) 489 .unregisterListener(); 490 } 491 } 492 } 493 494 @Test testHistorySize()495 public void testHistorySize() { 496 // Verify valid history size, otherwise it gits printed out the wrong order and whatnot. 497 assertEquals(0, SignalController.HISTORY_SIZE & (SignalController.HISTORY_SIZE - 1)); 498 } 499 setCdma()500 private void setCdma() { 501 setIsGsm(false); 502 updateDataConnectionState(TelephonyManager.DATA_CONNECTED, 503 TelephonyManager.NETWORK_TYPE_CDMA); 504 setCdmaRoaming(false); 505 } 506 507 @Test testOnReceive_stringsUpdatedAction_spn()508 public void testOnReceive_stringsUpdatedAction_spn() { 509 String expectedMNetworkName = "Test"; 510 Intent intent = createStringsUpdatedIntent(true /* showSpn */, 511 expectedMNetworkName /* spn */, 512 false /* showPlmn */, 513 "NotTest" /* plmn */); 514 515 mNetworkController.onReceive(mContext, intent); 516 517 assertNetworkNameEquals(expectedMNetworkName); 518 } 519 520 @Test testOnReceive_stringsUpdatedAction_plmn()521 public void testOnReceive_stringsUpdatedAction_plmn() { 522 String expectedMNetworkName = "Test"; 523 524 Intent intent = createStringsUpdatedIntent(false /* showSpn */, 525 "NotTest" /* spn */, 526 true /* showPlmn */, 527 expectedMNetworkName /* plmn */); 528 529 mNetworkController.onReceive(mContext, intent); 530 531 assertNetworkNameEquals(expectedMNetworkName); 532 } 533 534 @Test testOnReceive_stringsUpdatedAction_bothFalse()535 public void testOnReceive_stringsUpdatedAction_bothFalse() { 536 Intent intent = createStringsUpdatedIntent(false /* showSpn */, 537 "Irrelevant" /* spn */, 538 false /* showPlmn */, 539 "Irrelevant" /* plmn */); 540 541 mNetworkController.onReceive(mContext, intent); 542 543 String defaultNetworkName = mMobileSignalController 544 .getTextIfExists( 545 com.android.internal.R.string.lockscreen_carrier_default).toString(); 546 assertNetworkNameEquals(defaultNetworkName); 547 } 548 549 @Test testOnReceive_stringsUpdatedAction_bothTrueAndNull()550 public void testOnReceive_stringsUpdatedAction_bothTrueAndNull() { 551 Intent intent = createStringsUpdatedIntent(true /* showSpn */, 552 null /* spn */, 553 true /* showPlmn */, 554 null /* plmn */); 555 556 mNetworkController.onReceive(mContext, intent); 557 558 String defaultNetworkName = mMobileSignalController.getTextIfExists( 559 com.android.internal.R.string.lockscreen_carrier_default).toString(); 560 assertNetworkNameEquals(defaultNetworkName); 561 } 562 563 @Test testOnReceive_stringsUpdatedAction_bothTrueAndNonNull()564 public void testOnReceive_stringsUpdatedAction_bothTrueAndNonNull() { 565 String spn = "Test1"; 566 String plmn = "Test2"; 567 568 Intent intent = createStringsUpdatedIntent(true /* showSpn */, 569 spn /* spn */, 570 true /* showPlmn */, 571 plmn /* plmn */); 572 573 mNetworkController.onReceive(mContext, intent); 574 575 assertNetworkNameEquals(plmn 576 + mMobileSignalController.getTextIfExists( 577 R.string.status_bar_network_name_separator).toString() 578 + spn); 579 } 580 createStringsUpdatedIntent(boolean showSpn, String spn, boolean showPlmn, String plmn)581 private Intent createStringsUpdatedIntent(boolean showSpn, String spn, 582 boolean showPlmn, String plmn) { 583 584 Intent intent = new Intent(); 585 intent.setAction(TelephonyManager.ACTION_SERVICE_PROVIDERS_UPDATED); 586 587 intent.putExtra(TelephonyManager.EXTRA_SHOW_SPN, showSpn); 588 intent.putExtra(TelephonyManager.EXTRA_SPN, spn); 589 590 intent.putExtra(TelephonyManager.EXTRA_SHOW_PLMN, showPlmn); 591 intent.putExtra(TelephonyManager.EXTRA_PLMN, plmn); 592 SubscriptionManager.putSubscriptionIdExtra(intent, mSubId); 593 594 return intent; 595 } 596 597 @Test testOnUpdateDataActivity_dataIn()598 public void testOnUpdateDataActivity_dataIn() { 599 setupDefaultSignal(); 600 601 updateDataActivity(TelephonyManager.DATA_ACTIVITY_IN); 602 603 verifyLastQsMobileDataIndicators(true /* visible */, 604 DEFAULT_LEVEL /* icon */, 605 DEFAULT_QS_ICON /* typeIcon */, 606 true /* dataIn */, 607 false /* dataOut */); 608 609 } 610 611 @Test testOnUpdateDataActivity_dataOut()612 public void testOnUpdateDataActivity_dataOut() { 613 setupDefaultSignal(); 614 615 updateDataActivity(TelephonyManager.DATA_ACTIVITY_OUT); 616 617 verifyLastQsMobileDataIndicators(true /* visible */, 618 DEFAULT_LEVEL /* icon */, 619 DEFAULT_QS_ICON /* typeIcon */, 620 false /* dataIn */, 621 true /* dataOut */); 622 } 623 624 @Test testOnUpdateDataActivity_dataInOut()625 public void testOnUpdateDataActivity_dataInOut() { 626 setupDefaultSignal(); 627 628 updateDataActivity(TelephonyManager.DATA_ACTIVITY_INOUT); 629 630 verifyLastQsMobileDataIndicators(true /* visible */, 631 DEFAULT_LEVEL /* icon */, 632 DEFAULT_QS_ICON /* typeIcon */, 633 true /* dataIn */, 634 true /* dataOut */); 635 636 } 637 638 @Test testOnUpdateDataActivity_dataActivityNone()639 public void testOnUpdateDataActivity_dataActivityNone() { 640 setupDefaultSignal(); 641 642 updateDataActivity(TelephonyManager.DATA_ACTIVITY_NONE); 643 644 verifyLastQsMobileDataIndicators(true /* visible */, 645 DEFAULT_LEVEL /* icon */, 646 DEFAULT_QS_ICON /* typeIcon */, 647 false /* dataIn */, 648 false /* dataOut */); 649 650 } 651 652 @Test testCarrierNetworkChange_carrierNetworkChange()653 public void testCarrierNetworkChange_carrierNetworkChange() { 654 int strength = SignalStrength.SIGNAL_STRENGTH_GREAT; 655 656 setupDefaultSignal(); 657 setLevel(strength); 658 659 // Verify baseline 660 verifyLastMobileDataIndicators(true /* visible */, 661 strength /* strengthIcon */, 662 DEFAULT_ICON /* typeIcon */); 663 664 // API call is made 665 setCarrierNetworkChange(true /* enabled */); 666 667 // Carrier network change is true, show special indicator 668 verifyLastMobileDataIndicators(true /* visible */, 669 SignalDrawable.getCarrierChangeState( 670 CellSignalStrength.getNumSignalStrengthLevels()), 671 0 /* typeIcon */); 672 673 // Revert back 674 setCarrierNetworkChange(false /* enabled */); 675 676 // Verify back in previous state 677 verifyLastMobileDataIndicators(true /* visible */, 678 strength /* strengthIcon */, 679 DEFAULT_ICON /* typeIcon */); 680 } 681 682 @Test testCarrierNetworkChange_roamingBeforeNetworkChange()683 public void testCarrierNetworkChange_roamingBeforeNetworkChange() { 684 int strength = SignalStrength.SIGNAL_STRENGTH_GREAT; 685 686 setupDefaultSignal(); 687 setLevel(strength); 688 setGsmRoaming(true); 689 690 // Verify baseline 691 verifyLastMobileDataIndicators(true /* visible */, 692 strength /* strengthIcon */, 693 DEFAULT_ICON /* typeIcon */, 694 true /* roaming */); 695 696 // API call is made 697 setCarrierNetworkChange(true /* enabled */); 698 699 // Carrier network change is true, show special indicator, no roaming. 700 verifyLastMobileDataIndicators(true /* visible */, 701 SignalDrawable.getCarrierChangeState( 702 CellSignalStrength.getNumSignalStrengthLevels()), 703 0 /* typeIcon */, 704 false /* roaming */); 705 706 // Revert back 707 setCarrierNetworkChange(false /* enabled */); 708 709 // Verify back in previous state 710 verifyLastMobileDataIndicators(true /* visible */, 711 strength /* strengthIcon */, 712 DEFAULT_ICON /* typeIcon */, 713 true /* roaming */); 714 } 715 716 @Test testCarrierNetworkChange_roamingAfterNetworkChange()717 public void testCarrierNetworkChange_roamingAfterNetworkChange() { 718 int strength = SignalStrength.SIGNAL_STRENGTH_GREAT; 719 720 setupDefaultSignal(); 721 setLevel(strength); 722 723 // Verify baseline 724 verifyLastMobileDataIndicators(true /* visible */, 725 strength /* strengthIcon */, 726 DEFAULT_ICON /* typeIcon */, 727 false /* roaming */); 728 729 // API call is made 730 setCarrierNetworkChange(true /* enabled */); 731 732 // Carrier network change is true, show special indicator, no roaming. 733 verifyLastMobileDataIndicators(true /* visible */, 734 SignalDrawable.getCarrierChangeState( 735 CellSignalStrength.getNumSignalStrengthLevels()), 736 0 /* typeIcon */, 737 false /* roaming */); 738 739 setGsmRoaming(true); 740 741 // Roaming should not show. 742 verifyLastMobileDataIndicators(true /* visible */, 743 SignalDrawable.getCarrierChangeState( 744 CellSignalStrength.getNumSignalStrengthLevels()), 745 0 /* typeIcon */, 746 false /* roaming */); 747 748 // Revert back 749 setCarrierNetworkChange(false /* enabled */); 750 751 // Verify back in previous state 752 verifyLastMobileDataIndicators(true /* visible */, 753 strength /* strengthIcon */, 754 DEFAULT_ICON /* typeIcon */, 755 true /* roaming */); 756 } 757 verifyEmergencyOnly(boolean isEmergencyOnly)758 private void verifyEmergencyOnly(boolean isEmergencyOnly) { 759 ArgumentCaptor<Boolean> emergencyOnly = ArgumentCaptor.forClass(Boolean.class); 760 Mockito.verify(mCallbackHandler, Mockito.atLeastOnce()).setEmergencyCallsOnly( 761 emergencyOnly.capture()); 762 assertEquals(isEmergencyOnly, (boolean) emergencyOnly.getValue()); 763 } 764 } 765