GsmCdmaPhoneTest.java revision 0cf8dcd827da174a7d7f366aa8caa5dd29206ea1
1/* 2 * Copyright (C) 2016 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 17package com.android.internal.telephony; 18 19import android.app.Activity; 20import android.app.IApplicationThread; 21import android.content.IIntentReceiver; 22import android.content.Intent; 23import android.content.SharedPreferences; 24import android.os.AsyncResult; 25import android.os.Bundle; 26import android.os.Handler; 27import android.os.HandlerThread; 28import android.os.Message; 29import android.preference.PreferenceManager; 30import android.provider.Settings; 31import android.telephony.CarrierConfigManager; 32import android.telephony.CellLocation; 33import android.telephony.ServiceState; 34import android.telephony.SubscriptionManager; 35import android.telephony.cdma.CdmaCellLocation; 36import android.telephony.gsm.GsmCellLocation; 37import android.test.suitebuilder.annotation.SmallTest; 38 39import com.android.internal.telephony.test.SimulatedCommands; 40import com.android.internal.telephony.uicc.IccException; 41import com.android.internal.telephony.uicc.IccRecords; 42 43import org.junit.After; 44import org.junit.Before; 45import org.junit.Test; 46import org.mockito.ArgumentCaptor; 47import org.mockito.Mock; 48 49import java.util.List; 50 51import static com.android.internal.telephony.CommandsInterface.CF_ACTION_ENABLE; 52import static com.android.internal.telephony.CommandsInterface.CF_REASON_UNCONDITIONAL; 53import static com.android.internal.telephony.TelephonyTestUtils.waitForMs; 54import static org.junit.Assert.assertEquals; 55import static org.junit.Assert.assertFalse; 56import static org.junit.Assert.assertTrue; 57import static org.junit.Assert.fail; 58import static org.mockito.Matchers.anyLong; 59import static org.mockito.Mockito.any; 60import static org.mockito.Mockito.anyBoolean; 61import static org.mockito.Mockito.anyInt; 62import static org.mockito.Mockito.anyObject; 63import static org.mockito.Mockito.anyString; 64import static org.mockito.Mockito.atLeast; 65import static org.mockito.Mockito.doReturn; 66import static org.mockito.Mockito.eq; 67import static org.mockito.Mockito.times; 68import static org.mockito.Mockito.verify; 69 70public class GsmCdmaPhoneTest extends TelephonyTest { 71 @Mock 72 private Handler mTestHandler; 73 74 //mPhoneUnderTest 75 private GsmCdmaPhone mPhoneUT; 76 77 private static final int EVENT_EMERGENCY_CALLBACK_MODE_EXIT = 1; 78 private static final int EVENT_EMERGENCY_CALL_TOGGLE = 2; 79 80 private class GsmCdmaPhoneTestHandler extends HandlerThread { 81 82 private GsmCdmaPhoneTestHandler(String name) { 83 super(name); 84 } 85 86 @Override 87 public void onLooperPrepared() { 88 mPhoneUT = new GsmCdmaPhone(mContext, mSimulatedCommands, mNotifier, true, 0, 89 PhoneConstants.PHONE_TYPE_GSM, mTelephonyComponentFactory); 90 setReady(true); 91 } 92 } 93 94 private void switchToGsm() { 95 mSimulatedCommands.setVoiceRadioTech(ServiceState.RIL_RADIO_TECHNOLOGY_GSM); 96 mPhoneUT.sendMessage(mPhoneUT.obtainMessage(GsmCdmaPhone.EVENT_VOICE_RADIO_TECH_CHANGED, 97 new AsyncResult(null, new int[]{ServiceState.RIL_RADIO_TECHNOLOGY_GSM}, null))); 98 //wait for voice RAT to be updated 99 waitForMs(50); 100 assertEquals(PhoneConstants.PHONE_TYPE_GSM, mPhoneUT.getPhoneType()); 101 } 102 103 private void switchToCdma() { 104 mSimulatedCommands.setVoiceRadioTech(ServiceState.RIL_RADIO_TECHNOLOGY_IS95A); 105 mPhoneUT.sendMessage(mPhoneUT.obtainMessage(GsmCdmaPhone.EVENT_VOICE_RADIO_TECH_CHANGED, 106 new AsyncResult(null, new int[]{ServiceState.RIL_RADIO_TECHNOLOGY_IS95A}, null))); 107 //wait for voice RAT to be updated 108 waitForMs(50); 109 assertEquals(PhoneConstants.PHONE_TYPE_CDMA, mPhoneUT.getPhoneType()); 110 } 111 112 @Before 113 public void setUp() throws Exception { 114 super.setUp(getClass().getSimpleName()); 115 116 doReturn(false).when(mSST).isDeviceShuttingDown(); 117 118 new GsmCdmaPhoneTestHandler(TAG).start(); 119 waitUntilReady(); 120 ArgumentCaptor<Integer> integerArgumentCaptor = ArgumentCaptor.forClass(Integer.class); 121 verify(mUiccController).registerForIccChanged(eq(mPhoneUT), integerArgumentCaptor.capture(), 122 anyObject()); 123 Message msg = Message.obtain(); 124 msg.what = integerArgumentCaptor.getValue(); 125 mPhoneUT.sendMessage(msg); 126 waitForMs(50); 127 } 128 129 @After 130 public void tearDown() throws Exception { 131 mPhoneUT.removeCallbacksAndMessages(null); 132 mPhoneUT = null; 133 super.tearDown(); 134 } 135 136 @Test 137 @SmallTest 138 public void testPhoneTypeSwitch() { 139 assertTrue(mPhoneUT.isPhoneTypeGsm()); 140 switchToCdma(); 141 assertTrue(mPhoneUT.isPhoneTypeCdmaLte()); 142 } 143 144 @Test 145 @SmallTest 146 public void testHandleActionCarrierConfigChanged() { 147 // set voice radio tech in RIL to 1xRTT. ACTION_CARRIER_CONFIG_CHANGED should trigger a 148 // query and change phone type 149 mSimulatedCommands.setVoiceRadioTech(ServiceState.RIL_RADIO_TECHNOLOGY_1xRTT); 150 assertTrue(mPhoneUT.isPhoneTypeGsm()); 151 Intent intent = new Intent(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED); 152 mContext.sendBroadcast(intent); 153 waitForMs(50); 154 assertTrue(mPhoneUT.isPhoneTypeCdmaLte()); 155 } 156 157 @Test 158 @SmallTest 159 public void testGetServiceState() { 160 ServiceState serviceState = new ServiceState(); 161 mSST.mSS = serviceState; 162 assertEquals(serviceState, mPhoneUT.getServiceState()); 163 } 164 165 @Test 166 @SmallTest 167 public void testGetCellLocation() { 168 // GSM 169 CellLocation cellLocation = new GsmCellLocation(); 170 doReturn(cellLocation).when(mSST).getCellLocation(); 171 assertEquals(cellLocation, mPhoneUT.getCellLocation()); 172 173 // Switch to CDMA 174 switchToCdma(); 175 176 CdmaCellLocation cdmaCellLocation = new CdmaCellLocation(); 177 cdmaCellLocation.setCellLocationData(0, 0, 0, 0, 0); 178 mSST.mCellLoc = cdmaCellLocation; 179 180 /* 181 LOCATION_MODE is a special case in SettingsProvider. Adding the special handling in mock 182 content provider is probably not worth the effort; it will also tightly couple tests with 183 SettingsProvider implementation. 184 // LOCATION_MODE_ON 185 Settings.Secure.putInt(mContext.getContentResolver(), 186 Settings.Secure.LOCATION_MODE, Settings.Secure.LOCATION_MODE_HIGH_ACCURACY); 187 waitForMs(50); 188 CdmaCellLocation actualCellLocation = (CdmaCellLocation) mPhoneUT.getCellLocation(); 189 assertEquals(0, actualCellLocation.getBaseStationLatitude()); 190 assertEquals(0, actualCellLocation.getBaseStationLongitude()); 191 192 // LOCATION_MODE_OFF 193 Settings.Secure.putInt(TestApplication.getAppContext().getContentResolver(), 194 Settings.Secure.LOCATION_MODE, Settings.Secure.LOCATION_MODE_OFF); 195 waitForMs(50); 196 */ 197 198 CdmaCellLocation actualCellLocation = (CdmaCellLocation) mPhoneUT.getCellLocation(); 199 assertEquals(CdmaCellLocation.INVALID_LAT_LONG, 200 actualCellLocation.getBaseStationLatitude()); 201 assertEquals(CdmaCellLocation.INVALID_LAT_LONG, 202 actualCellLocation.getBaseStationLongitude()); 203 } 204 205 @Test 206 @SmallTest 207 public void testGetPhoneType() { 208 assertEquals(PhoneConstants.PHONE_TYPE_GSM, mPhoneUT.getPhoneType()); 209 210 // Switch to CDMA 211 switchToCdma(); 212 213 assertEquals(PhoneConstants.PHONE_TYPE_CDMA, mPhoneUT.getPhoneType()); 214 } 215 216 @Test 217 @SmallTest 218 public void testGetDataConnectionState() { 219 // There are several cases possible. Testing few of them for now. 220 // 1. GSM, getCurrentDataConnectionState != STATE_IN_SERVICE, apn != APN_TYPE_EMERGENCY 221 doReturn(ServiceState.STATE_OUT_OF_SERVICE).when(mSST).getCurrentDataConnectionState(); 222 assertEquals(PhoneConstants.DataState.DISCONNECTED, mPhoneUT.getDataConnectionState( 223 PhoneConstants.APN_TYPE_ALL)); 224 225 // 2. GSM, getCurrentDataConnectionState != STATE_IN_SERVICE, apn = APN_TYPE_EMERGENCY, apn 226 // not enabled and not active 227 assertEquals(PhoneConstants.DataState.DISCONNECTED, mPhoneUT.getDataConnectionState( 228 PhoneConstants.APN_TYPE_EMERGENCY)); 229 230 // 3. GSM, getCurrentDataConnectionState != STATE_IN_SERVICE, apn = APN_TYPE_EMERGENCY, 231 // APN enabled, active and CONNECTED, callTracker state = idle 232 doReturn(true).when(mDcTracker).isApnTypeEnabled(PhoneConstants.APN_TYPE_EMERGENCY); 233 doReturn(true).when(mDcTracker).isApnTypeActive(PhoneConstants.APN_TYPE_EMERGENCY); 234 doReturn(DctConstants.State.CONNECTED).when(mDcTracker).getState( 235 PhoneConstants.APN_TYPE_EMERGENCY); 236 mCT.mState = PhoneConstants.State.IDLE; 237 assertEquals(PhoneConstants.DataState.CONNECTED, mPhoneUT.getDataConnectionState( 238 PhoneConstants.APN_TYPE_EMERGENCY)); 239 240 // 3. GSM, getCurrentDataConnectionState != STATE_IN_SERVICE, apn = APN_TYPE_EMERGENCY, 241 // APN enabled and CONNECTED, callTracker state != idle, !isConcurrentVoiceAndDataAllowed 242 mCT.mState = PhoneConstants.State.RINGING; 243 doReturn(false).when(mSST).isConcurrentVoiceAndDataAllowed(); 244 assertEquals(PhoneConstants.DataState.SUSPENDED, mPhoneUT.getDataConnectionState( 245 PhoneConstants.APN_TYPE_EMERGENCY)); 246 } 247 248 @Test 249 @SmallTest 250 public void testHandleInCallMmiCommands() { 251 try { 252 // Switch to CDMA 253 switchToCdma(); 254 255 assertFalse(mPhoneUT.handleInCallMmiCommands("0")); 256 257 // Switch to GSM 258 switchToGsm(); 259 260 mCT.mForegroundCall = mGsmCdmaCall; 261 mCT.mBackgroundCall = mGsmCdmaCall; 262 mCT.mRingingCall = mGsmCdmaCall; 263 doReturn(GsmCdmaCall.State.IDLE).when(mGsmCdmaCall).getState(); 264 265 // !isInCall 266 assertFalse(mPhoneUT.handleInCallMmiCommands("0")); 267 268 // isInCall 269 doReturn(GsmCdmaCall.State.ACTIVE).when(mGsmCdmaCall).getState(); 270 assertTrue(mPhoneUT.handleInCallMmiCommands("0")); 271 272 // empty dialString 273 assertFalse(mPhoneUT.handleInCallMmiCommands("")); 274 assertFalse(mPhoneUT.handleInCallMmiCommands(null)); 275 276 } catch (Exception e) { 277 fail(e.toString()); 278 } 279 } 280 281 @Test 282 @SmallTest 283 public void testDial() { 284 try { 285 mSST.mSS = mServiceState; 286 doReturn(ServiceState.STATE_IN_SERVICE).when(mServiceState).getState(); 287 288 mCT.mForegroundCall = mGsmCdmaCall; 289 mCT.mBackgroundCall = mGsmCdmaCall; 290 mCT.mRingingCall = mGsmCdmaCall; 291 doReturn(GsmCdmaCall.State.IDLE).when(mGsmCdmaCall).getState(); 292 293 Connection connection = mPhoneUT.dial("1234567890", 0); 294 verify(mCT).dial("1234567890", null, null); 295 } catch (CallStateException e) { 296 fail(); 297 } 298 } 299 300 @Test 301 @SmallTest 302 public void testHandlePinMmi() { 303 assertFalse(mPhoneUT.handlePinMmi("1234567890")); 304 } 305 306 @Test 307 @SmallTest 308 public void testSendBurstDtmf() { 309 //Should do nothing for GSM 310 mPhoneUT.sendBurstDtmf("1234567890", 0, 0, null); 311 verify(mSimulatedCommandsVerifier, times(0)).sendBurstDtmf(anyString(), anyInt(), anyInt(), 312 any(Message.class)); 313 314 switchToCdma(); 315 //invalid character 316 mPhoneUT.sendBurstDtmf("12345a67890", 0, 0, null); 317 verify(mSimulatedCommandsVerifier, times(0)).sendBurstDtmf(anyString(), anyInt(), anyInt(), 318 any(Message.class)); 319 320 //state IDLE 321 mCT.mState = PhoneConstants.State.IDLE; 322 mPhoneUT.sendBurstDtmf("1234567890", 0, 0, null); 323 verify(mSimulatedCommandsVerifier, times(0)).sendBurstDtmf(anyString(), anyInt(), anyInt(), 324 any(Message.class)); 325 326 //state RINGING 327 mCT.mState = PhoneConstants.State.RINGING; 328 mPhoneUT.sendBurstDtmf("1234567890", 0, 0, null); 329 verify(mSimulatedCommandsVerifier, times(0)).sendBurstDtmf(anyString(), anyInt(), anyInt(), 330 any(Message.class)); 331 332 mCT.mState = PhoneConstants.State.OFFHOOK; 333 mPhoneUT.sendBurstDtmf("1234567890", 0, 0, null); 334 verify(mSimulatedCommandsVerifier).sendBurstDtmf("1234567890", 0, 0, null); 335 } 336 337 @Test 338 @SmallTest 339 public void testVoiceMailNumberGsm() { 340 String voiceMailNumber = "1234567890"; 341 // first test for GSM 342 assertEquals(PhoneConstants.PHONE_TYPE_GSM, mPhoneUT.getPhoneType()); 343 344 // no resource or sharedPreference set -- should be null 345 assertEquals(null, mPhoneUT.getVoiceMailNumber()); 346 347 // voicemail number from config 348 mContextFixture.putStringArrayResource( 349 com.android.internal.R.array.config_default_vm_number, 350 new String[]{voiceMailNumber}); 351 assertEquals(voiceMailNumber, mPhoneUT.getVoiceMailNumber()); 352 353 // voicemail number that is explicitly set 354 voiceMailNumber = "1234567891"; 355 mPhoneUT.setVoiceMailNumber("alphaTag", voiceMailNumber, null); 356 verify(mSimRecords).setVoiceMailNumber(eq("alphaTag"), eq(voiceMailNumber), 357 any(Message.class)); 358 359 doReturn(voiceMailNumber).when(mSimRecords).getVoiceMailNumber(); 360 assertEquals(voiceMailNumber, mPhoneUT.getVoiceMailNumber()); 361 } 362 363 @Test 364 @SmallTest 365 public void testVoiceMailNumberCdma() { 366 switchToCdma(); 367 String voiceMailNumber = "1234567890"; 368 369 // no resource or sharedPreference set -- should be *86 370 assertEquals("*86", mPhoneUT.getVoiceMailNumber()); 371 372 // config_telephony_use_own_number_for_voicemail 373 mContextFixture.putBooleanResource( 374 com.android.internal.R.bool.config_telephony_use_own_number_for_voicemail, true); 375 doReturn(voiceMailNumber).when(mSST).getMdnNumber(); 376 assertEquals(voiceMailNumber, mPhoneUT.getVoiceMailNumber()); 377 378 // voicemail number from config 379 voiceMailNumber = "1234567891"; 380 mContextFixture.putStringArrayResource( 381 com.android.internal.R.array.config_default_vm_number, 382 new String[]{voiceMailNumber}); 383 assertEquals(voiceMailNumber, mPhoneUT.getVoiceMailNumber()); 384 385 // voicemail number from sharedPreference 386 mPhoneUT.setVoiceMailNumber("alphaTag", voiceMailNumber, null); 387 ArgumentCaptor<Message> messageArgumentCaptor = ArgumentCaptor.forClass(Message.class); 388 verify(mRuimRecords).setVoiceMailNumber(eq("alphaTag"), eq(voiceMailNumber), 389 messageArgumentCaptor.capture()); 390 391 Message msg = messageArgumentCaptor.getValue(); 392 AsyncResult.forMessage(msg).exception = 393 new IccException("setVoiceMailNumber not implemented"); 394 msg.sendToTarget(); 395 waitForMs(50); 396 397 assertEquals(voiceMailNumber, mPhoneUT.getVoiceMailNumber()); 398 } 399 400 @Test 401 @SmallTest 402 public void testVoiceMailCount() { 403 // initial value 404 assertEquals(0, mPhoneUT.getVoiceMessageCount()); 405 406 // old sharedPreference set (testing upgrade from M to N scenario) 407 SharedPreferences sharedPreferences = 408 PreferenceManager.getDefaultSharedPreferences(mContext); 409 SharedPreferences.Editor editor = sharedPreferences.edit(); 410 String imsi = "1234567890"; 411 editor.putString("vm_id_key", imsi); 412 editor.putInt("vm_count_key", 5); 413 editor.apply(); 414 doReturn(imsi).when(mSimRecords).getIMSI(); 415 416 // updateVoiceMail should read old shared pref and delete it and new sharedPref should be 417 // updated now 418 doReturn(-1).when(mSimRecords).getVoiceMessageCount(); 419 mPhoneUT.updateVoiceMail(); 420 assertEquals(5, mPhoneUT.getVoiceMessageCount()); 421 assertEquals(null, sharedPreferences.getString("vm_id_key", null)); 422 assertEquals(5, sharedPreferences.getInt("vm_count_key" + mPhoneUT.getSubId(), 0)); 423 424 // sim records return count as 0, that overrides shared preference 425 doReturn(0).when(mSimRecords).getVoiceMessageCount(); 426 mPhoneUT.updateVoiceMail(); 427 assertEquals(0, mPhoneUT.getVoiceMessageCount()); 428 429 // sim records return count as -1 430 doReturn(-1).when(mSimRecords).getVoiceMessageCount(); 431 mPhoneUT.updateVoiceMail(); 432 assertEquals(-1, mPhoneUT.getVoiceMessageCount()); 433 434 // sim records return count as -1 and sharedPreference says 0 435 mPhoneUT.setVoiceMessageCount(0); 436 mPhoneUT.updateVoiceMail(); 437 assertEquals(-1, mPhoneUT.getVoiceMessageCount()); 438 439 // sim records return count as -1 and sharedPreference says 2 440 mPhoneUT.setVoiceMessageCount(2); 441 mPhoneUT.updateVoiceMail(); 442 assertEquals(2, mPhoneUT.getVoiceMessageCount()); 443 444 // sim records return count as 0 and sharedPreference says 2 445 doReturn(0).when(mSimRecords).getVoiceMessageCount(); 446 mPhoneUT.setVoiceMessageCount(2); 447 mPhoneUT.updateVoiceMail(); 448 assertEquals(0, mPhoneUT.getVoiceMessageCount()); 449 } 450 451 @Test 452 @SmallTest 453 public void testGetCallForwardingOption() { 454 // invalid reason (-1) 455 mPhoneUT.getCallForwardingOption(-1, null); 456 verify(mSimulatedCommandsVerifier, times(0)).queryCallForwardStatus( 457 anyInt(), anyInt(), anyString(), any(Message.class)); 458 459 // valid reason 460 String imsi = "1234567890"; 461 doReturn(imsi).when(mSimRecords).getIMSI(); 462 mPhoneUT.getCallForwardingOption(CF_REASON_UNCONDITIONAL, null); 463 verify(mSimulatedCommandsVerifier).queryCallForwardStatus( 464 eq(CF_REASON_UNCONDITIONAL), anyInt(), anyString(), any(Message.class)); 465 waitForMs(50); 466 verify(mSimRecords).setVoiceCallForwardingFlag(anyInt(), anyBoolean(), anyString()); 467 468 // should have updated shared preferences 469 SharedPreferences sharedPreferences = PreferenceManager. 470 getDefaultSharedPreferences(mContext); 471 assertEquals(IccRecords.CALL_FORWARDING_STATUS_DISABLED, 472 sharedPreferences.getInt(Phone.CF_STATUS + mPhoneUT.getSubId(), 473 IccRecords.CALL_FORWARDING_STATUS_ENABLED)); 474 475 // clean up 476 SharedPreferences.Editor editor = sharedPreferences.edit(); 477 editor.remove(Phone.CF_STATUS + mPhoneUT.getSubId()); 478 editor.apply(); 479 } 480 481 @Test 482 @SmallTest 483 public void testSetCallForwardingOption() { 484 String cfNumber = "1234567890"; 485 486 // invalid action 487 mPhoneUT.setCallForwardingOption(-1, CF_REASON_UNCONDITIONAL, 488 cfNumber, 0, null); 489 verify(mSimulatedCommandsVerifier, times(0)).setCallForward(anyInt(), anyInt(), anyInt(), 490 anyString(), anyInt(), any(Message.class)); 491 492 // valid action 493 mPhoneUT.setCallForwardingOption(CF_ACTION_ENABLE, CF_REASON_UNCONDITIONAL, cfNumber, 0, 494 null); 495 verify(mSimulatedCommandsVerifier).setCallForward(eq(CF_ACTION_ENABLE), 496 eq(CF_REASON_UNCONDITIONAL), anyInt(), eq(cfNumber), eq(0), any(Message.class)); 497 waitForMs(50); 498 verify(mSimRecords).setVoiceCallForwardingFlag(anyInt(), anyBoolean(), eq(cfNumber)); 499 } 500 501 /** 502 * GsmCdmaPhone handles a lot of messages. This function verifies behavior for messages that are 503 * received when obj is created and that are received on phone type switch 504 */ 505 @Test 506 @SmallTest 507 public void testHandleInitialMessages() { 508 // EVENT_RADIO_AVAILABLE 509 verify(mSimulatedCommandsVerifier).getBasebandVersion(any(Message.class)); 510 verify(mSimulatedCommandsVerifier).getIMEI(any(Message.class)); 511 verify(mSimulatedCommandsVerifier).getIMEISV(any(Message.class)); 512 verify(mSimulatedCommandsVerifier).getRadioCapability(any(Message.class)); 513 // once as part of constructor, and once on radio available 514 verify(mSimulatedCommandsVerifier, times(2)).startLceService(anyInt(), anyBoolean(), 515 any(Message.class)); 516 517 // EVENT_RADIO_ON 518 verify(mSimulatedCommandsVerifier).getVoiceRadioTechnology(any(Message.class)); 519 verify(mSimulatedCommandsVerifier).setPreferredNetworkType( 520 eq(RILConstants.NETWORK_MODE_LTE_CDMA_EVDO_GSM_WCDMA), any(Message.class)); 521 522 // verify responses for above requests: 523 // baseband version 524 verify(mTelephonyManager).setBasebandVersionForPhone(eq(mPhoneUT.getPhoneId()), 525 anyString()); 526 // IMEI 527 assertEquals(SimulatedCommands.FAKE_IMEI, mPhoneUT.getImei()); 528 // IMEISV 529 assertEquals(SimulatedCommands.FAKE_IMEISV, mPhoneUT.getDeviceSvn()); 530 // radio capability 531 verify(mSimulatedCommandsVerifier).getNetworkSelectionMode(any(Message.class)); 532 533 switchToCdma(); // this leads to eventRadioAvailable handling on cdma 534 535 // EVENT_RADIO_AVAILABLE 536 verify(mSimulatedCommandsVerifier, times(2)).getBasebandVersion(any(Message.class)); 537 verify(mSimulatedCommandsVerifier).getDeviceIdentity(any(Message.class)); 538 verify(mSimulatedCommandsVerifier, times(3)).startLceService(anyInt(), anyBoolean(), 539 any(Message.class)); 540 541 // EVENT_RADIO_ON 542 verify(mSimulatedCommandsVerifier, times(2)).getVoiceRadioTechnology(any(Message.class)); 543 // once on radio on, and once on get baseband version 544 verify(mSimulatedCommandsVerifier, times(3)).setPreferredNetworkType( 545 eq(RILConstants.NETWORK_MODE_LTE_CDMA_EVDO_GSM_WCDMA), any(Message.class)); 546 547 // verify responses for above requests: 548 // baseband version 549 verify(mTelephonyManager, times(2)).setBasebandVersionForPhone(eq(mPhoneUT.getPhoneId()), 550 anyString()); 551 // device identity 552 assertEquals(SimulatedCommands.FAKE_IMEI, mPhoneUT.getImei()); 553 assertEquals(SimulatedCommands.FAKE_IMEISV, mPhoneUT.getDeviceSvn()); 554 assertEquals(SimulatedCommands.FAKE_ESN, mPhoneUT.getEsn()); 555 assertEquals(SimulatedCommands.FAKE_MEID, mPhoneUT.getMeid()); 556 } 557 558 @Test 559 @SmallTest 560 public void testEmergencyCallbackMessages() { 561 verify(mSimulatedCommandsVerifier).setEmergencyCallbackMode(eq(mPhoneUT), anyInt(), 562 anyObject()); 563 verify(mSimulatedCommandsVerifier).registerForExitEmergencyCallbackMode(eq(mPhoneUT), 564 anyInt(), anyObject()); 565 566 // verify handling of emergency callback mode 567 mSimulatedCommands.notifyEmergencyCallbackMode(); 568 waitForMs(50); 569 570 // verify ACTION_EMERGENCY_CALLBACK_MODE_CHANGED 571 ArgumentCaptor<Intent> intentArgumentCaptor = ArgumentCaptor.forClass(Intent.class); 572 try { 573 verify(mIActivityManager, atLeast(1)).broadcastIntent(eq((IApplicationThread)null), 574 intentArgumentCaptor.capture(), 575 eq((String)null), 576 eq((IIntentReceiver)null), 577 eq(Activity.RESULT_OK), 578 eq((String)null), 579 eq((Bundle)null), 580 eq((String[])null), 581 anyInt(), 582 eq((Bundle)null), 583 eq(false), 584 eq(true), 585 anyInt()); 586 } catch(Exception e) { 587 fail("Unexpected exception: " + e.getStackTrace()); 588 } 589 590 Intent intent = intentArgumentCaptor.getValue(); 591 assertEquals(TelephonyIntents.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED, intent.getAction()); 592 assertEquals(true, intent.getBooleanExtra(PhoneConstants.PHONE_IN_ECM_STATE, false)); 593 594 // verify that wakeLock is acquired in ECM 595 assertEquals(true, mPhoneUT.getWakeLock().isHeld()); 596 597 mPhoneUT.setOnEcbModeExitResponse(mTestHandler, EVENT_EMERGENCY_CALLBACK_MODE_EXIT, null); 598 mPhoneUT.registerForEmergencyCallToggle(mTestHandler, EVENT_EMERGENCY_CALL_TOGGLE, null); 599 600 // verify handling of emergency callback mode exit 601 mSimulatedCommands.notifyExitEmergencyCallbackMode(); 602 waitForMs(50); 603 604 // verify ACTION_EMERGENCY_CALLBACK_MODE_CHANGED 605 try { 606 verify(mIActivityManager, atLeast(2)).broadcastIntent(eq((IApplicationThread)null), 607 intentArgumentCaptor.capture(), 608 eq((String)null), 609 eq((IIntentReceiver)null), 610 eq(Activity.RESULT_OK), 611 eq((String)null), 612 eq((Bundle)null), 613 eq((String[])null), 614 anyInt(), 615 eq((Bundle)null), 616 eq(false), 617 eq(true), 618 anyInt()); 619 } catch(Exception e) { 620 fail("Unexpected exception: " + e.getStackTrace()); 621 } 622 623 intent = intentArgumentCaptor.getValue(); 624 assertEquals(TelephonyIntents.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED, intent.getAction()); 625 assertEquals(false, intent.getBooleanExtra(PhoneConstants.PHONE_IN_ECM_STATE, true)); 626 627 ArgumentCaptor<Message> messageArgumentCaptor = ArgumentCaptor.forClass(Message.class); 628 629 // verify EcmExitRespRegistrant and mEmergencyCallToggledRegistrants are notified 630 verify(mTestHandler, times(2)).sendMessageAtTime(messageArgumentCaptor.capture(), 631 anyLong()); 632 List<Message> msgList = messageArgumentCaptor.getAllValues(); 633 assertEquals(EVENT_EMERGENCY_CALLBACK_MODE_EXIT, msgList.get(0).what); 634 assertEquals(EVENT_EMERGENCY_CALL_TOGGLE, msgList.get(1).what); 635 636 // verify setInternalDataEnabled 637 verify(mDcTracker).setInternalDataEnabled(true); 638 639 // verify wakeLock released 640 assertEquals(false, mPhoneUT.getWakeLock().isHeld()); 641 } 642 643 @Test 644 @SmallTest 645 public void testCallForwardingIndicator() { 646 doReturn(IccRecords.CALL_FORWARDING_STATUS_UNKNOWN).when(mSimRecords). 647 getVoiceCallForwardingFlag(); 648 649 // invalid subId 650 doReturn(SubscriptionManager.INVALID_SUBSCRIPTION_ID).when(mSubscriptionController). 651 getSubIdUsingPhoneId(anyInt()); 652 assertEquals(false, mPhoneUT.getCallForwardingIndicator()); 653 654 // valid subId, sharedPreference not present 655 int subId1 = 0; 656 int subId2 = 1; 657 doReturn(subId1).when(mSubscriptionController).getSubIdUsingPhoneId(anyInt()); 658 assertEquals(false, mPhoneUT.getCallForwardingIndicator()); 659 660 // old sharedPreference present 661 String imsi = "1234"; 662 doReturn(imsi).when(mSimRecords).getIMSI(); 663 SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(mContext); 664 SharedPreferences.Editor editor = sp.edit(); 665 editor.putString(Phone.CF_ID, imsi); 666 editor.putInt(Phone.CF_STATUS, IccRecords.CALL_FORWARDING_STATUS_ENABLED); 667 editor.apply(); 668 assertEquals(true, mPhoneUT.getCallForwardingIndicator()); 669 670 // old sharedPreference should be removed now 671 assertEquals(null, sp.getString(Phone.CF_ID, null)); 672 assertEquals(IccRecords.CALL_FORWARDING_STATUS_UNKNOWN, 673 sp.getInt(Phone.CF_ID, IccRecords.CALL_FORWARDING_STATUS_UNKNOWN)); 674 675 // now verify value from new sharedPreference 676 assertEquals(true, mPhoneUT.getCallForwardingIndicator()); 677 678 // check for another subId 679 doReturn(subId2).when(mSubscriptionController).getSubIdUsingPhoneId(anyInt()); 680 assertEquals(false, mPhoneUT.getCallForwardingIndicator()); 681 682 // set value for the new subId in sharedPreference 683 editor.putInt(Phone.CF_STATUS + subId2, IccRecords.CALL_FORWARDING_STATUS_ENABLED); 684 editor.apply(); 685 assertEquals(true, mPhoneUT.getCallForwardingIndicator()); 686 687 // switching back to previous subId, stored value should still be available 688 doReturn(subId1).when(mSubscriptionController).getSubIdUsingPhoneId(anyInt()); 689 assertEquals(true, mPhoneUT.getCallForwardingIndicator()); 690 691 // cleanup 692 editor.remove(Phone.CF_STATUS + subId1); 693 editor.remove(Phone.CF_STATUS + subId2); 694 editor.apply(); 695 } 696} 697