blob: 6f742e99c52f28ff89b21cb7adbf41f1c57dd7c8 [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
Ihab Awad542e0ea2014-05-16 10:22:16 -070095 // Flag controlling whether PII is emitted into the logs
Ihab Awad60ac30b2014-05-20 22:32:12 -070096 private static final boolean PII_DEBUG = Log.isLoggable(android.util.Log.DEBUG);
Ihab Awad542e0ea2014-05-16 10:22:16 -070097
Brad Ebingerb32d4f82016-10-24 16:40:49 -070098 // Session Definitions
99 private static final String SESSION_HANDLER = "H.";
100 private static final String SESSION_ADD_CS_ADAPTER = "CS.aCSA";
101 private static final String SESSION_REMOVE_CS_ADAPTER = "CS.rCSA";
102 private static final String SESSION_CREATE_CONN = "CS.crCo";
Tyler Gunnd104a4f2017-05-12 10:04:49 -0700103 private static final String SESSION_CREATE_CONN_COMPLETE = "CS.crCoC";
Tyler Gunn44e01912017-01-31 10:49:05 -0800104 private static final String SESSION_CREATE_CONN_FAILED = "CS.crCoF";
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700105 private static final String SESSION_ABORT = "CS.ab";
106 private static final String SESSION_ANSWER = "CS.an";
107 private static final String SESSION_ANSWER_VIDEO = "CS.anV";
108 private static final String SESSION_REJECT = "CS.r";
109 private static final String SESSION_REJECT_MESSAGE = "CS.rWM";
110 private static final String SESSION_SILENCE = "CS.s";
111 private static final String SESSION_DISCONNECT = "CS.d";
112 private static final String SESSION_HOLD = "CS.h";
113 private static final String SESSION_UNHOLD = "CS.u";
114 private static final String SESSION_CALL_AUDIO_SC = "CS.cASC";
115 private static final String SESSION_PLAY_DTMF = "CS.pDT";
116 private static final String SESSION_STOP_DTMF = "CS.sDT";
117 private static final String SESSION_CONFERENCE = "CS.c";
118 private static final String SESSION_SPLIT_CONFERENCE = "CS.sFC";
119 private static final String SESSION_MERGE_CONFERENCE = "CS.mC";
120 private static final String SESSION_SWAP_CONFERENCE = "CS.sC";
121 private static final String SESSION_POST_DIAL_CONT = "CS.oPDC";
122 private static final String SESSION_PULL_EXTERNAL_CALL = "CS.pEC";
123 private static final String SESSION_SEND_CALL_EVENT = "CS.sCE";
124 private static final String SESSION_EXTRAS_CHANGED = "CS.oEC";
Hall Liub64ac4c2017-02-06 10:49:48 -0800125 private static final String SESSION_START_RTT = "CS.+RTT";
126 private static final String SESSION_STOP_RTT = "CS.-RTT";
127 private static final String SESSION_RTT_UPGRADE_RESPONSE = "CS.rTRUR";
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700128
Ihab Awad8aecfed2014-08-08 17:06:11 -0700129 private static final int MSG_ADD_CONNECTION_SERVICE_ADAPTER = 1;
Sailesh Nepalc5b01572014-07-14 16:29:44 -0700130 private static final int MSG_CREATE_CONNECTION = 2;
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700131 private static final int MSG_ABORT = 3;
Sailesh Nepalc5b01572014-07-14 16:29:44 -0700132 private static final int MSG_ANSWER = 4;
133 private static final int MSG_REJECT = 5;
134 private static final int MSG_DISCONNECT = 6;
135 private static final int MSG_HOLD = 7;
136 private static final int MSG_UNHOLD = 8;
Yorke Lee4af59352015-05-13 14:14:54 -0700137 private static final int MSG_ON_CALL_AUDIO_STATE_CHANGED = 9;
Sailesh Nepalc5b01572014-07-14 16:29:44 -0700138 private static final int MSG_PLAY_DTMF_TONE = 10;
139 private static final int MSG_STOP_DTMF_TONE = 11;
140 private static final int MSG_CONFERENCE = 12;
141 private static final int MSG_SPLIT_FROM_CONFERENCE = 13;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700142 private static final int MSG_ON_POST_DIAL_CONTINUE = 14;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700143 private static final int MSG_REMOVE_CONNECTION_SERVICE_ADAPTER = 16;
Tyler Gunnbe74de02014-08-29 14:51:48 -0700144 private static final int MSG_ANSWER_VIDEO = 17;
Santos Cordona4868042014-09-04 17:39:22 -0700145 private static final int MSG_MERGE_CONFERENCE = 18;
146 private static final int MSG_SWAP_CONFERENCE = 19;
Bryce Lee81901682015-08-28 16:38:02 -0700147 private static final int MSG_REJECT_WITH_MESSAGE = 20;
Bryce Leecac50772015-11-17 15:13:29 -0800148 private static final int MSG_SILENCE = 21;
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700149 private static final int MSG_PULL_EXTERNAL_CALL = 22;
150 private static final int MSG_SEND_CALL_EVENT = 23;
Tyler Gunndee56a82016-03-23 16:06:34 -0700151 private static final int MSG_ON_EXTRAS_CHANGED = 24;
Tyler Gunn44e01912017-01-31 10:49:05 -0800152 private static final int MSG_CREATE_CONNECTION_FAILED = 25;
Hall Liub64ac4c2017-02-06 10:49:48 -0800153 private static final int MSG_ON_START_RTT = 26;
154 private static final int MSG_ON_STOP_RTT = 27;
155 private static final int MSG_RTT_UPGRADE_RESPONSE = 28;
Tyler Gunnd104a4f2017-05-12 10:04:49 -0700156 private static final int MSG_CREATE_CONNECTION_COMPLETE = 29;
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700157
Sailesh Nepalcf7020b2014-08-20 10:07:19 -0700158 private static Connection sNullConnection;
159
mike dooley95e80702014-09-18 14:07:52 -0700160 private final Map<String, Connection> mConnectionById = new ConcurrentHashMap<>();
161 private final Map<Connection, String> mIdByConnection = new ConcurrentHashMap<>();
162 private final Map<String, Conference> mConferenceById = new ConcurrentHashMap<>();
163 private final Map<Conference, String> mIdByConference = new ConcurrentHashMap<>();
Ihab Awadb8e85c72014-08-23 20:34:57 -0700164 private final RemoteConnectionManager mRemoteConnectionManager =
165 new RemoteConnectionManager(this);
Ihab Awad5d0410f2014-07-30 10:07:40 -0700166 private final List<Runnable> mPreInitializationConnectionRequests = new ArrayList<>();
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700167 private final ConnectionServiceAdapter mAdapter = new ConnectionServiceAdapter();
Ihab Awad542e0ea2014-05-16 10:22:16 -0700168
Santos Cordon823fd3c2014-08-07 18:35:18 -0700169 private boolean mAreAccountsInitialized = false;
Santos Cordon0159ac02014-08-21 14:28:11 -0700170 private Conference sNullConference;
Tyler Gunnf0500bd2015-09-01 10:59:48 -0700171 private Object mIdSyncRoot = new Object();
172 private int mId = 0;
Santos Cordon823fd3c2014-08-07 18:35:18 -0700173
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700174 private final IBinder mBinder = new IConnectionService.Stub() {
175 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700176 public void addConnectionServiceAdapter(IConnectionServiceAdapter adapter,
177 Session.Info sessionInfo) {
178 Log.startSession(sessionInfo, SESSION_ADD_CS_ADAPTER);
179 try {
180 SomeArgs args = SomeArgs.obtain();
181 args.arg1 = adapter;
182 args.arg2 = Log.createSubsession();
183 mHandler.obtainMessage(MSG_ADD_CONNECTION_SERVICE_ADAPTER, args).sendToTarget();
184 } finally {
185 Log.endSession();
186 }
Ihab Awad8aecfed2014-08-08 17:06:11 -0700187 }
188
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700189 public void removeConnectionServiceAdapter(IConnectionServiceAdapter adapter,
190 Session.Info sessionInfo) {
191 Log.startSession(sessionInfo, SESSION_REMOVE_CS_ADAPTER);
192 try {
193 SomeArgs args = SomeArgs.obtain();
194 args.arg1 = adapter;
195 args.arg2 = Log.createSubsession();
196 mHandler.obtainMessage(MSG_REMOVE_CONNECTION_SERVICE_ADAPTER, args).sendToTarget();
197 } finally {
198 Log.endSession();
199 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700200 }
201
202 @Override
Ihab Awadf8b69882014-07-25 15:14:01 -0700203 public void createConnection(
204 PhoneAccountHandle connectionManagerPhoneAccount,
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700205 String id,
Ihab Awadf8b69882014-07-25 15:14:01 -0700206 ConnectionRequest request,
Yorke Leec3cf9822014-10-02 09:38:39 -0700207 boolean isIncoming,
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700208 boolean isUnknown,
209 Session.Info sessionInfo) {
210 Log.startSession(sessionInfo, SESSION_CREATE_CONN);
211 try {
212 SomeArgs args = SomeArgs.obtain();
213 args.arg1 = connectionManagerPhoneAccount;
214 args.arg2 = id;
215 args.arg3 = request;
216 args.arg4 = Log.createSubsession();
217 args.argi1 = isIncoming ? 1 : 0;
218 args.argi2 = isUnknown ? 1 : 0;
219 mHandler.obtainMessage(MSG_CREATE_CONNECTION, args).sendToTarget();
220 } finally {
221 Log.endSession();
222 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700223 }
224
225 @Override
Tyler Gunnd104a4f2017-05-12 10:04:49 -0700226 public void createConnectionComplete(String id, Session.Info sessionInfo) {
227 Log.startSession(sessionInfo, SESSION_CREATE_CONN_COMPLETE);
228 try {
229 SomeArgs args = SomeArgs.obtain();
230 args.arg1 = id;
231 args.arg2 = Log.createSubsession();
232 mHandler.obtainMessage(MSG_CREATE_CONNECTION_COMPLETE, args).sendToTarget();
233 } finally {
234 Log.endSession();
235 }
236 }
237
238 @Override
Tyler Gunn44e01912017-01-31 10:49:05 -0800239 public void createConnectionFailed(
Tyler Gunn159f35c2017-03-02 09:28:37 -0800240 PhoneAccountHandle connectionManagerPhoneAccount,
Tyler Gunn44e01912017-01-31 10:49:05 -0800241 String callId,
242 ConnectionRequest request,
243 boolean isIncoming,
244 Session.Info sessionInfo) {
245 Log.startSession(sessionInfo, SESSION_CREATE_CONN_FAILED);
246 try {
247 SomeArgs args = SomeArgs.obtain();
248 args.arg1 = callId;
249 args.arg2 = request;
250 args.arg3 = Log.createSubsession();
Tyler Gunn159f35c2017-03-02 09:28:37 -0800251 args.arg4 = connectionManagerPhoneAccount;
Tyler Gunn44e01912017-01-31 10:49:05 -0800252 args.argi1 = isIncoming ? 1 : 0;
253 mHandler.obtainMessage(MSG_CREATE_CONNECTION_FAILED, args).sendToTarget();
254 } finally {
255 Log.endSession();
256 }
257 }
258
259 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700260 public void abort(String callId, Session.Info sessionInfo) {
261 Log.startSession(sessionInfo, SESSION_ABORT);
262 try {
263 SomeArgs args = SomeArgs.obtain();
264 args.arg1 = callId;
265 args.arg2 = Log.createSubsession();
266 mHandler.obtainMessage(MSG_ABORT, args).sendToTarget();
267 } finally {
268 Log.endSession();
269 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700270 }
271
272 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700273 public void answerVideo(String callId, int videoState, Session.Info sessionInfo) {
274 Log.startSession(sessionInfo, SESSION_ANSWER_VIDEO);
275 try {
276 SomeArgs args = SomeArgs.obtain();
277 args.arg1 = callId;
278 args.arg2 = Log.createSubsession();
279 args.argi1 = videoState;
280 mHandler.obtainMessage(MSG_ANSWER_VIDEO, args).sendToTarget();
281 } finally {
282 Log.endSession();
283 }
Tyler Gunnbe74de02014-08-29 14:51:48 -0700284 }
285
286 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700287 public void answer(String callId, Session.Info sessionInfo) {
288 Log.startSession(sessionInfo, SESSION_ANSWER);
289 try {
290 SomeArgs args = SomeArgs.obtain();
291 args.arg1 = callId;
292 args.arg2 = Log.createSubsession();
293 mHandler.obtainMessage(MSG_ANSWER, args).sendToTarget();
294 } finally {
295 Log.endSession();
296 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700297 }
298
299 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700300 public void reject(String callId, Session.Info sessionInfo) {
301 Log.startSession(sessionInfo, SESSION_REJECT);
302 try {
303 SomeArgs args = SomeArgs.obtain();
304 args.arg1 = callId;
305 args.arg2 = Log.createSubsession();
306 mHandler.obtainMessage(MSG_REJECT, args).sendToTarget();
307 } finally {
308 Log.endSession();
309 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700310 }
311
312 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700313 public void rejectWithMessage(String callId, String message, Session.Info sessionInfo) {
314 Log.startSession(sessionInfo, SESSION_REJECT_MESSAGE);
315 try {
316 SomeArgs args = SomeArgs.obtain();
317 args.arg1 = callId;
318 args.arg2 = message;
319 args.arg3 = Log.createSubsession();
320 mHandler.obtainMessage(MSG_REJECT_WITH_MESSAGE, args).sendToTarget();
321 } finally {
322 Log.endSession();
323 }
Bryce Lee81901682015-08-28 16:38:02 -0700324 }
325
326 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700327 public void silence(String callId, Session.Info sessionInfo) {
328 Log.startSession(sessionInfo, SESSION_SILENCE);
329 try {
330 SomeArgs args = SomeArgs.obtain();
331 args.arg1 = callId;
332 args.arg2 = Log.createSubsession();
333 mHandler.obtainMessage(MSG_SILENCE, args).sendToTarget();
334 } finally {
335 Log.endSession();
336 }
Bryce Leecac50772015-11-17 15:13:29 -0800337 }
338
339 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700340 public void disconnect(String callId, Session.Info sessionInfo) {
341 Log.startSession(sessionInfo, SESSION_DISCONNECT);
342 try {
343 SomeArgs args = SomeArgs.obtain();
344 args.arg1 = callId;
345 args.arg2 = Log.createSubsession();
346 mHandler.obtainMessage(MSG_DISCONNECT, args).sendToTarget();
347 } finally {
348 Log.endSession();
349 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700350 }
351
352 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700353 public void hold(String callId, Session.Info sessionInfo) {
354 Log.startSession(sessionInfo, SESSION_HOLD);
355 try {
356 SomeArgs args = SomeArgs.obtain();
357 args.arg1 = callId;
358 args.arg2 = Log.createSubsession();
359 mHandler.obtainMessage(MSG_HOLD, args).sendToTarget();
360 } finally {
361 Log.endSession();
362 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700363 }
364
365 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700366 public void unhold(String callId, Session.Info sessionInfo) {
367 Log.startSession(sessionInfo, SESSION_UNHOLD);
368 try {
369 SomeArgs args = SomeArgs.obtain();
370 args.arg1 = callId;
371 args.arg2 = Log.createSubsession();
372 mHandler.obtainMessage(MSG_UNHOLD, args).sendToTarget();
373 } finally {
374 Log.endSession();
375 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700376 }
377
378 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700379 public void onCallAudioStateChanged(String callId, CallAudioState callAudioState,
380 Session.Info sessionInfo) {
381 Log.startSession(sessionInfo, SESSION_CALL_AUDIO_SC);
382 try {
383 SomeArgs args = SomeArgs.obtain();
384 args.arg1 = callId;
385 args.arg2 = callAudioState;
386 args.arg3 = Log.createSubsession();
387 mHandler.obtainMessage(MSG_ON_CALL_AUDIO_STATE_CHANGED, args).sendToTarget();
388 } finally {
389 Log.endSession();
390 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700391 }
392
393 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700394 public void playDtmfTone(String callId, char digit, Session.Info sessionInfo) {
395 Log.startSession(sessionInfo, SESSION_PLAY_DTMF);
396 try {
397 SomeArgs args = SomeArgs.obtain();
398 args.arg1 = digit;
399 args.arg2 = callId;
400 args.arg3 = Log.createSubsession();
401 mHandler.obtainMessage(MSG_PLAY_DTMF_TONE, args).sendToTarget();
402 } finally {
403 Log.endSession();
404 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700405 }
406
407 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700408 public void stopDtmfTone(String callId, Session.Info sessionInfo) {
409 Log.startSession(sessionInfo, SESSION_STOP_DTMF);
410 try {
411 SomeArgs args = SomeArgs.obtain();
412 args.arg1 = callId;
413 args.arg2 = Log.createSubsession();
414 mHandler.obtainMessage(MSG_STOP_DTMF_TONE, args).sendToTarget();
415 } finally {
416 Log.endSession();
417 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700418 }
419
420 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700421 public void conference(String callId1, String callId2, Session.Info sessionInfo) {
422 Log.startSession(sessionInfo, SESSION_CONFERENCE);
423 try {
424 SomeArgs args = SomeArgs.obtain();
425 args.arg1 = callId1;
426 args.arg2 = callId2;
427 args.arg3 = Log.createSubsession();
428 mHandler.obtainMessage(MSG_CONFERENCE, args).sendToTarget();
429 } finally {
430 Log.endSession();
431 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700432 }
433
434 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700435 public void splitFromConference(String callId, Session.Info sessionInfo) {
436 Log.startSession(sessionInfo, SESSION_SPLIT_CONFERENCE);
437 try {
438 SomeArgs args = SomeArgs.obtain();
439 args.arg1 = callId;
440 args.arg2 = Log.createSubsession();
441 mHandler.obtainMessage(MSG_SPLIT_FROM_CONFERENCE, args).sendToTarget();
442 } finally {
443 Log.endSession();
444 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700445 }
446
447 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700448 public void mergeConference(String callId, Session.Info sessionInfo) {
449 Log.startSession(sessionInfo, SESSION_MERGE_CONFERENCE);
450 try {
451 SomeArgs args = SomeArgs.obtain();
452 args.arg1 = callId;
453 args.arg2 = Log.createSubsession();
454 mHandler.obtainMessage(MSG_MERGE_CONFERENCE, args).sendToTarget();
455 } finally {
456 Log.endSession();
457 }
Santos Cordona4868042014-09-04 17:39:22 -0700458 }
459
460 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700461 public void swapConference(String callId, Session.Info sessionInfo) {
462 Log.startSession(sessionInfo, SESSION_SWAP_CONFERENCE);
463 try {
464 SomeArgs args = SomeArgs.obtain();
465 args.arg1 = callId;
466 args.arg2 = Log.createSubsession();
467 mHandler.obtainMessage(MSG_SWAP_CONFERENCE, args).sendToTarget();
468 } finally {
469 Log.endSession();
470 }
Santos Cordona4868042014-09-04 17:39:22 -0700471 }
472
473 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700474 public void onPostDialContinue(String callId, boolean proceed, Session.Info sessionInfo) {
475 Log.startSession(sessionInfo, SESSION_POST_DIAL_CONT);
476 try {
477 SomeArgs args = SomeArgs.obtain();
478 args.arg1 = callId;
479 args.arg2 = Log.createSubsession();
480 args.argi1 = proceed ? 1 : 0;
481 mHandler.obtainMessage(MSG_ON_POST_DIAL_CONTINUE, args).sendToTarget();
482 } finally {
483 Log.endSession();
484 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700485 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700486
487 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700488 public void pullExternalCall(String callId, Session.Info sessionInfo) {
489 Log.startSession(sessionInfo, SESSION_PULL_EXTERNAL_CALL);
490 try {
491 SomeArgs args = SomeArgs.obtain();
492 args.arg1 = callId;
493 args.arg2 = Log.createSubsession();
494 mHandler.obtainMessage(MSG_PULL_EXTERNAL_CALL, args).sendToTarget();
495 } finally {
496 Log.endSession();
497 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700498 }
499
500 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700501 public void sendCallEvent(String callId, String event, Bundle extras,
502 Session.Info sessionInfo) {
503 Log.startSession(sessionInfo, SESSION_SEND_CALL_EVENT);
504 try {
505 SomeArgs args = SomeArgs.obtain();
506 args.arg1 = callId;
507 args.arg2 = event;
508 args.arg3 = extras;
509 args.arg4 = Log.createSubsession();
510 mHandler.obtainMessage(MSG_SEND_CALL_EVENT, args).sendToTarget();
511 } finally {
512 Log.endSession();
513 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700514 }
Tyler Gunndee56a82016-03-23 16:06:34 -0700515
516 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700517 public void onExtrasChanged(String callId, Bundle extras, Session.Info sessionInfo) {
518 Log.startSession(sessionInfo, SESSION_EXTRAS_CHANGED);
519 try {
520 SomeArgs args = SomeArgs.obtain();
521 args.arg1 = callId;
522 args.arg2 = extras;
523 args.arg3 = Log.createSubsession();
524 mHandler.obtainMessage(MSG_ON_EXTRAS_CHANGED, args).sendToTarget();
525 } finally {
526 Log.endSession();
527 }
Tyler Gunndee56a82016-03-23 16:06:34 -0700528 }
Hall Liub64ac4c2017-02-06 10:49:48 -0800529
530 @Override
531 public void startRtt(String callId, ParcelFileDescriptor fromInCall,
532 ParcelFileDescriptor toInCall, Session.Info sessionInfo) throws RemoteException {
533 Log.startSession(sessionInfo, SESSION_START_RTT);
534 try {
535 SomeArgs args = SomeArgs.obtain();
536 args.arg1 = callId;
537 args.arg2 = new Connection.RttTextStream(toInCall, fromInCall);
538 args.arg3 = Log.createSubsession();
539 mHandler.obtainMessage(MSG_ON_START_RTT, args).sendToTarget();
540 } finally {
541 Log.endSession();
542 }
543 }
544
545 @Override
546 public void stopRtt(String callId, Session.Info sessionInfo) throws RemoteException {
547 Log.startSession(sessionInfo, SESSION_STOP_RTT);
548 try {
549 SomeArgs args = SomeArgs.obtain();
550 args.arg1 = callId;
551 args.arg2 = Log.createSubsession();
552 mHandler.obtainMessage(MSG_ON_STOP_RTT, args).sendToTarget();
553 } finally {
554 Log.endSession();
555 }
556 }
557
558 @Override
559 public void respondToRttUpgradeRequest(String callId, ParcelFileDescriptor fromInCall,
560 ParcelFileDescriptor toInCall, Session.Info sessionInfo) throws RemoteException {
561 Log.startSession(sessionInfo, SESSION_RTT_UPGRADE_RESPONSE);
562 try {
563 SomeArgs args = SomeArgs.obtain();
564 args.arg1 = callId;
565 if (toInCall == null || fromInCall == null) {
566 args.arg2 = null;
567 } else {
568 args.arg2 = new Connection.RttTextStream(toInCall, fromInCall);
569 }
570 args.arg3 = Log.createSubsession();
571 mHandler.obtainMessage(MSG_RTT_UPGRADE_RESPONSE, args).sendToTarget();
572 } finally {
573 Log.endSession();
574 }
575 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700576 };
577
578 private final Handler mHandler = new Handler(Looper.getMainLooper()) {
579 @Override
580 public void handleMessage(Message msg) {
581 switch (msg.what) {
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700582 case MSG_ADD_CONNECTION_SERVICE_ADAPTER: {
583 SomeArgs args = (SomeArgs) msg.obj;
584 try {
585 IConnectionServiceAdapter adapter = (IConnectionServiceAdapter) args.arg1;
586 Log.continueSession((Session) args.arg2,
587 SESSION_HANDLER + SESSION_ADD_CS_ADAPTER);
588 mAdapter.addAdapter(adapter);
589 onAdapterAttached();
590 } finally {
591 args.recycle();
592 Log.endSession();
593 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700594 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700595 }
596 case MSG_REMOVE_CONNECTION_SERVICE_ADAPTER: {
597 SomeArgs args = (SomeArgs) msg.obj;
598 try {
599 Log.continueSession((Session) args.arg2,
600 SESSION_HANDLER + SESSION_REMOVE_CS_ADAPTER);
601 mAdapter.removeAdapter((IConnectionServiceAdapter) args.arg1);
602 } finally {
603 args.recycle();
604 Log.endSession();
605 }
Ihab Awad8aecfed2014-08-08 17:06:11 -0700606 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700607 }
Ihab Awadf8b69882014-07-25 15:14:01 -0700608 case MSG_CREATE_CONNECTION: {
609 SomeArgs args = (SomeArgs) msg.obj;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700610 Log.continueSession((Session) args.arg4, SESSION_HANDLER + SESSION_CREATE_CONN);
Ihab Awadf8b69882014-07-25 15:14:01 -0700611 try {
Ihab Awad5d0410f2014-07-30 10:07:40 -0700612 final PhoneAccountHandle connectionManagerPhoneAccount =
Ihab Awadf8b69882014-07-25 15:14:01 -0700613 (PhoneAccountHandle) args.arg1;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700614 final String id = (String) args.arg2;
615 final ConnectionRequest request = (ConnectionRequest) args.arg3;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700616 final boolean isIncoming = args.argi1 == 1;
Yorke Leec3cf9822014-10-02 09:38:39 -0700617 final boolean isUnknown = args.argi2 == 1;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700618 if (!mAreAccountsInitialized) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700619 Log.d(this, "Enqueueing pre-init request %s", id);
Brad Ebinger0c3541b2016-11-01 14:11:38 -0700620 mPreInitializationConnectionRequests.add(
621 new android.telecom.Logging.Runnable(
622 SESSION_HANDLER + SESSION_CREATE_CONN + ".pICR",
623 null /*lock*/) {
Ihab Awad5d0410f2014-07-30 10:07:40 -0700624 @Override
Brad Ebinger0c3541b2016-11-01 14:11:38 -0700625 public void loggedRun() {
Ihab Awad5d0410f2014-07-30 10:07:40 -0700626 createConnection(
627 connectionManagerPhoneAccount,
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700628 id,
Ihab Awad5d0410f2014-07-30 10:07:40 -0700629 request,
Yorke Leec3cf9822014-10-02 09:38:39 -0700630 isIncoming,
631 isUnknown);
Ihab Awad5d0410f2014-07-30 10:07:40 -0700632 }
Brad Ebinger0c3541b2016-11-01 14:11:38 -0700633 }.prepare());
Ihab Awad5d0410f2014-07-30 10:07:40 -0700634 } else {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700635 createConnection(
636 connectionManagerPhoneAccount,
637 id,
638 request,
Yorke Leec3cf9822014-10-02 09:38:39 -0700639 isIncoming,
640 isUnknown);
Ihab Awad5d0410f2014-07-30 10:07:40 -0700641 }
Ihab Awadf8b69882014-07-25 15:14:01 -0700642 } finally {
643 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700644 Log.endSession();
Ihab Awadf8b69882014-07-25 15:14:01 -0700645 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700646 break;
Ihab Awadf8b69882014-07-25 15:14:01 -0700647 }
Tyler Gunnd104a4f2017-05-12 10:04:49 -0700648 case MSG_CREATE_CONNECTION_COMPLETE: {
649 SomeArgs args = (SomeArgs) msg.obj;
650 Log.continueSession((Session) args.arg2,
651 SESSION_HANDLER + SESSION_CREATE_CONN_COMPLETE);
652 try {
653 final String id = (String) args.arg1;
654 if (!mAreAccountsInitialized) {
655 Log.d(this, "Enqueueing pre-init request %s", id);
656 mPreInitializationConnectionRequests.add(
657 new android.telecom.Logging.Runnable(
658 SESSION_HANDLER + SESSION_CREATE_CONN_COMPLETE
659 + ".pICR",
660 null /*lock*/) {
661 @Override
662 public void loggedRun() {
663 notifyCreateConnectionComplete(id);
664 }
665 }.prepare());
666 } else {
667 notifyCreateConnectionComplete(id);
668 }
669 } finally {
670 args.recycle();
671 Log.endSession();
672 }
673 break;
674 }
Tyler Gunn44e01912017-01-31 10:49:05 -0800675 case MSG_CREATE_CONNECTION_FAILED: {
676 SomeArgs args = (SomeArgs) msg.obj;
677 Log.continueSession((Session) args.arg3, SESSION_HANDLER +
678 SESSION_CREATE_CONN_FAILED);
679 try {
680 final String id = (String) args.arg1;
681 final ConnectionRequest request = (ConnectionRequest) args.arg2;
682 final boolean isIncoming = args.argi1 == 1;
Tyler Gunn159f35c2017-03-02 09:28:37 -0800683 final PhoneAccountHandle connectionMgrPhoneAccount =
684 (PhoneAccountHandle) args.arg4;
Tyler Gunn44e01912017-01-31 10:49:05 -0800685 if (!mAreAccountsInitialized) {
686 Log.d(this, "Enqueueing pre-init request %s", id);
687 mPreInitializationConnectionRequests.add(
688 new android.telecom.Logging.Runnable(
689 SESSION_HANDLER + SESSION_CREATE_CONN_FAILED + ".pICR",
690 null /*lock*/) {
691 @Override
692 public void loggedRun() {
Tyler Gunn159f35c2017-03-02 09:28:37 -0800693 createConnectionFailed(connectionMgrPhoneAccount, id,
694 request, isIncoming);
Tyler Gunn44e01912017-01-31 10:49:05 -0800695 }
696 }.prepare());
697 } else {
698 Log.i(this, "createConnectionFailed %s", id);
Tyler Gunn159f35c2017-03-02 09:28:37 -0800699 createConnectionFailed(connectionMgrPhoneAccount, id, request,
700 isIncoming);
Tyler Gunn44e01912017-01-31 10:49:05 -0800701 }
702 } finally {
703 args.recycle();
704 Log.endSession();
705 }
706 break;
707 }
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700708 case MSG_ABORT: {
709 SomeArgs args = (SomeArgs) msg.obj;
710 Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_ABORT);
711 try {
712 abort((String) args.arg1);
713 } finally {
714 args.recycle();
715 Log.endSession();
716 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700717 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700718 }
719 case MSG_ANSWER: {
720 SomeArgs args = (SomeArgs) msg.obj;
721 Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_ANSWER);
722 try {
723 answer((String) args.arg1);
724 } finally {
725 args.recycle();
726 Log.endSession();
727 }
Tyler Gunnbe74de02014-08-29 14:51:48 -0700728 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700729 }
Tyler Gunnbe74de02014-08-29 14:51:48 -0700730 case MSG_ANSWER_VIDEO: {
Andrew Lee8da4c3c2014-07-16 10:11:42 -0700731 SomeArgs args = (SomeArgs) msg.obj;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700732 Log.continueSession((Session) args.arg2,
733 SESSION_HANDLER + SESSION_ANSWER_VIDEO);
Andrew Lee8da4c3c2014-07-16 10:11:42 -0700734 try {
735 String callId = (String) args.arg1;
Evan Charltonbf11f982014-07-20 22:06:28 -0700736 int videoState = args.argi1;
Tyler Gunnbe74de02014-08-29 14:51:48 -0700737 answerVideo(callId, videoState);
Andrew Lee8da4c3c2014-07-16 10:11:42 -0700738 } finally {
739 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700740 Log.endSession();
Andrew Lee8da4c3c2014-07-16 10:11:42 -0700741 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700742 break;
Andrew Lee8da4c3c2014-07-16 10:11:42 -0700743 }
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700744 case MSG_REJECT: {
745 SomeArgs args = (SomeArgs) msg.obj;
746 Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_REJECT);
747 try {
748 reject((String) args.arg1);
749 } finally {
750 args.recycle();
751 Log.endSession();
752 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700753 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700754 }
Bryce Lee81901682015-08-28 16:38:02 -0700755 case MSG_REJECT_WITH_MESSAGE: {
756 SomeArgs args = (SomeArgs) msg.obj;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700757 Log.continueSession((Session) args.arg3,
758 SESSION_HANDLER + SESSION_REJECT_MESSAGE);
Bryce Lee81901682015-08-28 16:38:02 -0700759 try {
760 reject((String) args.arg1, (String) args.arg2);
761 } finally {
762 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700763 Log.endSession();
Bryce Lee81901682015-08-28 16:38:02 -0700764 }
765 break;
766 }
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700767 case MSG_DISCONNECT: {
768 SomeArgs args = (SomeArgs) msg.obj;
769 Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_DISCONNECT);
770 try {
771 disconnect((String) args.arg1);
772 } finally {
773 args.recycle();
774 Log.endSession();
775 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700776 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700777 }
778 case MSG_SILENCE: {
779 SomeArgs args = (SomeArgs) msg.obj;
780 Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_SILENCE);
781 try {
782 silence((String) args.arg1);
783 } finally {
784 args.recycle();
785 Log.endSession();
786 }
Bryce Leecac50772015-11-17 15:13:29 -0800787 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700788 }
789 case MSG_HOLD: {
790 SomeArgs args = (SomeArgs) msg.obj;
791 Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_REJECT);
792 try {
793 hold((String) args.arg1);
794 } finally {
795 args.recycle();
796 Log.endSession();
797 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700798 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700799 }
800 case MSG_UNHOLD: {
801 SomeArgs args = (SomeArgs) msg.obj;
802 Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_UNHOLD);
803 try {
804 unhold((String) args.arg1);
805 } finally {
806 args.recycle();
807 Log.endSession();
808 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700809 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700810 }
Yorke Lee4af59352015-05-13 14:14:54 -0700811 case MSG_ON_CALL_AUDIO_STATE_CHANGED: {
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700812 SomeArgs args = (SomeArgs) msg.obj;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700813 Log.continueSession((Session) args.arg3,
814 SESSION_HANDLER + SESSION_CALL_AUDIO_SC);
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700815 try {
816 String callId = (String) args.arg1;
Yorke Lee4af59352015-05-13 14:14:54 -0700817 CallAudioState audioState = (CallAudioState) args.arg2;
818 onCallAudioStateChanged(callId, new CallAudioState(audioState));
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700819 } finally {
820 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700821 Log.endSession();
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700822 }
823 break;
824 }
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700825 case MSG_PLAY_DTMF_TONE: {
826 SomeArgs args = (SomeArgs) msg.obj;
827 try {
828 Log.continueSession((Session) args.arg3,
829 SESSION_HANDLER + SESSION_PLAY_DTMF);
830 playDtmfTone((String) args.arg2, (char) args.arg1);
831 } finally {
832 args.recycle();
833 Log.endSession();
834 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700835 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700836 }
837 case MSG_STOP_DTMF_TONE: {
838 SomeArgs args = (SomeArgs) msg.obj;
839 try {
840 Log.continueSession((Session) args.arg2,
841 SESSION_HANDLER + SESSION_STOP_DTMF);
842 stopDtmfTone((String) args.arg1);
843 } finally {
844 args.recycle();
845 Log.endSession();
846 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700847 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700848 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700849 case MSG_CONFERENCE: {
850 SomeArgs args = (SomeArgs) msg.obj;
851 try {
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700852 Log.continueSession((Session) args.arg3,
853 SESSION_HANDLER + SESSION_CONFERENCE);
Santos Cordon823fd3c2014-08-07 18:35:18 -0700854 String callId1 = (String) args.arg1;
855 String callId2 = (String) args.arg2;
856 conference(callId1, callId2);
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700857 } finally {
858 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700859 Log.endSession();
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700860 }
861 break;
862 }
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700863 case MSG_SPLIT_FROM_CONFERENCE: {
864 SomeArgs args = (SomeArgs) msg.obj;
865 try {
866 Log.continueSession((Session) args.arg2,
867 SESSION_HANDLER + SESSION_SPLIT_CONFERENCE);
868 splitFromConference((String) args.arg1);
869 } finally {
870 args.recycle();
871 Log.endSession();
872 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700873 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700874 }
875 case MSG_MERGE_CONFERENCE: {
876 SomeArgs args = (SomeArgs) msg.obj;
877 try {
878 Log.continueSession((Session) args.arg2,
879 SESSION_HANDLER + SESSION_MERGE_CONFERENCE);
880 mergeConference((String) args.arg1);
881 } finally {
882 args.recycle();
883 Log.endSession();
884 }
Santos Cordona4868042014-09-04 17:39:22 -0700885 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700886 }
887 case MSG_SWAP_CONFERENCE: {
888 SomeArgs args = (SomeArgs) msg.obj;
889 try {
890 Log.continueSession((Session) args.arg2,
891 SESSION_HANDLER + SESSION_SWAP_CONFERENCE);
892 swapConference((String) args.arg1);
893 } finally {
894 args.recycle();
895 Log.endSession();
896 }
Santos Cordona4868042014-09-04 17:39:22 -0700897 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700898 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700899 case MSG_ON_POST_DIAL_CONTINUE: {
900 SomeArgs args = (SomeArgs) msg.obj;
901 try {
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700902 Log.continueSession((Session) args.arg2,
903 SESSION_HANDLER + SESSION_POST_DIAL_CONT);
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700904 String callId = (String) args.arg1;
905 boolean proceed = (args.argi1 == 1);
906 onPostDialContinue(callId, proceed);
907 } finally {
908 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700909 Log.endSession();
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700910 }
911 break;
912 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700913 case MSG_PULL_EXTERNAL_CALL: {
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700914 SomeArgs args = (SomeArgs) msg.obj;
915 try {
916 Log.continueSession((Session) args.arg2,
917 SESSION_HANDLER + SESSION_PULL_EXTERNAL_CALL);
918 pullExternalCall((String) args.arg1);
919 } finally {
920 args.recycle();
921 Log.endSession();
922 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700923 break;
924 }
925 case MSG_SEND_CALL_EVENT: {
926 SomeArgs args = (SomeArgs) msg.obj;
927 try {
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700928 Log.continueSession((Session) args.arg4,
929 SESSION_HANDLER + SESSION_SEND_CALL_EVENT);
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700930 String callId = (String) args.arg1;
931 String event = (String) args.arg2;
932 Bundle extras = (Bundle) args.arg3;
933 sendCallEvent(callId, event, extras);
934 } finally {
935 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700936 Log.endSession();
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700937 }
938 break;
939 }
Tyler Gunndee56a82016-03-23 16:06:34 -0700940 case MSG_ON_EXTRAS_CHANGED: {
941 SomeArgs args = (SomeArgs) msg.obj;
942 try {
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700943 Log.continueSession((Session) args.arg3,
944 SESSION_HANDLER + SESSION_EXTRAS_CHANGED);
Tyler Gunndee56a82016-03-23 16:06:34 -0700945 String callId = (String) args.arg1;
946 Bundle extras = (Bundle) args.arg2;
947 handleExtrasChanged(callId, extras);
948 } finally {
949 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700950 Log.endSession();
Tyler Gunndee56a82016-03-23 16:06:34 -0700951 }
952 break;
953 }
Hall Liub64ac4c2017-02-06 10:49:48 -0800954 case MSG_ON_START_RTT: {
955 SomeArgs args = (SomeArgs) msg.obj;
956 try {
957 Log.continueSession((Session) args.arg3,
958 SESSION_HANDLER + SESSION_START_RTT);
959 String callId = (String) args.arg1;
960 Connection.RttTextStream rttTextStream =
961 (Connection.RttTextStream) args.arg2;
962 startRtt(callId, rttTextStream);
963 } finally {
964 args.recycle();
965 Log.endSession();
966 }
967 break;
968 }
969 case MSG_ON_STOP_RTT: {
970 SomeArgs args = (SomeArgs) msg.obj;
971 try {
972 Log.continueSession((Session) args.arg2,
973 SESSION_HANDLER + SESSION_STOP_RTT);
974 String callId = (String) args.arg1;
975 stopRtt(callId);
976 } finally {
977 args.recycle();
978 Log.endSession();
979 }
980 break;
981 }
982 case MSG_RTT_UPGRADE_RESPONSE: {
983 SomeArgs args = (SomeArgs) msg.obj;
984 try {
985 Log.continueSession((Session) args.arg3,
986 SESSION_HANDLER + SESSION_RTT_UPGRADE_RESPONSE);
987 String callId = (String) args.arg1;
988 Connection.RttTextStream rttTextStream =
989 (Connection.RttTextStream) args.arg2;
990 handleRttUpgradeResponse(callId, rttTextStream);
991 } finally {
992 args.recycle();
993 Log.endSession();
994 }
995 break;
996 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700997 default:
998 break;
999 }
1000 }
1001 };
1002
Santos Cordon823fd3c2014-08-07 18:35:18 -07001003 private final Conference.Listener mConferenceListener = new Conference.Listener() {
1004 @Override
1005 public void onStateChanged(Conference conference, int oldState, int newState) {
1006 String id = mIdByConference.get(conference);
1007 switch (newState) {
1008 case Connection.STATE_ACTIVE:
1009 mAdapter.setActive(id);
1010 break;
1011 case Connection.STATE_HOLDING:
1012 mAdapter.setOnHold(id);
1013 break;
1014 case Connection.STATE_DISCONNECTED:
1015 // handled by onDisconnected
1016 break;
1017 }
1018 }
1019
1020 @Override
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001021 public void onDisconnected(Conference conference, DisconnectCause disconnectCause) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07001022 String id = mIdByConference.get(conference);
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001023 mAdapter.setDisconnected(id, disconnectCause);
Santos Cordon823fd3c2014-08-07 18:35:18 -07001024 }
1025
1026 @Override
1027 public void onConnectionAdded(Conference conference, Connection connection) {
1028 }
1029
1030 @Override
1031 public void onConnectionRemoved(Conference conference, Connection connection) {
1032 }
1033
1034 @Override
Ihab Awad50e35062014-09-30 09:17:03 -07001035 public void onConferenceableConnectionsChanged(
1036 Conference conference, List<Connection> conferenceableConnections) {
1037 mAdapter.setConferenceableConnections(
1038 mIdByConference.get(conference),
1039 createConnectionIdList(conferenceableConnections));
1040 }
1041
1042 @Override
Santos Cordon823fd3c2014-08-07 18:35:18 -07001043 public void onDestroyed(Conference conference) {
1044 removeConference(conference);
1045 }
1046
1047 @Override
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001048 public void onConnectionCapabilitiesChanged(
1049 Conference conference,
1050 int connectionCapabilities) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07001051 String id = mIdByConference.get(conference);
1052 Log.d(this, "call capabilities: conference: %s",
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001053 Connection.capabilitiesToString(connectionCapabilities));
1054 mAdapter.setConnectionCapabilities(id, connectionCapabilities);
Santos Cordon823fd3c2014-08-07 18:35:18 -07001055 }
Rekha Kumar07366812015-03-24 16:42:31 -07001056
1057 @Override
Tyler Gunn720c6642016-03-22 09:02:47 -07001058 public void onConnectionPropertiesChanged(
1059 Conference conference,
1060 int connectionProperties) {
1061 String id = mIdByConference.get(conference);
1062 Log.d(this, "call capabilities: conference: %s",
1063 Connection.propertiesToString(connectionProperties));
1064 mAdapter.setConnectionProperties(id, connectionProperties);
1065 }
1066
1067 @Override
Rekha Kumar07366812015-03-24 16:42:31 -07001068 public void onVideoStateChanged(Conference c, int videoState) {
1069 String id = mIdByConference.get(c);
1070 Log.d(this, "onVideoStateChanged set video state %d", videoState);
1071 mAdapter.setVideoState(id, videoState);
1072 }
1073
1074 @Override
1075 public void onVideoProviderChanged(Conference c, Connection.VideoProvider videoProvider) {
1076 String id = mIdByConference.get(c);
1077 Log.d(this, "onVideoProviderChanged: Connection: %s, VideoProvider: %s", c,
1078 videoProvider);
1079 mAdapter.setVideoProvider(id, videoProvider);
1080 }
Andrew Lee0f51da32015-04-16 13:11:55 -07001081
1082 @Override
Andrew Leeedc625f2015-04-14 13:38:12 -07001083 public void onStatusHintsChanged(Conference conference, StatusHints statusHints) {
1084 String id = mIdByConference.get(conference);
Tyler Gunndee56a82016-03-23 16:06:34 -07001085 if (id != null) {
1086 mAdapter.setStatusHints(id, statusHints);
1087 }
Andrew Leeedc625f2015-04-14 13:38:12 -07001088 }
Santos Cordon6b7f9552015-05-27 17:21:45 -07001089
1090 @Override
Tyler Gunndee56a82016-03-23 16:06:34 -07001091 public void onExtrasChanged(Conference c, Bundle extras) {
1092 String id = mIdByConference.get(c);
1093 if (id != null) {
1094 mAdapter.putExtras(id, extras);
1095 }
1096 }
1097
1098 @Override
1099 public void onExtrasRemoved(Conference c, List<String> keys) {
1100 String id = mIdByConference.get(c);
1101 if (id != null) {
1102 mAdapter.removeExtras(id, keys);
1103 }
Santos Cordon6b7f9552015-05-27 17:21:45 -07001104 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07001105 };
1106
Ihab Awad542e0ea2014-05-16 10:22:16 -07001107 private final Connection.Listener mConnectionListener = new Connection.Listener() {
1108 @Override
1109 public void onStateChanged(Connection c, int state) {
1110 String id = mIdByConnection.get(c);
Ihab Awad42b30e12014-05-22 09:49:34 -07001111 Log.d(this, "Adapter set state %s %s", id, Connection.stateToString(state));
Ihab Awad542e0ea2014-05-16 10:22:16 -07001112 switch (state) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001113 case Connection.STATE_ACTIVE:
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001114 mAdapter.setActive(id);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001115 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001116 case Connection.STATE_DIALING:
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001117 mAdapter.setDialing(id);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001118 break;
Tyler Gunnc96b5e02016-07-07 22:53:57 -07001119 case Connection.STATE_PULLING_CALL:
1120 mAdapter.setPulling(id);
1121 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001122 case Connection.STATE_DISCONNECTED:
Ihab Awad542e0ea2014-05-16 10:22:16 -07001123 // Handled in onDisconnected()
1124 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001125 case Connection.STATE_HOLDING:
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001126 mAdapter.setOnHold(id);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001127 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001128 case Connection.STATE_NEW:
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001129 // Nothing to tell Telecom
Ihab Awad542e0ea2014-05-16 10:22:16 -07001130 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001131 case Connection.STATE_RINGING:
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001132 mAdapter.setRinging(id);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001133 break;
1134 }
1135 }
1136
1137 @Override
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001138 public void onDisconnected(Connection c, DisconnectCause disconnectCause) {
Ihab Awad542e0ea2014-05-16 10:22:16 -07001139 String id = mIdByConnection.get(c);
Andrew Lee26786392014-09-16 18:14:59 -07001140 Log.d(this, "Adapter set disconnected %s", disconnectCause);
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001141 mAdapter.setDisconnected(id, disconnectCause);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001142 }
1143
1144 @Override
Tyler Gunnaa07df82014-07-17 07:50:22 -07001145 public void onVideoStateChanged(Connection c, int videoState) {
1146 String id = mIdByConnection.get(c);
1147 Log.d(this, "Adapter set video state %d", videoState);
1148 mAdapter.setVideoState(id, videoState);
1149 }
1150
1151 @Override
Andrew Lee100e2932014-09-08 15:34:24 -07001152 public void onAddressChanged(Connection c, Uri address, int presentation) {
Sailesh Nepal61203862014-07-11 14:50:13 -07001153 String id = mIdByConnection.get(c);
Andrew Lee100e2932014-09-08 15:34:24 -07001154 mAdapter.setAddress(id, address, presentation);
Sailesh Nepal61203862014-07-11 14:50:13 -07001155 }
1156
1157 @Override
1158 public void onCallerDisplayNameChanged(
1159 Connection c, String callerDisplayName, int presentation) {
1160 String id = mIdByConnection.get(c);
1161 mAdapter.setCallerDisplayName(id, callerDisplayName, presentation);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001162 }
1163
1164 @Override
Ihab Awad542e0ea2014-05-16 10:22:16 -07001165 public void onDestroyed(Connection c) {
1166 removeConnection(c);
1167 }
Ihab Awadf8358972014-05-28 16:46:42 -07001168
1169 @Override
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001170 public void onPostDialWait(Connection c, String remaining) {
Sailesh Nepal091768c2014-06-30 15:15:23 -07001171 String id = mIdByConnection.get(c);
1172 Log.d(this, "Adapter onPostDialWait %s, %s", c, remaining);
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001173 mAdapter.onPostDialWait(id, remaining);
Sailesh Nepal091768c2014-06-30 15:15:23 -07001174 }
1175
1176 @Override
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001177 public void onPostDialChar(Connection c, char nextChar) {
1178 String id = mIdByConnection.get(c);
1179 Log.d(this, "Adapter onPostDialChar %s, %s", c, nextChar);
1180 mAdapter.onPostDialChar(id, nextChar);
1181 }
1182
1183 @Override
Andrew Lee100e2932014-09-08 15:34:24 -07001184 public void onRingbackRequested(Connection c, boolean ringback) {
Ihab Awadf8358972014-05-28 16:46:42 -07001185 String id = mIdByConnection.get(c);
1186 Log.d(this, "Adapter onRingback %b", ringback);
Andrew Lee100e2932014-09-08 15:34:24 -07001187 mAdapter.setRingbackRequested(id, ringback);
Ihab Awadf8358972014-05-28 16:46:42 -07001188 }
Santos Cordonb6939982014-06-04 20:20:58 -07001189
1190 @Override
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001191 public void onConnectionCapabilitiesChanged(Connection c, int capabilities) {
Santos Cordonb6939982014-06-04 20:20:58 -07001192 String id = mIdByConnection.get(c);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001193 Log.d(this, "capabilities: parcelableconnection: %s",
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001194 Connection.capabilitiesToString(capabilities));
1195 mAdapter.setConnectionCapabilities(id, capabilities);
Santos Cordonb6939982014-06-04 20:20:58 -07001196 }
1197
Santos Cordonb6939982014-06-04 20:20:58 -07001198 @Override
Tyler Gunn720c6642016-03-22 09:02:47 -07001199 public void onConnectionPropertiesChanged(Connection c, int properties) {
1200 String id = mIdByConnection.get(c);
1201 Log.d(this, "properties: parcelableconnection: %s",
1202 Connection.propertiesToString(properties));
1203 mAdapter.setConnectionProperties(id, properties);
1204 }
1205
1206 @Override
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001207 public void onVideoProviderChanged(Connection c, Connection.VideoProvider videoProvider) {
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07001208 String id = mIdByConnection.get(c);
Rekha Kumar07366812015-03-24 16:42:31 -07001209 Log.d(this, "onVideoProviderChanged: Connection: %s, VideoProvider: %s", c,
1210 videoProvider);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001211 mAdapter.setVideoProvider(id, videoProvider);
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07001212 }
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001213
1214 @Override
Sailesh Nepal001bbbb2014-07-15 14:40:39 -07001215 public void onAudioModeIsVoipChanged(Connection c, boolean isVoip) {
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001216 String id = mIdByConnection.get(c);
Andrew Lee100e2932014-09-08 15:34:24 -07001217 mAdapter.setIsVoipAudioMode(id, isVoip);
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001218 }
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001219
1220 @Override
Sailesh Nepal001bbbb2014-07-15 14:40:39 -07001221 public void onStatusHintsChanged(Connection c, StatusHints statusHints) {
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001222 String id = mIdByConnection.get(c);
1223 mAdapter.setStatusHints(id, statusHints);
1224 }
Sailesh Nepal2ab88cc2014-07-18 14:49:18 -07001225
1226 @Override
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001227 public void onConferenceablesChanged(
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001228 Connection connection, List<Conferenceable> conferenceables) {
Ihab Awadb8e85c72014-08-23 20:34:57 -07001229 mAdapter.setConferenceableConnections(
1230 mIdByConnection.get(connection),
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001231 createIdList(conferenceables));
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001232 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07001233
1234 @Override
1235 public void onConferenceChanged(Connection connection, Conference conference) {
1236 String id = mIdByConnection.get(connection);
1237 if (id != null) {
1238 String conferenceId = null;
1239 if (conference != null) {
1240 conferenceId = mIdByConference.get(conference);
1241 }
1242 mAdapter.setIsConferenced(id, conferenceId);
1243 }
1244 }
Anthony Lee17455a32015-04-24 15:25:29 -07001245
1246 @Override
1247 public void onConferenceMergeFailed(Connection connection) {
1248 String id = mIdByConnection.get(connection);
1249 if (id != null) {
1250 mAdapter.onConferenceMergeFailed(id);
1251 }
1252 }
Santos Cordon6b7f9552015-05-27 17:21:45 -07001253
1254 @Override
Tyler Gunndee56a82016-03-23 16:06:34 -07001255 public void onExtrasChanged(Connection c, Bundle extras) {
1256 String id = mIdByConnection.get(c);
Santos Cordon6b7f9552015-05-27 17:21:45 -07001257 if (id != null) {
Tyler Gunndee56a82016-03-23 16:06:34 -07001258 mAdapter.putExtras(id, extras);
Santos Cordon6b7f9552015-05-27 17:21:45 -07001259 }
1260 }
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001261
Tyler Gunnf5035432017-01-09 09:43:12 -08001262 @Override
Tyler Gunndee56a82016-03-23 16:06:34 -07001263 public void onExtrasRemoved(Connection c, List<String> keys) {
1264 String id = mIdByConnection.get(c);
1265 if (id != null) {
1266 mAdapter.removeExtras(id, keys);
1267 }
1268 }
1269
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08001270 @Override
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001271 public void onConnectionEvent(Connection connection, String event, Bundle extras) {
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08001272 String id = mIdByConnection.get(connection);
1273 if (id != null) {
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001274 mAdapter.onConnectionEvent(id, event, extras);
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08001275 }
1276 }
Tyler Gunnf5035432017-01-09 09:43:12 -08001277
1278 @Override
1279 public void onAudioRouteChanged(Connection c, int audioRoute) {
1280 String id = mIdByConnection.get(c);
1281 if (id != null) {
1282 mAdapter.setAudioRoute(id, audioRoute);
1283 }
1284 }
Hall Liub64ac4c2017-02-06 10:49:48 -08001285
1286 @Override
1287 public void onRttInitiationSuccess(Connection c) {
1288 String id = mIdByConnection.get(c);
1289 if (id != null) {
1290 mAdapter.onRttInitiationSuccess(id);
1291 }
1292 }
1293
1294 @Override
1295 public void onRttInitiationFailure(Connection c, int reason) {
1296 String id = mIdByConnection.get(c);
1297 if (id != null) {
1298 mAdapter.onRttInitiationFailure(id, reason);
1299 }
1300 }
1301
1302 @Override
1303 public void onRttSessionRemotelyTerminated(Connection c) {
1304 String id = mIdByConnection.get(c);
1305 if (id != null) {
1306 mAdapter.onRttSessionRemotelyTerminated(id);
1307 }
1308 }
1309
1310 @Override
1311 public void onRemoteRttRequest(Connection c) {
1312 String id = mIdByConnection.get(c);
1313 if (id != null) {
1314 mAdapter.onRemoteRttRequest(id);
1315 }
1316 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001317 };
1318
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001319 /** {@inheritDoc} */
Ihab Awad542e0ea2014-05-16 10:22:16 -07001320 @Override
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001321 public final IBinder onBind(Intent intent) {
1322 return mBinder;
1323 }
1324
Santos Cordon29f2f2e2014-09-11 19:50:24 -07001325 /** {@inheritDoc} */
1326 @Override
1327 public boolean onUnbind(Intent intent) {
1328 endAllConnections();
1329 return super.onUnbind(intent);
1330 }
1331
Sailesh Nepalc5b01572014-07-14 16:29:44 -07001332 /**
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001333 * This can be used by telecom to either create a new outgoing call or attach to an existing
1334 * incoming call. In either case, telecom will cycle through a set of services and call
Sailesh Nepalc5b01572014-07-14 16:29:44 -07001335 * createConnection util a connection service cancels the process or completes it successfully.
1336 */
Ihab Awadf8b69882014-07-25 15:14:01 -07001337 private void createConnection(
1338 final PhoneAccountHandle callManagerAccount,
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001339 final String callId,
Ihab Awadf8b69882014-07-25 15:14:01 -07001340 final ConnectionRequest request,
Yorke Leec3cf9822014-10-02 09:38:39 -07001341 boolean isIncoming,
1342 boolean isUnknown) {
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001343 Log.d(this, "createConnection, callManagerAccount: %s, callId: %s, request: %s, " +
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001344 "isIncoming: %b, isUnknown: %b", callManagerAccount, callId, request,
1345 isIncoming,
Yorke Leec3cf9822014-10-02 09:38:39 -07001346 isUnknown);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001347
Yorke Leec3cf9822014-10-02 09:38:39 -07001348 Connection connection = isUnknown ? onCreateUnknownConnection(callManagerAccount, request)
1349 : isIncoming ? onCreateIncomingConnection(callManagerAccount, request)
Ihab Awad6107bab2014-08-18 09:23:25 -07001350 : onCreateOutgoingConnection(callManagerAccount, request);
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001351 Log.d(this, "createConnection, connection: %s", connection);
1352 if (connection == null) {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001353 connection = Connection.createFailedConnection(
1354 new DisconnectCause(DisconnectCause.ERROR));
Sailesh Nepalc5b01572014-07-14 16:29:44 -07001355 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001356
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001357 connection.setTelecomCallId(callId);
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001358 if (connection.getState() != Connection.STATE_DISCONNECTED) {
Ihab Awad6107bab2014-08-18 09:23:25 -07001359 addConnection(callId, connection);
1360 }
1361
Andrew Lee100e2932014-09-08 15:34:24 -07001362 Uri address = connection.getAddress();
1363 String number = address == null ? "null" : address.getSchemeSpecificPart();
Tyler Gunn720c6642016-03-22 09:02:47 -07001364 Log.v(this, "createConnection, number: %s, state: %s, capabilities: %s, properties: %s",
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001365 Connection.toLogSafePhoneNumber(number),
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001366 Connection.stateToString(connection.getState()),
Tyler Gunn720c6642016-03-22 09:02:47 -07001367 Connection.capabilitiesToString(connection.getConnectionCapabilities()),
1368 Connection.propertiesToString(connection.getConnectionProperties()));
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001369
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001370 Log.d(this, "createConnection, calling handleCreateConnectionSuccessful %s", callId);
Ihab Awad6107bab2014-08-18 09:23:25 -07001371 mAdapter.handleCreateConnectionComplete(
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001372 callId,
Evan Charltonbf11f982014-07-20 22:06:28 -07001373 request,
1374 new ParcelableConnection(
1375 request.getAccountHandle(),
1376 connection.getState(),
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001377 connection.getConnectionCapabilities(),
Tyler Gunn720c6642016-03-22 09:02:47 -07001378 connection.getConnectionProperties(),
Christine Hallstrom2830ce92016-11-30 16:06:42 -08001379 connection.getSupportedAudioRoutes(),
Andrew Lee100e2932014-09-08 15:34:24 -07001380 connection.getAddress(),
1381 connection.getAddressPresentation(),
Evan Charltonbf11f982014-07-20 22:06:28 -07001382 connection.getCallerDisplayName(),
1383 connection.getCallerDisplayNamePresentation(),
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001384 connection.getVideoProvider() == null ?
1385 null : connection.getVideoProvider().getInterface(),
Sailesh Nepal8b9d3ca2014-08-14 17:39:34 -07001386 connection.getVideoState(),
Andrew Lee100e2932014-09-08 15:34:24 -07001387 connection.isRingbackRequested(),
Sailesh Nepal8b9d3ca2014-08-14 17:39:34 -07001388 connection.getAudioModeIsVoip(),
Roshan Piuse927ec02015-07-15 15:47:21 -07001389 connection.getConnectTimeMillis(),
Ihab Awad6107bab2014-08-18 09:23:25 -07001390 connection.getStatusHints(),
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001391 connection.getDisconnectCause(),
Santos Cordon6b7f9552015-05-27 17:21:45 -07001392 createIdList(connection.getConferenceables()),
1393 connection.getExtras()));
Tyler Gunnf5035432017-01-09 09:43:12 -08001394
1395 if (isIncoming && request.shouldShowIncomingCallUi() &&
1396 (connection.getConnectionProperties() & Connection.PROPERTY_SELF_MANAGED) ==
1397 Connection.PROPERTY_SELF_MANAGED) {
1398 // Tell ConnectionService to show its incoming call UX.
1399 connection.onShowIncomingCallUi();
1400 }
Shriram Ganesh6bf35ac2014-12-11 17:53:38 -08001401 if (isUnknown) {
1402 triggerConferenceRecalculate();
1403 }
Evan Charltonbf11f982014-07-20 22:06:28 -07001404 }
1405
Tyler Gunn159f35c2017-03-02 09:28:37 -08001406 private void createConnectionFailed(final PhoneAccountHandle callManagerAccount,
1407 final String callId, final ConnectionRequest request,
1408 boolean isIncoming) {
Tyler Gunn44e01912017-01-31 10:49:05 -08001409
1410 Log.i(this, "createConnectionFailed %s", callId);
1411 if (isIncoming) {
Tyler Gunn159f35c2017-03-02 09:28:37 -08001412 onCreateIncomingConnectionFailed(callManagerAccount, request);
Tyler Gunn44e01912017-01-31 10:49:05 -08001413 } else {
Tyler Gunn159f35c2017-03-02 09:28:37 -08001414 onCreateOutgoingConnectionFailed(callManagerAccount, request);
Tyler Gunn44e01912017-01-31 10:49:05 -08001415 }
1416 }
1417
Tyler Gunnd104a4f2017-05-12 10:04:49 -07001418 /**
1419 * Called by Telecom when the creation of a new Connection has completed and it is now added
1420 * to Telecom.
1421 * @param callId The ID of the connection.
1422 */
1423 private void notifyCreateConnectionComplete(final String callId) {
1424 Log.i(this, "notifyCreateConnectionComplete %s", callId);
1425 onCreateConnectionComplete(findConnectionForAction(callId,
1426 "notifyCreateConnectionComplete"));
1427 }
1428
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001429 private void abort(String callId) {
Ihab Awad60ac30b2014-05-20 22:32:12 -07001430 Log.d(this, "abort %s", callId);
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001431 findConnectionForAction(callId, "abort").onAbort();
Ihab Awad542e0ea2014-05-16 10:22:16 -07001432 }
1433
Tyler Gunnbe74de02014-08-29 14:51:48 -07001434 private void answerVideo(String callId, int videoState) {
1435 Log.d(this, "answerVideo %s", callId);
Andrew Lee8da4c3c2014-07-16 10:11:42 -07001436 findConnectionForAction(callId, "answer").onAnswer(videoState);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001437 }
1438
Tyler Gunnbe74de02014-08-29 14:51:48 -07001439 private void answer(String callId) {
1440 Log.d(this, "answer %s", callId);
1441 findConnectionForAction(callId, "answer").onAnswer();
1442 }
1443
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001444 private void reject(String callId) {
Ihab Awad60ac30b2014-05-20 22:32:12 -07001445 Log.d(this, "reject %s", callId);
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001446 findConnectionForAction(callId, "reject").onReject();
Ihab Awad542e0ea2014-05-16 10:22:16 -07001447 }
1448
Bryce Lee81901682015-08-28 16:38:02 -07001449 private void reject(String callId, String rejectWithMessage) {
1450 Log.d(this, "reject %s with message", callId);
1451 findConnectionForAction(callId, "reject").onReject(rejectWithMessage);
1452 }
1453
Bryce Leecac50772015-11-17 15:13:29 -08001454 private void silence(String callId) {
1455 Log.d(this, "silence %s", callId);
1456 findConnectionForAction(callId, "silence").onSilence();
1457 }
1458
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001459 private void disconnect(String callId) {
Ihab Awad60ac30b2014-05-20 22:32:12 -07001460 Log.d(this, "disconnect %s", callId);
Santos Cordon0159ac02014-08-21 14:28:11 -07001461 if (mConnectionById.containsKey(callId)) {
1462 findConnectionForAction(callId, "disconnect").onDisconnect();
1463 } else {
1464 findConferenceForAction(callId, "disconnect").onDisconnect();
1465 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001466 }
1467
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001468 private void hold(String callId) {
Ihab Awad60ac30b2014-05-20 22:32:12 -07001469 Log.d(this, "hold %s", callId);
Santos Cordon0159ac02014-08-21 14:28:11 -07001470 if (mConnectionById.containsKey(callId)) {
1471 findConnectionForAction(callId, "hold").onHold();
1472 } else {
1473 findConferenceForAction(callId, "hold").onHold();
1474 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001475 }
1476
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001477 private void unhold(String callId) {
Ihab Awad60ac30b2014-05-20 22:32:12 -07001478 Log.d(this, "unhold %s", callId);
Santos Cordon0159ac02014-08-21 14:28:11 -07001479 if (mConnectionById.containsKey(callId)) {
1480 findConnectionForAction(callId, "unhold").onUnhold();
1481 } else {
1482 findConferenceForAction(callId, "unhold").onUnhold();
1483 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001484 }
1485
Yorke Lee4af59352015-05-13 14:14:54 -07001486 private void onCallAudioStateChanged(String callId, CallAudioState callAudioState) {
1487 Log.d(this, "onAudioStateChanged %s %s", callId, callAudioState);
Yorke Leea0d3ca92014-09-15 19:18:13 -07001488 if (mConnectionById.containsKey(callId)) {
Yorke Lee4af59352015-05-13 14:14:54 -07001489 findConnectionForAction(callId, "onCallAudioStateChanged").setCallAudioState(
1490 callAudioState);
Yorke Leea0d3ca92014-09-15 19:18:13 -07001491 } else {
Yorke Lee4af59352015-05-13 14:14:54 -07001492 findConferenceForAction(callId, "onCallAudioStateChanged").setCallAudioState(
1493 callAudioState);
Yorke Leea0d3ca92014-09-15 19:18:13 -07001494 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001495 }
1496
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001497 private void playDtmfTone(String callId, char digit) {
1498 Log.d(this, "playDtmfTone %s %c", callId, digit);
Yorke Leea0d3ca92014-09-15 19:18:13 -07001499 if (mConnectionById.containsKey(callId)) {
1500 findConnectionForAction(callId, "playDtmfTone").onPlayDtmfTone(digit);
1501 } else {
1502 findConferenceForAction(callId, "playDtmfTone").onPlayDtmfTone(digit);
1503 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001504 }
1505
1506 private void stopDtmfTone(String callId) {
1507 Log.d(this, "stopDtmfTone %s", callId);
Yorke Leea0d3ca92014-09-15 19:18:13 -07001508 if (mConnectionById.containsKey(callId)) {
1509 findConnectionForAction(callId, "stopDtmfTone").onStopDtmfTone();
1510 } else {
1511 findConferenceForAction(callId, "stopDtmfTone").onStopDtmfTone();
1512 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001513 }
1514
Santos Cordon823fd3c2014-08-07 18:35:18 -07001515 private void conference(String callId1, String callId2) {
1516 Log.d(this, "conference %s, %s", callId1, callId2);
Santos Cordon980acb92014-05-31 10:31:19 -07001517
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001518 // Attempt to get second connection or conference.
Santos Cordon823fd3c2014-08-07 18:35:18 -07001519 Connection connection2 = findConnectionForAction(callId2, "conference");
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001520 Conference conference2 = getNullConference();
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001521 if (connection2 == getNullConnection()) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001522 conference2 = findConferenceForAction(callId2, "conference");
1523 if (conference2 == getNullConference()) {
1524 Log.w(this, "Connection2 or Conference2 missing in conference request %s.",
1525 callId2);
1526 return;
1527 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07001528 }
Santos Cordonb6939982014-06-04 20:20:58 -07001529
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001530 // Attempt to get first connection or conference and perform merge.
Ihab Awad50e35062014-09-30 09:17:03 -07001531 Connection connection1 = findConnectionForAction(callId1, "conference");
1532 if (connection1 == getNullConnection()) {
1533 Conference conference1 = findConferenceForAction(callId1, "addConnection");
1534 if (conference1 == getNullConference()) {
1535 Log.w(this,
1536 "Connection1 or Conference1 missing in conference request %s.",
1537 callId1);
1538 } else {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001539 // Call 1 is a conference.
1540 if (connection2 != getNullConnection()) {
1541 // Call 2 is a connection so merge via call 1 (conference).
1542 conference1.onMerge(connection2);
1543 } else {
1544 // Call 2 is ALSO a conference; this should never happen.
1545 Log.wtf(this, "There can only be one conference and an attempt was made to " +
1546 "merge two conferences.");
1547 return;
1548 }
Ihab Awad50e35062014-09-30 09:17:03 -07001549 }
1550 } else {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001551 // Call 1 is a connection.
1552 if (conference2 != getNullConference()) {
1553 // Call 2 is a conference, so merge via call 2.
1554 conference2.onMerge(connection1);
1555 } else {
1556 // Call 2 is a connection, so merge together.
1557 onConference(connection1, connection2);
1558 }
Ihab Awad50e35062014-09-30 09:17:03 -07001559 }
Santos Cordon980acb92014-05-31 10:31:19 -07001560 }
1561
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001562 private void splitFromConference(String callId) {
Santos Cordonb6939982014-06-04 20:20:58 -07001563 Log.d(this, "splitFromConference(%s)", callId);
Santos Cordon980acb92014-05-31 10:31:19 -07001564
1565 Connection connection = findConnectionForAction(callId, "splitFromConference");
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001566 if (connection == getNullConnection()) {
Santos Cordon980acb92014-05-31 10:31:19 -07001567 Log.w(this, "Connection missing in conference request %s.", callId);
1568 return;
1569 }
1570
Santos Cordon0159ac02014-08-21 14:28:11 -07001571 Conference conference = connection.getConference();
1572 if (conference != null) {
1573 conference.onSeparate(connection);
1574 }
Santos Cordon980acb92014-05-31 10:31:19 -07001575 }
1576
Santos Cordona4868042014-09-04 17:39:22 -07001577 private void mergeConference(String callId) {
1578 Log.d(this, "mergeConference(%s)", callId);
1579 Conference conference = findConferenceForAction(callId, "mergeConference");
1580 if (conference != null) {
1581 conference.onMerge();
1582 }
1583 }
1584
1585 private void swapConference(String callId) {
1586 Log.d(this, "swapConference(%s)", callId);
1587 Conference conference = findConferenceForAction(callId, "swapConference");
1588 if (conference != null) {
1589 conference.onSwap();
1590 }
1591 }
1592
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001593 /**
1594 * Notifies a {@link Connection} of a request to pull an external call.
1595 *
1596 * See {@link Call#pullExternalCall()}.
1597 *
1598 * @param callId The ID of the call to pull.
1599 */
1600 private void pullExternalCall(String callId) {
1601 Log.d(this, "pullExternalCall(%s)", callId);
1602 Connection connection = findConnectionForAction(callId, "pullExternalCall");
1603 if (connection != null) {
1604 connection.onPullExternalCall();
1605 }
1606 }
1607
1608 /**
1609 * Notifies a {@link Connection} of a call event.
1610 *
1611 * See {@link Call#sendCallEvent(String, Bundle)}.
1612 *
1613 * @param callId The ID of the call receiving the event.
1614 * @param event The event.
1615 * @param extras Extras associated with the event.
1616 */
1617 private void sendCallEvent(String callId, String event, Bundle extras) {
1618 Log.d(this, "sendCallEvent(%s, %s)", callId, event);
1619 Connection connection = findConnectionForAction(callId, "sendCallEvent");
1620 if (connection != null) {
1621 connection.onCallEvent(event, extras);
1622 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001623 }
1624
Tyler Gunndee56a82016-03-23 16:06:34 -07001625 /**
1626 * Notifies a {@link Connection} or {@link Conference} of a change to the extras from Telecom.
1627 * <p>
1628 * These extra changes can originate from Telecom itself, or from an {@link InCallService} via
1629 * the {@link android.telecom.Call#putExtra(String, boolean)},
1630 * {@link android.telecom.Call#putExtra(String, int)},
1631 * {@link android.telecom.Call#putExtra(String, String)},
1632 * {@link Call#removeExtras(List)}.
1633 *
1634 * @param callId The ID of the call receiving the event.
1635 * @param extras The new extras bundle.
1636 */
1637 private void handleExtrasChanged(String callId, Bundle extras) {
1638 Log.d(this, "handleExtrasChanged(%s, %s)", callId, extras);
1639 if (mConnectionById.containsKey(callId)) {
1640 findConnectionForAction(callId, "handleExtrasChanged").handleExtrasChanged(extras);
1641 } else if (mConferenceById.containsKey(callId)) {
1642 findConferenceForAction(callId, "handleExtrasChanged").handleExtrasChanged(extras);
1643 }
1644 }
1645
Hall Liub64ac4c2017-02-06 10:49:48 -08001646 private void startRtt(String callId, Connection.RttTextStream rttTextStream) {
1647 Log.d(this, "startRtt(%s)", callId);
1648 if (mConnectionById.containsKey(callId)) {
1649 findConnectionForAction(callId, "startRtt").onStartRtt(rttTextStream);
1650 } else if (mConferenceById.containsKey(callId)) {
1651 Log.w(this, "startRtt called on a conference.");
1652 }
1653 }
1654
1655 private void stopRtt(String callId) {
1656 Log.d(this, "stopRtt(%s)", callId);
1657 if (mConnectionById.containsKey(callId)) {
1658 findConnectionForAction(callId, "stopRtt").onStopRtt();
Hall Liuffa4a812017-03-02 16:11:00 -08001659 findConnectionForAction(callId, "stopRtt").unsetRttProperty();
Hall Liub64ac4c2017-02-06 10:49:48 -08001660 } else if (mConferenceById.containsKey(callId)) {
1661 Log.w(this, "stopRtt called on a conference.");
1662 }
1663 }
1664
1665 private void handleRttUpgradeResponse(String callId, Connection.RttTextStream rttTextStream) {
1666 Log.d(this, "handleRttUpgradeResponse(%s, %s)", callId, rttTextStream == null);
1667 if (mConnectionById.containsKey(callId)) {
1668 findConnectionForAction(callId, "handleRttUpgradeResponse")
1669 .handleRttUpgradeResponse(rttTextStream);
1670 } else if (mConferenceById.containsKey(callId)) {
1671 Log.w(this, "handleRttUpgradeResponse called on a conference.");
1672 }
1673 }
1674
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001675 private void onPostDialContinue(String callId, boolean proceed) {
Evan Charlton6dea4ac2014-06-03 14:07:13 -07001676 Log.d(this, "onPostDialContinue(%s)", callId);
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001677 findConnectionForAction(callId, "stopDtmfTone").onPostDialContinue(proceed);
Evan Charlton6dea4ac2014-06-03 14:07:13 -07001678 }
1679
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001680 private void onAdapterAttached() {
Ihab Awad9c3f1882014-06-30 21:17:13 -07001681 if (mAreAccountsInitialized) {
Santos Cordon52d8a152014-06-17 19:08:45 -07001682 // No need to query again if we already did it.
1683 return;
1684 }
1685
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001686 mAdapter.queryRemoteConnectionServices(new RemoteServiceCallback.Stub() {
Santos Cordon52d8a152014-06-17 19:08:45 -07001687 @Override
1688 public void onResult(
1689 final List<ComponentName> componentNames,
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001690 final List<IBinder> services) {
Brad Ebinger0c3541b2016-11-01 14:11:38 -07001691 mHandler.post(new android.telecom.Logging.Runnable("oAA.qRCS.oR", null /*lock*/) {
Ihab Awad6107bab2014-08-18 09:23:25 -07001692 @Override
Brad Ebinger0c3541b2016-11-01 14:11:38 -07001693 public void loggedRun() {
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001694 for (int i = 0; i < componentNames.size() && i < services.size(); i++) {
Santos Cordon52d8a152014-06-17 19:08:45 -07001695 mRemoteConnectionManager.addConnectionService(
1696 componentNames.get(i),
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001697 IConnectionService.Stub.asInterface(services.get(i)));
Santos Cordon52d8a152014-06-17 19:08:45 -07001698 }
Ihab Awad5d0410f2014-07-30 10:07:40 -07001699 onAccountsInitialized();
Sailesh Nepalc5b01572014-07-14 16:29:44 -07001700 Log.d(this, "remote connection services found: " + services);
Santos Cordon52d8a152014-06-17 19:08:45 -07001701 }
Brad Ebinger0c3541b2016-11-01 14:11:38 -07001702 }.prepare());
Santos Cordon52d8a152014-06-17 19:08:45 -07001703 }
1704
1705 @Override
1706 public void onError() {
Brad Ebinger0c3541b2016-11-01 14:11:38 -07001707 mHandler.post(new android.telecom.Logging.Runnable("oAA.qRCS.oE", null /*lock*/) {
Ihab Awad6107bab2014-08-18 09:23:25 -07001708 @Override
Brad Ebinger0c3541b2016-11-01 14:11:38 -07001709 public void loggedRun() {
Ihab Awad9c3f1882014-06-30 21:17:13 -07001710 mAreAccountsInitialized = true;
Santos Cordon52d8a152014-06-17 19:08:45 -07001711 }
Brad Ebinger0c3541b2016-11-01 14:11:38 -07001712 }.prepare());
Santos Cordon52d8a152014-06-17 19:08:45 -07001713 }
1714 });
1715 }
1716
Ihab Awadf8b69882014-07-25 15:14:01 -07001717 /**
1718 * Ask some other {@code ConnectionService} to create a {@code RemoteConnection} given an
Santos Cordona663f862014-10-29 13:49:58 -07001719 * incoming request. This is used by {@code ConnectionService}s that are registered with
1720 * {@link PhoneAccount#CAPABILITY_CONNECTION_MANAGER} and want to be able to manage
1721 * SIM-based incoming calls.
Ihab Awadf8b69882014-07-25 15:14:01 -07001722 *
1723 * @param connectionManagerPhoneAccount See description at
1724 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
1725 * @param request Details about the incoming call.
1726 * @return The {@code Connection} object to satisfy this call, or {@code null} to
1727 * not handle the call.
1728 */
1729 public final RemoteConnection createRemoteIncomingConnection(
1730 PhoneAccountHandle connectionManagerPhoneAccount,
1731 ConnectionRequest request) {
1732 return mRemoteConnectionManager.createRemoteConnection(
1733 connectionManagerPhoneAccount, request, true);
Santos Cordon52d8a152014-06-17 19:08:45 -07001734 }
1735
1736 /**
Ihab Awadf8b69882014-07-25 15:14:01 -07001737 * Ask some other {@code ConnectionService} to create a {@code RemoteConnection} given an
Santos Cordona663f862014-10-29 13:49:58 -07001738 * outgoing request. This is used by {@code ConnectionService}s that are registered with
1739 * {@link PhoneAccount#CAPABILITY_CONNECTION_MANAGER} and want to be able to use the
1740 * SIM-based {@code ConnectionService} to place its outgoing calls.
Ihab Awadf8b69882014-07-25 15:14:01 -07001741 *
1742 * @param connectionManagerPhoneAccount See description at
1743 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
Cuihtlauac ALVARADO0b3b2a52016-09-13 14:49:41 +02001744 * @param request Details about the outgoing call.
Ihab Awadf8b69882014-07-25 15:14:01 -07001745 * @return The {@code Connection} object to satisfy this call, or {@code null} to
1746 * not handle the call.
1747 */
1748 public final RemoteConnection createRemoteOutgoingConnection(
1749 PhoneAccountHandle connectionManagerPhoneAccount,
1750 ConnectionRequest request) {
1751 return mRemoteConnectionManager.createRemoteConnection(
1752 connectionManagerPhoneAccount, request, false);
1753 }
1754
1755 /**
Santos Cordona663f862014-10-29 13:49:58 -07001756 * Indicates to the relevant {@code RemoteConnectionService} that the specified
1757 * {@link RemoteConnection}s should be merged into a conference call.
1758 * <p>
1759 * If the conference request is successful, the method {@link #onRemoteConferenceAdded} will
1760 * be invoked.
1761 *
1762 * @param remoteConnection1 The first of the remote connections to conference.
1763 * @param remoteConnection2 The second of the remote connections to conference.
Ihab Awadb8e85c72014-08-23 20:34:57 -07001764 */
1765 public final void conferenceRemoteConnections(
Santos Cordona663f862014-10-29 13:49:58 -07001766 RemoteConnection remoteConnection1,
1767 RemoteConnection remoteConnection2) {
1768 mRemoteConnectionManager.conferenceRemoteConnections(remoteConnection1, remoteConnection2);
Ihab Awadb8e85c72014-08-23 20:34:57 -07001769 }
1770
1771 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07001772 * Adds a new conference call. When a conference call is created either as a result of an
1773 * explicit request via {@link #onConference} or otherwise, the connection service should supply
1774 * an instance of {@link Conference} by invoking this method. A conference call provided by this
1775 * method will persist until {@link Conference#destroy} is invoked on the conference instance.
1776 *
1777 * @param conference The new conference object.
1778 */
1779 public final void addConference(Conference conference) {
Rekha Kumar07366812015-03-24 16:42:31 -07001780 Log.d(this, "addConference: conference=%s", conference);
1781
Santos Cordon823fd3c2014-08-07 18:35:18 -07001782 String id = addConferenceInternal(conference);
1783 if (id != null) {
1784 List<String> connectionIds = new ArrayList<>(2);
1785 for (Connection connection : conference.getConnections()) {
1786 if (mIdByConnection.containsKey(connection)) {
1787 connectionIds.add(mIdByConnection.get(connection));
1788 }
1789 }
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001790 conference.setTelecomCallId(id);
Santos Cordon823fd3c2014-08-07 18:35:18 -07001791 ParcelableConference parcelableConference = new ParcelableConference(
Nancy Chenea38cca2014-09-05 16:38:49 -07001792 conference.getPhoneAccountHandle(),
Santos Cordon823fd3c2014-08-07 18:35:18 -07001793 conference.getState(),
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001794 conference.getConnectionCapabilities(),
Tyler Gunn720c6642016-03-22 09:02:47 -07001795 conference.getConnectionProperties(),
Tyler Gunncd5d33c2015-01-12 09:02:01 -08001796 connectionIds,
Rekha Kumar07366812015-03-24 16:42:31 -07001797 conference.getVideoProvider() == null ?
1798 null : conference.getVideoProvider().getInterface(),
1799 conference.getVideoState(),
Andrew Lee3e3e2f22015-04-16 13:48:43 -07001800 conference.getConnectTimeMillis(),
Santos Cordon6b7f9552015-05-27 17:21:45 -07001801 conference.getStatusHints(),
1802 conference.getExtras());
Andrew Lee0f51da32015-04-16 13:11:55 -07001803
Santos Cordon823fd3c2014-08-07 18:35:18 -07001804 mAdapter.addConferenceCall(id, parcelableConference);
Rekha Kumar07366812015-03-24 16:42:31 -07001805 mAdapter.setVideoProvider(id, conference.getVideoProvider());
1806 mAdapter.setVideoState(id, conference.getVideoState());
Santos Cordon823fd3c2014-08-07 18:35:18 -07001807
1808 // Go through any child calls and set the parent.
1809 for (Connection connection : conference.getConnections()) {
1810 String connectionId = mIdByConnection.get(connection);
1811 if (connectionId != null) {
1812 mAdapter.setIsConferenced(connectionId, id);
1813 }
1814 }
1815 }
1816 }
1817
1818 /**
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07001819 * Adds a connection created by the {@link ConnectionService} and informs telecom of the new
1820 * connection.
1821 *
1822 * @param phoneAccountHandle The phone account handle for the connection.
1823 * @param connection The connection to add.
1824 */
1825 public final void addExistingConnection(PhoneAccountHandle phoneAccountHandle,
1826 Connection connection) {
Tyler Gunn78da7812017-05-09 14:34:57 -07001827 addExistingConnection(phoneAccountHandle, connection, null /* conference */);
1828 }
1829
1830 /**
1831 * Adds a connection created by the {@link ConnectionService} and informs telecom of the new
1832 * connection.
1833 *
1834 * @param phoneAccountHandle The phone account handle for the connection.
1835 * @param connection The connection to add.
1836 * @param conference The parent conference of the new connection.
1837 * @hide
1838 */
1839 public final void addExistingConnection(PhoneAccountHandle phoneAccountHandle,
1840 Connection connection, Conference conference) {
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07001841
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001842 String id = addExistingConnectionInternal(phoneAccountHandle, connection);
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07001843 if (id != null) {
1844 List<String> emptyList = new ArrayList<>(0);
Tyler Gunn78da7812017-05-09 14:34:57 -07001845 String conferenceId = null;
1846 if (conference != null) {
1847 conferenceId = mIdByConference.get(conference);
1848 }
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07001849
1850 ParcelableConnection parcelableConnection = new ParcelableConnection(
1851 phoneAccountHandle,
1852 connection.getState(),
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001853 connection.getConnectionCapabilities(),
Tyler Gunn720c6642016-03-22 09:02:47 -07001854 connection.getConnectionProperties(),
Christine Hallstrom2830ce92016-11-30 16:06:42 -08001855 connection.getSupportedAudioRoutes(),
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07001856 connection.getAddress(),
1857 connection.getAddressPresentation(),
1858 connection.getCallerDisplayName(),
1859 connection.getCallerDisplayNamePresentation(),
1860 connection.getVideoProvider() == null ?
1861 null : connection.getVideoProvider().getInterface(),
1862 connection.getVideoState(),
1863 connection.isRingbackRequested(),
1864 connection.getAudioModeIsVoip(),
Roshan Piuse927ec02015-07-15 15:47:21 -07001865 connection.getConnectTimeMillis(),
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07001866 connection.getStatusHints(),
1867 connection.getDisconnectCause(),
Santos Cordon6b7f9552015-05-27 17:21:45 -07001868 emptyList,
Tyler Gunn78da7812017-05-09 14:34:57 -07001869 connection.getExtras(),
1870 conferenceId);
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07001871 mAdapter.addExistingConnection(id, parcelableConnection);
1872 }
1873 }
1874
1875 /**
Ihab Awadf8b69882014-07-25 15:14:01 -07001876 * Returns all the active {@code Connection}s for which this {@code ConnectionService}
1877 * has taken responsibility.
1878 *
1879 * @return A collection of {@code Connection}s created by this {@code ConnectionService}.
Santos Cordonb6939982014-06-04 20:20:58 -07001880 */
Sailesh Nepal091768c2014-06-30 15:15:23 -07001881 public final Collection<Connection> getAllConnections() {
Santos Cordonb6939982014-06-04 20:20:58 -07001882 return mConnectionById.values();
1883 }
1884
1885 /**
Santos Cordona6018b92016-02-16 14:23:12 -08001886 * Returns all the active {@code Conference}s for which this {@code ConnectionService}
1887 * has taken responsibility.
1888 *
1889 * @return A collection of {@code Conference}s created by this {@code ConnectionService}.
1890 */
1891 public final Collection<Conference> getAllConferences() {
1892 return mConferenceById.values();
1893 }
1894
1895 /**
Ihab Awadf8b69882014-07-25 15:14:01 -07001896 * Create a {@code Connection} given an incoming request. This is used to attach to existing
1897 * incoming calls.
Evan Charltonbf11f982014-07-20 22:06:28 -07001898 *
Ihab Awadf8b69882014-07-25 15:14:01 -07001899 * @param connectionManagerPhoneAccount See description at
1900 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
1901 * @param request Details about the incoming call.
1902 * @return The {@code Connection} object to satisfy this call, or {@code null} to
1903 * not handle the call.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001904 */
Ihab Awadf8b69882014-07-25 15:14:01 -07001905 public Connection onCreateIncomingConnection(
1906 PhoneAccountHandle connectionManagerPhoneAccount,
1907 ConnectionRequest request) {
1908 return null;
1909 }
Sailesh Nepalc5b01572014-07-14 16:29:44 -07001910
1911 /**
Tyler Gunnd104a4f2017-05-12 10:04:49 -07001912 * Called after the {@link Connection} returned by
1913 * {@link #onCreateIncomingConnection(PhoneAccountHandle, ConnectionRequest)}
1914 * or {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)} has been
1915 * added to the {@link ConnectionService} and sent to Telecom.
1916 *
1917 * @param connection the {@link Connection}.
1918 * @hide
1919 */
1920 public void onCreateConnectionComplete(Connection connection) {
1921 }
1922
1923 /**
Tyler Gunnf5035432017-01-09 09:43:12 -08001924 * Called by Telecom to inform the {@link ConnectionService} that its request to create a new
1925 * incoming {@link Connection} was denied.
1926 * <p>
1927 * Used when a self-managed {@link ConnectionService} attempts to create a new incoming
1928 * {@link Connection}, but Telecom has determined that the call cannot be allowed at this time.
1929 * The {@link ConnectionService} is responsible for silently rejecting the new incoming
1930 * {@link Connection}.
1931 * <p>
1932 * See {@link TelecomManager#isIncomingCallPermitted(PhoneAccountHandle)} for more information.
1933 *
Tyler Gunn159f35c2017-03-02 09:28:37 -08001934 * @param connectionManagerPhoneAccount See description at
1935 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
Tyler Gunnf5035432017-01-09 09:43:12 -08001936 * @param request The incoming connection request.
1937 */
Tyler Gunn159f35c2017-03-02 09:28:37 -08001938 public void onCreateIncomingConnectionFailed(PhoneAccountHandle connectionManagerPhoneAccount,
1939 ConnectionRequest request) {
Tyler Gunnf5035432017-01-09 09:43:12 -08001940 }
1941
1942 /**
1943 * Called by Telecom to inform the {@link ConnectionService} that its request to create a new
1944 * outgoing {@link Connection} was denied.
1945 * <p>
1946 * Used when a self-managed {@link ConnectionService} attempts to create a new outgoing
1947 * {@link Connection}, but Telecom has determined that the call cannot be placed at this time.
1948 * The {@link ConnectionService} is responisible for informing the user that the
1949 * {@link Connection} cannot be made at this time.
1950 * <p>
1951 * See {@link TelecomManager#isOutgoingCallPermitted(PhoneAccountHandle)} for more information.
1952 *
Tyler Gunn159f35c2017-03-02 09:28:37 -08001953 * @param connectionManagerPhoneAccount See description at
1954 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
Tyler Gunnf5035432017-01-09 09:43:12 -08001955 * @param request The outgoing connection request.
1956 */
Tyler Gunn159f35c2017-03-02 09:28:37 -08001957 public void onCreateOutgoingConnectionFailed(PhoneAccountHandle connectionManagerPhoneAccount,
1958 ConnectionRequest request) {
Tyler Gunnf5035432017-01-09 09:43:12 -08001959 }
1960
1961 /**
Shriram Ganesh6bf35ac2014-12-11 17:53:38 -08001962 * Trigger recalculate functinality for conference calls. This is used when a Telephony
1963 * Connection is part of a conference controller but is not yet added to Connection
1964 * Service and hence cannot be added to the conference call.
1965 *
1966 * @hide
1967 */
1968 public void triggerConferenceRecalculate() {
1969 }
1970
1971 /**
Ihab Awadf8b69882014-07-25 15:14:01 -07001972 * Create a {@code Connection} given an outgoing request. This is used to initiate new
1973 * outgoing calls.
Sailesh Nepalc5b01572014-07-14 16:29:44 -07001974 *
Ihab Awadf8b69882014-07-25 15:14:01 -07001975 * @param connectionManagerPhoneAccount The connection manager account to use for managing
1976 * this call.
1977 * <p>
1978 * If this parameter is not {@code null}, it means that this {@code ConnectionService}
1979 * has registered one or more {@code PhoneAccount}s having
1980 * {@link PhoneAccount#CAPABILITY_CONNECTION_MANAGER}. This parameter will contain
1981 * one of these {@code PhoneAccount}s, while the {@code request} will contain another
1982 * (usually but not always distinct) {@code PhoneAccount} to be used for actually
1983 * making the connection.
1984 * <p>
1985 * If this parameter is {@code null}, it means that this {@code ConnectionService} is
1986 * being asked to make a direct connection. The
1987 * {@link ConnectionRequest#getAccountHandle()} of parameter {@code request} will be
1988 * a {@code PhoneAccount} registered by this {@code ConnectionService} to use for
1989 * making the connection.
1990 * @param request Details about the outgoing call.
1991 * @return The {@code Connection} object to satisfy this call, or the result of an invocation
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001992 * of {@link Connection#createFailedConnection(DisconnectCause)} to not handle the call.
Sailesh Nepalc5b01572014-07-14 16:29:44 -07001993 */
Ihab Awadf8b69882014-07-25 15:14:01 -07001994 public Connection onCreateOutgoingConnection(
1995 PhoneAccountHandle connectionManagerPhoneAccount,
1996 ConnectionRequest request) {
1997 return null;
1998 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001999
2000 /**
Yorke Leec3cf9822014-10-02 09:38:39 -07002001 * Create a {@code Connection} for a new unknown call. An unknown call is a call originating
2002 * from the ConnectionService that was neither a user-initiated outgoing call, nor an incoming
2003 * call created using
2004 * {@code TelecomManager#addNewIncomingCall(PhoneAccountHandle, android.os.Bundle)}.
2005 *
Yorke Lee770ed6e2014-10-06 18:58:52 -07002006 * @hide
Yorke Leec3cf9822014-10-02 09:38:39 -07002007 */
2008 public Connection onCreateUnknownConnection(PhoneAccountHandle connectionManagerPhoneAccount,
2009 ConnectionRequest request) {
Brad Ebingerb32d4f82016-10-24 16:40:49 -07002010 return null;
Yorke Leec3cf9822014-10-02 09:38:39 -07002011 }
2012
2013 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07002014 * Conference two specified connections. Invoked when the user has made a request to merge the
2015 * specified connections into a conference call. In response, the connection service should
2016 * create an instance of {@link Conference} and pass it into {@link #addConference}.
Santos Cordonb6939982014-06-04 20:20:58 -07002017 *
Santos Cordon823fd3c2014-08-07 18:35:18 -07002018 * @param connection1 A connection to merge into a conference call.
2019 * @param connection2 A connection to merge into a conference call.
Santos Cordonb6939982014-06-04 20:20:58 -07002020 */
Santos Cordon823fd3c2014-08-07 18:35:18 -07002021 public void onConference(Connection connection1, Connection connection2) {}
Santos Cordonb6939982014-06-04 20:20:58 -07002022
Santos Cordona663f862014-10-29 13:49:58 -07002023 /**
2024 * Indicates that a remote conference has been created for existing {@link RemoteConnection}s.
2025 * When this method is invoked, this {@link ConnectionService} should create its own
2026 * representation of the conference call and send it to telecom using {@link #addConference}.
2027 * <p>
2028 * This is only relevant to {@link ConnectionService}s which are registered with
2029 * {@link PhoneAccount#CAPABILITY_CONNECTION_MANAGER}.
2030 *
2031 * @param conference The remote conference call.
2032 */
Ihab Awadb8e85c72014-08-23 20:34:57 -07002033 public void onRemoteConferenceAdded(RemoteConference conference) {}
2034
Santos Cordon823fd3c2014-08-07 18:35:18 -07002035 /**
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002036 * Called when an existing connection is added remotely.
2037 * @param connection The existing connection which was added.
2038 */
2039 public void onRemoteExistingConnectionAdded(RemoteConnection connection) {}
2040
2041 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07002042 * @hide
2043 */
2044 public boolean containsConference(Conference conference) {
2045 return mIdByConference.containsKey(conference);
2046 }
2047
Ihab Awadb8e85c72014-08-23 20:34:57 -07002048 /** {@hide} */
2049 void addRemoteConference(RemoteConference remoteConference) {
2050 onRemoteConferenceAdded(remoteConference);
2051 }
2052
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002053 /** {@hide} */
2054 void addRemoteExistingConnection(RemoteConnection remoteConnection) {
2055 onRemoteExistingConnectionAdded(remoteConnection);
2056 }
2057
Ihab Awad5d0410f2014-07-30 10:07:40 -07002058 private void onAccountsInitialized() {
2059 mAreAccountsInitialized = true;
2060 for (Runnable r : mPreInitializationConnectionRequests) {
2061 r.run();
2062 }
2063 mPreInitializationConnectionRequests.clear();
2064 }
2065
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002066 /**
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002067 * Adds an existing connection to the list of connections, identified by a new call ID unique
2068 * to this connection service.
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002069 *
2070 * @param connection The connection.
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002071 * @return The ID of the connection (e.g. the call-id).
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002072 */
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002073 private String addExistingConnectionInternal(PhoneAccountHandle handle, Connection connection) {
2074 String id;
Tyler Gunncd6ccfd2016-10-17 15:48:19 -07002075
2076 if (connection.getExtras() != null && connection.getExtras()
2077 .containsKey(Connection.EXTRA_ORIGINAL_CONNECTION_ID)) {
2078 id = connection.getExtras().getString(Connection.EXTRA_ORIGINAL_CONNECTION_ID);
2079 Log.d(this, "addExistingConnectionInternal - conn %s reusing original id %s",
2080 connection.getTelecomCallId(), id);
2081 } else if (handle == null) {
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002082 // If no phone account handle was provided, we cannot be sure the call ID is unique,
2083 // so just use a random UUID.
2084 id = UUID.randomUUID().toString();
2085 } else {
2086 // Phone account handle was provided, so use the ConnectionService class name as a
2087 // prefix for a unique incremental call ID.
2088 id = handle.getComponentName().getClassName() + "@" + getNextCallId();
2089 }
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002090 addConnection(id, connection);
2091 return id;
2092 }
2093
Ihab Awad542e0ea2014-05-16 10:22:16 -07002094 private void addConnection(String callId, Connection connection) {
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002095 connection.setTelecomCallId(callId);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002096 mConnectionById.put(callId, connection);
2097 mIdByConnection.put(connection, callId);
2098 connection.addConnectionListener(mConnectionListener);
Santos Cordon823fd3c2014-08-07 18:35:18 -07002099 connection.setConnectionService(this);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002100 }
2101
Anthony Lee30e65842014-11-06 16:30:53 -08002102 /** {@hide} */
2103 protected void removeConnection(Connection connection) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07002104 connection.unsetConnectionService(this);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002105 connection.removeConnectionListener(mConnectionListener);
Chenjie Luoe370b532016-05-12 16:59:43 -07002106 String id = mIdByConnection.get(connection);
2107 if (id != null) {
2108 mConnectionById.remove(id);
2109 mIdByConnection.remove(connection);
2110 mAdapter.removeCall(id);
2111 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002112 }
2113
Santos Cordon823fd3c2014-08-07 18:35:18 -07002114 private String addConferenceInternal(Conference conference) {
Tyler Gunncd6ccfd2016-10-17 15:48:19 -07002115 String originalId = null;
2116 if (conference.getExtras() != null && conference.getExtras()
2117 .containsKey(Connection.EXTRA_ORIGINAL_CONNECTION_ID)) {
2118 originalId = conference.getExtras().getString(Connection.EXTRA_ORIGINAL_CONNECTION_ID);
2119 Log.d(this, "addConferenceInternal: conf %s reusing original id %s",
2120 conference.getTelecomCallId(),
2121 originalId);
2122 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07002123 if (mIdByConference.containsKey(conference)) {
2124 Log.w(this, "Re-adding an existing conference: %s.", conference);
2125 } else if (conference != null) {
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002126 // Conferences do not (yet) have a PhoneAccountHandle associated with them, so we
2127 // cannot determine a ConnectionService class name to associate with the ID, so use
2128 // a unique UUID (for now).
Tyler Gunncd6ccfd2016-10-17 15:48:19 -07002129 String id = originalId == null ? UUID.randomUUID().toString() : originalId;
Santos Cordon823fd3c2014-08-07 18:35:18 -07002130 mConferenceById.put(id, conference);
2131 mIdByConference.put(conference, id);
2132 conference.addListener(mConferenceListener);
2133 return id;
2134 }
2135
2136 return null;
2137 }
2138
2139 private void removeConference(Conference conference) {
2140 if (mIdByConference.containsKey(conference)) {
2141 conference.removeListener(mConferenceListener);
2142
2143 String id = mIdByConference.get(conference);
2144 mConferenceById.remove(id);
2145 mIdByConference.remove(conference);
2146 mAdapter.removeCall(id);
2147 }
2148 }
2149
Ihab Awad542e0ea2014-05-16 10:22:16 -07002150 private Connection findConnectionForAction(String callId, String action) {
2151 if (mConnectionById.containsKey(callId)) {
2152 return mConnectionById.get(callId);
2153 }
Ihab Awad60ac30b2014-05-20 22:32:12 -07002154 Log.w(this, "%s - Cannot find Connection %s", action, callId);
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07002155 return getNullConnection();
2156 }
2157
2158 static synchronized Connection getNullConnection() {
2159 if (sNullConnection == null) {
2160 sNullConnection = new Connection() {};
2161 }
2162 return sNullConnection;
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002163 }
Santos Cordon0159ac02014-08-21 14:28:11 -07002164
2165 private Conference findConferenceForAction(String conferenceId, String action) {
2166 if (mConferenceById.containsKey(conferenceId)) {
2167 return mConferenceById.get(conferenceId);
2168 }
2169 Log.w(this, "%s - Cannot find conference %s", action, conferenceId);
2170 return getNullConference();
2171 }
2172
Ihab Awadb8e85c72014-08-23 20:34:57 -07002173 private List<String> createConnectionIdList(List<Connection> connections) {
2174 List<String> ids = new ArrayList<>();
2175 for (Connection c : connections) {
2176 if (mIdByConnection.containsKey(c)) {
2177 ids.add(mIdByConnection.get(c));
2178 }
2179 }
2180 Collections.sort(ids);
2181 return ids;
2182 }
2183
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002184 /**
2185 * Builds a list of {@link Connection} and {@link Conference} IDs based on the list of
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002186 * {@link Conferenceable}s passed in.
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002187 *
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002188 * @param conferenceables The {@link Conferenceable} connections and conferences.
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002189 * @return List of string conference and call Ids.
2190 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002191 private List<String> createIdList(List<Conferenceable> conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002192 List<String> ids = new ArrayList<>();
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002193 for (Conferenceable c : conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002194 // Only allow Connection and Conference conferenceables.
2195 if (c instanceof Connection) {
2196 Connection connection = (Connection) c;
2197 if (mIdByConnection.containsKey(connection)) {
2198 ids.add(mIdByConnection.get(connection));
2199 }
2200 } else if (c instanceof Conference) {
2201 Conference conference = (Conference) c;
2202 if (mIdByConference.containsKey(conference)) {
2203 ids.add(mIdByConference.get(conference));
2204 }
2205 }
2206 }
2207 Collections.sort(ids);
2208 return ids;
2209 }
2210
Santos Cordon0159ac02014-08-21 14:28:11 -07002211 private Conference getNullConference() {
2212 if (sNullConference == null) {
2213 sNullConference = new Conference(null) {};
2214 }
2215 return sNullConference;
2216 }
Santos Cordon29f2f2e2014-09-11 19:50:24 -07002217
2218 private void endAllConnections() {
2219 // Unbound from telecomm. We should end all connections and conferences.
2220 for (Connection connection : mIdByConnection.keySet()) {
2221 // only operate on top-level calls. Conference calls will be removed on their own.
2222 if (connection.getConference() == null) {
2223 connection.onDisconnect();
2224 }
2225 }
2226 for (Conference conference : mIdByConference.keySet()) {
2227 conference.onDisconnect();
2228 }
2229 }
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002230
2231 /**
2232 * Retrieves the next call ID as maintainted by the connection service.
2233 *
2234 * @return The call ID.
2235 */
2236 private int getNextCallId() {
Brad Ebingerb32d4f82016-10-24 16:40:49 -07002237 synchronized (mIdSyncRoot) {
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002238 return ++mId;
2239 }
2240 }
Santos Cordon980acb92014-05-31 10:31:19 -07002241}