blob: 966b2ae12614414d48fe19901c302c768e8e19a3 [file] [log] [blame]
Ihab Awad542e0ea2014-05-16 10:22:16 -07001/*
2 * Copyright (C) 2014 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
Tyler Gunnef9f6f92014-09-12 22:16:17 -070017package android.telecom;
Ihab Awad542e0ea2014-05-16 10:22:16 -070018
Santos Cordon5c6fa952014-07-20 17:47:12 -070019import android.annotation.SdkConstant;
Sailesh Nepal2a46b902014-07-04 17:21:07 -070020import android.app.Service;
Santos Cordon52d8a152014-06-17 19:08:45 -070021import android.content.ComponentName;
Santos Cordon5c6fa952014-07-20 17:47:12 -070022import android.content.Intent;
Ihab Awad542e0ea2014-05-16 10:22:16 -070023import android.net.Uri;
Santos Cordon6b7f9552015-05-27 17:21:45 -070024import android.os.Bundle;
Santos Cordon52d8a152014-06-17 19:08:45 -070025import android.os.Handler;
26import android.os.IBinder;
27import android.os.Looper;
Sailesh Nepal2a46b902014-07-04 17:21:07 -070028import android.os.Message;
Andrew Lee14185762014-07-25 09:41:56 -070029
Sailesh Nepal2a46b902014-07-04 17:21:07 -070030import com.android.internal.os.SomeArgs;
Tyler Gunnef9f6f92014-09-12 22:16:17 -070031import com.android.internal.telecom.IConnectionService;
32import com.android.internal.telecom.IConnectionServiceAdapter;
33import com.android.internal.telecom.RemoteServiceCallback;
Santos Cordon52d8a152014-06-17 19:08:45 -070034
Ihab Awad5d0410f2014-07-30 10:07:40 -070035import java.util.ArrayList;
Santos Cordonb6939982014-06-04 20:20:58 -070036import java.util.Collection;
Santos Cordon7c7bc7f2014-07-28 18:15:48 -070037import java.util.Collections;
Santos Cordon52d8a152014-06-17 19:08:45 -070038import java.util.List;
Ihab Awad542e0ea2014-05-16 10:22:16 -070039import java.util.Map;
Santos Cordon823fd3c2014-08-07 18:35:18 -070040import java.util.UUID;
mike dooley95e80702014-09-18 14:07:52 -070041import java.util.concurrent.ConcurrentHashMap;
Ihab Awad542e0ea2014-05-16 10:22:16 -070042
43/**
Santos Cordon895d4b82015-06-25 16:41:48 -070044 * An abstract service that should be implemented by any apps which can make phone calls (VoIP or
45 * otherwise) and want those calls to be integrated into the built-in phone app.
Santos Cordona663f862014-10-29 13:49:58 -070046 * Once implemented, the {@code ConnectionService} needs two additional steps before it will be
47 * integrated into the phone app:
48 * <p>
49 * 1. <i>Registration in AndroidManifest.xml</i>
50 * <br/>
51 * <pre>
52 * &lt;service android:name="com.example.package.MyConnectionService"
53 * android:label="@string/some_label_for_my_connection_service"
Yorke Lee249c12e2015-05-13 15:59:29 -070054 * android:permission="android.permission.BIND_TELECOM_CONNECTION_SERVICE"&gt;
Santos Cordona663f862014-10-29 13:49:58 -070055 * &lt;intent-filter&gt;
56 * &lt;action android:name="android.telecom.ConnectionService" /&gt;
57 * &lt;/intent-filter&gt;
58 * &lt;/service&gt;
59 * </pre>
60 * <p>
61 * 2. <i> Registration of {@link PhoneAccount} with {@link TelecomManager}.</i>
62 * <br/>
63 * See {@link PhoneAccount} and {@link TelecomManager#registerPhoneAccount} for more information.
64 * <p>
Santos Cordon895d4b82015-06-25 16:41:48 -070065 * Once registered and enabled by the user in the phone app settings, telecom will bind to a
Santos Cordona663f862014-10-29 13:49:58 -070066 * {@code ConnectionService} implementation when it wants that {@code ConnectionService} to place
67 * a call or the service has indicated that is has an incoming call through
68 * {@link TelecomManager#addNewIncomingCall}. The {@code ConnectionService} can then expect a call
69 * to {@link #onCreateIncomingConnection} or {@link #onCreateOutgoingConnection} wherein it
70 * should provide a new instance of a {@link Connection} object. It is through this
71 * {@link Connection} object that telecom receives state updates and the {@code ConnectionService}
72 * receives call-commands such as answer, reject, hold and disconnect.
73 * <p>
74 * When there are no more live calls, telecom will unbind from the {@code ConnectionService}.
Ihab Awad542e0ea2014-05-16 10:22:16 -070075 */
Sailesh Nepal2a46b902014-07-04 17:21:07 -070076public abstract class ConnectionService extends Service {
Santos Cordon5c6fa952014-07-20 17:47:12 -070077 /**
78 * The {@link Intent} that must be declared as handled by the service.
79 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -070080 @SdkConstant(SdkConstant.SdkConstantType.SERVICE_ACTION)
Tyler Gunnef9f6f92014-09-12 22:16:17 -070081 public static final String SERVICE_INTERFACE = "android.telecom.ConnectionService";
Santos Cordon5c6fa952014-07-20 17:47:12 -070082
Ihab Awad542e0ea2014-05-16 10:22:16 -070083 // Flag controlling whether PII is emitted into the logs
Ihab Awad60ac30b2014-05-20 22:32:12 -070084 private static final boolean PII_DEBUG = Log.isLoggable(android.util.Log.DEBUG);
Ihab Awad542e0ea2014-05-16 10:22:16 -070085
Ihab Awad8aecfed2014-08-08 17:06:11 -070086 private static final int MSG_ADD_CONNECTION_SERVICE_ADAPTER = 1;
Sailesh Nepalc5b01572014-07-14 16:29:44 -070087 private static final int MSG_CREATE_CONNECTION = 2;
Sailesh Nepal2a46b902014-07-04 17:21:07 -070088 private static final int MSG_ABORT = 3;
Sailesh Nepalc5b01572014-07-14 16:29:44 -070089 private static final int MSG_ANSWER = 4;
90 private static final int MSG_REJECT = 5;
91 private static final int MSG_DISCONNECT = 6;
92 private static final int MSG_HOLD = 7;
93 private static final int MSG_UNHOLD = 8;
Yorke Lee4af59352015-05-13 14:14:54 -070094 private static final int MSG_ON_CALL_AUDIO_STATE_CHANGED = 9;
Sailesh Nepalc5b01572014-07-14 16:29:44 -070095 private static final int MSG_PLAY_DTMF_TONE = 10;
96 private static final int MSG_STOP_DTMF_TONE = 11;
97 private static final int MSG_CONFERENCE = 12;
98 private static final int MSG_SPLIT_FROM_CONFERENCE = 13;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070099 private static final int MSG_ON_POST_DIAL_CONTINUE = 14;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700100 private static final int MSG_REMOVE_CONNECTION_SERVICE_ADAPTER = 16;
Tyler Gunnbe74de02014-08-29 14:51:48 -0700101 private static final int MSG_ANSWER_VIDEO = 17;
Santos Cordona4868042014-09-04 17:39:22 -0700102 private static final int MSG_MERGE_CONFERENCE = 18;
103 private static final int MSG_SWAP_CONFERENCE = 19;
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700104
Sailesh Nepalcf7020b2014-08-20 10:07:19 -0700105 private static Connection sNullConnection;
106
mike dooley95e80702014-09-18 14:07:52 -0700107 private final Map<String, Connection> mConnectionById = new ConcurrentHashMap<>();
108 private final Map<Connection, String> mIdByConnection = new ConcurrentHashMap<>();
109 private final Map<String, Conference> mConferenceById = new ConcurrentHashMap<>();
110 private final Map<Conference, String> mIdByConference = new ConcurrentHashMap<>();
Ihab Awadb8e85c72014-08-23 20:34:57 -0700111 private final RemoteConnectionManager mRemoteConnectionManager =
112 new RemoteConnectionManager(this);
Ihab Awad5d0410f2014-07-30 10:07:40 -0700113 private final List<Runnable> mPreInitializationConnectionRequests = new ArrayList<>();
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700114 private final ConnectionServiceAdapter mAdapter = new ConnectionServiceAdapter();
Ihab Awad542e0ea2014-05-16 10:22:16 -0700115
Santos Cordon823fd3c2014-08-07 18:35:18 -0700116 private boolean mAreAccountsInitialized = false;
Santos Cordon0159ac02014-08-21 14:28:11 -0700117 private Conference sNullConference;
Santos Cordon823fd3c2014-08-07 18:35:18 -0700118
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700119 private final IBinder mBinder = new IConnectionService.Stub() {
120 @Override
121 public void addConnectionServiceAdapter(IConnectionServiceAdapter adapter) {
Ihab Awad8aecfed2014-08-08 17:06:11 -0700122 mHandler.obtainMessage(MSG_ADD_CONNECTION_SERVICE_ADAPTER, adapter).sendToTarget();
123 }
124
125 public void removeConnectionServiceAdapter(IConnectionServiceAdapter adapter) {
126 mHandler.obtainMessage(MSG_REMOVE_CONNECTION_SERVICE_ADAPTER, adapter).sendToTarget();
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700127 }
128
129 @Override
Ihab Awadf8b69882014-07-25 15:14:01 -0700130 public void createConnection(
131 PhoneAccountHandle connectionManagerPhoneAccount,
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700132 String id,
Ihab Awadf8b69882014-07-25 15:14:01 -0700133 ConnectionRequest request,
Yorke Leec3cf9822014-10-02 09:38:39 -0700134 boolean isIncoming,
135 boolean isUnknown) {
Ihab Awadf8b69882014-07-25 15:14:01 -0700136 SomeArgs args = SomeArgs.obtain();
137 args.arg1 = connectionManagerPhoneAccount;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700138 args.arg2 = id;
139 args.arg3 = request;
Ihab Awadf8b69882014-07-25 15:14:01 -0700140 args.argi1 = isIncoming ? 1 : 0;
Yorke Leec3cf9822014-10-02 09:38:39 -0700141 args.argi2 = isUnknown ? 1 : 0;
Ihab Awadf8b69882014-07-25 15:14:01 -0700142 mHandler.obtainMessage(MSG_CREATE_CONNECTION, args).sendToTarget();
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700143 }
144
145 @Override
146 public void abort(String callId) {
147 mHandler.obtainMessage(MSG_ABORT, callId).sendToTarget();
148 }
149
150 @Override
Tyler Gunnbe74de02014-08-29 14:51:48 -0700151 public void answerVideo(String callId, int videoState) {
Andrew Lee8da4c3c2014-07-16 10:11:42 -0700152 SomeArgs args = SomeArgs.obtain();
153 args.arg1 = callId;
Evan Charltonbf11f982014-07-20 22:06:28 -0700154 args.argi1 = videoState;
Tyler Gunnbe74de02014-08-29 14:51:48 -0700155 mHandler.obtainMessage(MSG_ANSWER_VIDEO, args).sendToTarget();
156 }
157
158 @Override
159 public void answer(String callId) {
160 mHandler.obtainMessage(MSG_ANSWER, callId).sendToTarget();
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700161 }
162
163 @Override
164 public void reject(String callId) {
165 mHandler.obtainMessage(MSG_REJECT, callId).sendToTarget();
166 }
167
168 @Override
169 public void disconnect(String callId) {
170 mHandler.obtainMessage(MSG_DISCONNECT, callId).sendToTarget();
171 }
172
173 @Override
174 public void hold(String callId) {
175 mHandler.obtainMessage(MSG_HOLD, callId).sendToTarget();
176 }
177
178 @Override
179 public void unhold(String callId) {
180 mHandler.obtainMessage(MSG_UNHOLD, callId).sendToTarget();
181 }
182
183 @Override
Yorke Lee4af59352015-05-13 14:14:54 -0700184 public void onCallAudioStateChanged(String callId, CallAudioState callAudioState) {
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700185 SomeArgs args = SomeArgs.obtain();
186 args.arg1 = callId;
Yorke Lee4af59352015-05-13 14:14:54 -0700187 args.arg2 = callAudioState;
188 mHandler.obtainMessage(MSG_ON_CALL_AUDIO_STATE_CHANGED, args).sendToTarget();
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700189 }
190
191 @Override
192 public void playDtmfTone(String callId, char digit) {
193 mHandler.obtainMessage(MSG_PLAY_DTMF_TONE, digit, 0, callId).sendToTarget();
194 }
195
196 @Override
197 public void stopDtmfTone(String callId) {
198 mHandler.obtainMessage(MSG_STOP_DTMF_TONE, callId).sendToTarget();
199 }
200
201 @Override
Santos Cordon823fd3c2014-08-07 18:35:18 -0700202 public void conference(String callId1, String callId2) {
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700203 SomeArgs args = SomeArgs.obtain();
Santos Cordon823fd3c2014-08-07 18:35:18 -0700204 args.arg1 = callId1;
205 args.arg2 = callId2;
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700206 mHandler.obtainMessage(MSG_CONFERENCE, args).sendToTarget();
207 }
208
209 @Override
210 public void splitFromConference(String callId) {
211 mHandler.obtainMessage(MSG_SPLIT_FROM_CONFERENCE, callId).sendToTarget();
212 }
213
214 @Override
Santos Cordona4868042014-09-04 17:39:22 -0700215 public void mergeConference(String callId) {
216 mHandler.obtainMessage(MSG_MERGE_CONFERENCE, callId).sendToTarget();
217 }
218
219 @Override
220 public void swapConference(String callId) {
221 mHandler.obtainMessage(MSG_SWAP_CONFERENCE, callId).sendToTarget();
222 }
223
224 @Override
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700225 public void onPostDialContinue(String callId, boolean proceed) {
226 SomeArgs args = SomeArgs.obtain();
227 args.arg1 = callId;
228 args.argi1 = proceed ? 1 : 0;
229 mHandler.obtainMessage(MSG_ON_POST_DIAL_CONTINUE, args).sendToTarget();
230 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700231 };
232
233 private final Handler mHandler = new Handler(Looper.getMainLooper()) {
234 @Override
235 public void handleMessage(Message msg) {
236 switch (msg.what) {
Ihab Awad8aecfed2014-08-08 17:06:11 -0700237 case MSG_ADD_CONNECTION_SERVICE_ADAPTER:
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700238 mAdapter.addAdapter((IConnectionServiceAdapter) msg.obj);
239 onAdapterAttached();
240 break;
Ihab Awad8aecfed2014-08-08 17:06:11 -0700241 case MSG_REMOVE_CONNECTION_SERVICE_ADAPTER:
242 mAdapter.removeAdapter((IConnectionServiceAdapter) msg.obj);
243 break;
Ihab Awadf8b69882014-07-25 15:14:01 -0700244 case MSG_CREATE_CONNECTION: {
245 SomeArgs args = (SomeArgs) msg.obj;
246 try {
Ihab Awad5d0410f2014-07-30 10:07:40 -0700247 final PhoneAccountHandle connectionManagerPhoneAccount =
Ihab Awadf8b69882014-07-25 15:14:01 -0700248 (PhoneAccountHandle) args.arg1;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700249 final String id = (String) args.arg2;
250 final ConnectionRequest request = (ConnectionRequest) args.arg3;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700251 final boolean isIncoming = args.argi1 == 1;
Yorke Leec3cf9822014-10-02 09:38:39 -0700252 final boolean isUnknown = args.argi2 == 1;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700253 if (!mAreAccountsInitialized) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700254 Log.d(this, "Enqueueing pre-init request %s", id);
Ihab Awad5d0410f2014-07-30 10:07:40 -0700255 mPreInitializationConnectionRequests.add(new Runnable() {
256 @Override
257 public void run() {
258 createConnection(
259 connectionManagerPhoneAccount,
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700260 id,
Ihab Awad5d0410f2014-07-30 10:07:40 -0700261 request,
Yorke Leec3cf9822014-10-02 09:38:39 -0700262 isIncoming,
263 isUnknown);
Ihab Awad5d0410f2014-07-30 10:07:40 -0700264 }
265 });
266 } else {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700267 createConnection(
268 connectionManagerPhoneAccount,
269 id,
270 request,
Yorke Leec3cf9822014-10-02 09:38:39 -0700271 isIncoming,
272 isUnknown);
Ihab Awad5d0410f2014-07-30 10:07:40 -0700273 }
Ihab Awadf8b69882014-07-25 15:14:01 -0700274 } finally {
275 args.recycle();
276 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700277 break;
Ihab Awadf8b69882014-07-25 15:14:01 -0700278 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700279 case MSG_ABORT:
280 abort((String) msg.obj);
281 break;
Tyler Gunnbe74de02014-08-29 14:51:48 -0700282 case MSG_ANSWER:
283 answer((String) msg.obj);
284 break;
285 case MSG_ANSWER_VIDEO: {
Andrew Lee8da4c3c2014-07-16 10:11:42 -0700286 SomeArgs args = (SomeArgs) msg.obj;
287 try {
288 String callId = (String) args.arg1;
Evan Charltonbf11f982014-07-20 22:06:28 -0700289 int videoState = args.argi1;
Tyler Gunnbe74de02014-08-29 14:51:48 -0700290 answerVideo(callId, videoState);
Andrew Lee8da4c3c2014-07-16 10:11:42 -0700291 } finally {
292 args.recycle();
293 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700294 break;
Andrew Lee8da4c3c2014-07-16 10:11:42 -0700295 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700296 case MSG_REJECT:
297 reject((String) msg.obj);
298 break;
299 case MSG_DISCONNECT:
300 disconnect((String) msg.obj);
301 break;
302 case MSG_HOLD:
303 hold((String) msg.obj);
304 break;
305 case MSG_UNHOLD:
306 unhold((String) msg.obj);
307 break;
Yorke Lee4af59352015-05-13 14:14:54 -0700308 case MSG_ON_CALL_AUDIO_STATE_CHANGED: {
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700309 SomeArgs args = (SomeArgs) msg.obj;
310 try {
311 String callId = (String) args.arg1;
Yorke Lee4af59352015-05-13 14:14:54 -0700312 CallAudioState audioState = (CallAudioState) args.arg2;
313 onCallAudioStateChanged(callId, new CallAudioState(audioState));
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700314 } finally {
315 args.recycle();
316 }
317 break;
318 }
319 case MSG_PLAY_DTMF_TONE:
320 playDtmfTone((String) msg.obj, (char) msg.arg1);
321 break;
322 case MSG_STOP_DTMF_TONE:
323 stopDtmfTone((String) msg.obj);
324 break;
325 case MSG_CONFERENCE: {
326 SomeArgs args = (SomeArgs) msg.obj;
327 try {
Santos Cordon823fd3c2014-08-07 18:35:18 -0700328 String callId1 = (String) args.arg1;
329 String callId2 = (String) args.arg2;
330 conference(callId1, callId2);
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700331 } finally {
332 args.recycle();
333 }
334 break;
335 }
336 case MSG_SPLIT_FROM_CONFERENCE:
337 splitFromConference((String) msg.obj);
338 break;
Santos Cordona4868042014-09-04 17:39:22 -0700339 case MSG_MERGE_CONFERENCE:
340 mergeConference((String) msg.obj);
341 break;
342 case MSG_SWAP_CONFERENCE:
343 swapConference((String) msg.obj);
344 break;
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700345 case MSG_ON_POST_DIAL_CONTINUE: {
346 SomeArgs args = (SomeArgs) msg.obj;
347 try {
348 String callId = (String) args.arg1;
349 boolean proceed = (args.argi1 == 1);
350 onPostDialContinue(callId, proceed);
351 } finally {
352 args.recycle();
353 }
354 break;
355 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700356 default:
357 break;
358 }
359 }
360 };
361
Santos Cordon823fd3c2014-08-07 18:35:18 -0700362 private final Conference.Listener mConferenceListener = new Conference.Listener() {
363 @Override
364 public void onStateChanged(Conference conference, int oldState, int newState) {
365 String id = mIdByConference.get(conference);
366 switch (newState) {
367 case Connection.STATE_ACTIVE:
368 mAdapter.setActive(id);
369 break;
370 case Connection.STATE_HOLDING:
371 mAdapter.setOnHold(id);
372 break;
373 case Connection.STATE_DISCONNECTED:
374 // handled by onDisconnected
375 break;
376 }
377 }
378
379 @Override
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700380 public void onDisconnected(Conference conference, DisconnectCause disconnectCause) {
Santos Cordon823fd3c2014-08-07 18:35:18 -0700381 String id = mIdByConference.get(conference);
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700382 mAdapter.setDisconnected(id, disconnectCause);
Santos Cordon823fd3c2014-08-07 18:35:18 -0700383 }
384
385 @Override
386 public void onConnectionAdded(Conference conference, Connection connection) {
387 }
388
389 @Override
390 public void onConnectionRemoved(Conference conference, Connection connection) {
391 }
392
393 @Override
Ihab Awad50e35062014-09-30 09:17:03 -0700394 public void onConferenceableConnectionsChanged(
395 Conference conference, List<Connection> conferenceableConnections) {
396 mAdapter.setConferenceableConnections(
397 mIdByConference.get(conference),
398 createConnectionIdList(conferenceableConnections));
399 }
400
401 @Override
Santos Cordon823fd3c2014-08-07 18:35:18 -0700402 public void onDestroyed(Conference conference) {
403 removeConference(conference);
404 }
405
406 @Override
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800407 public void onConnectionCapabilitiesChanged(
408 Conference conference,
409 int connectionCapabilities) {
Santos Cordon823fd3c2014-08-07 18:35:18 -0700410 String id = mIdByConference.get(conference);
411 Log.d(this, "call capabilities: conference: %s",
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800412 Connection.capabilitiesToString(connectionCapabilities));
413 mAdapter.setConnectionCapabilities(id, connectionCapabilities);
Santos Cordon823fd3c2014-08-07 18:35:18 -0700414 }
Rekha Kumar07366812015-03-24 16:42:31 -0700415
416 @Override
417 public void onVideoStateChanged(Conference c, int videoState) {
418 String id = mIdByConference.get(c);
419 Log.d(this, "onVideoStateChanged set video state %d", videoState);
420 mAdapter.setVideoState(id, videoState);
421 }
422
423 @Override
424 public void onVideoProviderChanged(Conference c, Connection.VideoProvider videoProvider) {
425 String id = mIdByConference.get(c);
426 Log.d(this, "onVideoProviderChanged: Connection: %s, VideoProvider: %s", c,
427 videoProvider);
428 mAdapter.setVideoProvider(id, videoProvider);
429 }
Andrew Lee0f51da32015-04-16 13:11:55 -0700430
431 @Override
Andrew Leeedc625f2015-04-14 13:38:12 -0700432 public void onStatusHintsChanged(Conference conference, StatusHints statusHints) {
433 String id = mIdByConference.get(conference);
434 mAdapter.setStatusHints(id, statusHints);
435 }
Santos Cordon6b7f9552015-05-27 17:21:45 -0700436
437 @Override
438 public void onExtrasChanged(Conference conference, Bundle extras) {
439 String id = mIdByConference.get(conference);
440 mAdapter.setExtras(id, extras);
441 }
Santos Cordon823fd3c2014-08-07 18:35:18 -0700442 };
443
Ihab Awad542e0ea2014-05-16 10:22:16 -0700444 private final Connection.Listener mConnectionListener = new Connection.Listener() {
445 @Override
446 public void onStateChanged(Connection c, int state) {
447 String id = mIdByConnection.get(c);
Ihab Awad42b30e12014-05-22 09:49:34 -0700448 Log.d(this, "Adapter set state %s %s", id, Connection.stateToString(state));
Ihab Awad542e0ea2014-05-16 10:22:16 -0700449 switch (state) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700450 case Connection.STATE_ACTIVE:
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700451 mAdapter.setActive(id);
Ihab Awad542e0ea2014-05-16 10:22:16 -0700452 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700453 case Connection.STATE_DIALING:
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700454 mAdapter.setDialing(id);
Ihab Awad542e0ea2014-05-16 10:22:16 -0700455 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700456 case Connection.STATE_DISCONNECTED:
Ihab Awad542e0ea2014-05-16 10:22:16 -0700457 // Handled in onDisconnected()
458 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700459 case Connection.STATE_HOLDING:
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700460 mAdapter.setOnHold(id);
Ihab Awad542e0ea2014-05-16 10:22:16 -0700461 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700462 case Connection.STATE_NEW:
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700463 // Nothing to tell Telecom
Ihab Awad542e0ea2014-05-16 10:22:16 -0700464 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700465 case Connection.STATE_RINGING:
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700466 mAdapter.setRinging(id);
Ihab Awad542e0ea2014-05-16 10:22:16 -0700467 break;
468 }
469 }
470
471 @Override
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700472 public void onDisconnected(Connection c, DisconnectCause disconnectCause) {
Ihab Awad542e0ea2014-05-16 10:22:16 -0700473 String id = mIdByConnection.get(c);
Andrew Lee26786392014-09-16 18:14:59 -0700474 Log.d(this, "Adapter set disconnected %s", disconnectCause);
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700475 mAdapter.setDisconnected(id, disconnectCause);
Ihab Awad542e0ea2014-05-16 10:22:16 -0700476 }
477
478 @Override
Tyler Gunnaa07df82014-07-17 07:50:22 -0700479 public void onVideoStateChanged(Connection c, int videoState) {
480 String id = mIdByConnection.get(c);
481 Log.d(this, "Adapter set video state %d", videoState);
482 mAdapter.setVideoState(id, videoState);
483 }
484
485 @Override
Andrew Lee100e2932014-09-08 15:34:24 -0700486 public void onAddressChanged(Connection c, Uri address, int presentation) {
Sailesh Nepal61203862014-07-11 14:50:13 -0700487 String id = mIdByConnection.get(c);
Andrew Lee100e2932014-09-08 15:34:24 -0700488 mAdapter.setAddress(id, address, presentation);
Sailesh Nepal61203862014-07-11 14:50:13 -0700489 }
490
491 @Override
492 public void onCallerDisplayNameChanged(
493 Connection c, String callerDisplayName, int presentation) {
494 String id = mIdByConnection.get(c);
495 mAdapter.setCallerDisplayName(id, callerDisplayName, presentation);
Ihab Awad542e0ea2014-05-16 10:22:16 -0700496 }
497
498 @Override
Ihab Awad542e0ea2014-05-16 10:22:16 -0700499 public void onDestroyed(Connection c) {
500 removeConnection(c);
501 }
Ihab Awadf8358972014-05-28 16:46:42 -0700502
503 @Override
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700504 public void onPostDialWait(Connection c, String remaining) {
Sailesh Nepal091768c2014-06-30 15:15:23 -0700505 String id = mIdByConnection.get(c);
506 Log.d(this, "Adapter onPostDialWait %s, %s", c, remaining);
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700507 mAdapter.onPostDialWait(id, remaining);
Sailesh Nepal091768c2014-06-30 15:15:23 -0700508 }
509
510 @Override
Nancy Chen27d1c2d2014-12-15 16:12:50 -0800511 public void onPostDialChar(Connection c, char nextChar) {
512 String id = mIdByConnection.get(c);
513 Log.d(this, "Adapter onPostDialChar %s, %s", c, nextChar);
514 mAdapter.onPostDialChar(id, nextChar);
515 }
516
517 @Override
Andrew Lee100e2932014-09-08 15:34:24 -0700518 public void onRingbackRequested(Connection c, boolean ringback) {
Ihab Awadf8358972014-05-28 16:46:42 -0700519 String id = mIdByConnection.get(c);
520 Log.d(this, "Adapter onRingback %b", ringback);
Andrew Lee100e2932014-09-08 15:34:24 -0700521 mAdapter.setRingbackRequested(id, ringback);
Ihab Awadf8358972014-05-28 16:46:42 -0700522 }
Santos Cordonb6939982014-06-04 20:20:58 -0700523
524 @Override
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800525 public void onConnectionCapabilitiesChanged(Connection c, int capabilities) {
Santos Cordonb6939982014-06-04 20:20:58 -0700526 String id = mIdByConnection.get(c);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700527 Log.d(this, "capabilities: parcelableconnection: %s",
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800528 Connection.capabilitiesToString(capabilities));
529 mAdapter.setConnectionCapabilities(id, capabilities);
Santos Cordonb6939982014-06-04 20:20:58 -0700530 }
531
Santos Cordonb6939982014-06-04 20:20:58 -0700532 @Override
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700533 public void onVideoProviderChanged(Connection c, Connection.VideoProvider videoProvider) {
Andrew Lee5ffbe8b2014-06-20 16:29:33 -0700534 String id = mIdByConnection.get(c);
Rekha Kumar07366812015-03-24 16:42:31 -0700535 Log.d(this, "onVideoProviderChanged: Connection: %s, VideoProvider: %s", c,
536 videoProvider);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700537 mAdapter.setVideoProvider(id, videoProvider);
Andrew Lee5ffbe8b2014-06-20 16:29:33 -0700538 }
Sailesh Nepal33aaae42014-07-07 22:49:44 -0700539
540 @Override
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700541 public void onAudioModeIsVoipChanged(Connection c, boolean isVoip) {
Sailesh Nepal33aaae42014-07-07 22:49:44 -0700542 String id = mIdByConnection.get(c);
Andrew Lee100e2932014-09-08 15:34:24 -0700543 mAdapter.setIsVoipAudioMode(id, isVoip);
Sailesh Nepal33aaae42014-07-07 22:49:44 -0700544 }
Sailesh Nepale7ef59a2014-07-08 21:48:22 -0700545
546 @Override
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700547 public void onStatusHintsChanged(Connection c, StatusHints statusHints) {
Sailesh Nepale7ef59a2014-07-08 21:48:22 -0700548 String id = mIdByConnection.get(c);
549 mAdapter.setStatusHints(id, statusHints);
550 }
Sailesh Nepal2ab88cc2014-07-18 14:49:18 -0700551
552 @Override
Tyler Gunn6d76ca02014-11-17 15:49:51 -0800553 public void onConferenceablesChanged(
Tyler Gunndf2cbc82015-04-20 09:13:01 -0700554 Connection connection, List<Conferenceable> conferenceables) {
Ihab Awadb8e85c72014-08-23 20:34:57 -0700555 mAdapter.setConferenceableConnections(
556 mIdByConnection.get(connection),
Tyler Gunn6d76ca02014-11-17 15:49:51 -0800557 createIdList(conferenceables));
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700558 }
Santos Cordon823fd3c2014-08-07 18:35:18 -0700559
560 @Override
561 public void onConferenceChanged(Connection connection, Conference conference) {
562 String id = mIdByConnection.get(connection);
563 if (id != null) {
564 String conferenceId = null;
565 if (conference != null) {
566 conferenceId = mIdByConference.get(conference);
567 }
568 mAdapter.setIsConferenced(id, conferenceId);
569 }
570 }
Anthony Lee17455a32015-04-24 15:25:29 -0700571
572 @Override
573 public void onConferenceMergeFailed(Connection connection) {
574 String id = mIdByConnection.get(connection);
575 if (id != null) {
576 mAdapter.onConferenceMergeFailed(id);
577 }
578 }
Santos Cordon6b7f9552015-05-27 17:21:45 -0700579
580 @Override
581 public void onExtrasChanged(Connection connection, Bundle extras) {
582 String id = mIdByConnection.get(connection);
583 if (id != null) {
584 mAdapter.setExtras(id, extras);
585 }
586 }
Ihab Awad542e0ea2014-05-16 10:22:16 -0700587 };
588
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700589 /** {@inheritDoc} */
Ihab Awad542e0ea2014-05-16 10:22:16 -0700590 @Override
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700591 public final IBinder onBind(Intent intent) {
592 return mBinder;
593 }
594
Santos Cordon29f2f2e2014-09-11 19:50:24 -0700595 /** {@inheritDoc} */
596 @Override
597 public boolean onUnbind(Intent intent) {
598 endAllConnections();
599 return super.onUnbind(intent);
600 }
601
Sailesh Nepalc5b01572014-07-14 16:29:44 -0700602 /**
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700603 * This can be used by telecom to either create a new outgoing call or attach to an existing
604 * incoming call. In either case, telecom will cycle through a set of services and call
Sailesh Nepalc5b01572014-07-14 16:29:44 -0700605 * createConnection util a connection service cancels the process or completes it successfully.
606 */
Ihab Awadf8b69882014-07-25 15:14:01 -0700607 private void createConnection(
608 final PhoneAccountHandle callManagerAccount,
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700609 final String callId,
Ihab Awadf8b69882014-07-25 15:14:01 -0700610 final ConnectionRequest request,
Yorke Leec3cf9822014-10-02 09:38:39 -0700611 boolean isIncoming,
612 boolean isUnknown) {
Sailesh Nepalcf7020b2014-08-20 10:07:19 -0700613 Log.d(this, "createConnection, callManagerAccount: %s, callId: %s, request: %s, " +
Yorke Leec3cf9822014-10-02 09:38:39 -0700614 "isIncoming: %b, isUnknown: %b", callManagerAccount, callId, request, isIncoming,
615 isUnknown);
Ihab Awad542e0ea2014-05-16 10:22:16 -0700616
Yorke Leec3cf9822014-10-02 09:38:39 -0700617 Connection connection = isUnknown ? onCreateUnknownConnection(callManagerAccount, request)
618 : isIncoming ? onCreateIncomingConnection(callManagerAccount, request)
Ihab Awad6107bab2014-08-18 09:23:25 -0700619 : onCreateOutgoingConnection(callManagerAccount, request);
Sailesh Nepalcf7020b2014-08-20 10:07:19 -0700620 Log.d(this, "createConnection, connection: %s", connection);
621 if (connection == null) {
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700622 connection = Connection.createFailedConnection(
623 new DisconnectCause(DisconnectCause.ERROR));
Sailesh Nepalc5b01572014-07-14 16:29:44 -0700624 }
Ihab Awad542e0ea2014-05-16 10:22:16 -0700625
Sailesh Nepalcf7020b2014-08-20 10:07:19 -0700626 if (connection.getState() != Connection.STATE_DISCONNECTED) {
Ihab Awad6107bab2014-08-18 09:23:25 -0700627 addConnection(callId, connection);
628 }
629
Andrew Lee100e2932014-09-08 15:34:24 -0700630 Uri address = connection.getAddress();
631 String number = address == null ? "null" : address.getSchemeSpecificPart();
Sailesh Nepalcf7020b2014-08-20 10:07:19 -0700632 Log.v(this, "createConnection, number: %s, state: %s, capabilities: %s",
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700633 Connection.toLogSafePhoneNumber(number),
Sailesh Nepalcf7020b2014-08-20 10:07:19 -0700634 Connection.stateToString(connection.getState()),
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800635 Connection.capabilitiesToString(connection.getConnectionCapabilities()));
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700636
Sailesh Nepalcf7020b2014-08-20 10:07:19 -0700637 Log.d(this, "createConnection, calling handleCreateConnectionSuccessful %s", callId);
Ihab Awad6107bab2014-08-18 09:23:25 -0700638 mAdapter.handleCreateConnectionComplete(
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700639 callId,
Evan Charltonbf11f982014-07-20 22:06:28 -0700640 request,
641 new ParcelableConnection(
642 request.getAccountHandle(),
643 connection.getState(),
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800644 connection.getConnectionCapabilities(),
Andrew Lee100e2932014-09-08 15:34:24 -0700645 connection.getAddress(),
646 connection.getAddressPresentation(),
Evan Charltonbf11f982014-07-20 22:06:28 -0700647 connection.getCallerDisplayName(),
648 connection.getCallerDisplayNamePresentation(),
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700649 connection.getVideoProvider() == null ?
650 null : connection.getVideoProvider().getInterface(),
Sailesh Nepal8b9d3ca2014-08-14 17:39:34 -0700651 connection.getVideoState(),
Andrew Lee100e2932014-09-08 15:34:24 -0700652 connection.isRingbackRequested(),
Sailesh Nepal8b9d3ca2014-08-14 17:39:34 -0700653 connection.getAudioModeIsVoip(),
Ihab Awad6107bab2014-08-18 09:23:25 -0700654 connection.getStatusHints(),
Sailesh Nepalcf7020b2014-08-20 10:07:19 -0700655 connection.getDisconnectCause(),
Santos Cordon6b7f9552015-05-27 17:21:45 -0700656 createIdList(connection.getConferenceables()),
657 connection.getExtras()));
Shriram Ganesh6bf35ac2014-12-11 17:53:38 -0800658 if (isUnknown) {
659 triggerConferenceRecalculate();
660 }
Evan Charltonbf11f982014-07-20 22:06:28 -0700661 }
662
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700663 private void abort(String callId) {
Ihab Awad60ac30b2014-05-20 22:32:12 -0700664 Log.d(this, "abort %s", callId);
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700665 findConnectionForAction(callId, "abort").onAbort();
Ihab Awad542e0ea2014-05-16 10:22:16 -0700666 }
667
Tyler Gunnbe74de02014-08-29 14:51:48 -0700668 private void answerVideo(String callId, int videoState) {
669 Log.d(this, "answerVideo %s", callId);
Andrew Lee8da4c3c2014-07-16 10:11:42 -0700670 findConnectionForAction(callId, "answer").onAnswer(videoState);
Ihab Awad542e0ea2014-05-16 10:22:16 -0700671 }
672
Tyler Gunnbe74de02014-08-29 14:51:48 -0700673 private void answer(String callId) {
674 Log.d(this, "answer %s", callId);
675 findConnectionForAction(callId, "answer").onAnswer();
676 }
677
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700678 private void reject(String callId) {
Ihab Awad60ac30b2014-05-20 22:32:12 -0700679 Log.d(this, "reject %s", callId);
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700680 findConnectionForAction(callId, "reject").onReject();
Ihab Awad542e0ea2014-05-16 10:22:16 -0700681 }
682
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700683 private void disconnect(String callId) {
Ihab Awad60ac30b2014-05-20 22:32:12 -0700684 Log.d(this, "disconnect %s", callId);
Santos Cordon0159ac02014-08-21 14:28:11 -0700685 if (mConnectionById.containsKey(callId)) {
686 findConnectionForAction(callId, "disconnect").onDisconnect();
687 } else {
688 findConferenceForAction(callId, "disconnect").onDisconnect();
689 }
Ihab Awad542e0ea2014-05-16 10:22:16 -0700690 }
691
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700692 private void hold(String callId) {
Ihab Awad60ac30b2014-05-20 22:32:12 -0700693 Log.d(this, "hold %s", callId);
Santos Cordon0159ac02014-08-21 14:28:11 -0700694 if (mConnectionById.containsKey(callId)) {
695 findConnectionForAction(callId, "hold").onHold();
696 } else {
697 findConferenceForAction(callId, "hold").onHold();
698 }
Ihab Awad542e0ea2014-05-16 10:22:16 -0700699 }
700
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700701 private void unhold(String callId) {
Ihab Awad60ac30b2014-05-20 22:32:12 -0700702 Log.d(this, "unhold %s", callId);
Santos Cordon0159ac02014-08-21 14:28:11 -0700703 if (mConnectionById.containsKey(callId)) {
704 findConnectionForAction(callId, "unhold").onUnhold();
705 } else {
706 findConferenceForAction(callId, "unhold").onUnhold();
707 }
Ihab Awad542e0ea2014-05-16 10:22:16 -0700708 }
709
Yorke Lee4af59352015-05-13 14:14:54 -0700710 private void onCallAudioStateChanged(String callId, CallAudioState callAudioState) {
711 Log.d(this, "onAudioStateChanged %s %s", callId, callAudioState);
Yorke Leea0d3ca92014-09-15 19:18:13 -0700712 if (mConnectionById.containsKey(callId)) {
Yorke Lee4af59352015-05-13 14:14:54 -0700713 findConnectionForAction(callId, "onCallAudioStateChanged").setCallAudioState(
714 callAudioState);
Yorke Leea0d3ca92014-09-15 19:18:13 -0700715 } else {
Yorke Lee4af59352015-05-13 14:14:54 -0700716 findConferenceForAction(callId, "onCallAudioStateChanged").setCallAudioState(
717 callAudioState);
Yorke Leea0d3ca92014-09-15 19:18:13 -0700718 }
Ihab Awad542e0ea2014-05-16 10:22:16 -0700719 }
720
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700721 private void playDtmfTone(String callId, char digit) {
722 Log.d(this, "playDtmfTone %s %c", callId, digit);
Yorke Leea0d3ca92014-09-15 19:18:13 -0700723 if (mConnectionById.containsKey(callId)) {
724 findConnectionForAction(callId, "playDtmfTone").onPlayDtmfTone(digit);
725 } else {
726 findConferenceForAction(callId, "playDtmfTone").onPlayDtmfTone(digit);
727 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700728 }
729
730 private void stopDtmfTone(String callId) {
731 Log.d(this, "stopDtmfTone %s", callId);
Yorke Leea0d3ca92014-09-15 19:18:13 -0700732 if (mConnectionById.containsKey(callId)) {
733 findConnectionForAction(callId, "stopDtmfTone").onStopDtmfTone();
734 } else {
735 findConferenceForAction(callId, "stopDtmfTone").onStopDtmfTone();
736 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700737 }
738
Santos Cordon823fd3c2014-08-07 18:35:18 -0700739 private void conference(String callId1, String callId2) {
740 Log.d(this, "conference %s, %s", callId1, callId2);
Santos Cordon980acb92014-05-31 10:31:19 -0700741
Tyler Gunn6d76ca02014-11-17 15:49:51 -0800742 // Attempt to get second connection or conference.
Santos Cordon823fd3c2014-08-07 18:35:18 -0700743 Connection connection2 = findConnectionForAction(callId2, "conference");
Tyler Gunn6d76ca02014-11-17 15:49:51 -0800744 Conference conference2 = getNullConference();
Sailesh Nepalcf7020b2014-08-20 10:07:19 -0700745 if (connection2 == getNullConnection()) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -0800746 conference2 = findConferenceForAction(callId2, "conference");
747 if (conference2 == getNullConference()) {
748 Log.w(this, "Connection2 or Conference2 missing in conference request %s.",
749 callId2);
750 return;
751 }
Santos Cordon823fd3c2014-08-07 18:35:18 -0700752 }
Santos Cordonb6939982014-06-04 20:20:58 -0700753
Tyler Gunn6d76ca02014-11-17 15:49:51 -0800754 // Attempt to get first connection or conference and perform merge.
Ihab Awad50e35062014-09-30 09:17:03 -0700755 Connection connection1 = findConnectionForAction(callId1, "conference");
756 if (connection1 == getNullConnection()) {
757 Conference conference1 = findConferenceForAction(callId1, "addConnection");
758 if (conference1 == getNullConference()) {
759 Log.w(this,
760 "Connection1 or Conference1 missing in conference request %s.",
761 callId1);
762 } else {
Tyler Gunn6d76ca02014-11-17 15:49:51 -0800763 // Call 1 is a conference.
764 if (connection2 != getNullConnection()) {
765 // Call 2 is a connection so merge via call 1 (conference).
766 conference1.onMerge(connection2);
767 } else {
768 // Call 2 is ALSO a conference; this should never happen.
769 Log.wtf(this, "There can only be one conference and an attempt was made to " +
770 "merge two conferences.");
771 return;
772 }
Ihab Awad50e35062014-09-30 09:17:03 -0700773 }
774 } else {
Tyler Gunn6d76ca02014-11-17 15:49:51 -0800775 // Call 1 is a connection.
776 if (conference2 != getNullConference()) {
777 // Call 2 is a conference, so merge via call 2.
778 conference2.onMerge(connection1);
779 } else {
780 // Call 2 is a connection, so merge together.
781 onConference(connection1, connection2);
782 }
Ihab Awad50e35062014-09-30 09:17:03 -0700783 }
Santos Cordon980acb92014-05-31 10:31:19 -0700784 }
785
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700786 private void splitFromConference(String callId) {
Santos Cordonb6939982014-06-04 20:20:58 -0700787 Log.d(this, "splitFromConference(%s)", callId);
Santos Cordon980acb92014-05-31 10:31:19 -0700788
789 Connection connection = findConnectionForAction(callId, "splitFromConference");
Sailesh Nepalcf7020b2014-08-20 10:07:19 -0700790 if (connection == getNullConnection()) {
Santos Cordon980acb92014-05-31 10:31:19 -0700791 Log.w(this, "Connection missing in conference request %s.", callId);
792 return;
793 }
794
Santos Cordon0159ac02014-08-21 14:28:11 -0700795 Conference conference = connection.getConference();
796 if (conference != null) {
797 conference.onSeparate(connection);
798 }
Santos Cordon980acb92014-05-31 10:31:19 -0700799 }
800
Santos Cordona4868042014-09-04 17:39:22 -0700801 private void mergeConference(String callId) {
802 Log.d(this, "mergeConference(%s)", callId);
803 Conference conference = findConferenceForAction(callId, "mergeConference");
804 if (conference != null) {
805 conference.onMerge();
806 }
807 }
808
809 private void swapConference(String callId) {
810 Log.d(this, "swapConference(%s)", callId);
811 Conference conference = findConferenceForAction(callId, "swapConference");
812 if (conference != null) {
813 conference.onSwap();
814 }
815 }
816
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700817 private void onPostDialContinue(String callId, boolean proceed) {
Evan Charlton6dea4ac2014-06-03 14:07:13 -0700818 Log.d(this, "onPostDialContinue(%s)", callId);
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700819 findConnectionForAction(callId, "stopDtmfTone").onPostDialContinue(proceed);
Evan Charlton6dea4ac2014-06-03 14:07:13 -0700820 }
821
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700822 private void onAdapterAttached() {
Ihab Awad9c3f1882014-06-30 21:17:13 -0700823 if (mAreAccountsInitialized) {
Santos Cordon52d8a152014-06-17 19:08:45 -0700824 // No need to query again if we already did it.
825 return;
826 }
827
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700828 mAdapter.queryRemoteConnectionServices(new RemoteServiceCallback.Stub() {
Santos Cordon52d8a152014-06-17 19:08:45 -0700829 @Override
830 public void onResult(
831 final List<ComponentName> componentNames,
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700832 final List<IBinder> services) {
Santos Cordon52d8a152014-06-17 19:08:45 -0700833 mHandler.post(new Runnable() {
Ihab Awad6107bab2014-08-18 09:23:25 -0700834 @Override
835 public void run() {
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700836 for (int i = 0; i < componentNames.size() && i < services.size(); i++) {
Santos Cordon52d8a152014-06-17 19:08:45 -0700837 mRemoteConnectionManager.addConnectionService(
838 componentNames.get(i),
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700839 IConnectionService.Stub.asInterface(services.get(i)));
Santos Cordon52d8a152014-06-17 19:08:45 -0700840 }
Ihab Awad5d0410f2014-07-30 10:07:40 -0700841 onAccountsInitialized();
Sailesh Nepalc5b01572014-07-14 16:29:44 -0700842 Log.d(this, "remote connection services found: " + services);
Santos Cordon52d8a152014-06-17 19:08:45 -0700843 }
844 });
845 }
846
847 @Override
848 public void onError() {
849 mHandler.post(new Runnable() {
Ihab Awad6107bab2014-08-18 09:23:25 -0700850 @Override
851 public void run() {
Ihab Awad9c3f1882014-06-30 21:17:13 -0700852 mAreAccountsInitialized = true;
Santos Cordon52d8a152014-06-17 19:08:45 -0700853 }
854 });
855 }
856 });
857 }
858
Ihab Awadf8b69882014-07-25 15:14:01 -0700859 /**
860 * Ask some other {@code ConnectionService} to create a {@code RemoteConnection} given an
Santos Cordona663f862014-10-29 13:49:58 -0700861 * incoming request. This is used by {@code ConnectionService}s that are registered with
862 * {@link PhoneAccount#CAPABILITY_CONNECTION_MANAGER} and want to be able to manage
863 * SIM-based incoming calls.
Ihab Awadf8b69882014-07-25 15:14:01 -0700864 *
865 * @param connectionManagerPhoneAccount See description at
866 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
867 * @param request Details about the incoming call.
868 * @return The {@code Connection} object to satisfy this call, or {@code null} to
869 * not handle the call.
870 */
871 public final RemoteConnection createRemoteIncomingConnection(
872 PhoneAccountHandle connectionManagerPhoneAccount,
873 ConnectionRequest request) {
874 return mRemoteConnectionManager.createRemoteConnection(
875 connectionManagerPhoneAccount, request, true);
Santos Cordon52d8a152014-06-17 19:08:45 -0700876 }
877
878 /**
Ihab Awadf8b69882014-07-25 15:14:01 -0700879 * Ask some other {@code ConnectionService} to create a {@code RemoteConnection} given an
Santos Cordona663f862014-10-29 13:49:58 -0700880 * outgoing request. This is used by {@code ConnectionService}s that are registered with
881 * {@link PhoneAccount#CAPABILITY_CONNECTION_MANAGER} and want to be able to use the
882 * SIM-based {@code ConnectionService} to place its outgoing calls.
Ihab Awadf8b69882014-07-25 15:14:01 -0700883 *
884 * @param connectionManagerPhoneAccount See description at
885 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
886 * @param request Details about the incoming call.
887 * @return The {@code Connection} object to satisfy this call, or {@code null} to
888 * not handle the call.
889 */
890 public final RemoteConnection createRemoteOutgoingConnection(
891 PhoneAccountHandle connectionManagerPhoneAccount,
892 ConnectionRequest request) {
893 return mRemoteConnectionManager.createRemoteConnection(
894 connectionManagerPhoneAccount, request, false);
895 }
896
897 /**
Santos Cordona663f862014-10-29 13:49:58 -0700898 * Indicates to the relevant {@code RemoteConnectionService} that the specified
899 * {@link RemoteConnection}s should be merged into a conference call.
900 * <p>
901 * If the conference request is successful, the method {@link #onRemoteConferenceAdded} will
902 * be invoked.
903 *
904 * @param remoteConnection1 The first of the remote connections to conference.
905 * @param remoteConnection2 The second of the remote connections to conference.
Ihab Awadb8e85c72014-08-23 20:34:57 -0700906 */
907 public final void conferenceRemoteConnections(
Santos Cordona663f862014-10-29 13:49:58 -0700908 RemoteConnection remoteConnection1,
909 RemoteConnection remoteConnection2) {
910 mRemoteConnectionManager.conferenceRemoteConnections(remoteConnection1, remoteConnection2);
Ihab Awadb8e85c72014-08-23 20:34:57 -0700911 }
912
913 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -0700914 * Adds a new conference call. When a conference call is created either as a result of an
915 * explicit request via {@link #onConference} or otherwise, the connection service should supply
916 * an instance of {@link Conference} by invoking this method. A conference call provided by this
917 * method will persist until {@link Conference#destroy} is invoked on the conference instance.
918 *
919 * @param conference The new conference object.
920 */
921 public final void addConference(Conference conference) {
Rekha Kumar07366812015-03-24 16:42:31 -0700922 Log.d(this, "addConference: conference=%s", conference);
923
Santos Cordon823fd3c2014-08-07 18:35:18 -0700924 String id = addConferenceInternal(conference);
925 if (id != null) {
926 List<String> connectionIds = new ArrayList<>(2);
927 for (Connection connection : conference.getConnections()) {
928 if (mIdByConnection.containsKey(connection)) {
929 connectionIds.add(mIdByConnection.get(connection));
930 }
931 }
932 ParcelableConference parcelableConference = new ParcelableConference(
Nancy Chenea38cca2014-09-05 16:38:49 -0700933 conference.getPhoneAccountHandle(),
Santos Cordon823fd3c2014-08-07 18:35:18 -0700934 conference.getState(),
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800935 conference.getConnectionCapabilities(),
Tyler Gunncd5d33c2015-01-12 09:02:01 -0800936 connectionIds,
Rekha Kumar07366812015-03-24 16:42:31 -0700937 conference.getVideoProvider() == null ?
938 null : conference.getVideoProvider().getInterface(),
939 conference.getVideoState(),
Andrew Lee3e3e2f22015-04-16 13:48:43 -0700940 conference.getConnectTimeMillis(),
Santos Cordon6b7f9552015-05-27 17:21:45 -0700941 conference.getStatusHints(),
942 conference.getExtras());
Andrew Lee0f51da32015-04-16 13:11:55 -0700943
Santos Cordon823fd3c2014-08-07 18:35:18 -0700944 mAdapter.addConferenceCall(id, parcelableConference);
Rekha Kumar07366812015-03-24 16:42:31 -0700945 mAdapter.setVideoProvider(id, conference.getVideoProvider());
946 mAdapter.setVideoState(id, conference.getVideoState());
Santos Cordon823fd3c2014-08-07 18:35:18 -0700947
948 // Go through any child calls and set the parent.
949 for (Connection connection : conference.getConnections()) {
950 String connectionId = mIdByConnection.get(connection);
951 if (connectionId != null) {
952 mAdapter.setIsConferenced(connectionId, id);
953 }
954 }
955 }
956 }
957
958 /**
Tyler Gunn4a57b9b2014-10-30 14:27:48 -0700959 * Adds a connection created by the {@link ConnectionService} and informs telecom of the new
960 * connection.
961 *
962 * @param phoneAccountHandle The phone account handle for the connection.
963 * @param connection The connection to add.
964 */
965 public final void addExistingConnection(PhoneAccountHandle phoneAccountHandle,
966 Connection connection) {
967
968 String id = addExistingConnectionInternal(connection);
969 if (id != null) {
970 List<String> emptyList = new ArrayList<>(0);
971
972 ParcelableConnection parcelableConnection = new ParcelableConnection(
973 phoneAccountHandle,
974 connection.getState(),
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800975 connection.getConnectionCapabilities(),
Tyler Gunn4a57b9b2014-10-30 14:27:48 -0700976 connection.getAddress(),
977 connection.getAddressPresentation(),
978 connection.getCallerDisplayName(),
979 connection.getCallerDisplayNamePresentation(),
980 connection.getVideoProvider() == null ?
981 null : connection.getVideoProvider().getInterface(),
982 connection.getVideoState(),
983 connection.isRingbackRequested(),
984 connection.getAudioModeIsVoip(),
985 connection.getStatusHints(),
986 connection.getDisconnectCause(),
Santos Cordon6b7f9552015-05-27 17:21:45 -0700987 emptyList,
988 connection.getExtras());
Tyler Gunn4a57b9b2014-10-30 14:27:48 -0700989 mAdapter.addExistingConnection(id, parcelableConnection);
990 }
991 }
992
993 /**
Ihab Awadf8b69882014-07-25 15:14:01 -0700994 * Returns all the active {@code Connection}s for which this {@code ConnectionService}
995 * has taken responsibility.
996 *
997 * @return A collection of {@code Connection}s created by this {@code ConnectionService}.
Santos Cordonb6939982014-06-04 20:20:58 -0700998 */
Sailesh Nepal091768c2014-06-30 15:15:23 -0700999 public final Collection<Connection> getAllConnections() {
Santos Cordonb6939982014-06-04 20:20:58 -07001000 return mConnectionById.values();
1001 }
1002
1003 /**
Ihab Awadf8b69882014-07-25 15:14:01 -07001004 * Create a {@code Connection} given an incoming request. This is used to attach to existing
1005 * incoming calls.
Evan Charltonbf11f982014-07-20 22:06:28 -07001006 *
Ihab Awadf8b69882014-07-25 15:14:01 -07001007 * @param connectionManagerPhoneAccount See description at
1008 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
1009 * @param request Details about the incoming call.
1010 * @return The {@code Connection} object to satisfy this call, or {@code null} to
1011 * not handle the call.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001012 */
Ihab Awadf8b69882014-07-25 15:14:01 -07001013 public Connection onCreateIncomingConnection(
1014 PhoneAccountHandle connectionManagerPhoneAccount,
1015 ConnectionRequest request) {
1016 return null;
1017 }
Sailesh Nepalc5b01572014-07-14 16:29:44 -07001018
1019 /**
Shriram Ganesh6bf35ac2014-12-11 17:53:38 -08001020 * Trigger recalculate functinality for conference calls. This is used when a Telephony
1021 * Connection is part of a conference controller but is not yet added to Connection
1022 * Service and hence cannot be added to the conference call.
1023 *
1024 * @hide
1025 */
1026 public void triggerConferenceRecalculate() {
1027 }
1028
1029 /**
Ihab Awadf8b69882014-07-25 15:14:01 -07001030 * Create a {@code Connection} given an outgoing request. This is used to initiate new
1031 * outgoing calls.
Sailesh Nepalc5b01572014-07-14 16:29:44 -07001032 *
Ihab Awadf8b69882014-07-25 15:14:01 -07001033 * @param connectionManagerPhoneAccount The connection manager account to use for managing
1034 * this call.
1035 * <p>
1036 * If this parameter is not {@code null}, it means that this {@code ConnectionService}
1037 * has registered one or more {@code PhoneAccount}s having
1038 * {@link PhoneAccount#CAPABILITY_CONNECTION_MANAGER}. This parameter will contain
1039 * one of these {@code PhoneAccount}s, while the {@code request} will contain another
1040 * (usually but not always distinct) {@code PhoneAccount} to be used for actually
1041 * making the connection.
1042 * <p>
1043 * If this parameter is {@code null}, it means that this {@code ConnectionService} is
1044 * being asked to make a direct connection. The
1045 * {@link ConnectionRequest#getAccountHandle()} of parameter {@code request} will be
1046 * a {@code PhoneAccount} registered by this {@code ConnectionService} to use for
1047 * making the connection.
1048 * @param request Details about the outgoing call.
1049 * @return The {@code Connection} object to satisfy this call, or the result of an invocation
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001050 * of {@link Connection#createFailedConnection(DisconnectCause)} to not handle the call.
Sailesh Nepalc5b01572014-07-14 16:29:44 -07001051 */
Ihab Awadf8b69882014-07-25 15:14:01 -07001052 public Connection onCreateOutgoingConnection(
1053 PhoneAccountHandle connectionManagerPhoneAccount,
1054 ConnectionRequest request) {
1055 return null;
1056 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001057
1058 /**
Yorke Leec3cf9822014-10-02 09:38:39 -07001059 * Create a {@code Connection} for a new unknown call. An unknown call is a call originating
1060 * from the ConnectionService that was neither a user-initiated outgoing call, nor an incoming
1061 * call created using
1062 * {@code TelecomManager#addNewIncomingCall(PhoneAccountHandle, android.os.Bundle)}.
1063 *
1064 * @param connectionManagerPhoneAccount
1065 * @param request
1066 * @return
Yorke Lee770ed6e2014-10-06 18:58:52 -07001067 *
1068 * @hide
Yorke Leec3cf9822014-10-02 09:38:39 -07001069 */
1070 public Connection onCreateUnknownConnection(PhoneAccountHandle connectionManagerPhoneAccount,
1071 ConnectionRequest request) {
1072 return null;
1073 }
1074
1075 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07001076 * Conference two specified connections. Invoked when the user has made a request to merge the
1077 * specified connections into a conference call. In response, the connection service should
1078 * create an instance of {@link Conference} and pass it into {@link #addConference}.
Santos Cordonb6939982014-06-04 20:20:58 -07001079 *
Santos Cordon823fd3c2014-08-07 18:35:18 -07001080 * @param connection1 A connection to merge into a conference call.
1081 * @param connection2 A connection to merge into a conference call.
Santos Cordonb6939982014-06-04 20:20:58 -07001082 */
Santos Cordon823fd3c2014-08-07 18:35:18 -07001083 public void onConference(Connection connection1, Connection connection2) {}
Santos Cordonb6939982014-06-04 20:20:58 -07001084
Santos Cordona663f862014-10-29 13:49:58 -07001085 /**
1086 * Indicates that a remote conference has been created for existing {@link RemoteConnection}s.
1087 * When this method is invoked, this {@link ConnectionService} should create its own
1088 * representation of the conference call and send it to telecom using {@link #addConference}.
1089 * <p>
1090 * This is only relevant to {@link ConnectionService}s which are registered with
1091 * {@link PhoneAccount#CAPABILITY_CONNECTION_MANAGER}.
1092 *
1093 * @param conference The remote conference call.
1094 */
Ihab Awadb8e85c72014-08-23 20:34:57 -07001095 public void onRemoteConferenceAdded(RemoteConference conference) {}
1096
Santos Cordon823fd3c2014-08-07 18:35:18 -07001097 /**
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07001098 * Called when an existing connection is added remotely.
1099 * @param connection The existing connection which was added.
1100 */
1101 public void onRemoteExistingConnectionAdded(RemoteConnection connection) {}
1102
1103 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07001104 * @hide
1105 */
1106 public boolean containsConference(Conference conference) {
1107 return mIdByConference.containsKey(conference);
1108 }
1109
Ihab Awadb8e85c72014-08-23 20:34:57 -07001110 /** {@hide} */
1111 void addRemoteConference(RemoteConference remoteConference) {
1112 onRemoteConferenceAdded(remoteConference);
1113 }
1114
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07001115 /** {@hide} */
1116 void addRemoteExistingConnection(RemoteConnection remoteConnection) {
1117 onRemoteExistingConnectionAdded(remoteConnection);
1118 }
1119
Ihab Awad5d0410f2014-07-30 10:07:40 -07001120 private void onAccountsInitialized() {
1121 mAreAccountsInitialized = true;
1122 for (Runnable r : mPreInitializationConnectionRequests) {
1123 r.run();
1124 }
1125 mPreInitializationConnectionRequests.clear();
1126 }
1127
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07001128 /**
1129 * Adds an existing connection to the list of connections, identified by a new UUID.
1130 *
1131 * @param connection The connection.
1132 * @return The UUID of the connection (e.g. the call-id).
1133 */
1134 private String addExistingConnectionInternal(Connection connection) {
1135 String id = UUID.randomUUID().toString();
1136 addConnection(id, connection);
1137 return id;
1138 }
1139
Ihab Awad542e0ea2014-05-16 10:22:16 -07001140 private void addConnection(String callId, Connection connection) {
1141 mConnectionById.put(callId, connection);
1142 mIdByConnection.put(connection, callId);
1143 connection.addConnectionListener(mConnectionListener);
Santos Cordon823fd3c2014-08-07 18:35:18 -07001144 connection.setConnectionService(this);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001145 }
1146
Anthony Lee30e65842014-11-06 16:30:53 -08001147 /** {@hide} */
1148 protected void removeConnection(Connection connection) {
Ihab Awad8aecfed2014-08-08 17:06:11 -07001149 String id = mIdByConnection.get(connection);
Santos Cordon823fd3c2014-08-07 18:35:18 -07001150 connection.unsetConnectionService(this);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001151 connection.removeConnectionListener(mConnectionListener);
1152 mConnectionById.remove(mIdByConnection.get(connection));
1153 mIdByConnection.remove(connection);
Ihab Awad8aecfed2014-08-08 17:06:11 -07001154 mAdapter.removeCall(id);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001155 }
1156
Santos Cordon823fd3c2014-08-07 18:35:18 -07001157 private String addConferenceInternal(Conference conference) {
1158 if (mIdByConference.containsKey(conference)) {
1159 Log.w(this, "Re-adding an existing conference: %s.", conference);
1160 } else if (conference != null) {
1161 String id = UUID.randomUUID().toString();
1162 mConferenceById.put(id, conference);
1163 mIdByConference.put(conference, id);
1164 conference.addListener(mConferenceListener);
1165 return id;
1166 }
1167
1168 return null;
1169 }
1170
1171 private void removeConference(Conference conference) {
1172 if (mIdByConference.containsKey(conference)) {
1173 conference.removeListener(mConferenceListener);
1174
1175 String id = mIdByConference.get(conference);
1176 mConferenceById.remove(id);
1177 mIdByConference.remove(conference);
1178 mAdapter.removeCall(id);
1179 }
1180 }
1181
Ihab Awad542e0ea2014-05-16 10:22:16 -07001182 private Connection findConnectionForAction(String callId, String action) {
1183 if (mConnectionById.containsKey(callId)) {
1184 return mConnectionById.get(callId);
1185 }
Ihab Awad60ac30b2014-05-20 22:32:12 -07001186 Log.w(this, "%s - Cannot find Connection %s", action, callId);
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001187 return getNullConnection();
1188 }
1189
1190 static synchronized Connection getNullConnection() {
1191 if (sNullConnection == null) {
1192 sNullConnection = new Connection() {};
1193 }
1194 return sNullConnection;
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001195 }
Santos Cordon0159ac02014-08-21 14:28:11 -07001196
1197 private Conference findConferenceForAction(String conferenceId, String action) {
1198 if (mConferenceById.containsKey(conferenceId)) {
1199 return mConferenceById.get(conferenceId);
1200 }
1201 Log.w(this, "%s - Cannot find conference %s", action, conferenceId);
1202 return getNullConference();
1203 }
1204
Ihab Awadb8e85c72014-08-23 20:34:57 -07001205 private List<String> createConnectionIdList(List<Connection> connections) {
1206 List<String> ids = new ArrayList<>();
1207 for (Connection c : connections) {
1208 if (mIdByConnection.containsKey(c)) {
1209 ids.add(mIdByConnection.get(c));
1210 }
1211 }
1212 Collections.sort(ids);
1213 return ids;
1214 }
1215
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001216 /**
1217 * Builds a list of {@link Connection} and {@link Conference} IDs based on the list of
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001218 * {@link Conferenceable}s passed in.
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001219 *
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001220 * @param conferenceables The {@link Conferenceable} connections and conferences.
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001221 * @return List of string conference and call Ids.
1222 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001223 private List<String> createIdList(List<Conferenceable> conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001224 List<String> ids = new ArrayList<>();
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001225 for (Conferenceable c : conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001226 // Only allow Connection and Conference conferenceables.
1227 if (c instanceof Connection) {
1228 Connection connection = (Connection) c;
1229 if (mIdByConnection.containsKey(connection)) {
1230 ids.add(mIdByConnection.get(connection));
1231 }
1232 } else if (c instanceof Conference) {
1233 Conference conference = (Conference) c;
1234 if (mIdByConference.containsKey(conference)) {
1235 ids.add(mIdByConference.get(conference));
1236 }
1237 }
1238 }
1239 Collections.sort(ids);
1240 return ids;
1241 }
1242
Santos Cordon0159ac02014-08-21 14:28:11 -07001243 private Conference getNullConference() {
1244 if (sNullConference == null) {
1245 sNullConference = new Conference(null) {};
1246 }
1247 return sNullConference;
1248 }
Santos Cordon29f2f2e2014-09-11 19:50:24 -07001249
1250 private void endAllConnections() {
1251 // Unbound from telecomm. We should end all connections and conferences.
1252 for (Connection connection : mIdByConnection.keySet()) {
1253 // only operate on top-level calls. Conference calls will be removed on their own.
1254 if (connection.getConference() == null) {
1255 connection.onDisconnect();
1256 }
1257 }
1258 for (Conference conference : mIdByConference.keySet()) {
1259 conference.onDisconnect();
1260 }
1261 }
Santos Cordon980acb92014-05-31 10:31:19 -07001262}