blob: 698da2667e3ddd01a5d98dcc2513495d0043758f [file] [log] [blame]
Ihab Awadaa383cc2015-03-22 22:12:28 -07001/*
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
17package com.android.server.telecom.tests;
18
19import com.android.internal.telecom.IConnectionService;
20import com.android.internal.telecom.IConnectionServiceAdapter;
21import com.android.internal.telecom.IVideoProvider;
22import com.android.internal.telecom.RemoteServiceCallback;
Ihab Awad1b5490a2015-05-12 13:13:48 -070023import com.android.server.telecom.Log;
Ihab Awadaa383cc2015-03-22 22:12:28 -070024
25import junit.framework.TestCase;
26
27import org.mockito.Mockito;
Ihab Awadaa383cc2015-03-22 22:12:28 -070028
29import android.content.ComponentName;
Abhijith Shastryb7853c02016-02-03 12:56:59 -080030import android.net.Uri;
Santos Cordonb3907b32015-05-27 17:39:59 -070031import android.os.Bundle;
Ihab Awadaa383cc2015-03-22 22:12:28 -070032import android.os.IBinder;
Ihab Awad1b5490a2015-05-12 13:13:48 -070033import android.os.IInterface;
Ihab Awadaa383cc2015-03-22 22:12:28 -070034import android.os.RemoteException;
Ihab Awad1b5490a2015-05-12 13:13:48 -070035import android.telecom.CallAudioState;
Hall Liuf7783fb2015-11-23 18:45:48 -080036import android.telecom.Conference;
Ihab Awadaa383cc2015-03-22 22:12:28 -070037import android.telecom.Connection;
38import android.telecom.ConnectionRequest;
Hall Liuf7783fb2015-11-23 18:45:48 -080039import android.telecom.ConnectionService;
Ihab Awadaa383cc2015-03-22 22:12:28 -070040import android.telecom.DisconnectCause;
41import android.telecom.ParcelableConference;
42import android.telecom.ParcelableConnection;
43import android.telecom.PhoneAccountHandle;
44import android.telecom.StatusHints;
Abhijith Shastryb7853c02016-02-03 12:56:59 -080045import android.telecom.TelecomManager;
Ihab Awadaa383cc2015-03-22 22:12:28 -070046
Abhijith Shastryc6e42ef2016-02-19 18:26:44 -080047import com.google.android.collect.Lists;
48
Bryce Lee6d962522015-11-30 10:28:37 -080049import java.lang.Override;
Ihab Awadaa383cc2015-03-22 22:12:28 -070050import java.util.ArrayList;
Tyler Gunn961694a2016-03-21 16:01:40 -070051import java.util.Collection;
Ihab Awadaa383cc2015-03-22 22:12:28 -070052import java.util.HashMap;
53import java.util.HashSet;
54import java.util.List;
55import java.util.Map;
56import java.util.Set;
Tyler Gunn961694a2016-03-21 16:01:40 -070057import java.util.concurrent.CountDownLatch;
58import java.util.concurrent.TimeUnit;
Ihab Awadaa383cc2015-03-22 22:12:28 -070059
Ihab Awadaa383cc2015-03-22 22:12:28 -070060/**
61 * Controls a test {@link IConnectionService} as would be provided by a source of connectivity
62 * to the Telecom framework.
63 */
64public class ConnectionServiceFixture implements TestFixture<IConnectionService> {
Abhijith Shastryb7853c02016-02-03 12:56:59 -080065 static int INVALID_VIDEO_STATE = -1;
Tyler Gunn961694a2016-03-21 16:01:40 -070066 public CountDownLatch mExtrasLock = new CountDownLatch(1);
Tyler Gunn571d5e62016-03-15 15:55:18 -070067 static int NOT_SPECIFIED = 0;
Ihab Awadaa383cc2015-03-22 22:12:28 -070068
Hall Liuf7783fb2015-11-23 18:45:48 -080069 /**
70 * Implementation of ConnectionService that performs no-ops for tasks normally meant for
71 * Telephony and reports success back to Telecom
72 */
73 public class FakeConnectionServiceDelegate extends ConnectionService {
Abhijith Shastryb7853c02016-02-03 12:56:59 -080074 int mVideoState = INVALID_VIDEO_STATE;
Tyler Gunn571d5e62016-03-15 15:55:18 -070075 int mCapabilities = NOT_SPECIFIED;
76 int mProperties = NOT_SPECIFIED;
Abhijith Shastryb7853c02016-02-03 12:56:59 -080077
Hall Liuf7783fb2015-11-23 18:45:48 -080078 @Override
79 public Connection onCreateUnknownConnection(
80 PhoneAccountHandle connectionManagerPhoneAccount, ConnectionRequest request) {
Tyler Gunn961694a2016-03-21 16:01:40 -070081 mLatestConnection = new FakeConnection(request.getVideoState(), request.getAddress());
82 return mLatestConnection;
Hall Liuf7783fb2015-11-23 18:45:48 -080083 }
84
85 @Override
86 public Connection onCreateIncomingConnection(
87 PhoneAccountHandle connectionManagerPhoneAccount, ConnectionRequest request) {
Tyler Gunnd45e6d92016-03-10 20:15:39 -080088 FakeConnection fakeConnection = new FakeConnection(
Abhijith Shastryb7853c02016-02-03 12:56:59 -080089 mVideoState == INVALID_VIDEO_STATE ? request.getVideoState() : mVideoState,
90 request.getAddress());
Tyler Gunn961694a2016-03-21 16:01:40 -070091 mLatestConnection = fakeConnection;
Tyler Gunn571d5e62016-03-15 15:55:18 -070092 if (mCapabilities != NOT_SPECIFIED) {
Tyler Gunnd45e6d92016-03-10 20:15:39 -080093 fakeConnection.setConnectionCapabilities(mCapabilities);
94 }
Tyler Gunn571d5e62016-03-15 15:55:18 -070095 if (mProperties != NOT_SPECIFIED) {
96 fakeConnection.setConnectionProperties(mProperties);
97 }
Tyler Gunnd45e6d92016-03-10 20:15:39 -080098
99 return fakeConnection;
Hall Liuf7783fb2015-11-23 18:45:48 -0800100 }
101
102 @Override
103 public Connection onCreateOutgoingConnection(
104 PhoneAccountHandle connectionManagerPhoneAccount, ConnectionRequest request) {
Brad Ebinger84771f82016-05-18 16:57:30 -0700105 FakeConnection fakeConnection = new FakeConnection(request.getVideoState(),
106 request.getAddress());
107 mLatestConnection = fakeConnection;
108 if (mCapabilities != NOT_SPECIFIED) {
109 fakeConnection.setConnectionCapabilities(mCapabilities);
110 }
111 if (mProperties != NOT_SPECIFIED) {
112 fakeConnection.setConnectionProperties(mProperties);
113 }
114 return fakeConnection;
Hall Liuf7783fb2015-11-23 18:45:48 -0800115 }
116
117 @Override
118 public void onConference(Connection cxn1, Connection cxn2) {
Brad Ebinger0d402552016-05-27 16:02:53 -0700119 if (((FakeConnection) cxn1).getIsConferenceCreated()) {
120 // Usually, this is implemented by something in Telephony, which does a bunch of
121 // radio work to conference the two connections together. Here we just short-cut
122 // that and declare them conferenced.
123 Conference fakeConference = new FakeConference();
124 fakeConference.addConnection(cxn1);
125 fakeConference.addConnection(cxn2);
126 mLatestConference = fakeConference;
127 addConference(fakeConference);
128 } else {
129 try {
130 sendSetConferenceMergeFailed(cxn1.getTelecomCallId());
131 } catch (Exception e) {
132 Log.w(this, "Exception on sendSetConferenceMergeFailed: " + e.getMessage());
133 }
134 }
Hall Liuf7783fb2015-11-23 18:45:48 -0800135 }
136 }
137
138 public class FakeConnection extends Connection {
Brad Ebinger0d402552016-05-27 16:02:53 -0700139 // Set to false if you wish the Conference merge to fail.
140 boolean mIsConferenceCreated = true;
141
Abhijith Shastryb7853c02016-02-03 12:56:59 -0800142 public FakeConnection(int videoState, Uri address) {
Hall Liuf7783fb2015-11-23 18:45:48 -0800143 super();
144 int capabilities = getConnectionCapabilities();
145 capabilities |= CAPABILITY_MUTE;
146 capabilities |= CAPABILITY_SUPPORT_HOLD;
147 capabilities |= CAPABILITY_HOLD;
Tyler Gunnb492f4c2015-12-15 08:15:43 -0800148 setVideoState(videoState);
Hall Liuf7783fb2015-11-23 18:45:48 -0800149 setConnectionCapabilities(capabilities);
Brad Ebinger6e8f3d72016-06-20 11:35:42 -0700150 setDialing();
Abhijith Shastryb7853c02016-02-03 12:56:59 -0800151 setAddress(address, TelecomManager.PRESENTATION_ALLOWED);
Hall Liuf7783fb2015-11-23 18:45:48 -0800152 }
Tyler Gunn961694a2016-03-21 16:01:40 -0700153
154 @Override
155 public void onExtrasChanged(Bundle extras) {
156 mExtrasLock.countDown();
157 }
Brad Ebinger0d402552016-05-27 16:02:53 -0700158
159 public boolean getIsConferenceCreated() {
160 return mIsConferenceCreated;
161 }
162
163 public void setIsConferenceCreated(boolean isConferenceCreated) {
164 mIsConferenceCreated = isConferenceCreated;
165 }
Hall Liuf7783fb2015-11-23 18:45:48 -0800166 }
167
168 public class FakeConference extends Conference {
169 public FakeConference() {
170 super(null);
171 setConnectionCapabilities(
172 Connection.CAPABILITY_SUPPORT_HOLD
173 | Connection.CAPABILITY_HOLD
174 | Connection.CAPABILITY_MUTE
175 | Connection.CAPABILITY_MANAGE_CONFERENCE);
176 }
177
178 @Override
179 public void onMerge(Connection connection) {
180 // Do nothing besides inform the connection that it was merged into this conference.
181 connection.setConference(this);
182 }
Tyler Gunn961694a2016-03-21 16:01:40 -0700183
184 @Override
185 public void onExtrasChanged(Bundle extras) {
186 Log.w(this, "FakeConference onExtrasChanged");
187 mExtrasLock.countDown();
188 }
Hall Liuf7783fb2015-11-23 18:45:48 -0800189 }
190
Ihab Awad1b5490a2015-05-12 13:13:48 -0700191 public class FakeConnectionService extends IConnectionService.Stub {
Abhijith Shastryc6e42ef2016-02-19 18:26:44 -0800192 List<String> rejectedCallIds = Lists.newArrayList();
Ihab Awad1b5490a2015-05-12 13:13:48 -0700193
194 @Override
195 public void addConnectionServiceAdapter(IConnectionServiceAdapter adapter)
196 throws RemoteException {
197 if (!mConnectionServiceAdapters.add(adapter)) {
198 throw new RuntimeException("Adapter already added: " + adapter);
199 }
Hall Liuf7783fb2015-11-23 18:45:48 -0800200 mConnectionServiceDelegateAdapter.addConnectionServiceAdapter(adapter);
Ihab Awad1b5490a2015-05-12 13:13:48 -0700201 }
202
203 @Override
204 public void removeConnectionServiceAdapter(IConnectionServiceAdapter adapter)
205 throws RemoteException {
206 if (!mConnectionServiceAdapters.remove(adapter)) {
207 throw new RuntimeException("Adapter never added: " + adapter);
208 }
Hall Liuf7783fb2015-11-23 18:45:48 -0800209 mConnectionServiceDelegateAdapter.removeConnectionServiceAdapter(adapter);
Ihab Awad1b5490a2015-05-12 13:13:48 -0700210 }
211
212 @Override
213 public void createConnection(PhoneAccountHandle connectionManagerPhoneAccount,
214 String id,
215 ConnectionRequest request, boolean isIncoming, boolean isUnknown)
216 throws RemoteException {
217 Log.i(ConnectionServiceFixture.this, "xoxox createConnection --> " + id);
218
219 if (mConnectionById.containsKey(id)) {
220 throw new RuntimeException("Connection already exists: " + id);
221 }
222 mLatestConnectionId = id;
223 ConnectionInfo c = new ConnectionInfo();
224 c.connectionManagerPhoneAccount = connectionManagerPhoneAccount;
225 c.id = id;
226 c.request = request;
227 c.isIncoming = isIncoming;
228 c.isUnknown = isUnknown;
Ihab Awad32dd7c32015-05-28 10:52:20 -0700229 c.capabilities |= Connection.CAPABILITY_HOLD | Connection.CAPABILITY_SUPPORT_HOLD;
Tyler Gunnb492f4c2015-12-15 08:15:43 -0800230 c.videoState = request.getVideoState();
231 c.mockVideoProvider = new MockVideoProvider();
232 c.videoProvider = c.mockVideoProvider.getInterface();
Brad Ebinger0d402552016-05-27 16:02:53 -0700233 c.isConferenceCreated = true;
Ihab Awad1b5490a2015-05-12 13:13:48 -0700234 mConnectionById.put(id, c);
Hall Liuf7783fb2015-11-23 18:45:48 -0800235 mConnectionServiceDelegateAdapter.createConnection(connectionManagerPhoneAccount,
236 id, request, isIncoming, isUnknown);
Ihab Awad1b5490a2015-05-12 13:13:48 -0700237 }
238
239 @Override
240 public void abort(String callId) throws RemoteException { }
241
242 @Override
243 public void answerVideo(String callId, int videoState) throws RemoteException { }
244
245 @Override
246 public void answer(String callId) throws RemoteException { }
247
248 @Override
Abhijith Shastryc6e42ef2016-02-19 18:26:44 -0800249 public void reject(String callId) throws RemoteException {
250 rejectedCallIds.add(callId);
251 }
Ihab Awad1b5490a2015-05-12 13:13:48 -0700252
253 @Override
Bryce Leeddd966e2015-08-28 16:33:50 -0700254 public void rejectWithMessage(String callId, String message) throws RemoteException { }
255
256 @Override
Ihab Awad1b5490a2015-05-12 13:13:48 -0700257 public void disconnect(String callId) throws RemoteException { }
258
259 @Override
Bryce Lee6d962522015-11-30 10:28:37 -0800260 public void silence(String callId) throws RemoteException { }
261
262 @Override
Ihab Awad1b5490a2015-05-12 13:13:48 -0700263 public void hold(String callId) throws RemoteException { }
264
265 @Override
266 public void unhold(String callId) throws RemoteException { }
267
268 @Override
269 public void onCallAudioStateChanged(String activeCallId, CallAudioState audioState)
270 throws RemoteException { }
271
272 @Override
273 public void playDtmfTone(String callId, char digit) throws RemoteException { }
274
275 @Override
276 public void stopDtmfTone(String callId) throws RemoteException { }
277
278 @Override
Hall Liuf7783fb2015-11-23 18:45:48 -0800279 public void conference(String conferenceCallId, String callId) throws RemoteException {
280 mConnectionServiceDelegateAdapter.conference(conferenceCallId, callId);
281 }
Ihab Awad1b5490a2015-05-12 13:13:48 -0700282
283 @Override
284 public void splitFromConference(String callId) throws RemoteException { }
285
286 @Override
287 public void mergeConference(String conferenceCallId) throws RemoteException { }
288
289 @Override
290 public void swapConference(String conferenceCallId) throws RemoteException { }
291
292 @Override
293 public void onPostDialContinue(String callId, boolean proceed) throws RemoteException { }
294
295 @Override
Tyler Gunnd45e6d92016-03-10 20:15:39 -0800296 public void pullExternalCall(String callId) throws RemoteException { }
297
298 @Override
299 public void sendCallEvent(String callId, String event, Bundle extras) throws RemoteException
300 {}
301
Tyler Gunn961694a2016-03-21 16:01:40 -0700302 public void onExtrasChanged(String callId, Bundle extras) throws RemoteException {
303 mConnectionServiceDelegateAdapter.onExtrasChanged(callId, extras);
304 }
305
Tyler Gunnd45e6d92016-03-10 20:15:39 -0800306 @Override
Suchand Ghosh47b2f422014-09-22 12:13:47 +0530307 public void addParticipantWithConference(String callId, String recipients) {}
308
309 @Override
Ihab Awad1b5490a2015-05-12 13:13:48 -0700310 public IBinder asBinder() {
311 return this;
312 }
313
314 @Override
315 public IInterface queryLocalInterface(String descriptor) {
316 return this;
317 }
Hall Liuf7783fb2015-11-23 18:45:48 -0800318 }
319
Abhijith Shastryb7853c02016-02-03 12:56:59 -0800320 FakeConnectionServiceDelegate mConnectionServiceDelegate =
Hall Liuf7783fb2015-11-23 18:45:48 -0800321 new FakeConnectionServiceDelegate();
322 private IConnectionService mConnectionServiceDelegateAdapter =
323 IConnectionService.Stub.asInterface(mConnectionServiceDelegate.onBind(null));
Ihab Awad1b5490a2015-05-12 13:13:48 -0700324
Abhijith Shastryc6e42ef2016-02-19 18:26:44 -0800325 FakeConnectionService mConnectionService = new FakeConnectionService();
Ihab Awad1b5490a2015-05-12 13:13:48 -0700326 private IConnectionService.Stub mConnectionServiceSpy = Mockito.spy(mConnectionService);
Ihab Awadaa383cc2015-03-22 22:12:28 -0700327
328 public class ConnectionInfo {
329 PhoneAccountHandle connectionManagerPhoneAccount;
330 String id;
331 boolean ringing;
332 ConnectionRequest request;
333 boolean isIncoming;
334 boolean isUnknown;
335 int state;
336 int addressPresentation;
337 int capabilities;
Tyler Gunn571d5e62016-03-15 15:55:18 -0700338 int properties;
Christine Hallstrom96a0be62016-11-30 16:05:13 -0800339 int supportedAudioRoutes;
Ihab Awadaa383cc2015-03-22 22:12:28 -0700340 StatusHints statusHints;
341 DisconnectCause disconnectCause;
342 String conferenceId;
343 String callerDisplayName;
344 int callerDisplayNamePresentation;
345 final List<String> conferenceableConnectionIds = new ArrayList<>();
346 IVideoProvider videoProvider;
Tyler Gunnb492f4c2015-12-15 08:15:43 -0800347 Connection.VideoProvider videoProviderImpl;
348 MockVideoProvider mockVideoProvider;
Ihab Awadaa383cc2015-03-22 22:12:28 -0700349 int videoState;
350 boolean isVoipAudioMode;
Santos Cordonb3907b32015-05-27 17:39:59 -0700351 Bundle extras;
Brad Ebinger0d402552016-05-27 16:02:53 -0700352 boolean isConferenceCreated;
Ihab Awadaa383cc2015-03-22 22:12:28 -0700353 }
354
355 public class ConferenceInfo {
356 PhoneAccountHandle phoneAccount;
357 int state;
358 int capabilities;
Tyler Gunn571d5e62016-03-15 15:55:18 -0700359 int properties;
Ihab Awadaa383cc2015-03-22 22:12:28 -0700360 final List<String> connectionIds = new ArrayList<>();
Rekha Kumard240fe82015-04-01 21:45:57 -0700361 IVideoProvider videoProvider;
362 int videoState;
Ihab Awadaa383cc2015-03-22 22:12:28 -0700363 long connectTimeMillis;
Andrew Lee569b54e2015-04-16 13:57:49 -0700364 StatusHints statusHints;
Santos Cordonb3907b32015-05-27 17:39:59 -0700365 Bundle extras;
Ihab Awadaa383cc2015-03-22 22:12:28 -0700366 }
367
368 public String mLatestConnectionId;
Tyler Gunn961694a2016-03-21 16:01:40 -0700369 public Connection mLatestConnection;
370 public Conference mLatestConference;
Ihab Awadaa383cc2015-03-22 22:12:28 -0700371 public final Set<IConnectionServiceAdapter> mConnectionServiceAdapters = new HashSet<>();
372 public final Map<String, ConnectionInfo> mConnectionById = new HashMap<>();
373 public final Map<String, ConferenceInfo> mConferenceById = new HashMap<>();
374 public final List<ComponentName> mRemoteConnectionServiceNames = new ArrayList<>();
375 public final List<IBinder> mRemoteConnectionServices = new ArrayList<>();
376
Ihab Awad1b5490a2015-05-12 13:13:48 -0700377 public ConnectionServiceFixture() throws Exception { }
Ihab Awadaa383cc2015-03-22 22:12:28 -0700378
379 @Override
380 public IConnectionService getTestDouble() {
Ihab Awad1b5490a2015-05-12 13:13:48 -0700381 return mConnectionServiceSpy;
Ihab Awadaa383cc2015-03-22 22:12:28 -0700382 }
383
384 public void sendHandleCreateConnectionComplete(String id) throws Exception {
385 for (IConnectionServiceAdapter a : mConnectionServiceAdapters) {
386 a.handleCreateConnectionComplete(
387 id,
388 mConnectionById.get(id).request,
389 parcelable(mConnectionById.get(id)));
390 }
391 }
392
393 public void sendSetActive(String id) throws Exception {
394 mConnectionById.get(id).state = Connection.STATE_ACTIVE;
395 for (IConnectionServiceAdapter a : mConnectionServiceAdapters) {
396 a.setActive(id);
397 }
398 }
399
400 public void sendSetRinging(String id) throws Exception {
401 mConnectionById.get(id).state = Connection.STATE_RINGING;
402 for (IConnectionServiceAdapter a : mConnectionServiceAdapters) {
403 a.setRinging(id);
404 }
405 }
406
407 public void sendSetDialing(String id) throws Exception {
408 mConnectionById.get(id).state = Connection.STATE_DIALING;
409 for (IConnectionServiceAdapter a : mConnectionServiceAdapters) {
410 a.setDialing(id);
411 }
412 }
413
414 public void sendSetDisconnected(String id, int disconnectCause) throws Exception {
415 mConnectionById.get(id).state = Connection.STATE_DISCONNECTED;
416 mConnectionById.get(id).disconnectCause = new DisconnectCause(disconnectCause);
417 for (IConnectionServiceAdapter a : mConnectionServiceAdapters) {
418 a.setDisconnected(id, mConnectionById.get(id).disconnectCause);
419 }
420 }
421
422 public void sendSetOnHold(String id) throws Exception {
423 mConnectionById.get(id).state = Connection.STATE_HOLDING;
424 for (IConnectionServiceAdapter a : mConnectionServiceAdapters) {
425 a.setOnHold(id);
426 }
427 }
428
429 public void sendSetRingbackRequested(String id) throws Exception {
430 for (IConnectionServiceAdapter a : mConnectionServiceAdapters) {
431 a.setRingbackRequested(id, mConnectionById.get(id).ringing);
432 }
433 }
434
435 public void sendSetConnectionCapabilities(String id) throws Exception {
436 for (IConnectionServiceAdapter a : mConnectionServiceAdapters) {
437 a.setConnectionCapabilities(id, mConnectionById.get(id).capabilities);
438 }
439 }
440
Hall Liud7fe6862016-09-09 16:36:14 -0700441 public void sendSetConnectionProperties(String id) throws Exception {
442 for (IConnectionServiceAdapter a : mConnectionServiceAdapters) {
443 a.setConnectionProperties(id, mConnectionById.get(id).properties);
444 }
445 }
Ihab Awadaa383cc2015-03-22 22:12:28 -0700446 public void sendSetIsConferenced(String id) throws Exception {
447 for (IConnectionServiceAdapter a : mConnectionServiceAdapters) {
448 a.setIsConferenced(id, mConnectionById.get(id).conferenceId);
449 }
450 }
451
452 public void sendAddConferenceCall(String id) throws Exception {
453 for (IConnectionServiceAdapter a : mConnectionServiceAdapters) {
454 a.addConferenceCall(id, parcelable(mConferenceById.get(id)));
455 }
456 }
457
458 public void sendRemoveCall(String id) throws Exception {
459 for (IConnectionServiceAdapter a : mConnectionServiceAdapters) {
460 a.removeCall(id);
461 }
462 }
463
464 public void sendOnPostDialWait(String id, String remaining) throws Exception {
465 for (IConnectionServiceAdapter a : mConnectionServiceAdapters) {
466 a.onPostDialWait(id, remaining);
467 }
468 }
469
470 public void sendOnPostDialChar(String id, char nextChar) throws Exception {
471 for (IConnectionServiceAdapter a : mConnectionServiceAdapters) {
472 a.onPostDialChar(id, nextChar);
473 }
474 }
475
476 public void sendQueryRemoteConnectionServices() throws Exception {
477 mRemoteConnectionServices.clear();
478 for (IConnectionServiceAdapter a : mConnectionServiceAdapters) {
479 a.queryRemoteConnectionServices(new RemoteServiceCallback.Stub() {
480 @Override
481 public void onError() throws RemoteException {
482 throw new RuntimeException();
483 }
484
485 @Override
486 public void onResult(
487 List<ComponentName> names,
488 List<IBinder> services)
489 throws RemoteException {
490 TestCase.assertEquals(names.size(), services.size());
491 mRemoteConnectionServiceNames.addAll(names);
492 mRemoteConnectionServices.addAll(services);
493 }
494
495 @Override
496 public IBinder asBinder() {
497 return this;
498 }
499 });
500 }
501 }
502
503 public void sendSetVideoProvider(String id) throws Exception {
504 for (IConnectionServiceAdapter a : mConnectionServiceAdapters) {
505 a.setVideoProvider(id, mConnectionById.get(id).videoProvider);
506 }
507 }
508
509 public void sendSetVideoState(String id) throws Exception {
510 for (IConnectionServiceAdapter a : mConnectionServiceAdapters) {
511 a.setVideoState(id, mConnectionById.get(id).videoState);
512 }
513 }
514
515 public void sendSetIsVoipAudioMode(String id) throws Exception {
516 for (IConnectionServiceAdapter a : mConnectionServiceAdapters) {
517 a.setIsVoipAudioMode(id, mConnectionById.get(id).isVoipAudioMode);
518 }
519 }
520
521 public void sendSetStatusHints(String id) throws Exception {
522 for (IConnectionServiceAdapter a : mConnectionServiceAdapters) {
523 a.setStatusHints(id, mConnectionById.get(id).statusHints);
524 }
525 }
526
527 public void sendSetAddress(String id) throws Exception {
528 for (IConnectionServiceAdapter a : mConnectionServiceAdapters) {
529 a.setAddress(
530 id,
531 mConnectionById.get(id).request.getAddress(),
532 mConnectionById.get(id).addressPresentation);
533 }
534 }
535
536 public void sendSetCallerDisplayName(String id) throws Exception {
537 for (IConnectionServiceAdapter a : mConnectionServiceAdapters) {
538 a.setCallerDisplayName(
539 id,
540 mConnectionById.get(id).callerDisplayName,
541 mConnectionById.get(id).callerDisplayNamePresentation);
542 }
543 }
544
545 public void sendSetConferenceableConnections(String id) throws Exception {
546 for (IConnectionServiceAdapter a : mConnectionServiceAdapters) {
547 a.setConferenceableConnections(id, mConnectionById.get(id).conferenceableConnectionIds);
548 }
549 }
550
551 public void sendAddExistingConnection(String id) throws Exception {
552 for (IConnectionServiceAdapter a : mConnectionServiceAdapters) {
553 a.addExistingConnection(id, parcelable(mConnectionById.get(id)));
554 }
555 }
556
Tyler Gunnd45e6d92016-03-10 20:15:39 -0800557 public void sendConnectionEvent(String id, String event, Bundle extras) throws Exception {
558 for (IConnectionServiceAdapter a : mConnectionServiceAdapters) {
559 a.onConnectionEvent(id, event, extras);
560 }
561 }
562
Brad Ebinger0d402552016-05-27 16:02:53 -0700563 public void sendSetConferenceMergeFailed(String id) throws Exception {
564 for (IConnectionServiceAdapter a : mConnectionServiceAdapters) {
565 a.setConferenceMergeFailed(id);
566 }
567 }
568
Tyler Gunn961694a2016-03-21 16:01:40 -0700569 /**
570 * Waits until the {@link Connection#onExtrasChanged(Bundle)} API has been called on a
571 * {@link Connection} or {@link Conference}.
572 */
573 public void waitForExtras() {
574 try {
575 mExtrasLock.await(TelecomSystemTest.TEST_TIMEOUT, TimeUnit.MILLISECONDS);
576 } catch (InterruptedException ie) {
577 }
578 mExtrasLock = new CountDownLatch(1);
579 }
580
Ihab Awadaa383cc2015-03-22 22:12:28 -0700581 private ParcelableConference parcelable(ConferenceInfo c) {
582 return new ParcelableConference(
583 c.phoneAccount,
584 c.state,
585 c.capabilities,
Tyler Gunn571d5e62016-03-15 15:55:18 -0700586 c.properties,
Ihab Awadaa383cc2015-03-22 22:12:28 -0700587 c.connectionIds,
Rekha Kumard240fe82015-04-01 21:45:57 -0700588 c.videoProvider,
589 c.videoState,
Andrew Lee569b54e2015-04-16 13:57:49 -0700590 c.connectTimeMillis,
Santos Cordonb3907b32015-05-27 17:39:59 -0700591 c.statusHints,
592 c.extras);
Ihab Awadaa383cc2015-03-22 22:12:28 -0700593 }
594
595 private ParcelableConnection parcelable(ConnectionInfo c) {
596 return new ParcelableConnection(
597 c.request.getAccountHandle(),
598 c.state,
599 c.capabilities,
Tyler Gunn571d5e62016-03-15 15:55:18 -0700600 c.properties,
Christine Hallstrom96a0be62016-11-30 16:05:13 -0800601 c.supportedAudioRoutes,
Ihab Awadaa383cc2015-03-22 22:12:28 -0700602 c.request.getAddress(),
603 c.addressPresentation,
604 c.callerDisplayName,
605 c.callerDisplayNamePresentation,
606 c.videoProvider,
607 c.videoState,
608 false, /* ringback requested */
609 false, /* voip audio mode */
Roshan Pius084ab082015-07-15 12:17:04 -0700610 0, /* Connect Time for conf call on this connection */
Ihab Awadaa383cc2015-03-22 22:12:28 -0700611 c.statusHints,
612 c.disconnectCause,
Santos Cordonb3907b32015-05-27 17:39:59 -0700613 c.conferenceableConnectionIds,
614 c.extras);
Ihab Awadaa383cc2015-03-22 22:12:28 -0700615 }
616}