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 Bundle changedExtras = (Bundle) callbackInvoker.getArgs(0)[1]; 557 assertTrue(changedExtras.containsKey(TelecomManager.EXTRA_CALL_DISCONNECT_MESSAGE)); 558 mRemoteConnectionObject.unregisterCallback(callback); 559 } 560 561 /** 562 * Verifies that a {@link RemoteConnection} receives a 563 * {@link Connection#sendConnectionEvent(String, Bundle)} notification. 564 */ 565 public void testRemoteConnectionCallbacks_ConnectionEvent() { 566 if (!mShouldTestTelecom) { 567 return; 568 } 569 570 Handler handler = setupRemoteConnectionCallbacksTest(); 571 572 final InvokeCounter callbackInvoker = 573 new InvokeCounter("testRemoteConnectionCallbacks_Extras"); 574 RemoteConnection.Callback callback; 575 576 callback = new RemoteConnection.Callback() { 577 @Override 578 public void onConnectionEvent(RemoteConnection connection, String event, 579 Bundle extras) { 580 super.onConnectionEvent(connection, event, extras); 581 callbackInvoker.invoke(connection, event, extras); 582 } 583 }; 584 mRemoteConnectionObject.registerCallback(callback, handler); 585 Bundle extras = new Bundle(); 586 extras.putString(TelecomManager.EXTRA_CALL_DISCONNECT_MESSAGE, "Test"); 587 mRemoteConnection.sendConnectionEvent(Connection.EVENT_CALL_PULL_FAILED, extras); 588 callbackInvoker.waitForCount(1, WAIT_FOR_STATE_CHANGE_TIMEOUT_MS); 589 assertEquals(mRemoteConnectionObject, callbackInvoker.getArgs(0)[0]); 590 assertEquals(Connection.EVENT_CALL_PULL_FAILED, callbackInvoker.getArgs(0)[1]); 591 assertTrue(areBundlesEqual(extras, (Bundle) callbackInvoker.getArgs(0)[2])); 592 mRemoteConnectionObject.unregisterCallback(callback); 593 } 594 595 public void testRemoteConnectionCallbacks_Disconnect() { 596 if (!mShouldTestTelecom) { 597 return; 598 } 599 600 Handler handler = setupRemoteConnectionCallbacksTest(); 601 602 final InvokeCounter callbackInvoker = 603 new InvokeCounter("testRemoteConnectionCallbacks_Disconnect"); 604 RemoteConnection.Callback callback; 605 606 callback = new RemoteConnection.Callback() { 607 @Override 608 public void onDisconnected( 609 RemoteConnection connection, 610 DisconnectCause disconnectCause) { 611 super.onDisconnected(connection, disconnectCause); 612 callbackInvoker.invoke(connection, disconnectCause); 613 } 614 }; 615 mRemoteConnectionObject.registerCallback(callback, handler); 616 DisconnectCause cause = new DisconnectCause(DisconnectCause.LOCAL); 617 mRemoteConnection.setDisconnected(cause); 618 callbackInvoker.waitForCount(1, WAIT_FOR_STATE_CHANGE_TIMEOUT_MS); 619 assertEquals(mRemoteConnectionObject, callbackInvoker.getArgs(0)[0]); 620 assertEquals(cause, callbackInvoker.getArgs(0)[1]); 621 mRemoteConnectionObject.unregisterCallback(callback); 622 } 623 624 /** 625 * Verifies that a call to {@link RemoteConnection#pullExternalCall()} is proxied to 626 * {@link Connection#onPullExternalCall()}. 627 */ 628 public void testRemoteConnectionCallbacks_PullExternalCall() { 629 if (!mShouldTestTelecom) { 630 return; 631 } 632 633 Handler handler = setupRemoteConnectionCallbacksTest(); 634 635 InvokeCounter counter = 636 mRemoteConnection.getInvokeCounter(MockConnection.ON_PULL_EXTERNAL_CALL); 637 mRemoteConnectionObject.pullExternalCall(); 638 counter.waitForCount(1); 639 } 640 641 public void testRemoteConnectionCallbacks_Destroy() { 642 if (!mShouldTestTelecom) { 643 return; 644 } 645 646 Handler handler = setupRemoteConnectionCallbacksTest(); 647 648 final InvokeCounter callbackInvoker = 649 new InvokeCounter("testRemoteConnectionCallbacks_Destroy"); 650 RemoteConnection.Callback callback; 651 652 callback = new RemoteConnection.Callback() { 653 @Override 654 public void onDestroyed(RemoteConnection connection) { 655 super.onDestroyed(connection); 656 callbackInvoker.invoke(connection); 657 } 658 }; 659 mRemoteConnectionObject.registerCallback(callback, handler); 660 mRemoteConnection.destroy(); 661 callbackInvoker.waitForCount(1, WAIT_FOR_STATE_CHANGE_TIMEOUT_MS); 662 assertEquals(mRemoteConnectionObject, callbackInvoker.getArgs(0)[0]); 663 mRemoteConnectionObject.unregisterCallback(callback); 664 } 665 666 public void testRemoteConnectionVideoCallbacks_SessionModify() { 667 if (!mShouldTestTelecom) { 668 return; 669 } 670 671 setupRemoteConnectionVideoCallbacksTest(); 672 673 final InvokeCounter callbackInvoker = 674 new InvokeCounter("testRemoteConnectionVideoCallbacks_SessionModify"); 675 final VideoProvider remoteVideoProvider = mRemoteConnectionObject.getVideoProvider(); 676 final MockVideoProvider mockVideoProvider = mRemoteConnection.getMockVideoProvider(); 677 RemoteConnection.VideoProvider.Callback videoCallback; 678 679 videoCallback = new RemoteConnection.VideoProvider.Callback() { 680 @Override 681 public void onSessionModifyRequestReceived( 682 VideoProvider videoProvider, 683 VideoProfile videoProfile) { 684 super.onSessionModifyRequestReceived(videoProvider, videoProfile); 685 callbackInvoker.invoke(videoProvider, videoProfile); 686 } 687 688 @Override 689 public void onSessionModifyResponseReceived( 690 VideoProvider videoProvider, 691 int status, 692 VideoProfile requestedProfile, 693 VideoProfile responseProfile) { 694 super.onSessionModifyResponseReceived(videoProvider, status, requestedProfile, 695 responseProfile); 696 callbackInvoker.invoke(videoProvider, status, requestedProfile, responseProfile); 697 } 698 }; 699 remoteVideoProvider.registerCallback(videoCallback); 700 VideoProfile videoProfile = new VideoProfile(VideoProfile.STATE_BIDIRECTIONAL); 701 mockVideoProvider.waitForVideoProviderHandler(remoteVideoProvider); 702 mockVideoProvider.sendMockSessionModifyRequest(videoProfile); 703 callbackInvoker.waitForCount(1, WAIT_FOR_STATE_CHANGE_TIMEOUT_MS); 704 assertEquals(remoteVideoProvider, callbackInvoker.getArgs(0)[0]); 705 assertEquals(videoProfile, callbackInvoker.getArgs(0)[1]); 706 remoteVideoProvider.unregisterCallback(videoCallback); 707 } 708 709 public void testRemoteConnectionVideoCallbacks_SessionEvent() { 710 if (!mShouldTestTelecom) { 711 return; 712 } 713 714 setupRemoteConnectionVideoCallbacksTest(); 715 716 final InvokeCounter callbackInvoker = 717 new InvokeCounter("testRemoteConnectionVideoCallbacks_SessionEvent"); 718 final VideoProvider remoteVideoProvider = mRemoteConnectionObject.getVideoProvider(); 719 final MockVideoProvider mockVideoProvider = mRemoteConnection.getMockVideoProvider(); 720 RemoteConnection.VideoProvider.Callback videoCallback; 721 722 videoCallback = new RemoteConnection.VideoProvider.Callback() { 723 @Override 724 public void onCallSessionEvent(VideoProvider videoProvider, int event) { 725 super.onCallSessionEvent(videoProvider, event); 726 callbackInvoker.invoke(videoProvider, event); 727 } 728 }; 729 remoteVideoProvider.registerCallback(videoCallback); 730 mockVideoProvider.waitForVideoProviderHandler(remoteVideoProvider); 731 mockVideoProvider.handleCallSessionEvent(Connection.VideoProvider.SESSION_EVENT_RX_PAUSE); 732 callbackInvoker.waitForCount(1, WAIT_FOR_STATE_CHANGE_TIMEOUT_MS); 733 assertEquals(remoteVideoProvider, callbackInvoker.getArgs(0)[0]); 734 assertEquals(Connection.VideoProvider.SESSION_EVENT_RX_PAUSE, callbackInvoker.getArgs(0)[1]); 735 remoteVideoProvider.unregisterCallback(videoCallback); 736 } 737 738 public void testRemoteConnectionVideoCallbacks_PeerDimensions() { 739 if (!mShouldTestTelecom) { 740 return; 741 } 742 743 setupRemoteConnectionVideoCallbacksTest(); 744 745 final InvokeCounter callbackInvoker = 746 new InvokeCounter("testRemoteConnectionVideoCallbacks_PeerDimensions"); 747 final VideoProvider remoteVideoProvider = mRemoteConnectionObject.getVideoProvider(); 748 final MockVideoProvider mockVideoProvider = mRemoteConnection.getMockVideoProvider(); 749 RemoteConnection.VideoProvider.Callback videoCallback; 750 751 videoCallback = new RemoteConnection.VideoProvider.Callback() { 752 @Override 753 public void onPeerDimensionsChanged(VideoProvider videoProvider, int width, 754 int height) { 755 super.onPeerDimensionsChanged(videoProvider, width, height); 756 callbackInvoker.invoke(videoProvider, width, height); 757 } 758 }; 759 remoteVideoProvider.registerCallback(videoCallback); 760 final int width = 100, heigth = 20; 761 mockVideoProvider.waitForVideoProviderHandler(remoteVideoProvider); 762 mockVideoProvider.changePeerDimensions(width, heigth); 763 callbackInvoker.waitForCount(1, WAIT_FOR_STATE_CHANGE_TIMEOUT_MS); 764 assertEquals(remoteVideoProvider, callbackInvoker.getArgs(0)[0]); 765 assertEquals(width, callbackInvoker.getArgs(0)[1]); 766 assertEquals(heigth, callbackInvoker.getArgs(0)[2]); 767 remoteVideoProvider.unregisterCallback(videoCallback); 768 } 769 770 public void testRemoteConnectionVideoCallbacks_CallDataUsage() { 771 if (!mShouldTestTelecom) { 772 return; 773 } 774 775 setupRemoteConnectionVideoCallbacksTest(); 776 777 final InvokeCounter callbackInvoker = 778 new InvokeCounter("testRemoteConnectionVideoCallbacks_CallDataUsage"); 779 final VideoProvider remoteVideoProvider = mRemoteConnectionObject.getVideoProvider(); 780 final MockVideoProvider mockVideoProvider = mRemoteConnection.getMockVideoProvider(); 781 RemoteConnection.VideoProvider.Callback videoCallback; 782 783 videoCallback = new RemoteConnection.VideoProvider.Callback() { 784 @Override 785 public void onCallDataUsageChanged(VideoProvider videoProvider, long dataUsage) { 786 super.onCallDataUsageChanged(videoProvider, dataUsage); 787 callbackInvoker.invoke(videoProvider, dataUsage); 788 } 789 }; 790 remoteVideoProvider.registerCallback(videoCallback); 791 callbackInvoker.waitForCount(WAIT_FOR_STATE_CHANGE_TIMEOUT_CALLBACK); 792 long callDataUsage = 10000; 793 mockVideoProvider.waitForVideoProviderHandler(remoteVideoProvider); 794 mockVideoProvider.setCallDataUsage(callDataUsage); 795 callbackInvoker.waitForCount(1, WAIT_FOR_STATE_CHANGE_TIMEOUT_MS); 796 assertEquals(remoteVideoProvider, callbackInvoker.getArgs(0)[0]); 797 assertEquals(callDataUsage, callbackInvoker.getArgs(0)[1]); 798 remoteVideoProvider.unregisterCallback(videoCallback); 799 } 800 801 public void testRemoteConnectionVideoCallbacks_CameraCapabilities() { 802 if (!mShouldTestTelecom) { 803 return; 804 } 805 806 setupRemoteConnectionVideoCallbacksTest(); 807 808 final InvokeCounter callbackInvoker = 809 new InvokeCounter("testRemoteConnectionVideoCallbacks_CameraCapabilities"); 810 final VideoProvider remoteVideoProvider = mRemoteConnectionObject.getVideoProvider(); 811 final MockVideoProvider mockVideoProvider = mRemoteConnection.getMockVideoProvider(); 812 RemoteConnection.VideoProvider.Callback videoCallback; 813 814 videoCallback = new RemoteConnection.VideoProvider.Callback() { 815 @Override 816 public void onCameraCapabilitiesChanged( 817 VideoProvider videoProvider, 818 VideoProfile.CameraCapabilities cameraCapabilities) { 819 super.onCameraCapabilitiesChanged(videoProvider, cameraCapabilities); 820 callbackInvoker.invoke(videoProvider, cameraCapabilities); 821 } 822 }; 823 remoteVideoProvider.registerCallback(videoCallback); 824 VideoProfile.CameraCapabilities capabilities = new VideoProfile.CameraCapabilities(100, 200); 825 mockVideoProvider.waitForVideoProviderHandler(remoteVideoProvider); 826 mockVideoProvider.changeCameraCapabilities(capabilities); 827 callbackInvoker.waitForCount(1, WAIT_FOR_STATE_CHANGE_TIMEOUT_MS); 828 assertEquals(remoteVideoProvider, callbackInvoker.getArgs(0)[0]); 829 assertEquals(capabilities, callbackInvoker.getArgs(0)[1]); 830 remoteVideoProvider.unregisterCallback(videoCallback); 831 } 832 833 public void testRemoteConnectionVideoCallbacks_VideoQuality() { 834 if (!mShouldTestTelecom) { 835 return; 836 } 837 838 setupRemoteConnectionVideoCallbacksTest(); 839 840 final InvokeCounter callbackInvoker = 841 new InvokeCounter("testRemoteConnectionVideoCallbacks_VideoQuality"); 842 final VideoProvider remoteVideoProvider = mRemoteConnectionObject.getVideoProvider(); 843 final MockVideoProvider mockVideoProvider = mRemoteConnection.getMockVideoProvider(); 844 RemoteConnection.VideoProvider.Callback videoCallback; 845 846 videoCallback = new RemoteConnection.VideoProvider.Callback() { 847 @Override 848 public void onVideoQualityChanged(VideoProvider videoProvider, int videoQuality) { 849 super.onVideoQualityChanged(videoProvider, videoQuality); 850 callbackInvoker.invoke(videoProvider, videoQuality); 851 } 852 }; 853 remoteVideoProvider.registerCallback(videoCallback); 854 final int videoQuality = 10; 855 mockVideoProvider.waitForVideoProviderHandler(remoteVideoProvider); 856 mockVideoProvider.changeVideoQuality(videoQuality); 857 callbackInvoker.waitForCount(1, WAIT_FOR_STATE_CHANGE_TIMEOUT_MS); 858 assertEquals(remoteVideoProvider, callbackInvoker.getArgs(0)[0]); 859 assertEquals(videoQuality, callbackInvoker.getArgs(0)[1]); 860 remoteVideoProvider.unregisterCallback(videoCallback); 861 } 862 863 public void testRemoteConnectionVideo_RequestCallDataUsage() { 864 if (!mShouldTestTelecom) { 865 return; 866 } 867 868 final long callDataUsage = 10000; 869 final InvokeCounter callbackInvoker = 870 new InvokeCounter("testRemoteConnectionVideo_RequestCallDataUsage"); 871 final MockVideoProvider mockVideoProvider = new MockVideoProvider(mRemoteConnection) { 872 @Override 873 public void onRequestConnectionDataUsage() { 874 callbackInvoker.invoke(); 875 super.setCallDataUsage(callDataUsage); 876 } 877 }; 878 setupRemoteConnectionVideoTest(mockVideoProvider); 879 880 final VideoProvider remoteVideoProvider = mRemoteConnectionObject.getVideoProvider(); 881 RemoteConnection.VideoProvider.Callback videoCallback; 882 883 videoCallback = new RemoteConnection.VideoProvider.Callback() { 884 @Override 885 public void onCallDataUsageChanged(VideoProvider videoProvider, long dataUsage) { 886 super.onCallDataUsageChanged(videoProvider, dataUsage); 887 callbackInvoker.invoke(videoProvider, dataUsage); 888 } 889 }; 890 remoteVideoProvider.registerCallback(videoCallback); 891 remoteVideoProvider.requestCallDataUsage(); 892 callbackInvoker.waitForCount(2, WAIT_FOR_STATE_CHANGE_TIMEOUT_MS); 893 assertEquals(remoteVideoProvider, callbackInvoker.getArgs(1)[0]); 894 assertEquals(callDataUsage, callbackInvoker.getArgs(1)[1]); 895 remoteVideoProvider.unregisterCallback(videoCallback); 896 } 897 898 public void testRemoteConnectionVideo_RequestCameraCapabilities() { 899 if (!mShouldTestTelecom) { 900 return; 901 } 902 903 final VideoProfile.CameraCapabilities capabilities = 904 new VideoProfile.CameraCapabilities(100, 200); 905 final InvokeCounter callbackInvoker = 906 new InvokeCounter("testRemoteConnectionVideo_RequestCameraCapabilities"); 907 final MockVideoProvider mockVideoProvider = new MockVideoProvider(mRemoteConnection) { 908 @Override 909 public void onRequestCameraCapabilities() { 910 callbackInvoker.invoke(); 911 super.changeCameraCapabilities(capabilities); 912 } 913 }; 914 setupRemoteConnectionVideoTest(mockVideoProvider); 915 916 final VideoProvider remoteVideoProvider = mRemoteConnectionObject.getVideoProvider(); 917 RemoteConnection.VideoProvider.Callback videoCallback; 918 919 videoCallback = new RemoteConnection.VideoProvider.Callback() { 920 @Override 921 public void onCameraCapabilitiesChanged( 922 VideoProvider videoProvider, 923 VideoProfile.CameraCapabilities cameraCapabilities) { 924 super.onCameraCapabilitiesChanged(videoProvider, cameraCapabilities); 925 callbackInvoker.invoke(videoProvider, cameraCapabilities); 926 } 927 }; 928 remoteVideoProvider.registerCallback(videoCallback); 929 remoteVideoProvider.requestCameraCapabilities(); 930 callbackInvoker.waitForCount(2, WAIT_FOR_STATE_CHANGE_TIMEOUT_MS); 931 assertEquals(remoteVideoProvider, callbackInvoker.getArgs(1)[0]); 932 assertEquals(capabilities, callbackInvoker.getArgs(1)[1]); 933 remoteVideoProvider.unregisterCallback(videoCallback); 934 } 935 936 public void testRemoteConnectionVideo_SendSessionModifyRequest() { 937 if (!mShouldTestTelecom) { 938 return; 939 } 940 941 VideoProfile fromVideoProfile = new VideoProfile(VideoProfile.STATE_AUDIO_ONLY); 942 VideoProfile toVideoProfile = new VideoProfile(VideoProfile.STATE_BIDIRECTIONAL); 943 final InvokeCounter callbackInvoker = 944 new InvokeCounter("testRemoteConnectionVideo_SendSessionModifyRequest"); 945 final MockVideoProvider mockVideoProvider = new MockVideoProvider(mRemoteConnection) { 946 @Override 947 public void onSendSessionModifyRequest(VideoProfile fromProfile, 948 VideoProfile toProfile) { 949 callbackInvoker.invoke(fromProfile, toProfile); 950 super.receiveSessionModifyRequest(toProfile); 951 } 952 }; 953 setupRemoteConnectionVideoTest(mockVideoProvider); 954 955 final VideoProvider remoteVideoProvider = mRemoteConnectionObject.getVideoProvider(); 956 RemoteConnection.VideoProvider.Callback videoCallback; 957 958 videoCallback = new RemoteConnection.VideoProvider.Callback() { 959 @Override 960 public void onSessionModifyRequestReceived( 961 VideoProvider videoProvider, 962 VideoProfile videoProfile) { 963 super.onSessionModifyRequestReceived(videoProvider, videoProfile); 964 callbackInvoker.invoke(videoProvider, videoProfile); 965 } 966 }; 967 remoteVideoProvider.registerCallback(videoCallback); 968 remoteVideoProvider.sendSessionModifyRequest(fromVideoProfile, toVideoProfile); 969 callbackInvoker.waitForCount(2, WAIT_FOR_STATE_CHANGE_TIMEOUT_MS); 970 assertEquals(fromVideoProfile, callbackInvoker.getArgs(0)[0]); 971 assertEquals(toVideoProfile, callbackInvoker.getArgs(0)[1]); 972 assertEquals(remoteVideoProvider, callbackInvoker.getArgs(1)[0]); 973 assertEquals(toVideoProfile, callbackInvoker.getArgs(1)[1]); 974 remoteVideoProvider.unregisterCallback(videoCallback); 975 } 976 977 public void testRemoteConnectionVideo_SendSessionModifyResponse() { 978 if (!mShouldTestTelecom) { 979 return; 980 } 981 982 VideoProfile toVideoProfile = new VideoProfile(VideoProfile.STATE_BIDIRECTIONAL); 983 final InvokeCounter callbackInvoker = 984 new InvokeCounter("testRemoteConnectionVideo_SendSessionModifyResponse"); 985 final MockVideoProvider mockVideoProvider = new MockVideoProvider(mRemoteConnection) { 986 @Override 987 public void onSendSessionModifyResponse(VideoProfile responseProfile) { 988 callbackInvoker.invoke(responseProfile); 989 super.receiveSessionModifyResponse( 990 Connection.VideoProvider.SESSION_MODIFY_REQUEST_SUCCESS, 991 responseProfile, responseProfile); 992 } 993 }; 994 setupRemoteConnectionVideoTest(mockVideoProvider); 995 996 final VideoProvider remoteVideoProvider = mRemoteConnectionObject.getVideoProvider(); 997 RemoteConnection.VideoProvider.Callback videoCallback; 998 999 videoCallback = new RemoteConnection.VideoProvider.Callback() { 1000 @Override 1001 public void onSessionModifyResponseReceived( 1002 VideoProvider videoProvider, 1003 int status, 1004 VideoProfile requestedProfile, 1005 VideoProfile responseProfile) { 1006 super.onSessionModifyResponseReceived(videoProvider, status, requestedProfile, 1007 responseProfile); 1008 callbackInvoker.invoke(videoProvider, status, requestedProfile, responseProfile); 1009 } 1010 }; 1011 remoteVideoProvider.registerCallback(videoCallback); 1012 remoteVideoProvider.sendSessionModifyResponse(toVideoProfile); 1013 callbackInvoker.waitForCount(2, WAIT_FOR_STATE_CHANGE_TIMEOUT_MS); 1014 assertEquals(toVideoProfile, callbackInvoker.getArgs(0)[0]); 1015 assertEquals(remoteVideoProvider, callbackInvoker.getArgs(1)[0]); 1016 assertEquals(toVideoProfile, callbackInvoker.getArgs(1)[2]); 1017 assertEquals(Connection.VideoProvider.SESSION_MODIFY_REQUEST_SUCCESS, 1018 callbackInvoker.getArgs(1)[1]); 1019 assertEquals(toVideoProfile, callbackInvoker.getArgs(1)[3]); 1020 remoteVideoProvider.unregisterCallback(videoCallback); 1021 } 1022 1023 public void testRemoteConnectionVideo_SetCamera() { 1024 if (!mShouldTestTelecom) { 1025 return; 1026 } 1027 1028 final String newCameraId = "5"; 1029 final VideoProfile.CameraCapabilities capabilities = 1030 new VideoProfile.CameraCapabilities(100, 200); 1031 final InvokeCounter callbackInvoker = 1032 new InvokeCounter("testRemoteConnectionVideo_SetCamera"); 1033 final MockVideoProvider mockVideoProvider = new MockVideoProvider(mRemoteConnection) { 1034 @Override 1035 public void onSetCamera(String cameraId) { 1036 callbackInvoker.invoke(cameraId); 1037 super.changeCameraCapabilities(capabilities); 1038 } 1039 }; 1040 setupRemoteConnectionVideoTest(mockVideoProvider); 1041 1042 final VideoProvider remoteVideoProvider = mRemoteConnectionObject.getVideoProvider(); 1043 RemoteConnection.VideoProvider.Callback videoCallback; 1044 1045 videoCallback = new RemoteConnection.VideoProvider.Callback() { 1046 @Override 1047 public void onCameraCapabilitiesChanged( 1048 VideoProvider videoProvider, 1049 VideoProfile.CameraCapabilities cameraCapabilities) { 1050 super.onCameraCapabilitiesChanged(videoProvider, cameraCapabilities); 1051 callbackInvoker.invoke(videoProvider, cameraCapabilities); 1052 } 1053 }; 1054 remoteVideoProvider.registerCallback(videoCallback); 1055 remoteVideoProvider.setCamera(newCameraId); 1056 callbackInvoker.waitForCount(2, WAIT_FOR_STATE_CHANGE_TIMEOUT_MS); 1057 assertEquals(newCameraId, callbackInvoker.getArgs(0)[0]); 1058 assertEquals(remoteVideoProvider, callbackInvoker.getArgs(1)[0]); 1059 assertEquals(capabilities, callbackInvoker.getArgs(1)[1]); 1060 remoteVideoProvider.unregisterCallback(videoCallback); 1061 } 1062 1063 public void testRemoteConnectionVideo_SetDeviceOrientation() { 1064 if (!mShouldTestTelecom) { 1065 return; 1066 } 1067 1068 final int newRotation = 5; 1069 final InvokeCounter callbackInvoker = 1070 new InvokeCounter("testRemoteConnectionVideo_SetDeviceOrientation"); 1071 final MockVideoProvider mockVideoProvider = new MockVideoProvider(mRemoteConnection) { 1072 @Override 1073 public void onSetDeviceOrientation(int rotation) { 1074 callbackInvoker.invoke(rotation); 1075 } 1076 }; 1077 setupRemoteConnectionVideoTest(mockVideoProvider); 1078 1079 final VideoProvider remoteVideoProvider = mRemoteConnectionObject.getVideoProvider(); 1080 1081 remoteVideoProvider.setDeviceOrientation(newRotation); 1082 callbackInvoker.waitForCount(1, WAIT_FOR_STATE_CHANGE_TIMEOUT_MS); 1083 assertEquals(newRotation, callbackInvoker.getArgs(0)[0]); 1084 } 1085 1086 public void testRemoteConnectionVideo_SetDisplaySurface() { 1087 if (!mShouldTestTelecom) { 1088 return; 1089 } 1090 1091 final Surface newSurface = new Surface(new SurfaceTexture(1)); 1092 final InvokeCounter callbackInvoker = 1093 new InvokeCounter("testRemoteConnectionVideo_SetDisplaySurface"); 1094 final MockVideoProvider mockVideoProvider = new MockVideoProvider(mRemoteConnection) { 1095 @Override 1096 public void onSetDisplaySurface(Surface surface) { 1097 callbackInvoker.invoke(surface); 1098 } 1099 }; 1100 setupRemoteConnectionVideoTest(mockVideoProvider); 1101 1102 final VideoProvider remoteVideoProvider = mRemoteConnectionObject.getVideoProvider(); 1103 1104 remoteVideoProvider.setDisplaySurface(newSurface); 1105 callbackInvoker.waitForCount(1, WAIT_FOR_STATE_CHANGE_TIMEOUT_MS); 1106 assertEquals(newSurface, callbackInvoker.getArgs(0)[0]); 1107 } 1108 1109 public void testRemoteConnectionVideo_SetPauseImage() { 1110 if (!mShouldTestTelecom) { 1111 return; 1112 } 1113 1114 final Uri newUri = Uri.parse("content://"); 1115 final InvokeCounter callbackInvoker = 1116 new InvokeCounter("testRemoteConnectionVideo_SetPauseImage"); 1117 final MockVideoProvider mockVideoProvider = new MockVideoProvider(mRemoteConnection) { 1118 @Override 1119 public void onSetPauseImage(Uri uri) { 1120 callbackInvoker.invoke(uri); 1121 } 1122 }; 1123 setupRemoteConnectionVideoTest(mockVideoProvider); 1124 1125 final VideoProvider remoteVideoProvider = mRemoteConnectionObject.getVideoProvider(); 1126 1127 remoteVideoProvider.setPauseImage(newUri); 1128 callbackInvoker.waitForCount(1, WAIT_FOR_STATE_CHANGE_TIMEOUT_MS); 1129 assertEquals(newUri, callbackInvoker.getArgs(0)[0]); 1130 } 1131 1132 public void testRemoteConnectionVideo_SetPreviewSurface() { 1133 if (!mShouldTestTelecom) { 1134 return; 1135 } 1136 1137 final Surface newSurface = new Surface(new SurfaceTexture(1)); 1138 final InvokeCounter callbackInvoker = 1139 new InvokeCounter("testRemoteConnectionVideo_SetPreviewSurface"); 1140 final MockVideoProvider mockVideoProvider = new MockVideoProvider(mRemoteConnection) { 1141 @Override 1142 public void onSetPreviewSurface(Surface surface) { 1143 callbackInvoker.invoke(surface); 1144 } 1145 }; 1146 setupRemoteConnectionVideoTest(mockVideoProvider); 1147 1148 final VideoProvider remoteVideoProvider = mRemoteConnectionObject.getVideoProvider(); 1149 1150 remoteVideoProvider.setPreviewSurface(newSurface); 1151 callbackInvoker.waitForCount(1, WAIT_FOR_STATE_CHANGE_TIMEOUT_MS); 1152 assertEquals(newSurface, callbackInvoker.getArgs(0)[0]); 1153 } 1154 1155 public void testRemoteConnectionVideo_SetZoom() { 1156 if (!mShouldTestTelecom) { 1157 return; 1158 } 1159 1160 final float newZoom = 1.0f; 1161 final InvokeCounter callbackInvoker = 1162 new InvokeCounter("testRemoteConnectionVideo_SetPreviewSurface"); 1163 final MockVideoProvider mockVideoProvider = new MockVideoProvider(mRemoteConnection) { 1164 @Override 1165 public void onSetZoom(float value) { 1166 callbackInvoker.invoke(value); 1167 } 1168 }; 1169 setupRemoteConnectionVideoTest(mockVideoProvider); 1170 1171 final VideoProvider remoteVideoProvider = mRemoteConnectionObject.getVideoProvider(); 1172 1173 remoteVideoProvider.setZoom(newZoom); 1174 callbackInvoker.waitForCount(1, WAIT_FOR_STATE_CHANGE_TIMEOUT_MS); 1175 assertEquals(newZoom, callbackInvoker.getArgs(0)[0]); 1176 } 1177 1178 private void verifyRemoteConnectionObject(RemoteConnection remoteConnection, 1179 Connection connection) { 1180 assertEquals(connection.getAddress(), remoteConnection.getAddress()); 1181 assertEquals(connection.getAddressPresentation(), 1182 remoteConnection.getAddressPresentation()); 1183 assertEquals(connection.getCallerDisplayName(), remoteConnection.getCallerDisplayName()); 1184 assertEquals(connection.getCallerDisplayNamePresentation(), 1185 remoteConnection.getCallerDisplayNamePresentation()); 1186 assertEquals(connection.getConnectionCapabilities(), 1187 remoteConnection.getConnectionCapabilities()); 1188 assertEquals(connection.getConnectionProperties(), 1189 remoteConnection.getConnectionProperties()); 1190 assertEquals(connection.getDisconnectCause(), remoteConnection.getDisconnectCause()); 1191 assertTrue(areBundlesEqual(connection.getExtras(), remoteConnection.getExtras())); 1192 assertEquals(connection.getStatusHints(), remoteConnection.getStatusHints()); 1193 assertEquals(VideoProfile.STATE_AUDIO_ONLY, remoteConnection.getVideoState()); 1194 assertNull(remoteConnection.getVideoProvider()); 1195 assertTrue(remoteConnection.getConferenceableConnections().isEmpty()); 1196 } 1197 1198 private void addRemoteConnectionOutgoingCall() { 1199 try { 1200 MockConnectionService managerConnectionService = new MockConnectionService() { 1201 @Override 1202 public Connection onCreateOutgoingConnection( 1203 PhoneAccountHandle connectionManagerPhoneAccount, 1204 ConnectionRequest request) { 1205 MockConnection connection = (MockConnection)super.onCreateOutgoingConnection( 1206 connectionManagerPhoneAccount, request); 1207 ConnectionRequest remoteRequest = new ConnectionRequest( 1208 TEST_REMOTE_PHONE_ACCOUNT_HANDLE, 1209 request.getAddress(), 1210 request.getExtras()); 1211 RemoteConnection remoteConnection = 1212 CtsConnectionService.createRemoteOutgoingConnectionToTelecom( 1213 TEST_REMOTE_PHONE_ACCOUNT_HANDLE, remoteRequest); 1214 connection.setRemoteConnection(remoteConnection); 1215 return connection; 1216 } 1217 }; 1218 setupConnectionServices(managerConnectionService, null, FLAG_REGISTER | FLAG_ENABLE); 1219 } catch(Exception e) { 1220 fail("Error in setting up the connection services"); 1221 } 1222 placeAndVerifyCall(); 1223 /** 1224 * Retrieve the connection from both the connection services and see if the plumbing via 1225 * RemoteConnection object is working. 1226 */ 1227 mConnection = verifyConnectionForOutgoingCall(); 1228 mRemoteConnection = verifyConnectionForOutgoingCallOnRemoteCS(); 1229 mRemoteConnectionObject = mConnection.getRemoteConnection(); 1230 } 1231 1232 private void addRemoteConnectionIncomingCall() { 1233 try { 1234 MockConnectionService managerConnectionService = new MockConnectionService() { 1235 @Override 1236 public Connection onCreateIncomingConnection( 1237 PhoneAccountHandle connectionManagerPhoneAccount, 1238 ConnectionRequest request) { 1239 MockConnection connection = (MockConnection)super.onCreateIncomingConnection( 1240 connectionManagerPhoneAccount, request); 1241 ConnectionRequest remoteRequest = new ConnectionRequest( 1242 TEST_REMOTE_PHONE_ACCOUNT_HANDLE, 1243 request.getAddress(), 1244 request.getExtras()); 1245 RemoteConnection remoteConnection = 1246 CtsConnectionService.createRemoteIncomingConnectionToTelecom( 1247 TEST_REMOTE_PHONE_ACCOUNT_HANDLE, remoteRequest); 1248 connection.setRemoteConnection(remoteConnection); 1249 return connection; 1250 } 1251 }; 1252 setupConnectionServices(managerConnectionService, null, FLAG_REGISTER | FLAG_ENABLE); 1253 } catch(Exception e) { 1254 fail("Error in setting up the connection services"); 1255 } 1256 addAndVerifyNewIncomingCall(createTestNumber(), null); 1257 /** 1258 * Retrieve the connection from both the connection services and see if the plumbing via 1259 * RemoteConnection object is working. 1260 */ 1261 mConnection = verifyConnectionForIncomingCall(); 1262 mRemoteConnection = verifyConnectionForIncomingCallOnRemoteCS(); 1263 mRemoteConnectionObject = mConnection.getRemoteConnection(); 1264 } 1265 1266 private Handler setupRemoteConnectionCallbacksTest() { 1267 addRemoteConnectionOutgoingCall(); 1268 final Call call = mInCallCallbacks.getService().getLastCall(); 1269 assertCallState(call, Call.STATE_DIALING); 1270 verifyRemoteConnectionObject(mRemoteConnectionObject, mRemoteConnection); 1271 1272 // Create a looper thread for the callbacks. 1273 HandlerThread workerThread = new HandlerThread("CallbackThread"); 1274 workerThread.start(); 1275 Handler handler = new Handler(workerThread.getLooper()); 1276 return handler; 1277 } 1278 1279 private Handler setupRemoteConnectionVideoCallbacksTest() { 1280 addRemoteConnectionOutgoingCall(); 1281 final Call call = mInCallCallbacks.getService().getLastCall(); 1282 assertCallState(call, Call.STATE_DIALING); 1283 verifyRemoteConnectionObject(mRemoteConnectionObject, mRemoteConnection); 1284 1285 // Create a looper thread for the callbacks. 1286 HandlerThread workerThread = new HandlerThread("CallbackThread"); 1287 workerThread.start(); 1288 Handler handler = new Handler(workerThread.getLooper()); 1289 1290 final InvokeCounter callbackInvoker = new InvokeCounter("RemoteConnectionCallbacks"); 1291 1292 RemoteConnection.Callback callback = new RemoteConnection.Callback() { 1293 @Override 1294 public void onVideoProviderChanged( 1295 RemoteConnection connection, VideoProvider videoProvider) { 1296 callbackInvoker.invoke(connection, videoProvider); 1297 } 1298 }; 1299 mRemoteConnectionObject.registerCallback(callback, handler); 1300 mRemoteConnection.createMockVideoProvider(); 1301 callbackInvoker.waitForCount(1, WAIT_FOR_STATE_CHANGE_TIMEOUT_MS); 1302 assertEquals(mRemoteConnectionObject, callbackInvoker.getArgs(0)[0]); 1303 mRemoteConnectionObject.unregisterCallback(callback); 1304 return handler; 1305 } 1306 1307 private Handler setupRemoteConnectionVideoTest(MockVideoProvider mockVideoProvider) { 1308 addRemoteConnectionOutgoingCall(); 1309 final Call call = mInCallCallbacks.getService().getLastCall(); 1310 assertCallState(call, Call.STATE_DIALING); 1311 verifyRemoteConnectionObject(mRemoteConnectionObject, mRemoteConnection); 1312 1313 // Create a looper thread for the callbacks. 1314 HandlerThread workerThread = new HandlerThread("CallbackThread"); 1315 workerThread.start(); 1316 Handler handler = new Handler(workerThread.getLooper()); 1317 1318 final InvokeCounter callbackInvoker = new InvokeCounter("RemoteConnectionCallbacks"); 1319 1320 RemoteConnection.Callback callback = new RemoteConnection.Callback() { 1321 @Override 1322 public void onVideoProviderChanged( 1323 RemoteConnection connection, VideoProvider videoProvider) { 1324 callbackInvoker.invoke(connection, videoProvider); 1325 } 1326 }; 1327 mRemoteConnectionObject.registerCallback(callback, handler); 1328 mRemoteConnection.setVideoProvider(mockVideoProvider); 1329 callbackInvoker.waitForCount(1, WAIT_FOR_STATE_CHANGE_TIMEOUT_MS); 1330 assertEquals(mRemoteConnectionObject, callbackInvoker.getArgs(0)[0]); 1331 mRemoteConnectionObject.unregisterCallback(callback); 1332 return handler; 1333 } 1334 } 1335