blob: 2faa96b1ff5748ad01f804ca539af3df3c43c3a1 [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 }
Srikanth Chintalafcb15012017-05-04 20:58:34 +05301317
1318 @Override
1319 public void onPhoneAccountChanged(Connection c, PhoneAccountHandle pHandle) {
1320 String id = mIdByConnection.get(c);
1321 if (id != null) {
1322 mAdapter.onPhoneAccountChanged(id, pHandle);
1323 }
1324 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001325 };
1326
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001327 /** {@inheritDoc} */
Ihab Awad542e0ea2014-05-16 10:22:16 -07001328 @Override
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001329 public final IBinder onBind(Intent intent) {
1330 return mBinder;
1331 }
1332
Santos Cordon29f2f2e2014-09-11 19:50:24 -07001333 /** {@inheritDoc} */
1334 @Override
1335 public boolean onUnbind(Intent intent) {
1336 endAllConnections();
1337 return super.onUnbind(intent);
1338 }
1339
Sailesh Nepalc5b01572014-07-14 16:29:44 -07001340 /**
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001341 * This can be used by telecom to either create a new outgoing call or attach to an existing
1342 * incoming call. In either case, telecom will cycle through a set of services and call
Sailesh Nepalc5b01572014-07-14 16:29:44 -07001343 * createConnection util a connection service cancels the process or completes it successfully.
1344 */
Ihab Awadf8b69882014-07-25 15:14:01 -07001345 private void createConnection(
1346 final PhoneAccountHandle callManagerAccount,
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001347 final String callId,
Ihab Awadf8b69882014-07-25 15:14:01 -07001348 final ConnectionRequest request,
Yorke Leec3cf9822014-10-02 09:38:39 -07001349 boolean isIncoming,
1350 boolean isUnknown) {
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001351 Log.d(this, "createConnection, callManagerAccount: %s, callId: %s, request: %s, " +
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001352 "isIncoming: %b, isUnknown: %b", callManagerAccount, callId, request,
1353 isIncoming,
Yorke Leec3cf9822014-10-02 09:38:39 -07001354 isUnknown);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001355
Yorke Leec3cf9822014-10-02 09:38:39 -07001356 Connection connection = isUnknown ? onCreateUnknownConnection(callManagerAccount, request)
1357 : isIncoming ? onCreateIncomingConnection(callManagerAccount, request)
Ihab Awad6107bab2014-08-18 09:23:25 -07001358 : onCreateOutgoingConnection(callManagerAccount, request);
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001359 Log.d(this, "createConnection, connection: %s", connection);
1360 if (connection == null) {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001361 connection = Connection.createFailedConnection(
1362 new DisconnectCause(DisconnectCause.ERROR));
Sailesh Nepalc5b01572014-07-14 16:29:44 -07001363 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001364
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001365 connection.setTelecomCallId(callId);
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001366 if (connection.getState() != Connection.STATE_DISCONNECTED) {
Ihab Awad6107bab2014-08-18 09:23:25 -07001367 addConnection(callId, connection);
1368 }
1369
Andrew Lee100e2932014-09-08 15:34:24 -07001370 Uri address = connection.getAddress();
1371 String number = address == null ? "null" : address.getSchemeSpecificPart();
Tyler Gunn720c6642016-03-22 09:02:47 -07001372 Log.v(this, "createConnection, number: %s, state: %s, capabilities: %s, properties: %s",
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001373 Connection.toLogSafePhoneNumber(number),
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001374 Connection.stateToString(connection.getState()),
Tyler Gunn720c6642016-03-22 09:02:47 -07001375 Connection.capabilitiesToString(connection.getConnectionCapabilities()),
1376 Connection.propertiesToString(connection.getConnectionProperties()));
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001377
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001378 Log.d(this, "createConnection, calling handleCreateConnectionSuccessful %s", callId);
Ihab Awad6107bab2014-08-18 09:23:25 -07001379 mAdapter.handleCreateConnectionComplete(
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001380 callId,
Evan Charltonbf11f982014-07-20 22:06:28 -07001381 request,
1382 new ParcelableConnection(
1383 request.getAccountHandle(),
1384 connection.getState(),
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001385 connection.getConnectionCapabilities(),
Tyler Gunn720c6642016-03-22 09:02:47 -07001386 connection.getConnectionProperties(),
Christine Hallstrom2830ce92016-11-30 16:06:42 -08001387 connection.getSupportedAudioRoutes(),
Andrew Lee100e2932014-09-08 15:34:24 -07001388 connection.getAddress(),
1389 connection.getAddressPresentation(),
Evan Charltonbf11f982014-07-20 22:06:28 -07001390 connection.getCallerDisplayName(),
1391 connection.getCallerDisplayNamePresentation(),
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001392 connection.getVideoProvider() == null ?
1393 null : connection.getVideoProvider().getInterface(),
Sailesh Nepal8b9d3ca2014-08-14 17:39:34 -07001394 connection.getVideoState(),
Andrew Lee100e2932014-09-08 15:34:24 -07001395 connection.isRingbackRequested(),
Sailesh Nepal8b9d3ca2014-08-14 17:39:34 -07001396 connection.getAudioModeIsVoip(),
Roshan Piuse927ec02015-07-15 15:47:21 -07001397 connection.getConnectTimeMillis(),
Tyler Gunn3fa819c2017-08-04 09:27:26 -07001398 connection.getConnectElapsedTimeMillis(),
Ihab Awad6107bab2014-08-18 09:23:25 -07001399 connection.getStatusHints(),
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001400 connection.getDisconnectCause(),
Santos Cordon6b7f9552015-05-27 17:21:45 -07001401 createIdList(connection.getConferenceables()),
1402 connection.getExtras()));
Tyler Gunnf5035432017-01-09 09:43:12 -08001403
1404 if (isIncoming && request.shouldShowIncomingCallUi() &&
1405 (connection.getConnectionProperties() & Connection.PROPERTY_SELF_MANAGED) ==
1406 Connection.PROPERTY_SELF_MANAGED) {
1407 // Tell ConnectionService to show its incoming call UX.
1408 connection.onShowIncomingCallUi();
1409 }
Shriram Ganesh6bf35ac2014-12-11 17:53:38 -08001410 if (isUnknown) {
1411 triggerConferenceRecalculate();
1412 }
Evan Charltonbf11f982014-07-20 22:06:28 -07001413 }
1414
Tyler Gunn159f35c2017-03-02 09:28:37 -08001415 private void createConnectionFailed(final PhoneAccountHandle callManagerAccount,
1416 final String callId, final ConnectionRequest request,
1417 boolean isIncoming) {
Tyler Gunn44e01912017-01-31 10:49:05 -08001418
1419 Log.i(this, "createConnectionFailed %s", callId);
1420 if (isIncoming) {
Tyler Gunn159f35c2017-03-02 09:28:37 -08001421 onCreateIncomingConnectionFailed(callManagerAccount, request);
Tyler Gunn44e01912017-01-31 10:49:05 -08001422 } else {
Tyler Gunn159f35c2017-03-02 09:28:37 -08001423 onCreateOutgoingConnectionFailed(callManagerAccount, request);
Tyler Gunn44e01912017-01-31 10:49:05 -08001424 }
1425 }
1426
Tyler Gunnd104a4f2017-05-12 10:04:49 -07001427 /**
1428 * Called by Telecom when the creation of a new Connection has completed and it is now added
1429 * to Telecom.
1430 * @param callId The ID of the connection.
1431 */
1432 private void notifyCreateConnectionComplete(final String callId) {
1433 Log.i(this, "notifyCreateConnectionComplete %s", callId);
1434 onCreateConnectionComplete(findConnectionForAction(callId,
1435 "notifyCreateConnectionComplete"));
1436 }
1437
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001438 private void abort(String callId) {
Ihab Awad60ac30b2014-05-20 22:32:12 -07001439 Log.d(this, "abort %s", callId);
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001440 findConnectionForAction(callId, "abort").onAbort();
Ihab Awad542e0ea2014-05-16 10:22:16 -07001441 }
1442
Tyler Gunnbe74de02014-08-29 14:51:48 -07001443 private void answerVideo(String callId, int videoState) {
1444 Log.d(this, "answerVideo %s", callId);
Andrew Lee8da4c3c2014-07-16 10:11:42 -07001445 findConnectionForAction(callId, "answer").onAnswer(videoState);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001446 }
1447
Tyler Gunnbe74de02014-08-29 14:51:48 -07001448 private void answer(String callId) {
1449 Log.d(this, "answer %s", callId);
1450 findConnectionForAction(callId, "answer").onAnswer();
1451 }
1452
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001453 private void reject(String callId) {
Ihab Awad60ac30b2014-05-20 22:32:12 -07001454 Log.d(this, "reject %s", callId);
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001455 findConnectionForAction(callId, "reject").onReject();
Ihab Awad542e0ea2014-05-16 10:22:16 -07001456 }
1457
Bryce Lee81901682015-08-28 16:38:02 -07001458 private void reject(String callId, String rejectWithMessage) {
1459 Log.d(this, "reject %s with message", callId);
1460 findConnectionForAction(callId, "reject").onReject(rejectWithMessage);
1461 }
1462
Bryce Leecac50772015-11-17 15:13:29 -08001463 private void silence(String callId) {
1464 Log.d(this, "silence %s", callId);
1465 findConnectionForAction(callId, "silence").onSilence();
1466 }
1467
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001468 private void disconnect(String callId) {
Ihab Awad60ac30b2014-05-20 22:32:12 -07001469 Log.d(this, "disconnect %s", callId);
Santos Cordon0159ac02014-08-21 14:28:11 -07001470 if (mConnectionById.containsKey(callId)) {
1471 findConnectionForAction(callId, "disconnect").onDisconnect();
1472 } else {
1473 findConferenceForAction(callId, "disconnect").onDisconnect();
1474 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001475 }
1476
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001477 private void hold(String callId) {
Ihab Awad60ac30b2014-05-20 22:32:12 -07001478 Log.d(this, "hold %s", callId);
Santos Cordon0159ac02014-08-21 14:28:11 -07001479 if (mConnectionById.containsKey(callId)) {
1480 findConnectionForAction(callId, "hold").onHold();
1481 } else {
1482 findConferenceForAction(callId, "hold").onHold();
1483 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001484 }
1485
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001486 private void unhold(String callId) {
Ihab Awad60ac30b2014-05-20 22:32:12 -07001487 Log.d(this, "unhold %s", callId);
Santos Cordon0159ac02014-08-21 14:28:11 -07001488 if (mConnectionById.containsKey(callId)) {
1489 findConnectionForAction(callId, "unhold").onUnhold();
1490 } else {
1491 findConferenceForAction(callId, "unhold").onUnhold();
1492 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001493 }
1494
Yorke Lee4af59352015-05-13 14:14:54 -07001495 private void onCallAudioStateChanged(String callId, CallAudioState callAudioState) {
1496 Log.d(this, "onAudioStateChanged %s %s", callId, callAudioState);
Yorke Leea0d3ca92014-09-15 19:18:13 -07001497 if (mConnectionById.containsKey(callId)) {
Yorke Lee4af59352015-05-13 14:14:54 -07001498 findConnectionForAction(callId, "onCallAudioStateChanged").setCallAudioState(
1499 callAudioState);
Yorke Leea0d3ca92014-09-15 19:18:13 -07001500 } else {
Yorke Lee4af59352015-05-13 14:14:54 -07001501 findConferenceForAction(callId, "onCallAudioStateChanged").setCallAudioState(
1502 callAudioState);
Yorke Leea0d3ca92014-09-15 19:18:13 -07001503 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001504 }
1505
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001506 private void playDtmfTone(String callId, char digit) {
1507 Log.d(this, "playDtmfTone %s %c", callId, digit);
Yorke Leea0d3ca92014-09-15 19:18:13 -07001508 if (mConnectionById.containsKey(callId)) {
1509 findConnectionForAction(callId, "playDtmfTone").onPlayDtmfTone(digit);
1510 } else {
1511 findConferenceForAction(callId, "playDtmfTone").onPlayDtmfTone(digit);
1512 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001513 }
1514
1515 private void stopDtmfTone(String callId) {
1516 Log.d(this, "stopDtmfTone %s", callId);
Yorke Leea0d3ca92014-09-15 19:18:13 -07001517 if (mConnectionById.containsKey(callId)) {
1518 findConnectionForAction(callId, "stopDtmfTone").onStopDtmfTone();
1519 } else {
1520 findConferenceForAction(callId, "stopDtmfTone").onStopDtmfTone();
1521 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001522 }
1523
Santos Cordon823fd3c2014-08-07 18:35:18 -07001524 private void conference(String callId1, String callId2) {
1525 Log.d(this, "conference %s, %s", callId1, callId2);
Santos Cordon980acb92014-05-31 10:31:19 -07001526
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001527 // Attempt to get second connection or conference.
Santos Cordon823fd3c2014-08-07 18:35:18 -07001528 Connection connection2 = findConnectionForAction(callId2, "conference");
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001529 Conference conference2 = getNullConference();
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001530 if (connection2 == getNullConnection()) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001531 conference2 = findConferenceForAction(callId2, "conference");
1532 if (conference2 == getNullConference()) {
1533 Log.w(this, "Connection2 or Conference2 missing in conference request %s.",
1534 callId2);
1535 return;
1536 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07001537 }
Santos Cordonb6939982014-06-04 20:20:58 -07001538
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001539 // Attempt to get first connection or conference and perform merge.
Ihab Awad50e35062014-09-30 09:17:03 -07001540 Connection connection1 = findConnectionForAction(callId1, "conference");
1541 if (connection1 == getNullConnection()) {
1542 Conference conference1 = findConferenceForAction(callId1, "addConnection");
1543 if (conference1 == getNullConference()) {
1544 Log.w(this,
1545 "Connection1 or Conference1 missing in conference request %s.",
1546 callId1);
1547 } else {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001548 // Call 1 is a conference.
1549 if (connection2 != getNullConnection()) {
1550 // Call 2 is a connection so merge via call 1 (conference).
1551 conference1.onMerge(connection2);
1552 } else {
1553 // Call 2 is ALSO a conference; this should never happen.
1554 Log.wtf(this, "There can only be one conference and an attempt was made to " +
1555 "merge two conferences.");
1556 return;
1557 }
Ihab Awad50e35062014-09-30 09:17:03 -07001558 }
1559 } else {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001560 // Call 1 is a connection.
1561 if (conference2 != getNullConference()) {
1562 // Call 2 is a conference, so merge via call 2.
1563 conference2.onMerge(connection1);
1564 } else {
1565 // Call 2 is a connection, so merge together.
1566 onConference(connection1, connection2);
1567 }
Ihab Awad50e35062014-09-30 09:17:03 -07001568 }
Santos Cordon980acb92014-05-31 10:31:19 -07001569 }
1570
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001571 private void splitFromConference(String callId) {
Santos Cordonb6939982014-06-04 20:20:58 -07001572 Log.d(this, "splitFromConference(%s)", callId);
Santos Cordon980acb92014-05-31 10:31:19 -07001573
1574 Connection connection = findConnectionForAction(callId, "splitFromConference");
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001575 if (connection == getNullConnection()) {
Santos Cordon980acb92014-05-31 10:31:19 -07001576 Log.w(this, "Connection missing in conference request %s.", callId);
1577 return;
1578 }
1579
Santos Cordon0159ac02014-08-21 14:28:11 -07001580 Conference conference = connection.getConference();
1581 if (conference != null) {
1582 conference.onSeparate(connection);
1583 }
Santos Cordon980acb92014-05-31 10:31:19 -07001584 }
1585
Santos Cordona4868042014-09-04 17:39:22 -07001586 private void mergeConference(String callId) {
1587 Log.d(this, "mergeConference(%s)", callId);
1588 Conference conference = findConferenceForAction(callId, "mergeConference");
1589 if (conference != null) {
1590 conference.onMerge();
1591 }
1592 }
1593
1594 private void swapConference(String callId) {
1595 Log.d(this, "swapConference(%s)", callId);
1596 Conference conference = findConferenceForAction(callId, "swapConference");
1597 if (conference != null) {
1598 conference.onSwap();
1599 }
1600 }
1601
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001602 /**
1603 * Notifies a {@link Connection} of a request to pull an external call.
1604 *
1605 * See {@link Call#pullExternalCall()}.
1606 *
1607 * @param callId The ID of the call to pull.
1608 */
1609 private void pullExternalCall(String callId) {
1610 Log.d(this, "pullExternalCall(%s)", callId);
1611 Connection connection = findConnectionForAction(callId, "pullExternalCall");
1612 if (connection != null) {
1613 connection.onPullExternalCall();
1614 }
1615 }
1616
1617 /**
1618 * Notifies a {@link Connection} of a call event.
1619 *
1620 * See {@link Call#sendCallEvent(String, Bundle)}.
1621 *
1622 * @param callId The ID of the call receiving the event.
1623 * @param event The event.
1624 * @param extras Extras associated with the event.
1625 */
1626 private void sendCallEvent(String callId, String event, Bundle extras) {
1627 Log.d(this, "sendCallEvent(%s, %s)", callId, event);
1628 Connection connection = findConnectionForAction(callId, "sendCallEvent");
1629 if (connection != null) {
1630 connection.onCallEvent(event, extras);
1631 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001632 }
1633
Tyler Gunndee56a82016-03-23 16:06:34 -07001634 /**
1635 * Notifies a {@link Connection} or {@link Conference} of a change to the extras from Telecom.
1636 * <p>
1637 * These extra changes can originate from Telecom itself, or from an {@link InCallService} via
1638 * the {@link android.telecom.Call#putExtra(String, boolean)},
1639 * {@link android.telecom.Call#putExtra(String, int)},
1640 * {@link android.telecom.Call#putExtra(String, String)},
1641 * {@link Call#removeExtras(List)}.
1642 *
1643 * @param callId The ID of the call receiving the event.
1644 * @param extras The new extras bundle.
1645 */
1646 private void handleExtrasChanged(String callId, Bundle extras) {
1647 Log.d(this, "handleExtrasChanged(%s, %s)", callId, extras);
1648 if (mConnectionById.containsKey(callId)) {
1649 findConnectionForAction(callId, "handleExtrasChanged").handleExtrasChanged(extras);
1650 } else if (mConferenceById.containsKey(callId)) {
1651 findConferenceForAction(callId, "handleExtrasChanged").handleExtrasChanged(extras);
1652 }
1653 }
1654
Hall Liub64ac4c2017-02-06 10:49:48 -08001655 private void startRtt(String callId, Connection.RttTextStream rttTextStream) {
1656 Log.d(this, "startRtt(%s)", callId);
1657 if (mConnectionById.containsKey(callId)) {
1658 findConnectionForAction(callId, "startRtt").onStartRtt(rttTextStream);
1659 } else if (mConferenceById.containsKey(callId)) {
1660 Log.w(this, "startRtt called on a conference.");
1661 }
1662 }
1663
1664 private void stopRtt(String callId) {
1665 Log.d(this, "stopRtt(%s)", callId);
1666 if (mConnectionById.containsKey(callId)) {
1667 findConnectionForAction(callId, "stopRtt").onStopRtt();
Hall Liuffa4a812017-03-02 16:11:00 -08001668 findConnectionForAction(callId, "stopRtt").unsetRttProperty();
Hall Liub64ac4c2017-02-06 10:49:48 -08001669 } else if (mConferenceById.containsKey(callId)) {
1670 Log.w(this, "stopRtt called on a conference.");
1671 }
1672 }
1673
1674 private void handleRttUpgradeResponse(String callId, Connection.RttTextStream rttTextStream) {
1675 Log.d(this, "handleRttUpgradeResponse(%s, %s)", callId, rttTextStream == null);
1676 if (mConnectionById.containsKey(callId)) {
1677 findConnectionForAction(callId, "handleRttUpgradeResponse")
1678 .handleRttUpgradeResponse(rttTextStream);
1679 } else if (mConferenceById.containsKey(callId)) {
1680 Log.w(this, "handleRttUpgradeResponse called on a conference.");
1681 }
1682 }
1683
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001684 private void onPostDialContinue(String callId, boolean proceed) {
Evan Charlton6dea4ac2014-06-03 14:07:13 -07001685 Log.d(this, "onPostDialContinue(%s)", callId);
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001686 findConnectionForAction(callId, "stopDtmfTone").onPostDialContinue(proceed);
Evan Charlton6dea4ac2014-06-03 14:07:13 -07001687 }
1688
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001689 private void onAdapterAttached() {
Ihab Awad9c3f1882014-06-30 21:17:13 -07001690 if (mAreAccountsInitialized) {
Santos Cordon52d8a152014-06-17 19:08:45 -07001691 // No need to query again if we already did it.
1692 return;
1693 }
1694
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001695 mAdapter.queryRemoteConnectionServices(new RemoteServiceCallback.Stub() {
Santos Cordon52d8a152014-06-17 19:08:45 -07001696 @Override
1697 public void onResult(
1698 final List<ComponentName> componentNames,
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001699 final List<IBinder> services) {
Brad Ebinger0c3541b2016-11-01 14:11:38 -07001700 mHandler.post(new android.telecom.Logging.Runnable("oAA.qRCS.oR", null /*lock*/) {
Ihab Awad6107bab2014-08-18 09:23:25 -07001701 @Override
Brad Ebinger0c3541b2016-11-01 14:11:38 -07001702 public void loggedRun() {
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001703 for (int i = 0; i < componentNames.size() && i < services.size(); i++) {
Santos Cordon52d8a152014-06-17 19:08:45 -07001704 mRemoteConnectionManager.addConnectionService(
1705 componentNames.get(i),
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001706 IConnectionService.Stub.asInterface(services.get(i)));
Santos Cordon52d8a152014-06-17 19:08:45 -07001707 }
Ihab Awad5d0410f2014-07-30 10:07:40 -07001708 onAccountsInitialized();
Sailesh Nepalc5b01572014-07-14 16:29:44 -07001709 Log.d(this, "remote connection services found: " + services);
Santos Cordon52d8a152014-06-17 19:08:45 -07001710 }
Brad Ebinger0c3541b2016-11-01 14:11:38 -07001711 }.prepare());
Santos Cordon52d8a152014-06-17 19:08:45 -07001712 }
1713
1714 @Override
1715 public void onError() {
Brad Ebinger0c3541b2016-11-01 14:11:38 -07001716 mHandler.post(new android.telecom.Logging.Runnable("oAA.qRCS.oE", null /*lock*/) {
Ihab Awad6107bab2014-08-18 09:23:25 -07001717 @Override
Brad Ebinger0c3541b2016-11-01 14:11:38 -07001718 public void loggedRun() {
Ihab Awad9c3f1882014-06-30 21:17:13 -07001719 mAreAccountsInitialized = true;
Santos Cordon52d8a152014-06-17 19:08:45 -07001720 }
Brad Ebinger0c3541b2016-11-01 14:11:38 -07001721 }.prepare());
Santos Cordon52d8a152014-06-17 19:08:45 -07001722 }
1723 });
1724 }
1725
Ihab Awadf8b69882014-07-25 15:14:01 -07001726 /**
1727 * Ask some other {@code ConnectionService} to create a {@code RemoteConnection} given an
Santos Cordona663f862014-10-29 13:49:58 -07001728 * incoming request. This is used by {@code ConnectionService}s that are registered with
1729 * {@link PhoneAccount#CAPABILITY_CONNECTION_MANAGER} and want to be able to manage
1730 * SIM-based incoming calls.
Ihab Awadf8b69882014-07-25 15:14:01 -07001731 *
1732 * @param connectionManagerPhoneAccount See description at
1733 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
1734 * @param request Details about the incoming call.
1735 * @return The {@code Connection} object to satisfy this call, or {@code null} to
1736 * not handle the call.
1737 */
1738 public final RemoteConnection createRemoteIncomingConnection(
1739 PhoneAccountHandle connectionManagerPhoneAccount,
1740 ConnectionRequest request) {
1741 return mRemoteConnectionManager.createRemoteConnection(
1742 connectionManagerPhoneAccount, request, true);
Santos Cordon52d8a152014-06-17 19:08:45 -07001743 }
1744
1745 /**
Ihab Awadf8b69882014-07-25 15:14:01 -07001746 * Ask some other {@code ConnectionService} to create a {@code RemoteConnection} given an
Santos Cordona663f862014-10-29 13:49:58 -07001747 * outgoing request. This is used by {@code ConnectionService}s that are registered with
1748 * {@link PhoneAccount#CAPABILITY_CONNECTION_MANAGER} and want to be able to use the
1749 * SIM-based {@code ConnectionService} to place its outgoing calls.
Ihab Awadf8b69882014-07-25 15:14:01 -07001750 *
1751 * @param connectionManagerPhoneAccount See description at
1752 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
Cuihtlauac ALVARADO0b3b2a52016-09-13 14:49:41 +02001753 * @param request Details about the outgoing call.
Ihab Awadf8b69882014-07-25 15:14:01 -07001754 * @return The {@code Connection} object to satisfy this call, or {@code null} to
1755 * not handle the call.
1756 */
1757 public final RemoteConnection createRemoteOutgoingConnection(
1758 PhoneAccountHandle connectionManagerPhoneAccount,
1759 ConnectionRequest request) {
1760 return mRemoteConnectionManager.createRemoteConnection(
1761 connectionManagerPhoneAccount, request, false);
1762 }
1763
1764 /**
Santos Cordona663f862014-10-29 13:49:58 -07001765 * Indicates to the relevant {@code RemoteConnectionService} that the specified
1766 * {@link RemoteConnection}s should be merged into a conference call.
1767 * <p>
1768 * If the conference request is successful, the method {@link #onRemoteConferenceAdded} will
1769 * be invoked.
1770 *
1771 * @param remoteConnection1 The first of the remote connections to conference.
1772 * @param remoteConnection2 The second of the remote connections to conference.
Ihab Awadb8e85c72014-08-23 20:34:57 -07001773 */
1774 public final void conferenceRemoteConnections(
Santos Cordona663f862014-10-29 13:49:58 -07001775 RemoteConnection remoteConnection1,
1776 RemoteConnection remoteConnection2) {
1777 mRemoteConnectionManager.conferenceRemoteConnections(remoteConnection1, remoteConnection2);
Ihab Awadb8e85c72014-08-23 20:34:57 -07001778 }
1779
1780 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07001781 * Adds a new conference call. When a conference call is created either as a result of an
1782 * explicit request via {@link #onConference} or otherwise, the connection service should supply
1783 * an instance of {@link Conference} by invoking this method. A conference call provided by this
1784 * method will persist until {@link Conference#destroy} is invoked on the conference instance.
1785 *
1786 * @param conference The new conference object.
1787 */
1788 public final void addConference(Conference conference) {
Rekha Kumar07366812015-03-24 16:42:31 -07001789 Log.d(this, "addConference: conference=%s", conference);
1790
Santos Cordon823fd3c2014-08-07 18:35:18 -07001791 String id = addConferenceInternal(conference);
1792 if (id != null) {
1793 List<String> connectionIds = new ArrayList<>(2);
1794 for (Connection connection : conference.getConnections()) {
1795 if (mIdByConnection.containsKey(connection)) {
1796 connectionIds.add(mIdByConnection.get(connection));
1797 }
1798 }
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001799 conference.setTelecomCallId(id);
Santos Cordon823fd3c2014-08-07 18:35:18 -07001800 ParcelableConference parcelableConference = new ParcelableConference(
Nancy Chenea38cca2014-09-05 16:38:49 -07001801 conference.getPhoneAccountHandle(),
Santos Cordon823fd3c2014-08-07 18:35:18 -07001802 conference.getState(),
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001803 conference.getConnectionCapabilities(),
Tyler Gunn720c6642016-03-22 09:02:47 -07001804 conference.getConnectionProperties(),
Tyler Gunncd5d33c2015-01-12 09:02:01 -08001805 connectionIds,
Rekha Kumar07366812015-03-24 16:42:31 -07001806 conference.getVideoProvider() == null ?
1807 null : conference.getVideoProvider().getInterface(),
1808 conference.getVideoState(),
Andrew Lee3e3e2f22015-04-16 13:48:43 -07001809 conference.getConnectTimeMillis(),
Tyler Gunn3fa819c2017-08-04 09:27:26 -07001810 conference.getConnectElapsedTime(),
Santos Cordon6b7f9552015-05-27 17:21:45 -07001811 conference.getStatusHints(),
1812 conference.getExtras());
Andrew Lee0f51da32015-04-16 13:11:55 -07001813
Santos Cordon823fd3c2014-08-07 18:35:18 -07001814 mAdapter.addConferenceCall(id, parcelableConference);
Rekha Kumar07366812015-03-24 16:42:31 -07001815 mAdapter.setVideoProvider(id, conference.getVideoProvider());
1816 mAdapter.setVideoState(id, conference.getVideoState());
Santos Cordon823fd3c2014-08-07 18:35:18 -07001817
1818 // Go through any child calls and set the parent.
1819 for (Connection connection : conference.getConnections()) {
1820 String connectionId = mIdByConnection.get(connection);
1821 if (connectionId != null) {
1822 mAdapter.setIsConferenced(connectionId, id);
1823 }
1824 }
1825 }
1826 }
1827
1828 /**
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07001829 * Adds a connection created by the {@link ConnectionService} and informs telecom of the new
1830 * connection.
1831 *
1832 * @param phoneAccountHandle The phone account handle for the connection.
1833 * @param connection The connection to add.
1834 */
1835 public final void addExistingConnection(PhoneAccountHandle phoneAccountHandle,
1836 Connection connection) {
Tyler Gunn78da7812017-05-09 14:34:57 -07001837 addExistingConnection(phoneAccountHandle, connection, null /* conference */);
1838 }
1839
1840 /**
1841 * Adds a connection created by the {@link ConnectionService} and informs telecom of the new
1842 * connection.
1843 *
1844 * @param phoneAccountHandle The phone account handle for the connection.
1845 * @param connection The connection to add.
1846 * @param conference The parent conference of the new connection.
1847 * @hide
1848 */
1849 public final void addExistingConnection(PhoneAccountHandle phoneAccountHandle,
1850 Connection connection, Conference conference) {
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07001851
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001852 String id = addExistingConnectionInternal(phoneAccountHandle, connection);
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07001853 if (id != null) {
1854 List<String> emptyList = new ArrayList<>(0);
Tyler Gunn78da7812017-05-09 14:34:57 -07001855 String conferenceId = null;
1856 if (conference != null) {
1857 conferenceId = mIdByConference.get(conference);
1858 }
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07001859
1860 ParcelableConnection parcelableConnection = new ParcelableConnection(
1861 phoneAccountHandle,
1862 connection.getState(),
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001863 connection.getConnectionCapabilities(),
Tyler Gunn720c6642016-03-22 09:02:47 -07001864 connection.getConnectionProperties(),
Christine Hallstrom2830ce92016-11-30 16:06:42 -08001865 connection.getSupportedAudioRoutes(),
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07001866 connection.getAddress(),
1867 connection.getAddressPresentation(),
1868 connection.getCallerDisplayName(),
1869 connection.getCallerDisplayNamePresentation(),
1870 connection.getVideoProvider() == null ?
1871 null : connection.getVideoProvider().getInterface(),
1872 connection.getVideoState(),
1873 connection.isRingbackRequested(),
1874 connection.getAudioModeIsVoip(),
Roshan Piuse927ec02015-07-15 15:47:21 -07001875 connection.getConnectTimeMillis(),
Tyler Gunn3fa819c2017-08-04 09:27:26 -07001876 connection.getConnectElapsedTimeMillis(),
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07001877 connection.getStatusHints(),
1878 connection.getDisconnectCause(),
Santos Cordon6b7f9552015-05-27 17:21:45 -07001879 emptyList,
Tyler Gunn78da7812017-05-09 14:34:57 -07001880 connection.getExtras(),
1881 conferenceId);
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07001882 mAdapter.addExistingConnection(id, parcelableConnection);
1883 }
1884 }
1885
1886 /**
Ihab Awadf8b69882014-07-25 15:14:01 -07001887 * Returns all the active {@code Connection}s for which this {@code ConnectionService}
1888 * has taken responsibility.
1889 *
1890 * @return A collection of {@code Connection}s created by this {@code ConnectionService}.
Santos Cordonb6939982014-06-04 20:20:58 -07001891 */
Sailesh Nepal091768c2014-06-30 15:15:23 -07001892 public final Collection<Connection> getAllConnections() {
Santos Cordonb6939982014-06-04 20:20:58 -07001893 return mConnectionById.values();
1894 }
1895
1896 /**
Santos Cordona6018b92016-02-16 14:23:12 -08001897 * Returns all the active {@code Conference}s for which this {@code ConnectionService}
1898 * has taken responsibility.
1899 *
1900 * @return A collection of {@code Conference}s created by this {@code ConnectionService}.
1901 */
1902 public final Collection<Conference> getAllConferences() {
1903 return mConferenceById.values();
1904 }
1905
1906 /**
Ihab Awadf8b69882014-07-25 15:14:01 -07001907 * Create a {@code Connection} given an incoming request. This is used to attach to existing
1908 * incoming calls.
Evan Charltonbf11f982014-07-20 22:06:28 -07001909 *
Ihab Awadf8b69882014-07-25 15:14:01 -07001910 * @param connectionManagerPhoneAccount See description at
1911 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
1912 * @param request Details about the incoming call.
1913 * @return The {@code Connection} object to satisfy this call, or {@code null} to
1914 * not handle the call.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001915 */
Ihab Awadf8b69882014-07-25 15:14:01 -07001916 public Connection onCreateIncomingConnection(
1917 PhoneAccountHandle connectionManagerPhoneAccount,
1918 ConnectionRequest request) {
1919 return null;
1920 }
Sailesh Nepalc5b01572014-07-14 16:29:44 -07001921
1922 /**
Tyler Gunnd104a4f2017-05-12 10:04:49 -07001923 * Called after the {@link Connection} returned by
1924 * {@link #onCreateIncomingConnection(PhoneAccountHandle, ConnectionRequest)}
1925 * or {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)} has been
1926 * added to the {@link ConnectionService} and sent to Telecom.
1927 *
1928 * @param connection the {@link Connection}.
1929 * @hide
1930 */
1931 public void onCreateConnectionComplete(Connection connection) {
1932 }
1933
1934 /**
Tyler Gunnf5035432017-01-09 09:43:12 -08001935 * Called by Telecom to inform the {@link ConnectionService} that its request to create a new
1936 * incoming {@link Connection} was denied.
1937 * <p>
1938 * Used when a self-managed {@link ConnectionService} attempts to create a new incoming
1939 * {@link Connection}, but Telecom has determined that the call cannot be allowed at this time.
1940 * The {@link ConnectionService} is responsible for silently rejecting the new incoming
1941 * {@link Connection}.
1942 * <p>
1943 * See {@link TelecomManager#isIncomingCallPermitted(PhoneAccountHandle)} for more information.
1944 *
Tyler Gunn159f35c2017-03-02 09:28:37 -08001945 * @param connectionManagerPhoneAccount See description at
1946 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
Tyler Gunnf5035432017-01-09 09:43:12 -08001947 * @param request The incoming connection request.
1948 */
Tyler Gunn159f35c2017-03-02 09:28:37 -08001949 public void onCreateIncomingConnectionFailed(PhoneAccountHandle connectionManagerPhoneAccount,
1950 ConnectionRequest request) {
Tyler Gunnf5035432017-01-09 09:43:12 -08001951 }
1952
1953 /**
1954 * Called by Telecom to inform the {@link ConnectionService} that its request to create a new
1955 * outgoing {@link Connection} was denied.
1956 * <p>
1957 * Used when a self-managed {@link ConnectionService} attempts to create a new outgoing
1958 * {@link Connection}, but Telecom has determined that the call cannot be placed at this time.
1959 * The {@link ConnectionService} is responisible for informing the user that the
1960 * {@link Connection} cannot be made at this time.
1961 * <p>
1962 * See {@link TelecomManager#isOutgoingCallPermitted(PhoneAccountHandle)} for more information.
1963 *
Tyler Gunn159f35c2017-03-02 09:28:37 -08001964 * @param connectionManagerPhoneAccount See description at
1965 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
Tyler Gunnf5035432017-01-09 09:43:12 -08001966 * @param request The outgoing connection request.
1967 */
Tyler Gunn159f35c2017-03-02 09:28:37 -08001968 public void onCreateOutgoingConnectionFailed(PhoneAccountHandle connectionManagerPhoneAccount,
1969 ConnectionRequest request) {
Tyler Gunnf5035432017-01-09 09:43:12 -08001970 }
1971
1972 /**
Shriram Ganesh6bf35ac2014-12-11 17:53:38 -08001973 * Trigger recalculate functinality for conference calls. This is used when a Telephony
1974 * Connection is part of a conference controller but is not yet added to Connection
1975 * Service and hence cannot be added to the conference call.
1976 *
1977 * @hide
1978 */
1979 public void triggerConferenceRecalculate() {
1980 }
1981
1982 /**
Ihab Awadf8b69882014-07-25 15:14:01 -07001983 * Create a {@code Connection} given an outgoing request. This is used to initiate new
1984 * outgoing calls.
Sailesh Nepalc5b01572014-07-14 16:29:44 -07001985 *
Ihab Awadf8b69882014-07-25 15:14:01 -07001986 * @param connectionManagerPhoneAccount The connection manager account to use for managing
1987 * this call.
1988 * <p>
1989 * If this parameter is not {@code null}, it means that this {@code ConnectionService}
1990 * has registered one or more {@code PhoneAccount}s having
1991 * {@link PhoneAccount#CAPABILITY_CONNECTION_MANAGER}. This parameter will contain
1992 * one of these {@code PhoneAccount}s, while the {@code request} will contain another
1993 * (usually but not always distinct) {@code PhoneAccount} to be used for actually
1994 * making the connection.
1995 * <p>
1996 * If this parameter is {@code null}, it means that this {@code ConnectionService} is
1997 * being asked to make a direct connection. The
1998 * {@link ConnectionRequest#getAccountHandle()} of parameter {@code request} will be
1999 * a {@code PhoneAccount} registered by this {@code ConnectionService} to use for
2000 * making the connection.
2001 * @param request Details about the outgoing call.
2002 * @return The {@code Connection} object to satisfy this call, or the result of an invocation
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002003 * of {@link Connection#createFailedConnection(DisconnectCause)} to not handle the call.
Sailesh Nepalc5b01572014-07-14 16:29:44 -07002004 */
Ihab Awadf8b69882014-07-25 15:14:01 -07002005 public Connection onCreateOutgoingConnection(
2006 PhoneAccountHandle connectionManagerPhoneAccount,
2007 ConnectionRequest request) {
2008 return null;
2009 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002010
2011 /**
Yorke Leec3cf9822014-10-02 09:38:39 -07002012 * Create a {@code Connection} for a new unknown call. An unknown call is a call originating
2013 * from the ConnectionService that was neither a user-initiated outgoing call, nor an incoming
2014 * call created using
2015 * {@code TelecomManager#addNewIncomingCall(PhoneAccountHandle, android.os.Bundle)}.
2016 *
Yorke Lee770ed6e2014-10-06 18:58:52 -07002017 * @hide
Yorke Leec3cf9822014-10-02 09:38:39 -07002018 */
2019 public Connection onCreateUnknownConnection(PhoneAccountHandle connectionManagerPhoneAccount,
2020 ConnectionRequest request) {
Brad Ebingerb32d4f82016-10-24 16:40:49 -07002021 return null;
Yorke Leec3cf9822014-10-02 09:38:39 -07002022 }
2023
2024 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07002025 * Conference two specified connections. Invoked when the user has made a request to merge the
2026 * specified connections into a conference call. In response, the connection service should
2027 * create an instance of {@link Conference} and pass it into {@link #addConference}.
Santos Cordonb6939982014-06-04 20:20:58 -07002028 *
Santos Cordon823fd3c2014-08-07 18:35:18 -07002029 * @param connection1 A connection to merge into a conference call.
2030 * @param connection2 A connection to merge into a conference call.
Santos Cordonb6939982014-06-04 20:20:58 -07002031 */
Santos Cordon823fd3c2014-08-07 18:35:18 -07002032 public void onConference(Connection connection1, Connection connection2) {}
Santos Cordonb6939982014-06-04 20:20:58 -07002033
Santos Cordona663f862014-10-29 13:49:58 -07002034 /**
2035 * Indicates that a remote conference has been created for existing {@link RemoteConnection}s.
2036 * When this method is invoked, this {@link ConnectionService} should create its own
2037 * representation of the conference call and send it to telecom using {@link #addConference}.
2038 * <p>
2039 * This is only relevant to {@link ConnectionService}s which are registered with
2040 * {@link PhoneAccount#CAPABILITY_CONNECTION_MANAGER}.
2041 *
2042 * @param conference The remote conference call.
2043 */
Ihab Awadb8e85c72014-08-23 20:34:57 -07002044 public void onRemoteConferenceAdded(RemoteConference conference) {}
2045
Santos Cordon823fd3c2014-08-07 18:35:18 -07002046 /**
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002047 * Called when an existing connection is added remotely.
2048 * @param connection The existing connection which was added.
2049 */
2050 public void onRemoteExistingConnectionAdded(RemoteConnection connection) {}
2051
2052 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07002053 * @hide
2054 */
2055 public boolean containsConference(Conference conference) {
2056 return mIdByConference.containsKey(conference);
2057 }
2058
Ihab Awadb8e85c72014-08-23 20:34:57 -07002059 /** {@hide} */
2060 void addRemoteConference(RemoteConference remoteConference) {
2061 onRemoteConferenceAdded(remoteConference);
2062 }
2063
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002064 /** {@hide} */
2065 void addRemoteExistingConnection(RemoteConnection remoteConnection) {
2066 onRemoteExistingConnectionAdded(remoteConnection);
2067 }
2068
Ihab Awad5d0410f2014-07-30 10:07:40 -07002069 private void onAccountsInitialized() {
2070 mAreAccountsInitialized = true;
2071 for (Runnable r : mPreInitializationConnectionRequests) {
2072 r.run();
2073 }
2074 mPreInitializationConnectionRequests.clear();
2075 }
2076
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002077 /**
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002078 * Adds an existing connection to the list of connections, identified by a new call ID unique
2079 * to this connection service.
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002080 *
2081 * @param connection The connection.
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002082 * @return The ID of the connection (e.g. the call-id).
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002083 */
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002084 private String addExistingConnectionInternal(PhoneAccountHandle handle, Connection connection) {
2085 String id;
Tyler Gunncd6ccfd2016-10-17 15:48:19 -07002086
2087 if (connection.getExtras() != null && connection.getExtras()
2088 .containsKey(Connection.EXTRA_ORIGINAL_CONNECTION_ID)) {
2089 id = connection.getExtras().getString(Connection.EXTRA_ORIGINAL_CONNECTION_ID);
2090 Log.d(this, "addExistingConnectionInternal - conn %s reusing original id %s",
2091 connection.getTelecomCallId(), id);
2092 } else if (handle == null) {
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002093 // If no phone account handle was provided, we cannot be sure the call ID is unique,
2094 // so just use a random UUID.
2095 id = UUID.randomUUID().toString();
2096 } else {
2097 // Phone account handle was provided, so use the ConnectionService class name as a
2098 // prefix for a unique incremental call ID.
2099 id = handle.getComponentName().getClassName() + "@" + getNextCallId();
2100 }
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002101 addConnection(id, connection);
2102 return id;
2103 }
2104
Ihab Awad542e0ea2014-05-16 10:22:16 -07002105 private void addConnection(String callId, Connection connection) {
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002106 connection.setTelecomCallId(callId);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002107 mConnectionById.put(callId, connection);
2108 mIdByConnection.put(connection, callId);
2109 connection.addConnectionListener(mConnectionListener);
Santos Cordon823fd3c2014-08-07 18:35:18 -07002110 connection.setConnectionService(this);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002111 }
2112
Anthony Lee30e65842014-11-06 16:30:53 -08002113 /** {@hide} */
2114 protected void removeConnection(Connection connection) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07002115 connection.unsetConnectionService(this);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002116 connection.removeConnectionListener(mConnectionListener);
Chenjie Luoe370b532016-05-12 16:59:43 -07002117 String id = mIdByConnection.get(connection);
2118 if (id != null) {
2119 mConnectionById.remove(id);
2120 mIdByConnection.remove(connection);
2121 mAdapter.removeCall(id);
2122 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002123 }
2124
Santos Cordon823fd3c2014-08-07 18:35:18 -07002125 private String addConferenceInternal(Conference conference) {
Tyler Gunncd6ccfd2016-10-17 15:48:19 -07002126 String originalId = null;
2127 if (conference.getExtras() != null && conference.getExtras()
2128 .containsKey(Connection.EXTRA_ORIGINAL_CONNECTION_ID)) {
2129 originalId = conference.getExtras().getString(Connection.EXTRA_ORIGINAL_CONNECTION_ID);
2130 Log.d(this, "addConferenceInternal: conf %s reusing original id %s",
2131 conference.getTelecomCallId(),
2132 originalId);
2133 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07002134 if (mIdByConference.containsKey(conference)) {
2135 Log.w(this, "Re-adding an existing conference: %s.", conference);
2136 } else if (conference != null) {
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002137 // Conferences do not (yet) have a PhoneAccountHandle associated with them, so we
2138 // cannot determine a ConnectionService class name to associate with the ID, so use
2139 // a unique UUID (for now).
Tyler Gunncd6ccfd2016-10-17 15:48:19 -07002140 String id = originalId == null ? UUID.randomUUID().toString() : originalId;
Santos Cordon823fd3c2014-08-07 18:35:18 -07002141 mConferenceById.put(id, conference);
2142 mIdByConference.put(conference, id);
2143 conference.addListener(mConferenceListener);
2144 return id;
2145 }
2146
2147 return null;
2148 }
2149
2150 private void removeConference(Conference conference) {
2151 if (mIdByConference.containsKey(conference)) {
2152 conference.removeListener(mConferenceListener);
2153
2154 String id = mIdByConference.get(conference);
2155 mConferenceById.remove(id);
2156 mIdByConference.remove(conference);
2157 mAdapter.removeCall(id);
2158 }
2159 }
2160
Ihab Awad542e0ea2014-05-16 10:22:16 -07002161 private Connection findConnectionForAction(String callId, String action) {
2162 if (mConnectionById.containsKey(callId)) {
2163 return mConnectionById.get(callId);
2164 }
Ihab Awad60ac30b2014-05-20 22:32:12 -07002165 Log.w(this, "%s - Cannot find Connection %s", action, callId);
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07002166 return getNullConnection();
2167 }
2168
2169 static synchronized Connection getNullConnection() {
2170 if (sNullConnection == null) {
2171 sNullConnection = new Connection() {};
2172 }
2173 return sNullConnection;
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002174 }
Santos Cordon0159ac02014-08-21 14:28:11 -07002175
2176 private Conference findConferenceForAction(String conferenceId, String action) {
2177 if (mConferenceById.containsKey(conferenceId)) {
2178 return mConferenceById.get(conferenceId);
2179 }
2180 Log.w(this, "%s - Cannot find conference %s", action, conferenceId);
2181 return getNullConference();
2182 }
2183
Ihab Awadb8e85c72014-08-23 20:34:57 -07002184 private List<String> createConnectionIdList(List<Connection> connections) {
2185 List<String> ids = new ArrayList<>();
2186 for (Connection c : connections) {
2187 if (mIdByConnection.containsKey(c)) {
2188 ids.add(mIdByConnection.get(c));
2189 }
2190 }
2191 Collections.sort(ids);
2192 return ids;
2193 }
2194
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002195 /**
2196 * Builds a list of {@link Connection} and {@link Conference} IDs based on the list of
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002197 * {@link Conferenceable}s passed in.
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002198 *
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002199 * @param conferenceables The {@link Conferenceable} connections and conferences.
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002200 * @return List of string conference and call Ids.
2201 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002202 private List<String> createIdList(List<Conferenceable> conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002203 List<String> ids = new ArrayList<>();
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002204 for (Conferenceable c : conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002205 // Only allow Connection and Conference conferenceables.
2206 if (c instanceof Connection) {
2207 Connection connection = (Connection) c;
2208 if (mIdByConnection.containsKey(connection)) {
2209 ids.add(mIdByConnection.get(connection));
2210 }
2211 } else if (c instanceof Conference) {
2212 Conference conference = (Conference) c;
2213 if (mIdByConference.containsKey(conference)) {
2214 ids.add(mIdByConference.get(conference));
2215 }
2216 }
2217 }
2218 Collections.sort(ids);
2219 return ids;
2220 }
2221
Santos Cordon0159ac02014-08-21 14:28:11 -07002222 private Conference getNullConference() {
2223 if (sNullConference == null) {
2224 sNullConference = new Conference(null) {};
2225 }
2226 return sNullConference;
2227 }
Santos Cordon29f2f2e2014-09-11 19:50:24 -07002228
2229 private void endAllConnections() {
2230 // Unbound from telecomm. We should end all connections and conferences.
2231 for (Connection connection : mIdByConnection.keySet()) {
2232 // only operate on top-level calls. Conference calls will be removed on their own.
2233 if (connection.getConference() == null) {
2234 connection.onDisconnect();
2235 }
2236 }
2237 for (Conference conference : mIdByConference.keySet()) {
2238 conference.onDisconnect();
2239 }
2240 }
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002241
2242 /**
2243 * Retrieves the next call ID as maintainted by the connection service.
2244 *
2245 * @return The call ID.
2246 */
2247 private int getNextCallId() {
Brad Ebingerb32d4f82016-10-24 16:40:49 -07002248 synchronized (mIdSyncRoot) {
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002249 return ++mId;
2250 }
2251 }
Santos Cordon980acb92014-05-31 10:31:19 -07002252}