1 /* 2 * Copyright 2017 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.internal.telephony.uicc; 17 18 import static com.android.internal.telephony.TelephonyTestUtils.waitForMs; 19 20 import static org.junit.Assert.assertEquals; 21 import static org.junit.Assert.assertFalse; 22 import static org.junit.Assert.assertNull; 23 import static org.junit.Assert.assertTrue; 24 import static org.mockito.Mockito.anyInt; 25 import static org.mockito.Mockito.anyString; 26 import static org.mockito.Mockito.atLeast; 27 import static org.mockito.Mockito.doReturn; 28 import static org.mockito.Mockito.isA; 29 import static org.mockito.Mockito.times; 30 import static org.mockito.Mockito.verify; 31 32 import android.content.Intent; 33 import android.os.Handler; 34 import android.os.HandlerThread; 35 import android.os.Message; 36 import android.os.PersistableBundle; 37 import android.support.test.filters.SmallTest; 38 import android.telephony.CarrierConfigManager; 39 40 import com.android.internal.telephony.IccCardConstants.State; 41 import com.android.internal.telephony.TelephonyTest; 42 import com.android.internal.telephony.cat.CatService; 43 import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppState; 44 45 import org.junit.After; 46 import org.junit.Before; 47 import org.junit.Test; 48 import org.mockito.ArgumentCaptor; 49 import org.mockito.Mock; 50 51 import java.util.Map; 52 53 public class UiccProfileTest extends TelephonyTest { 54 private UiccProfile mUiccProfile; 55 56 public UiccProfileTest() { 57 super(); 58 } 59 60 private IccIoResult mIccIoResult; 61 private static final int SCARY_SLEEP_MS = 200; 62 63 private UiccProfileHandlerThread mTestHandlerThread; 64 private Handler mHandler; 65 private static final int UICCPROFILE_UPDATE_PROFILE_EVENT = 1; 66 private static final int UICCPROFILE_UPDATE_APPLICATION_EVENT = 2; 67 private static final int UICCPROFILE_CARRIER_PRIVILEDGE_LOADED_EVENT = 3; 68 69 @Mock 70 private CatService mCAT; 71 @Mock 72 private IccCardStatus mIccCardStatus; 73 @Mock 74 private Handler mMockedHandler; 75 @Mock 76 private UiccCard mUiccCard; 77 78 private class UiccProfileHandlerThread extends HandlerThread { 79 80 private UiccProfileHandlerThread(String name) { 81 super(name); 82 } 83 84 @Override 85 public void onLooperPrepared() { 86 mUiccProfile = new UiccProfile(mContextFixture.getTestDouble(), 87 mSimulatedCommands, mIccCardStatus, 0 /* phoneId */, 88 mUiccCard, new Object()); 89 /* create a custom handler for the Handler Thread */ 90 mHandler = new Handler(mTestHandlerThread.getLooper()) { 91 @Override 92 public void handleMessage(Message msg) { 93 switch (msg.what) { 94 case UICCPROFILE_UPDATE_PROFILE_EVENT: 95 /* Upon handling this event, new CarrierPrivilegeRule 96 will be created with the looper of HandlerThread */ 97 logd("Update UICC Profile"); 98 mUiccProfile.update(mContextFixture.getTestDouble(), 99 mSimulatedCommands, mIccCardStatus); 100 setReady(true); 101 break; 102 case UICCPROFILE_UPDATE_APPLICATION_EVENT: 103 logd("Update UICC Profile Applications"); 104 mUiccProfile.update(mContextFixture.getTestDouble(), 105 mSimulatedCommands, mIccCardStatus); 106 setReady(true); 107 break; 108 default: 109 logd("Unknown Event " + msg.what); 110 } 111 } 112 }; 113 /* wait for the carrier privilege rules to be loaded */ 114 waitForMs(50); 115 setReady(true); 116 logd("Create UiccProfile"); 117 } 118 } 119 120 private IccCardApplicationStatus composeUiccApplicationStatus( 121 IccCardApplicationStatus.AppType appType, 122 IccCardApplicationStatus.AppState appState, String aid) { 123 IccCardApplicationStatus mIccCardAppStatus = new IccCardApplicationStatus(); 124 mIccCardAppStatus.aid = aid; 125 mIccCardAppStatus.app_type = appType; 126 mIccCardAppStatus.app_state = appState; 127 mIccCardAppStatus.pin1 = mIccCardAppStatus.pin2 = 128 IccCardStatus.PinState.PINSTATE_ENABLED_VERIFIED; 129 return mIccCardAppStatus; 130 } 131 132 @Before 133 public void setUp() throws Exception { 134 super.setUp(getClass().getSimpleName()); 135 /* initially there are no application available, but the array should not be empty. */ 136 IccCardApplicationStatus umtsApp = composeUiccApplicationStatus( 137 IccCardApplicationStatus.AppType.APPTYPE_USIM, 138 IccCardApplicationStatus.AppState.APPSTATE_UNKNOWN, "0xA2"); 139 mIccCardStatus.mApplications = new IccCardApplicationStatus[]{umtsApp}; 140 mIccCardStatus.mCdmaSubscriptionAppIndex = 141 mIccCardStatus.mImsSubscriptionAppIndex = 142 mIccCardStatus.mGsmUmtsSubscriptionAppIndex = -1; 143 mIccIoResult = new IccIoResult(0x90, 0x00, IccUtils.hexStringToBytes("FF40")); 144 mSimulatedCommands.setIccIoResultForApduLogicalChannel(mIccIoResult); 145 /* starting the Handler Thread */ 146 mTestHandlerThread = new UiccProfileHandlerThread(TAG); 147 mTestHandlerThread.start(); 148 149 waitUntilReady(); 150 151 /* wait for the carrier privilege rules to be loaded */ 152 waitForMs(50); 153 154 replaceInstance(UiccProfile.class, "mCatService", mUiccProfile, mCAT); 155 } 156 157 @After 158 public void tearDown() throws Exception { 159 mTestHandlerThread.quit(); 160 super.tearDown(); 161 } 162 163 @Test 164 @SmallTest 165 public void tesUiccProfileInfoSanity() { 166 assertEquals(1, mUiccProfile.getNumApplications()); 167 assertNull(mUiccProfile.getUniversalPinState()); 168 assertNull(mUiccProfile.getOperatorBrandOverride()); 169 for (IccCardApplicationStatus.AppType mAppType : 170 IccCardApplicationStatus.AppType.values()) { 171 if (mAppType == IccCardApplicationStatus.AppType.APPTYPE_USIM) { 172 assertTrue(mUiccProfile.isApplicationOnIcc(mAppType)); 173 } else { 174 assertFalse(mUiccProfile.isApplicationOnIcc(mAppType)); 175 } 176 177 } 178 } 179 180 @Test 181 @SmallTest 182 public void testParseWhitelistMapFromString() { 183 String whitelist = ""; 184 Map<String, String> parsedMap = UiccProfile.parseToCertificateToPackageMap(whitelist); 185 assertTrue(parsedMap.isEmpty()); 186 187 whitelist = "nokey;value;separation"; 188 parsedMap = UiccProfile.parseToCertificateToPackageMap(whitelist); 189 assertTrue(parsedMap.isEmpty()); 190 191 whitelist = "KEY1:value1"; 192 parsedMap = UiccProfile.parseToCertificateToPackageMap(whitelist); 193 assertEquals("value1", parsedMap.get("KEY1")); 194 195 whitelist = "KEY1:value1; KEY2:value2 ;KEY3:value3"; 196 parsedMap = UiccProfile.parseToCertificateToPackageMap(whitelist); 197 assertEquals("value1", parsedMap.get("KEY1")); 198 assertEquals("value2", parsedMap.get("KEY2")); 199 assertEquals("value3", parsedMap.get("KEY3")); 200 } 201 202 @Test 203 @SmallTest 204 public void testUpdateUiccProfileApplication() { 205 /* update app status and index */ 206 IccCardApplicationStatus cdmaApp = composeUiccApplicationStatus( 207 IccCardApplicationStatus.AppType.APPTYPE_CSIM, 208 IccCardApplicationStatus.AppState.APPSTATE_UNKNOWN, "0xA0"); 209 IccCardApplicationStatus imsApp = composeUiccApplicationStatus( 210 IccCardApplicationStatus.AppType.APPTYPE_ISIM, 211 IccCardApplicationStatus.AppState.APPSTATE_UNKNOWN, "0xA1"); 212 IccCardApplicationStatus umtsApp = composeUiccApplicationStatus( 213 IccCardApplicationStatus.AppType.APPTYPE_USIM, 214 IccCardApplicationStatus.AppState.APPSTATE_UNKNOWN, "0xA2"); 215 mIccCardStatus.mApplications = new IccCardApplicationStatus[]{cdmaApp, imsApp, umtsApp}; 216 mIccCardStatus.mCdmaSubscriptionAppIndex = 0; 217 mIccCardStatus.mImsSubscriptionAppIndex = 1; 218 mIccCardStatus.mGsmUmtsSubscriptionAppIndex = 2; 219 Message mProfileUpdate = mHandler.obtainMessage(UICCPROFILE_UPDATE_APPLICATION_EVENT); 220 setReady(false); 221 mProfileUpdate.sendToTarget(); 222 223 waitUntilReady(); 224 225 /* wait for the carrier privilege rules to be loaded */ 226 waitForMs(50); 227 228 assertEquals(3, mUiccProfile.getNumApplications()); 229 assertTrue(mUiccProfile.isApplicationOnIcc(IccCardApplicationStatus.AppType.APPTYPE_CSIM)); 230 assertTrue(mUiccProfile.isApplicationOnIcc(IccCardApplicationStatus.AppType.APPTYPE_ISIM)); 231 assertTrue(mUiccProfile.isApplicationOnIcc(IccCardApplicationStatus.AppType.APPTYPE_USIM)); 232 } 233 234 @Test 235 @SmallTest 236 public void testUpdateUiccProfile() { 237 int mChannelId = 1; 238 mIccCardStatus.mCardState = IccCardStatus.CardState.CARDSTATE_PRESENT; 239 mSimulatedCommands.setOpenChannelId(mChannelId); 240 Message mCardUpdate = mHandler.obtainMessage(UICCPROFILE_UPDATE_PROFILE_EVENT); 241 setReady(false); 242 mCardUpdate.sendToTarget(); 243 /* try to create a new CarrierPrivilege, loading state -> loaded state */ 244 /* wait till the async result and message delay */ 245 waitUntilReady(); 246 /* wait for the carrier privilege rules to be loaded */ 247 waitForMs(50); 248 249 assertTrue(mUiccProfile.areCarrierPriviligeRulesLoaded()); 250 verify(mSimulatedCommandsVerifier, times(2)).iccOpenLogicalChannel(isA(String.class), 251 anyInt(), isA(Message.class)); 252 verify(mSimulatedCommandsVerifier, times(2)).iccTransmitApduLogicalChannel( 253 anyInt(), anyInt(), anyInt(), anyInt(), anyInt(), anyInt(), anyString(), 254 isA(Message.class) 255 ); 256 } 257 258 @Test 259 @SmallTest 260 public void testUpdateUiccProfilePinState() { 261 mIccCardStatus.mUniversalPinState = IccCardStatus.PinState.PINSTATE_ENABLED_VERIFIED; 262 mUiccProfile.update(mContextFixture.getTestDouble(), mSimulatedCommands, mIccCardStatus); 263 assertEquals(IccCardStatus.PinState.PINSTATE_ENABLED_VERIFIED, 264 mUiccProfile.getUniversalPinState()); 265 } 266 267 @Test 268 @SmallTest 269 public void testCarrierPriviledgeLoadedListener() { 270 mUiccProfile.registerForCarrierPrivilegeRulesLoaded(mMockedHandler, 271 UICCPROFILE_CARRIER_PRIVILEDGE_LOADED_EVENT, null); 272 ArgumentCaptor<Message> mCaptorMessage = ArgumentCaptor.forClass(Message.class); 273 ArgumentCaptor<Long> mCaptorLong = ArgumentCaptor.forClass(Long.class); 274 testUpdateUiccProfile(); 275 verify(mMockedHandler, atLeast(1)).sendMessageDelayed(mCaptorMessage.capture(), 276 mCaptorLong.capture()); 277 assertEquals(UICCPROFILE_CARRIER_PRIVILEDGE_LOADED_EVENT, mCaptorMessage.getValue().what); 278 } 279 280 @Test 281 @SmallTest 282 public void testInitialCardState() { 283 // after updateExternalState() is called, the state will not be UNKNOWN 284 assertEquals(mUiccProfile.getState(), State.NOT_READY); 285 } 286 287 @Test 288 @SmallTest 289 public void testUpdateUiccProfileApplicationNotReady() { 290 /* update app status and index */ 291 IccCardApplicationStatus cdmaApp = composeUiccApplicationStatus( 292 IccCardApplicationStatus.AppType.APPTYPE_CSIM, 293 IccCardApplicationStatus.AppState.APPSTATE_READY, "0xA0"); 294 IccCardApplicationStatus imsApp = composeUiccApplicationStatus( 295 IccCardApplicationStatus.AppType.APPTYPE_ISIM, 296 IccCardApplicationStatus.AppState.APPSTATE_READY, "0xA1"); 297 IccCardApplicationStatus umtsApp = composeUiccApplicationStatus( 298 IccCardApplicationStatus.AppType.APPTYPE_USIM, 299 IccCardApplicationStatus.AppState.APPSTATE_UNKNOWN, "0xA2"); 300 mIccCardStatus.mApplications = new IccCardApplicationStatus[]{cdmaApp, imsApp, umtsApp}; 301 mIccCardStatus.mCdmaSubscriptionAppIndex = 0; 302 mIccCardStatus.mImsSubscriptionAppIndex = 1; 303 mIccCardStatus.mGsmUmtsSubscriptionAppIndex = 2; 304 Message mProfileUpdate = mHandler.obtainMessage(UICCPROFILE_UPDATE_APPLICATION_EVENT); 305 setReady(false); 306 mProfileUpdate.sendToTarget(); 307 308 waitUntilReady(); 309 310 /* wait for the carrier privilege rules to be loaded */ 311 waitForMs(50); 312 assertEquals(3, mUiccProfile.getNumApplications()); 313 314 mUiccProfile.mHandler.sendMessage( 315 mUiccProfile.mHandler.obtainMessage(UiccProfile.EVENT_APP_READY)); 316 waitForMs(SCARY_SLEEP_MS); 317 assertEquals(mUiccProfile.getState(), State.NOT_READY); 318 } 319 320 @Test 321 @SmallTest 322 public void testUpdateUiccProfileApplicationAllReady() { 323 /* update app status and index */ 324 IccCardApplicationStatus cdmaApp = composeUiccApplicationStatus( 325 IccCardApplicationStatus.AppType.APPTYPE_CSIM, 326 IccCardApplicationStatus.AppState.APPSTATE_READY, "0xA0"); 327 IccCardApplicationStatus imsApp = composeUiccApplicationStatus( 328 IccCardApplicationStatus.AppType.APPTYPE_ISIM, 329 IccCardApplicationStatus.AppState.APPSTATE_READY, "0xA1"); 330 IccCardApplicationStatus umtsApp = composeUiccApplicationStatus( 331 IccCardApplicationStatus.AppType.APPTYPE_USIM, 332 IccCardApplicationStatus.AppState.APPSTATE_READY, "0xA2"); 333 mIccCardStatus.mApplications = new IccCardApplicationStatus[]{cdmaApp, imsApp, umtsApp}; 334 mIccCardStatus.mCdmaSubscriptionAppIndex = 0; 335 mIccCardStatus.mImsSubscriptionAppIndex = 1; 336 mIccCardStatus.mGsmUmtsSubscriptionAppIndex = 2; 337 Message mProfileUpdate = mHandler.obtainMessage(UICCPROFILE_UPDATE_APPLICATION_EVENT); 338 setReady(false); 339 mProfileUpdate.sendToTarget(); 340 341 waitUntilReady(); 342 343 /* wait for the carrier privilege rules to be loaded */ 344 waitForMs(50); 345 assertEquals(3, mUiccProfile.getNumApplications()); 346 347 mUiccProfile.mHandler.sendMessage( 348 mUiccProfile.mHandler.obtainMessage(UiccProfile.EVENT_APP_READY)); 349 waitForMs(SCARY_SLEEP_MS); 350 // state is loaded as all records are loaded right away as SimulatedCommands returns 351 // response for them right away. Ideally applications and records should be mocked. 352 assertEquals(State.LOADED, mUiccProfile.getState()); 353 } 354 355 @Test 356 @SmallTest 357 public void testUpdateUiccProfileApplicationAllSupportedAppsReady() { 358 /* update app status and index */ 359 IccCardApplicationStatus umtsApp = composeUiccApplicationStatus( 360 IccCardApplicationStatus.AppType.APPTYPE_USIM, 361 IccCardApplicationStatus.AppState.APPSTATE_READY, "0xA2"); 362 IccCardApplicationStatus imsApp = composeUiccApplicationStatus( 363 IccCardApplicationStatus.AppType.APPTYPE_ISIM, 364 IccCardApplicationStatus.AppState.APPSTATE_READY, "0xA1"); 365 IccCardApplicationStatus unknownApp = composeUiccApplicationStatus( 366 IccCardApplicationStatus.AppType.APPTYPE_UNKNOWN, 367 IccCardApplicationStatus.AppState.APPSTATE_UNKNOWN, "0xA2"); 368 mIccCardStatus.mApplications = new IccCardApplicationStatus[]{imsApp, umtsApp, unknownApp}; 369 mIccCardStatus.mCdmaSubscriptionAppIndex = -1; 370 mIccCardStatus.mImsSubscriptionAppIndex = 0; 371 mIccCardStatus.mGsmUmtsSubscriptionAppIndex = 1; 372 Message mProfileUpdate = mHandler.obtainMessage(UICCPROFILE_UPDATE_APPLICATION_EVENT); 373 setReady(false); 374 mProfileUpdate.sendToTarget(); 375 376 waitUntilReady(); 377 378 /* wait for the carrier privilege rules to be loaded */ 379 waitForMs(50); 380 assertEquals(3, mUiccProfile.getNumApplications()); 381 382 mUiccProfile.mHandler.sendMessage( 383 mUiccProfile.mHandler.obtainMessage(UiccProfile.EVENT_APP_READY)); 384 waitForMs(SCARY_SLEEP_MS); 385 // state is loaded as all records are loaded right away as SimulatedCommands returns 386 // response for them right away. Ideally applications and records should be mocked. 387 assertEquals(State.LOADED, mUiccProfile.getState()); 388 } 389 390 @Test 391 @SmallTest 392 public void testUpdateUiccProfileApplicationWithDuplicateApps() { 393 /* update app status and index */ 394 IccCardApplicationStatus umtsApp = composeUiccApplicationStatus( 395 IccCardApplicationStatus.AppType.APPTYPE_USIM, 396 IccCardApplicationStatus.AppState.APPSTATE_READY, "0xA2"); 397 IccCardApplicationStatus imsApp = composeUiccApplicationStatus( 398 IccCardApplicationStatus.AppType.APPTYPE_ISIM, 399 IccCardApplicationStatus.AppState.APPSTATE_READY, "0xA1"); 400 IccCardApplicationStatus unknownApp = composeUiccApplicationStatus( 401 IccCardApplicationStatus.AppType.APPTYPE_UNKNOWN, 402 IccCardApplicationStatus.AppState.APPSTATE_UNKNOWN, "0xA2"); 403 IccCardApplicationStatus umtsAppDup = composeUiccApplicationStatus( 404 IccCardApplicationStatus.AppType.APPTYPE_USIM, 405 AppState.APPSTATE_DETECTED, "0xA2"); 406 mIccCardStatus.mApplications = new IccCardApplicationStatus[]{imsApp, umtsApp, unknownApp, 407 umtsAppDup}; 408 mIccCardStatus.mCdmaSubscriptionAppIndex = -1; 409 mIccCardStatus.mImsSubscriptionAppIndex = 0; 410 mIccCardStatus.mGsmUmtsSubscriptionAppIndex = 1; 411 Message mProfileUpdate = mHandler.obtainMessage(UICCPROFILE_UPDATE_APPLICATION_EVENT); 412 setReady(false); 413 mProfileUpdate.sendToTarget(); 414 415 waitUntilReady(); 416 417 /* wait for the carrier privilege rules to be loaded */ 418 waitForMs(50); 419 assertEquals(4, mUiccProfile.getNumApplications()); 420 421 mUiccProfile.mHandler.sendMessage( 422 mUiccProfile.mHandler.obtainMessage(UiccProfile.EVENT_APP_READY)); 423 waitForMs(SCARY_SLEEP_MS); 424 // state is loaded as all records are loaded right away as SimulatedCommands returns 425 // response for them right away. Ideally applications and records should be mocked. 426 assertEquals(State.LOADED, mUiccProfile.getState()); 427 } 428 429 @Test 430 @SmallTest 431 public void testUpdateUiccProfileApplicationNoApplication() { 432 mIccCardStatus.mApplications = new IccCardApplicationStatus[]{}; 433 mIccCardStatus.mCdmaSubscriptionAppIndex = -1; 434 mIccCardStatus.mImsSubscriptionAppIndex = -1; 435 mIccCardStatus.mGsmUmtsSubscriptionAppIndex = -1; 436 Message mProfileUpdate = mHandler.obtainMessage(UICCPROFILE_UPDATE_APPLICATION_EVENT); 437 setReady(false); 438 mProfileUpdate.sendToTarget(); 439 440 waitUntilReady(); 441 442 /* wait for the carrier privilege rules to be loaded */ 443 waitForMs(50); 444 assertEquals(0, mUiccProfile.getNumApplications()); 445 446 mUiccProfile.mHandler.sendMessage( 447 mUiccProfile.mHandler.obtainMessage(UiccProfile.EVENT_APP_READY)); 448 waitForMs(SCARY_SLEEP_MS); 449 // state is loaded since there is no applications. 450 assertEquals(State.NOT_READY, mUiccProfile.getState()); 451 } 452 453 @Test 454 @SmallTest 455 public void testUpdateUiccProfileApplicationNoSupportApplication() { 456 IccCardApplicationStatus unknownApp = composeUiccApplicationStatus( 457 IccCardApplicationStatus.AppType.APPTYPE_UNKNOWN, 458 IccCardApplicationStatus.AppState.APPSTATE_UNKNOWN, ""); 459 mIccCardStatus.mApplications = new IccCardApplicationStatus[]{unknownApp}; 460 mIccCardStatus.mCdmaSubscriptionAppIndex = -1; 461 mIccCardStatus.mImsSubscriptionAppIndex = -1; 462 mIccCardStatus.mGsmUmtsSubscriptionAppIndex = -1; 463 Message mProfileUpdate = mHandler.obtainMessage(UICCPROFILE_UPDATE_APPLICATION_EVENT); 464 setReady(false); 465 mProfileUpdate.sendToTarget(); 466 467 waitUntilReady(); 468 469 /* wait for the carrier privilege rules to be loaded */ 470 waitForMs(50); 471 assertEquals(1, mUiccProfile.getNumApplications()); 472 473 mUiccProfile.mHandler.sendMessage( 474 mUiccProfile.mHandler.obtainMessage(UiccProfile.EVENT_APP_READY)); 475 waitForMs(SCARY_SLEEP_MS); 476 // state is loaded since there is no applications. 477 assertEquals(State.NOT_READY, mUiccProfile.getState()); 478 } 479 480 @Test 481 @SmallTest 482 public void testUpdateExternalState() { 483 // IO_ERROR 484 doReturn(IccCardStatus.CardState.CARDSTATE_ERROR).when(mUiccCard).getCardState(); 485 mUiccProfile.updateExternalState(); 486 assertEquals(State.CARD_IO_ERROR, mUiccProfile.getState()); 487 488 // RESTRICTED 489 doReturn(IccCardStatus.CardState.CARDSTATE_RESTRICTED).when(mUiccCard).getCardState(); 490 mUiccProfile.updateExternalState(); 491 assertEquals(State.CARD_RESTRICTED, mUiccProfile.getState()); 492 493 // CARD PRESENT; no mUiccApplication - state should be NOT_READY 494 doReturn(IccCardStatus.CardState.CARDSTATE_PRESENT).when(mUiccCard).getCardState(); 495 mUiccProfile.updateExternalState(); 496 assertEquals(State.NOT_READY, mUiccProfile.getState()); 497 498 // set mUiccApplication 499 testUpdateUiccProfileApplicationAllReady(); 500 mUiccProfile.updateExternalState(); 501 assertEquals(State.LOADED, mUiccProfile.getState()); 502 } 503 504 @Test 505 @SmallTest 506 public void testCarrierConfigHandling() { 507 testUpdateUiccProfileApplication(); 508 509 // Fake carrier name 510 String fakeCarrierName = "fakeCarrierName"; 511 PersistableBundle carrierConfigBundle = mContextFixture.getCarrierConfigBundle(); 512 carrierConfigBundle.putBoolean(CarrierConfigManager.KEY_CARRIER_NAME_OVERRIDE_BOOL, true); 513 carrierConfigBundle.putString(CarrierConfigManager.KEY_CARRIER_NAME_STRING, 514 fakeCarrierName); 515 516 // broadcast CARRIER_CONFIG_CHANGED 517 mContext.sendBroadcast(new Intent(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED)); 518 waitForMs(200); 519 520 // verify that setSimOperatorNameForPhone() is called with fakeCarrierName 521 ArgumentCaptor<String> stringArgumentCaptor = ArgumentCaptor.forClass(String.class); 522 verify(mTelephonyManager, atLeast(1)).setSimOperatorNameForPhone(anyInt(), 523 stringArgumentCaptor.capture()); 524 boolean carrierFound = false; 525 for (String carrierName : stringArgumentCaptor.getAllValues()) { 526 if (fakeCarrierName.equals(carrierName)) { 527 carrierFound = true; 528 break; 529 } 530 } 531 assertTrue(carrierFound); 532 } 533 } 534