1 /* 2 * Copyright (C) 2015 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package android.telecom.cts; 18 19 import static android.telecom.cts.TestUtils.*; 20 21 import android.app.UiModeManager; 22 import android.content.ContentValues; 23 import android.content.Context; 24 import android.net.Uri; 25 import android.os.Bundle; 26 import android.provider.BlockedNumberContract; 27 import android.telecom.CallAudioState; 28 import android.telecom.Call; 29 import android.telecom.Connection; 30 import android.telecom.ConnectionService; 31 import android.telecom.InCallService; 32 import android.telecom.TelecomManager; 33 import android.telecom.VideoProfile; 34 import android.telephony.TelephonyManager; 35 36 import java.util.List; 37 38 /** 39 * Extended suite of tests that use {@link CtsConnectionService} and {@link MockInCallService} to 40 * verify the functionality of the Telecom service. 41 */ 42 public class ExtendedInCallServiceTest extends BaseTelecomTestWithMockServices { 43 44 @Override 45 protected void setUp() throws Exception { 46 super.setUp(); 47 if (mShouldTestTelecom) { 48 setupConnectionService(null, FLAG_REGISTER | FLAG_ENABLE); 49 } 50 } 51 52 public void testAddNewOutgoingCallAndThenDisconnect() { 53 if (!mShouldTestTelecom) { 54 return; 55 } 56 57 placeAndVerifyCall(); 58 verifyConnectionForOutgoingCall(); 59 60 final MockInCallService inCallService = mInCallCallbacks.getService(); 61 inCallService.disconnectLastCall(); 62 63 assertNumCalls(inCallService, 0); 64 } 65 66 public void testMuteAndUnmutePhone() { 67 if (!mShouldTestTelecom) { 68 return; 69 } 70 71 placeAndVerifyCall(); 72 final MockConnection connection = verifyConnectionForOutgoingCall(); 73 74 final MockInCallService inCallService = mInCallCallbacks.getService(); 75 76 final Call call = inCallService.getLastCall(); 77 78 assertCallState(call, Call.STATE_DIALING); 79 80 assertMuteState(connection, false); 81 82 // Explicitly call super implementation to enable detection of CTS coverage 83 ((InCallService) inCallService).setMuted(true); 84 85 assertMuteState(connection, true); 86 assertMuteState(inCallService, true); 87 88 inCallService.setMuted(false); 89 assertMuteState(connection, false); 90 assertMuteState(inCallService, false); 91 } 92 93 public void testSwitchAudioRoutes() { 94 if (!mShouldTestTelecom) { 95 return; 96 } 97 98 placeAndVerifyCall(); 99 final MockConnection connection = verifyConnectionForOutgoingCall(); 100 101 final MockInCallService inCallService = mInCallCallbacks.getService(); 102 103 final Call call = inCallService.getLastCall(); 104 assertCallState(call, Call.STATE_DIALING); 105 106 final int currentInvokeCount = mOnCallAudioStateChangedCounter.getInvokeCount(); 107 mOnCallAudioStateChangedCounter.waitForCount(WAIT_FOR_STATE_CHANGE_TIMEOUT_MS); 108 CallAudioState callAudioState = 109 (CallAudioState) mOnCallAudioStateChangedCounter.getArgs(0)[0]; 110 111 // We need to check what audio routes are available. If speaker and either headset or 112 // earpiece aren't available, then we should skip this test. 113 114 int availableRoutes = callAudioState.getSupportedRouteMask(); 115 if ((availableRoutes & CallAudioState.ROUTE_SPEAKER) == 0) { 116 return; 117 } 118 if ((availableRoutes & CallAudioState.ROUTE_WIRED_OR_EARPIECE) == 0) { 119 return; 120 } 121 // Determine what the second route to go to after SPEAKER should be, depending on what's 122 // supported. 123 int secondRoute = (availableRoutes & CallAudioState.ROUTE_EARPIECE) == 0 ? 124 CallAudioState.ROUTE_WIRED_HEADSET : CallAudioState.ROUTE_EARPIECE; 125 126 // Explicitly call super implementation to enable detection of CTS coverage 127 ((InCallService) inCallService).setAudioRoute(CallAudioState.ROUTE_SPEAKER); 128 mOnCallAudioStateChangedCounter.waitForCount(currentInvokeCount + 1, 129 WAIT_FOR_STATE_CHANGE_TIMEOUT_MS); 130 assertAudioRoute(connection, CallAudioState.ROUTE_SPEAKER); 131 assertAudioRoute(inCallService, CallAudioState.ROUTE_SPEAKER); 132 133 inCallService.setAudioRoute(secondRoute); 134 mOnCallAudioStateChangedCounter.waitForCount(currentInvokeCount + 2, 135 WAIT_FOR_STATE_CHANGE_TIMEOUT_MS); 136 assertAudioRoute(connection, secondRoute); 137 assertAudioRoute(inCallService, secondRoute); 138 139 // Call requestBluetoothAudio on a dummy device. This will be a noop since no devices are 140 // connected. 141 if(TestUtils.HAS_BLUETOOTH) { 142 ((InCallService) inCallService).requestBluetoothAudio(TestUtils.BLUETOOTH_DEVICE1); 143 } 144 } 145 146 /** 147 * Tests that DTMF Tones are sent from the {@link InCallService} to the 148 * {@link ConnectionService} in the correct sequence. 149 * 150 * @see {@link Call#playDtmfTone(char)} 151 * @see {@link Call#stopDtmfTone()} 152 */ 153 public void testPlayAndStopDtmfTones() { 154 if (!mShouldTestTelecom) { 155 return; 156 } 157 158 placeAndVerifyCall(); 159 final MockConnection connection = verifyConnectionForOutgoingCall(); 160 161 final MockInCallService inCallService = mInCallCallbacks.getService(); 162 163 final Call call = inCallService.getLastCall(); 164 assertCallState(call, Call.STATE_DIALING); 165 166 assertDtmfString(connection, ""); 167 168 call.playDtmfTone('1'); 169 assertDtmfString(connection, "1"); 170 171 call.playDtmfTone('2'); 172 assertDtmfString(connection, "12"); 173 174 call.stopDtmfTone(); 175 assertDtmfString(connection, "12."); 176 177 call.playDtmfTone('3'); 178 call.playDtmfTone('4'); 179 call.playDtmfTone('5'); 180 assertDtmfString(connection, "12.345"); 181 182 call.stopDtmfTone(); 183 assertDtmfString(connection, "12.345."); 184 } 185 186 public void testHoldAndUnholdCall() { 187 if (!mShouldTestTelecom) { 188 return; 189 } 190 191 placeAndVerifyCall(); 192 final MockConnection connection = verifyConnectionForOutgoingCall(); 193 194 final MockInCallService inCallService = mInCallCallbacks.getService(); 195 196 final Call call = inCallService.getLastCall(); 197 198 assertCallState(call, Call.STATE_DIALING); 199 200 connection.setActive(); 201 202 assertCallState(call, Call.STATE_ACTIVE); 203 204 call.hold(); 205 assertCallState(call, Call.STATE_HOLDING); 206 assertEquals(Connection.STATE_HOLDING, connection.getState()); 207 208 call.unhold(); 209 assertCallState(call, Call.STATE_ACTIVE); 210 assertEquals(Connection.STATE_ACTIVE, connection.getState()); 211 } 212 213 public void testAnswerIncomingCallAudioOnly() { 214 if (!mShouldTestTelecom) { 215 return; 216 } 217 218 addAndVerifyNewIncomingCall(createTestNumber(), null); 219 final MockConnection connection = verifyConnectionForIncomingCall(); 220 221 final MockInCallService inCallService = mInCallCallbacks.getService(); 222 223 final Call call = inCallService.getLastCall(); 224 225 assertCallState(call, Call.STATE_RINGING); 226 assertConnectionState(connection, Connection.STATE_RINGING); 227 228 call.answer(VideoProfile.STATE_AUDIO_ONLY); 229 230 assertCallState(call, Call.STATE_ACTIVE); 231 assertConnectionState(connection, Connection.STATE_ACTIVE); 232 } 233 234 public void testAcceptRingingCall() { 235 if (!mShouldTestTelecom) { 236 return; 237 } 238 239 addAndVerifyNewIncomingCall(createTestNumber(), null); 240 MockConnection connection = verifyConnectionForIncomingCall(0); 241 final MockInCallService inCallService = mInCallCallbacks.getService(); 242 final Call call = inCallService.getLastCall(); 243 244 assertCallState(call, Call.STATE_RINGING); 245 assertConnectionState(connection, Connection.STATE_RINGING); 246 247 mTelecomManager.acceptRingingCall(); 248 249 assertCallState(call, Call.STATE_ACTIVE); 250 assertConnectionState(connection, Connection.STATE_ACTIVE); 251 } 252 253 /** 254 * Verifies that the {@link TelecomManager#endCall()} API is able to end a ringing call. 255 */ 256 public void testEndRingingCall() { 257 if (!mShouldTestTelecom) { 258 return; 259 } 260 261 addAndVerifyNewIncomingCall(createTestNumber(), null); 262 MockConnection connection = verifyConnectionForIncomingCall(0); 263 final MockInCallService inCallService = mInCallCallbacks.getService(); 264 final Call call = inCallService.getLastCall(); 265 266 assertCallState(call, Call.STATE_RINGING); 267 assertConnectionState(connection, Connection.STATE_RINGING); 268 269 mTelecomManager.endCall(); 270 271 assertCallState(call, Call.STATE_DISCONNECTED); 272 assertConnectionState(connection, Connection.STATE_DISCONNECTED); 273 } 274 275 /** 276 * Verifies that the {@link TelecomManager#endCall()} API is able to end an active call. 277 */ 278 public void testEndCall() { 279 if (!mShouldTestTelecom) { 280 return; 281 } 282 283 addAndVerifyNewIncomingCall(createTestNumber(), null); 284 MockConnection connection = verifyConnectionForIncomingCall(0); 285 final MockInCallService inCallService = mInCallCallbacks.getService(); 286 final Call call = inCallService.getLastCall(); 287 288 assertCallState(call, Call.STATE_RINGING); 289 assertConnectionState(connection, Connection.STATE_RINGING); 290 291 mTelecomManager.acceptRingingCall(); 292 293 assertCallState(call, Call.STATE_ACTIVE); 294 assertConnectionState(connection, Connection.STATE_ACTIVE); 295 296 mTelecomManager.endCall(); 297 298 assertCallState(call, Call.STATE_DISCONNECTED); 299 assertConnectionState(connection, Connection.STATE_DISCONNECTED); 300 } 301 302 303 /** 304 * Tests that if there is the device is in a call and a second call comes in, 305 * answering the call immediately answers second call without blocking. 306 */ 307 public void testAcceptRingingCallTwoCalls() { 308 if (!mShouldTestTelecom) { 309 return; 310 } 311 312 addAndVerifyNewIncomingCall(createTestNumber(), null); 313 MockConnection connection1 = verifyConnectionForIncomingCall(0); 314 final MockInCallService inCallService = mInCallCallbacks.getService(); 315 final Call call1 = inCallService.getLastCall(); 316 317 call1.answer(VideoProfile.STATE_AUDIO_ONLY); 318 319 assertCallState(call1, Call.STATE_ACTIVE); 320 321 addAndVerifyNewIncomingCall(createTestNumber(), null); 322 final MockConnection connection2 = verifyConnectionForIncomingCall(1); 323 final Call call2 = inCallService.getLastCall(); 324 325 assertCallState(call2, Call.STATE_RINGING); 326 assertConnectionState(connection2, Connection.STATE_RINGING); 327 328 mTelecomManager.acceptRingingCall(); 329 330 // The second call must now be active 331 assertCallState(call2, Call.STATE_ACTIVE); 332 assertConnectionState(connection2, Connection.STATE_ACTIVE); 333 } 334 335 /** 336 * Tests that if there is the device is in a call and a second call comes in, 337 * answering the call immediately answers second call while in carMode. 338 */ 339 public void testAcceptRingingCallTwoCallsCarMode() { 340 if (!mShouldTestTelecom) { 341 return; 342 } 343 344 addAndVerifyNewIncomingCall(createTestNumber(), null); 345 MockConnection connection1 = verifyConnectionForIncomingCall(0); 346 final MockInCallService inCallService = mInCallCallbacks.getService(); 347 final Call call1 = inCallService.getLastCall(); 348 349 call1.answer(VideoProfile.STATE_AUDIO_ONLY); 350 351 assertCallState(call1, Call.STATE_ACTIVE); 352 353 addAndVerifyNewIncomingCall(createTestNumber(), null); 354 final MockConnection connection2 = verifyConnectionForIncomingCall(1); 355 final Call call2 = inCallService.getLastCall(); 356 357 assertCallState(call2, Call.STATE_RINGING); 358 assertConnectionState(connection2, Connection.STATE_RINGING); 359 360 UiModeManager manager = (UiModeManager) mContext.getSystemService(Context.UI_MODE_SERVICE); 361 try { 362 manager.enableCarMode(0); 363 364 mTelecomManager.acceptRingingCall(); 365 366 // The second call should now be active 367 assertCallState(call2, Call.STATE_ACTIVE); 368 assertConnectionState(connection2, Connection.STATE_ACTIVE); 369 370 } finally { 371 // Set device back to normal 372 manager.disableCarMode(0); 373 } 374 } 375 376 public void testIncomingCallFromBlockedNumber_IsRejected() throws Exception { 377 if (!mShouldTestTelecom) { 378 return; 379 } 380 381 Uri blockedUri = null; 382 383 try { 384 Uri testNumberUri = createTestNumber(); 385 blockedUri = blockNumber(testNumberUri); 386 387 final Bundle extras = new Bundle(); 388 extras.putParcelable(TelecomManager.EXTRA_INCOMING_CALL_ADDRESS, testNumberUri); 389 mTelecomManager.addNewIncomingCall(TEST_PHONE_ACCOUNT_HANDLE, extras); 390 391 final MockConnection connection = verifyConnectionForIncomingCall(); 392 assertConnectionState(connection, Connection.STATE_DISCONNECTED); 393 assertNull(mInCallCallbacks.getService()); 394 } finally { 395 if (blockedUri != null) { 396 mContext.getContentResolver().delete(blockedUri, null, null); 397 } 398 } 399 } 400 401 private Uri blockNumber(Uri phoneNumberUri) { 402 ContentValues cv = new ContentValues(); 403 cv.put(BlockedNumberContract.BlockedNumbers.COLUMN_ORIGINAL_NUMBER, 404 phoneNumberUri.getSchemeSpecificPart()); 405 return mContext.getContentResolver().insert( 406 BlockedNumberContract.BlockedNumbers.CONTENT_URI, cv); 407 } 408 409 public void testAnswerIncomingCallAsVideo_SendsCorrectVideoState() { 410 if (!mShouldTestTelecom) { 411 return; 412 } 413 414 addAndVerifyNewIncomingCall(createTestNumber(), null); 415 final MockConnection connection = verifyConnectionForIncomingCall(); 416 417 final MockInCallService inCallService = mInCallCallbacks.getService(); 418 419 final Call call = inCallService.getLastCall(); 420 421 assertCallState(call, Call.STATE_RINGING); 422 assertConnectionState(connection, Connection.STATE_RINGING); 423 424 call.answer(VideoProfile.STATE_BIDIRECTIONAL); 425 426 assertCallState(call, Call.STATE_ACTIVE); 427 assertConnectionState(connection, Connection.STATE_ACTIVE); 428 assertEquals("Connection did not receive VideoState for answered call", 429 VideoProfile.STATE_BIDIRECTIONAL, connection.videoState); 430 } 431 432 public void testRejectIncomingCall() { 433 if (!mShouldTestTelecom) { 434 return; 435 } 436 437 addAndVerifyNewIncomingCall(createTestNumber(), null); 438 final MockConnection connection = verifyConnectionForIncomingCall(); 439 440 final MockInCallService inCallService = mInCallCallbacks.getService(); 441 442 final Call call = inCallService.getLastCall(); 443 444 assertCallState(call, Call.STATE_RINGING); 445 assertConnectionState(connection, Connection.STATE_RINGING); 446 447 call.reject(false, null); 448 449 assertCallState(call, Call.STATE_DISCONNECTED); 450 assertConnectionState(connection, Connection.STATE_DISCONNECTED); 451 } 452 453 public void testRejectIncomingCallWithMessage() { 454 if (!mShouldTestTelecom) { 455 return; 456 } 457 String disconnectReason = "Test reason for disconnect"; 458 459 addAndVerifyNewIncomingCall(createTestNumber(), null); 460 final MockConnection connection = verifyConnectionForIncomingCall(); 461 462 final MockInCallService inCallService = mInCallCallbacks.getService(); 463 464 final Call call = inCallService.getLastCall(); 465 466 assertCallState(call, Call.STATE_RINGING); 467 assertConnectionState(connection, Connection.STATE_RINGING); 468 469 call.reject(true, disconnectReason); 470 471 assertCallState(call, Call.STATE_DISCONNECTED); 472 assertConnectionState(connection, Connection.STATE_DISCONNECTED); 473 assertDisconnectReason(connection, disconnectReason); 474 } 475 476 public void testCanAddCall_CannotAddForExistingDialingCall() { 477 if (!mShouldTestTelecom) { 478 return; 479 } 480 481 placeAndVerifyCall(); 482 verifyConnectionForOutgoingCall(); 483 484 final MockInCallService inCallService = mInCallCallbacks.getService(); 485 486 final Call call = inCallService.getLastCall(); 487 assertCallState(call, Call.STATE_DIALING); 488 489 assertCanAddCall(inCallService, false, 490 "Should not be able to add call with existing dialing call"); 491 } 492 493 public void testCanAddCall_CanAddForExistingActiveCall() { 494 if (!mShouldTestTelecom) { 495 return; 496 } 497 498 placeAndVerifyCall(); 499 final MockConnection connection = verifyConnectionForOutgoingCall(); 500 501 final MockInCallService inCallService = mInCallCallbacks.getService(); 502 503 final Call call = inCallService.getLastCall(); 504 assertCallState(call, Call.STATE_DIALING); 505 506 connection.setActive(); 507 508 assertCallState(call, Call.STATE_ACTIVE); 509 510 assertCanAddCall(inCallService, true, 511 "Should be able to add call with only one active call"); 512 } 513 514 public void testCanAddCall_CannotAddIfTooManyCalls() { 515 if (!mShouldTestTelecom) { 516 return; 517 } 518 519 placeAndVerifyCall(); 520 final MockConnection connection1 = verifyConnectionForOutgoingCall(0); 521 final MockInCallService inCallService = mInCallCallbacks.getService(); 522 final Call call1 = inCallService.getLastCall(); 523 assertCallState(call1, Call.STATE_DIALING); 524 525 connection1.setActive(); 526 527 assertCallState(call1, Call.STATE_ACTIVE); 528 529 placeAndVerifyCall(); 530 final MockConnection connection2 = verifyConnectionForOutgoingCall(1); 531 532 final Call call2 = inCallService.getLastCall(); 533 assertCallState(call2, Call.STATE_DIALING); 534 connection2.setActive(); 535 assertCallState(call2, Call.STATE_ACTIVE); 536 537 assertEquals("InCallService should have 2 calls", 2, inCallService.getCallCount()); 538 539 assertCanAddCall(inCallService, false, 540 "Should not be able to add call with two calls already present"); 541 542 call1.hold(); 543 assertCallState(call1, Call.STATE_HOLDING); 544 545 assertCanAddCall(inCallService, false, 546 "Should not be able to add call with two calls already present"); 547 } 548 549 public void testOnBringToForeground() { 550 if (!mShouldTestTelecom) { 551 return; 552 } 553 554 placeAndVerifyCall(); 555 verifyConnectionForOutgoingCall(); 556 557 final MockInCallService inCallService = mInCallCallbacks.getService(); 558 559 final Call call = inCallService.getLastCall(); 560 561 assertCallState(call, Call.STATE_DIALING); 562 563 assertEquals(0, mOnBringToForegroundCounter.getInvokeCount()); 564 565 final TelecomManager tm = 566 (TelecomManager) mContext.getSystemService(Context.TELECOM_SERVICE); 567 568 tm.showInCallScreen(false); 569 570 mOnBringToForegroundCounter.waitForCount(1, WAIT_FOR_STATE_CHANGE_TIMEOUT_MS); 571 572 assertFalse((Boolean) mOnBringToForegroundCounter.getArgs(0)[0]); 573 574 tm.showInCallScreen(true); 575 576 mOnBringToForegroundCounter.waitForCount(2, WAIT_FOR_STATE_CHANGE_TIMEOUT_MS); 577 578 assertTrue((Boolean) mOnBringToForegroundCounter.getArgs(1)[0]); 579 } 580 581 public void testSilenceRinger() { 582 if (!mShouldTestTelecom) { 583 return; 584 } 585 586 addAndVerifyNewIncomingCall(createTestNumber(), null); 587 final MockConnection connection = verifyConnectionForIncomingCall(); 588 final MockInCallService inCallService = mInCallCallbacks.getService(); 589 590 final TelecomManager telecomManager = 591 (TelecomManager) mContext.getSystemService(Context.TELECOM_SERVICE); 592 telecomManager.silenceRinger(); 593 mOnSilenceRingerCounter.waitForCount(1); 594 } 595 596 public void testOnPostDialWaitAndContinue() { 597 if (!mShouldTestTelecom) { 598 return; 599 } 600 601 placeAndVerifyCall(); 602 final MockConnection connection = verifyConnectionForOutgoingCall(); 603 final MockInCallService inCallService = mInCallCallbacks.getService(); 604 final Call call = inCallService.getLastCall(); 605 assertCallState(call, Call.STATE_DIALING); 606 607 connection.setActive(); 608 assertCallState(call, Call.STATE_ACTIVE); 609 610 final String postDialString = "12345"; 611 ((Connection) connection).setPostDialWait(postDialString); 612 mOnPostDialWaitCounter.waitForCount(1, WAIT_FOR_STATE_CHANGE_TIMEOUT_MS); 613 614 assertEquals(postDialString, mOnPostDialWaitCounter.getArgs(0)[1]); 615 assertEquals(postDialString, call.getRemainingPostDialSequence()); 616 617 final InvokeCounter counter = connection.getInvokeCounter(MockConnection.ON_POST_DIAL_WAIT); 618 619 call.postDialContinue(true); 620 counter.waitForCount(1); 621 assertTrue((Boolean) counter.getArgs(0)[0]); 622 623 call.postDialContinue(false); 624 counter.waitForCount(2); 625 assertFalse((Boolean) counter.getArgs(1)[0]); 626 } 627 628 public void testOnCannedTextResponsesLoaded() { 629 if (!mShouldTestTelecom) { 630 return; 631 } 632 633 TelephonyManager tm = (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE); 634 if (tm != null && !tm.isSmsCapable()) { 635 return ; 636 } 637 638 addAndVerifyNewIncomingCall(createTestNumber(), null); 639 verifyConnectionForIncomingCall(); 640 final MockInCallService inCallService = mInCallCallbacks.getService(); 641 642 final Call call = inCallService.getLastCall(); 643 644 assertCallState(call, Call.STATE_RINGING); 645 646 // We can't do much to enforce the number and type of responses that are preloaded on 647 // device, so the best we can do is to make sure that the call back is called and 648 // that the returned list is non-empty. 649 650 // This test should also verify that the callback is called as well, but unfortunately it 651 // is never called right now (b/22952515). 652 // mOnCannedTextResponsesLoadedCounter.waitForCount(1); 653 654 assertGetCannedTextResponsesNotEmpty(call); 655 } 656 657 public void testGetCalls() { 658 if (!mShouldTestTelecom) { 659 return; 660 } 661 662 placeAndVerifyCall(); 663 final MockConnection connection1 = verifyConnectionForOutgoingCall(0); 664 final MockInCallService inCallService = mInCallCallbacks.getService(); 665 final Call call1 = inCallService.getLastCall(); 666 assertCallState(call1, Call.STATE_DIALING); 667 668 connection1.setActive(); 669 670 assertCallState(call1, Call.STATE_ACTIVE); 671 672 List<Call> calls = inCallService.getCalls(); 673 assertEquals("InCallService.getCalls() should return list with 1 call.", 1, calls.size()); 674 assertEquals(call1, calls.get(0)); 675 676 addAndVerifyNewIncomingCall(createTestNumber(), null); 677 verifyConnectionForIncomingCall(); 678 679 final Call call2 = inCallService.getLastCall(); 680 calls = inCallService.getCalls(); 681 assertEquals("InCallService.getCalls() should return list with 2 calls.", 2, calls.size()); 682 assertEquals(call1, calls.get(0)); 683 assertEquals(call2, calls.get(1)); 684 } 685 686 private void assertGetCannedTextResponsesNotEmpty(final Call call) { 687 waitUntilConditionIsTrueOrTimeout( 688 new Condition() { 689 @Override 690 public Object expected() { 691 return true; 692 } 693 694 @Override 695 public Object actual() { 696 return call.getCannedTextResponses() != null 697 && !call.getCannedTextResponses().isEmpty(); 698 } 699 700 }, 701 WAIT_FOR_STATE_CHANGE_TIMEOUT_MS, 702 "Call.getCannedTextResponses should not be empty"); 703 } 704 705 private void assertCanAddCall(final InCallService inCallService, final boolean canAddCall, 706 String message) { 707 waitUntilConditionIsTrueOrTimeout( 708 new Condition() { 709 @Override 710 public Object expected() { 711 return canAddCall; 712 } 713 714 @Override 715 public Object actual() { 716 return inCallService.canAddCall(); 717 } 718 }, 719 WAIT_FOR_STATE_CHANGE_TIMEOUT_MS, 720 message 721 ); 722 } 723 } 724