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.graphics.SurfaceTexture; 22 import android.net.Uri; 23 import android.os.Bundle; 24 import android.os.Handler; 25 import android.os.HandlerThread; 26 import android.telecom.Call; 27 import android.telecom.Connection; 28 import android.telecom.ConnectionRequest; 29 import android.telecom.DisconnectCause; 30 import android.telecom.PhoneAccountHandle; 31 import android.telecom.RemoteConnection; 32 import android.telecom.RemoteConnection.VideoProvider; 33 import android.telecom.StatusHints; 34 import android.telecom.TelecomManager; 35 import android.telecom.VideoProfile; 36 import android.view.Surface; 37 38 import java.util.ArrayList; 39 import java.util.List; 40 41 /** 42 * Extended suite of tests that use {@link CtsConnectionService} and {@link MockInCallService} to 43 * verify the functionality of Remote Connections. 44 * We make 2 connections on the {@link CtsConnectionService} & we create 2 connections on the 45 * {@link CtsRemoteConnectionService} via the {@link RemoteConnection} object. We store this 46 * corresponding RemoteConnection object on the connections to plumb the modifications on 47 * the connections in {@link CtsConnectionService} to the connections on 48 * {@link CtsRemoteConnectionService}. 49 */ 50 public class RemoteConnectionTest extends BaseRemoteTelecomTest { 51 52 MockConnection mConnection; 53 MockConnection mRemoteConnection; 54 RemoteConnection mRemoteConnectionObject; 55 56 public void testRemoteConnectionOutgoingCall() { 57 if (!mShouldTestTelecom) { 58 return; 59 } 60 addRemoteConnectionOutgoingCall(); 61 final Call call = mInCallCallbacks.getService().getLastCall(); 62 assertCallState(call, Call.STATE_DIALING); 63 64 verifyRemoteConnectionObject(mRemoteConnectionObject, mRemoteConnection); 65 66 mConnection.setActive(); 67 mRemoteConnection.setActive(); 68 69 assertCallState(call, Call.STATE_ACTIVE); 70 assertConnectionState(mConnection, Connection.STATE_ACTIVE); 71 assertRemoteConnectionState(mRemoteConnectionObject, Connection.STATE_ACTIVE); 72 assertConnectionState(mRemoteConnection, Connection.STATE_ACTIVE); 73 74 call.hold(); 75 assertCallState(call, Call.STATE_HOLDING); 76 assertConnectionState(mConnection, Connection.STATE_HOLDING); 77 assertRemoteConnectionState(mRemoteConnectionObject, Connection.STATE_HOLDING); 78 assertConnectionState(mRemoteConnection, Connection.STATE_HOLDING); 79 80 call.unhold(); 81 assertCallState(call, Call.STATE_ACTIVE); 82 assertConnectionState(mConnection, Connection.STATE_ACTIVE); 83 assertRemoteConnectionState(mRemoteConnectionObject, Connection.STATE_ACTIVE); 84 assertConnectionState(mRemoteConnection, Connection.STATE_ACTIVE); 85 86 call.disconnect(); 87 assertCallState(call, Call.STATE_DISCONNECTED); 88 assertConnectionState(mConnection, Connection.STATE_DISCONNECTED); 89 assertRemoteConnectionState(mRemoteConnectionObject, Connection.STATE_DISCONNECTED); 90 assertConnectionState(mRemoteConnection, Connection.STATE_DISCONNECTED); 91 } 92 93 public void testRemoteConnectionIncomingCallAccept() { 94 if (!mShouldTestTelecom) { 95 return; 96 } 97 addRemoteConnectionIncomingCall(); 98 final Call call = mInCallCallbacks.getService().getLastCall(); 99 assertCallState(call, Call.STATE_RINGING); 100 101 verifyRemoteConnectionObject(mRemoteConnectionObject, mRemoteConnection); 102 103 assertConnectionState(mConnection, Connection.STATE_RINGING); 104 assertRemoteConnectionState(mRemoteConnectionObject, Connection.STATE_RINGING); 105 assertConnectionState(mRemoteConnection, Connection.STATE_RINGING); 106 107 call.answer(VideoProfile.STATE_AUDIO_ONLY); 108 assertCallState(call, Call.STATE_ACTIVE); 109 assertConnectionState(mConnection, Connection.STATE_ACTIVE); 110 assertRemoteConnectionState(mRemoteConnectionObject, Connection.STATE_ACTIVE); 111 assertConnectionState(mRemoteConnection, Connection.STATE_ACTIVE); 112 } 113 114 public void testRemoteConnectionIncomingCallReject() { 115 if (!mShouldTestTelecom) { 116 return; 117 } 118 addRemoteConnectionIncomingCall(); 119 final Call call = mInCallCallbacks.getService().getLastCall(); 120 assertCallState(call, Call.STATE_RINGING); 121 122 verifyRemoteConnectionObject(mRemoteConnectionObject, mRemoteConnection); 123 124 assertConnectionState(mConnection, Connection.STATE_RINGING); 125 assertRemoteConnectionState(mRemoteConnectionObject, Connection.STATE_RINGING); 126 assertConnectionState(mRemoteConnection, Connection.STATE_RINGING); 127 128 call.reject(false, null); 129 assertCallState(call, Call.STATE_DISCONNECTED); 130 assertConnectionState(mConnection, Connection.STATE_DISCONNECTED); 131 assertRemoteConnectionState(mRemoteConnectionObject, Connection.STATE_DISCONNECTED); 132 assertConnectionState(mRemoteConnection, Connection.STATE_DISCONNECTED); 133 } 134 135 public void testRemoteConnectionDTMFTone() { 136 if (!mShouldTestTelecom) { 137 return; 138 } 139 addRemoteConnectionIncomingCall(); 140 final Call call = mInCallCallbacks.getService().getLastCall(); 141 assertCallState(call, Call.STATE_RINGING); 142 143 verifyRemoteConnectionObject(mRemoteConnectionObject, mRemoteConnection); 144 145 assertTrue(mConnection.getDtmfString().isEmpty()); 146 assertTrue(mRemoteConnection.getDtmfString().isEmpty()); 147 call.playDtmfTone('1'); 148 assertDtmfString(mConnection, "1"); 149 assertDtmfString(mRemoteConnection, "1"); 150 call.stopDtmfTone(); 151 assertDtmfString(mConnection, "1."); 152 assertDtmfString(mRemoteConnection, "1."); 153 call.playDtmfTone('3'); 154 assertDtmfString(mConnection, "1.3"); 155 assertDtmfString(mRemoteConnection, "1.3"); 156 call.stopDtmfTone(); 157 assertDtmfString(mConnection, "1.3."); 158 assertDtmfString(mRemoteConnection, "1.3."); 159 } 160 161 public void testRemoteConnectionCallbacks_StateChange() { 162 if (!mShouldTestTelecom) { 163 return; 164 } 165 166 Handler handler = setupRemoteConnectionCallbacksTest(); 167 168 final InvokeCounter callbackInvoker = 169 new InvokeCounter("testRemoteConnectionCallbacks_StateChange"); 170 RemoteConnection.Callback callback; 171 172 callback = new RemoteConnection.Callback() { 173 @Override 174 public void onStateChanged(RemoteConnection connection, int state) { 175 super.onStateChanged(connection, state); 176 callbackInvoker.invoke(connection, state); 177 } 178 }; 179 mRemoteConnectionObject.registerCallback(callback, handler); 180 mRemoteConnection.setActive(); 181 callbackInvoker.waitForCount(1, WAIT_FOR_STATE_CHANGE_TIMEOUT_MS); 182 assertEquals(mRemoteConnectionObject, callbackInvoker.getArgs(0)[0]); 183 assertEquals(Connection.STATE_ACTIVE, callbackInvoker.getArgs(0)[1]); 184 mRemoteConnectionObject.unregisterCallback(callback); 185 } 186 187 public void testRemoteConnectionCallbacks_RingbackRequest() { 188 if (!mShouldTestTelecom) { 189 return; 190 } 191 192 Handler handler = setupRemoteConnectionCallbacksTest(); 193 194 final InvokeCounter callbackInvoker = 195 new InvokeCounter("testRemoteConnectionCallbacks_RingbackRequest"); 196 RemoteConnection.Callback callback; 197 198 callback = new RemoteConnection.Callback() { 199 @Override 200 public void onRingbackRequested(RemoteConnection connection, boolean ringback) { 201 super.onRingbackRequested(connection, ringback); 202 callbackInvoker.invoke(connection, ringback); 203 } 204 }; 205 mRemoteConnectionObject.registerCallback(callback, handler); 206 mRemoteConnection.setRingbackRequested(true); 207 callbackInvoker.waitForCount(1, WAIT_FOR_STATE_CHANGE_TIMEOUT_MS); 208 assertEquals(mRemoteConnectionObject, callbackInvoker.getArgs(0)[0]); 209 assertTrue((boolean) callbackInvoker.getArgs(0)[1]); 210 mRemoteConnectionObject.unregisterCallback(callback); 211 } 212 213 public void testRemoteConnectionCallbacks_ConnectionCapabilities() { 214 if (!mShouldTestTelecom) { 215 return; 216 } 217 218 Handler handler = setupRemoteConnectionCallbacksTest(); 219 220 final InvokeCounter callbackInvoker = 221 new InvokeCounter("testRemoteConnectionCallbacks_ConnectionCapabilities"); 222 RemoteConnection.Callback callback; 223 224 callback = new RemoteConnection.Callback() { 225 @Override 226 public void onConnectionCapabilitiesChanged( 227 RemoteConnection connection, 228 int connectionCapabilities) { 229 super.onConnectionCapabilitiesChanged(connection, connectionCapabilities); 230 callbackInvoker.invoke(connection, connectionCapabilities); 231 } 232 }; 233 mRemoteConnectionObject.registerCallback(callback, handler); 234 int capabilities = mRemoteConnection.getConnectionCapabilities() | Connection.CAPABILITY_MUTE; 235 mRemoteConnection.setConnectionCapabilities(capabilities); 236 callbackInvoker.waitForCount(1, WAIT_FOR_STATE_CHANGE_TIMEOUT_MS); 237 assertEquals(mRemoteConnectionObject, callbackInvoker.getArgs(0)[0]); 238 assertEquals(capabilities, callbackInvoker.getArgs(0)[1]); 239 mRemoteConnectionObject.unregisterCallback(callback); 240 } 241 242 public void testRemoteConnectionCallbacks_ConnectionProperties() { 243 if (!mShouldTestTelecom) { 244 return; 245 } 246 247 Handler handler = setupRemoteConnectionCallbacksTest(); 248 249 final InvokeCounter callbackInvoker = 250 new InvokeCounter("testRemoteConnectionCallbacks_ConnectionCapabilities"); 251 RemoteConnection.Callback callback; 252 253 callback = new RemoteConnection.Callback() { 254 @Override 255 public void onConnectionPropertiesChanged( 256 RemoteConnection connection, 257 int connectionProperties) { 258 super.onConnectionPropertiesChanged(connection, connectionProperties); 259 callbackInvoker.invoke(connection, connectionProperties); 260 } 261 }; 262 mRemoteConnectionObject.registerCallback(callback, handler); 263 int properties = mRemoteConnection.getConnectionCapabilities() 264 | Connection.PROPERTY_IS_EXTERNAL_CALL; 265 mRemoteConnection.setConnectionProperties(properties); 266 callbackInvoker.waitForCount(1, WAIT_FOR_STATE_CHANGE_TIMEOUT_MS); 267 assertEquals(mRemoteConnectionObject, callbackInvoker.getArgs(0)[0]); 268 assertEquals(properties, callbackInvoker.getArgs(0)[1]); 269 mRemoteConnectionObject.unregisterCallback(callback); 270 } 271 272 public void testRemoteConnectionCallbacks_PostDialWait() { 273 if (!mShouldTestTelecom) { 274 return; 275 } 276 277 Handler handler = setupRemoteConnectionCallbacksTest(); 278 279 final InvokeCounter callbackInvoker = 280 new InvokeCounter("testRemoteConnectionCallbacks_PostDialWait"); 281 RemoteConnection.Callback callback; 282 283 callback = new RemoteConnection.Callback() { 284 @Override 285 public void onPostDialWait(RemoteConnection connection, 286 String remainingPostDialSequence) { 287 super.onPostDialWait(connection, remainingPostDialSequence); 288 callbackInvoker.invoke(connection, remainingPostDialSequence); 289 } 290 }; 291 mRemoteConnectionObject.registerCallback(callback, handler); 292 String postDialSequence = "test"; 293 mRemoteConnection.setPostDialWait(postDialSequence); 294 callbackInvoker.waitForCount(1, WAIT_FOR_STATE_CHANGE_TIMEOUT_MS); 295 assertEquals(mRemoteConnectionObject, callbackInvoker.getArgs(0)[0]); 296 assertEquals(postDialSequence, callbackInvoker.getArgs(0)[1]); 297 mRemoteConnectionObject.unregisterCallback(callback); 298 } 299 300 public void testRemoteConnectionCallbacks_PostDialChar() { 301 if (!mShouldTestTelecom) { 302 return; 303 } 304 305 Handler handler = setupRemoteConnectionCallbacksTest(); 306 307 final InvokeCounter callbackInvoker = 308 new InvokeCounter("testRemoteConnectionCallbacks_PostDialChar"); 309 RemoteConnection.Callback callback; 310 311 callback = new RemoteConnection.Callback() { 312 @Override 313 public void onPostDialChar(RemoteConnection connection, char nextChar) { 314 super.onPostDialChar(connection, nextChar); 315 callbackInvoker.invoke(connection, nextChar); 316 } 317 }; 318 mRemoteConnectionObject.registerCallback(callback, handler); 319 char postDialChar = '3'; 320 ((Connection) mRemoteConnection).setNextPostDialChar(postDialChar); 321 callbackInvoker.waitForCount(1, WAIT_FOR_STATE_CHANGE_TIMEOUT_MS); 322 assertEquals(mRemoteConnectionObject, callbackInvoker.getArgs(0)[0]); 323 assertEquals(postDialChar, callbackInvoker.getArgs(0)[1]); 324 mRemoteConnectionObject.unregisterCallback(callback); 325 } 326 327 public void testRemoteConnectionCallbacks_VoipAudio() { 328 if (!mShouldTestTelecom) { 329 return; 330 } 331 332 Handler handler = setupRemoteConnectionCallbacksTest(); 333 334 final InvokeCounter callbackInvoker = 335 new InvokeCounter("testRemoteConnectionCallbacks_VoipAudio"); 336 RemoteConnection.Callback callback; 337 338 callback = new RemoteConnection.Callback() { 339 @Override 340 public void onVoipAudioChanged(RemoteConnection connection, boolean isVoip) { 341 super.onVoipAudioChanged(connection, isVoip); 342 callbackInvoker.invoke(connection, isVoip); 343 } 344 }; 345 mRemoteConnectionObject.registerCallback(callback, handler); 346 mRemoteConnection.setAudioModeIsVoip(true); 347 callbackInvoker.waitForCount(1, WAIT_FOR_STATE_CHANGE_TIMEOUT_MS); 348 assertEquals(mRemoteConnectionObject, callbackInvoker.getArgs(0)[0]); 349 assertTrue((boolean) callbackInvoker.getArgs(0)[1]); 350 mRemoteConnectionObject.unregisterCallback(callback); 351 } 352 353 public void testRemoteConnectionCallbacks_StatusHints() { 354 if (!mShouldTestTelecom) { 355 return; 356 } 357 358 Handler handler = setupRemoteConnectionCallbacksTest(); 359 360 final InvokeCounter callbackInvoker = 361 new InvokeCounter("testRemoteConnectionCallbacks_StatusHints"); 362 RemoteConnection.Callback callback; 363 364 callback = new RemoteConnection.Callback() { 365 @Override 366 public void onStatusHintsChanged(RemoteConnection connection, StatusHints statusHints) { 367 super.onStatusHintsChanged(connection, statusHints); 368 callbackInvoker.invoke(connection, statusHints); 369 } 370 }; 371 mRemoteConnectionObject.registerCallback(callback, handler); 372 StatusHints hints = new StatusHints("test", null, null); 373 mRemoteConnection.setStatusHints(hints); 374 callbackInvoker.waitForCount(1, WAIT_FOR_STATE_CHANGE_TIMEOUT_MS); 375 assertEquals(mRemoteConnectionObject, callbackInvoker.getArgs(0)[0]); 376 assertEquals(hints, callbackInvoker.getArgs(0)[1]); 377 mRemoteConnectionObject.unregisterCallback(callback); 378 } 379 380 public void testRemoteConnectionCallbacks_AddressChange() { 381 if (!mShouldTestTelecom) { 382 return; 383 } 384 385 Handler handler = setupRemoteConnectionCallbacksTest(); 386 387 final InvokeCounter callbackInvoker = 388 new InvokeCounter("testRemoteConnectionCallbacks_AddressChange"); 389 RemoteConnection.Callback callback; 390 391 callback = new RemoteConnection.Callback() { 392 @Override 393 public void onAddressChanged(RemoteConnection connection, Uri address, 394 int presentation) { 395 super.onAddressChanged(connection, address, presentation); 396 callbackInvoker.invoke(connection, address, presentation); 397 } 398 }; 399 mRemoteConnectionObject.registerCallback(callback, handler); 400 Uri address = Uri.parse("tel:555"); 401 mRemoteConnection.setAddress(address, TelecomManager.PRESENTATION_ALLOWED); 402 callbackInvoker.waitForCount(1, WAIT_FOR_STATE_CHANGE_TIMEOUT_MS); 403 assertEquals(mRemoteConnectionObject, callbackInvoker.getArgs(0)[0]); 404 assertEquals(address, callbackInvoker.getArgs(0)[1]); 405 assertEquals(TelecomManager.PRESENTATION_ALLOWED, callbackInvoker.getArgs(0)[2]); 406 mRemoteConnectionObject.unregisterCallback(callback); 407 } 408 409 public void testRemoteConnectionCallbacks_CallerDisplayName() { 410 if (!mShouldTestTelecom) { 411 return; 412 } 413 414 Handler handler = setupRemoteConnectionCallbacksTest(); 415 416 final InvokeCounter callbackInvoker = 417 new InvokeCounter("testRemoteConnectionCallbacks_CallerDisplayName"); 418 RemoteConnection.Callback callback; 419 420 callback = new RemoteConnection.Callback() { 421 @Override 422 public void onCallerDisplayNameChanged( 423 RemoteConnection connection, String callerDisplayName, int presentation) { 424 super.onCallerDisplayNameChanged(connection, callerDisplayName, presentation); 425 callbackInvoker.invoke(connection, callerDisplayName, presentation); 426 } 427 }; 428 mRemoteConnectionObject.registerCallback(callback, handler); 429 String callerDisplayName = "test"; 430 mRemoteConnection.setCallerDisplayName(callerDisplayName, TelecomManager.PRESENTATION_ALLOWED); 431 callbackInvoker.waitForCount(1, WAIT_FOR_STATE_CHANGE_TIMEOUT_MS); 432 assertEquals(mRemoteConnectionObject, callbackInvoker.getArgs(0)[0]); 433 assertEquals(callerDisplayName, callbackInvoker.getArgs(0)[1]); 434 assertEquals(TelecomManager.PRESENTATION_ALLOWED, callbackInvoker.getArgs(0)[2]); 435 mRemoteConnectionObject.unregisterCallback(callback); 436 } 437 438 public void testRemoteConnectionCallbacks_VideoState() { 439 if (!mShouldTestTelecom) { 440 return; 441 } 442 443 Handler handler = setupRemoteConnectionCallbacksTest(); 444 445 final InvokeCounter callbackInvoker = 446 new InvokeCounter("testRemoteConnectionCallbacks_VideoState"); 447 RemoteConnection.Callback callback; 448 449 callback = new RemoteConnection.Callback() { 450 @Override 451 public void onVideoStateChanged(RemoteConnection connection, int videoState) { 452 super.onVideoStateChanged(connection, videoState); 453 callbackInvoker.invoke(connection, videoState); 454 } 455 }; 456 mRemoteConnectionObject.registerCallback(callback, handler); 457 mRemoteConnection.setVideoState(VideoProfile.STATE_BIDIRECTIONAL); 458 callbackInvoker.waitForCount(1, WAIT_FOR_STATE_CHANGE_TIMEOUT_MS); 459 assertEquals(mRemoteConnectionObject, callbackInvoker.getArgs(0)[0]); 460 assertEquals(VideoProfile.STATE_BIDIRECTIONAL, callbackInvoker.getArgs(0)[1]); 461 mRemoteConnectionObject.unregisterCallback(callback); 462 } 463 464 public void testRemoteConnectionCallbacks_ConferenceableConnections() { 465 if (!mShouldTestTelecom) { 466 return; 467 } 468 469 Handler handler = setupRemoteConnectionCallbacksTest(); 470 471 final InvokeCounter callbackInvoker = 472 new InvokeCounter("testRemoteConnectionCallbacks_ConferenceableConnections"); 473 RemoteConnection.Callback callback; 474 475 callback = new RemoteConnection.Callback() { 476 @Override 477 public void onConferenceableConnectionsChanged( 478 RemoteConnection connection, 479 List<RemoteConnection> conferenceableConnections) { 480 super.onConferenceableConnectionsChanged(connection, conferenceableConnections); 481 callbackInvoker.invoke(connection, conferenceableConnections); 482 } 483 }; 484 mRemoteConnectionObject.registerCallback(callback, handler); 485 //Make the existing call active to add a new call 486 final Call call = mInCallCallbacks.getService().getLastCall(); 487 mConnection.setActive(); 488 mRemoteConnection.setActive(); 489 assertCallState(call, Call.STATE_ACTIVE); 490 placeAndVerifyCall(); 491 RemoteConnection newRemoteConnectionObject = 492 verifyConnectionForOutgoingCall(1).getRemoteConnection(); 493 MockConnection newConnection = verifyConnectionForOutgoingCallOnRemoteCS(1); 494 ArrayList<Connection> confList = new ArrayList<>(); 495 confList.add(newConnection); 496 mRemoteConnection.setConferenceableConnections(confList); 497 callbackInvoker.waitForCount(1, WAIT_FOR_STATE_CHANGE_TIMEOUT_MS); 498 assertEquals(mRemoteConnectionObject, callbackInvoker.getArgs(0)[0]); 499 //assertTrue(((List<RemoteConnection>)callbackInvoker.getArgs(0)[1]).contains( 500 //newRemoteConnectionObject)); No "equals" method in RemoteConnection 501 mRemoteConnectionObject.unregisterCallback(callback); 502 } 503 504 public void testRemoteConnectionCallbacks_VideoProvider() { 505 if (!mShouldTestTelecom) { 506 return; 507 } 508 509 Handler handler = setupRemoteConnectionCallbacksTest(); 510 511 final InvokeCounter callbackInvoker = 512 new InvokeCounter("testRemoteConnectionCallbacks_VideoProvider"); 513 RemoteConnection.Callback callback; 514 515 callback = new RemoteConnection.Callback() { 516 @Override 517 public void onVideoProviderChanged( 518 RemoteConnection connection, VideoProvider videoProvider) { 519 super.onVideoProviderChanged(connection, videoProvider); 520 callbackInvoker.invoke(connection, videoProvider); 521 } 522 }; 523 mRemoteConnectionObject.registerCallback(callback, handler); 524 mRemoteConnection.createMockVideoProvider(); 525 MockVideoProvider mockVideoProvider = mRemoteConnection.getMockVideoProvider(); 526 mRemoteConnection.setVideoProvider(mockVideoProvider); 527 callbackInvoker.waitForCount(1, WAIT_FOR_STATE_CHANGE_TIMEOUT_MS); 528 assertEquals(mRemoteConnectionObject, callbackInvoker.getArgs(0)[0]); 529 mRemoteConnectionObject.unregisterCallback(callback); 530 } 531 532 public void testRemoteConnectionCallbacks_Extras() { 533 if (!mShouldTestTelecom) { 534 return; 535 } 536 537 Handler handler = setupRemoteConnectionCallbacksTest(); 538 539 final InvokeCounter callbackInvoker = 540 new InvokeCounter("testRemoteConnectionCallbacks_Extras"); 541 RemoteConnection.Callback callback; 542 543 callback = new RemoteConnection.Callback() { 544 @Override 545 public void onExtrasChanged(RemoteConnection connection, Bundle extras) { 546 super.onExtrasChanged(connection, extras); 547 callbackInvoker.invoke(connection, extras); 548 } 549 }; 550 mRemoteConnectionObject.registerCallback(callback, handler); 551 Bundle extras = new Bundle(); 552 extras.putString(TelecomManager.EXTRA_CALL_DISCONNECT_MESSAGE, "Test"); 553 mRemoteConnection.setExtras(extras); 554 callbackInvoker.waitForCount(1, WAIT_FOR_STATE_CHANGE_TIMEOUT_MS); 555 assertEquals(mRemoteConnectionObject, callbackInvoker.getArgs(0)[0]); 556 assertTrue(areBundlesEqual(extras, (Bundle) callbackInvoker.getArgs(0)[1])); 557 mRemoteConnectionObject.unregisterCallback(callback); 558 } 559 560 /** 561 * Verifies that a {@link RemoteConnection} receives a 562 * {@link Connection#sendConnectionEvent(String, Bundle)} notification. 563 */ 564 public void testRemoteConnectionCallbacks_ConnectionEvent() { 565 if (!mShouldTestTelecom) { 566 return; 567 } 568 569 Handler handler = setupRemoteConnectionCallbacksTest(); 570 571 final InvokeCounter callbackInvoker = 572 new InvokeCounter("testRemoteConnectionCallbacks_Extras"); 573 RemoteConnection.Callback callback; 574 575 callback = new RemoteConnection.Callback() { 576 @Override 577 public void onConnectionEvent(RemoteConnection connection, String event, 578 Bundle extras) { 579 super.onConnectionEvent(connection, event, extras); 580 callbackInvoker.invoke(connection, event, extras); 581 } 582 }; 583 mRemoteConnectionObject.registerCallback(callback, handler); 584 Bundle extras = new Bundle(); 585 extras.putString(TelecomManager.EXTRA_CALL_DISCONNECT_MESSAGE, "Test"); 586 mRemoteConnection.sendConnectionEvent(Connection.EVENT_CALL_PULL_FAILED, extras); 587 callbackInvoker.waitForCount(1, WAIT_FOR_STATE_CHANGE_TIMEOUT_MS); 588 assertEquals(mRemoteConnectionObject, callbackInvoker.getArgs(0)[0]); 589 assertEquals(Connection.EVENT_CALL_PULL_FAILED, callbackInvoker.getArgs(0)[1]); 590 assertTrue(areBundlesEqual(extras, (Bundle) callbackInvoker.getArgs(0)[2])); 591 mRemoteConnectionObject.unregisterCallback(callback); 592 } 593 594 public void testRemoteConnectionCallbacks_Disconnect() { 595 if (!mShouldTestTelecom) { 596 return; 597 } 598 599 Handler handler = setupRemoteConnectionCallbacksTest(); 600 601 final InvokeCounter callbackInvoker = 602 new InvokeCounter("testRemoteConnectionCallbacks_Disconnect"); 603 RemoteConnection.Callback callback; 604 605 callback = new RemoteConnection.Callback() { 606 @Override 607 public void onDisconnected( 608 RemoteConnection connection, 609 DisconnectCause disconnectCause) { 610 super.onDisconnected(connection, disconnectCause); 611 callbackInvoker.invoke(connection, disconnectCause); 612 } 613 }; 614 mRemoteConnectionObject.registerCallback(callback, handler); 615 DisconnectCause cause = new DisconnectCause(DisconnectCause.LOCAL); 616 mRemoteConnection.setDisconnected(cause); 617 callbackInvoker.waitForCount(1, WAIT_FOR_STATE_CHANGE_TIMEOUT_MS); 618 assertEquals(mRemoteConnectionObject, callbackInvoker.getArgs(0)[0]); 619 assertEquals(cause, callbackInvoker.getArgs(0)[1]); 620 mRemoteConnectionObject.unregisterCallback(callback); 621 } 622 623 /** 624 * Verifies that a call to {@link RemoteConnection#pullExternalCall()} is proxied to 625 * {@link Connection#onPullExternalCall()}. 626 */ 627 public void testRemoteConnectionCallbacks_PullExternalCall() { 628 if (!mShouldTestTelecom) { 629 return; 630 } 631 632 Handler handler = setupRemoteConnectionCallbacksTest(); 633 634 InvokeCounter counter = 635 mRemoteConnection.getInvokeCounter(MockConnection.ON_PULL_EXTERNAL_CALL); 636 mRemoteConnectionObject.pullExternalCall(); 637 counter.waitForCount(1); 638 } 639 640 public void testRemoteConnectionCallbacks_Destroy() { 641 if (!mShouldTestTelecom) { 642 return; 643 } 644 645 Handler handler = setupRemoteConnectionCallbacksTest(); 646 647 final InvokeCounter callbackInvoker = 648 new InvokeCounter("testRemoteConnectionCallbacks_Destroy"); 649 RemoteConnection.Callback callback; 650 651 callback = new RemoteConnection.Callback() { 652 @Override 653 public void onDestroyed(RemoteConnection connection) { 654 super.onDestroyed(connection); 655 callbackInvoker.invoke(connection); 656 } 657 }; 658 mRemoteConnectionObject.registerCallback(callback, handler); 659 mRemoteConnection.destroy(); 660 callbackInvoker.waitForCount(1, WAIT_FOR_STATE_CHANGE_TIMEOUT_MS); 661 assertEquals(mRemoteConnectionObject, callbackInvoker.getArgs(0)[0]); 662 mRemoteConnectionObject.unregisterCallback(callback); 663 } 664 665 public void testRemoteConnectionVideoCallbacks_SessionModify() { 666 if (!mShouldTestTelecom) { 667 return; 668 } 669 670 setupRemoteConnectionVideoCallbacksTest(); 671 672 final InvokeCounter callbackInvoker = 673 new InvokeCounter("testRemoteConnectionVideoCallbacks_SessionModify"); 674 final VideoProvider remoteVideoProvider = mRemoteConnectionObject.getVideoProvider(); 675 final MockVideoProvider mockVideoProvider = mRemoteConnection.getMockVideoProvider(); 676 RemoteConnection.VideoProvider.Callback videoCallback; 677 678 videoCallback = new RemoteConnection.VideoProvider.Callback() { 679 @Override 680 public void onSessionModifyRequestReceived( 681 VideoProvider videoProvider, 682 VideoProfile videoProfile) { 683 super.onSessionModifyRequestReceived(videoProvider, videoProfile); 684 callbackInvoker.invoke(videoProvider, videoProfile); 685 } 686 687 @Override 688 public void onSessionModifyResponseReceived( 689 VideoProvider videoProvider, 690 int status, 691 VideoProfile requestedProfile, 692 VideoProfile responseProfile) { 693 super.onSessionModifyResponseReceived(videoProvider, status, requestedProfile, 694 responseProfile); 695 callbackInvoker.invoke(videoProvider, status, requestedProfile, responseProfile); 696 } 697 }; 698 remoteVideoProvider.registerCallback(videoCallback); 699 VideoProfile videoProfile = new VideoProfile(VideoProfile.STATE_BIDIRECTIONAL); 700 mockVideoProvider.waitForVideoProviderHandler(remoteVideoProvider); 701 mockVideoProvider.sendMockSessionModifyRequest(videoProfile); 702 callbackInvoker.waitForCount(1, WAIT_FOR_STATE_CHANGE_TIMEOUT_MS); 703 assertEquals(remoteVideoProvider, callbackInvoker.getArgs(0)[0]); 704 assertEquals(videoProfile, callbackInvoker.getArgs(0)[1]); 705 remoteVideoProvider.unregisterCallback(videoCallback); 706 } 707 708 public void testRemoteConnectionVideoCallbacks_SessionEvent() { 709 if (!mShouldTestTelecom) { 710 return; 711 } 712 713 setupRemoteConnectionVideoCallbacksTest(); 714 715 final InvokeCounter callbackInvoker = 716 new InvokeCounter("testRemoteConnectionVideoCallbacks_SessionEvent"); 717 final VideoProvider remoteVideoProvider = mRemoteConnectionObject.getVideoProvider(); 718 final MockVideoProvider mockVideoProvider = mRemoteConnection.getMockVideoProvider(); 719 RemoteConnection.VideoProvider.Callback videoCallback; 720 721 videoCallback = new RemoteConnection.VideoProvider.Callback() { 722 @Override 723 public void onCallSessionEvent(VideoProvider videoProvider, int event) { 724 super.onCallSessionEvent(videoProvider, event); 725 callbackInvoker.invoke(videoProvider, event); 726 } 727 }; 728 remoteVideoProvider.registerCallback(videoCallback); 729 mockVideoProvider.waitForVideoProviderHandler(remoteVideoProvider); 730 mockVideoProvider.handleCallSessionEvent(Connection.VideoProvider.SESSION_EVENT_RX_PAUSE); 731 callbackInvoker.waitForCount(1, WAIT_FOR_STATE_CHANGE_TIMEOUT_MS); 732 assertEquals(remoteVideoProvider, callbackInvoker.getArgs(0)[0]); 733 assertEquals(Connection.VideoProvider.SESSION_EVENT_RX_PAUSE, callbackInvoker.getArgs(0)[1]); 734 remoteVideoProvider.unregisterCallback(videoCallback); 735 } 736 737 public void testRemoteConnectionVideoCallbacks_PeerDimensions() { 738 if (!mShouldTestTelecom) { 739 return; 740 } 741 742 setupRemoteConnectionVideoCallbacksTest(); 743 744 final InvokeCounter callbackInvoker = 745 new InvokeCounter("testRemoteConnectionVideoCallbacks_PeerDimensions"); 746 final VideoProvider remoteVideoProvider = mRemoteConnectionObject.getVideoProvider(); 747 final MockVideoProvider mockVideoProvider = mRemoteConnection.getMockVideoProvider(); 748 RemoteConnection.VideoProvider.Callback videoCallback; 749 750 videoCallback = new RemoteConnection.VideoProvider.Callback() { 751 @Override 752 public void onPeerDimensionsChanged(VideoProvider videoProvider, int width, 753 int height) { 754 super.onPeerDimensionsChanged(videoProvider, width, height); 755 callbackInvoker.invoke(videoProvider, width, height); 756 } 757 }; 758 remoteVideoProvider.registerCallback(videoCallback); 759 final int width = 100, heigth = 20; 760 mockVideoProvider.waitForVideoProviderHandler(remoteVideoProvider); 761 mockVideoProvider.changePeerDimensions(width, heigth); 762 callbackInvoker.waitForCount(1, WAIT_FOR_STATE_CHANGE_TIMEOUT_MS); 763 assertEquals(remoteVideoProvider, callbackInvoker.getArgs(0)[0]); 764 assertEquals(width, callbackInvoker.getArgs(0)[1]); 765 assertEquals(heigth, callbackInvoker.getArgs(0)[2]); 766 remoteVideoProvider.unregisterCallback(videoCallback); 767 } 768 769 public void testRemoteConnectionVideoCallbacks_CallDataUsage() { 770 if (!mShouldTestTelecom) { 771 return; 772 } 773 774 setupRemoteConnectionVideoCallbacksTest(); 775 776 final InvokeCounter callbackInvoker = 777 new InvokeCounter("testRemoteConnectionVideoCallbacks_CallDataUsage"); 778 final VideoProvider remoteVideoProvider = mRemoteConnectionObject.getVideoProvider(); 779 final MockVideoProvider mockVideoProvider = mRemoteConnection.getMockVideoProvider(); 780 RemoteConnection.VideoProvider.Callback videoCallback; 781 782 videoCallback = new RemoteConnection.VideoProvider.Callback() { 783 @Override 784 public void onCallDataUsageChanged(VideoProvider videoProvider, long dataUsage) { 785 super.onCallDataUsageChanged(videoProvider, dataUsage); 786 callbackInvoker.invoke(videoProvider, dataUsage); 787 } 788 }; 789 remoteVideoProvider.registerCallback(videoCallback); 790 callbackInvoker.waitForCount(WAIT_FOR_STATE_CHANGE_TIMEOUT_CALLBACK); 791 long callDataUsage = 10000; 792 mockVideoProvider.waitForVideoProviderHandler(remoteVideoProvider); 793 mockVideoProvider.setCallDataUsage(callDataUsage); 794 callbackInvoker.waitForCount(1, WAIT_FOR_STATE_CHANGE_TIMEOUT_MS); 795 assertEquals(remoteVideoProvider, callbackInvoker.getArgs(0)[0]); 796 assertEquals(callDataUsage, callbackInvoker.getArgs(0)[1]); 797 remoteVideoProvider.unregisterCallback(videoCallback); 798 } 799 800 public void testRemoteConnectionVideoCallbacks_CameraCapabilities() { 801 if (!mShouldTestTelecom) { 802 return; 803 } 804 805 setupRemoteConnectionVideoCallbacksTest(); 806 807 final InvokeCounter callbackInvoker = 808 new InvokeCounter("testRemoteConnectionVideoCallbacks_CameraCapabilities"); 809 final VideoProvider remoteVideoProvider = mRemoteConnectionObject.getVideoProvider(); 810 final MockVideoProvider mockVideoProvider = mRemoteConnection.getMockVideoProvider(); 811 RemoteConnection.VideoProvider.Callback videoCallback; 812 813 videoCallback = new RemoteConnection.VideoProvider.Callback() { 814 @Override 815 public void onCameraCapabilitiesChanged( 816 VideoProvider videoProvider, 817 VideoProfile.CameraCapabilities cameraCapabilities) { 818 super.onCameraCapabilitiesChanged(videoProvider, cameraCapabilities); 819 callbackInvoker.invoke(videoProvider, cameraCapabilities); 820 } 821 }; 822 remoteVideoProvider.registerCallback(videoCallback); 823 VideoProfile.CameraCapabilities capabilities = new VideoProfile.CameraCapabilities(100, 200); 824 mockVideoProvider.waitForVideoProviderHandler(remoteVideoProvider); 825 mockVideoProvider.changeCameraCapabilities(capabilities); 826 callbackInvoker.waitForCount(1, WAIT_FOR_STATE_CHANGE_TIMEOUT_MS); 827 assertEquals(remoteVideoProvider, callbackInvoker.getArgs(0)[0]); 828 assertEquals(capabilities, callbackInvoker.getArgs(0)[1]); 829 remoteVideoProvider.unregisterCallback(videoCallback); 830 } 831 832 public void testRemoteConnectionVideoCallbacks_VideoQuality() { 833 if (!mShouldTestTelecom) { 834 return; 835 } 836 837 setupRemoteConnectionVideoCallbacksTest(); 838 839 final InvokeCounter callbackInvoker = 840 new InvokeCounter("testRemoteConnectionVideoCallbacks_VideoQuality"); 841 final VideoProvider remoteVideoProvider = mRemoteConnectionObject.getVideoProvider(); 842 final MockVideoProvider mockVideoProvider = mRemoteConnection.getMockVideoProvider(); 843 RemoteConnection.VideoProvider.Callback videoCallback; 844 845 videoCallback = new RemoteConnection.VideoProvider.Callback() { 846 @Override 847 public void onVideoQualityChanged(VideoProvider videoProvider, int videoQuality) { 848 super.onVideoQualityChanged(videoProvider, videoQuality); 849 callbackInvoker.invoke(videoProvider, videoQuality); 850 } 851 }; 852 remoteVideoProvider.registerCallback(videoCallback); 853 final int videoQuality = 10; 854 mockVideoProvider.waitForVideoProviderHandler(remoteVideoProvider); 855 mockVideoProvider.changeVideoQuality(videoQuality); 856 callbackInvoker.waitForCount(1, WAIT_FOR_STATE_CHANGE_TIMEOUT_MS); 857 assertEquals(remoteVideoProvider, callbackInvoker.getArgs(0)[0]); 858 assertEquals(videoQuality, callbackInvoker.getArgs(0)[1]); 859 remoteVideoProvider.unregisterCallback(videoCallback); 860 } 861 862 public void testRemoteConnectionVideo_RequestCallDataUsage() { 863 if (!mShouldTestTelecom) { 864 return; 865 } 866 867 final long callDataUsage = 10000; 868 final InvokeCounter callbackInvoker = 869 new InvokeCounter("testRemoteConnectionVideo_RequestCallDataUsage"); 870 final MockVideoProvider mockVideoProvider = new MockVideoProvider(mRemoteConnection) { 871 @Override 872 public void onRequestConnectionDataUsage() { 873 callbackInvoker.invoke(); 874 super.setCallDataUsage(callDataUsage); 875 } 876 }; 877 setupRemoteConnectionVideoTest(mockVideoProvider); 878 879 final VideoProvider remoteVideoProvider = mRemoteConnectionObject.getVideoProvider(); 880 RemoteConnection.VideoProvider.Callback videoCallback; 881 882 videoCallback = new RemoteConnection.VideoProvider.Callback() { 883 @Override 884 public void onCallDataUsageChanged(VideoProvider videoProvider, long dataUsage) { 885 super.onCallDataUsageChanged(videoProvider, dataUsage); 886 callbackInvoker.invoke(videoProvider, dataUsage); 887 } 888 }; 889 remoteVideoProvider.registerCallback(videoCallback); 890 remoteVideoProvider.requestCallDataUsage(); 891 callbackInvoker.waitForCount(2, WAIT_FOR_STATE_CHANGE_TIMEOUT_MS); 892 assertEquals(remoteVideoProvider, callbackInvoker.getArgs(1)[0]); 893 assertEquals(callDataUsage, callbackInvoker.getArgs(1)[1]); 894 remoteVideoProvider.unregisterCallback(videoCallback); 895 } 896 897 public void testRemoteConnectionVideo_RequestCameraCapabilities() { 898 if (!mShouldTestTelecom) { 899 return; 900 } 901 902 final VideoProfile.CameraCapabilities capabilities = 903 new VideoProfile.CameraCapabilities(100, 200); 904 final InvokeCounter callbackInvoker = 905 new InvokeCounter("testRemoteConnectionVideo_RequestCameraCapabilities"); 906 final MockVideoProvider mockVideoProvider = new MockVideoProvider(mRemoteConnection) { 907 @Override 908 public void onRequestCameraCapabilities() { 909 callbackInvoker.invoke(); 910 super.changeCameraCapabilities(capabilities); 911 } 912 }; 913 setupRemoteConnectionVideoTest(mockVideoProvider); 914 915 final VideoProvider remoteVideoProvider = mRemoteConnectionObject.getVideoProvider(); 916 RemoteConnection.VideoProvider.Callback videoCallback; 917 918 videoCallback = new RemoteConnection.VideoProvider.Callback() { 919 @Override 920 public void onCameraCapabilitiesChanged( 921 VideoProvider videoProvider, 922 VideoProfile.CameraCapabilities cameraCapabilities) { 923 super.onCameraCapabilitiesChanged(videoProvider, cameraCapabilities); 924 callbackInvoker.invoke(videoProvider, cameraCapabilities); 925 } 926 }; 927 remoteVideoProvider.registerCallback(videoCallback); 928 remoteVideoProvider.requestCameraCapabilities(); 929 callbackInvoker.waitForCount(2, WAIT_FOR_STATE_CHANGE_TIMEOUT_MS); 930 assertEquals(remoteVideoProvider, callbackInvoker.getArgs(1)[0]); 931 assertEquals(capabilities, callbackInvoker.getArgs(1)[1]); 932 remoteVideoProvider.unregisterCallback(videoCallback); 933 } 934 935 public void testRemoteConnectionVideo_SendSessionModifyRequest() { 936 if (!mShouldTestTelecom) { 937 return; 938 } 939 940 VideoProfile fromVideoProfile = new VideoProfile(VideoProfile.STATE_AUDIO_ONLY); 941 VideoProfile toVideoProfile = new VideoProfile(VideoProfile.STATE_BIDIRECTIONAL); 942 final InvokeCounter callbackInvoker = 943 new InvokeCounter("testRemoteConnectionVideo_SendSessionModifyRequest"); 944 final MockVideoProvider mockVideoProvider = new MockVideoProvider(mRemoteConnection) { 945 @Override 946 public void onSendSessionModifyRequest(VideoProfile fromProfile, 947 VideoProfile toProfile) { 948 callbackInvoker.invoke(fromProfile, toProfile); 949 super.receiveSessionModifyRequest(toProfile); 950 } 951 }; 952 setupRemoteConnectionVideoTest(mockVideoProvider); 953 954 final VideoProvider remoteVideoProvider = mRemoteConnectionObject.getVideoProvider(); 955 RemoteConnection.VideoProvider.Callback videoCallback; 956 957 videoCallback = new RemoteConnection.VideoProvider.Callback() { 958 @Override 959 public void onSessionModifyRequestReceived( 960 VideoProvider videoProvider, 961 VideoProfile videoProfile) { 962 super.onSessionModifyRequestReceived(videoProvider, videoProfile); 963 callbackInvoker.invoke(videoProvider, videoProfile); 964 } 965 }; 966 remoteVideoProvider.registerCallback(videoCallback); 967 remoteVideoProvider.sendSessionModifyRequest(fromVideoProfile, toVideoProfile); 968 callbackInvoker.waitForCount(2, WAIT_FOR_STATE_CHANGE_TIMEOUT_MS); 969 assertEquals(fromVideoProfile, callbackInvoker.getArgs(0)[0]); 970 assertEquals(toVideoProfile, callbackInvoker.getArgs(0)[1]); 971 assertEquals(remoteVideoProvider, callbackInvoker.getArgs(1)[0]); 972 assertEquals(toVideoProfile, callbackInvoker.getArgs(1)[1]); 973 remoteVideoProvider.unregisterCallback(videoCallback); 974 } 975 976 public void testRemoteConnectionVideo_SendSessionModifyResponse() { 977 if (!mShouldTestTelecom) { 978 return; 979 } 980 981 VideoProfile toVideoProfile = new VideoProfile(VideoProfile.STATE_BIDIRECTIONAL); 982 final InvokeCounter callbackInvoker = 983 new InvokeCounter("testRemoteConnectionVideo_SendSessionModifyResponse"); 984 final MockVideoProvider mockVideoProvider = new MockVideoProvider(mRemoteConnection) { 985 @Override 986 public void onSendSessionModifyResponse(VideoProfile responseProfile) { 987 callbackInvoker.invoke(responseProfile); 988 super.receiveSessionModifyResponse( 989 Connection.VideoProvider.SESSION_MODIFY_REQUEST_SUCCESS, 990 responseProfile, responseProfile); 991 } 992 }; 993 setupRemoteConnectionVideoTest(mockVideoProvider); 994 995 final VideoProvider remoteVideoProvider = mRemoteConnectionObject.getVideoProvider(); 996 RemoteConnection.VideoProvider.Callback videoCallback; 997 998 videoCallback = new RemoteConnection.VideoProvider.Callback() { 999 @Override 1000 public void onSessionModifyResponseReceived( 1001 VideoProvider videoProvider, 1002 int status, 1003 VideoProfile requestedProfile, 1004 VideoProfile responseProfile) { 1005 super.onSessionModifyResponseReceived(videoProvider, status, requestedProfile, 1006 responseProfile); 1007 callbackInvoker.invoke(videoProvider, status, requestedProfile, responseProfile); 1008 } 1009 }; 1010 remoteVideoProvider.registerCallback(videoCallback); 1011 remoteVideoProvider.sendSessionModifyResponse(toVideoProfile); 1012 callbackInvoker.waitForCount(2, WAIT_FOR_STATE_CHANGE_TIMEOUT_MS); 1013 assertEquals(toVideoProfile, callbackInvoker.getArgs(0)[0]); 1014 assertEquals(remoteVideoProvider, callbackInvoker.getArgs(1)[0]); 1015 assertEquals(toVideoProfile, callbackInvoker.getArgs(1)[2]); 1016 assertEquals(Connection.VideoProvider.SESSION_MODIFY_REQUEST_SUCCESS, 1017 callbackInvoker.getArgs(1)[1]); 1018 assertEquals(toVideoProfile, callbackInvoker.getArgs(1)[3]); 1019 remoteVideoProvider.unregisterCallback(videoCallback); 1020 } 1021 1022 public void testRemoteConnectionVideo_SetCamera() { 1023 if (!mShouldTestTelecom) { 1024 return; 1025 } 1026 1027 final String newCameraId = "5"; 1028 final VideoProfile.CameraCapabilities capabilities = 1029 new VideoProfile.CameraCapabilities(100, 200); 1030 final InvokeCounter callbackInvoker = 1031 new InvokeCounter("testRemoteConnectionVideo_SetCamera"); 1032 final MockVideoProvider mockVideoProvider = new MockVideoProvider(mRemoteConnection) { 1033 @Override 1034 public void onSetCamera(String cameraId) { 1035 callbackInvoker.invoke(cameraId); 1036 super.changeCameraCapabilities(capabilities); 1037 } 1038 }; 1039 setupRemoteConnectionVideoTest(mockVideoProvider); 1040 1041 final VideoProvider remoteVideoProvider = mRemoteConnectionObject.getVideoProvider(); 1042 RemoteConnection.VideoProvider.Callback videoCallback; 1043 1044 videoCallback = new RemoteConnection.VideoProvider.Callback() { 1045 @Override 1046 public void onCameraCapabilitiesChanged( 1047 VideoProvider videoProvider, 1048 VideoProfile.CameraCapabilities cameraCapabilities) { 1049 super.onCameraCapabilitiesChanged(videoProvider, cameraCapabilities); 1050 callbackInvoker.invoke(videoProvider, cameraCapabilities); 1051 } 1052 }; 1053 remoteVideoProvider.registerCallback(videoCallback); 1054 remoteVideoProvider.setCamera(newCameraId); 1055 callbackInvoker.waitForCount(2, WAIT_FOR_STATE_CHANGE_TIMEOUT_MS); 1056 assertEquals(newCameraId, callbackInvoker.getArgs(0)[0]); 1057 assertEquals(remoteVideoProvider, callbackInvoker.getArgs(1)[0]); 1058 assertEquals(capabilities, callbackInvoker.getArgs(1)[1]); 1059 remoteVideoProvider.unregisterCallback(videoCallback); 1060 } 1061 1062 public void testRemoteConnectionVideo_SetDeviceOrientation() { 1063 if (!mShouldTestTelecom) { 1064 return; 1065 } 1066 1067 final int newRotation = 5; 1068 final InvokeCounter callbackInvoker = 1069 new InvokeCounter("testRemoteConnectionVideo_SetDeviceOrientation"); 1070 final MockVideoProvider mockVideoProvider = new MockVideoProvider(mRemoteConnection) { 1071 @Override 1072 public void onSetDeviceOrientation(int rotation) { 1073 callbackInvoker.invoke(rotation); 1074 } 1075 }; 1076 setupRemoteConnectionVideoTest(mockVideoProvider); 1077 1078 final VideoProvider remoteVideoProvider = mRemoteConnectionObject.getVideoProvider(); 1079 1080 remoteVideoProvider.setDeviceOrientation(newRotation); 1081 callbackInvoker.waitForCount(1, WAIT_FOR_STATE_CHANGE_TIMEOUT_MS); 1082 assertEquals(newRotation, callbackInvoker.getArgs(0)[0]); 1083 } 1084 1085 public void testRemoteConnectionVideo_SetDisplaySurface() { 1086 if (!mShouldTestTelecom) { 1087 return; 1088 } 1089 1090 final Surface newSurface = new Surface(new SurfaceTexture(1)); 1091 final InvokeCounter callbackInvoker = 1092 new InvokeCounter("testRemoteConnectionVideo_SetDisplaySurface"); 1093 final MockVideoProvider mockVideoProvider = new MockVideoProvider(mRemoteConnection) { 1094 @Override 1095 public void onSetDisplaySurface(Surface surface) { 1096 callbackInvoker.invoke(surface); 1097 } 1098 }; 1099 setupRemoteConnectionVideoTest(mockVideoProvider); 1100 1101 final VideoProvider remoteVideoProvider = mRemoteConnectionObject.getVideoProvider(); 1102 1103 remoteVideoProvider.setDisplaySurface(newSurface); 1104 callbackInvoker.waitForCount(1, WAIT_FOR_STATE_CHANGE_TIMEOUT_MS); 1105 assertEquals(newSurface, callbackInvoker.getArgs(0)[0]); 1106 } 1107 1108 public void testRemoteConnectionVideo_SetPauseImage() { 1109 if (!mShouldTestTelecom) { 1110 return; 1111 } 1112 1113 final Uri newUri = Uri.parse("content://"); 1114 final InvokeCounter callbackInvoker = 1115 new InvokeCounter("testRemoteConnectionVideo_SetPauseImage"); 1116 final MockVideoProvider mockVideoProvider = new MockVideoProvider(mRemoteConnection) { 1117 @Override 1118 public void onSetPauseImage(Uri uri) { 1119 callbackInvoker.invoke(uri); 1120 } 1121 }; 1122 setupRemoteConnectionVideoTest(mockVideoProvider); 1123 1124 final VideoProvider remoteVideoProvider = mRemoteConnectionObject.getVideoProvider(); 1125 1126 remoteVideoProvider.setPauseImage(newUri); 1127 callbackInvoker.waitForCount(1, WAIT_FOR_STATE_CHANGE_TIMEOUT_MS); 1128 assertEquals(newUri, callbackInvoker.getArgs(0)[0]); 1129 } 1130 1131 public void testRemoteConnectionVideo_SetPreviewSurface() { 1132 if (!mShouldTestTelecom) { 1133 return; 1134 } 1135 1136 final Surface newSurface = new Surface(new SurfaceTexture(1)); 1137 final InvokeCounter callbackInvoker = 1138 new InvokeCounter("testRemoteConnectionVideo_SetPreviewSurface"); 1139 final MockVideoProvider mockVideoProvider = new MockVideoProvider(mRemoteConnection) { 1140 @Override 1141 public void onSetPreviewSurface(Surface surface) { 1142 callbackInvoker.invoke(surface); 1143 } 1144 }; 1145 setupRemoteConnectionVideoTest(mockVideoProvider); 1146 1147 final VideoProvider remoteVideoProvider = mRemoteConnectionObject.getVideoProvider(); 1148 1149 remoteVideoProvider.setPreviewSurface(newSurface); 1150 callbackInvoker.waitForCount(1, WAIT_FOR_STATE_CHANGE_TIMEOUT_MS); 1151 assertEquals(newSurface, callbackInvoker.getArgs(0)[0]); 1152 } 1153 1154 public void testRemoteConnectionVideo_SetZoom() { 1155 if (!mShouldTestTelecom) { 1156 return; 1157 } 1158 1159 final float newZoom = 1.0f; 1160 final InvokeCounter callbackInvoker = 1161 new InvokeCounter("testRemoteConnectionVideo_SetPreviewSurface"); 1162 final MockVideoProvider mockVideoProvider = new MockVideoProvider(mRemoteConnection) { 1163 @Override 1164 public void onSetZoom(float value) { 1165 callbackInvoker.invoke(value); 1166 } 1167 }; 1168 setupRemoteConnectionVideoTest(mockVideoProvider); 1169 1170 final VideoProvider remoteVideoProvider = mRemoteConnectionObject.getVideoProvider(); 1171 1172 remoteVideoProvider.setZoom(newZoom); 1173 callbackInvoker.waitForCount(1, WAIT_FOR_STATE_CHANGE_TIMEOUT_MS); 1174 assertEquals(newZoom, callbackInvoker.getArgs(0)[0]); 1175 } 1176 1177 private void verifyRemoteConnectionObject(RemoteConnection remoteConnection, 1178 Connection connection) { 1179 assertEquals(connection.getAddress(), remoteConnection.getAddress()); 1180 assertEquals(connection.getAddressPresentation(), 1181 remoteConnection.getAddressPresentation()); 1182 assertEquals(connection.getCallerDisplayName(), remoteConnection.getCallerDisplayName()); 1183 assertEquals(connection.getCallerDisplayNamePresentation(), 1184 remoteConnection.getCallerDisplayNamePresentation()); 1185 assertEquals(connection.getConnectionCapabilities(), 1186 remoteConnection.getConnectionCapabilities()); 1187 assertEquals(connection.getConnectionProperties(), 1188 remoteConnection.getConnectionProperties()); 1189 assertEquals(connection.getDisconnectCause(), remoteConnection.getDisconnectCause()); 1190 assertEquals(connection.getExtras(), remoteConnection.getExtras()); 1191 assertEquals(connection.getStatusHints(), remoteConnection.getStatusHints()); 1192 assertEquals(VideoProfile.STATE_AUDIO_ONLY, remoteConnection.getVideoState()); 1193 assertNull(remoteConnection.getVideoProvider()); 1194 assertTrue(remoteConnection.getConferenceableConnections().isEmpty()); 1195 } 1196 1197 private void addRemoteConnectionOutgoingCall() { 1198 try { 1199 MockConnectionService managerConnectionService = new MockConnectionService() { 1200 @Override 1201 public Connection onCreateOutgoingConnection( 1202 PhoneAccountHandle connectionManagerPhoneAccount, 1203 ConnectionRequest request) { 1204 MockConnection connection = (MockConnection)super.onCreateOutgoingConnection( 1205 connectionManagerPhoneAccount, request); 1206 ConnectionRequest remoteRequest = new ConnectionRequest( 1207 TEST_REMOTE_PHONE_ACCOUNT_HANDLE, 1208 request.getAddress(), 1209 request.getExtras()); 1210 RemoteConnection remoteConnection = 1211 CtsConnectionService.createRemoteOutgoingConnectionToTelecom( 1212 TEST_REMOTE_PHONE_ACCOUNT_HANDLE, remoteRequest); 1213 connection.setRemoteConnection(remoteConnection); 1214 return connection; 1215 } 1216 }; 1217 setupConnectionServices(managerConnectionService, null, FLAG_REGISTER | FLAG_ENABLE); 1218 } catch(Exception e) { 1219 fail("Error in setting up the connection services"); 1220 } 1221 placeAndVerifyCall(); 1222 /** 1223 * Retrieve the connection from both the connection services and see if the plumbing via 1224 * RemoteConnection object is working. 1225 */ 1226 mConnection = verifyConnectionForOutgoingCall(); 1227 mRemoteConnection = verifyConnectionForOutgoingCallOnRemoteCS(); 1228 mRemoteConnectionObject = mConnection.getRemoteConnection(); 1229 } 1230 1231 private void addRemoteConnectionIncomingCall() { 1232 try { 1233 MockConnectionService managerConnectionService = new MockConnectionService() { 1234 @Override 1235 public Connection onCreateIncomingConnection( 1236 PhoneAccountHandle connectionManagerPhoneAccount, 1237 ConnectionRequest request) { 1238 MockConnection connection = (MockConnection)super.onCreateIncomingConnection( 1239 connectionManagerPhoneAccount, request); 1240 ConnectionRequest remoteRequest = new ConnectionRequest( 1241 TEST_REMOTE_PHONE_ACCOUNT_HANDLE, 1242 request.getAddress(), 1243 request.getExtras()); 1244 RemoteConnection remoteConnection = 1245 CtsConnectionService.createRemoteIncomingConnectionToTelecom( 1246 TEST_REMOTE_PHONE_ACCOUNT_HANDLE, remoteRequest); 1247 connection.setRemoteConnection(remoteConnection); 1248 return connection; 1249 } 1250 }; 1251 setupConnectionServices(managerConnectionService, null, FLAG_REGISTER | FLAG_ENABLE); 1252 } catch(Exception e) { 1253 fail("Error in setting up the connection services"); 1254 } 1255 addAndVerifyNewIncomingCall(createTestNumber(), null); 1256 /** 1257 * Retrieve the connection from both the connection services and see if the plumbing via 1258 * RemoteConnection object is working. 1259 */ 1260 mConnection = verifyConnectionForIncomingCall(); 1261 mRemoteConnection = verifyConnectionForIncomingCallOnRemoteCS(); 1262 mRemoteConnectionObject = mConnection.getRemoteConnection(); 1263 } 1264 1265 private Handler setupRemoteConnectionCallbacksTest() { 1266 addRemoteConnectionOutgoingCall(); 1267 final Call call = mInCallCallbacks.getService().getLastCall(); 1268 assertCallState(call, Call.STATE_DIALING); 1269 verifyRemoteConnectionObject(mRemoteConnectionObject, mRemoteConnection); 1270 1271 // Create a looper thread for the callbacks. 1272 HandlerThread workerThread = new HandlerThread("CallbackThread"); 1273 workerThread.start(); 1274 Handler handler = new Handler(workerThread.getLooper()); 1275 return handler; 1276 } 1277 1278 private Handler setupRemoteConnectionVideoCallbacksTest() { 1279 addRemoteConnectionOutgoingCall(); 1280 final Call call = mInCallCallbacks.getService().getLastCall(); 1281 assertCallState(call, Call.STATE_DIALING); 1282 verifyRemoteConnectionObject(mRemoteConnectionObject, mRemoteConnection); 1283 1284 // Create a looper thread for the callbacks. 1285 HandlerThread workerThread = new HandlerThread("CallbackThread"); 1286 workerThread.start(); 1287 Handler handler = new Handler(workerThread.getLooper()); 1288 1289 final InvokeCounter callbackInvoker = new InvokeCounter("RemoteConnectionCallbacks"); 1290 1291 RemoteConnection.Callback callback = new RemoteConnection.Callback() { 1292 @Override 1293 public void onVideoProviderChanged( 1294 RemoteConnection connection, VideoProvider videoProvider) { 1295 callbackInvoker.invoke(connection, videoProvider); 1296 } 1297 }; 1298 mRemoteConnectionObject.registerCallback(callback, handler); 1299 mRemoteConnection.createMockVideoProvider(); 1300 callbackInvoker.waitForCount(1, WAIT_FOR_STATE_CHANGE_TIMEOUT_MS); 1301 assertEquals(mRemoteConnectionObject, callbackInvoker.getArgs(0)[0]); 1302 mRemoteConnectionObject.unregisterCallback(callback); 1303 return handler; 1304 } 1305 1306 private Handler setupRemoteConnectionVideoTest(MockVideoProvider mockVideoProvider) { 1307 addRemoteConnectionOutgoingCall(); 1308 final Call call = mInCallCallbacks.getService().getLastCall(); 1309 assertCallState(call, Call.STATE_DIALING); 1310 verifyRemoteConnectionObject(mRemoteConnectionObject, mRemoteConnection); 1311 1312 // Create a looper thread for the callbacks. 1313 HandlerThread workerThread = new HandlerThread("CallbackThread"); 1314 workerThread.start(); 1315 Handler handler = new Handler(workerThread.getLooper()); 1316 1317 final InvokeCounter callbackInvoker = new InvokeCounter("RemoteConnectionCallbacks"); 1318 1319 RemoteConnection.Callback callback = new RemoteConnection.Callback() { 1320 @Override 1321 public void onVideoProviderChanged( 1322 RemoteConnection connection, VideoProvider videoProvider) { 1323 callbackInvoker.invoke(connection, videoProvider); 1324 } 1325 }; 1326 mRemoteConnectionObject.registerCallback(callback, handler); 1327 mRemoteConnection.setVideoProvider(mockVideoProvider); 1328 callbackInvoker.waitForCount(1, WAIT_FOR_STATE_CHANGE_TIMEOUT_MS); 1329 assertEquals(mRemoteConnectionObject, callbackInvoker.getArgs(0)[0]); 1330 mRemoteConnectionObject.unregisterCallback(callback); 1331 return handler; 1332 } 1333 } 1334