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