blob: 3eafaf5aa06507bbe989165dc9cc620022a503ac [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;
Hall Liub64ac4c2017-02-06 10:49:48 -080029import android.os.ParcelFileDescriptor;
30import android.os.RemoteException;
Brad Ebingerb32d4f82016-10-24 16:40:49 -070031import android.telecom.Logging.Session;
Andrew Lee14185762014-07-25 09:41:56 -070032
Sailesh Nepal2a46b902014-07-04 17:21:07 -070033import com.android.internal.os.SomeArgs;
Tyler Gunnef9f6f92014-09-12 22:16:17 -070034import com.android.internal.telecom.IConnectionService;
35import com.android.internal.telecom.IConnectionServiceAdapter;
36import com.android.internal.telecom.RemoteServiceCallback;
Santos Cordon52d8a152014-06-17 19:08:45 -070037
Ihab Awad5d0410f2014-07-30 10:07:40 -070038import java.util.ArrayList;
Santos Cordonb6939982014-06-04 20:20:58 -070039import java.util.Collection;
Santos Cordon7c7bc7f2014-07-28 18:15:48 -070040import java.util.Collections;
Santos Cordon52d8a152014-06-17 19:08:45 -070041import java.util.List;
Ihab Awad542e0ea2014-05-16 10:22:16 -070042import java.util.Map;
Santos Cordon823fd3c2014-08-07 18:35:18 -070043import java.util.UUID;
mike dooley95e80702014-09-18 14:07:52 -070044import java.util.concurrent.ConcurrentHashMap;
Ihab Awad542e0ea2014-05-16 10:22:16 -070045
46/**
Tyler Gunnf5035432017-01-09 09:43:12 -080047 * An abstract service that should be implemented by any apps which either:
48 * <ol>
49 * <li>Can make phone calls (VoIP or otherwise) and want those calls to be integrated into the
50 * built-in phone app. Referred to as a <b>system managed</b> {@link ConnectionService}.</li>
51 * <li>Are a standalone calling app and don't want their calls to be integrated into the
52 * built-in phone app. Referred to as a <b>self managed</b> {@link ConnectionService}.</li>
53 * </ol>
54 * Once implemented, the {@link ConnectionService} needs to take the following steps so that Telecom
55 * will bind to it:
Santos Cordona663f862014-10-29 13:49:58 -070056 * <p>
57 * 1. <i>Registration in AndroidManifest.xml</i>
58 * <br/>
59 * <pre>
60 * &lt;service android:name="com.example.package.MyConnectionService"
61 * android:label="@string/some_label_for_my_connection_service"
Yorke Lee249c12e2015-05-13 15:59:29 -070062 * android:permission="android.permission.BIND_TELECOM_CONNECTION_SERVICE"&gt;
Santos Cordona663f862014-10-29 13:49:58 -070063 * &lt;intent-filter&gt;
64 * &lt;action android:name="android.telecom.ConnectionService" /&gt;
65 * &lt;/intent-filter&gt;
66 * &lt;/service&gt;
67 * </pre>
68 * <p>
69 * 2. <i> Registration of {@link PhoneAccount} with {@link TelecomManager}.</i>
70 * <br/>
71 * See {@link PhoneAccount} and {@link TelecomManager#registerPhoneAccount} for more information.
72 * <p>
Tyler Gunnf5035432017-01-09 09:43:12 -080073 * System managed {@link ConnectionService}s must be enabled by the user in the phone app settings
74 * before Telecom will bind to them. Self-manged {@link ConnectionService}s must be granted the
75 * appropriate permission before Telecom will bind to them.
76 * <p>
77 * Once registered and enabled by the user in the phone app settings or granted permission, telecom
78 * will bind to a {@link ConnectionService} implementation when it wants that
79 * {@link ConnectionService} to place a call or the service has indicated that is has an incoming
80 * call through {@link TelecomManager#addNewIncomingCall}. The {@link ConnectionService} can then
81 * expect a call to {@link #onCreateIncomingConnection} or {@link #onCreateOutgoingConnection}
82 * wherein it should provide a new instance of a {@link Connection} object. It is through this
83 * {@link Connection} object that telecom receives state updates and the {@link ConnectionService}
Santos Cordona663f862014-10-29 13:49:58 -070084 * receives call-commands such as answer, reject, hold and disconnect.
85 * <p>
Tyler Gunnf5035432017-01-09 09:43:12 -080086 * When there are no more live calls, telecom will unbind from the {@link ConnectionService}.
Ihab Awad542e0ea2014-05-16 10:22:16 -070087 */
Sailesh Nepal2a46b902014-07-04 17:21:07 -070088public abstract class ConnectionService extends Service {
Santos Cordon5c6fa952014-07-20 17:47:12 -070089 /**
90 * The {@link Intent} that must be declared as handled by the service.
91 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -070092 @SdkConstant(SdkConstant.SdkConstantType.SERVICE_ACTION)
Tyler Gunnef9f6f92014-09-12 22:16:17 -070093 public static final String SERVICE_INTERFACE = "android.telecom.ConnectionService";
Santos Cordon5c6fa952014-07-20 17:47:12 -070094
Tyler Gunn8bf76572017-04-06 15:30:08 -070095 /**
96 * Boolean extra used by Telecom to inform a {@link ConnectionService} that the purpose of it
97 * being asked to create a new outgoing {@link Connection} is to perform a handover of an
98 * ongoing call on the device from another {@link PhoneAccount}/{@link ConnectionService}. Will
99 * be specified in the {@link ConnectionRequest#getExtras()} passed by Telecom when
100 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)} is called.
101 * <p>
102 * Telecom will also specify {@link #EXTRA_HANDOVER_TOKEN} to provide a Telecom-specific opaque
103 * token representing the ongoing call which is to be handed over.
104 * <p>
105 * When your {@link ConnectionService} receives this extra, it should communicate the
106 * {@link #EXTRA_HANDOVER_TOKEN} to the other device's matching {@link ConnectionService}. That
107 * {@link ConnectionService} will continue the handover using
108 * {@link TelecomManager#addNewIncomingCall(PhoneAccountHandle, Bundle)}, specifying
109 * {@link TelecomManager#EXTRA_IS_HANDOVER} and {@link TelecomManager#EXTRA_HANDOVER_TOKEN}.
110 * @hide
111 */
112 public static final String EXTRA_IS_HANDOVER = TelecomManager.EXTRA_IS_HANDOVER;
113
114 /**
115 * String extra used by Telecom when {@link #EXTRA_IS_HANDOVER} is true to provide an identifier
116 * for the call to be handed over.
117 * @hide
118 */
119 public static final String EXTRA_HANDOVER_TOKEN = TelecomManager.EXTRA_HANDOVER_TOKEN;
120
Ihab Awad542e0ea2014-05-16 10:22:16 -0700121 // Flag controlling whether PII is emitted into the logs
Ihab Awad60ac30b2014-05-20 22:32:12 -0700122 private static final boolean PII_DEBUG = Log.isLoggable(android.util.Log.DEBUG);
Ihab Awad542e0ea2014-05-16 10:22:16 -0700123
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700124 // Session Definitions
125 private static final String SESSION_HANDLER = "H.";
126 private static final String SESSION_ADD_CS_ADAPTER = "CS.aCSA";
127 private static final String SESSION_REMOVE_CS_ADAPTER = "CS.rCSA";
128 private static final String SESSION_CREATE_CONN = "CS.crCo";
Tyler Gunn44e01912017-01-31 10:49:05 -0800129 private static final String SESSION_CREATE_CONN_FAILED = "CS.crCoF";
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700130 private static final String SESSION_ABORT = "CS.ab";
131 private static final String SESSION_ANSWER = "CS.an";
132 private static final String SESSION_ANSWER_VIDEO = "CS.anV";
133 private static final String SESSION_REJECT = "CS.r";
134 private static final String SESSION_REJECT_MESSAGE = "CS.rWM";
135 private static final String SESSION_SILENCE = "CS.s";
136 private static final String SESSION_DISCONNECT = "CS.d";
137 private static final String SESSION_HOLD = "CS.h";
138 private static final String SESSION_UNHOLD = "CS.u";
139 private static final String SESSION_CALL_AUDIO_SC = "CS.cASC";
140 private static final String SESSION_PLAY_DTMF = "CS.pDT";
141 private static final String SESSION_STOP_DTMF = "CS.sDT";
142 private static final String SESSION_CONFERENCE = "CS.c";
143 private static final String SESSION_SPLIT_CONFERENCE = "CS.sFC";
144 private static final String SESSION_MERGE_CONFERENCE = "CS.mC";
145 private static final String SESSION_SWAP_CONFERENCE = "CS.sC";
146 private static final String SESSION_POST_DIAL_CONT = "CS.oPDC";
147 private static final String SESSION_PULL_EXTERNAL_CALL = "CS.pEC";
148 private static final String SESSION_SEND_CALL_EVENT = "CS.sCE";
149 private static final String SESSION_EXTRAS_CHANGED = "CS.oEC";
Hall Liub64ac4c2017-02-06 10:49:48 -0800150 private static final String SESSION_START_RTT = "CS.+RTT";
151 private static final String SESSION_STOP_RTT = "CS.-RTT";
152 private static final String SESSION_RTT_UPGRADE_RESPONSE = "CS.rTRUR";
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700153
Ihab Awad8aecfed2014-08-08 17:06:11 -0700154 private static final int MSG_ADD_CONNECTION_SERVICE_ADAPTER = 1;
Sailesh Nepalc5b01572014-07-14 16:29:44 -0700155 private static final int MSG_CREATE_CONNECTION = 2;
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700156 private static final int MSG_ABORT = 3;
Sailesh Nepalc5b01572014-07-14 16:29:44 -0700157 private static final int MSG_ANSWER = 4;
158 private static final int MSG_REJECT = 5;
159 private static final int MSG_DISCONNECT = 6;
160 private static final int MSG_HOLD = 7;
161 private static final int MSG_UNHOLD = 8;
Yorke Lee4af59352015-05-13 14:14:54 -0700162 private static final int MSG_ON_CALL_AUDIO_STATE_CHANGED = 9;
Sailesh Nepalc5b01572014-07-14 16:29:44 -0700163 private static final int MSG_PLAY_DTMF_TONE = 10;
164 private static final int MSG_STOP_DTMF_TONE = 11;
165 private static final int MSG_CONFERENCE = 12;
166 private static final int MSG_SPLIT_FROM_CONFERENCE = 13;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700167 private static final int MSG_ON_POST_DIAL_CONTINUE = 14;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700168 private static final int MSG_REMOVE_CONNECTION_SERVICE_ADAPTER = 16;
Tyler Gunnbe74de02014-08-29 14:51:48 -0700169 private static final int MSG_ANSWER_VIDEO = 17;
Santos Cordona4868042014-09-04 17:39:22 -0700170 private static final int MSG_MERGE_CONFERENCE = 18;
171 private static final int MSG_SWAP_CONFERENCE = 19;
Bryce Lee81901682015-08-28 16:38:02 -0700172 private static final int MSG_REJECT_WITH_MESSAGE = 20;
Bryce Leecac50772015-11-17 15:13:29 -0800173 private static final int MSG_SILENCE = 21;
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700174 private static final int MSG_PULL_EXTERNAL_CALL = 22;
175 private static final int MSG_SEND_CALL_EVENT = 23;
Tyler Gunndee56a82016-03-23 16:06:34 -0700176 private static final int MSG_ON_EXTRAS_CHANGED = 24;
Tyler Gunn44e01912017-01-31 10:49:05 -0800177 private static final int MSG_CREATE_CONNECTION_FAILED = 25;
Hall Liub64ac4c2017-02-06 10:49:48 -0800178 private static final int MSG_ON_START_RTT = 26;
179 private static final int MSG_ON_STOP_RTT = 27;
180 private static final int MSG_RTT_UPGRADE_RESPONSE = 28;
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700181
Sailesh Nepalcf7020b2014-08-20 10:07:19 -0700182 private static Connection sNullConnection;
183
mike dooley95e80702014-09-18 14:07:52 -0700184 private final Map<String, Connection> mConnectionById = new ConcurrentHashMap<>();
185 private final Map<Connection, String> mIdByConnection = new ConcurrentHashMap<>();
186 private final Map<String, Conference> mConferenceById = new ConcurrentHashMap<>();
187 private final Map<Conference, String> mIdByConference = new ConcurrentHashMap<>();
Ihab Awadb8e85c72014-08-23 20:34:57 -0700188 private final RemoteConnectionManager mRemoteConnectionManager =
189 new RemoteConnectionManager(this);
Ihab Awad5d0410f2014-07-30 10:07:40 -0700190 private final List<Runnable> mPreInitializationConnectionRequests = new ArrayList<>();
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700191 private final ConnectionServiceAdapter mAdapter = new ConnectionServiceAdapter();
Ihab Awad542e0ea2014-05-16 10:22:16 -0700192
Santos Cordon823fd3c2014-08-07 18:35:18 -0700193 private boolean mAreAccountsInitialized = false;
Santos Cordon0159ac02014-08-21 14:28:11 -0700194 private Conference sNullConference;
Tyler Gunnf0500bd2015-09-01 10:59:48 -0700195 private Object mIdSyncRoot = new Object();
196 private int mId = 0;
Santos Cordon823fd3c2014-08-07 18:35:18 -0700197
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700198 private final IBinder mBinder = new IConnectionService.Stub() {
199 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700200 public void addConnectionServiceAdapter(IConnectionServiceAdapter adapter,
201 Session.Info sessionInfo) {
202 Log.startSession(sessionInfo, SESSION_ADD_CS_ADAPTER);
203 try {
204 SomeArgs args = SomeArgs.obtain();
205 args.arg1 = adapter;
206 args.arg2 = Log.createSubsession();
207 mHandler.obtainMessage(MSG_ADD_CONNECTION_SERVICE_ADAPTER, args).sendToTarget();
208 } finally {
209 Log.endSession();
210 }
Ihab Awad8aecfed2014-08-08 17:06:11 -0700211 }
212
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700213 public void removeConnectionServiceAdapter(IConnectionServiceAdapter adapter,
214 Session.Info sessionInfo) {
215 Log.startSession(sessionInfo, SESSION_REMOVE_CS_ADAPTER);
216 try {
217 SomeArgs args = SomeArgs.obtain();
218 args.arg1 = adapter;
219 args.arg2 = Log.createSubsession();
220 mHandler.obtainMessage(MSG_REMOVE_CONNECTION_SERVICE_ADAPTER, args).sendToTarget();
221 } finally {
222 Log.endSession();
223 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700224 }
225
226 @Override
Ihab Awadf8b69882014-07-25 15:14:01 -0700227 public void createConnection(
228 PhoneAccountHandle connectionManagerPhoneAccount,
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700229 String id,
Ihab Awadf8b69882014-07-25 15:14:01 -0700230 ConnectionRequest request,
Yorke Leec3cf9822014-10-02 09:38:39 -0700231 boolean isIncoming,
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700232 boolean isUnknown,
233 Session.Info sessionInfo) {
234 Log.startSession(sessionInfo, SESSION_CREATE_CONN);
235 try {
236 SomeArgs args = SomeArgs.obtain();
237 args.arg1 = connectionManagerPhoneAccount;
238 args.arg2 = id;
239 args.arg3 = request;
240 args.arg4 = Log.createSubsession();
241 args.argi1 = isIncoming ? 1 : 0;
242 args.argi2 = isUnknown ? 1 : 0;
243 mHandler.obtainMessage(MSG_CREATE_CONNECTION, args).sendToTarget();
244 } finally {
245 Log.endSession();
246 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700247 }
248
249 @Override
Tyler Gunn44e01912017-01-31 10:49:05 -0800250 public void createConnectionFailed(
Tyler Gunn159f35c2017-03-02 09:28:37 -0800251 PhoneAccountHandle connectionManagerPhoneAccount,
Tyler Gunn44e01912017-01-31 10:49:05 -0800252 String callId,
253 ConnectionRequest request,
254 boolean isIncoming,
255 Session.Info sessionInfo) {
256 Log.startSession(sessionInfo, SESSION_CREATE_CONN_FAILED);
257 try {
258 SomeArgs args = SomeArgs.obtain();
259 args.arg1 = callId;
260 args.arg2 = request;
261 args.arg3 = Log.createSubsession();
Tyler Gunn159f35c2017-03-02 09:28:37 -0800262 args.arg4 = connectionManagerPhoneAccount;
Tyler Gunn44e01912017-01-31 10:49:05 -0800263 args.argi1 = isIncoming ? 1 : 0;
264 mHandler.obtainMessage(MSG_CREATE_CONNECTION_FAILED, args).sendToTarget();
265 } finally {
266 Log.endSession();
267 }
268 }
269
270 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700271 public void abort(String callId, Session.Info sessionInfo) {
272 Log.startSession(sessionInfo, SESSION_ABORT);
273 try {
274 SomeArgs args = SomeArgs.obtain();
275 args.arg1 = callId;
276 args.arg2 = Log.createSubsession();
277 mHandler.obtainMessage(MSG_ABORT, args).sendToTarget();
278 } finally {
279 Log.endSession();
280 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700281 }
282
283 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700284 public void answerVideo(String callId, int videoState, Session.Info sessionInfo) {
285 Log.startSession(sessionInfo, SESSION_ANSWER_VIDEO);
286 try {
287 SomeArgs args = SomeArgs.obtain();
288 args.arg1 = callId;
289 args.arg2 = Log.createSubsession();
290 args.argi1 = videoState;
291 mHandler.obtainMessage(MSG_ANSWER_VIDEO, args).sendToTarget();
292 } finally {
293 Log.endSession();
294 }
Tyler Gunnbe74de02014-08-29 14:51:48 -0700295 }
296
297 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700298 public void answer(String callId, Session.Info sessionInfo) {
299 Log.startSession(sessionInfo, SESSION_ANSWER);
300 try {
301 SomeArgs args = SomeArgs.obtain();
302 args.arg1 = callId;
303 args.arg2 = Log.createSubsession();
304 mHandler.obtainMessage(MSG_ANSWER, args).sendToTarget();
305 } finally {
306 Log.endSession();
307 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700308 }
309
310 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700311 public void reject(String callId, Session.Info sessionInfo) {
312 Log.startSession(sessionInfo, SESSION_REJECT);
313 try {
314 SomeArgs args = SomeArgs.obtain();
315 args.arg1 = callId;
316 args.arg2 = Log.createSubsession();
317 mHandler.obtainMessage(MSG_REJECT, args).sendToTarget();
318 } finally {
319 Log.endSession();
320 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700321 }
322
323 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700324 public void rejectWithMessage(String callId, String message, Session.Info sessionInfo) {
325 Log.startSession(sessionInfo, SESSION_REJECT_MESSAGE);
326 try {
327 SomeArgs args = SomeArgs.obtain();
328 args.arg1 = callId;
329 args.arg2 = message;
330 args.arg3 = Log.createSubsession();
331 mHandler.obtainMessage(MSG_REJECT_WITH_MESSAGE, args).sendToTarget();
332 } finally {
333 Log.endSession();
334 }
Bryce Lee81901682015-08-28 16:38:02 -0700335 }
336
337 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700338 public void silence(String callId, Session.Info sessionInfo) {
339 Log.startSession(sessionInfo, SESSION_SILENCE);
340 try {
341 SomeArgs args = SomeArgs.obtain();
342 args.arg1 = callId;
343 args.arg2 = Log.createSubsession();
344 mHandler.obtainMessage(MSG_SILENCE, args).sendToTarget();
345 } finally {
346 Log.endSession();
347 }
Bryce Leecac50772015-11-17 15:13:29 -0800348 }
349
350 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700351 public void disconnect(String callId, Session.Info sessionInfo) {
352 Log.startSession(sessionInfo, SESSION_DISCONNECT);
353 try {
354 SomeArgs args = SomeArgs.obtain();
355 args.arg1 = callId;
356 args.arg2 = Log.createSubsession();
357 mHandler.obtainMessage(MSG_DISCONNECT, args).sendToTarget();
358 } finally {
359 Log.endSession();
360 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700361 }
362
363 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700364 public void hold(String callId, Session.Info sessionInfo) {
365 Log.startSession(sessionInfo, SESSION_HOLD);
366 try {
367 SomeArgs args = SomeArgs.obtain();
368 args.arg1 = callId;
369 args.arg2 = Log.createSubsession();
370 mHandler.obtainMessage(MSG_HOLD, args).sendToTarget();
371 } finally {
372 Log.endSession();
373 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700374 }
375
376 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700377 public void unhold(String callId, Session.Info sessionInfo) {
378 Log.startSession(sessionInfo, SESSION_UNHOLD);
379 try {
380 SomeArgs args = SomeArgs.obtain();
381 args.arg1 = callId;
382 args.arg2 = Log.createSubsession();
383 mHandler.obtainMessage(MSG_UNHOLD, args).sendToTarget();
384 } finally {
385 Log.endSession();
386 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700387 }
388
389 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700390 public void onCallAudioStateChanged(String callId, CallAudioState callAudioState,
391 Session.Info sessionInfo) {
392 Log.startSession(sessionInfo, SESSION_CALL_AUDIO_SC);
393 try {
394 SomeArgs args = SomeArgs.obtain();
395 args.arg1 = callId;
396 args.arg2 = callAudioState;
397 args.arg3 = Log.createSubsession();
398 mHandler.obtainMessage(MSG_ON_CALL_AUDIO_STATE_CHANGED, args).sendToTarget();
399 } finally {
400 Log.endSession();
401 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700402 }
403
404 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700405 public void playDtmfTone(String callId, char digit, Session.Info sessionInfo) {
406 Log.startSession(sessionInfo, SESSION_PLAY_DTMF);
407 try {
408 SomeArgs args = SomeArgs.obtain();
409 args.arg1 = digit;
410 args.arg2 = callId;
411 args.arg3 = Log.createSubsession();
412 mHandler.obtainMessage(MSG_PLAY_DTMF_TONE, args).sendToTarget();
413 } finally {
414 Log.endSession();
415 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700416 }
417
418 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700419 public void stopDtmfTone(String callId, Session.Info sessionInfo) {
420 Log.startSession(sessionInfo, SESSION_STOP_DTMF);
421 try {
422 SomeArgs args = SomeArgs.obtain();
423 args.arg1 = callId;
424 args.arg2 = Log.createSubsession();
425 mHandler.obtainMessage(MSG_STOP_DTMF_TONE, args).sendToTarget();
426 } finally {
427 Log.endSession();
428 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700429 }
430
431 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700432 public void conference(String callId1, String callId2, Session.Info sessionInfo) {
433 Log.startSession(sessionInfo, SESSION_CONFERENCE);
434 try {
435 SomeArgs args = SomeArgs.obtain();
436 args.arg1 = callId1;
437 args.arg2 = callId2;
438 args.arg3 = Log.createSubsession();
439 mHandler.obtainMessage(MSG_CONFERENCE, args).sendToTarget();
440 } finally {
441 Log.endSession();
442 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700443 }
444
445 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700446 public void splitFromConference(String callId, Session.Info sessionInfo) {
447 Log.startSession(sessionInfo, SESSION_SPLIT_CONFERENCE);
448 try {
449 SomeArgs args = SomeArgs.obtain();
450 args.arg1 = callId;
451 args.arg2 = Log.createSubsession();
452 mHandler.obtainMessage(MSG_SPLIT_FROM_CONFERENCE, args).sendToTarget();
453 } finally {
454 Log.endSession();
455 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700456 }
457
458 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700459 public void mergeConference(String callId, Session.Info sessionInfo) {
460 Log.startSession(sessionInfo, SESSION_MERGE_CONFERENCE);
461 try {
462 SomeArgs args = SomeArgs.obtain();
463 args.arg1 = callId;
464 args.arg2 = Log.createSubsession();
465 mHandler.obtainMessage(MSG_MERGE_CONFERENCE, args).sendToTarget();
466 } finally {
467 Log.endSession();
468 }
Santos Cordona4868042014-09-04 17:39:22 -0700469 }
470
471 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700472 public void swapConference(String callId, Session.Info sessionInfo) {
473 Log.startSession(sessionInfo, SESSION_SWAP_CONFERENCE);
474 try {
475 SomeArgs args = SomeArgs.obtain();
476 args.arg1 = callId;
477 args.arg2 = Log.createSubsession();
478 mHandler.obtainMessage(MSG_SWAP_CONFERENCE, args).sendToTarget();
479 } finally {
480 Log.endSession();
481 }
Santos Cordona4868042014-09-04 17:39:22 -0700482 }
483
484 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700485 public void onPostDialContinue(String callId, boolean proceed, Session.Info sessionInfo) {
486 Log.startSession(sessionInfo, SESSION_POST_DIAL_CONT);
487 try {
488 SomeArgs args = SomeArgs.obtain();
489 args.arg1 = callId;
490 args.arg2 = Log.createSubsession();
491 args.argi1 = proceed ? 1 : 0;
492 mHandler.obtainMessage(MSG_ON_POST_DIAL_CONTINUE, args).sendToTarget();
493 } finally {
494 Log.endSession();
495 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700496 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700497
498 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700499 public void pullExternalCall(String callId, Session.Info sessionInfo) {
500 Log.startSession(sessionInfo, SESSION_PULL_EXTERNAL_CALL);
501 try {
502 SomeArgs args = SomeArgs.obtain();
503 args.arg1 = callId;
504 args.arg2 = Log.createSubsession();
505 mHandler.obtainMessage(MSG_PULL_EXTERNAL_CALL, args).sendToTarget();
506 } finally {
507 Log.endSession();
508 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700509 }
510
511 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700512 public void sendCallEvent(String callId, String event, Bundle extras,
513 Session.Info sessionInfo) {
514 Log.startSession(sessionInfo, SESSION_SEND_CALL_EVENT);
515 try {
516 SomeArgs args = SomeArgs.obtain();
517 args.arg1 = callId;
518 args.arg2 = event;
519 args.arg3 = extras;
520 args.arg4 = Log.createSubsession();
521 mHandler.obtainMessage(MSG_SEND_CALL_EVENT, args).sendToTarget();
522 } finally {
523 Log.endSession();
524 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700525 }
Tyler Gunndee56a82016-03-23 16:06:34 -0700526
527 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700528 public void onExtrasChanged(String callId, Bundle extras, Session.Info sessionInfo) {
529 Log.startSession(sessionInfo, SESSION_EXTRAS_CHANGED);
530 try {
531 SomeArgs args = SomeArgs.obtain();
532 args.arg1 = callId;
533 args.arg2 = extras;
534 args.arg3 = Log.createSubsession();
535 mHandler.obtainMessage(MSG_ON_EXTRAS_CHANGED, args).sendToTarget();
536 } finally {
537 Log.endSession();
538 }
Tyler Gunndee56a82016-03-23 16:06:34 -0700539 }
Hall Liub64ac4c2017-02-06 10:49:48 -0800540
541 @Override
542 public void startRtt(String callId, ParcelFileDescriptor fromInCall,
543 ParcelFileDescriptor toInCall, Session.Info sessionInfo) throws RemoteException {
544 Log.startSession(sessionInfo, SESSION_START_RTT);
545 try {
546 SomeArgs args = SomeArgs.obtain();
547 args.arg1 = callId;
548 args.arg2 = new Connection.RttTextStream(toInCall, fromInCall);
549 args.arg3 = Log.createSubsession();
550 mHandler.obtainMessage(MSG_ON_START_RTT, args).sendToTarget();
551 } finally {
552 Log.endSession();
553 }
554 }
555
556 @Override
557 public void stopRtt(String callId, Session.Info sessionInfo) throws RemoteException {
558 Log.startSession(sessionInfo, SESSION_STOP_RTT);
559 try {
560 SomeArgs args = SomeArgs.obtain();
561 args.arg1 = callId;
562 args.arg2 = Log.createSubsession();
563 mHandler.obtainMessage(MSG_ON_STOP_RTT, args).sendToTarget();
564 } finally {
565 Log.endSession();
566 }
567 }
568
569 @Override
570 public void respondToRttUpgradeRequest(String callId, ParcelFileDescriptor fromInCall,
571 ParcelFileDescriptor toInCall, Session.Info sessionInfo) throws RemoteException {
572 Log.startSession(sessionInfo, SESSION_RTT_UPGRADE_RESPONSE);
573 try {
574 SomeArgs args = SomeArgs.obtain();
575 args.arg1 = callId;
576 if (toInCall == null || fromInCall == null) {
577 args.arg2 = null;
578 } else {
579 args.arg2 = new Connection.RttTextStream(toInCall, fromInCall);
580 }
581 args.arg3 = Log.createSubsession();
582 mHandler.obtainMessage(MSG_RTT_UPGRADE_RESPONSE, args).sendToTarget();
583 } finally {
584 Log.endSession();
585 }
586 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700587 };
588
589 private final Handler mHandler = new Handler(Looper.getMainLooper()) {
590 @Override
591 public void handleMessage(Message msg) {
592 switch (msg.what) {
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700593 case MSG_ADD_CONNECTION_SERVICE_ADAPTER: {
594 SomeArgs args = (SomeArgs) msg.obj;
595 try {
596 IConnectionServiceAdapter adapter = (IConnectionServiceAdapter) args.arg1;
597 Log.continueSession((Session) args.arg2,
598 SESSION_HANDLER + SESSION_ADD_CS_ADAPTER);
599 mAdapter.addAdapter(adapter);
600 onAdapterAttached();
601 } finally {
602 args.recycle();
603 Log.endSession();
604 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700605 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700606 }
607 case MSG_REMOVE_CONNECTION_SERVICE_ADAPTER: {
608 SomeArgs args = (SomeArgs) msg.obj;
609 try {
610 Log.continueSession((Session) args.arg2,
611 SESSION_HANDLER + SESSION_REMOVE_CS_ADAPTER);
612 mAdapter.removeAdapter((IConnectionServiceAdapter) args.arg1);
613 } finally {
614 args.recycle();
615 Log.endSession();
616 }
Ihab Awad8aecfed2014-08-08 17:06:11 -0700617 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700618 }
Ihab Awadf8b69882014-07-25 15:14:01 -0700619 case MSG_CREATE_CONNECTION: {
620 SomeArgs args = (SomeArgs) msg.obj;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700621 Log.continueSession((Session) args.arg4, SESSION_HANDLER + SESSION_CREATE_CONN);
Ihab Awadf8b69882014-07-25 15:14:01 -0700622 try {
Ihab Awad5d0410f2014-07-30 10:07:40 -0700623 final PhoneAccountHandle connectionManagerPhoneAccount =
Ihab Awadf8b69882014-07-25 15:14:01 -0700624 (PhoneAccountHandle) args.arg1;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700625 final String id = (String) args.arg2;
626 final ConnectionRequest request = (ConnectionRequest) args.arg3;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700627 final boolean isIncoming = args.argi1 == 1;
Yorke Leec3cf9822014-10-02 09:38:39 -0700628 final boolean isUnknown = args.argi2 == 1;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700629 if (!mAreAccountsInitialized) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700630 Log.d(this, "Enqueueing pre-init request %s", id);
Brad Ebinger0c3541b2016-11-01 14:11:38 -0700631 mPreInitializationConnectionRequests.add(
632 new android.telecom.Logging.Runnable(
633 SESSION_HANDLER + SESSION_CREATE_CONN + ".pICR",
634 null /*lock*/) {
Ihab Awad5d0410f2014-07-30 10:07:40 -0700635 @Override
Brad Ebinger0c3541b2016-11-01 14:11:38 -0700636 public void loggedRun() {
Ihab Awad5d0410f2014-07-30 10:07:40 -0700637 createConnection(
638 connectionManagerPhoneAccount,
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700639 id,
Ihab Awad5d0410f2014-07-30 10:07:40 -0700640 request,
Yorke Leec3cf9822014-10-02 09:38:39 -0700641 isIncoming,
642 isUnknown);
Ihab Awad5d0410f2014-07-30 10:07:40 -0700643 }
Brad Ebinger0c3541b2016-11-01 14:11:38 -0700644 }.prepare());
Ihab Awad5d0410f2014-07-30 10:07:40 -0700645 } else {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700646 createConnection(
647 connectionManagerPhoneAccount,
648 id,
649 request,
Yorke Leec3cf9822014-10-02 09:38:39 -0700650 isIncoming,
651 isUnknown);
Ihab Awad5d0410f2014-07-30 10:07:40 -0700652 }
Ihab Awadf8b69882014-07-25 15:14:01 -0700653 } finally {
654 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700655 Log.endSession();
Ihab Awadf8b69882014-07-25 15:14:01 -0700656 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700657 break;
Ihab Awadf8b69882014-07-25 15:14:01 -0700658 }
Tyler Gunn44e01912017-01-31 10:49:05 -0800659 case MSG_CREATE_CONNECTION_FAILED: {
660 SomeArgs args = (SomeArgs) msg.obj;
661 Log.continueSession((Session) args.arg3, SESSION_HANDLER +
662 SESSION_CREATE_CONN_FAILED);
663 try {
664 final String id = (String) args.arg1;
665 final ConnectionRequest request = (ConnectionRequest) args.arg2;
666 final boolean isIncoming = args.argi1 == 1;
Tyler Gunn159f35c2017-03-02 09:28:37 -0800667 final PhoneAccountHandle connectionMgrPhoneAccount =
668 (PhoneAccountHandle) args.arg4;
Tyler Gunn44e01912017-01-31 10:49:05 -0800669 if (!mAreAccountsInitialized) {
670 Log.d(this, "Enqueueing pre-init request %s", id);
671 mPreInitializationConnectionRequests.add(
672 new android.telecom.Logging.Runnable(
673 SESSION_HANDLER + SESSION_CREATE_CONN_FAILED + ".pICR",
674 null /*lock*/) {
675 @Override
676 public void loggedRun() {
Tyler Gunn159f35c2017-03-02 09:28:37 -0800677 createConnectionFailed(connectionMgrPhoneAccount, id,
678 request, isIncoming);
Tyler Gunn44e01912017-01-31 10:49:05 -0800679 }
680 }.prepare());
681 } else {
682 Log.i(this, "createConnectionFailed %s", id);
Tyler Gunn159f35c2017-03-02 09:28:37 -0800683 createConnectionFailed(connectionMgrPhoneAccount, id, request,
684 isIncoming);
Tyler Gunn44e01912017-01-31 10:49:05 -0800685 }
686 } finally {
687 args.recycle();
688 Log.endSession();
689 }
690 break;
691 }
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700692 case MSG_ABORT: {
693 SomeArgs args = (SomeArgs) msg.obj;
694 Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_ABORT);
695 try {
696 abort((String) args.arg1);
697 } finally {
698 args.recycle();
699 Log.endSession();
700 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700701 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700702 }
703 case MSG_ANSWER: {
704 SomeArgs args = (SomeArgs) msg.obj;
705 Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_ANSWER);
706 try {
707 answer((String) args.arg1);
708 } finally {
709 args.recycle();
710 Log.endSession();
711 }
Tyler Gunnbe74de02014-08-29 14:51:48 -0700712 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700713 }
Tyler Gunnbe74de02014-08-29 14:51:48 -0700714 case MSG_ANSWER_VIDEO: {
Andrew Lee8da4c3c2014-07-16 10:11:42 -0700715 SomeArgs args = (SomeArgs) msg.obj;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700716 Log.continueSession((Session) args.arg2,
717 SESSION_HANDLER + SESSION_ANSWER_VIDEO);
Andrew Lee8da4c3c2014-07-16 10:11:42 -0700718 try {
719 String callId = (String) args.arg1;
Evan Charltonbf11f982014-07-20 22:06:28 -0700720 int videoState = args.argi1;
Tyler Gunnbe74de02014-08-29 14:51:48 -0700721 answerVideo(callId, videoState);
Andrew Lee8da4c3c2014-07-16 10:11:42 -0700722 } finally {
723 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700724 Log.endSession();
Andrew Lee8da4c3c2014-07-16 10:11:42 -0700725 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700726 break;
Andrew Lee8da4c3c2014-07-16 10:11:42 -0700727 }
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700728 case MSG_REJECT: {
729 SomeArgs args = (SomeArgs) msg.obj;
730 Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_REJECT);
731 try {
732 reject((String) args.arg1);
733 } finally {
734 args.recycle();
735 Log.endSession();
736 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700737 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700738 }
Bryce Lee81901682015-08-28 16:38:02 -0700739 case MSG_REJECT_WITH_MESSAGE: {
740 SomeArgs args = (SomeArgs) msg.obj;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700741 Log.continueSession((Session) args.arg3,
742 SESSION_HANDLER + SESSION_REJECT_MESSAGE);
Bryce Lee81901682015-08-28 16:38:02 -0700743 try {
744 reject((String) args.arg1, (String) args.arg2);
745 } finally {
746 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700747 Log.endSession();
Bryce Lee81901682015-08-28 16:38:02 -0700748 }
749 break;
750 }
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700751 case MSG_DISCONNECT: {
752 SomeArgs args = (SomeArgs) msg.obj;
753 Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_DISCONNECT);
754 try {
755 disconnect((String) args.arg1);
756 } finally {
757 args.recycle();
758 Log.endSession();
759 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700760 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700761 }
762 case MSG_SILENCE: {
763 SomeArgs args = (SomeArgs) msg.obj;
764 Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_SILENCE);
765 try {
766 silence((String) args.arg1);
767 } finally {
768 args.recycle();
769 Log.endSession();
770 }
Bryce Leecac50772015-11-17 15:13:29 -0800771 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700772 }
773 case MSG_HOLD: {
774 SomeArgs args = (SomeArgs) msg.obj;
775 Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_REJECT);
776 try {
777 hold((String) args.arg1);
778 } finally {
779 args.recycle();
780 Log.endSession();
781 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700782 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700783 }
784 case MSG_UNHOLD: {
785 SomeArgs args = (SomeArgs) msg.obj;
786 Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_UNHOLD);
787 try {
788 unhold((String) args.arg1);
789 } finally {
790 args.recycle();
791 Log.endSession();
792 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700793 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700794 }
Yorke Lee4af59352015-05-13 14:14:54 -0700795 case MSG_ON_CALL_AUDIO_STATE_CHANGED: {
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700796 SomeArgs args = (SomeArgs) msg.obj;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700797 Log.continueSession((Session) args.arg3,
798 SESSION_HANDLER + SESSION_CALL_AUDIO_SC);
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700799 try {
800 String callId = (String) args.arg1;
Yorke Lee4af59352015-05-13 14:14:54 -0700801 CallAudioState audioState = (CallAudioState) args.arg2;
802 onCallAudioStateChanged(callId, new CallAudioState(audioState));
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700803 } finally {
804 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700805 Log.endSession();
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700806 }
807 break;
808 }
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700809 case MSG_PLAY_DTMF_TONE: {
810 SomeArgs args = (SomeArgs) msg.obj;
811 try {
812 Log.continueSession((Session) args.arg3,
813 SESSION_HANDLER + SESSION_PLAY_DTMF);
814 playDtmfTone((String) args.arg2, (char) args.arg1);
815 } finally {
816 args.recycle();
817 Log.endSession();
818 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700819 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700820 }
821 case MSG_STOP_DTMF_TONE: {
822 SomeArgs args = (SomeArgs) msg.obj;
823 try {
824 Log.continueSession((Session) args.arg2,
825 SESSION_HANDLER + SESSION_STOP_DTMF);
826 stopDtmfTone((String) args.arg1);
827 } finally {
828 args.recycle();
829 Log.endSession();
830 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700831 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700832 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700833 case MSG_CONFERENCE: {
834 SomeArgs args = (SomeArgs) msg.obj;
835 try {
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700836 Log.continueSession((Session) args.arg3,
837 SESSION_HANDLER + SESSION_CONFERENCE);
Santos Cordon823fd3c2014-08-07 18:35:18 -0700838 String callId1 = (String) args.arg1;
839 String callId2 = (String) args.arg2;
840 conference(callId1, callId2);
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700841 } finally {
842 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700843 Log.endSession();
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700844 }
845 break;
846 }
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700847 case MSG_SPLIT_FROM_CONFERENCE: {
848 SomeArgs args = (SomeArgs) msg.obj;
849 try {
850 Log.continueSession((Session) args.arg2,
851 SESSION_HANDLER + SESSION_SPLIT_CONFERENCE);
852 splitFromConference((String) args.arg1);
853 } finally {
854 args.recycle();
855 Log.endSession();
856 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700857 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700858 }
859 case MSG_MERGE_CONFERENCE: {
860 SomeArgs args = (SomeArgs) msg.obj;
861 try {
862 Log.continueSession((Session) args.arg2,
863 SESSION_HANDLER + SESSION_MERGE_CONFERENCE);
864 mergeConference((String) args.arg1);
865 } finally {
866 args.recycle();
867 Log.endSession();
868 }
Santos Cordona4868042014-09-04 17:39:22 -0700869 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700870 }
871 case MSG_SWAP_CONFERENCE: {
872 SomeArgs args = (SomeArgs) msg.obj;
873 try {
874 Log.continueSession((Session) args.arg2,
875 SESSION_HANDLER + SESSION_SWAP_CONFERENCE);
876 swapConference((String) args.arg1);
877 } finally {
878 args.recycle();
879 Log.endSession();
880 }
Santos Cordona4868042014-09-04 17:39:22 -0700881 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700882 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700883 case MSG_ON_POST_DIAL_CONTINUE: {
884 SomeArgs args = (SomeArgs) msg.obj;
885 try {
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700886 Log.continueSession((Session) args.arg2,
887 SESSION_HANDLER + SESSION_POST_DIAL_CONT);
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700888 String callId = (String) args.arg1;
889 boolean proceed = (args.argi1 == 1);
890 onPostDialContinue(callId, proceed);
891 } finally {
892 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700893 Log.endSession();
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700894 }
895 break;
896 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700897 case MSG_PULL_EXTERNAL_CALL: {
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700898 SomeArgs args = (SomeArgs) msg.obj;
899 try {
900 Log.continueSession((Session) args.arg2,
901 SESSION_HANDLER + SESSION_PULL_EXTERNAL_CALL);
902 pullExternalCall((String) args.arg1);
903 } finally {
904 args.recycle();
905 Log.endSession();
906 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700907 break;
908 }
909 case MSG_SEND_CALL_EVENT: {
910 SomeArgs args = (SomeArgs) msg.obj;
911 try {
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700912 Log.continueSession((Session) args.arg4,
913 SESSION_HANDLER + SESSION_SEND_CALL_EVENT);
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700914 String callId = (String) args.arg1;
915 String event = (String) args.arg2;
916 Bundle extras = (Bundle) args.arg3;
917 sendCallEvent(callId, event, extras);
918 } finally {
919 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700920 Log.endSession();
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700921 }
922 break;
923 }
Tyler Gunndee56a82016-03-23 16:06:34 -0700924 case MSG_ON_EXTRAS_CHANGED: {
925 SomeArgs args = (SomeArgs) msg.obj;
926 try {
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700927 Log.continueSession((Session) args.arg3,
928 SESSION_HANDLER + SESSION_EXTRAS_CHANGED);
Tyler Gunndee56a82016-03-23 16:06:34 -0700929 String callId = (String) args.arg1;
930 Bundle extras = (Bundle) args.arg2;
931 handleExtrasChanged(callId, extras);
932 } finally {
933 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700934 Log.endSession();
Tyler Gunndee56a82016-03-23 16:06:34 -0700935 }
936 break;
937 }
Hall Liub64ac4c2017-02-06 10:49:48 -0800938 case MSG_ON_START_RTT: {
939 SomeArgs args = (SomeArgs) msg.obj;
940 try {
941 Log.continueSession((Session) args.arg3,
942 SESSION_HANDLER + SESSION_START_RTT);
943 String callId = (String) args.arg1;
944 Connection.RttTextStream rttTextStream =
945 (Connection.RttTextStream) args.arg2;
946 startRtt(callId, rttTextStream);
947 } finally {
948 args.recycle();
949 Log.endSession();
950 }
951 break;
952 }
953 case MSG_ON_STOP_RTT: {
954 SomeArgs args = (SomeArgs) msg.obj;
955 try {
956 Log.continueSession((Session) args.arg2,
957 SESSION_HANDLER + SESSION_STOP_RTT);
958 String callId = (String) args.arg1;
959 stopRtt(callId);
960 } finally {
961 args.recycle();
962 Log.endSession();
963 }
964 break;
965 }
966 case MSG_RTT_UPGRADE_RESPONSE: {
967 SomeArgs args = (SomeArgs) msg.obj;
968 try {
969 Log.continueSession((Session) args.arg3,
970 SESSION_HANDLER + SESSION_RTT_UPGRADE_RESPONSE);
971 String callId = (String) args.arg1;
972 Connection.RttTextStream rttTextStream =
973 (Connection.RttTextStream) args.arg2;
974 handleRttUpgradeResponse(callId, rttTextStream);
975 } finally {
976 args.recycle();
977 Log.endSession();
978 }
979 break;
980 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700981 default:
982 break;
983 }
984 }
985 };
986
Santos Cordon823fd3c2014-08-07 18:35:18 -0700987 private final Conference.Listener mConferenceListener = new Conference.Listener() {
988 @Override
989 public void onStateChanged(Conference conference, int oldState, int newState) {
990 String id = mIdByConference.get(conference);
991 switch (newState) {
992 case Connection.STATE_ACTIVE:
993 mAdapter.setActive(id);
994 break;
995 case Connection.STATE_HOLDING:
996 mAdapter.setOnHold(id);
997 break;
998 case Connection.STATE_DISCONNECTED:
999 // handled by onDisconnected
1000 break;
1001 }
1002 }
1003
1004 @Override
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001005 public void onDisconnected(Conference conference, DisconnectCause disconnectCause) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07001006 String id = mIdByConference.get(conference);
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001007 mAdapter.setDisconnected(id, disconnectCause);
Santos Cordon823fd3c2014-08-07 18:35:18 -07001008 }
1009
1010 @Override
1011 public void onConnectionAdded(Conference conference, Connection connection) {
1012 }
1013
1014 @Override
1015 public void onConnectionRemoved(Conference conference, Connection connection) {
1016 }
1017
1018 @Override
Ihab Awad50e35062014-09-30 09:17:03 -07001019 public void onConferenceableConnectionsChanged(
1020 Conference conference, List<Connection> conferenceableConnections) {
1021 mAdapter.setConferenceableConnections(
1022 mIdByConference.get(conference),
1023 createConnectionIdList(conferenceableConnections));
1024 }
1025
1026 @Override
Santos Cordon823fd3c2014-08-07 18:35:18 -07001027 public void onDestroyed(Conference conference) {
1028 removeConference(conference);
1029 }
1030
1031 @Override
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001032 public void onConnectionCapabilitiesChanged(
1033 Conference conference,
1034 int connectionCapabilities) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07001035 String id = mIdByConference.get(conference);
1036 Log.d(this, "call capabilities: conference: %s",
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001037 Connection.capabilitiesToString(connectionCapabilities));
1038 mAdapter.setConnectionCapabilities(id, connectionCapabilities);
Santos Cordon823fd3c2014-08-07 18:35:18 -07001039 }
Rekha Kumar07366812015-03-24 16:42:31 -07001040
1041 @Override
Tyler Gunn720c6642016-03-22 09:02:47 -07001042 public void onConnectionPropertiesChanged(
1043 Conference conference,
1044 int connectionProperties) {
1045 String id = mIdByConference.get(conference);
1046 Log.d(this, "call capabilities: conference: %s",
1047 Connection.propertiesToString(connectionProperties));
1048 mAdapter.setConnectionProperties(id, connectionProperties);
1049 }
1050
1051 @Override
Rekha Kumar07366812015-03-24 16:42:31 -07001052 public void onVideoStateChanged(Conference c, int videoState) {
1053 String id = mIdByConference.get(c);
1054 Log.d(this, "onVideoStateChanged set video state %d", videoState);
1055 mAdapter.setVideoState(id, videoState);
1056 }
1057
1058 @Override
1059 public void onVideoProviderChanged(Conference c, Connection.VideoProvider videoProvider) {
1060 String id = mIdByConference.get(c);
1061 Log.d(this, "onVideoProviderChanged: Connection: %s, VideoProvider: %s", c,
1062 videoProvider);
1063 mAdapter.setVideoProvider(id, videoProvider);
1064 }
Andrew Lee0f51da32015-04-16 13:11:55 -07001065
1066 @Override
Andrew Leeedc625f2015-04-14 13:38:12 -07001067 public void onStatusHintsChanged(Conference conference, StatusHints statusHints) {
1068 String id = mIdByConference.get(conference);
Tyler Gunndee56a82016-03-23 16:06:34 -07001069 if (id != null) {
1070 mAdapter.setStatusHints(id, statusHints);
1071 }
Andrew Leeedc625f2015-04-14 13:38:12 -07001072 }
Santos Cordon6b7f9552015-05-27 17:21:45 -07001073
1074 @Override
Tyler Gunndee56a82016-03-23 16:06:34 -07001075 public void onExtrasChanged(Conference c, Bundle extras) {
1076 String id = mIdByConference.get(c);
1077 if (id != null) {
1078 mAdapter.putExtras(id, extras);
1079 }
1080 }
1081
1082 @Override
1083 public void onExtrasRemoved(Conference c, List<String> keys) {
1084 String id = mIdByConference.get(c);
1085 if (id != null) {
1086 mAdapter.removeExtras(id, keys);
1087 }
Santos Cordon6b7f9552015-05-27 17:21:45 -07001088 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07001089 };
1090
Ihab Awad542e0ea2014-05-16 10:22:16 -07001091 private final Connection.Listener mConnectionListener = new Connection.Listener() {
1092 @Override
1093 public void onStateChanged(Connection c, int state) {
1094 String id = mIdByConnection.get(c);
Ihab Awad42b30e12014-05-22 09:49:34 -07001095 Log.d(this, "Adapter set state %s %s", id, Connection.stateToString(state));
Ihab Awad542e0ea2014-05-16 10:22:16 -07001096 switch (state) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001097 case Connection.STATE_ACTIVE:
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001098 mAdapter.setActive(id);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001099 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001100 case Connection.STATE_DIALING:
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001101 mAdapter.setDialing(id);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001102 break;
Tyler Gunnc96b5e02016-07-07 22:53:57 -07001103 case Connection.STATE_PULLING_CALL:
1104 mAdapter.setPulling(id);
1105 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001106 case Connection.STATE_DISCONNECTED:
Ihab Awad542e0ea2014-05-16 10:22:16 -07001107 // Handled in onDisconnected()
1108 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001109 case Connection.STATE_HOLDING:
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001110 mAdapter.setOnHold(id);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001111 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001112 case Connection.STATE_NEW:
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001113 // Nothing to tell Telecom
Ihab Awad542e0ea2014-05-16 10:22:16 -07001114 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001115 case Connection.STATE_RINGING:
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001116 mAdapter.setRinging(id);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001117 break;
1118 }
1119 }
1120
1121 @Override
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001122 public void onDisconnected(Connection c, DisconnectCause disconnectCause) {
Ihab Awad542e0ea2014-05-16 10:22:16 -07001123 String id = mIdByConnection.get(c);
Andrew Lee26786392014-09-16 18:14:59 -07001124 Log.d(this, "Adapter set disconnected %s", disconnectCause);
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001125 mAdapter.setDisconnected(id, disconnectCause);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001126 }
1127
1128 @Override
Tyler Gunnaa07df82014-07-17 07:50:22 -07001129 public void onVideoStateChanged(Connection c, int videoState) {
1130 String id = mIdByConnection.get(c);
1131 Log.d(this, "Adapter set video state %d", videoState);
1132 mAdapter.setVideoState(id, videoState);
1133 }
1134
1135 @Override
Andrew Lee100e2932014-09-08 15:34:24 -07001136 public void onAddressChanged(Connection c, Uri address, int presentation) {
Sailesh Nepal61203862014-07-11 14:50:13 -07001137 String id = mIdByConnection.get(c);
Andrew Lee100e2932014-09-08 15:34:24 -07001138 mAdapter.setAddress(id, address, presentation);
Sailesh Nepal61203862014-07-11 14:50:13 -07001139 }
1140
1141 @Override
1142 public void onCallerDisplayNameChanged(
1143 Connection c, String callerDisplayName, int presentation) {
1144 String id = mIdByConnection.get(c);
1145 mAdapter.setCallerDisplayName(id, callerDisplayName, presentation);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001146 }
1147
1148 @Override
Ihab Awad542e0ea2014-05-16 10:22:16 -07001149 public void onDestroyed(Connection c) {
1150 removeConnection(c);
1151 }
Ihab Awadf8358972014-05-28 16:46:42 -07001152
1153 @Override
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001154 public void onPostDialWait(Connection c, String remaining) {
Sailesh Nepal091768c2014-06-30 15:15:23 -07001155 String id = mIdByConnection.get(c);
1156 Log.d(this, "Adapter onPostDialWait %s, %s", c, remaining);
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001157 mAdapter.onPostDialWait(id, remaining);
Sailesh Nepal091768c2014-06-30 15:15:23 -07001158 }
1159
1160 @Override
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001161 public void onPostDialChar(Connection c, char nextChar) {
1162 String id = mIdByConnection.get(c);
1163 Log.d(this, "Adapter onPostDialChar %s, %s", c, nextChar);
1164 mAdapter.onPostDialChar(id, nextChar);
1165 }
1166
1167 @Override
Andrew Lee100e2932014-09-08 15:34:24 -07001168 public void onRingbackRequested(Connection c, boolean ringback) {
Ihab Awadf8358972014-05-28 16:46:42 -07001169 String id = mIdByConnection.get(c);
1170 Log.d(this, "Adapter onRingback %b", ringback);
Andrew Lee100e2932014-09-08 15:34:24 -07001171 mAdapter.setRingbackRequested(id, ringback);
Ihab Awadf8358972014-05-28 16:46:42 -07001172 }
Santos Cordonb6939982014-06-04 20:20:58 -07001173
1174 @Override
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001175 public void onConnectionCapabilitiesChanged(Connection c, int capabilities) {
Santos Cordonb6939982014-06-04 20:20:58 -07001176 String id = mIdByConnection.get(c);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001177 Log.d(this, "capabilities: parcelableconnection: %s",
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001178 Connection.capabilitiesToString(capabilities));
1179 mAdapter.setConnectionCapabilities(id, capabilities);
Santos Cordonb6939982014-06-04 20:20:58 -07001180 }
1181
Santos Cordonb6939982014-06-04 20:20:58 -07001182 @Override
Tyler Gunn720c6642016-03-22 09:02:47 -07001183 public void onConnectionPropertiesChanged(Connection c, int properties) {
1184 String id = mIdByConnection.get(c);
1185 Log.d(this, "properties: parcelableconnection: %s",
1186 Connection.propertiesToString(properties));
1187 mAdapter.setConnectionProperties(id, properties);
1188 }
1189
1190 @Override
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001191 public void onVideoProviderChanged(Connection c, Connection.VideoProvider videoProvider) {
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07001192 String id = mIdByConnection.get(c);
Rekha Kumar07366812015-03-24 16:42:31 -07001193 Log.d(this, "onVideoProviderChanged: Connection: %s, VideoProvider: %s", c,
1194 videoProvider);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001195 mAdapter.setVideoProvider(id, videoProvider);
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07001196 }
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001197
1198 @Override
Sailesh Nepal001bbbb2014-07-15 14:40:39 -07001199 public void onAudioModeIsVoipChanged(Connection c, boolean isVoip) {
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001200 String id = mIdByConnection.get(c);
Andrew Lee100e2932014-09-08 15:34:24 -07001201 mAdapter.setIsVoipAudioMode(id, isVoip);
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001202 }
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001203
1204 @Override
Sailesh Nepal001bbbb2014-07-15 14:40:39 -07001205 public void onStatusHintsChanged(Connection c, StatusHints statusHints) {
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001206 String id = mIdByConnection.get(c);
1207 mAdapter.setStatusHints(id, statusHints);
1208 }
Sailesh Nepal2ab88cc2014-07-18 14:49:18 -07001209
1210 @Override
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001211 public void onConferenceablesChanged(
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001212 Connection connection, List<Conferenceable> conferenceables) {
Ihab Awadb8e85c72014-08-23 20:34:57 -07001213 mAdapter.setConferenceableConnections(
1214 mIdByConnection.get(connection),
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001215 createIdList(conferenceables));
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001216 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07001217
1218 @Override
1219 public void onConferenceChanged(Connection connection, Conference conference) {
1220 String id = mIdByConnection.get(connection);
1221 if (id != null) {
1222 String conferenceId = null;
1223 if (conference != null) {
1224 conferenceId = mIdByConference.get(conference);
1225 }
1226 mAdapter.setIsConferenced(id, conferenceId);
1227 }
1228 }
Anthony Lee17455a32015-04-24 15:25:29 -07001229
1230 @Override
1231 public void onConferenceMergeFailed(Connection connection) {
1232 String id = mIdByConnection.get(connection);
1233 if (id != null) {
1234 mAdapter.onConferenceMergeFailed(id);
1235 }
1236 }
Santos Cordon6b7f9552015-05-27 17:21:45 -07001237
1238 @Override
Tyler Gunndee56a82016-03-23 16:06:34 -07001239 public void onExtrasChanged(Connection c, Bundle extras) {
1240 String id = mIdByConnection.get(c);
Santos Cordon6b7f9552015-05-27 17:21:45 -07001241 if (id != null) {
Tyler Gunndee56a82016-03-23 16:06:34 -07001242 mAdapter.putExtras(id, extras);
Santos Cordon6b7f9552015-05-27 17:21:45 -07001243 }
1244 }
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001245
Tyler Gunnf5035432017-01-09 09:43:12 -08001246 @Override
Tyler Gunndee56a82016-03-23 16:06:34 -07001247 public void onExtrasRemoved(Connection c, List<String> keys) {
1248 String id = mIdByConnection.get(c);
1249 if (id != null) {
1250 mAdapter.removeExtras(id, keys);
1251 }
1252 }
1253
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08001254 @Override
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001255 public void onConnectionEvent(Connection connection, String event, Bundle extras) {
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08001256 String id = mIdByConnection.get(connection);
1257 if (id != null) {
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001258 mAdapter.onConnectionEvent(id, event, extras);
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08001259 }
1260 }
Tyler Gunnf5035432017-01-09 09:43:12 -08001261
1262 @Override
1263 public void onAudioRouteChanged(Connection c, int audioRoute) {
1264 String id = mIdByConnection.get(c);
1265 if (id != null) {
1266 mAdapter.setAudioRoute(id, audioRoute);
1267 }
1268 }
Hall Liub64ac4c2017-02-06 10:49:48 -08001269
1270 @Override
1271 public void onRttInitiationSuccess(Connection c) {
1272 String id = mIdByConnection.get(c);
1273 if (id != null) {
1274 mAdapter.onRttInitiationSuccess(id);
1275 }
1276 }
1277
1278 @Override
1279 public void onRttInitiationFailure(Connection c, int reason) {
1280 String id = mIdByConnection.get(c);
1281 if (id != null) {
1282 mAdapter.onRttInitiationFailure(id, reason);
1283 }
1284 }
1285
1286 @Override
1287 public void onRttSessionRemotelyTerminated(Connection c) {
1288 String id = mIdByConnection.get(c);
1289 if (id != null) {
1290 mAdapter.onRttSessionRemotelyTerminated(id);
1291 }
1292 }
1293
1294 @Override
1295 public void onRemoteRttRequest(Connection c) {
1296 String id = mIdByConnection.get(c);
1297 if (id != null) {
1298 mAdapter.onRemoteRttRequest(id);
1299 }
1300 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001301 };
1302
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001303 /** {@inheritDoc} */
Ihab Awad542e0ea2014-05-16 10:22:16 -07001304 @Override
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001305 public final IBinder onBind(Intent intent) {
1306 return mBinder;
1307 }
1308
Santos Cordon29f2f2e2014-09-11 19:50:24 -07001309 /** {@inheritDoc} */
1310 @Override
1311 public boolean onUnbind(Intent intent) {
1312 endAllConnections();
1313 return super.onUnbind(intent);
1314 }
1315
Sailesh Nepalc5b01572014-07-14 16:29:44 -07001316 /**
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001317 * This can be used by telecom to either create a new outgoing call or attach to an existing
1318 * incoming call. In either case, telecom will cycle through a set of services and call
Sailesh Nepalc5b01572014-07-14 16:29:44 -07001319 * createConnection util a connection service cancels the process or completes it successfully.
1320 */
Ihab Awadf8b69882014-07-25 15:14:01 -07001321 private void createConnection(
1322 final PhoneAccountHandle callManagerAccount,
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001323 final String callId,
Ihab Awadf8b69882014-07-25 15:14:01 -07001324 final ConnectionRequest request,
Yorke Leec3cf9822014-10-02 09:38:39 -07001325 boolean isIncoming,
1326 boolean isUnknown) {
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001327 Log.d(this, "createConnection, callManagerAccount: %s, callId: %s, request: %s, " +
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001328 "isIncoming: %b, isUnknown: %b", callManagerAccount, callId, request,
1329 isIncoming,
Yorke Leec3cf9822014-10-02 09:38:39 -07001330 isUnknown);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001331
Yorke Leec3cf9822014-10-02 09:38:39 -07001332 Connection connection = isUnknown ? onCreateUnknownConnection(callManagerAccount, request)
1333 : isIncoming ? onCreateIncomingConnection(callManagerAccount, request)
Ihab Awad6107bab2014-08-18 09:23:25 -07001334 : onCreateOutgoingConnection(callManagerAccount, request);
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001335 Log.d(this, "createConnection, connection: %s", connection);
1336 if (connection == null) {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001337 connection = Connection.createFailedConnection(
1338 new DisconnectCause(DisconnectCause.ERROR));
Sailesh Nepalc5b01572014-07-14 16:29:44 -07001339 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001340
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001341 connection.setTelecomCallId(callId);
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001342 if (connection.getState() != Connection.STATE_DISCONNECTED) {
Ihab Awad6107bab2014-08-18 09:23:25 -07001343 addConnection(callId, connection);
1344 }
1345
Andrew Lee100e2932014-09-08 15:34:24 -07001346 Uri address = connection.getAddress();
1347 String number = address == null ? "null" : address.getSchemeSpecificPart();
Tyler Gunn720c6642016-03-22 09:02:47 -07001348 Log.v(this, "createConnection, number: %s, state: %s, capabilities: %s, properties: %s",
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001349 Connection.toLogSafePhoneNumber(number),
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001350 Connection.stateToString(connection.getState()),
Tyler Gunn720c6642016-03-22 09:02:47 -07001351 Connection.capabilitiesToString(connection.getConnectionCapabilities()),
1352 Connection.propertiesToString(connection.getConnectionProperties()));
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001353
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001354 Log.d(this, "createConnection, calling handleCreateConnectionSuccessful %s", callId);
Ihab Awad6107bab2014-08-18 09:23:25 -07001355 mAdapter.handleCreateConnectionComplete(
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001356 callId,
Evan Charltonbf11f982014-07-20 22:06:28 -07001357 request,
1358 new ParcelableConnection(
1359 request.getAccountHandle(),
1360 connection.getState(),
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001361 connection.getConnectionCapabilities(),
Tyler Gunn720c6642016-03-22 09:02:47 -07001362 connection.getConnectionProperties(),
Christine Hallstrom2830ce92016-11-30 16:06:42 -08001363 connection.getSupportedAudioRoutes(),
Andrew Lee100e2932014-09-08 15:34:24 -07001364 connection.getAddress(),
1365 connection.getAddressPresentation(),
Evan Charltonbf11f982014-07-20 22:06:28 -07001366 connection.getCallerDisplayName(),
1367 connection.getCallerDisplayNamePresentation(),
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001368 connection.getVideoProvider() == null ?
1369 null : connection.getVideoProvider().getInterface(),
Sailesh Nepal8b9d3ca2014-08-14 17:39:34 -07001370 connection.getVideoState(),
Andrew Lee100e2932014-09-08 15:34:24 -07001371 connection.isRingbackRequested(),
Sailesh Nepal8b9d3ca2014-08-14 17:39:34 -07001372 connection.getAudioModeIsVoip(),
Roshan Piuse927ec02015-07-15 15:47:21 -07001373 connection.getConnectTimeMillis(),
Ihab Awad6107bab2014-08-18 09:23:25 -07001374 connection.getStatusHints(),
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001375 connection.getDisconnectCause(),
Santos Cordon6b7f9552015-05-27 17:21:45 -07001376 createIdList(connection.getConferenceables()),
1377 connection.getExtras()));
Tyler Gunnf5035432017-01-09 09:43:12 -08001378
1379 if (isIncoming && request.shouldShowIncomingCallUi() &&
1380 (connection.getConnectionProperties() & Connection.PROPERTY_SELF_MANAGED) ==
1381 Connection.PROPERTY_SELF_MANAGED) {
1382 // Tell ConnectionService to show its incoming call UX.
1383 connection.onShowIncomingCallUi();
1384 }
Shriram Ganesh6bf35ac2014-12-11 17:53:38 -08001385 if (isUnknown) {
1386 triggerConferenceRecalculate();
1387 }
Evan Charltonbf11f982014-07-20 22:06:28 -07001388 }
1389
Tyler Gunn159f35c2017-03-02 09:28:37 -08001390 private void createConnectionFailed(final PhoneAccountHandle callManagerAccount,
1391 final String callId, final ConnectionRequest request,
1392 boolean isIncoming) {
Tyler Gunn44e01912017-01-31 10:49:05 -08001393
1394 Log.i(this, "createConnectionFailed %s", callId);
1395 if (isIncoming) {
Tyler Gunn159f35c2017-03-02 09:28:37 -08001396 onCreateIncomingConnectionFailed(callManagerAccount, request);
Tyler Gunn44e01912017-01-31 10:49:05 -08001397 } else {
Tyler Gunn159f35c2017-03-02 09:28:37 -08001398 onCreateOutgoingConnectionFailed(callManagerAccount, request);
Tyler Gunn44e01912017-01-31 10:49:05 -08001399 }
1400 }
1401
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001402 private void abort(String callId) {
Ihab Awad60ac30b2014-05-20 22:32:12 -07001403 Log.d(this, "abort %s", callId);
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001404 findConnectionForAction(callId, "abort").onAbort();
Ihab Awad542e0ea2014-05-16 10:22:16 -07001405 }
1406
Tyler Gunnbe74de02014-08-29 14:51:48 -07001407 private void answerVideo(String callId, int videoState) {
1408 Log.d(this, "answerVideo %s", callId);
Andrew Lee8da4c3c2014-07-16 10:11:42 -07001409 findConnectionForAction(callId, "answer").onAnswer(videoState);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001410 }
1411
Tyler Gunnbe74de02014-08-29 14:51:48 -07001412 private void answer(String callId) {
1413 Log.d(this, "answer %s", callId);
1414 findConnectionForAction(callId, "answer").onAnswer();
1415 }
1416
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001417 private void reject(String callId) {
Ihab Awad60ac30b2014-05-20 22:32:12 -07001418 Log.d(this, "reject %s", callId);
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001419 findConnectionForAction(callId, "reject").onReject();
Ihab Awad542e0ea2014-05-16 10:22:16 -07001420 }
1421
Bryce Lee81901682015-08-28 16:38:02 -07001422 private void reject(String callId, String rejectWithMessage) {
1423 Log.d(this, "reject %s with message", callId);
1424 findConnectionForAction(callId, "reject").onReject(rejectWithMessage);
1425 }
1426
Bryce Leecac50772015-11-17 15:13:29 -08001427 private void silence(String callId) {
1428 Log.d(this, "silence %s", callId);
1429 findConnectionForAction(callId, "silence").onSilence();
1430 }
1431
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001432 private void disconnect(String callId) {
Ihab Awad60ac30b2014-05-20 22:32:12 -07001433 Log.d(this, "disconnect %s", callId);
Santos Cordon0159ac02014-08-21 14:28:11 -07001434 if (mConnectionById.containsKey(callId)) {
1435 findConnectionForAction(callId, "disconnect").onDisconnect();
1436 } else {
1437 findConferenceForAction(callId, "disconnect").onDisconnect();
1438 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001439 }
1440
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001441 private void hold(String callId) {
Ihab Awad60ac30b2014-05-20 22:32:12 -07001442 Log.d(this, "hold %s", callId);
Santos Cordon0159ac02014-08-21 14:28:11 -07001443 if (mConnectionById.containsKey(callId)) {
1444 findConnectionForAction(callId, "hold").onHold();
1445 } else {
1446 findConferenceForAction(callId, "hold").onHold();
1447 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001448 }
1449
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001450 private void unhold(String callId) {
Ihab Awad60ac30b2014-05-20 22:32:12 -07001451 Log.d(this, "unhold %s", callId);
Santos Cordon0159ac02014-08-21 14:28:11 -07001452 if (mConnectionById.containsKey(callId)) {
1453 findConnectionForAction(callId, "unhold").onUnhold();
1454 } else {
1455 findConferenceForAction(callId, "unhold").onUnhold();
1456 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001457 }
1458
Yorke Lee4af59352015-05-13 14:14:54 -07001459 private void onCallAudioStateChanged(String callId, CallAudioState callAudioState) {
1460 Log.d(this, "onAudioStateChanged %s %s", callId, callAudioState);
Yorke Leea0d3ca92014-09-15 19:18:13 -07001461 if (mConnectionById.containsKey(callId)) {
Yorke Lee4af59352015-05-13 14:14:54 -07001462 findConnectionForAction(callId, "onCallAudioStateChanged").setCallAudioState(
1463 callAudioState);
Yorke Leea0d3ca92014-09-15 19:18:13 -07001464 } else {
Yorke Lee4af59352015-05-13 14:14:54 -07001465 findConferenceForAction(callId, "onCallAudioStateChanged").setCallAudioState(
1466 callAudioState);
Yorke Leea0d3ca92014-09-15 19:18:13 -07001467 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001468 }
1469
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001470 private void playDtmfTone(String callId, char digit) {
1471 Log.d(this, "playDtmfTone %s %c", callId, digit);
Yorke Leea0d3ca92014-09-15 19:18:13 -07001472 if (mConnectionById.containsKey(callId)) {
1473 findConnectionForAction(callId, "playDtmfTone").onPlayDtmfTone(digit);
1474 } else {
1475 findConferenceForAction(callId, "playDtmfTone").onPlayDtmfTone(digit);
1476 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001477 }
1478
1479 private void stopDtmfTone(String callId) {
1480 Log.d(this, "stopDtmfTone %s", callId);
Yorke Leea0d3ca92014-09-15 19:18:13 -07001481 if (mConnectionById.containsKey(callId)) {
1482 findConnectionForAction(callId, "stopDtmfTone").onStopDtmfTone();
1483 } else {
1484 findConferenceForAction(callId, "stopDtmfTone").onStopDtmfTone();
1485 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001486 }
1487
Santos Cordon823fd3c2014-08-07 18:35:18 -07001488 private void conference(String callId1, String callId2) {
1489 Log.d(this, "conference %s, %s", callId1, callId2);
Santos Cordon980acb92014-05-31 10:31:19 -07001490
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001491 // Attempt to get second connection or conference.
Santos Cordon823fd3c2014-08-07 18:35:18 -07001492 Connection connection2 = findConnectionForAction(callId2, "conference");
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001493 Conference conference2 = getNullConference();
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001494 if (connection2 == getNullConnection()) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001495 conference2 = findConferenceForAction(callId2, "conference");
1496 if (conference2 == getNullConference()) {
1497 Log.w(this, "Connection2 or Conference2 missing in conference request %s.",
1498 callId2);
1499 return;
1500 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07001501 }
Santos Cordonb6939982014-06-04 20:20:58 -07001502
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001503 // Attempt to get first connection or conference and perform merge.
Ihab Awad50e35062014-09-30 09:17:03 -07001504 Connection connection1 = findConnectionForAction(callId1, "conference");
1505 if (connection1 == getNullConnection()) {
1506 Conference conference1 = findConferenceForAction(callId1, "addConnection");
1507 if (conference1 == getNullConference()) {
1508 Log.w(this,
1509 "Connection1 or Conference1 missing in conference request %s.",
1510 callId1);
1511 } else {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001512 // Call 1 is a conference.
1513 if (connection2 != getNullConnection()) {
1514 // Call 2 is a connection so merge via call 1 (conference).
1515 conference1.onMerge(connection2);
1516 } else {
1517 // Call 2 is ALSO a conference; this should never happen.
1518 Log.wtf(this, "There can only be one conference and an attempt was made to " +
1519 "merge two conferences.");
1520 return;
1521 }
Ihab Awad50e35062014-09-30 09:17:03 -07001522 }
1523 } else {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001524 // Call 1 is a connection.
1525 if (conference2 != getNullConference()) {
1526 // Call 2 is a conference, so merge via call 2.
1527 conference2.onMerge(connection1);
1528 } else {
1529 // Call 2 is a connection, so merge together.
1530 onConference(connection1, connection2);
1531 }
Ihab Awad50e35062014-09-30 09:17:03 -07001532 }
Santos Cordon980acb92014-05-31 10:31:19 -07001533 }
1534
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001535 private void splitFromConference(String callId) {
Santos Cordonb6939982014-06-04 20:20:58 -07001536 Log.d(this, "splitFromConference(%s)", callId);
Santos Cordon980acb92014-05-31 10:31:19 -07001537
1538 Connection connection = findConnectionForAction(callId, "splitFromConference");
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001539 if (connection == getNullConnection()) {
Santos Cordon980acb92014-05-31 10:31:19 -07001540 Log.w(this, "Connection missing in conference request %s.", callId);
1541 return;
1542 }
1543
Santos Cordon0159ac02014-08-21 14:28:11 -07001544 Conference conference = connection.getConference();
1545 if (conference != null) {
1546 conference.onSeparate(connection);
1547 }
Santos Cordon980acb92014-05-31 10:31:19 -07001548 }
1549
Santos Cordona4868042014-09-04 17:39:22 -07001550 private void mergeConference(String callId) {
1551 Log.d(this, "mergeConference(%s)", callId);
1552 Conference conference = findConferenceForAction(callId, "mergeConference");
1553 if (conference != null) {
1554 conference.onMerge();
1555 }
1556 }
1557
1558 private void swapConference(String callId) {
1559 Log.d(this, "swapConference(%s)", callId);
1560 Conference conference = findConferenceForAction(callId, "swapConference");
1561 if (conference != null) {
1562 conference.onSwap();
1563 }
1564 }
1565
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001566 /**
1567 * Notifies a {@link Connection} of a request to pull an external call.
1568 *
1569 * See {@link Call#pullExternalCall()}.
1570 *
1571 * @param callId The ID of the call to pull.
1572 */
1573 private void pullExternalCall(String callId) {
1574 Log.d(this, "pullExternalCall(%s)", callId);
1575 Connection connection = findConnectionForAction(callId, "pullExternalCall");
1576 if (connection != null) {
1577 connection.onPullExternalCall();
1578 }
1579 }
1580
1581 /**
1582 * Notifies a {@link Connection} of a call event.
1583 *
1584 * See {@link Call#sendCallEvent(String, Bundle)}.
1585 *
1586 * @param callId The ID of the call receiving the event.
1587 * @param event The event.
1588 * @param extras Extras associated with the event.
1589 */
1590 private void sendCallEvent(String callId, String event, Bundle extras) {
1591 Log.d(this, "sendCallEvent(%s, %s)", callId, event);
1592 Connection connection = findConnectionForAction(callId, "sendCallEvent");
1593 if (connection != null) {
1594 connection.onCallEvent(event, extras);
1595 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001596 }
1597
Tyler Gunndee56a82016-03-23 16:06:34 -07001598 /**
1599 * Notifies a {@link Connection} or {@link Conference} of a change to the extras from Telecom.
1600 * <p>
1601 * These extra changes can originate from Telecom itself, or from an {@link InCallService} via
1602 * the {@link android.telecom.Call#putExtra(String, boolean)},
1603 * {@link android.telecom.Call#putExtra(String, int)},
1604 * {@link android.telecom.Call#putExtra(String, String)},
1605 * {@link Call#removeExtras(List)}.
1606 *
1607 * @param callId The ID of the call receiving the event.
1608 * @param extras The new extras bundle.
1609 */
1610 private void handleExtrasChanged(String callId, Bundle extras) {
1611 Log.d(this, "handleExtrasChanged(%s, %s)", callId, extras);
1612 if (mConnectionById.containsKey(callId)) {
1613 findConnectionForAction(callId, "handleExtrasChanged").handleExtrasChanged(extras);
1614 } else if (mConferenceById.containsKey(callId)) {
1615 findConferenceForAction(callId, "handleExtrasChanged").handleExtrasChanged(extras);
1616 }
1617 }
1618
Hall Liub64ac4c2017-02-06 10:49:48 -08001619 private void startRtt(String callId, Connection.RttTextStream rttTextStream) {
1620 Log.d(this, "startRtt(%s)", callId);
1621 if (mConnectionById.containsKey(callId)) {
1622 findConnectionForAction(callId, "startRtt").onStartRtt(rttTextStream);
1623 } else if (mConferenceById.containsKey(callId)) {
1624 Log.w(this, "startRtt called on a conference.");
1625 }
1626 }
1627
1628 private void stopRtt(String callId) {
1629 Log.d(this, "stopRtt(%s)", callId);
1630 if (mConnectionById.containsKey(callId)) {
1631 findConnectionForAction(callId, "stopRtt").onStopRtt();
Hall Liuffa4a812017-03-02 16:11:00 -08001632 findConnectionForAction(callId, "stopRtt").unsetRttProperty();
Hall Liub64ac4c2017-02-06 10:49:48 -08001633 } else if (mConferenceById.containsKey(callId)) {
1634 Log.w(this, "stopRtt called on a conference.");
1635 }
1636 }
1637
1638 private void handleRttUpgradeResponse(String callId, Connection.RttTextStream rttTextStream) {
1639 Log.d(this, "handleRttUpgradeResponse(%s, %s)", callId, rttTextStream == null);
1640 if (mConnectionById.containsKey(callId)) {
1641 findConnectionForAction(callId, "handleRttUpgradeResponse")
1642 .handleRttUpgradeResponse(rttTextStream);
1643 } else if (mConferenceById.containsKey(callId)) {
1644 Log.w(this, "handleRttUpgradeResponse called on a conference.");
1645 }
1646 }
1647
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001648 private void onPostDialContinue(String callId, boolean proceed) {
Evan Charlton6dea4ac2014-06-03 14:07:13 -07001649 Log.d(this, "onPostDialContinue(%s)", callId);
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001650 findConnectionForAction(callId, "stopDtmfTone").onPostDialContinue(proceed);
Evan Charlton6dea4ac2014-06-03 14:07:13 -07001651 }
1652
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001653 private void onAdapterAttached() {
Ihab Awad9c3f1882014-06-30 21:17:13 -07001654 if (mAreAccountsInitialized) {
Santos Cordon52d8a152014-06-17 19:08:45 -07001655 // No need to query again if we already did it.
1656 return;
1657 }
1658
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001659 mAdapter.queryRemoteConnectionServices(new RemoteServiceCallback.Stub() {
Santos Cordon52d8a152014-06-17 19:08:45 -07001660 @Override
1661 public void onResult(
1662 final List<ComponentName> componentNames,
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001663 final List<IBinder> services) {
Brad Ebinger0c3541b2016-11-01 14:11:38 -07001664 mHandler.post(new android.telecom.Logging.Runnable("oAA.qRCS.oR", null /*lock*/) {
Ihab Awad6107bab2014-08-18 09:23:25 -07001665 @Override
Brad Ebinger0c3541b2016-11-01 14:11:38 -07001666 public void loggedRun() {
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001667 for (int i = 0; i < componentNames.size() && i < services.size(); i++) {
Santos Cordon52d8a152014-06-17 19:08:45 -07001668 mRemoteConnectionManager.addConnectionService(
1669 componentNames.get(i),
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001670 IConnectionService.Stub.asInterface(services.get(i)));
Santos Cordon52d8a152014-06-17 19:08:45 -07001671 }
Ihab Awad5d0410f2014-07-30 10:07:40 -07001672 onAccountsInitialized();
Sailesh Nepalc5b01572014-07-14 16:29:44 -07001673 Log.d(this, "remote connection services found: " + services);
Santos Cordon52d8a152014-06-17 19:08:45 -07001674 }
Brad Ebinger0c3541b2016-11-01 14:11:38 -07001675 }.prepare());
Santos Cordon52d8a152014-06-17 19:08:45 -07001676 }
1677
1678 @Override
1679 public void onError() {
Brad Ebinger0c3541b2016-11-01 14:11:38 -07001680 mHandler.post(new android.telecom.Logging.Runnable("oAA.qRCS.oE", null /*lock*/) {
Ihab Awad6107bab2014-08-18 09:23:25 -07001681 @Override
Brad Ebinger0c3541b2016-11-01 14:11:38 -07001682 public void loggedRun() {
Ihab Awad9c3f1882014-06-30 21:17:13 -07001683 mAreAccountsInitialized = true;
Santos Cordon52d8a152014-06-17 19:08:45 -07001684 }
Brad Ebinger0c3541b2016-11-01 14:11:38 -07001685 }.prepare());
Santos Cordon52d8a152014-06-17 19:08:45 -07001686 }
1687 });
1688 }
1689
Ihab Awadf8b69882014-07-25 15:14:01 -07001690 /**
1691 * Ask some other {@code ConnectionService} to create a {@code RemoteConnection} given an
Santos Cordona663f862014-10-29 13:49:58 -07001692 * incoming request. This is used by {@code ConnectionService}s that are registered with
1693 * {@link PhoneAccount#CAPABILITY_CONNECTION_MANAGER} and want to be able to manage
1694 * SIM-based incoming calls.
Ihab Awadf8b69882014-07-25 15:14:01 -07001695 *
1696 * @param connectionManagerPhoneAccount See description at
1697 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
1698 * @param request Details about the incoming call.
1699 * @return The {@code Connection} object to satisfy this call, or {@code null} to
1700 * not handle the call.
1701 */
1702 public final RemoteConnection createRemoteIncomingConnection(
1703 PhoneAccountHandle connectionManagerPhoneAccount,
1704 ConnectionRequest request) {
1705 return mRemoteConnectionManager.createRemoteConnection(
1706 connectionManagerPhoneAccount, request, true);
Santos Cordon52d8a152014-06-17 19:08:45 -07001707 }
1708
1709 /**
Ihab Awadf8b69882014-07-25 15:14:01 -07001710 * Ask some other {@code ConnectionService} to create a {@code RemoteConnection} given an
Santos Cordona663f862014-10-29 13:49:58 -07001711 * outgoing request. This is used by {@code ConnectionService}s that are registered with
1712 * {@link PhoneAccount#CAPABILITY_CONNECTION_MANAGER} and want to be able to use the
1713 * SIM-based {@code ConnectionService} to place its outgoing calls.
Ihab Awadf8b69882014-07-25 15:14:01 -07001714 *
1715 * @param connectionManagerPhoneAccount See description at
1716 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
Cuihtlauac ALVARADO0b3b2a52016-09-13 14:49:41 +02001717 * @param request Details about the outgoing call.
Ihab Awadf8b69882014-07-25 15:14:01 -07001718 * @return The {@code Connection} object to satisfy this call, or {@code null} to
1719 * not handle the call.
1720 */
1721 public final RemoteConnection createRemoteOutgoingConnection(
1722 PhoneAccountHandle connectionManagerPhoneAccount,
1723 ConnectionRequest request) {
1724 return mRemoteConnectionManager.createRemoteConnection(
1725 connectionManagerPhoneAccount, request, false);
1726 }
1727
1728 /**
Santos Cordona663f862014-10-29 13:49:58 -07001729 * Indicates to the relevant {@code RemoteConnectionService} that the specified
1730 * {@link RemoteConnection}s should be merged into a conference call.
1731 * <p>
1732 * If the conference request is successful, the method {@link #onRemoteConferenceAdded} will
1733 * be invoked.
1734 *
1735 * @param remoteConnection1 The first of the remote connections to conference.
1736 * @param remoteConnection2 The second of the remote connections to conference.
Ihab Awadb8e85c72014-08-23 20:34:57 -07001737 */
1738 public final void conferenceRemoteConnections(
Santos Cordona663f862014-10-29 13:49:58 -07001739 RemoteConnection remoteConnection1,
1740 RemoteConnection remoteConnection2) {
1741 mRemoteConnectionManager.conferenceRemoteConnections(remoteConnection1, remoteConnection2);
Ihab Awadb8e85c72014-08-23 20:34:57 -07001742 }
1743
1744 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07001745 * Adds a new conference call. When a conference call is created either as a result of an
1746 * explicit request via {@link #onConference} or otherwise, the connection service should supply
1747 * an instance of {@link Conference} by invoking this method. A conference call provided by this
1748 * method will persist until {@link Conference#destroy} is invoked on the conference instance.
1749 *
1750 * @param conference The new conference object.
1751 */
1752 public final void addConference(Conference conference) {
Rekha Kumar07366812015-03-24 16:42:31 -07001753 Log.d(this, "addConference: conference=%s", conference);
1754
Santos Cordon823fd3c2014-08-07 18:35:18 -07001755 String id = addConferenceInternal(conference);
1756 if (id != null) {
1757 List<String> connectionIds = new ArrayList<>(2);
1758 for (Connection connection : conference.getConnections()) {
1759 if (mIdByConnection.containsKey(connection)) {
1760 connectionIds.add(mIdByConnection.get(connection));
1761 }
1762 }
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001763 conference.setTelecomCallId(id);
Santos Cordon823fd3c2014-08-07 18:35:18 -07001764 ParcelableConference parcelableConference = new ParcelableConference(
Nancy Chenea38cca2014-09-05 16:38:49 -07001765 conference.getPhoneAccountHandle(),
Santos Cordon823fd3c2014-08-07 18:35:18 -07001766 conference.getState(),
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001767 conference.getConnectionCapabilities(),
Tyler Gunn720c6642016-03-22 09:02:47 -07001768 conference.getConnectionProperties(),
Tyler Gunncd5d33c2015-01-12 09:02:01 -08001769 connectionIds,
Rekha Kumar07366812015-03-24 16:42:31 -07001770 conference.getVideoProvider() == null ?
1771 null : conference.getVideoProvider().getInterface(),
1772 conference.getVideoState(),
Andrew Lee3e3e2f22015-04-16 13:48:43 -07001773 conference.getConnectTimeMillis(),
Santos Cordon6b7f9552015-05-27 17:21:45 -07001774 conference.getStatusHints(),
1775 conference.getExtras());
Andrew Lee0f51da32015-04-16 13:11:55 -07001776
Santos Cordon823fd3c2014-08-07 18:35:18 -07001777 mAdapter.addConferenceCall(id, parcelableConference);
Rekha Kumar07366812015-03-24 16:42:31 -07001778 mAdapter.setVideoProvider(id, conference.getVideoProvider());
1779 mAdapter.setVideoState(id, conference.getVideoState());
Santos Cordon823fd3c2014-08-07 18:35:18 -07001780
1781 // Go through any child calls and set the parent.
1782 for (Connection connection : conference.getConnections()) {
1783 String connectionId = mIdByConnection.get(connection);
1784 if (connectionId != null) {
1785 mAdapter.setIsConferenced(connectionId, id);
1786 }
1787 }
1788 }
1789 }
1790
1791 /**
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07001792 * Adds a connection created by the {@link ConnectionService} and informs telecom of the new
1793 * connection.
1794 *
1795 * @param phoneAccountHandle The phone account handle for the connection.
1796 * @param connection The connection to add.
1797 */
1798 public final void addExistingConnection(PhoneAccountHandle phoneAccountHandle,
1799 Connection connection) {
1800
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001801 String id = addExistingConnectionInternal(phoneAccountHandle, connection);
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07001802 if (id != null) {
1803 List<String> emptyList = new ArrayList<>(0);
1804
1805 ParcelableConnection parcelableConnection = new ParcelableConnection(
1806 phoneAccountHandle,
1807 connection.getState(),
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001808 connection.getConnectionCapabilities(),
Tyler Gunn720c6642016-03-22 09:02:47 -07001809 connection.getConnectionProperties(),
Christine Hallstrom2830ce92016-11-30 16:06:42 -08001810 connection.getSupportedAudioRoutes(),
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07001811 connection.getAddress(),
1812 connection.getAddressPresentation(),
1813 connection.getCallerDisplayName(),
1814 connection.getCallerDisplayNamePresentation(),
1815 connection.getVideoProvider() == null ?
1816 null : connection.getVideoProvider().getInterface(),
1817 connection.getVideoState(),
1818 connection.isRingbackRequested(),
1819 connection.getAudioModeIsVoip(),
Roshan Piuse927ec02015-07-15 15:47:21 -07001820 connection.getConnectTimeMillis(),
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07001821 connection.getStatusHints(),
1822 connection.getDisconnectCause(),
Santos Cordon6b7f9552015-05-27 17:21:45 -07001823 emptyList,
1824 connection.getExtras());
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07001825 mAdapter.addExistingConnection(id, parcelableConnection);
1826 }
1827 }
1828
1829 /**
Ihab Awadf8b69882014-07-25 15:14:01 -07001830 * Returns all the active {@code Connection}s for which this {@code ConnectionService}
1831 * has taken responsibility.
1832 *
1833 * @return A collection of {@code Connection}s created by this {@code ConnectionService}.
Santos Cordonb6939982014-06-04 20:20:58 -07001834 */
Sailesh Nepal091768c2014-06-30 15:15:23 -07001835 public final Collection<Connection> getAllConnections() {
Santos Cordonb6939982014-06-04 20:20:58 -07001836 return mConnectionById.values();
1837 }
1838
1839 /**
Santos Cordona6018b92016-02-16 14:23:12 -08001840 * Returns all the active {@code Conference}s for which this {@code ConnectionService}
1841 * has taken responsibility.
1842 *
1843 * @return A collection of {@code Conference}s created by this {@code ConnectionService}.
1844 */
1845 public final Collection<Conference> getAllConferences() {
1846 return mConferenceById.values();
1847 }
1848
1849 /**
Ihab Awadf8b69882014-07-25 15:14:01 -07001850 * Create a {@code Connection} given an incoming request. This is used to attach to existing
1851 * incoming calls.
Evan Charltonbf11f982014-07-20 22:06:28 -07001852 *
Ihab Awadf8b69882014-07-25 15:14:01 -07001853 * @param connectionManagerPhoneAccount See description at
1854 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
1855 * @param request Details about the incoming call.
1856 * @return The {@code Connection} object to satisfy this call, or {@code null} to
1857 * not handle the call.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001858 */
Ihab Awadf8b69882014-07-25 15:14:01 -07001859 public Connection onCreateIncomingConnection(
1860 PhoneAccountHandle connectionManagerPhoneAccount,
1861 ConnectionRequest request) {
1862 return null;
1863 }
Sailesh Nepalc5b01572014-07-14 16:29:44 -07001864
1865 /**
Tyler Gunnf5035432017-01-09 09:43:12 -08001866 * Called by Telecom to inform the {@link ConnectionService} that its request to create a new
1867 * incoming {@link Connection} was denied.
1868 * <p>
1869 * Used when a self-managed {@link ConnectionService} attempts to create a new incoming
1870 * {@link Connection}, but Telecom has determined that the call cannot be allowed at this time.
1871 * The {@link ConnectionService} is responsible for silently rejecting the new incoming
1872 * {@link Connection}.
1873 * <p>
1874 * See {@link TelecomManager#isIncomingCallPermitted(PhoneAccountHandle)} for more information.
1875 *
Tyler Gunn159f35c2017-03-02 09:28:37 -08001876 * @param connectionManagerPhoneAccount See description at
1877 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
Tyler Gunnf5035432017-01-09 09:43:12 -08001878 * @param request The incoming connection request.
1879 */
Tyler Gunn159f35c2017-03-02 09:28:37 -08001880 public void onCreateIncomingConnectionFailed(PhoneAccountHandle connectionManagerPhoneAccount,
1881 ConnectionRequest request) {
Tyler Gunnf5035432017-01-09 09:43:12 -08001882 }
1883
1884 /**
1885 * Called by Telecom to inform the {@link ConnectionService} that its request to create a new
1886 * outgoing {@link Connection} was denied.
1887 * <p>
1888 * Used when a self-managed {@link ConnectionService} attempts to create a new outgoing
1889 * {@link Connection}, but Telecom has determined that the call cannot be placed at this time.
1890 * The {@link ConnectionService} is responisible for informing the user that the
1891 * {@link Connection} cannot be made at this time.
1892 * <p>
1893 * See {@link TelecomManager#isOutgoingCallPermitted(PhoneAccountHandle)} for more information.
1894 *
Tyler Gunn159f35c2017-03-02 09:28:37 -08001895 * @param connectionManagerPhoneAccount See description at
1896 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
Tyler Gunnf5035432017-01-09 09:43:12 -08001897 * @param request The outgoing connection request.
1898 */
Tyler Gunn159f35c2017-03-02 09:28:37 -08001899 public void onCreateOutgoingConnectionFailed(PhoneAccountHandle connectionManagerPhoneAccount,
1900 ConnectionRequest request) {
Tyler Gunnf5035432017-01-09 09:43:12 -08001901 }
1902
1903 /**
Shriram Ganesh6bf35ac2014-12-11 17:53:38 -08001904 * Trigger recalculate functinality for conference calls. This is used when a Telephony
1905 * Connection is part of a conference controller but is not yet added to Connection
1906 * Service and hence cannot be added to the conference call.
1907 *
1908 * @hide
1909 */
1910 public void triggerConferenceRecalculate() {
1911 }
1912
1913 /**
Ihab Awadf8b69882014-07-25 15:14:01 -07001914 * Create a {@code Connection} given an outgoing request. This is used to initiate new
1915 * outgoing calls.
Sailesh Nepalc5b01572014-07-14 16:29:44 -07001916 *
Ihab Awadf8b69882014-07-25 15:14:01 -07001917 * @param connectionManagerPhoneAccount The connection manager account to use for managing
1918 * this call.
1919 * <p>
1920 * If this parameter is not {@code null}, it means that this {@code ConnectionService}
1921 * has registered one or more {@code PhoneAccount}s having
1922 * {@link PhoneAccount#CAPABILITY_CONNECTION_MANAGER}. This parameter will contain
1923 * one of these {@code PhoneAccount}s, while the {@code request} will contain another
1924 * (usually but not always distinct) {@code PhoneAccount} to be used for actually
1925 * making the connection.
1926 * <p>
1927 * If this parameter is {@code null}, it means that this {@code ConnectionService} is
1928 * being asked to make a direct connection. The
1929 * {@link ConnectionRequest#getAccountHandle()} of parameter {@code request} will be
1930 * a {@code PhoneAccount} registered by this {@code ConnectionService} to use for
1931 * making the connection.
1932 * @param request Details about the outgoing call.
1933 * @return The {@code Connection} object to satisfy this call, or the result of an invocation
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001934 * of {@link Connection#createFailedConnection(DisconnectCause)} to not handle the call.
Sailesh Nepalc5b01572014-07-14 16:29:44 -07001935 */
Ihab Awadf8b69882014-07-25 15:14:01 -07001936 public Connection onCreateOutgoingConnection(
1937 PhoneAccountHandle connectionManagerPhoneAccount,
1938 ConnectionRequest request) {
1939 return null;
1940 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001941
1942 /**
Yorke Leec3cf9822014-10-02 09:38:39 -07001943 * Create a {@code Connection} for a new unknown call. An unknown call is a call originating
1944 * from the ConnectionService that was neither a user-initiated outgoing call, nor an incoming
1945 * call created using
1946 * {@code TelecomManager#addNewIncomingCall(PhoneAccountHandle, android.os.Bundle)}.
1947 *
Yorke Lee770ed6e2014-10-06 18:58:52 -07001948 * @hide
Yorke Leec3cf9822014-10-02 09:38:39 -07001949 */
1950 public Connection onCreateUnknownConnection(PhoneAccountHandle connectionManagerPhoneAccount,
1951 ConnectionRequest request) {
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001952 return null;
Yorke Leec3cf9822014-10-02 09:38:39 -07001953 }
1954
1955 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07001956 * Conference two specified connections. Invoked when the user has made a request to merge the
1957 * specified connections into a conference call. In response, the connection service should
1958 * create an instance of {@link Conference} and pass it into {@link #addConference}.
Santos Cordonb6939982014-06-04 20:20:58 -07001959 *
Santos Cordon823fd3c2014-08-07 18:35:18 -07001960 * @param connection1 A connection to merge into a conference call.
1961 * @param connection2 A connection to merge into a conference call.
Santos Cordonb6939982014-06-04 20:20:58 -07001962 */
Santos Cordon823fd3c2014-08-07 18:35:18 -07001963 public void onConference(Connection connection1, Connection connection2) {}
Santos Cordonb6939982014-06-04 20:20:58 -07001964
Santos Cordona663f862014-10-29 13:49:58 -07001965 /**
1966 * Indicates that a remote conference has been created for existing {@link RemoteConnection}s.
1967 * When this method is invoked, this {@link ConnectionService} should create its own
1968 * representation of the conference call and send it to telecom using {@link #addConference}.
1969 * <p>
1970 * This is only relevant to {@link ConnectionService}s which are registered with
1971 * {@link PhoneAccount#CAPABILITY_CONNECTION_MANAGER}.
1972 *
1973 * @param conference The remote conference call.
1974 */
Ihab Awadb8e85c72014-08-23 20:34:57 -07001975 public void onRemoteConferenceAdded(RemoteConference conference) {}
1976
Santos Cordon823fd3c2014-08-07 18:35:18 -07001977 /**
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07001978 * Called when an existing connection is added remotely.
1979 * @param connection The existing connection which was added.
1980 */
1981 public void onRemoteExistingConnectionAdded(RemoteConnection connection) {}
1982
1983 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07001984 * @hide
1985 */
1986 public boolean containsConference(Conference conference) {
1987 return mIdByConference.containsKey(conference);
1988 }
1989
Ihab Awadb8e85c72014-08-23 20:34:57 -07001990 /** {@hide} */
1991 void addRemoteConference(RemoteConference remoteConference) {
1992 onRemoteConferenceAdded(remoteConference);
1993 }
1994
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07001995 /** {@hide} */
1996 void addRemoteExistingConnection(RemoteConnection remoteConnection) {
1997 onRemoteExistingConnectionAdded(remoteConnection);
1998 }
1999
Ihab Awad5d0410f2014-07-30 10:07:40 -07002000 private void onAccountsInitialized() {
2001 mAreAccountsInitialized = true;
2002 for (Runnable r : mPreInitializationConnectionRequests) {
2003 r.run();
2004 }
2005 mPreInitializationConnectionRequests.clear();
2006 }
2007
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002008 /**
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002009 * Adds an existing connection to the list of connections, identified by a new call ID unique
2010 * to this connection service.
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002011 *
2012 * @param connection The connection.
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002013 * @return The ID of the connection (e.g. the call-id).
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002014 */
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002015 private String addExistingConnectionInternal(PhoneAccountHandle handle, Connection connection) {
2016 String id;
Tyler Gunncd6ccfd2016-10-17 15:48:19 -07002017
2018 if (connection.getExtras() != null && connection.getExtras()
2019 .containsKey(Connection.EXTRA_ORIGINAL_CONNECTION_ID)) {
2020 id = connection.getExtras().getString(Connection.EXTRA_ORIGINAL_CONNECTION_ID);
2021 Log.d(this, "addExistingConnectionInternal - conn %s reusing original id %s",
2022 connection.getTelecomCallId(), id);
2023 } else if (handle == null) {
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002024 // If no phone account handle was provided, we cannot be sure the call ID is unique,
2025 // so just use a random UUID.
2026 id = UUID.randomUUID().toString();
2027 } else {
2028 // Phone account handle was provided, so use the ConnectionService class name as a
2029 // prefix for a unique incremental call ID.
2030 id = handle.getComponentName().getClassName() + "@" + getNextCallId();
2031 }
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002032 addConnection(id, connection);
2033 return id;
2034 }
2035
Ihab Awad542e0ea2014-05-16 10:22:16 -07002036 private void addConnection(String callId, Connection connection) {
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002037 connection.setTelecomCallId(callId);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002038 mConnectionById.put(callId, connection);
2039 mIdByConnection.put(connection, callId);
2040 connection.addConnectionListener(mConnectionListener);
Santos Cordon823fd3c2014-08-07 18:35:18 -07002041 connection.setConnectionService(this);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002042 }
2043
Anthony Lee30e65842014-11-06 16:30:53 -08002044 /** {@hide} */
2045 protected void removeConnection(Connection connection) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07002046 connection.unsetConnectionService(this);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002047 connection.removeConnectionListener(mConnectionListener);
Chenjie Luoe370b532016-05-12 16:59:43 -07002048 String id = mIdByConnection.get(connection);
2049 if (id != null) {
2050 mConnectionById.remove(id);
2051 mIdByConnection.remove(connection);
2052 mAdapter.removeCall(id);
2053 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002054 }
2055
Santos Cordon823fd3c2014-08-07 18:35:18 -07002056 private String addConferenceInternal(Conference conference) {
Tyler Gunncd6ccfd2016-10-17 15:48:19 -07002057 String originalId = null;
2058 if (conference.getExtras() != null && conference.getExtras()
2059 .containsKey(Connection.EXTRA_ORIGINAL_CONNECTION_ID)) {
2060 originalId = conference.getExtras().getString(Connection.EXTRA_ORIGINAL_CONNECTION_ID);
2061 Log.d(this, "addConferenceInternal: conf %s reusing original id %s",
2062 conference.getTelecomCallId(),
2063 originalId);
2064 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07002065 if (mIdByConference.containsKey(conference)) {
2066 Log.w(this, "Re-adding an existing conference: %s.", conference);
2067 } else if (conference != null) {
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002068 // Conferences do not (yet) have a PhoneAccountHandle associated with them, so we
2069 // cannot determine a ConnectionService class name to associate with the ID, so use
2070 // a unique UUID (for now).
Tyler Gunncd6ccfd2016-10-17 15:48:19 -07002071 String id = originalId == null ? UUID.randomUUID().toString() : originalId;
Santos Cordon823fd3c2014-08-07 18:35:18 -07002072 mConferenceById.put(id, conference);
2073 mIdByConference.put(conference, id);
2074 conference.addListener(mConferenceListener);
2075 return id;
2076 }
2077
2078 return null;
2079 }
2080
2081 private void removeConference(Conference conference) {
2082 if (mIdByConference.containsKey(conference)) {
2083 conference.removeListener(mConferenceListener);
2084
2085 String id = mIdByConference.get(conference);
2086 mConferenceById.remove(id);
2087 mIdByConference.remove(conference);
2088 mAdapter.removeCall(id);
2089 }
2090 }
2091
Ihab Awad542e0ea2014-05-16 10:22:16 -07002092 private Connection findConnectionForAction(String callId, String action) {
2093 if (mConnectionById.containsKey(callId)) {
2094 return mConnectionById.get(callId);
2095 }
Ihab Awad60ac30b2014-05-20 22:32:12 -07002096 Log.w(this, "%s - Cannot find Connection %s", action, callId);
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07002097 return getNullConnection();
2098 }
2099
2100 static synchronized Connection getNullConnection() {
2101 if (sNullConnection == null) {
2102 sNullConnection = new Connection() {};
2103 }
2104 return sNullConnection;
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002105 }
Santos Cordon0159ac02014-08-21 14:28:11 -07002106
2107 private Conference findConferenceForAction(String conferenceId, String action) {
2108 if (mConferenceById.containsKey(conferenceId)) {
2109 return mConferenceById.get(conferenceId);
2110 }
2111 Log.w(this, "%s - Cannot find conference %s", action, conferenceId);
2112 return getNullConference();
2113 }
2114
Ihab Awadb8e85c72014-08-23 20:34:57 -07002115 private List<String> createConnectionIdList(List<Connection> connections) {
2116 List<String> ids = new ArrayList<>();
2117 for (Connection c : connections) {
2118 if (mIdByConnection.containsKey(c)) {
2119 ids.add(mIdByConnection.get(c));
2120 }
2121 }
2122 Collections.sort(ids);
2123 return ids;
2124 }
2125
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002126 /**
2127 * Builds a list of {@link Connection} and {@link Conference} IDs based on the list of
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002128 * {@link Conferenceable}s passed in.
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002129 *
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002130 * @param conferenceables The {@link Conferenceable} connections and conferences.
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002131 * @return List of string conference and call Ids.
2132 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002133 private List<String> createIdList(List<Conferenceable> conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002134 List<String> ids = new ArrayList<>();
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002135 for (Conferenceable c : conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002136 // Only allow Connection and Conference conferenceables.
2137 if (c instanceof Connection) {
2138 Connection connection = (Connection) c;
2139 if (mIdByConnection.containsKey(connection)) {
2140 ids.add(mIdByConnection.get(connection));
2141 }
2142 } else if (c instanceof Conference) {
2143 Conference conference = (Conference) c;
2144 if (mIdByConference.containsKey(conference)) {
2145 ids.add(mIdByConference.get(conference));
2146 }
2147 }
2148 }
2149 Collections.sort(ids);
2150 return ids;
2151 }
2152
Santos Cordon0159ac02014-08-21 14:28:11 -07002153 private Conference getNullConference() {
2154 if (sNullConference == null) {
2155 sNullConference = new Conference(null) {};
2156 }
2157 return sNullConference;
2158 }
Santos Cordon29f2f2e2014-09-11 19:50:24 -07002159
2160 private void endAllConnections() {
2161 // Unbound from telecomm. We should end all connections and conferences.
2162 for (Connection connection : mIdByConnection.keySet()) {
2163 // only operate on top-level calls. Conference calls will be removed on their own.
2164 if (connection.getConference() == null) {
2165 connection.onDisconnect();
2166 }
2167 }
2168 for (Conference conference : mIdByConference.keySet()) {
2169 conference.onDisconnect();
2170 }
2171 }
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002172
2173 /**
2174 * Retrieves the next call ID as maintainted by the connection service.
2175 *
2176 * @return The call ID.
2177 */
2178 private int getNextCallId() {
Brad Ebingerb32d4f82016-10-24 16:40:49 -07002179 synchronized (mIdSyncRoot) {
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002180 return ++mId;
2181 }
2182 }
Santos Cordon980acb92014-05-31 10:31:19 -07002183}