blob: 1ffc83fef55d396890f8d343aeea21648e01d6ac [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 Liu57006aa2017-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 Gunn3edafc12017-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 Liu57006aa2017-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 Gunn3edafc12017-01-31 10:49:05 -0800152 private static final int MSG_CREATE_CONNECTION_FAILED = 25;
Hall Liu57006aa2017-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 Gunn3edafc12017-01-31 10:49:05 -0800239 public void createConnectionFailed(
Tyler Gunn159f35c2017-03-02 09:28:37 -0800240 PhoneAccountHandle connectionManagerPhoneAccount,
Tyler Gunn3edafc12017-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 Gunn3edafc12017-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 Liu57006aa2017-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 Gunn3edafc12017-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 Gunn3edafc12017-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 Gunn3edafc12017-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 Gunn3edafc12017-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 Liu57006aa2017-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 Liu57006aa2017-02-06 10:49:48 -08001285
1286 @Override
1287 public void onRttInitiationSuccess(Connection c) {
1288 String id = mIdByConnection.get(c);
1289 if (id != null) {
1290 mAdapter.onRttInitiationSuccess(id);
1291 }
1292 }
1293
1294 @Override
1295 public void onRttInitiationFailure(Connection c, int reason) {
1296 String id = mIdByConnection.get(c);
1297 if (id != null) {
1298 mAdapter.onRttInitiationFailure(id, reason);
1299 }
1300 }
1301
1302 @Override
1303 public void onRttSessionRemotelyTerminated(Connection c) {
1304 String id = mIdByConnection.get(c);
1305 if (id != null) {
1306 mAdapter.onRttSessionRemotelyTerminated(id);
1307 }
1308 }
1309
1310 @Override
1311 public void onRemoteRttRequest(Connection c) {
1312 String id = mIdByConnection.get(c);
1313 if (id != null) {
1314 mAdapter.onRemoteRttRequest(id);
1315 }
1316 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001317 };
1318
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001319 /** {@inheritDoc} */
Ihab Awad542e0ea2014-05-16 10:22:16 -07001320 @Override
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001321 public final IBinder onBind(Intent intent) {
1322 return mBinder;
1323 }
1324
Santos Cordon29f2f2e2014-09-11 19:50:24 -07001325 /** {@inheritDoc} */
1326 @Override
1327 public boolean onUnbind(Intent intent) {
1328 endAllConnections();
1329 return super.onUnbind(intent);
1330 }
1331
Sailesh Nepalc5b01572014-07-14 16:29:44 -07001332 /**
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001333 * This can be used by telecom to either create a new outgoing call or attach to an existing
1334 * incoming call. In either case, telecom will cycle through a set of services and call
Sailesh Nepalc5b01572014-07-14 16:29:44 -07001335 * createConnection util a connection service cancels the process or completes it successfully.
1336 */
Ihab Awadf8b69882014-07-25 15:14:01 -07001337 private void createConnection(
1338 final PhoneAccountHandle callManagerAccount,
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001339 final String callId,
Ihab Awadf8b69882014-07-25 15:14:01 -07001340 final ConnectionRequest request,
Yorke Leec3cf9822014-10-02 09:38:39 -07001341 boolean isIncoming,
1342 boolean isUnknown) {
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001343 Log.d(this, "createConnection, callManagerAccount: %s, callId: %s, request: %s, " +
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001344 "isIncoming: %b, isUnknown: %b", callManagerAccount, callId, request,
1345 isIncoming,
Yorke Leec3cf9822014-10-02 09:38:39 -07001346 isUnknown);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001347
Yorke Leec3cf9822014-10-02 09:38:39 -07001348 Connection connection = isUnknown ? onCreateUnknownConnection(callManagerAccount, request)
1349 : isIncoming ? onCreateIncomingConnection(callManagerAccount, request)
Ihab Awad6107bab2014-08-18 09:23:25 -07001350 : onCreateOutgoingConnection(callManagerAccount, request);
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001351 Log.d(this, "createConnection, connection: %s", connection);
1352 if (connection == null) {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001353 connection = Connection.createFailedConnection(
1354 new DisconnectCause(DisconnectCause.ERROR));
Sailesh Nepalc5b01572014-07-14 16:29:44 -07001355 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001356
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001357 connection.setTelecomCallId(callId);
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001358 if (connection.getState() != Connection.STATE_DISCONNECTED) {
Ihab Awad6107bab2014-08-18 09:23:25 -07001359 addConnection(callId, connection);
1360 }
1361
Andrew Lee100e2932014-09-08 15:34:24 -07001362 Uri address = connection.getAddress();
1363 String number = address == null ? "null" : address.getSchemeSpecificPart();
Tyler Gunn720c6642016-03-22 09:02:47 -07001364 Log.v(this, "createConnection, number: %s, state: %s, capabilities: %s, properties: %s",
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001365 Connection.toLogSafePhoneNumber(number),
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001366 Connection.stateToString(connection.getState()),
Tyler Gunn720c6642016-03-22 09:02:47 -07001367 Connection.capabilitiesToString(connection.getConnectionCapabilities()),
1368 Connection.propertiesToString(connection.getConnectionProperties()));
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001369
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001370 Log.d(this, "createConnection, calling handleCreateConnectionSuccessful %s", callId);
Ihab Awad6107bab2014-08-18 09:23:25 -07001371 mAdapter.handleCreateConnectionComplete(
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001372 callId,
Evan Charltonbf11f982014-07-20 22:06:28 -07001373 request,
1374 new ParcelableConnection(
1375 request.getAccountHandle(),
1376 connection.getState(),
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001377 connection.getConnectionCapabilities(),
Tyler Gunn720c6642016-03-22 09:02:47 -07001378 connection.getConnectionProperties(),
Christine Hallstrom4e22d6d2016-11-30 16:06:42 -08001379 connection.getSupportedAudioRoutes(),
Andrew Lee100e2932014-09-08 15:34:24 -07001380 connection.getAddress(),
1381 connection.getAddressPresentation(),
Evan Charltonbf11f982014-07-20 22:06:28 -07001382 connection.getCallerDisplayName(),
1383 connection.getCallerDisplayNamePresentation(),
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001384 connection.getVideoProvider() == null ?
1385 null : connection.getVideoProvider().getInterface(),
Sailesh Nepal8b9d3ca2014-08-14 17:39:34 -07001386 connection.getVideoState(),
Andrew Lee100e2932014-09-08 15:34:24 -07001387 connection.isRingbackRequested(),
Sailesh Nepal8b9d3ca2014-08-14 17:39:34 -07001388 connection.getAudioModeIsVoip(),
Roshan Piuse927ec02015-07-15 15:47:21 -07001389 connection.getConnectTimeMillis(),
Ihab Awad6107bab2014-08-18 09:23:25 -07001390 connection.getStatusHints(),
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001391 connection.getDisconnectCause(),
Santos Cordon6b7f9552015-05-27 17:21:45 -07001392 createIdList(connection.getConferenceables()),
1393 connection.getExtras()));
Tyler Gunnf5035432017-01-09 09:43:12 -08001394
1395 if (isIncoming && request.shouldShowIncomingCallUi() &&
1396 (connection.getConnectionProperties() & Connection.PROPERTY_SELF_MANAGED) ==
1397 Connection.PROPERTY_SELF_MANAGED) {
1398 // Tell ConnectionService to show its incoming call UX.
1399 connection.onShowIncomingCallUi();
1400 }
Shriram Ganesh6bf35ac2014-12-11 17:53:38 -08001401 if (isUnknown) {
1402 triggerConferenceRecalculate();
1403 }
Evan Charltonbf11f982014-07-20 22:06:28 -07001404 }
1405
Tyler Gunn159f35c2017-03-02 09:28:37 -08001406 private void createConnectionFailed(final PhoneAccountHandle callManagerAccount,
1407 final String callId, final ConnectionRequest request,
1408 boolean isIncoming) {
Tyler Gunn3edafc12017-01-31 10:49:05 -08001409
1410 Log.i(this, "createConnectionFailed %s", callId);
1411 if (isIncoming) {
Tyler Gunn159f35c2017-03-02 09:28:37 -08001412 onCreateIncomingConnectionFailed(callManagerAccount, request);
Tyler Gunn3edafc12017-01-31 10:49:05 -08001413 } else {
Tyler Gunn159f35c2017-03-02 09:28:37 -08001414 onCreateOutgoingConnectionFailed(callManagerAccount, request);
Tyler Gunn3edafc12017-01-31 10:49:05 -08001415 }
1416 }
1417
Tyler Gunnd104a4f2017-05-12 10:04:49 -07001418 /**
1419 * Called by Telecom when the creation of a new Connection has completed and it is now added
1420 * to Telecom.
1421 * @param callId The ID of the connection.
1422 */
1423 private void notifyCreateConnectionComplete(final String callId) {
1424 Log.i(this, "notifyCreateConnectionComplete %s", callId);
1425 onCreateConnectionComplete(findConnectionForAction(callId,
1426 "notifyCreateConnectionComplete"));
1427 }
1428
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001429 private void abort(String callId) {
Ihab Awad60ac30b2014-05-20 22:32:12 -07001430 Log.d(this, "abort %s", callId);
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001431 findConnectionForAction(callId, "abort").onAbort();
Ihab Awad542e0ea2014-05-16 10:22:16 -07001432 }
1433
Tyler Gunnbe74de02014-08-29 14:51:48 -07001434 private void answerVideo(String callId, int videoState) {
1435 Log.d(this, "answerVideo %s", callId);
Andrew Lee8da4c3c2014-07-16 10:11:42 -07001436 findConnectionForAction(callId, "answer").onAnswer(videoState);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001437 }
1438
Tyler Gunnbe74de02014-08-29 14:51:48 -07001439 private void answer(String callId) {
1440 Log.d(this, "answer %s", callId);
1441 findConnectionForAction(callId, "answer").onAnswer();
1442 }
1443
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001444 private void reject(String callId) {
Ihab Awad60ac30b2014-05-20 22:32:12 -07001445 Log.d(this, "reject %s", callId);
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001446 findConnectionForAction(callId, "reject").onReject();
Ihab Awad542e0ea2014-05-16 10:22:16 -07001447 }
1448
Bryce Lee81901682015-08-28 16:38:02 -07001449 private void reject(String callId, String rejectWithMessage) {
1450 Log.d(this, "reject %s with message", callId);
1451 findConnectionForAction(callId, "reject").onReject(rejectWithMessage);
1452 }
1453
Bryce Leecac50772015-11-17 15:13:29 -08001454 private void silence(String callId) {
1455 Log.d(this, "silence %s", callId);
1456 findConnectionForAction(callId, "silence").onSilence();
1457 }
1458
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001459 private void disconnect(String callId) {
Ihab Awad60ac30b2014-05-20 22:32:12 -07001460 Log.d(this, "disconnect %s", callId);
Santos Cordon0159ac02014-08-21 14:28:11 -07001461 if (mConnectionById.containsKey(callId)) {
1462 findConnectionForAction(callId, "disconnect").onDisconnect();
1463 } else {
1464 findConferenceForAction(callId, "disconnect").onDisconnect();
1465 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001466 }
1467
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001468 private void hold(String callId) {
Ihab Awad60ac30b2014-05-20 22:32:12 -07001469 Log.d(this, "hold %s", callId);
Santos Cordon0159ac02014-08-21 14:28:11 -07001470 if (mConnectionById.containsKey(callId)) {
1471 findConnectionForAction(callId, "hold").onHold();
1472 } else {
1473 findConferenceForAction(callId, "hold").onHold();
1474 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001475 }
1476
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001477 private void unhold(String callId) {
Ihab Awad60ac30b2014-05-20 22:32:12 -07001478 Log.d(this, "unhold %s", callId);
Santos Cordon0159ac02014-08-21 14:28:11 -07001479 if (mConnectionById.containsKey(callId)) {
1480 findConnectionForAction(callId, "unhold").onUnhold();
1481 } else {
1482 findConferenceForAction(callId, "unhold").onUnhold();
1483 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001484 }
1485
Yorke Lee4af59352015-05-13 14:14:54 -07001486 private void onCallAudioStateChanged(String callId, CallAudioState callAudioState) {
1487 Log.d(this, "onAudioStateChanged %s %s", callId, callAudioState);
Yorke Leea0d3ca92014-09-15 19:18:13 -07001488 if (mConnectionById.containsKey(callId)) {
Yorke Lee4af59352015-05-13 14:14:54 -07001489 findConnectionForAction(callId, "onCallAudioStateChanged").setCallAudioState(
1490 callAudioState);
Yorke Leea0d3ca92014-09-15 19:18:13 -07001491 } else {
Yorke Lee4af59352015-05-13 14:14:54 -07001492 findConferenceForAction(callId, "onCallAudioStateChanged").setCallAudioState(
1493 callAudioState);
Yorke Leea0d3ca92014-09-15 19:18:13 -07001494 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001495 }
1496
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001497 private void playDtmfTone(String callId, char digit) {
1498 Log.d(this, "playDtmfTone %s %c", callId, digit);
Yorke Leea0d3ca92014-09-15 19:18:13 -07001499 if (mConnectionById.containsKey(callId)) {
1500 findConnectionForAction(callId, "playDtmfTone").onPlayDtmfTone(digit);
1501 } else {
1502 findConferenceForAction(callId, "playDtmfTone").onPlayDtmfTone(digit);
1503 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001504 }
1505
1506 private void stopDtmfTone(String callId) {
1507 Log.d(this, "stopDtmfTone %s", callId);
Yorke Leea0d3ca92014-09-15 19:18:13 -07001508 if (mConnectionById.containsKey(callId)) {
1509 findConnectionForAction(callId, "stopDtmfTone").onStopDtmfTone();
1510 } else {
1511 findConferenceForAction(callId, "stopDtmfTone").onStopDtmfTone();
1512 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001513 }
1514
Santos Cordon823fd3c2014-08-07 18:35:18 -07001515 private void conference(String callId1, String callId2) {
1516 Log.d(this, "conference %s, %s", callId1, callId2);
Santos Cordon980acb92014-05-31 10:31:19 -07001517
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001518 // Attempt to get second connection or conference.
Santos Cordon823fd3c2014-08-07 18:35:18 -07001519 Connection connection2 = findConnectionForAction(callId2, "conference");
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001520 Conference conference2 = getNullConference();
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001521 if (connection2 == getNullConnection()) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001522 conference2 = findConferenceForAction(callId2, "conference");
1523 if (conference2 == getNullConference()) {
1524 Log.w(this, "Connection2 or Conference2 missing in conference request %s.",
1525 callId2);
1526 return;
1527 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07001528 }
Santos Cordonb6939982014-06-04 20:20:58 -07001529
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001530 // Attempt to get first connection or conference and perform merge.
Ihab Awad50e35062014-09-30 09:17:03 -07001531 Connection connection1 = findConnectionForAction(callId1, "conference");
1532 if (connection1 == getNullConnection()) {
1533 Conference conference1 = findConferenceForAction(callId1, "addConnection");
1534 if (conference1 == getNullConference()) {
1535 Log.w(this,
1536 "Connection1 or Conference1 missing in conference request %s.",
1537 callId1);
1538 } else {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001539 // Call 1 is a conference.
1540 if (connection2 != getNullConnection()) {
1541 // Call 2 is a connection so merge via call 1 (conference).
1542 conference1.onMerge(connection2);
1543 } else {
1544 // Call 2 is ALSO a conference; this should never happen.
1545 Log.wtf(this, "There can only be one conference and an attempt was made to " +
1546 "merge two conferences.");
1547 return;
1548 }
Ihab Awad50e35062014-09-30 09:17:03 -07001549 }
1550 } else {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001551 // Call 1 is a connection.
1552 if (conference2 != getNullConference()) {
1553 // Call 2 is a conference, so merge via call 2.
1554 conference2.onMerge(connection1);
1555 } else {
1556 // Call 2 is a connection, so merge together.
1557 onConference(connection1, connection2);
1558 }
Ihab Awad50e35062014-09-30 09:17:03 -07001559 }
Santos Cordon980acb92014-05-31 10:31:19 -07001560 }
1561
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001562 private void splitFromConference(String callId) {
Santos Cordonb6939982014-06-04 20:20:58 -07001563 Log.d(this, "splitFromConference(%s)", callId);
Santos Cordon980acb92014-05-31 10:31:19 -07001564
1565 Connection connection = findConnectionForAction(callId, "splitFromConference");
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001566 if (connection == getNullConnection()) {
Santos Cordon980acb92014-05-31 10:31:19 -07001567 Log.w(this, "Connection missing in conference request %s.", callId);
1568 return;
1569 }
1570
Santos Cordon0159ac02014-08-21 14:28:11 -07001571 Conference conference = connection.getConference();
1572 if (conference != null) {
1573 conference.onSeparate(connection);
1574 }
Santos Cordon980acb92014-05-31 10:31:19 -07001575 }
1576
Santos Cordona4868042014-09-04 17:39:22 -07001577 private void mergeConference(String callId) {
1578 Log.d(this, "mergeConference(%s)", callId);
1579 Conference conference = findConferenceForAction(callId, "mergeConference");
1580 if (conference != null) {
1581 conference.onMerge();
1582 }
1583 }
1584
1585 private void swapConference(String callId) {
1586 Log.d(this, "swapConference(%s)", callId);
1587 Conference conference = findConferenceForAction(callId, "swapConference");
1588 if (conference != null) {
1589 conference.onSwap();
1590 }
1591 }
1592
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001593 /**
1594 * Notifies a {@link Connection} of a request to pull an external call.
1595 *
1596 * See {@link Call#pullExternalCall()}.
1597 *
1598 * @param callId The ID of the call to pull.
1599 */
1600 private void pullExternalCall(String callId) {
1601 Log.d(this, "pullExternalCall(%s)", callId);
1602 Connection connection = findConnectionForAction(callId, "pullExternalCall");
1603 if (connection != null) {
1604 connection.onPullExternalCall();
1605 }
1606 }
1607
1608 /**
1609 * Notifies a {@link Connection} of a call event.
1610 *
1611 * See {@link Call#sendCallEvent(String, Bundle)}.
1612 *
1613 * @param callId The ID of the call receiving the event.
1614 * @param event The event.
1615 * @param extras Extras associated with the event.
1616 */
1617 private void sendCallEvent(String callId, String event, Bundle extras) {
1618 Log.d(this, "sendCallEvent(%s, %s)", callId, event);
1619 Connection connection = findConnectionForAction(callId, "sendCallEvent");
1620 if (connection != null) {
1621 connection.onCallEvent(event, extras);
1622 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001623 }
1624
Tyler Gunndee56a82016-03-23 16:06:34 -07001625 /**
1626 * Notifies a {@link Connection} or {@link Conference} of a change to the extras from Telecom.
1627 * <p>
1628 * These extra changes can originate from Telecom itself, or from an {@link InCallService} via
1629 * the {@link android.telecom.Call#putExtra(String, boolean)},
1630 * {@link android.telecom.Call#putExtra(String, int)},
1631 * {@link android.telecom.Call#putExtra(String, String)},
1632 * {@link Call#removeExtras(List)}.
1633 *
1634 * @param callId The ID of the call receiving the event.
1635 * @param extras The new extras bundle.
1636 */
1637 private void handleExtrasChanged(String callId, Bundle extras) {
1638 Log.d(this, "handleExtrasChanged(%s, %s)", callId, extras);
1639 if (mConnectionById.containsKey(callId)) {
1640 findConnectionForAction(callId, "handleExtrasChanged").handleExtrasChanged(extras);
1641 } else if (mConferenceById.containsKey(callId)) {
1642 findConferenceForAction(callId, "handleExtrasChanged").handleExtrasChanged(extras);
1643 }
1644 }
1645
Hall Liu57006aa2017-02-06 10:49:48 -08001646 private void startRtt(String callId, Connection.RttTextStream rttTextStream) {
1647 Log.d(this, "startRtt(%s)", callId);
1648 if (mConnectionById.containsKey(callId)) {
1649 findConnectionForAction(callId, "startRtt").onStartRtt(rttTextStream);
1650 } else if (mConferenceById.containsKey(callId)) {
1651 Log.w(this, "startRtt called on a conference.");
1652 }
1653 }
1654
1655 private void stopRtt(String callId) {
1656 Log.d(this, "stopRtt(%s)", callId);
1657 if (mConnectionById.containsKey(callId)) {
1658 findConnectionForAction(callId, "stopRtt").onStopRtt();
1659 } else if (mConferenceById.containsKey(callId)) {
1660 Log.w(this, "stopRtt called on a conference.");
1661 }
1662 }
1663
1664 private void handleRttUpgradeResponse(String callId, Connection.RttTextStream rttTextStream) {
1665 Log.d(this, "handleRttUpgradeResponse(%s, %s)", callId, rttTextStream == null);
1666 if (mConnectionById.containsKey(callId)) {
1667 findConnectionForAction(callId, "handleRttUpgradeResponse")
1668 .handleRttUpgradeResponse(rttTextStream);
1669 } else if (mConferenceById.containsKey(callId)) {
1670 Log.w(this, "handleRttUpgradeResponse called on a conference.");
1671 }
1672 }
1673
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001674 private void onPostDialContinue(String callId, boolean proceed) {
Evan Charlton6dea4ac2014-06-03 14:07:13 -07001675 Log.d(this, "onPostDialContinue(%s)", callId);
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001676 findConnectionForAction(callId, "stopDtmfTone").onPostDialContinue(proceed);
Evan Charlton6dea4ac2014-06-03 14:07:13 -07001677 }
1678
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001679 private void onAdapterAttached() {
Ihab Awad9c3f1882014-06-30 21:17:13 -07001680 if (mAreAccountsInitialized) {
Santos Cordon52d8a152014-06-17 19:08:45 -07001681 // No need to query again if we already did it.
1682 return;
1683 }
1684
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001685 mAdapter.queryRemoteConnectionServices(new RemoteServiceCallback.Stub() {
Santos Cordon52d8a152014-06-17 19:08:45 -07001686 @Override
1687 public void onResult(
1688 final List<ComponentName> componentNames,
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001689 final List<IBinder> services) {
Brad Ebinger0c3541b2016-11-01 14:11:38 -07001690 mHandler.post(new android.telecom.Logging.Runnable("oAA.qRCS.oR", null /*lock*/) {
Ihab Awad6107bab2014-08-18 09:23:25 -07001691 @Override
Brad Ebinger0c3541b2016-11-01 14:11:38 -07001692 public void loggedRun() {
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001693 for (int i = 0; i < componentNames.size() && i < services.size(); i++) {
Santos Cordon52d8a152014-06-17 19:08:45 -07001694 mRemoteConnectionManager.addConnectionService(
1695 componentNames.get(i),
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001696 IConnectionService.Stub.asInterface(services.get(i)));
Santos Cordon52d8a152014-06-17 19:08:45 -07001697 }
Ihab Awad5d0410f2014-07-30 10:07:40 -07001698 onAccountsInitialized();
Sailesh Nepalc5b01572014-07-14 16:29:44 -07001699 Log.d(this, "remote connection services found: " + services);
Santos Cordon52d8a152014-06-17 19:08:45 -07001700 }
Brad Ebinger0c3541b2016-11-01 14:11:38 -07001701 }.prepare());
Santos Cordon52d8a152014-06-17 19:08:45 -07001702 }
1703
1704 @Override
1705 public void onError() {
Brad Ebinger0c3541b2016-11-01 14:11:38 -07001706 mHandler.post(new android.telecom.Logging.Runnable("oAA.qRCS.oE", null /*lock*/) {
Ihab Awad6107bab2014-08-18 09:23:25 -07001707 @Override
Brad Ebinger0c3541b2016-11-01 14:11:38 -07001708 public void loggedRun() {
Ihab Awad9c3f1882014-06-30 21:17:13 -07001709 mAreAccountsInitialized = true;
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 }
1715
Ihab Awadf8b69882014-07-25 15:14:01 -07001716 /**
1717 * Ask some other {@code ConnectionService} to create a {@code RemoteConnection} given an
Santos Cordona663f862014-10-29 13:49:58 -07001718 * incoming request. This is used by {@code ConnectionService}s that are registered with
1719 * {@link PhoneAccount#CAPABILITY_CONNECTION_MANAGER} and want to be able to manage
1720 * SIM-based incoming calls.
Ihab Awadf8b69882014-07-25 15:14:01 -07001721 *
1722 * @param connectionManagerPhoneAccount See description at
1723 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
1724 * @param request Details about the incoming call.
1725 * @return The {@code Connection} object to satisfy this call, or {@code null} to
1726 * not handle the call.
1727 */
1728 public final RemoteConnection createRemoteIncomingConnection(
1729 PhoneAccountHandle connectionManagerPhoneAccount,
1730 ConnectionRequest request) {
1731 return mRemoteConnectionManager.createRemoteConnection(
1732 connectionManagerPhoneAccount, request, true);
Santos Cordon52d8a152014-06-17 19:08:45 -07001733 }
1734
1735 /**
Ihab Awadf8b69882014-07-25 15:14:01 -07001736 * Ask some other {@code ConnectionService} to create a {@code RemoteConnection} given an
Santos Cordona663f862014-10-29 13:49:58 -07001737 * outgoing request. This is used by {@code ConnectionService}s that are registered with
1738 * {@link PhoneAccount#CAPABILITY_CONNECTION_MANAGER} and want to be able to use the
1739 * SIM-based {@code ConnectionService} to place its outgoing calls.
Ihab Awadf8b69882014-07-25 15:14:01 -07001740 *
1741 * @param connectionManagerPhoneAccount See description at
1742 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
Cuihtlauac ALVARADO0b3b2a52016-09-13 14:49:41 +02001743 * @param request Details about the outgoing call.
Ihab Awadf8b69882014-07-25 15:14:01 -07001744 * @return The {@code Connection} object to satisfy this call, or {@code null} to
1745 * not handle the call.
1746 */
1747 public final RemoteConnection createRemoteOutgoingConnection(
1748 PhoneAccountHandle connectionManagerPhoneAccount,
1749 ConnectionRequest request) {
1750 return mRemoteConnectionManager.createRemoteConnection(
1751 connectionManagerPhoneAccount, request, false);
1752 }
1753
1754 /**
Santos Cordona663f862014-10-29 13:49:58 -07001755 * Indicates to the relevant {@code RemoteConnectionService} that the specified
1756 * {@link RemoteConnection}s should be merged into a conference call.
1757 * <p>
1758 * If the conference request is successful, the method {@link #onRemoteConferenceAdded} will
1759 * be invoked.
1760 *
1761 * @param remoteConnection1 The first of the remote connections to conference.
1762 * @param remoteConnection2 The second of the remote connections to conference.
Ihab Awadb8e85c72014-08-23 20:34:57 -07001763 */
1764 public final void conferenceRemoteConnections(
Santos Cordona663f862014-10-29 13:49:58 -07001765 RemoteConnection remoteConnection1,
1766 RemoteConnection remoteConnection2) {
1767 mRemoteConnectionManager.conferenceRemoteConnections(remoteConnection1, remoteConnection2);
Ihab Awadb8e85c72014-08-23 20:34:57 -07001768 }
1769
1770 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07001771 * Adds a new conference call. When a conference call is created either as a result of an
1772 * explicit request via {@link #onConference} or otherwise, the connection service should supply
1773 * an instance of {@link Conference} by invoking this method. A conference call provided by this
1774 * method will persist until {@link Conference#destroy} is invoked on the conference instance.
1775 *
1776 * @param conference The new conference object.
1777 */
1778 public final void addConference(Conference conference) {
Rekha Kumar07366812015-03-24 16:42:31 -07001779 Log.d(this, "addConference: conference=%s", conference);
1780
Santos Cordon823fd3c2014-08-07 18:35:18 -07001781 String id = addConferenceInternal(conference);
1782 if (id != null) {
1783 List<String> connectionIds = new ArrayList<>(2);
1784 for (Connection connection : conference.getConnections()) {
1785 if (mIdByConnection.containsKey(connection)) {
1786 connectionIds.add(mIdByConnection.get(connection));
1787 }
1788 }
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001789 conference.setTelecomCallId(id);
Santos Cordon823fd3c2014-08-07 18:35:18 -07001790 ParcelableConference parcelableConference = new ParcelableConference(
Nancy Chenea38cca2014-09-05 16:38:49 -07001791 conference.getPhoneAccountHandle(),
Santos Cordon823fd3c2014-08-07 18:35:18 -07001792 conference.getState(),
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001793 conference.getConnectionCapabilities(),
Tyler Gunn720c6642016-03-22 09:02:47 -07001794 conference.getConnectionProperties(),
Tyler Gunncd5d33c2015-01-12 09:02:01 -08001795 connectionIds,
Rekha Kumar07366812015-03-24 16:42:31 -07001796 conference.getVideoProvider() == null ?
1797 null : conference.getVideoProvider().getInterface(),
1798 conference.getVideoState(),
Andrew Lee3e3e2f22015-04-16 13:48:43 -07001799 conference.getConnectTimeMillis(),
Santos Cordon6b7f9552015-05-27 17:21:45 -07001800 conference.getStatusHints(),
1801 conference.getExtras());
Andrew Lee0f51da32015-04-16 13:11:55 -07001802
Santos Cordon823fd3c2014-08-07 18:35:18 -07001803 mAdapter.addConferenceCall(id, parcelableConference);
Rekha Kumar07366812015-03-24 16:42:31 -07001804 mAdapter.setVideoProvider(id, conference.getVideoProvider());
1805 mAdapter.setVideoState(id, conference.getVideoState());
Santos Cordon823fd3c2014-08-07 18:35:18 -07001806
1807 // Go through any child calls and set the parent.
1808 for (Connection connection : conference.getConnections()) {
1809 String connectionId = mIdByConnection.get(connection);
1810 if (connectionId != null) {
1811 mAdapter.setIsConferenced(connectionId, id);
1812 }
1813 }
1814 }
1815 }
1816
1817 /**
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07001818 * Adds a connection created by the {@link ConnectionService} and informs telecom of the new
1819 * connection.
1820 *
1821 * @param phoneAccountHandle The phone account handle for the connection.
1822 * @param connection The connection to add.
1823 */
1824 public final void addExistingConnection(PhoneAccountHandle phoneAccountHandle,
1825 Connection connection) {
1826
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001827 String id = addExistingConnectionInternal(phoneAccountHandle, connection);
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07001828 if (id != null) {
1829 List<String> emptyList = new ArrayList<>(0);
1830
1831 ParcelableConnection parcelableConnection = new ParcelableConnection(
1832 phoneAccountHandle,
1833 connection.getState(),
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001834 connection.getConnectionCapabilities(),
Tyler Gunn720c6642016-03-22 09:02:47 -07001835 connection.getConnectionProperties(),
Christine Hallstrom4e22d6d2016-11-30 16:06:42 -08001836 connection.getSupportedAudioRoutes(),
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07001837 connection.getAddress(),
1838 connection.getAddressPresentation(),
1839 connection.getCallerDisplayName(),
1840 connection.getCallerDisplayNamePresentation(),
1841 connection.getVideoProvider() == null ?
1842 null : connection.getVideoProvider().getInterface(),
1843 connection.getVideoState(),
1844 connection.isRingbackRequested(),
1845 connection.getAudioModeIsVoip(),
Roshan Piuse927ec02015-07-15 15:47:21 -07001846 connection.getConnectTimeMillis(),
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07001847 connection.getStatusHints(),
1848 connection.getDisconnectCause(),
Santos Cordon6b7f9552015-05-27 17:21:45 -07001849 emptyList,
1850 connection.getExtras());
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07001851 mAdapter.addExistingConnection(id, parcelableConnection);
1852 }
1853 }
1854
1855 /**
Ihab Awadf8b69882014-07-25 15:14:01 -07001856 * Returns all the active {@code Connection}s for which this {@code ConnectionService}
1857 * has taken responsibility.
1858 *
1859 * @return A collection of {@code Connection}s created by this {@code ConnectionService}.
Santos Cordonb6939982014-06-04 20:20:58 -07001860 */
Sailesh Nepal091768c2014-06-30 15:15:23 -07001861 public final Collection<Connection> getAllConnections() {
Santos Cordonb6939982014-06-04 20:20:58 -07001862 return mConnectionById.values();
1863 }
1864
1865 /**
Santos Cordona6018b92016-02-16 14:23:12 -08001866 * Returns all the active {@code Conference}s for which this {@code ConnectionService}
1867 * has taken responsibility.
1868 *
1869 * @return A collection of {@code Conference}s created by this {@code ConnectionService}.
1870 */
1871 public final Collection<Conference> getAllConferences() {
1872 return mConferenceById.values();
1873 }
1874
1875 /**
Ihab Awadf8b69882014-07-25 15:14:01 -07001876 * Create a {@code Connection} given an incoming request. This is used to attach to existing
1877 * incoming calls.
Evan Charltonbf11f982014-07-20 22:06:28 -07001878 *
Ihab Awadf8b69882014-07-25 15:14:01 -07001879 * @param connectionManagerPhoneAccount See description at
1880 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
1881 * @param request Details about the incoming call.
1882 * @return The {@code Connection} object to satisfy this call, or {@code null} to
1883 * not handle the call.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001884 */
Ihab Awadf8b69882014-07-25 15:14:01 -07001885 public Connection onCreateIncomingConnection(
1886 PhoneAccountHandle connectionManagerPhoneAccount,
1887 ConnectionRequest request) {
1888 return null;
1889 }
Sailesh Nepalc5b01572014-07-14 16:29:44 -07001890
1891 /**
Tyler Gunnd104a4f2017-05-12 10:04:49 -07001892 * Called after the {@link Connection} returned by
1893 * {@link #onCreateIncomingConnection(PhoneAccountHandle, ConnectionRequest)}
1894 * or {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)} has been
1895 * added to the {@link ConnectionService} and sent to Telecom.
1896 *
1897 * @param connection the {@link Connection}.
1898 * @hide
1899 */
1900 public void onCreateConnectionComplete(Connection connection) {
1901 }
1902
1903 /**
Tyler Gunnf5035432017-01-09 09:43:12 -08001904 * Called by Telecom to inform the {@link ConnectionService} that its request to create a new
1905 * incoming {@link Connection} was denied.
1906 * <p>
1907 * Used when a self-managed {@link ConnectionService} attempts to create a new incoming
1908 * {@link Connection}, but Telecom has determined that the call cannot be allowed at this time.
1909 * The {@link ConnectionService} is responsible for silently rejecting the new incoming
1910 * {@link Connection}.
1911 * <p>
1912 * See {@link TelecomManager#isIncomingCallPermitted(PhoneAccountHandle)} for more information.
1913 *
Tyler Gunn159f35c2017-03-02 09:28:37 -08001914 * @param connectionManagerPhoneAccount See description at
1915 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
Tyler Gunnf5035432017-01-09 09:43:12 -08001916 * @param request The incoming connection request.
1917 */
Tyler Gunn159f35c2017-03-02 09:28:37 -08001918 public void onCreateIncomingConnectionFailed(PhoneAccountHandle connectionManagerPhoneAccount,
1919 ConnectionRequest request) {
Tyler Gunnf5035432017-01-09 09:43:12 -08001920 }
1921
1922 /**
1923 * Called by Telecom to inform the {@link ConnectionService} that its request to create a new
1924 * outgoing {@link Connection} was denied.
1925 * <p>
1926 * Used when a self-managed {@link ConnectionService} attempts to create a new outgoing
1927 * {@link Connection}, but Telecom has determined that the call cannot be placed at this time.
1928 * The {@link ConnectionService} is responisible for informing the user that the
1929 * {@link Connection} cannot be made at this time.
1930 * <p>
1931 * See {@link TelecomManager#isOutgoingCallPermitted(PhoneAccountHandle)} for more information.
1932 *
Tyler Gunn159f35c2017-03-02 09:28:37 -08001933 * @param connectionManagerPhoneAccount See description at
1934 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
Tyler Gunnf5035432017-01-09 09:43:12 -08001935 * @param request The outgoing connection request.
1936 */
Tyler Gunn159f35c2017-03-02 09:28:37 -08001937 public void onCreateOutgoingConnectionFailed(PhoneAccountHandle connectionManagerPhoneAccount,
1938 ConnectionRequest request) {
Tyler Gunnf5035432017-01-09 09:43:12 -08001939 }
1940
1941 /**
Shriram Ganesh6bf35ac2014-12-11 17:53:38 -08001942 * Trigger recalculate functinality for conference calls. This is used when a Telephony
1943 * Connection is part of a conference controller but is not yet added to Connection
1944 * Service and hence cannot be added to the conference call.
1945 *
1946 * @hide
1947 */
1948 public void triggerConferenceRecalculate() {
1949 }
1950
1951 /**
Ihab Awadf8b69882014-07-25 15:14:01 -07001952 * Create a {@code Connection} given an outgoing request. This is used to initiate new
1953 * outgoing calls.
Sailesh Nepalc5b01572014-07-14 16:29:44 -07001954 *
Ihab Awadf8b69882014-07-25 15:14:01 -07001955 * @param connectionManagerPhoneAccount The connection manager account to use for managing
1956 * this call.
1957 * <p>
1958 * If this parameter is not {@code null}, it means that this {@code ConnectionService}
1959 * has registered one or more {@code PhoneAccount}s having
1960 * {@link PhoneAccount#CAPABILITY_CONNECTION_MANAGER}. This parameter will contain
1961 * one of these {@code PhoneAccount}s, while the {@code request} will contain another
1962 * (usually but not always distinct) {@code PhoneAccount} to be used for actually
1963 * making the connection.
1964 * <p>
1965 * If this parameter is {@code null}, it means that this {@code ConnectionService} is
1966 * being asked to make a direct connection. The
1967 * {@link ConnectionRequest#getAccountHandle()} of parameter {@code request} will be
1968 * a {@code PhoneAccount} registered by this {@code ConnectionService} to use for
1969 * making the connection.
1970 * @param request Details about the outgoing call.
1971 * @return The {@code Connection} object to satisfy this call, or the result of an invocation
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001972 * of {@link Connection#createFailedConnection(DisconnectCause)} to not handle the call.
Sailesh Nepalc5b01572014-07-14 16:29:44 -07001973 */
Ihab Awadf8b69882014-07-25 15:14:01 -07001974 public Connection onCreateOutgoingConnection(
1975 PhoneAccountHandle connectionManagerPhoneAccount,
1976 ConnectionRequest request) {
1977 return null;
1978 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001979
1980 /**
Yorke Leec3cf9822014-10-02 09:38:39 -07001981 * Create a {@code Connection} for a new unknown call. An unknown call is a call originating
1982 * from the ConnectionService that was neither a user-initiated outgoing call, nor an incoming
1983 * call created using
1984 * {@code TelecomManager#addNewIncomingCall(PhoneAccountHandle, android.os.Bundle)}.
1985 *
Yorke Lee770ed6e2014-10-06 18:58:52 -07001986 * @hide
Yorke Leec3cf9822014-10-02 09:38:39 -07001987 */
1988 public Connection onCreateUnknownConnection(PhoneAccountHandle connectionManagerPhoneAccount,
1989 ConnectionRequest request) {
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001990 return null;
Yorke Leec3cf9822014-10-02 09:38:39 -07001991 }
1992
1993 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07001994 * Conference two specified connections. Invoked when the user has made a request to merge the
1995 * specified connections into a conference call. In response, the connection service should
1996 * create an instance of {@link Conference} and pass it into {@link #addConference}.
Santos Cordonb6939982014-06-04 20:20:58 -07001997 *
Santos Cordon823fd3c2014-08-07 18:35:18 -07001998 * @param connection1 A connection to merge into a conference call.
1999 * @param connection2 A connection to merge into a conference call.
Santos Cordonb6939982014-06-04 20:20:58 -07002000 */
Santos Cordon823fd3c2014-08-07 18:35:18 -07002001 public void onConference(Connection connection1, Connection connection2) {}
Santos Cordonb6939982014-06-04 20:20:58 -07002002
Santos Cordona663f862014-10-29 13:49:58 -07002003 /**
2004 * Indicates that a remote conference has been created for existing {@link RemoteConnection}s.
2005 * When this method is invoked, this {@link ConnectionService} should create its own
2006 * representation of the conference call and send it to telecom using {@link #addConference}.
2007 * <p>
2008 * This is only relevant to {@link ConnectionService}s which are registered with
2009 * {@link PhoneAccount#CAPABILITY_CONNECTION_MANAGER}.
2010 *
2011 * @param conference The remote conference call.
2012 */
Ihab Awadb8e85c72014-08-23 20:34:57 -07002013 public void onRemoteConferenceAdded(RemoteConference conference) {}
2014
Santos Cordon823fd3c2014-08-07 18:35:18 -07002015 /**
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002016 * Called when an existing connection is added remotely.
2017 * @param connection The existing connection which was added.
2018 */
2019 public void onRemoteExistingConnectionAdded(RemoteConnection connection) {}
2020
2021 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07002022 * @hide
2023 */
2024 public boolean containsConference(Conference conference) {
2025 return mIdByConference.containsKey(conference);
2026 }
2027
Ihab Awadb8e85c72014-08-23 20:34:57 -07002028 /** {@hide} */
2029 void addRemoteConference(RemoteConference remoteConference) {
2030 onRemoteConferenceAdded(remoteConference);
2031 }
2032
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002033 /** {@hide} */
2034 void addRemoteExistingConnection(RemoteConnection remoteConnection) {
2035 onRemoteExistingConnectionAdded(remoteConnection);
2036 }
2037
Ihab Awad5d0410f2014-07-30 10:07:40 -07002038 private void onAccountsInitialized() {
2039 mAreAccountsInitialized = true;
2040 for (Runnable r : mPreInitializationConnectionRequests) {
2041 r.run();
2042 }
2043 mPreInitializationConnectionRequests.clear();
2044 }
2045
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002046 /**
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002047 * Adds an existing connection to the list of connections, identified by a new call ID unique
2048 * to this connection service.
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002049 *
2050 * @param connection The connection.
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002051 * @return The ID of the connection (e.g. the call-id).
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002052 */
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002053 private String addExistingConnectionInternal(PhoneAccountHandle handle, Connection connection) {
2054 String id;
Tyler Gunn2282bb92016-10-17 15:48:19 -07002055
2056 if (connection.getExtras() != null && connection.getExtras()
2057 .containsKey(Connection.EXTRA_ORIGINAL_CONNECTION_ID)) {
2058 id = connection.getExtras().getString(Connection.EXTRA_ORIGINAL_CONNECTION_ID);
2059 Log.d(this, "addExistingConnectionInternal - conn %s reusing original id %s",
2060 connection.getTelecomCallId(), id);
2061 } else if (handle == null) {
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002062 // If no phone account handle was provided, we cannot be sure the call ID is unique,
2063 // so just use a random UUID.
2064 id = UUID.randomUUID().toString();
2065 } else {
2066 // Phone account handle was provided, so use the ConnectionService class name as a
2067 // prefix for a unique incremental call ID.
2068 id = handle.getComponentName().getClassName() + "@" + getNextCallId();
2069 }
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002070 addConnection(id, connection);
2071 return id;
2072 }
2073
Ihab Awad542e0ea2014-05-16 10:22:16 -07002074 private void addConnection(String callId, Connection connection) {
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002075 connection.setTelecomCallId(callId);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002076 mConnectionById.put(callId, connection);
2077 mIdByConnection.put(connection, callId);
2078 connection.addConnectionListener(mConnectionListener);
Santos Cordon823fd3c2014-08-07 18:35:18 -07002079 connection.setConnectionService(this);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002080 }
2081
Anthony Lee30e65842014-11-06 16:30:53 -08002082 /** {@hide} */
2083 protected void removeConnection(Connection connection) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07002084 connection.unsetConnectionService(this);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002085 connection.removeConnectionListener(mConnectionListener);
Chenjie Luoe370b532016-05-12 16:59:43 -07002086 String id = mIdByConnection.get(connection);
2087 if (id != null) {
2088 mConnectionById.remove(id);
2089 mIdByConnection.remove(connection);
2090 mAdapter.removeCall(id);
2091 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002092 }
2093
Santos Cordon823fd3c2014-08-07 18:35:18 -07002094 private String addConferenceInternal(Conference conference) {
Tyler Gunn2282bb92016-10-17 15:48:19 -07002095 String originalId = null;
2096 if (conference.getExtras() != null && conference.getExtras()
2097 .containsKey(Connection.EXTRA_ORIGINAL_CONNECTION_ID)) {
2098 originalId = conference.getExtras().getString(Connection.EXTRA_ORIGINAL_CONNECTION_ID);
2099 Log.d(this, "addConferenceInternal: conf %s reusing original id %s",
2100 conference.getTelecomCallId(),
2101 originalId);
2102 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07002103 if (mIdByConference.containsKey(conference)) {
2104 Log.w(this, "Re-adding an existing conference: %s.", conference);
2105 } else if (conference != null) {
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002106 // Conferences do not (yet) have a PhoneAccountHandle associated with them, so we
2107 // cannot determine a ConnectionService class name to associate with the ID, so use
2108 // a unique UUID (for now).
Tyler Gunn2282bb92016-10-17 15:48:19 -07002109 String id = originalId == null ? UUID.randomUUID().toString() : originalId;
Santos Cordon823fd3c2014-08-07 18:35:18 -07002110 mConferenceById.put(id, conference);
2111 mIdByConference.put(conference, id);
2112 conference.addListener(mConferenceListener);
2113 return id;
2114 }
2115
2116 return null;
2117 }
2118
2119 private void removeConference(Conference conference) {
2120 if (mIdByConference.containsKey(conference)) {
2121 conference.removeListener(mConferenceListener);
2122
2123 String id = mIdByConference.get(conference);
2124 mConferenceById.remove(id);
2125 mIdByConference.remove(conference);
2126 mAdapter.removeCall(id);
2127 }
2128 }
2129
Ihab Awad542e0ea2014-05-16 10:22:16 -07002130 private Connection findConnectionForAction(String callId, String action) {
2131 if (mConnectionById.containsKey(callId)) {
2132 return mConnectionById.get(callId);
2133 }
Ihab Awad60ac30b2014-05-20 22:32:12 -07002134 Log.w(this, "%s - Cannot find Connection %s", action, callId);
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07002135 return getNullConnection();
2136 }
2137
2138 static synchronized Connection getNullConnection() {
2139 if (sNullConnection == null) {
2140 sNullConnection = new Connection() {};
2141 }
2142 return sNullConnection;
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002143 }
Santos Cordon0159ac02014-08-21 14:28:11 -07002144
2145 private Conference findConferenceForAction(String conferenceId, String action) {
2146 if (mConferenceById.containsKey(conferenceId)) {
2147 return mConferenceById.get(conferenceId);
2148 }
2149 Log.w(this, "%s - Cannot find conference %s", action, conferenceId);
2150 return getNullConference();
2151 }
2152
Ihab Awadb8e85c72014-08-23 20:34:57 -07002153 private List<String> createConnectionIdList(List<Connection> connections) {
2154 List<String> ids = new ArrayList<>();
2155 for (Connection c : connections) {
2156 if (mIdByConnection.containsKey(c)) {
2157 ids.add(mIdByConnection.get(c));
2158 }
2159 }
2160 Collections.sort(ids);
2161 return ids;
2162 }
2163
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002164 /**
2165 * Builds a list of {@link Connection} and {@link Conference} IDs based on the list of
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002166 * {@link Conferenceable}s passed in.
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002167 *
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002168 * @param conferenceables The {@link Conferenceable} connections and conferences.
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002169 * @return List of string conference and call Ids.
2170 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002171 private List<String> createIdList(List<Conferenceable> conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002172 List<String> ids = new ArrayList<>();
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002173 for (Conferenceable c : conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002174 // Only allow Connection and Conference conferenceables.
2175 if (c instanceof Connection) {
2176 Connection connection = (Connection) c;
2177 if (mIdByConnection.containsKey(connection)) {
2178 ids.add(mIdByConnection.get(connection));
2179 }
2180 } else if (c instanceof Conference) {
2181 Conference conference = (Conference) c;
2182 if (mIdByConference.containsKey(conference)) {
2183 ids.add(mIdByConference.get(conference));
2184 }
2185 }
2186 }
2187 Collections.sort(ids);
2188 return ids;
2189 }
2190
Santos Cordon0159ac02014-08-21 14:28:11 -07002191 private Conference getNullConference() {
2192 if (sNullConference == null) {
2193 sNullConference = new Conference(null) {};
2194 }
2195 return sNullConference;
2196 }
Santos Cordon29f2f2e2014-09-11 19:50:24 -07002197
2198 private void endAllConnections() {
2199 // Unbound from telecomm. We should end all connections and conferences.
2200 for (Connection connection : mIdByConnection.keySet()) {
2201 // only operate on top-level calls. Conference calls will be removed on their own.
2202 if (connection.getConference() == null) {
2203 connection.onDisconnect();
2204 }
2205 }
2206 for (Conference conference : mIdByConference.keySet()) {
2207 conference.onDisconnect();
2208 }
2209 }
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002210
2211 /**
2212 * Retrieves the next call ID as maintainted by the connection service.
2213 *
2214 * @return The call ID.
2215 */
2216 private int getNextCallId() {
Brad Ebingerb32d4f82016-10-24 16:40:49 -07002217 synchronized (mIdSyncRoot) {
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002218 return ++mId;
2219 }
2220 }
Santos Cordon980acb92014-05-31 10:31:19 -07002221}