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