1 /* 2 * Copyright (C) 2019 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 17 package com.android.keyguard; 18 19 20 import static android.telephony.SubscriptionManager.DATA_ROAMING_DISABLE; 21 import static android.telephony.SubscriptionManager.DATA_ROAMING_ENABLE; 22 import static android.telephony.SubscriptionManager.NAME_SOURCE_CARRIER_ID; 23 24 import static com.google.common.truth.Truth.assertThat; 25 26 import static junit.framework.Assert.assertTrue; 27 import static junit.framework.TestCase.assertFalse; 28 29 import static org.junit.Assert.assertEquals; 30 import static org.junit.Assert.assertNotEquals; 31 import static org.mockito.ArgumentMatchers.any; 32 import static org.mockito.ArgumentMatchers.anyBoolean; 33 import static org.mockito.ArgumentMatchers.anyInt; 34 import static org.mockito.Mockito.doAnswer; 35 import static org.mockito.Mockito.mock; 36 import static org.mockito.Mockito.never; 37 import static org.mockito.Mockito.reset; 38 import static org.mockito.Mockito.verify; 39 import static org.mockito.Mockito.when; 40 41 import android.content.pm.PackageManager; 42 import android.net.wifi.WifiInfo; 43 import android.net.wifi.WifiManager; 44 import android.provider.Settings; 45 import android.telephony.ServiceState; 46 import android.telephony.SubscriptionInfo; 47 import android.telephony.SubscriptionManager; 48 import android.telephony.TelephonyManager; 49 import android.test.suitebuilder.annotation.SmallTest; 50 import android.testing.AndroidTestingRunner; 51 import android.text.TextUtils; 52 53 import com.android.systemui.R; 54 import com.android.systemui.SysuiTestCase; 55 import com.android.systemui.keyguard.WakefulnessLifecycle; 56 import com.android.systemui.telephony.TelephonyListenerManager; 57 import com.android.systemui.util.concurrency.FakeExecutor; 58 import com.android.systemui.util.time.FakeSystemClock; 59 60 import org.junit.Before; 61 import org.junit.Test; 62 import org.junit.runner.RunWith; 63 import org.mockito.ArgumentCaptor; 64 import org.mockito.Mock; 65 import org.mockito.MockitoAnnotations; 66 import org.mockito.invocation.InvocationOnMock; 67 68 import java.util.ArrayList; 69 import java.util.HashMap; 70 import java.util.List; 71 72 @SmallTest 73 @RunWith(AndroidTestingRunner.class) 74 public class CarrierTextManagerTest extends SysuiTestCase { 75 76 private static final CharSequence SEPARATOR = " \u2014 "; 77 private static final CharSequence INVALID_CARD_TEXT = "Invalid card"; 78 private static final CharSequence AIRPLANE_MODE_TEXT = "Airplane mode"; 79 private static final String TEST_CARRIER = "TEST_CARRIER"; 80 private static final String TEST_CARRIER_2 = "TEST_CARRIER_2"; 81 private static final int TEST_CARRIER_ID = 1; 82 private static final SubscriptionInfo TEST_SUBSCRIPTION = new SubscriptionInfo(0, "", 0, 83 TEST_CARRIER, TEST_CARRIER, NAME_SOURCE_CARRIER_ID, 0xFFFFFF, "", 84 DATA_ROAMING_DISABLE, null, null, null, null, false, null, "", false, null, 85 TEST_CARRIER_ID, 0); 86 private static final SubscriptionInfo TEST_SUBSCRIPTION_NULL = new SubscriptionInfo(0, "", 0, 87 TEST_CARRIER, null, NAME_SOURCE_CARRIER_ID, 0xFFFFFF, "", DATA_ROAMING_DISABLE, 88 null, null, null, null, false, null, ""); 89 private static final SubscriptionInfo TEST_SUBSCRIPTION_ROAMING = new SubscriptionInfo(0, "", 0, 90 TEST_CARRIER, TEST_CARRIER, NAME_SOURCE_CARRIER_ID, 0xFFFFFF, "", 91 DATA_ROAMING_ENABLE, null, null, null, null, false, null, ""); 92 @Mock 93 private WifiManager mWifiManager; 94 @Mock 95 private WakefulnessLifecycle mWakefulnessLifecycle; 96 @Mock 97 private CarrierTextManager.CarrierTextCallback mCarrierTextCallback; 98 @Mock 99 private KeyguardUpdateMonitor mKeyguardUpdateMonitor; 100 @Mock 101 private PackageManager mPackageManager; 102 @Mock 103 private TelephonyManager mTelephonyManager; 104 @Mock 105 private TelephonyListenerManager mTelephonyListenerManager; 106 private FakeSystemClock mFakeSystemClock = new FakeSystemClock(); 107 private FakeExecutor mMainExecutor = new FakeExecutor(mFakeSystemClock); 108 private FakeExecutor mBgExecutor = new FakeExecutor(mFakeSystemClock); 109 @Mock 110 private SubscriptionManager mSubscriptionManager; 111 private CarrierTextManager.CarrierTextCallbackInfo mCarrierTextCallbackInfo; 112 113 private CarrierTextManager mCarrierTextManager; 114 checkMainThread(InvocationOnMock inv)115 private Void checkMainThread(InvocationOnMock inv) { 116 assertThat(mMainExecutor.isExecuting()).isTrue(); 117 assertThat(mBgExecutor.isExecuting()).isFalse(); 118 return null; 119 } 120 121 @Before setUp()122 public void setUp() { 123 MockitoAnnotations.initMocks(this); 124 125 mContext.addMockSystemService(WifiManager.class, mWifiManager); 126 mContext.addMockSystemService(PackageManager.class, mPackageManager); 127 when(mPackageManager.hasSystemFeature(PackageManager.FEATURE_TELEPHONY)).thenReturn(true); 128 mContext.addMockSystemService(TelephonyManager.class, mTelephonyManager); 129 mContext.addMockSystemService(SubscriptionManager.class, mSubscriptionManager); 130 mContext.getOrCreateTestableResources().addOverride( 131 R.string.keyguard_sim_error_message_short, INVALID_CARD_TEXT); 132 mContext.getOrCreateTestableResources().addOverride( 133 R.string.airplane_mode, AIRPLANE_MODE_TEXT); 134 mDependency.injectMockDependency(WakefulnessLifecycle.class); 135 mDependency.injectTestDependency(KeyguardUpdateMonitor.class, mKeyguardUpdateMonitor); 136 137 doAnswer(this::checkMainThread).when(mKeyguardUpdateMonitor) 138 .registerCallback(any(KeyguardUpdateMonitorCallback.class)); 139 doAnswer(this::checkMainThread).when(mKeyguardUpdateMonitor) 140 .removeCallback(any(KeyguardUpdateMonitorCallback.class)); 141 142 mCarrierTextCallbackInfo = new CarrierTextManager.CarrierTextCallbackInfo("", 143 new CharSequence[]{}, false, new int[]{}); 144 when(mTelephonyManager.getSupportedModemCount()).thenReturn(3); 145 when(mTelephonyManager.getActiveModemCount()).thenReturn(3); 146 147 mCarrierTextManager = new CarrierTextManager.Builder( 148 mContext, mContext.getResources(), mWifiManager, 149 mTelephonyManager, mTelephonyListenerManager, mWakefulnessLifecycle, mMainExecutor, 150 mBgExecutor, mKeyguardUpdateMonitor) 151 .setShowAirplaneMode(true) 152 .setShowMissingSim(true) 153 .build(); 154 155 // This should not start listening on any of the real dependencies but will test that 156 // callbacks in mKeyguardUpdateMonitor are done in the mTestableLooper thread 157 mCarrierTextManager.setListening(mCarrierTextCallback); 158 FakeExecutor.exhaustExecutors(mMainExecutor, mBgExecutor); 159 } 160 161 @Test testKeyguardUpdateMonitorCalledInMainThread()162 public void testKeyguardUpdateMonitorCalledInMainThread() throws Exception { 163 mCarrierTextManager.setListening(null); 164 mCarrierTextManager.setListening(mCarrierTextCallback); 165 FakeExecutor.exhaustExecutors(mMainExecutor, mBgExecutor); 166 } 167 168 @Test testAirplaneMode()169 public void testAirplaneMode() { 170 Settings.Global.putInt(mContext.getContentResolver(), Settings.Global.AIRPLANE_MODE_ON, 1); 171 reset(mCarrierTextCallback); 172 List<SubscriptionInfo> list = new ArrayList<>(); 173 list.add(TEST_SUBSCRIPTION); 174 when(mKeyguardUpdateMonitor.getFilteredSubscriptionInfo(anyBoolean())).thenReturn(list); 175 when(mKeyguardUpdateMonitor.getSimState(0)).thenReturn(TelephonyManager.SIM_STATE_READY); 176 mKeyguardUpdateMonitor.mServiceStates = new HashMap<>(); 177 178 mCarrierTextManager.updateCarrierText(); 179 180 ArgumentCaptor<CarrierTextManager.CarrierTextCallbackInfo> captor = 181 ArgumentCaptor.forClass( 182 CarrierTextManager.CarrierTextCallbackInfo.class); 183 184 FakeExecutor.exhaustExecutors(mMainExecutor, mBgExecutor); 185 verify(mCarrierTextCallback).updateCarrierInfo(captor.capture()); 186 assertEquals(AIRPLANE_MODE_TEXT, captor.getValue().carrierText); 187 } 188 189 @Test testCardIOError()190 public void testCardIOError() { 191 reset(mCarrierTextCallback); 192 List<SubscriptionInfo> list = new ArrayList<>(); 193 list.add(TEST_SUBSCRIPTION); 194 when(mKeyguardUpdateMonitor.getFilteredSubscriptionInfo(anyBoolean())).thenReturn(list); 195 when(mKeyguardUpdateMonitor.getSimState(0)).thenReturn(TelephonyManager.SIM_STATE_READY); 196 when(mKeyguardUpdateMonitor.getSimState(1)).thenReturn( 197 TelephonyManager.SIM_STATE_CARD_IO_ERROR); 198 mKeyguardUpdateMonitor.mServiceStates = new HashMap<>(); 199 200 mCarrierTextManager.mCallback.onSimStateChanged(3, 1, 201 TelephonyManager.SIM_STATE_CARD_IO_ERROR); 202 203 ArgumentCaptor<CarrierTextManager.CarrierTextCallbackInfo> captor = 204 ArgumentCaptor.forClass( 205 CarrierTextManager.CarrierTextCallbackInfo.class); 206 207 FakeExecutor.exhaustExecutors(mMainExecutor, mBgExecutor); 208 verify(mCarrierTextCallback).updateCarrierInfo(captor.capture()); 209 assertEquals("TEST_CARRIER" + SEPARATOR + INVALID_CARD_TEXT, captor.getValue().carrierText); 210 // There's only one subscription in the list 211 assertEquals(1, captor.getValue().listOfCarriers.length); 212 assertEquals(TEST_CARRIER, captor.getValue().listOfCarriers[0]); 213 214 // Now it becomes single SIM active mode. 215 reset(mCarrierTextCallback); 216 when(mTelephonyManager.getActiveModemCount()).thenReturn(1); 217 // Update carrier text. It should ignore error state of subId 3 in inactive slotId. 218 mCarrierTextManager.updateCarrierText(); 219 FakeExecutor.exhaustExecutors(mMainExecutor, mBgExecutor); 220 verify(mCarrierTextCallback).updateCarrierInfo(captor.capture()); 221 assertEquals("TEST_CARRIER", captor.getValue().carrierText); 222 } 223 224 @Test testWrongSlots()225 public void testWrongSlots() { 226 reset(mCarrierTextCallback); 227 when(mKeyguardUpdateMonitor.getFilteredSubscriptionInfo(anyBoolean())).thenReturn( 228 new ArrayList<>()); 229 when(mKeyguardUpdateMonitor.getSimState(anyInt())).thenReturn( 230 TelephonyManager.SIM_STATE_CARD_IO_ERROR); 231 // This should not produce an out of bounds error, even though there are no subscriptions 232 mCarrierTextManager.mCallback.onSimStateChanged(0, -3, 233 TelephonyManager.SIM_STATE_CARD_IO_ERROR); 234 mCarrierTextManager.mCallback.onSimStateChanged(0, 3, TelephonyManager.SIM_STATE_READY); 235 verify(mCarrierTextCallback, never()).updateCarrierInfo(any()); 236 } 237 238 @Test testMoreSlotsThanSubs()239 public void testMoreSlotsThanSubs() { 240 reset(mCarrierTextCallback); 241 when(mKeyguardUpdateMonitor.getFilteredSubscriptionInfo(anyBoolean())).thenReturn( 242 new ArrayList<>()); 243 244 // STOPSHIP(b/130246708) This line makes sure that SubscriptionManager provides the 245 // same answer as KeyguardUpdateMonitor. Remove when this is addressed 246 when(mSubscriptionManager.getCompleteActiveSubscriptionInfoList()).thenReturn( 247 new ArrayList<>()); 248 249 when(mKeyguardUpdateMonitor.getSimState(anyInt())).thenReturn( 250 TelephonyManager.SIM_STATE_CARD_IO_ERROR); 251 // This should not produce an out of bounds error, even though there are no subscriptions 252 mCarrierTextManager.mCallback.onSimStateChanged(0, 1, 253 TelephonyManager.SIM_STATE_CARD_IO_ERROR); 254 255 FakeExecutor.exhaustExecutors(mMainExecutor, mBgExecutor); 256 verify(mCarrierTextCallback).updateCarrierInfo( 257 any(CarrierTextManager.CarrierTextCallbackInfo.class)); 258 } 259 260 @Test testCallback()261 public void testCallback() { 262 reset(mCarrierTextCallback); 263 mCarrierTextManager.postToCallback(mCarrierTextCallbackInfo); 264 FakeExecutor.exhaustExecutors(mMainExecutor, mBgExecutor); 265 266 ArgumentCaptor<CarrierTextManager.CarrierTextCallbackInfo> captor = 267 ArgumentCaptor.forClass( 268 CarrierTextManager.CarrierTextCallbackInfo.class); 269 verify(mCarrierTextCallback).updateCarrierInfo(captor.capture()); 270 assertEquals(mCarrierTextCallbackInfo, captor.getValue()); 271 } 272 273 @Test testNullingCallback()274 public void testNullingCallback() { 275 reset(mCarrierTextCallback); 276 277 mCarrierTextManager.postToCallback(mCarrierTextCallbackInfo); 278 mCarrierTextManager.setListening(null); 279 280 // This shouldn't produce NPE 281 FakeExecutor.exhaustExecutors(mMainExecutor, mBgExecutor); 282 verify(mCarrierTextCallback).updateCarrierInfo(any()); 283 } 284 285 @Test testCreateInfo_OneValidSubscription()286 public void testCreateInfo_OneValidSubscription() { 287 reset(mCarrierTextCallback); 288 List<SubscriptionInfo> list = new ArrayList<>(); 289 list.add(TEST_SUBSCRIPTION); 290 when(mKeyguardUpdateMonitor.getSimState(anyInt())).thenReturn( 291 TelephonyManager.SIM_STATE_READY); 292 when(mKeyguardUpdateMonitor.getFilteredSubscriptionInfo(anyBoolean())).thenReturn(list); 293 294 mKeyguardUpdateMonitor.mServiceStates = new HashMap<>(); 295 296 ArgumentCaptor<CarrierTextManager.CarrierTextCallbackInfo> captor = 297 ArgumentCaptor.forClass( 298 CarrierTextManager.CarrierTextCallbackInfo.class); 299 300 mCarrierTextManager.updateCarrierText(); 301 FakeExecutor.exhaustExecutors(mMainExecutor, mBgExecutor); 302 verify(mCarrierTextCallback).updateCarrierInfo(captor.capture()); 303 304 CarrierTextManager.CarrierTextCallbackInfo info = captor.getValue(); 305 assertEquals(1, info.listOfCarriers.length); 306 assertEquals(TEST_CARRIER, info.listOfCarriers[0]); 307 assertEquals(1, info.subscriptionIds.length); 308 } 309 310 @Test testCreateInfo_OneValidSubscriptionWithRoaming()311 public void testCreateInfo_OneValidSubscriptionWithRoaming() { 312 reset(mCarrierTextCallback); 313 List<SubscriptionInfo> list = new ArrayList<>(); 314 list.add(TEST_SUBSCRIPTION_ROAMING); 315 when(mKeyguardUpdateMonitor.getSimState(anyInt())).thenReturn( 316 TelephonyManager.SIM_STATE_READY); 317 when(mKeyguardUpdateMonitor.getFilteredSubscriptionInfo(anyBoolean())).thenReturn(list); 318 319 mKeyguardUpdateMonitor.mServiceStates = new HashMap<>(); 320 321 ArgumentCaptor<CarrierTextManager.CarrierTextCallbackInfo> captor = 322 ArgumentCaptor.forClass( 323 CarrierTextManager.CarrierTextCallbackInfo.class); 324 325 mCarrierTextManager.updateCarrierText(); 326 FakeExecutor.exhaustExecutors(mMainExecutor, mBgExecutor); 327 verify(mCarrierTextCallback).updateCarrierInfo(captor.capture()); 328 329 CarrierTextManager.CarrierTextCallbackInfo info = captor.getValue(); 330 assertEquals(1, info.listOfCarriers.length); 331 assertTrue(info.listOfCarriers[0].toString().contains(TEST_CARRIER)); 332 assertEquals(1, info.subscriptionIds.length); 333 } 334 335 @Test testCarrierText_noTextOnReadySimWhenNull()336 public void testCarrierText_noTextOnReadySimWhenNull() { 337 reset(mCarrierTextCallback); 338 List<SubscriptionInfo> list = new ArrayList<>(); 339 list.add(TEST_SUBSCRIPTION_NULL); 340 when(mKeyguardUpdateMonitor.getSimState(anyInt())).thenReturn( 341 TelephonyManager.SIM_STATE_READY); 342 when(mKeyguardUpdateMonitor.getFilteredSubscriptionInfo(anyBoolean())).thenReturn(list); 343 344 mKeyguardUpdateMonitor.mServiceStates = new HashMap<>(); 345 346 ArgumentCaptor<CarrierTextManager.CarrierTextCallbackInfo> captor = 347 ArgumentCaptor.forClass( 348 CarrierTextManager.CarrierTextCallbackInfo.class); 349 350 mCarrierTextManager.updateCarrierText(); 351 FakeExecutor.exhaustExecutors(mMainExecutor, mBgExecutor); 352 verify(mCarrierTextCallback).updateCarrierInfo(captor.capture()); 353 354 assertTrue("Carrier text should be empty, instead it's " + captor.getValue().carrierText, 355 TextUtils.isEmpty(captor.getValue().carrierText)); 356 assertFalse("No SIM should be available", captor.getValue().anySimReady); 357 } 358 359 @Test testCarrierText_noTextOnReadySimWhenNull_airplaneMode_wifiOn()360 public void testCarrierText_noTextOnReadySimWhenNull_airplaneMode_wifiOn() { 361 Settings.Global.putInt(mContext.getContentResolver(), Settings.Global.AIRPLANE_MODE_ON, 1); 362 reset(mCarrierTextCallback); 363 List<SubscriptionInfo> list = new ArrayList<>(); 364 list.add(TEST_SUBSCRIPTION_NULL); 365 when(mKeyguardUpdateMonitor.getSimState(anyInt())).thenReturn( 366 TelephonyManager.SIM_STATE_READY); 367 when(mKeyguardUpdateMonitor.getFilteredSubscriptionInfo(anyBoolean())).thenReturn(list); 368 mockWifi(); 369 370 mKeyguardUpdateMonitor.mServiceStates = new HashMap<>(); 371 ServiceState ss = mock(ServiceState.class); 372 when(ss.getDataRegistrationState()).thenReturn(ServiceState.STATE_IN_SERVICE); 373 mKeyguardUpdateMonitor.mServiceStates.put(TEST_SUBSCRIPTION_NULL.getSubscriptionId(), ss); 374 375 ArgumentCaptor<CarrierTextManager.CarrierTextCallbackInfo> captor = 376 ArgumentCaptor.forClass( 377 CarrierTextManager.CarrierTextCallbackInfo.class); 378 379 mCarrierTextManager.updateCarrierText(); 380 FakeExecutor.exhaustExecutors(mMainExecutor, mBgExecutor); 381 verify(mCarrierTextCallback).updateCarrierInfo(captor.capture()); 382 383 assertFalse("No SIM should be available", captor.getValue().anySimReady); 384 // There's no airplane mode if at least one SIM is State.READY and there's wifi 385 assertFalse("Device should not be in airplane mode", captor.getValue().airplaneMode); 386 assertNotEquals(AIRPLANE_MODE_TEXT, captor.getValue().carrierText); 387 } 388 mockWifi()389 private void mockWifi() { 390 when(mWifiManager.isWifiEnabled()).thenReturn(true); 391 WifiInfo wifiInfo = mock(WifiInfo.class); 392 when(wifiInfo.getBSSID()).thenReturn(""); 393 when(mWifiManager.getConnectionInfo()).thenReturn(wifiInfo); 394 } 395 396 @Test testCreateInfo_noSubscriptions()397 public void testCreateInfo_noSubscriptions() { 398 reset(mCarrierTextCallback); 399 when(mKeyguardUpdateMonitor.getFilteredSubscriptionInfo(anyBoolean())).thenReturn( 400 new ArrayList<>()); 401 402 ArgumentCaptor<CarrierTextManager.CarrierTextCallbackInfo> captor = 403 ArgumentCaptor.forClass( 404 CarrierTextManager.CarrierTextCallbackInfo.class); 405 406 mCarrierTextManager.updateCarrierText(); 407 FakeExecutor.exhaustExecutors(mMainExecutor, mBgExecutor); 408 verify(mCarrierTextCallback).updateCarrierInfo(captor.capture()); 409 410 CarrierTextManager.CarrierTextCallbackInfo info = captor.getValue(); 411 assertEquals(0, info.listOfCarriers.length); 412 assertEquals(0, info.subscriptionIds.length); 413 414 } 415 416 @Test testCarrierText_twoValidSubscriptions()417 public void testCarrierText_twoValidSubscriptions() { 418 reset(mCarrierTextCallback); 419 List<SubscriptionInfo> list = new ArrayList<>(); 420 list.add(TEST_SUBSCRIPTION); 421 list.add(TEST_SUBSCRIPTION); 422 when(mKeyguardUpdateMonitor.getSimState(anyInt())).thenReturn( 423 TelephonyManager.SIM_STATE_READY); 424 when(mKeyguardUpdateMonitor.getFilteredSubscriptionInfo(anyBoolean())).thenReturn(list); 425 426 mKeyguardUpdateMonitor.mServiceStates = new HashMap<>(); 427 428 ArgumentCaptor<CarrierTextManager.CarrierTextCallbackInfo> captor = 429 ArgumentCaptor.forClass( 430 CarrierTextManager.CarrierTextCallbackInfo.class); 431 432 mCarrierTextManager.updateCarrierText(); 433 FakeExecutor.exhaustExecutors(mMainExecutor, mBgExecutor); 434 verify(mCarrierTextCallback).updateCarrierInfo(captor.capture()); 435 436 assertEquals(TEST_CARRIER + SEPARATOR + TEST_CARRIER, 437 captor.getValue().carrierText); 438 } 439 440 @Test testCarrierText_oneDisabledSub()441 public void testCarrierText_oneDisabledSub() { 442 reset(mCarrierTextCallback); 443 List<SubscriptionInfo> list = new ArrayList<>(); 444 list.add(TEST_SUBSCRIPTION); 445 list.add(TEST_SUBSCRIPTION); 446 when(mKeyguardUpdateMonitor.getSimState(anyInt())) 447 .thenReturn(TelephonyManager.SIM_STATE_READY) 448 .thenReturn(TelephonyManager.SIM_STATE_NOT_READY); 449 when(mKeyguardUpdateMonitor.getFilteredSubscriptionInfo(anyBoolean())).thenReturn(list); 450 451 mKeyguardUpdateMonitor.mServiceStates = new HashMap<>(); 452 453 ArgumentCaptor<CarrierTextManager.CarrierTextCallbackInfo> captor = 454 ArgumentCaptor.forClass( 455 CarrierTextManager.CarrierTextCallbackInfo.class); 456 457 mCarrierTextManager.updateCarrierText(); 458 FakeExecutor.exhaustExecutors(mMainExecutor, mBgExecutor); 459 verify(mCarrierTextCallback).updateCarrierInfo(captor.capture()); 460 461 assertEquals(TEST_CARRIER, 462 captor.getValue().carrierText); 463 } 464 465 @Test testCarrierText_firstDisabledSub()466 public void testCarrierText_firstDisabledSub() { 467 reset(mCarrierTextCallback); 468 List<SubscriptionInfo> list = new ArrayList<>(); 469 list.add(TEST_SUBSCRIPTION); 470 list.add(TEST_SUBSCRIPTION); 471 when(mKeyguardUpdateMonitor.getSimState(anyInt())) 472 .thenReturn(TelephonyManager.SIM_STATE_NOT_READY) 473 .thenReturn(TelephonyManager.SIM_STATE_READY); 474 when(mKeyguardUpdateMonitor.getFilteredSubscriptionInfo(anyBoolean())).thenReturn(list); 475 476 mKeyguardUpdateMonitor.mServiceStates = new HashMap<>(); 477 478 ArgumentCaptor<CarrierTextManager.CarrierTextCallbackInfo> captor = 479 ArgumentCaptor.forClass( 480 CarrierTextManager.CarrierTextCallbackInfo.class); 481 482 mCarrierTextManager.updateCarrierText(); 483 FakeExecutor.exhaustExecutors(mMainExecutor, mBgExecutor); 484 verify(mCarrierTextCallback).updateCarrierInfo(captor.capture()); 485 486 assertEquals(TEST_CARRIER, 487 captor.getValue().carrierText); 488 } 489 490 @Test testCarrierText_threeSubsMiddleDisabled()491 public void testCarrierText_threeSubsMiddleDisabled() { 492 reset(mCarrierTextCallback); 493 List<SubscriptionInfo> list = new ArrayList<>(); 494 list.add(TEST_SUBSCRIPTION); 495 list.add(TEST_SUBSCRIPTION); 496 list.add(TEST_SUBSCRIPTION); 497 when(mKeyguardUpdateMonitor.getSimState(anyInt())) 498 .thenReturn(TelephonyManager.SIM_STATE_READY) 499 .thenReturn(TelephonyManager.SIM_STATE_NOT_READY) 500 .thenReturn(TelephonyManager.SIM_STATE_READY); 501 when(mKeyguardUpdateMonitor.getFilteredSubscriptionInfo(anyBoolean())).thenReturn(list); 502 mKeyguardUpdateMonitor.mServiceStates = new HashMap<>(); 503 504 ArgumentCaptor<CarrierTextManager.CarrierTextCallbackInfo> captor = 505 ArgumentCaptor.forClass( 506 CarrierTextManager.CarrierTextCallbackInfo.class); 507 508 mCarrierTextManager.updateCarrierText(); 509 FakeExecutor.exhaustExecutors(mMainExecutor, mBgExecutor); 510 verify(mCarrierTextCallback).updateCarrierInfo(captor.capture()); 511 512 assertEquals(TEST_CARRIER + SEPARATOR + TEST_CARRIER, 513 captor.getValue().carrierText); 514 } 515 } 516