1 /* 2 * Copyright (C) 2021 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 android.telephony.ims.cts; 18 19 import static junit.framework.Assert.assertNotNull; 20 import static junit.framework.Assert.assertTrue; 21 22 import static org.junit.Assert.assertEquals; 23 import static org.junit.Assert.assertNotEquals; 24 import static org.junit.Assert.fail; 25 26 import android.annotation.NonNull; 27 import android.content.Context; 28 import android.media.AudioManager; 29 import android.net.Uri; 30 import android.os.Bundle; 31 import android.telecom.Call; 32 import android.telecom.PhoneAccount; 33 import android.telecom.TelecomManager; 34 import android.telephony.AccessNetworkConstants; 35 import android.telephony.CallState; 36 import android.telephony.PreciseCallState; 37 import android.telephony.SubscriptionManager; 38 import android.telephony.TelephonyCallback; 39 import android.telephony.TelephonyManager; 40 import android.telephony.cts.InCallServiceStateValidator; 41 import android.telephony.ims.ImsCallProfile; 42 import android.telephony.ims.ImsCallSessionListener; 43 import android.telephony.ims.ImsStreamMediaProfile; 44 import android.telephony.ims.MediaQualityStatus; 45 import android.telephony.ims.feature.MmTelFeature; 46 import android.util.Log; 47 48 import androidx.test.ext.junit.runners.AndroidJUnit4; 49 import androidx.test.platform.app.InstrumentationRegistry; 50 51 import com.android.compatibility.common.util.ShellIdentityUtils; 52 53 import org.junit.After; 54 import org.junit.AfterClass; 55 import org.junit.Before; 56 import org.junit.BeforeClass; 57 import org.junit.Test; 58 import org.junit.runner.RunWith; 59 60 import java.util.ArrayList; 61 import java.util.List; 62 import java.util.Objects; 63 import java.util.concurrent.CountDownLatch; 64 import java.util.concurrent.LinkedBlockingQueue; 65 import java.util.concurrent.TimeUnit; 66 67 /** CTS tests for ImsCall . */ 68 @RunWith(AndroidJUnit4.class) 69 public class ImsCallingTest extends ImsCallingBase { 70 71 protected static final String LOG_TAG = "CtsImsCallingTest"; 72 73 private Call mCall1 = null; 74 private Call mCall2 = null; 75 private Call mCall3 = null; 76 private Call mConferenceCall = null; 77 private TestImsCallSessionImpl mCallSession1 = null; 78 private TestImsCallSessionImpl mCallSession2 = null; 79 private TestImsCallSessionImpl mCallSession3 = null; 80 private TestImsCallSessionImpl mConfCallSession = null; 81 82 // the timeout to wait result in milliseconds 83 private static final int WAIT_UPDATE_TIMEOUT_MS = 3000; 84 85 private static TelephonyManager sTelephonyManager; 86 87 static { initializeLatches()88 initializeLatches(); 89 } 90 91 @BeforeClass beforeAllTests()92 public static void beforeAllTests() throws Exception { 93 if (!ImsUtils.shouldTestImsCall()) { 94 return; 95 } 96 97 sTelephonyManager = 98 (TelephonyManager) getContext().getSystemService(Context.TELEPHONY_SERVICE); 99 100 sTestSub = ImsUtils.getPreferredActiveSubId(); 101 sTestSlot = SubscriptionManager.getSlotIndex(sTestSub); 102 if (!isSimReady()) { 103 return; 104 } 105 106 beforeAllTestsBase(); 107 } 108 isSimReady()109 private static boolean isSimReady() { 110 if (sTelephonyManager.getSimState(sTestSlot) != TelephonyManager.SIM_STATE_READY) { 111 Log.d(LOG_TAG, "sim is not present"); 112 return false; 113 } 114 return true; 115 } 116 117 @AfterClass afterAllTests()118 public static void afterAllTests() throws Exception { 119 if (!ImsUtils.shouldTestImsCall()) { 120 return; 121 } 122 123 if (!isSimReady()) { 124 return; 125 } 126 127 afterAllTestsBase(); 128 } 129 130 @Before beforeTest()131 public void beforeTest() throws Exception { 132 if (!ImsUtils.shouldTestImsCall()) { 133 return; 134 } 135 136 if (!isSimReady()) { 137 fail("This test requires that there is a SIM in the device!"); 138 } 139 140 // Correctness check: ensure that the subscription hasn't changed between tests. 141 int subId = SubscriptionManager.getSubscriptionId(sTestSlot); 142 if (subId != sTestSub) { 143 fail("The found subId " + subId + " does not match the test sub id " + sTestSub); 144 } 145 } 146 147 @After afterTest()148 public void afterTest() throws Exception { 149 if (!ImsUtils.shouldTestImsCall()) { 150 return; 151 } 152 153 if (!isSimReady()) { 154 return; 155 } 156 157 resetCallSessionObjects(); 158 159 if (!mCalls.isEmpty() && (mCurrentCallId != null)) { 160 Call call = mCalls.get(mCurrentCallId); 161 call.disconnect(); 162 } 163 164 //Set the untracked CountDownLatches which are reseted in ServiceCallBack 165 for (int i = 0; i < LATCH_MAX; i++) { 166 sLatches[i] = new CountDownLatch(1); 167 } 168 169 if (sServiceConnector != null && sIsBound) { 170 TestImsService imsService = sServiceConnector.getCarrierService(); 171 sServiceConnector.disconnectCarrierImsService(); 172 sIsBound = false; 173 imsService.waitForExecutorFinish(); 174 } 175 } 176 177 @Test testOutGoingCall()178 public void testOutGoingCall() throws Exception { 179 if (!ImsUtils.shouldTestImsCall()) { 180 return; 181 } 182 183 bindImsService(); 184 mServiceCallBack = new ServiceCallBack(); 185 InCallServiceStateValidator.setCallbacks(mServiceCallBack); 186 187 TelecomManager telecomManager = (TelecomManager) InstrumentationRegistry 188 .getInstrumentation().getContext().getSystemService(Context.TELECOM_SERVICE); 189 190 final Uri imsUri = Uri.fromParts(PhoneAccount.SCHEME_TEL, String.valueOf(++sCounter), null); 191 Bundle extras = new Bundle(); 192 193 // Place outgoing call 194 telecomManager.placeCall(imsUri, extras); 195 assertTrue(callingTestLatchCountdown(LATCH_IS_ON_CALL_ADDED, WAIT_FOR_CALL_STATE)); 196 197 Call call = getCall(mCurrentCallId); 198 waitForCallSessionToNotBe(null); 199 assertTrue(callingTestLatchCountdown(LATCH_IS_CALL_DIALING, WAIT_FOR_CALL_STATE)); 200 201 TestImsCallSessionImpl callSession = sServiceConnector.getCarrierService().getMmTelFeature() 202 .getImsCallsession(); 203 204 isCallActive(call, callSession); 205 call.disconnect(); 206 207 assertTrue(callingTestLatchCountdown(LATCH_IS_CALL_DISCONNECTING, WAIT_FOR_CALL_STATE)); 208 isCallDisconnected(call, callSession); 209 assertTrue(callingTestLatchCountdown(LATCH_IS_ON_CALL_REMOVED, WAIT_FOR_CALL_STATE)); 210 waitForUnboundService(); 211 } 212 213 @Test testOutGoingCallStartFailed()214 public void testOutGoingCallStartFailed() throws Exception { 215 if (!ImsUtils.shouldTestImsCall()) { 216 return; 217 } 218 219 bindImsService(); 220 mServiceCallBack = new ServiceCallBack(); 221 InCallServiceStateValidator.setCallbacks(mServiceCallBack); 222 223 TelecomManager telecomManager = (TelecomManager) InstrumentationRegistry 224 .getInstrumentation().getContext().getSystemService(Context.TELECOM_SERVICE); 225 226 final Uri imsUri = Uri.fromParts(PhoneAccount.SCHEME_TEL, String.valueOf(++sCounter), null); 227 Bundle extras = new Bundle(); 228 229 // Place outgoing call 230 telecomManager.placeCall(imsUri, extras); 231 assertTrue(callingTestLatchCountdown(LATCH_IS_ON_CALL_ADDED, WAIT_FOR_CALL_STATE)); 232 233 Call call = getCall(mCurrentCallId); 234 235 waitForCallSessionToNotBe(null); 236 TestImsCallSessionImpl callSession = 237 sServiceConnector.getCarrierService().getMmTelFeature().getImsCallsession(); 238 assertNotNull("Unable to get callSession, its null", callSession); 239 callSession.addTestType(TestImsCallSessionImpl.TEST_TYPE_MO_FAILED); 240 241 assertTrue(callingTestLatchCountdown(LATCH_IS_CALL_DIALING, WAIT_FOR_CALL_STATE)); 242 isCallDisconnected(call, callSession); 243 assertTrue(callingTestLatchCountdown(LATCH_IS_ON_CALL_REMOVED, WAIT_FOR_CALL_STATE)); 244 waitForUnboundService(); 245 } 246 247 @Test testIncomingCall()248 public void testIncomingCall() throws Exception { 249 if (!ImsUtils.shouldTestImsCall()) { 250 return; 251 } 252 bindImsService(); 253 mServiceCallBack = new ServiceCallBack(); 254 InCallServiceStateValidator.setCallbacks(mServiceCallBack); 255 256 Bundle extras = new Bundle(); 257 sServiceConnector.getCarrierService().getMmTelFeature().onIncomingCallReceived(extras); 258 assertTrue(callingTestLatchCountdown(LATCH_IS_ON_CALL_ADDED, WAIT_FOR_CALL_STATE)); 259 260 Call call = getCall(mCurrentCallId); 261 if (call.getDetails().getState() == Call.STATE_RINGING) { 262 call.answer(0); 263 } 264 265 waitForCallSessionToNotBe(null); 266 TestImsCallSessionImpl callSession = 267 sServiceConnector.getCarrierService().getMmTelFeature().getImsCallsession(); 268 269 isCallActive(call, callSession); 270 callSession.terminateIncomingCall(); 271 272 isCallDisconnected(call, callSession); 273 assertTrue(callingTestLatchCountdown(LATCH_IS_ON_CALL_REMOVED, WAIT_FOR_CALL_STATE)); 274 waitForUnboundService(); 275 } 276 277 @Test testIncomingCallReturnListener()278 public void testIncomingCallReturnListener() throws Exception { 279 if (!ImsUtils.shouldTestImsCall()) { 280 return; 281 } 282 bindImsService(); 283 mServiceCallBack = new ServiceCallBack(); 284 InCallServiceStateValidator.setCallbacks(mServiceCallBack); 285 286 Bundle extras = new Bundle(); 287 ImsCallSessionListener isl = sServiceConnector.getCarrierService().getMmTelFeature() 288 .onIncomingCallReceivedReturnListener(extras); 289 assertTrue("failed to get ImsCallSessionListener..", Objects.nonNull(isl)); 290 assertTrue(callingTestLatchCountdown(LATCH_IS_ON_CALL_ADDED, WAIT_FOR_CALL_STATE)); 291 292 Call call = getCall(mCurrentCallId); 293 if (call.getDetails().getState() == Call.STATE_RINGING) { 294 call.answer(0); 295 } 296 297 waitForCallSessionToNotBe(null); 298 TestImsCallSessionImpl callSession = 299 sServiceConnector.getCarrierService().getMmTelFeature().getImsCallsession(); 300 301 isCallActive(call, callSession); 302 callSession.terminateIncomingCall(); 303 304 isCallDisconnected(call, callSession); 305 assertTrue(callingTestLatchCountdown(LATCH_IS_ON_CALL_REMOVED, WAIT_FOR_CALL_STATE)); 306 waitForUnboundService(); 307 } 308 309 @Test testIncomingCallReject()310 public void testIncomingCallReject() throws Exception { 311 if (!ImsUtils.shouldTestImsCall()) { 312 return; 313 } 314 bindImsService(); 315 mServiceCallBack = new ServiceCallBack(); 316 InCallServiceStateValidator.setCallbacks(mServiceCallBack); 317 318 Bundle extras = new Bundle(); 319 sServiceConnector.getCarrierService().getMmTelFeature().onIncomingCallReceived(extras); 320 assertTrue(callingTestLatchCountdown(LATCH_IS_ON_CALL_ADDED, WAIT_FOR_CALL_STATE)); 321 322 Call call = getCall(mCurrentCallId); 323 if (call.getDetails().getState() == Call.STATE_RINGING) { 324 call.reject(504); 325 } 326 327 waitForCallSessionToNotBe(null); 328 TestImsCallSessionImpl callSession = 329 sServiceConnector.getCarrierService().getMmTelFeature().getImsCallsession(); 330 331 isCallDisconnected(call, callSession); 332 assertTrue(callingTestLatchCountdown(LATCH_IS_ON_CALL_REMOVED, WAIT_FOR_CALL_STATE)); 333 waitForUnboundService(); 334 } 335 336 @Test testOutGoingCallForExecutor()337 public void testOutGoingCallForExecutor() throws Exception { 338 if (!ImsUtils.shouldTestImsCall()) { 339 return; 340 } 341 342 sServiceConnector.setExecutorTestType(true); 343 bindImsService(); 344 345 mServiceCallBack = new ServiceCallBack(); 346 InCallServiceStateValidator.setCallbacks(mServiceCallBack); 347 348 TelecomManager telecomManager = (TelecomManager) InstrumentationRegistry 349 .getInstrumentation().getContext().getSystemService(Context.TELECOM_SERVICE); 350 351 final Uri imsUri = Uri.fromParts(PhoneAccount.SCHEME_TEL, String.valueOf(++sCounter), null); 352 Bundle extras = new Bundle(); 353 354 // Place outgoing call 355 telecomManager.placeCall(imsUri, extras); 356 assertTrue(callingTestLatchCountdown(LATCH_IS_ON_CALL_ADDED, WAIT_FOR_CALL_STATE)); 357 358 Call call = getCall(mCurrentCallId); 359 assertTrue(callingTestLatchCountdown(LATCH_IS_CALL_DIALING, WAIT_FOR_CALL_STATE)); 360 361 waitForCallSessionToNotBe(null); 362 TestImsCallSessionImpl callSession = 363 sServiceConnector.getCarrierService().getMmTelFeature().getImsCallsession(); 364 365 isCallActive(call, callSession); 366 call.disconnect(); 367 368 assertTrue(callingTestLatchCountdown(LATCH_IS_CALL_DISCONNECTING, WAIT_FOR_CALL_STATE)); 369 isCallDisconnected(call, callSession); 370 assertTrue(callingTestLatchCountdown(LATCH_IS_ON_CALL_REMOVED, WAIT_FOR_CALL_STATE)); 371 waitForUnboundService(); 372 } 373 374 @Test testOutGoingCallHoldResume()375 public void testOutGoingCallHoldResume() throws Exception { 376 if (!ImsUtils.shouldTestImsCall()) { 377 return; 378 } 379 380 bindImsService(); 381 mServiceCallBack = new ServiceCallBack(); 382 InCallServiceStateValidator.setCallbacks(mServiceCallBack); 383 384 TelecomManager telecomManager = (TelecomManager) InstrumentationRegistry 385 .getInstrumentation().getContext().getSystemService(Context.TELECOM_SERVICE); 386 387 final Uri imsUri = Uri.fromParts(PhoneAccount.SCHEME_TEL, String.valueOf(++sCounter), null); 388 Bundle extras = new Bundle(); 389 390 // Place outgoing call 391 telecomManager.placeCall(imsUri, extras); 392 assertTrue(callingTestLatchCountdown(LATCH_IS_ON_CALL_ADDED, WAIT_FOR_CALL_STATE)); 393 394 Call call = getCall(mCurrentCallId); 395 assertTrue(callingTestLatchCountdown(LATCH_IS_CALL_DIALING, WAIT_FOR_CALL_STATE)); 396 397 waitForCallSessionToNotBe(null); 398 TestImsCallSessionImpl callSession = 399 sServiceConnector.getCarrierService().getMmTelFeature().getImsCallsession(); 400 401 isCallActive(call, callSession); 402 403 // Put on hold 404 call.hold(); 405 assertTrue(callingTestLatchCountdown(LATCH_IS_CALL_HOLDING, WAIT_FOR_CALL_STATE)); 406 407 ImsUtils.waitInCurrentState(WAIT_IN_CURRENT_STATE); 408 // Put on resume 409 call.unhold(); 410 isCallActive(call, callSession); 411 call.disconnect(); 412 413 assertTrue(callingTestLatchCountdown(LATCH_IS_CALL_DISCONNECTING, WAIT_FOR_CALL_STATE)); 414 isCallDisconnected(call, callSession); 415 assertTrue(callingTestLatchCountdown(LATCH_IS_ON_CALL_REMOVED, WAIT_FOR_CALL_STATE)); 416 waitForUnboundService(); 417 } 418 419 @Test testOutGoingCallHoldFailure()420 public void testOutGoingCallHoldFailure() throws Exception { 421 if (!ImsUtils.shouldTestImsCall()) { 422 return; 423 } 424 425 bindImsService(); 426 mServiceCallBack = new ServiceCallBack(); 427 InCallServiceStateValidator.setCallbacks(mServiceCallBack); 428 429 TelecomManager telecomManager = (TelecomManager) InstrumentationRegistry 430 .getInstrumentation().getContext().getSystemService(Context.TELECOM_SERVICE); 431 432 final Uri imsUri = Uri.fromParts(PhoneAccount.SCHEME_TEL, String.valueOf(++sCounter), null); 433 Bundle extras = new Bundle(); 434 435 // Place outgoing call 436 telecomManager.placeCall(imsUri, extras); 437 assertTrue(callingTestLatchCountdown(LATCH_IS_ON_CALL_ADDED, WAIT_FOR_CALL_STATE)); 438 439 Call call = getCall(mCurrentCallId); 440 assertTrue(callingTestLatchCountdown(LATCH_IS_CALL_DIALING, WAIT_FOR_CALL_STATE)); 441 442 waitForCallSessionToNotBe(null); 443 TestImsCallSessionImpl callSession = 444 sServiceConnector.getCarrierService().getMmTelFeature().getImsCallsession(); 445 446 isCallActive(call, callSession); 447 callSession.addTestType(TestImsCallSessionImpl.TEST_TYPE_HOLD_FAILED); 448 449 ImsUtils.waitInCurrentState(WAIT_IN_CURRENT_STATE); 450 call.hold(); 451 assertTrue("call is not in Active State", (call.getDetails().getState() 452 == call.STATE_ACTIVE)); 453 454 call.disconnect(); 455 456 assertTrue(callingTestLatchCountdown(LATCH_IS_CALL_DISCONNECTING, WAIT_FOR_CALL_STATE)); 457 isCallDisconnected(call, callSession); 458 assertTrue(callingTestLatchCountdown(LATCH_IS_ON_CALL_REMOVED, WAIT_FOR_CALL_STATE)); 459 waitForUnboundService(); 460 } 461 462 @Test testOutGoingCallResumeFailure()463 public void testOutGoingCallResumeFailure() throws Exception { 464 if (!ImsUtils.shouldTestImsCall()) { 465 return; 466 } 467 468 bindImsService(); 469 mServiceCallBack = new ServiceCallBack(); 470 InCallServiceStateValidator.setCallbacks(mServiceCallBack); 471 472 TelecomManager telecomManager = (TelecomManager) InstrumentationRegistry 473 .getInstrumentation().getContext().getSystemService(Context.TELECOM_SERVICE); 474 475 final Uri imsUri = Uri.fromParts(PhoneAccount.SCHEME_TEL, String.valueOf(++sCounter), null); 476 Bundle extras = new Bundle(); 477 478 // Place outgoing call 479 telecomManager.placeCall(imsUri, extras); 480 assertTrue(callingTestLatchCountdown(LATCH_IS_ON_CALL_ADDED, WAIT_FOR_CALL_STATE)); 481 482 Call call = getCall(mCurrentCallId); 483 assertTrue(callingTestLatchCountdown(LATCH_IS_CALL_DIALING, WAIT_FOR_CALL_STATE)); 484 485 waitForCallSessionToNotBe(null); 486 TestImsCallSessionImpl callSession = 487 sServiceConnector.getCarrierService().getMmTelFeature().getImsCallsession(); 488 489 isCallActive(call, callSession); 490 491 // Put on hold 492 call.hold(); 493 assertTrue(callingTestLatchCountdown(LATCH_IS_CALL_HOLDING, WAIT_FOR_CALL_STATE)); 494 495 callSession.addTestType(TestImsCallSessionImpl.TEST_TYPE_RESUME_FAILED); 496 ImsUtils.waitInCurrentState(WAIT_IN_CURRENT_STATE); 497 call.unhold(); 498 assertTrue("Call is not in Hold State", (call.getDetails().getState() 499 == call.STATE_HOLDING)); 500 501 call.disconnect(); 502 503 assertTrue(callingTestLatchCountdown(LATCH_IS_CALL_DISCONNECTING, WAIT_FOR_CALL_STATE)); 504 isCallDisconnected(call, callSession); 505 assertTrue(callingTestLatchCountdown(LATCH_IS_ON_CALL_REMOVED, WAIT_FOR_CALL_STATE)); 506 waitForUnboundService(); 507 } 508 509 @Test testOutGoingCallReceivedHoldResume()510 public void testOutGoingCallReceivedHoldResume() throws Exception { 511 if (!ImsUtils.shouldTestImsCall()) { 512 return; 513 } 514 515 bindImsService(); 516 mServiceCallBack = new ServiceCallBack(); 517 InCallServiceStateValidator.setCallbacks(mServiceCallBack); 518 519 TelecomManager telecomManager = (TelecomManager) InstrumentationRegistry 520 .getInstrumentation().getContext().getSystemService(Context.TELECOM_SERVICE); 521 522 final Uri imsUri = Uri.fromParts(PhoneAccount.SCHEME_TEL, String.valueOf(++sCounter), null); 523 Bundle extras = new Bundle(); 524 525 telecomManager.placeCall(imsUri, extras); 526 assertTrue(callingTestLatchCountdown(LATCH_IS_ON_CALL_ADDED, WAIT_FOR_CALL_STATE)); 527 528 Call call = getCall(mCurrentCallId); 529 assertTrue(callingTestLatchCountdown(LATCH_IS_CALL_DIALING, WAIT_FOR_CALL_STATE)); 530 531 waitForCallSessionToNotBe(null); 532 TestImsCallSessionImpl callSession = 533 sServiceConnector.getCarrierService().getMmTelFeature().getImsCallsession(); 534 isCallActive(call, callSession); 535 536 // received hold and checking it is still active and received the connection event 537 // EVENT_CALL_REMOTELY_HELD 538 callSession.sendHoldReceived(); 539 assertTrue("Call is not in Active State", (call.getDetails().getState() 540 == Call.STATE_ACTIVE)); 541 assertTrue(callingTestLatchCountdown(LATCH_IS_ON_CALL_REMOTELY_HELD, WAIT_FOR_CALL_STATE)); 542 543 // received resume and checking it is still active and received the connection event 544 // EVENT_CALL_REMOTELY_UNHELD 545 callSession.sendResumeReceived(); 546 assertTrue("Call is not in Active State", (call.getDetails().getState() 547 == Call.STATE_ACTIVE)); 548 assertTrue( 549 callingTestLatchCountdown(LATCH_IS_ON_CALL_REMOTELY_UNHELD, WAIT_FOR_CALL_STATE)); 550 551 call.disconnect(); 552 553 assertTrue(callingTestLatchCountdown(LATCH_IS_CALL_DISCONNECTING, WAIT_FOR_CALL_STATE)); 554 isCallDisconnected(call, callSession); 555 assertTrue(callingTestLatchCountdown(LATCH_IS_ON_CALL_REMOVED, WAIT_FOR_CALL_STATE)); 556 waitForUnboundService(); 557 } 558 559 @Test testOutGoingIncomingMultiCall()560 public void testOutGoingIncomingMultiCall() throws Exception { 561 if (!ImsUtils.shouldTestImsCall()) { 562 return; 563 } 564 565 bindImsService(); 566 mServiceCallBack = new ServiceCallBack(); 567 InCallServiceStateValidator.setCallbacks(mServiceCallBack); 568 569 TelecomManager telecomManager = (TelecomManager) InstrumentationRegistry 570 .getInstrumentation().getContext().getSystemService(Context.TELECOM_SERVICE); 571 572 final Uri imsUri = Uri.fromParts(PhoneAccount.SCHEME_TEL, String.valueOf(++sCounter), null); 573 Bundle extras = new Bundle(); 574 575 // Place outgoing call 576 telecomManager.placeCall(imsUri, extras); 577 assertTrue(callingTestLatchCountdown(LATCH_IS_ON_CALL_ADDED, WAIT_FOR_CALL_STATE)); 578 579 Call moCall = getCall(mCurrentCallId); 580 assertTrue(callingTestLatchCountdown(LATCH_IS_CALL_DIALING, WAIT_FOR_CALL_STATE)); 581 582 waitForCallSessionToNotBe(null); 583 TestImsCallSessionImpl moCallSession = 584 sServiceConnector.getCarrierService().getMmTelFeature().getImsCallsession(); 585 isCallActive(moCall, moCallSession); 586 assertTrue("Call is not in Active State", (moCall.getDetails().getState() 587 == Call.STATE_ACTIVE)); 588 589 extras.putBoolean("android.telephony.ims.feature.extra.IS_USSD", false); 590 extras.putBoolean("android.telephony.ims.feature.extra.IS_UNKNOWN_CALL", false); 591 extras.putString("android:imsCallID", String.valueOf(++sCounter)); 592 extras.putLong("android:phone_id", 123456); 593 sServiceConnector.getCarrierService().getMmTelFeature().onIncomingCallReceived(extras); 594 assertTrue(callingTestLatchCountdown(LATCH_IS_ON_CALL_ADDED, WAIT_FOR_CALL_STATE)); 595 596 Call mtCall = null; 597 if (mCurrentCallId != null) { 598 mtCall = getCall(mCurrentCallId); 599 if (mtCall.getDetails().getState() == Call.STATE_RINGING) { 600 mtCall.answer(0); 601 } 602 } 603 604 assertTrue(callingTestLatchCountdown(LATCH_IS_CALL_HOLDING, WAIT_FOR_CALL_STATE)); 605 waitForCallSessionToNotBe(null); 606 TestImsCallSessionImpl mtCallSession = sServiceConnector.getCarrierService() 607 .getMmTelFeature().getImsCallsession(); 608 isCallActive(mtCall, mtCallSession); 609 assertTrue("Call is not in Active State", (mtCall.getDetails().getState() 610 == Call.STATE_ACTIVE)); 611 612 mtCall.disconnect(); 613 assertTrue(callingTestLatchCountdown(LATCH_IS_CALL_DISCONNECTING, WAIT_FOR_CALL_STATE)); 614 isCallDisconnected(mtCall, mtCallSession); 615 assertTrue(callingTestLatchCountdown(LATCH_IS_ON_CALL_REMOVED, WAIT_FOR_CALL_STATE)); 616 617 isCallActive(moCall, moCallSession); 618 assertTrue("Call is not in Active State", (moCall.getDetails().getState() 619 == Call.STATE_ACTIVE)); 620 621 moCall.disconnect(); 622 assertTrue(callingTestLatchCountdown(LATCH_IS_CALL_DISCONNECTING, WAIT_FOR_CALL_STATE)); 623 isCallDisconnected(moCall, moCallSession); 624 assertTrue(callingTestLatchCountdown(LATCH_IS_ON_CALL_REMOVED, WAIT_FOR_CALL_STATE)); 625 626 waitForUnboundService(); 627 } 628 629 @Test testOutGoingIncomingMultiCallAcceptTerminate()630 public void testOutGoingIncomingMultiCallAcceptTerminate() throws Exception { 631 if (!ImsUtils.shouldTestImsCall()) { 632 return; 633 } 634 635 bindImsService(); 636 mServiceCallBack = new ServiceCallBack(); 637 InCallServiceStateValidator.setCallbacks(mServiceCallBack); 638 639 TelecomManager telecomManager = (TelecomManager) InstrumentationRegistry 640 .getInstrumentation().getContext().getSystemService(Context.TELECOM_SERVICE); 641 642 final Uri imsUri = Uri.fromParts(PhoneAccount.SCHEME_TEL, String.valueOf(++sCounter), null); 643 Bundle extras = new Bundle(); 644 645 // Place outgoing call 646 telecomManager.placeCall(imsUri, extras); 647 assertTrue(callingTestLatchCountdown(LATCH_IS_ON_CALL_ADDED, WAIT_FOR_CALL_STATE)); 648 649 Call moCall = getCall(mCurrentCallId); 650 assertTrue(callingTestLatchCountdown(LATCH_IS_CALL_DIALING, WAIT_FOR_CALL_STATE)); 651 652 waitForCallSessionToNotBe(null); 653 TestImsCallSessionImpl moCallSession = 654 sServiceConnector.getCarrierService().getMmTelFeature().getImsCallsession(); 655 isCallActive(moCall, moCallSession); 656 assertTrue("Call is not in Active State", (moCall.getDetails().getState() 657 == Call.STATE_ACTIVE)); 658 659 extras.putBoolean("android.telephony.ims.feature.extra.IS_USSD", false); 660 extras.putBoolean("android.telephony.ims.feature.extra.IS_UNKNOWN_CALL", false); 661 extras.putString("android:imsCallID", String.valueOf(++sCounter)); 662 extras.putLong("android:phone_id", 123456); 663 sServiceConnector.getCarrierService().getMmTelFeature().onIncomingCallReceived(extras); 664 assertTrue(callingTestLatchCountdown(LATCH_IS_ON_CALL_ADDED, WAIT_FOR_CALL_STATE)); 665 waitForCallSessionToNotBe(null); 666 TestImsCallSessionImpl mtCallSession = 667 sServiceConnector.getCarrierService().getMmTelFeature().getImsCallsession(); 668 // do not generate an auto hold response here, need to simulate a timing issue. 669 moCallSession.addTestType(TestImsCallSessionImpl.TEST_TYPE_HOLD_NO_RESPONSE); 670 671 Call mtCall = null; 672 if (mCurrentCallId != null) { 673 mtCall = getCall(mCurrentCallId); 674 if (mtCall.getDetails().getState() == Call.STATE_RINGING) { 675 mtCall.answer(0); 676 } 677 } 678 679 ImsUtils.waitInCurrentState(WAIT_IN_CURRENT_STATE); 680 // simulate user hanging up the MT call at the same time as accept. 681 mtCallSession.terminateIncomingCall(); 682 isCallDisconnected(mtCall, mtCallSession); 683 assertTrue(callingTestLatchCountdown(LATCH_IS_ON_CALL_REMOVED, WAIT_FOR_CALL_STATE)); 684 685 // then send hold response, which should be reversed, since MT call was disconnected. 686 moCallSession.sendHoldResponse(); 687 688 // MO call should move back to active. 689 isCallActive(moCall, moCallSession); 690 assertTrue("Call is not in Active State", (moCall.getDetails().getState() 691 == Call.STATE_ACTIVE)); 692 693 moCall.disconnect(); 694 assertTrue(callingTestLatchCountdown(LATCH_IS_CALL_DISCONNECTING, WAIT_FOR_CALL_STATE)); 695 isCallDisconnected(moCall, moCallSession); 696 assertTrue(callingTestLatchCountdown(LATCH_IS_ON_CALL_REMOVED, WAIT_FOR_CALL_STATE)); 697 698 waitForUnboundService(); 699 } 700 701 @Test testOutGoingIncomingMultiCallHoldFailedTerminateByRemote()702 public void testOutGoingIncomingMultiCallHoldFailedTerminateByRemote() throws Exception { 703 if (!ImsUtils.shouldTestImsCall()) { 704 return; 705 } 706 707 bindImsService(); 708 mServiceCallBack = new ServiceCallBack(); 709 InCallServiceStateValidator.setCallbacks(mServiceCallBack); 710 711 TelecomManager telecomManager = (TelecomManager) InstrumentationRegistry 712 .getInstrumentation().getContext().getSystemService(Context.TELECOM_SERVICE); 713 714 final Uri imsUri = Uri.fromParts(PhoneAccount.SCHEME_TEL, String.valueOf(++sCounter), null); 715 Bundle extras = new Bundle(); 716 717 telecomManager.placeCall(imsUri, extras); 718 assertTrue(callingTestLatchCountdown(LATCH_IS_ON_CALL_ADDED, WAIT_FOR_CALL_STATE)); 719 720 Call moCall = getCall(mCurrentCallId); 721 assertTrue(callingTestLatchCountdown(LATCH_IS_CALL_DIALING, WAIT_FOR_CALL_STATE)); 722 723 waitForCallSessionToNotBe(null); 724 TestImsCallSessionImpl moCallSession = 725 sServiceConnector.getCarrierService().getMmTelFeature().getImsCallsession(); 726 isCallActive(moCall, moCallSession); 727 assertTrue("Call is not in Active State", (moCall.getDetails().getState() 728 == Call.STATE_ACTIVE)); 729 730 sServiceConnector.getCarrierService().getMmTelFeature().onIncomingCallReceived(extras); 731 assertTrue(callingTestLatchCountdown(LATCH_IS_ON_CALL_ADDED, WAIT_FOR_CALL_STATE)); 732 waitForCallSessionToNotBe(null); 733 TestImsCallSessionImpl mtCallSession = 734 sServiceConnector.getCarrierService().getMmTelFeature().getImsCallsession(); 735 moCallSession.addTestType(TestImsCallSessionImpl.TEST_TYPE_HOLD_NO_RESPONSE); 736 737 Call mtCall = null; 738 if (mCurrentCallId != null) { 739 mtCall = getCall(mCurrentCallId); 740 if (mtCall.getDetails().getState() == Call.STATE_RINGING) { 741 mtCall.answer(0); 742 } 743 } 744 745 ImsUtils.waitInCurrentState(WAIT_IN_CURRENT_STATE); 746 // received holdFailed because the other party of the outgoing call terminated the call 747 waitCallRenegotiating(moCallSession); 748 moCallSession.sendHoldFailRemoteTerminated(); 749 assertTrue(callingTestLatchCountdown(LATCH_IS_ON_CALL_REMOVED, WAIT_FOR_CALL_STATE)); 750 isCallDisconnected(moCall, moCallSession); 751 752 // incoming call accept again 753 mtCall.answer(0); 754 isCallActive(mtCall, mtCallSession); 755 assertTrue("Call is not in Active State", (mtCall.getDetails().getState() 756 == Call.STATE_ACTIVE)); 757 758 mtCall.disconnect(); 759 assertTrue(callingTestLatchCountdown(LATCH_IS_CALL_DISCONNECTING, WAIT_FOR_CALL_STATE)); 760 isCallDisconnected(mtCall, mtCallSession); 761 assertTrue(callingTestLatchCountdown(LATCH_IS_ON_CALL_REMOVED, WAIT_FOR_CALL_STATE)); 762 waitForUnboundService(); 763 } 764 765 @Test testOutGoingCallSwap()766 public void testOutGoingCallSwap() throws Exception { 767 if (!ImsUtils.shouldTestImsCall()) { 768 return; 769 } 770 771 bindImsService(); 772 mServiceCallBack = new ServiceCallBack(); 773 InCallServiceStateValidator.setCallbacks(mServiceCallBack); 774 addOutgoingCalls(); 775 776 // Swap the call 777 ImsUtils.waitInCurrentState(WAIT_IN_CURRENT_STATE); 778 mCall1.unhold(); 779 assertTrue(callingTestLatchCountdown(LATCH_IS_CALL_HOLDING, WAIT_FOR_CALL_STATE)); 780 assertTrue("Call is not in Hold State", (mCall2.getDetails().getState() 781 == Call.STATE_HOLDING)); 782 isCallActive(mCall1, mCallSession1); 783 784 // After successful call swap disconnect the call 785 mCall1.disconnect(); 786 assertTrue(callingTestLatchCountdown(LATCH_IS_CALL_DISCONNECTING, WAIT_FOR_CALL_STATE)); 787 isCallDisconnected(mCall1, mCallSession1); 788 assertTrue(callingTestLatchCountdown(LATCH_IS_ON_CALL_REMOVED, WAIT_FOR_CALL_STATE)); 789 790 //Wait till second call is in active state 791 waitUntilConditionIsTrueOrTimeout( 792 new Condition() { 793 @Override 794 public Object expected() { 795 return true; 796 } 797 798 @Override 799 public Object actual() { 800 return (mCall2.getDetails().getState() == Call.STATE_ACTIVE) 801 ? true : false; 802 } 803 }, WAIT_FOR_CALL_STATE_ACTIVE, "Call in Active State"); 804 805 isCallActive(mCall2, mCallSession2); 806 mCall2.disconnect(); 807 assertTrue(callingTestLatchCountdown(LATCH_IS_CALL_DISCONNECTING, WAIT_FOR_CALL_STATE)); 808 isCallDisconnected(mCall2, mCallSession2); 809 assertTrue(callingTestLatchCountdown(LATCH_IS_ON_CALL_REMOVED, WAIT_FOR_CALL_STATE)); 810 waitForUnboundService(); 811 } 812 813 @Test testOutGoingCallSwapFail()814 public void testOutGoingCallSwapFail() throws Exception { 815 if (!ImsUtils.shouldTestImsCall()) { 816 return; 817 } 818 819 bindImsService(); 820 mServiceCallBack = new ServiceCallBack(); 821 InCallServiceStateValidator.setCallbacks(mServiceCallBack); 822 addOutgoingCalls(); 823 824 mCallSession1.addTestType(TestImsCallSessionImpl.TEST_TYPE_RESUME_FAILED); 825 // Swap the call 826 ImsUtils.waitInCurrentState(WAIT_IN_CURRENT_STATE); 827 mCall1.unhold(); 828 assertTrue(callingTestLatchCountdown(LATCH_IS_CALL_HOLDING, WAIT_FOR_CALL_STATE)); 829 assertTrue("Call is not in Hold State", (mCall1.getDetails().getState() 830 == Call.STATE_HOLDING)); 831 832 // Wait till second call is in active state 833 waitUntilConditionIsTrueOrTimeout( 834 new Condition() { 835 @Override 836 public Object expected() { 837 return true; 838 } 839 840 @Override 841 public Object actual() { 842 return (mCall2.getDetails().getState() == Call.STATE_ACTIVE) 843 ? true : false; 844 } 845 }, WAIT_FOR_CALL_STATE_ACTIVE, "Call in Active State"); 846 847 isCallActive(mCall2, mCallSession2); 848 mCallSession1.removeTestType(TestImsCallSessionImpl.TEST_TYPE_RESUME_FAILED); 849 mCall2.disconnect(); 850 assertTrue(callingTestLatchCountdown(LATCH_IS_CALL_DISCONNECTING, WAIT_FOR_CALL_STATE)); 851 isCallDisconnected(mCall2, mCallSession2); 852 assertTrue(callingTestLatchCountdown(LATCH_IS_ON_CALL_REMOVED, WAIT_FOR_CALL_STATE)); 853 854 // Wait till second call is in active state 855 isCallActive(mCall1, mCallSession1); 856 mCall1.disconnect(); 857 assertTrue(callingTestLatchCountdown(LATCH_IS_CALL_DISCONNECTING, WAIT_FOR_CALL_STATE)); 858 isCallDisconnected(mCall1, mCallSession1); 859 assertTrue(callingTestLatchCountdown(LATCH_IS_ON_CALL_REMOVED, WAIT_FOR_CALL_STATE)); 860 waitForUnboundService(); 861 } 862 863 @Test testConferenceCall()864 public void testConferenceCall() throws Exception { 865 if (!ImsUtils.shouldTestImsCall()) { 866 return; 867 } 868 Log.i(LOG_TAG, "testConference "); 869 bindImsService(); 870 mServiceCallBack = new ServiceCallBack(); 871 InCallServiceStateValidator.setCallbacks(mServiceCallBack); 872 873 makeConferenceCall(); 874 875 //Disconnect the conference call. 876 mConferenceCall.disconnect(); 877 878 //Verify conference participant connections are disconnected. 879 assertParticiapantAddedToConference(0); 880 isCallDisconnected(mConferenceCall, mConfCallSession); 881 assertTrue(callingTestLatchCountdown(LATCH_IS_ON_CALL_REMOVED, WAIT_FOR_CALL_STATE)); 882 waitForUnboundService(); 883 } 884 885 @Test testConferenceCallFailure()886 public void testConferenceCallFailure() throws Exception { 887 if (!ImsUtils.shouldTestImsCall()) { 888 return; 889 } 890 Log.i(LOG_TAG, "testConferenceCallFailure "); 891 bindImsService(); 892 mServiceCallBack = new ServiceCallBack(); 893 InCallServiceStateValidator.setCallbacks(mServiceCallBack); 894 addOutgoingCalls(); 895 mCallSession2.addTestType(TestImsCallSessionImpl.TEST_TYPE_CONFERENCE_FAILED); 896 addConferenceCall(mCall1, mCall2); 897 898 ImsUtils.waitInCurrentState(WAIT_IN_CURRENT_STATE_MERGE_FAILED); 899 //Verify foreground call is in Active state after merge failed. 900 assertTrue("Call is not in Active State", (mCall2.getDetails().getState() 901 == Call.STATE_ACTIVE)); 902 //Verify background call is in Hold state after merge failed. 903 assertTrue("Call is not in Holding State", (mCall1.getDetails().getState() 904 == Call.STATE_HOLDING)); 905 906 mCall2.disconnect(); 907 assertTrue(callingTestLatchCountdown(LATCH_IS_CALL_DISCONNECTING, WAIT_FOR_CALL_STATE)); 908 isCallDisconnected(mCall2, mCallSession2); 909 assertTrue(callingTestLatchCountdown(LATCH_IS_ON_CALL_REMOVED, WAIT_FOR_CALL_STATE)); 910 911 //Wait till background call is in active state 912 isCallActive(mCall1, mCallSession1); 913 mCall1.disconnect(); 914 assertTrue(callingTestLatchCountdown(LATCH_IS_CALL_DISCONNECTING, WAIT_FOR_CALL_STATE)); 915 isCallDisconnected(mCall1, mCallSession1); 916 assertTrue(callingTestLatchCountdown(LATCH_IS_ON_CALL_REMOVED, WAIT_FOR_CALL_STATE)); 917 waitForUnboundService(); 918 } 919 920 @Test testConferenceCallFailureByRemoteTerminated()921 public void testConferenceCallFailureByRemoteTerminated() throws Exception { 922 if (!ImsUtils.shouldTestImsCall()) { 923 return; 924 } 925 926 bindImsService(); 927 mServiceCallBack = new ServiceCallBack(); 928 InCallServiceStateValidator.setCallbacks(mServiceCallBack); 929 addOutgoingCalls(); 930 mCallSession2.addTestType( 931 TestImsCallSessionImpl.TEST_TYPE_CONFERENCE_FAILED_REMOTE_TERMINATED); 932 addConferenceCall(mCall1, mCall2); 933 ImsUtils.waitInCurrentState(WAIT_IN_CURRENT_STATE); 934 935 // first call is terminated by remote 936 mCallSession1.sendTerminatedByRemote(); 937 // received mergeFailed due to terminated first call 938 mCallSession2.sendMergedFailed(); 939 940 ImsUtils.waitInCurrentState(WAIT_IN_CURRENT_STATE); 941 // verify foreground call is in Active state after merge failed. 942 assertTrue("Call is not in Active State", (mCall2.getDetails().getState() 943 == Call.STATE_ACTIVE)); 944 // verify background call is in Disconnected state. 945 isCallDisconnected(mCall1, mCallSession1); 946 assertTrue("Call is not in Disconnected State", (mCall1.getDetails().getState() 947 == Call.STATE_DISCONNECTED)); 948 949 mCall2.disconnect(); 950 assertTrue(callingTestLatchCountdown(LATCH_IS_CALL_DISCONNECTING, WAIT_FOR_CALL_STATE)); 951 isCallDisconnected(mCall2, mCallSession2); 952 assertTrue(callingTestLatchCountdown(LATCH_IS_ON_CALL_REMOVED, WAIT_FOR_CALL_STATE)); 953 waitForUnboundService(); 954 } 955 956 @Test testCallJoinExistingConferenceCall()957 public void testCallJoinExistingConferenceCall() throws Exception { 958 if (!ImsUtils.shouldTestImsCall()) { 959 return; 960 } 961 962 bindImsService(); 963 mServiceCallBack = new ServiceCallBack(); 964 InCallServiceStateValidator.setCallbacks(mServiceCallBack); 965 966 makeConferenceCall(); 967 // add third outgoing call, third call : active , conference call : hold 968 addThirdOutgoingCall(); 969 mCallSession3.addTestType(TestImsCallSessionImpl.TEST_TYPE_JOIN_EXIST_CONFERENCE); 970 971 mCall3.conference(mConferenceCall); 972 // Wait for merge complete for the third call: 973 assertTrue(callingTestLatchCountdown(LATCH_IS_ON_MERGE_COMPLETE, WAIT_FOR_CALL_STATE)); 974 isCallActive(mConferenceCall, mConfCallSession); 975 976 ImsUtils.waitInCurrentState(WAIT_IN_CURRENT_STATE); 977 // verify third call disconnected after conference Merge success 978 assertParticiapantDisconnected(mCall3); 979 980 // verify conference participant connections are connected. 981 assertParticiapantAddedToConference(3); 982 983 mConferenceCall.disconnect(); 984 985 assertParticiapantAddedToConference(0); 986 isCallDisconnected(mConferenceCall, mConfCallSession); 987 assertTrue(callingTestLatchCountdown(LATCH_IS_ON_CALL_REMOVED, WAIT_FOR_CALL_STATE)); 988 waitForUnboundService(); 989 } 990 991 @Test testCallJoinExistingConferenceCallAfterCallSwap()992 public void testCallJoinExistingConferenceCallAfterCallSwap() throws Exception { 993 if (!ImsUtils.shouldTestImsCall()) { 994 return; 995 } 996 997 bindImsService(); 998 mServiceCallBack = new ServiceCallBack(); 999 InCallServiceStateValidator.setCallbacks(mServiceCallBack); 1000 1001 makeConferenceCall(); 1002 // add third outgoing call, third call : active , conference call : hold 1003 addThirdOutgoingCall(); 1004 1005 // swap the call 1006 ImsUtils.waitInCurrentState(WAIT_IN_CURRENT_STATE); 1007 mConferenceCall.unhold(); 1008 isCallHolding(mCall3, mCallSession3); 1009 assertTrue("Call is not in Hold State", (mCall3.getDetails().getState() 1010 == Call.STATE_HOLDING)); 1011 isCallActive(mConferenceCall, mConfCallSession); 1012 1013 mConfCallSession.addTestType( 1014 TestImsCallSessionImpl.TEST_TYPE_JOIN_EXIST_CONFERENCE_AFTER_SWAP); 1015 1016 // merge call 1017 mConferenceCall.conference(mCall3); 1018 assertTrue(callingTestLatchCountdown(LATCH_IS_ON_MERGE_START, WAIT_FOR_CALL_STATE)); 1019 1020 // verify third call disconnected. 1021 assertTrue(callingTestLatchCountdown(LATCH_IS_ON_CALL_REMOVED, WAIT_FOR_CALL_STATE)); 1022 assertParticiapantDisconnected(mCall3); 1023 1024 // verify conference participant connections are connected. 1025 assertTrue(callingTestLatchCountdown(LATCH_IS_ON_MERGE_COMPLETE, WAIT_FOR_CALL_STATE)); 1026 assertTrue(callingTestLatchCountdown(LATCH_IS_ON_CHILDREN_CHANGED, WAIT_FOR_CALL_STATE)); 1027 assertParticiapantAddedToConference(3); 1028 1029 isCallActive(mConferenceCall, mConfCallSession); 1030 1031 // disconnect the conference call. 1032 mConferenceCall.disconnect(); 1033 1034 // verify conference participant connections are disconnected. 1035 assertParticiapantAddedToConference(0); 1036 isCallDisconnected(mConferenceCall, mConfCallSession); 1037 assertTrue(callingTestLatchCountdown(LATCH_IS_ON_CALL_REMOVED, WAIT_FOR_CALL_STATE)); 1038 waitForUnboundService(); 1039 } 1040 1041 @Test testCallJoinExistingConferenceCallAfterCallSwapFail()1042 public void testCallJoinExistingConferenceCallAfterCallSwapFail() throws Exception { 1043 if (!ImsUtils.shouldTestImsCall()) { 1044 return; 1045 } 1046 1047 bindImsService(); 1048 mServiceCallBack = new ServiceCallBack(); 1049 InCallServiceStateValidator.setCallbacks(mServiceCallBack); 1050 1051 makeConferenceCall(); 1052 // add third outgoing call, third call : active , conference call : hold 1053 addThirdOutgoingCall(); 1054 1055 // swap the call 1056 ImsUtils.waitInCurrentState(WAIT_IN_CURRENT_STATE); 1057 mConferenceCall.unhold(); 1058 isCallHolding(mCall3, mCallSession3); 1059 assertTrue("Call is not in Hold State", (mCall3.getDetails().getState() 1060 == Call.STATE_HOLDING)); 1061 isCallActive(mConferenceCall, mConfCallSession); 1062 1063 // fail to merge 1064 mConfCallSession.addTestType( 1065 TestImsCallSessionImpl.TEST_TYPE_JOIN_EXIST_CONFERENCE_FAILED_AFTER_SWAP); 1066 1067 mConferenceCall.conference(mCall3); 1068 ImsUtils.waitInCurrentState(WAIT_IN_CURRENT_STATE_MERGE_FAILED); 1069 1070 // verify foreground call is in Active state after merge failed. 1071 assertTrue("Call is not in Active State", (mConferenceCall.getDetails().getState() 1072 == Call.STATE_ACTIVE)); 1073 // verify background call is in Hold state after merge failed. 1074 assertTrue("Call is not in Holding State", (mCall3.getDetails().getState() 1075 == Call.STATE_HOLDING)); 1076 1077 // disconnect the conference call. 1078 mConferenceCall.disconnect(); 1079 1080 // verify conference participant connections are disconnected. 1081 assertParticiapantAddedToConference(0); 1082 isCallDisconnected(mConferenceCall, mConfCallSession); 1083 assertTrue(callingTestLatchCountdown(LATCH_IS_ON_CALL_REMOVED, WAIT_FOR_CALL_STATE)); 1084 1085 // verify third call is active 1086 isCallActive(mCall3, mCallSession3); 1087 mCall3.disconnect(); 1088 assertTrue(callingTestLatchCountdown(LATCH_IS_CALL_DISCONNECTING, WAIT_FOR_CALL_STATE)); 1089 isCallDisconnected(mCall3, mCallSession3); 1090 assertTrue(callingTestLatchCountdown(LATCH_IS_ON_CALL_REMOVED, WAIT_FOR_CALL_STATE)); 1091 waitForUnboundService(); 1092 } 1093 1094 @Test testSetCallAudioHandler()1095 public void testSetCallAudioHandler() throws Exception { 1096 if (!ImsUtils.shouldTestImsCall()) { 1097 return; 1098 } 1099 1100 bindImsService(); 1101 mServiceCallBack = new ServiceCallBack(); 1102 InCallServiceStateValidator.setCallbacks(mServiceCallBack); 1103 1104 TelecomManager telecomManager = (TelecomManager) InstrumentationRegistry 1105 .getInstrumentation().getContext().getSystemService(Context.TELECOM_SERVICE); 1106 AudioManager mAudioManager = (AudioManager) InstrumentationRegistry 1107 .getInstrumentation().getContext().getSystemService(Context.AUDIO_SERVICE); 1108 1109 final Uri imsUri = Uri.fromParts(PhoneAccount.SCHEME_TEL, String.valueOf(++sCounter), null); 1110 Bundle extras = new Bundle(); 1111 1112 mAudioManager.setMode(AudioManager.MODE_NORMAL); 1113 Log.i(LOG_TAG, "testSetCallAudioHandler - Reset AudioMode: " + mAudioManager.getMode()); 1114 1115 // Place outgoing call 1116 telecomManager.placeCall(imsUri, extras); 1117 assertTrue(callingTestLatchCountdown(LATCH_IS_ON_CALL_ADDED, WAIT_FOR_CALL_STATE)); 1118 1119 Call call = getCall(mCurrentCallId); 1120 assertTrue(callingTestLatchCountdown(LATCH_IS_CALL_DIALING, WAIT_FOR_CALL_STATE)); 1121 1122 waitForCallSessionToNotBe(null); 1123 TimeUnit.MILLISECONDS.sleep(WAIT_UPDATE_TIMEOUT_MS); 1124 1125 TestImsCallSessionImpl callSession = 1126 sServiceConnector.getCarrierService().getMmTelFeature().getImsCallsession(); 1127 1128 isCallActive(call, callSession); 1129 1130 sServiceConnector.getCarrierService().getMmTelFeature() 1131 .setCallAudioHandler(MmTelFeature.AUDIO_HANDLER_ANDROID); 1132 sServiceConnector.getCarrierService().getMmTelFeature() 1133 .getTerminalBasedCallWaitingLatch().await(WAIT_UPDATE_TIMEOUT_MS, 1134 TimeUnit.MILLISECONDS); 1135 1136 assertNotEquals(AudioManager.MODE_NORMAL, mAudioManager.getMode()); 1137 assertEquals(AudioManager.MODE_IN_COMMUNICATION, mAudioManager.getMode()); 1138 1139 call.disconnect(); 1140 assertTrue(callingTestLatchCountdown(LATCH_IS_CALL_DISCONNECTING, WAIT_FOR_CALL_STATE)); 1141 1142 // Place the 2nd outgoing call 1143 telecomManager.placeCall(imsUri, extras); 1144 assertTrue(callingTestLatchCountdown(LATCH_IS_ON_CALL_ADDED, WAIT_FOR_CALL_STATE)); 1145 1146 call = getCall(mCurrentCallId); 1147 assertTrue(callingTestLatchCountdown(LATCH_IS_CALL_DIALING, WAIT_FOR_CALL_STATE)); 1148 1149 waitForCallSessionToNotBe(null); 1150 TimeUnit.MILLISECONDS.sleep(WAIT_UPDATE_TIMEOUT_MS); 1151 callSession = sServiceConnector.getCarrierService().getMmTelFeature().getImsCallsession(); 1152 1153 isCallActive(call, callSession); 1154 1155 sServiceConnector.getCarrierService().getMmTelFeature() 1156 .setCallAudioHandler(MmTelFeature.AUDIO_HANDLER_BASEBAND); 1157 sServiceConnector.getCarrierService().getMmTelFeature() 1158 .getTerminalBasedCallWaitingLatch().await(WAIT_UPDATE_TIMEOUT_MS, 1159 TimeUnit.MILLISECONDS); 1160 1161 assertNotEquals(AudioManager.MODE_NORMAL, mAudioManager.getMode()); 1162 assertEquals(AudioManager.MODE_IN_CALL, mAudioManager.getMode()); 1163 1164 call.disconnect(); 1165 1166 assertTrue(callingTestLatchCountdown(LATCH_IS_CALL_DISCONNECTING, WAIT_FOR_CALL_STATE)); 1167 isCallDisconnected(call, callSession); 1168 assertTrue(callingTestLatchCountdown(LATCH_IS_ON_CALL_REMOVED, WAIT_FOR_CALL_STATE)); 1169 waitForUnboundService(); 1170 } 1171 1172 @Test testNotifyCallStateChanged()1173 public void testNotifyCallStateChanged() throws Exception { 1174 if (!ImsUtils.shouldTestImsCall()) { 1175 return; 1176 } 1177 1178 bindImsService(); 1179 mServiceCallBack = new ServiceCallBack(); 1180 InCallServiceStateValidator.setCallbacks(mServiceCallBack); 1181 1182 TelecomManager telecomManager = (TelecomManager) InstrumentationRegistry 1183 .getInstrumentation().getContext().getSystemService(Context.TELECOM_SERVICE); 1184 1185 final Uri imsUri = Uri.fromParts(PhoneAccount.SCHEME_TEL, String.valueOf(++sCounter), null); 1186 Bundle extras = new Bundle(); 1187 1188 // Place outgoing call 1189 telecomManager.placeCall(imsUri, extras); 1190 assertTrue(callingTestLatchCountdown(LATCH_IS_ON_CALL_ADDED, WAIT_FOR_CALL_STATE)); 1191 1192 Call call = getCall(mCurrentCallId); 1193 assertTrue(callingTestLatchCountdown(LATCH_IS_CALL_DIALING, WAIT_FOR_CALL_STATE)); 1194 1195 waitForCallSessionToNotBe(null); 1196 TestImsCallSessionImpl callSession = 1197 sServiceConnector.getCarrierService().getMmTelFeature().getImsCallsession(); 1198 1199 isCallActive(call, callSession); 1200 String callSessionId = callSession.getCallId(); 1201 1202 LinkedBlockingQueue<List<CallState>> queue = new LinkedBlockingQueue<>(); 1203 ImsCallingTest.TestTelephonyCallbackForCallStateChange testCb = 1204 new ImsCallingTest.TestTelephonyCallbackForCallStateChange(queue); 1205 1206 // test registration without permission 1207 try { 1208 sTelephonyManager.registerTelephonyCallback(Runnable::run, testCb); 1209 fail("registerTelephonyCallback requires READ_PRECISE_PHONE_STATE permission."); 1210 } catch (SecurityException e) { 1211 //expected 1212 } 1213 1214 ShellIdentityUtils.invokeMethodWithShellPermissionsNoReturn( 1215 sTelephonyManager, (tm) -> tm.registerTelephonyCallback(Runnable::run, testCb)); 1216 1217 // Expect to receive cached CallState in TelephonyRegistry when the listener register event. 1218 List<CallState> callStateList = queue.poll(ImsUtils.TEST_TIMEOUT_MS, TimeUnit.MILLISECONDS); 1219 assertNotNull(callStateList); 1220 assertEquals(1, callStateList.size()); 1221 assertEquals( 1222 PreciseCallState.PRECISE_CALL_STATE_ACTIVE, callStateList.get(0).getCallState()); 1223 assertEquals(callSessionId, callStateList.get(0).getImsCallSessionId()); 1224 assertEquals(ImsCallProfile.CALL_TYPE_VOICE, callStateList.get(0).getImsCallType()); 1225 assertEquals(ImsCallProfile.SERVICE_TYPE_NORMAL, 1226 callStateList.get(0).getImsCallServiceType()); 1227 1228 // Hold Call. 1229 ImsStreamMediaProfile mediaProfile = new ImsStreamMediaProfile( 1230 ImsStreamMediaProfile.AUDIO_QUALITY_AMR, 1231 ImsStreamMediaProfile.DIRECTION_SEND_RECEIVE, 1232 ImsStreamMediaProfile.VIDEO_QUALITY_QCIF, 1233 ImsStreamMediaProfile.DIRECTION_SEND_RECEIVE, 1234 ImsStreamMediaProfile.RTT_MODE_DISABLED); 1235 callSession.hold(mediaProfile); 1236 1237 //Check receiving CallState change callback. 1238 callStateList = queue.poll(ImsUtils.TEST_TIMEOUT_MS, TimeUnit.MILLISECONDS); 1239 assertNotNull(callStateList); 1240 assertEquals(1, callStateList.size()); 1241 assertEquals( 1242 PreciseCallState.PRECISE_CALL_STATE_HOLDING, callStateList.get(0).getCallState()); 1243 assertEquals(callSessionId, callStateList.get(0).getImsCallSessionId()); 1244 assertEquals(ImsCallProfile.CALL_TYPE_VOICE, callStateList.get(0).getImsCallType()); 1245 assertEquals(ImsCallProfile.SERVICE_TYPE_NORMAL, 1246 callStateList.get(0).getImsCallServiceType()); 1247 1248 call.disconnect(); 1249 1250 assertTrue(callingTestLatchCountdown(LATCH_IS_CALL_DISCONNECTING, WAIT_FOR_CALL_STATE)); 1251 isCallDisconnected(call, callSession); 1252 assertTrue(callingTestLatchCountdown(LATCH_IS_ON_CALL_REMOVED, WAIT_FOR_CALL_STATE)); 1253 waitForUnboundService(); 1254 } 1255 1256 @Test testNotifyMediaCallStatusChanged()1257 public void testNotifyMediaCallStatusChanged() throws Exception { 1258 if (!ImsUtils.shouldTestImsCall()) { 1259 return; 1260 } 1261 1262 bindImsService(); 1263 mServiceCallBack = new ServiceCallBack(); 1264 InCallServiceStateValidator.setCallbacks(mServiceCallBack); 1265 1266 TelecomManager telecomManager = (TelecomManager) InstrumentationRegistry 1267 .getInstrumentation().getContext().getSystemService(Context.TELECOM_SERVICE); 1268 1269 final Uri imsUri = Uri.fromParts(PhoneAccount.SCHEME_TEL, String.valueOf(++sCounter), null); 1270 Bundle extras = new Bundle(); 1271 1272 // Place outgoing call 1273 telecomManager.placeCall(imsUri, extras); 1274 assertTrue(callingTestLatchCountdown(LATCH_IS_ON_CALL_ADDED, WAIT_FOR_CALL_STATE)); 1275 1276 Call call = getCall(mCurrentCallId); 1277 assertTrue(callingTestLatchCountdown(LATCH_IS_CALL_DIALING, WAIT_FOR_CALL_STATE)); 1278 1279 waitForCallSessionToNotBe(null); 1280 TestImsCallSessionImpl callSession = 1281 sServiceConnector.getCarrierService().getMmTelFeature().getImsCallsession(); 1282 1283 isCallActive(call, callSession); 1284 String callSessionId = callSession.getCallId(); 1285 1286 LinkedBlockingQueue<MediaQualityStatus> queue = new LinkedBlockingQueue<>(); 1287 ImsCallingTest.TestTelephonyCallback testCb = 1288 new ImsCallingTest.TestTelephonyCallback(queue); 1289 1290 // test registration without permission 1291 try { 1292 sTelephonyManager.registerTelephonyCallback(Runnable::run, testCb); 1293 fail("registerTelephonyCallback requires READ_PRECISE_PHONE_STATE permission."); 1294 } catch (SecurityException e) { 1295 //expected 1296 } 1297 1298 ShellIdentityUtils.invokeMethodWithShellPermissionsNoReturn( 1299 sTelephonyManager, 1300 (tm) -> tm.registerTelephonyCallback(Runnable::run, testCb)); 1301 1302 MediaQualityStatus status = queue.poll(ImsUtils.TEST_TIMEOUT_MS, TimeUnit.MILLISECONDS); 1303 assertNotNull(status); 1304 assertEquals(callSessionId, status.getCallSessionId()); 1305 assertEquals(MediaQualityStatus.MEDIA_SESSION_TYPE_AUDIO, status.getMediaSessionType()); 1306 assertEquals(AccessNetworkConstants.TRANSPORT_TYPE_WWAN, status.getTransportType()); 1307 assertEquals(0, status.getRtpPacketLossRate()); 1308 assertEquals(0, status.getRtpJitterMillis()); 1309 assertEquals(0, status.getRtpInactivityMillis()); 1310 1311 //Notify a new media quality status. 1312 sServiceConnector.getCarrierService().getMmTelFeature() 1313 .notifyMediaQualityStatusChanged(new MediaQualityStatus(callSessionId, 1314 MediaQualityStatus.MEDIA_SESSION_TYPE_AUDIO, 1315 AccessNetworkConstants.TRANSPORT_TYPE_WWAN, 1316 TEST_RTP_THRESHOLD_PACKET_LOSS_RATE, 1317 TEST_RTP_THRESHOLD_JITTER_MILLIS, 1318 TEST_RTP_THRESHOLD_INACTIVITY_TIME_MILLIS)); 1319 1320 status = queue.poll(ImsUtils.TEST_TIMEOUT_MS, TimeUnit.MILLISECONDS); 1321 assertNotNull(status); 1322 assertEquals(callSessionId, status.getCallSessionId()); 1323 assertEquals(MediaQualityStatus.MEDIA_SESSION_TYPE_AUDIO, status.getMediaSessionType()); 1324 assertEquals(AccessNetworkConstants.TRANSPORT_TYPE_WWAN, status.getTransportType()); 1325 assertEquals(TEST_RTP_THRESHOLD_PACKET_LOSS_RATE, status.getRtpPacketLossRate()); 1326 assertEquals(TEST_RTP_THRESHOLD_JITTER_MILLIS, status.getRtpJitterMillis()); 1327 assertEquals(TEST_RTP_THRESHOLD_INACTIVITY_TIME_MILLIS, status.getRtpInactivityMillis()); 1328 1329 call.disconnect(); 1330 1331 assertTrue(callingTestLatchCountdown(LATCH_IS_CALL_DISCONNECTING, WAIT_FOR_CALL_STATE)); 1332 isCallDisconnected(call, callSession); 1333 assertTrue(callingTestLatchCountdown(LATCH_IS_ON_CALL_REMOVED, WAIT_FOR_CALL_STATE)); 1334 waitForUnboundService(); 1335 } 1336 1337 private class TestTelephonyCallback extends TelephonyCallback 1338 implements TelephonyCallback.MediaQualityStatusChangedListener { 1339 LinkedBlockingQueue<MediaQualityStatus> mTestMediaQualityStatusQueue; TestTelephonyCallback(LinkedBlockingQueue<MediaQualityStatus> queue)1340 TestTelephonyCallback(LinkedBlockingQueue<MediaQualityStatus> queue) { 1341 mTestMediaQualityStatusQueue = queue; 1342 } 1343 @Override onMediaQualityStatusChanged(@onNull MediaQualityStatus status)1344 public void onMediaQualityStatusChanged(@NonNull MediaQualityStatus status) { 1345 mTestMediaQualityStatusQueue.offer(status); 1346 } 1347 } 1348 1349 private class TestTelephonyCallbackForCallStateChange extends TelephonyCallback 1350 implements TelephonyCallback.CallAttributesListener { 1351 LinkedBlockingQueue<List<CallState>> mTestCallStateListeQueue; TestTelephonyCallbackForCallStateChange(LinkedBlockingQueue<List<CallState>> queue)1352 TestTelephonyCallbackForCallStateChange(LinkedBlockingQueue<List<CallState>> queue) { 1353 mTestCallStateListeQueue = queue; 1354 } 1355 @Override onCallStatesChanged(@onNull List<CallState> states)1356 public void onCallStatesChanged(@NonNull List<CallState> states) { 1357 mTestCallStateListeQueue.offer(states); 1358 } 1359 } 1360 addConferenceCall(Call call1, Call call2)1361 void addConferenceCall(Call call1, Call call2) { 1362 InCallServiceStateValidator inCallService = mServiceCallBack.getService(); 1363 1364 // Verify that the calls have each other on their conferenceable list before proceeding 1365 List<Call> callConfList = new ArrayList<>(); 1366 callConfList.add(call2); 1367 assertCallConferenceableList(call1, callConfList); 1368 1369 callConfList.clear(); 1370 callConfList.add(call1); 1371 assertCallConferenceableList(call2, callConfList); 1372 1373 call2.conference(call1); 1374 } 1375 assertCallConferenceableList(final Call call, final List<Call> conferenceableList)1376 void assertCallConferenceableList(final Call call, final List<Call> conferenceableList) { 1377 waitUntilConditionIsTrueOrTimeout( 1378 new Condition() { 1379 @Override 1380 public Object expected() { 1381 return conferenceableList; 1382 } 1383 1384 @Override 1385 public Object actual() { 1386 return call.getConferenceableCalls(); 1387 } 1388 }, WAIT_FOR_CONDITION, 1389 "Call: " + call + " does not have the correct conferenceable call list." 1390 ); 1391 } 1392 assertParticiapantDisconnected(Call call)1393 private void assertParticiapantDisconnected(Call call) { 1394 waitUntilConditionIsTrueOrTimeout( 1395 new Condition() { 1396 @Override 1397 public Object expected() { 1398 return true; 1399 } 1400 1401 @Override 1402 public Object actual() { 1403 return ((call.getState() == Call.STATE_DISCONNECTED)) ? true : false; 1404 } 1405 }, WAIT_FOR_CONDITION, "Call Disconnected"); 1406 } 1407 assertParticiapantAddedToConference(int count)1408 private void assertParticiapantAddedToConference(int count) { 1409 waitUntilConditionIsTrueOrTimeout( 1410 new Condition() { 1411 @Override 1412 public Object expected() { 1413 return true; 1414 } 1415 1416 @Override 1417 public Object actual() { 1418 return (mParticipantCount == count) ? true : false; 1419 } 1420 }, WAIT_FOR_CONDITION, "Call Added"); 1421 } 1422 addOutgoingCalls()1423 private void addOutgoingCalls() throws Exception { 1424 TelecomManager telecomManager = (TelecomManager) InstrumentationRegistry 1425 .getInstrumentation().getContext().getSystemService(Context.TELECOM_SERVICE); 1426 1427 // Place first outgoing call 1428 final Uri imsUri1 = Uri.fromParts(PhoneAccount.SCHEME_TEL, String.valueOf(++sCounter), 1429 null); 1430 Bundle extras1 = new Bundle(); 1431 1432 telecomManager.placeCall(imsUri1, extras1); 1433 assertTrue(callingTestLatchCountdown(LATCH_IS_ON_CALL_ADDED, WAIT_FOR_CALL_STATE)); 1434 1435 mCall1 = getCall(mCurrentCallId); 1436 assertTrue(callingTestLatchCountdown(LATCH_IS_CALL_DIALING, WAIT_FOR_CALL_STATE)); 1437 waitForCallSessionToNotBe(null); 1438 mCallSession1 = sServiceConnector.getCarrierService().getMmTelFeature().getImsCallsession(); 1439 isCallActive(mCall1, mCallSession1); 1440 assertTrue("Call is not in Active State", (mCall1.getDetails().getState() 1441 == Call.STATE_ACTIVE)); 1442 1443 // Place second outgoing call 1444 final Uri imsUri2 = Uri.fromParts(PhoneAccount.SCHEME_TEL, String.valueOf(++sCounter), 1445 null); 1446 Bundle extras2 = new Bundle(); 1447 1448 telecomManager.placeCall(imsUri2, extras2); 1449 assertTrue(callingTestLatchCountdown(LATCH_IS_ON_CALL_ADDED, WAIT_FOR_CALL_STATE)); 1450 1451 mCall2 = getCall(mCurrentCallId); 1452 assertTrue(callingTestLatchCountdown(LATCH_IS_CALL_DIALING, WAIT_FOR_CALL_STATE)); 1453 assertTrue(callingTestLatchCountdown(LATCH_IS_CALL_HOLDING, WAIT_FOR_CALL_STATE)); 1454 assertTrue("Call is not in Hold State", (mCall1.getDetails().getState() 1455 == Call.STATE_HOLDING)); 1456 1457 // Wait till the object of TestImsCallSessionImpl for second call created. 1458 waitForCallSessionToNotBe(mCallSession1); 1459 mCallSession2 = sServiceConnector.getCarrierService().getMmTelFeature().getImsCallsession(); 1460 isCallActive(mCall2, mCallSession2); 1461 assertTrue("Call is not in Active State", (mCall2.getDetails().getState() 1462 == Call.STATE_ACTIVE)); 1463 } 1464 addThirdOutgoingCall()1465 private void addThirdOutgoingCall() { 1466 // add a third outgoing call when a conference call already exists. 1467 TelecomManager telecomManager = (TelecomManager) InstrumentationRegistry 1468 .getInstrumentation().getContext().getSystemService(Context.TELECOM_SERVICE); 1469 final Uri imsUri3 = Uri.fromParts(PhoneAccount.SCHEME_TEL, String.valueOf(++sCounter), 1470 null); 1471 Bundle extras3 = new Bundle(); 1472 1473 telecomManager.placeCall(imsUri3, extras3); 1474 assertTrue(callingTestLatchCountdown(LATCH_IS_ON_CALL_ADDED, WAIT_FOR_CALL_STATE)); 1475 waitNextCallAdded(String.valueOf(sCounter)); 1476 1477 mCall3 = getCall(mCurrentCallId); 1478 assertTrue(callingTestLatchCountdown(LATCH_IS_CALL_DIALING, WAIT_FOR_CALL_STATE)); 1479 assertTrue(callingTestLatchCountdown(LATCH_IS_CALL_HOLDING, WAIT_FOR_CALL_STATE)); 1480 assertTrue("Call is not in Hold State", (mConferenceCall.getDetails().getState() 1481 == Call.STATE_HOLDING)); 1482 1483 waitForCallSessionToNotBe(mCallSession2); 1484 mCallSession3 = 1485 sServiceConnector.getCarrierService().getMmTelFeature().getImsCallsession(); 1486 1487 isCallActive(mCall3, mCallSession3); 1488 assertTrue("Call is not in Active State", (mCall3.getDetails().getState() 1489 == Call.STATE_ACTIVE)); 1490 } 1491 waitForCallSessionToNotBe(TestImsCallSessionImpl previousCallSession)1492 private void waitForCallSessionToNotBe(TestImsCallSessionImpl previousCallSession) { 1493 waitUntilConditionIsTrueOrTimeout( 1494 new Condition() { 1495 @Override 1496 public Object expected() { 1497 return true; 1498 } 1499 1500 @Override 1501 public Object actual() { 1502 TestMmTelFeature mmtelfeatue = sServiceConnector.getCarrierService() 1503 .getMmTelFeature(); 1504 return (mmtelfeatue.getImsCallsession() != previousCallSession) ? true 1505 : false; 1506 } 1507 }, WAIT_FOR_CONDITION, "CallSession Created"); 1508 } 1509 waitNextCallAdded(String expectedUri)1510 private void waitNextCallAdded(String expectedUri) { 1511 callingTestLatchCountdown(LATCH_IS_ON_CALL_ADDED, WAIT_FOR_CALL_STATE); 1512 final String[] actualUri = {getCall(mCurrentCallId).getDetails().getHandle().toString()}; 1513 waitUntilConditionIsTrueOrTimeout( 1514 new Condition() { 1515 @Override 1516 public Object expected() { 1517 return true; 1518 } 1519 1520 @Override 1521 public Object actual() { 1522 if (!actualUri[0].contains(expectedUri)) { 1523 assertTrue(callingTestLatchCountdown(LATCH_IS_ON_CALL_ADDED, 1524 WAIT_FOR_CALL_STATE)); 1525 actualUri[0] = getCall( 1526 mCurrentCallId).getDetails().getHandle().toString(); 1527 return false; 1528 } 1529 return true; 1530 } 1531 }, WAIT_FOR_CONDITION, "Next Call added"); 1532 } 1533 waitCallRenegotiating(TestImsCallSessionImpl callSession)1534 private void waitCallRenegotiating(TestImsCallSessionImpl callSession) { 1535 waitUntilConditionIsTrueOrTimeout( 1536 new Condition() { 1537 @Override 1538 public Object expected() { 1539 return true; 1540 } 1541 1542 @Override 1543 public Object actual() { 1544 return callSession.isRenegotiating() ? true : false; 1545 } 1546 }, WAIT_FOR_CONDITION, callSession.getState() + ", waitCallRenegotiating"); 1547 } 1548 makeConferenceCall()1549 private void makeConferenceCall() throws Exception { 1550 // Initialize the MERGE_START latch with a count of 2 (one for each call of the conference): 1551 overrideLatchCount(LATCH_IS_ON_MERGE_START, 2); 1552 1553 addOutgoingCalls(); 1554 addConferenceCall(mCall1, mCall2); 1555 1556 // Wait for merge start first and second call 1557 assertTrue(callingTestLatchCountdown(LATCH_IS_ON_MERGE_START, WAIT_FOR_CALL_STATE)); 1558 // Wait for merge complete background call: 1559 assertTrue(callingTestLatchCountdown(LATCH_IS_ON_MERGE_COMPLETE, WAIT_FOR_CALL_STATE)); 1560 // Wait for remove first call 1561 callingTestLatchCountdown(LATCH_IS_ON_CALL_REMOVED, WAIT_FOR_CALL_STATE); 1562 // Wait for merge complete foreground call: 1563 assertTrue(callingTestLatchCountdown(LATCH_IS_ON_MERGE_COMPLETE, WAIT_FOR_CALL_STATE)); 1564 // Wait for conference call added 1565 assertTrue( 1566 callingTestLatchCountdown(LATCH_IS_ON_CONFERENCE_CALL_ADDED, WAIT_FOR_CALL_STATE)); 1567 // Wait for remove second call 1568 callingTestLatchCountdown(LATCH_IS_ON_CALL_REMOVED, WAIT_FOR_CALL_STATE); 1569 // Wait to add participants in conference 1570 assertTrue("Conference call is not added", mServiceCallBack.getService() 1571 .getConferenceCallCount() > 0); 1572 1573 mConferenceCall = mServiceCallBack.getService().getLastConferenceCall(); 1574 assertNotNull("Unable to add conference call, its null", mConferenceCall); 1575 1576 ConferenceHelper confHelper = sServiceConnector.getCarrierService().getMmTelFeature() 1577 .getConferenceHelper(); 1578 1579 mConfCallSession = confHelper.getConferenceSession(); 1580 isCallActive(mConferenceCall, mConfCallSession); 1581 assertTrue("Conference call is not Active", mConfCallSession.isInCall()); 1582 1583 //Verify mCall1 and mCall2 disconnected after conference Merge success 1584 assertParticiapantDisconnected(mCall1); 1585 assertParticiapantDisconnected(mCall2); 1586 1587 //Verify conference participant connections are connected. 1588 assertTrue(callingTestLatchCountdown(LATCH_IS_ON_CHILDREN_CHANGED, WAIT_FOR_CALL_STATE)); 1589 assertParticiapantAddedToConference(2); 1590 1591 // Since the conference call has been made, remove session1&2 from the confHelper session. 1592 confHelper.removeSession(mCallSession1); 1593 confHelper.removeSession(mCallSession2); 1594 } 1595 resetCallSessionObjects()1596 private void resetCallSessionObjects() { 1597 mCall1 = mCall2 = mCall3 = mConferenceCall = null; 1598 mCallSession1 = mCallSession2 = mCallSession3 = mConfCallSession = null; 1599 if (sServiceConnector.getCarrierService().getMmTelFeature() == null) { 1600 return; 1601 } 1602 ConferenceHelper confHelper = sServiceConnector.getCarrierService().getMmTelFeature() 1603 .getConferenceHelper(); 1604 if (confHelper != null) { 1605 confHelper.clearSessions(); 1606 } 1607 } 1608 } 1609