blob: bf8f8e4e723e8c915567cf2f1474931fa8e341b9 [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 Gunn3edafc12017-01-31 10:49:05 -0800103 private static final String SESSION_CREATE_CONN_FAILED = "CS.crCoF";
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700104 private static final String SESSION_ABORT = "CS.ab";
105 private static final String SESSION_ANSWER = "CS.an";
106 private static final String SESSION_ANSWER_VIDEO = "CS.anV";
107 private static final String SESSION_REJECT = "CS.r";
108 private static final String SESSION_REJECT_MESSAGE = "CS.rWM";
109 private static final String SESSION_SILENCE = "CS.s";
110 private static final String SESSION_DISCONNECT = "CS.d";
111 private static final String SESSION_HOLD = "CS.h";
112 private static final String SESSION_UNHOLD = "CS.u";
113 private static final String SESSION_CALL_AUDIO_SC = "CS.cASC";
114 private static final String SESSION_PLAY_DTMF = "CS.pDT";
115 private static final String SESSION_STOP_DTMF = "CS.sDT";
116 private static final String SESSION_CONFERENCE = "CS.c";
117 private static final String SESSION_SPLIT_CONFERENCE = "CS.sFC";
118 private static final String SESSION_MERGE_CONFERENCE = "CS.mC";
119 private static final String SESSION_SWAP_CONFERENCE = "CS.sC";
120 private static final String SESSION_POST_DIAL_CONT = "CS.oPDC";
121 private static final String SESSION_PULL_EXTERNAL_CALL = "CS.pEC";
122 private static final String SESSION_SEND_CALL_EVENT = "CS.sCE";
123 private static final String SESSION_EXTRAS_CHANGED = "CS.oEC";
Hall Liu57006aa2017-02-06 10:49:48 -0800124 private static final String SESSION_START_RTT = "CS.+RTT";
125 private static final String SESSION_STOP_RTT = "CS.-RTT";
126 private static final String SESSION_RTT_UPGRADE_RESPONSE = "CS.rTRUR";
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700127
Ihab Awad8aecfed2014-08-08 17:06:11 -0700128 private static final int MSG_ADD_CONNECTION_SERVICE_ADAPTER = 1;
Sailesh Nepalc5b01572014-07-14 16:29:44 -0700129 private static final int MSG_CREATE_CONNECTION = 2;
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700130 private static final int MSG_ABORT = 3;
Sailesh Nepalc5b01572014-07-14 16:29:44 -0700131 private static final int MSG_ANSWER = 4;
132 private static final int MSG_REJECT = 5;
133 private static final int MSG_DISCONNECT = 6;
134 private static final int MSG_HOLD = 7;
135 private static final int MSG_UNHOLD = 8;
Yorke Lee4af59352015-05-13 14:14:54 -0700136 private static final int MSG_ON_CALL_AUDIO_STATE_CHANGED = 9;
Sailesh Nepalc5b01572014-07-14 16:29:44 -0700137 private static final int MSG_PLAY_DTMF_TONE = 10;
138 private static final int MSG_STOP_DTMF_TONE = 11;
139 private static final int MSG_CONFERENCE = 12;
140 private static final int MSG_SPLIT_FROM_CONFERENCE = 13;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700141 private static final int MSG_ON_POST_DIAL_CONTINUE = 14;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700142 private static final int MSG_REMOVE_CONNECTION_SERVICE_ADAPTER = 16;
Tyler Gunnbe74de02014-08-29 14:51:48 -0700143 private static final int MSG_ANSWER_VIDEO = 17;
Santos Cordona4868042014-09-04 17:39:22 -0700144 private static final int MSG_MERGE_CONFERENCE = 18;
145 private static final int MSG_SWAP_CONFERENCE = 19;
Bryce Lee81901682015-08-28 16:38:02 -0700146 private static final int MSG_REJECT_WITH_MESSAGE = 20;
Bryce Leecac50772015-11-17 15:13:29 -0800147 private static final int MSG_SILENCE = 21;
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700148 private static final int MSG_PULL_EXTERNAL_CALL = 22;
149 private static final int MSG_SEND_CALL_EVENT = 23;
Tyler Gunndee56a82016-03-23 16:06:34 -0700150 private static final int MSG_ON_EXTRAS_CHANGED = 24;
Tyler Gunn3edafc12017-01-31 10:49:05 -0800151 private static final int MSG_CREATE_CONNECTION_FAILED = 25;
Hall Liu57006aa2017-02-06 10:49:48 -0800152 private static final int MSG_ON_START_RTT = 26;
153 private static final int MSG_ON_STOP_RTT = 27;
154 private static final int MSG_RTT_UPGRADE_RESPONSE = 28;
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700155
Sailesh Nepalcf7020b2014-08-20 10:07:19 -0700156 private static Connection sNullConnection;
157
mike dooley95e80702014-09-18 14:07:52 -0700158 private final Map<String, Connection> mConnectionById = new ConcurrentHashMap<>();
159 private final Map<Connection, String> mIdByConnection = new ConcurrentHashMap<>();
160 private final Map<String, Conference> mConferenceById = new ConcurrentHashMap<>();
161 private final Map<Conference, String> mIdByConference = new ConcurrentHashMap<>();
Ihab Awadb8e85c72014-08-23 20:34:57 -0700162 private final RemoteConnectionManager mRemoteConnectionManager =
163 new RemoteConnectionManager(this);
Ihab Awad5d0410f2014-07-30 10:07:40 -0700164 private final List<Runnable> mPreInitializationConnectionRequests = new ArrayList<>();
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700165 private final ConnectionServiceAdapter mAdapter = new ConnectionServiceAdapter();
Ihab Awad542e0ea2014-05-16 10:22:16 -0700166
Santos Cordon823fd3c2014-08-07 18:35:18 -0700167 private boolean mAreAccountsInitialized = false;
Santos Cordon0159ac02014-08-21 14:28:11 -0700168 private Conference sNullConference;
Tyler Gunnf0500bd2015-09-01 10:59:48 -0700169 private Object mIdSyncRoot = new Object();
170 private int mId = 0;
Santos Cordon823fd3c2014-08-07 18:35:18 -0700171
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700172 private final IBinder mBinder = new IConnectionService.Stub() {
173 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700174 public void addConnectionServiceAdapter(IConnectionServiceAdapter adapter,
175 Session.Info sessionInfo) {
176 Log.startSession(sessionInfo, SESSION_ADD_CS_ADAPTER);
177 try {
178 SomeArgs args = SomeArgs.obtain();
179 args.arg1 = adapter;
180 args.arg2 = Log.createSubsession();
181 mHandler.obtainMessage(MSG_ADD_CONNECTION_SERVICE_ADAPTER, args).sendToTarget();
182 } finally {
183 Log.endSession();
184 }
Ihab Awad8aecfed2014-08-08 17:06:11 -0700185 }
186
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700187 public void removeConnectionServiceAdapter(IConnectionServiceAdapter adapter,
188 Session.Info sessionInfo) {
189 Log.startSession(sessionInfo, SESSION_REMOVE_CS_ADAPTER);
190 try {
191 SomeArgs args = SomeArgs.obtain();
192 args.arg1 = adapter;
193 args.arg2 = Log.createSubsession();
194 mHandler.obtainMessage(MSG_REMOVE_CONNECTION_SERVICE_ADAPTER, args).sendToTarget();
195 } finally {
196 Log.endSession();
197 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700198 }
199
200 @Override
Ihab Awadf8b69882014-07-25 15:14:01 -0700201 public void createConnection(
202 PhoneAccountHandle connectionManagerPhoneAccount,
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700203 String id,
Ihab Awadf8b69882014-07-25 15:14:01 -0700204 ConnectionRequest request,
Yorke Leec3cf9822014-10-02 09:38:39 -0700205 boolean isIncoming,
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700206 boolean isUnknown,
207 Session.Info sessionInfo) {
208 Log.startSession(sessionInfo, SESSION_CREATE_CONN);
209 try {
210 SomeArgs args = SomeArgs.obtain();
211 args.arg1 = connectionManagerPhoneAccount;
212 args.arg2 = id;
213 args.arg3 = request;
214 args.arg4 = Log.createSubsession();
215 args.argi1 = isIncoming ? 1 : 0;
216 args.argi2 = isUnknown ? 1 : 0;
217 mHandler.obtainMessage(MSG_CREATE_CONNECTION, args).sendToTarget();
218 } finally {
219 Log.endSession();
220 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700221 }
222
223 @Override
Tyler Gunn3edafc12017-01-31 10:49:05 -0800224 public void createConnectionFailed(
Tyler Gunn159f35c2017-03-02 09:28:37 -0800225 PhoneAccountHandle connectionManagerPhoneAccount,
Tyler Gunn3edafc12017-01-31 10:49:05 -0800226 String callId,
227 ConnectionRequest request,
228 boolean isIncoming,
229 Session.Info sessionInfo) {
230 Log.startSession(sessionInfo, SESSION_CREATE_CONN_FAILED);
231 try {
232 SomeArgs args = SomeArgs.obtain();
233 args.arg1 = callId;
234 args.arg2 = request;
235 args.arg3 = Log.createSubsession();
Tyler Gunn159f35c2017-03-02 09:28:37 -0800236 args.arg4 = connectionManagerPhoneAccount;
Tyler Gunn3edafc12017-01-31 10:49:05 -0800237 args.argi1 = isIncoming ? 1 : 0;
238 mHandler.obtainMessage(MSG_CREATE_CONNECTION_FAILED, args).sendToTarget();
239 } finally {
240 Log.endSession();
241 }
242 }
243
244 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700245 public void abort(String callId, Session.Info sessionInfo) {
246 Log.startSession(sessionInfo, SESSION_ABORT);
247 try {
248 SomeArgs args = SomeArgs.obtain();
249 args.arg1 = callId;
250 args.arg2 = Log.createSubsession();
251 mHandler.obtainMessage(MSG_ABORT, args).sendToTarget();
252 } finally {
253 Log.endSession();
254 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700255 }
256
257 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700258 public void answerVideo(String callId, int videoState, Session.Info sessionInfo) {
259 Log.startSession(sessionInfo, SESSION_ANSWER_VIDEO);
260 try {
261 SomeArgs args = SomeArgs.obtain();
262 args.arg1 = callId;
263 args.arg2 = Log.createSubsession();
264 args.argi1 = videoState;
265 mHandler.obtainMessage(MSG_ANSWER_VIDEO, args).sendToTarget();
266 } finally {
267 Log.endSession();
268 }
Tyler Gunnbe74de02014-08-29 14:51:48 -0700269 }
270
271 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700272 public void answer(String callId, Session.Info sessionInfo) {
273 Log.startSession(sessionInfo, SESSION_ANSWER);
274 try {
275 SomeArgs args = SomeArgs.obtain();
276 args.arg1 = callId;
277 args.arg2 = Log.createSubsession();
278 mHandler.obtainMessage(MSG_ANSWER, args).sendToTarget();
279 } finally {
280 Log.endSession();
281 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700282 }
283
284 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700285 public void reject(String callId, Session.Info sessionInfo) {
286 Log.startSession(sessionInfo, SESSION_REJECT);
287 try {
288 SomeArgs args = SomeArgs.obtain();
289 args.arg1 = callId;
290 args.arg2 = Log.createSubsession();
291 mHandler.obtainMessage(MSG_REJECT, args).sendToTarget();
292 } finally {
293 Log.endSession();
294 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700295 }
296
297 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700298 public void rejectWithMessage(String callId, String message, Session.Info sessionInfo) {
299 Log.startSession(sessionInfo, SESSION_REJECT_MESSAGE);
300 try {
301 SomeArgs args = SomeArgs.obtain();
302 args.arg1 = callId;
303 args.arg2 = message;
304 args.arg3 = Log.createSubsession();
305 mHandler.obtainMessage(MSG_REJECT_WITH_MESSAGE, args).sendToTarget();
306 } finally {
307 Log.endSession();
308 }
Bryce Lee81901682015-08-28 16:38:02 -0700309 }
310
311 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700312 public void silence(String callId, Session.Info sessionInfo) {
313 Log.startSession(sessionInfo, SESSION_SILENCE);
314 try {
315 SomeArgs args = SomeArgs.obtain();
316 args.arg1 = callId;
317 args.arg2 = Log.createSubsession();
318 mHandler.obtainMessage(MSG_SILENCE, args).sendToTarget();
319 } finally {
320 Log.endSession();
321 }
Bryce Leecac50772015-11-17 15:13:29 -0800322 }
323
324 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700325 public void disconnect(String callId, Session.Info sessionInfo) {
326 Log.startSession(sessionInfo, SESSION_DISCONNECT);
327 try {
328 SomeArgs args = SomeArgs.obtain();
329 args.arg1 = callId;
330 args.arg2 = Log.createSubsession();
331 mHandler.obtainMessage(MSG_DISCONNECT, args).sendToTarget();
332 } finally {
333 Log.endSession();
334 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700335 }
336
337 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700338 public void hold(String callId, Session.Info sessionInfo) {
339 Log.startSession(sessionInfo, SESSION_HOLD);
340 try {
341 SomeArgs args = SomeArgs.obtain();
342 args.arg1 = callId;
343 args.arg2 = Log.createSubsession();
344 mHandler.obtainMessage(MSG_HOLD, args).sendToTarget();
345 } finally {
346 Log.endSession();
347 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700348 }
349
350 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700351 public void unhold(String callId, Session.Info sessionInfo) {
352 Log.startSession(sessionInfo, SESSION_UNHOLD);
353 try {
354 SomeArgs args = SomeArgs.obtain();
355 args.arg1 = callId;
356 args.arg2 = Log.createSubsession();
357 mHandler.obtainMessage(MSG_UNHOLD, args).sendToTarget();
358 } finally {
359 Log.endSession();
360 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700361 }
362
363 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700364 public void onCallAudioStateChanged(String callId, CallAudioState callAudioState,
365 Session.Info sessionInfo) {
366 Log.startSession(sessionInfo, SESSION_CALL_AUDIO_SC);
367 try {
368 SomeArgs args = SomeArgs.obtain();
369 args.arg1 = callId;
370 args.arg2 = callAudioState;
371 args.arg3 = Log.createSubsession();
372 mHandler.obtainMessage(MSG_ON_CALL_AUDIO_STATE_CHANGED, 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 playDtmfTone(String callId, char digit, Session.Info sessionInfo) {
380 Log.startSession(sessionInfo, SESSION_PLAY_DTMF);
381 try {
382 SomeArgs args = SomeArgs.obtain();
383 args.arg1 = digit;
384 args.arg2 = callId;
385 args.arg3 = Log.createSubsession();
386 mHandler.obtainMessage(MSG_PLAY_DTMF_TONE, args).sendToTarget();
387 } finally {
388 Log.endSession();
389 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700390 }
391
392 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700393 public void stopDtmfTone(String callId, Session.Info sessionInfo) {
394 Log.startSession(sessionInfo, SESSION_STOP_DTMF);
395 try {
396 SomeArgs args = SomeArgs.obtain();
397 args.arg1 = callId;
398 args.arg2 = Log.createSubsession();
399 mHandler.obtainMessage(MSG_STOP_DTMF_TONE, args).sendToTarget();
400 } finally {
401 Log.endSession();
402 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700403 }
404
405 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700406 public void conference(String callId1, String callId2, Session.Info sessionInfo) {
407 Log.startSession(sessionInfo, SESSION_CONFERENCE);
408 try {
409 SomeArgs args = SomeArgs.obtain();
410 args.arg1 = callId1;
411 args.arg2 = callId2;
412 args.arg3 = Log.createSubsession();
413 mHandler.obtainMessage(MSG_CONFERENCE, args).sendToTarget();
414 } finally {
415 Log.endSession();
416 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700417 }
418
419 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700420 public void splitFromConference(String callId, Session.Info sessionInfo) {
421 Log.startSession(sessionInfo, SESSION_SPLIT_CONFERENCE);
422 try {
423 SomeArgs args = SomeArgs.obtain();
424 args.arg1 = callId;
425 args.arg2 = Log.createSubsession();
426 mHandler.obtainMessage(MSG_SPLIT_FROM_CONFERENCE, args).sendToTarget();
427 } finally {
428 Log.endSession();
429 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700430 }
431
432 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700433 public void mergeConference(String callId, Session.Info sessionInfo) {
434 Log.startSession(sessionInfo, SESSION_MERGE_CONFERENCE);
435 try {
436 SomeArgs args = SomeArgs.obtain();
437 args.arg1 = callId;
438 args.arg2 = Log.createSubsession();
439 mHandler.obtainMessage(MSG_MERGE_CONFERENCE, args).sendToTarget();
440 } finally {
441 Log.endSession();
442 }
Santos Cordona4868042014-09-04 17:39:22 -0700443 }
444
445 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700446 public void swapConference(String callId, Session.Info sessionInfo) {
447 Log.startSession(sessionInfo, SESSION_SWAP_CONFERENCE);
448 try {
449 SomeArgs args = SomeArgs.obtain();
450 args.arg1 = callId;
451 args.arg2 = Log.createSubsession();
452 mHandler.obtainMessage(MSG_SWAP_CONFERENCE, args).sendToTarget();
453 } finally {
454 Log.endSession();
455 }
Santos Cordona4868042014-09-04 17:39:22 -0700456 }
457
458 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700459 public void onPostDialContinue(String callId, boolean proceed, Session.Info sessionInfo) {
460 Log.startSession(sessionInfo, SESSION_POST_DIAL_CONT);
461 try {
462 SomeArgs args = SomeArgs.obtain();
463 args.arg1 = callId;
464 args.arg2 = Log.createSubsession();
465 args.argi1 = proceed ? 1 : 0;
466 mHandler.obtainMessage(MSG_ON_POST_DIAL_CONTINUE, args).sendToTarget();
467 } finally {
468 Log.endSession();
469 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700470 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700471
472 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700473 public void pullExternalCall(String callId, Session.Info sessionInfo) {
474 Log.startSession(sessionInfo, SESSION_PULL_EXTERNAL_CALL);
475 try {
476 SomeArgs args = SomeArgs.obtain();
477 args.arg1 = callId;
478 args.arg2 = Log.createSubsession();
479 mHandler.obtainMessage(MSG_PULL_EXTERNAL_CALL, args).sendToTarget();
480 } finally {
481 Log.endSession();
482 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700483 }
484
485 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700486 public void sendCallEvent(String callId, String event, Bundle extras,
487 Session.Info sessionInfo) {
488 Log.startSession(sessionInfo, SESSION_SEND_CALL_EVENT);
489 try {
490 SomeArgs args = SomeArgs.obtain();
491 args.arg1 = callId;
492 args.arg2 = event;
493 args.arg3 = extras;
494 args.arg4 = Log.createSubsession();
495 mHandler.obtainMessage(MSG_SEND_CALL_EVENT, args).sendToTarget();
496 } finally {
497 Log.endSession();
498 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700499 }
Tyler Gunndee56a82016-03-23 16:06:34 -0700500
501 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700502 public void onExtrasChanged(String callId, Bundle extras, Session.Info sessionInfo) {
503 Log.startSession(sessionInfo, SESSION_EXTRAS_CHANGED);
504 try {
505 SomeArgs args = SomeArgs.obtain();
506 args.arg1 = callId;
507 args.arg2 = extras;
508 args.arg3 = Log.createSubsession();
509 mHandler.obtainMessage(MSG_ON_EXTRAS_CHANGED, args).sendToTarget();
510 } finally {
511 Log.endSession();
512 }
Tyler Gunndee56a82016-03-23 16:06:34 -0700513 }
Hall Liu57006aa2017-02-06 10:49:48 -0800514
515 @Override
516 public void startRtt(String callId, ParcelFileDescriptor fromInCall,
517 ParcelFileDescriptor toInCall, Session.Info sessionInfo) throws RemoteException {
518 Log.startSession(sessionInfo, SESSION_START_RTT);
519 try {
520 SomeArgs args = SomeArgs.obtain();
521 args.arg1 = callId;
522 args.arg2 = new Connection.RttTextStream(toInCall, fromInCall);
523 args.arg3 = Log.createSubsession();
524 mHandler.obtainMessage(MSG_ON_START_RTT, args).sendToTarget();
525 } finally {
526 Log.endSession();
527 }
528 }
529
530 @Override
531 public void stopRtt(String callId, Session.Info sessionInfo) throws RemoteException {
532 Log.startSession(sessionInfo, SESSION_STOP_RTT);
533 try {
534 SomeArgs args = SomeArgs.obtain();
535 args.arg1 = callId;
536 args.arg2 = Log.createSubsession();
537 mHandler.obtainMessage(MSG_ON_STOP_RTT, args).sendToTarget();
538 } finally {
539 Log.endSession();
540 }
541 }
542
543 @Override
544 public void respondToRttUpgradeRequest(String callId, ParcelFileDescriptor fromInCall,
545 ParcelFileDescriptor toInCall, Session.Info sessionInfo) throws RemoteException {
546 Log.startSession(sessionInfo, SESSION_RTT_UPGRADE_RESPONSE);
547 try {
548 SomeArgs args = SomeArgs.obtain();
549 args.arg1 = callId;
550 if (toInCall == null || fromInCall == null) {
551 args.arg2 = null;
552 } else {
553 args.arg2 = new Connection.RttTextStream(toInCall, fromInCall);
554 }
555 args.arg3 = Log.createSubsession();
556 mHandler.obtainMessage(MSG_RTT_UPGRADE_RESPONSE, args).sendToTarget();
557 } finally {
558 Log.endSession();
559 }
560 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700561 };
562
563 private final Handler mHandler = new Handler(Looper.getMainLooper()) {
564 @Override
565 public void handleMessage(Message msg) {
566 switch (msg.what) {
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700567 case MSG_ADD_CONNECTION_SERVICE_ADAPTER: {
568 SomeArgs args = (SomeArgs) msg.obj;
569 try {
570 IConnectionServiceAdapter adapter = (IConnectionServiceAdapter) args.arg1;
571 Log.continueSession((Session) args.arg2,
572 SESSION_HANDLER + SESSION_ADD_CS_ADAPTER);
573 mAdapter.addAdapter(adapter);
574 onAdapterAttached();
575 } finally {
576 args.recycle();
577 Log.endSession();
578 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700579 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700580 }
581 case MSG_REMOVE_CONNECTION_SERVICE_ADAPTER: {
582 SomeArgs args = (SomeArgs) msg.obj;
583 try {
584 Log.continueSession((Session) args.arg2,
585 SESSION_HANDLER + SESSION_REMOVE_CS_ADAPTER);
586 mAdapter.removeAdapter((IConnectionServiceAdapter) args.arg1);
587 } finally {
588 args.recycle();
589 Log.endSession();
590 }
Ihab Awad8aecfed2014-08-08 17:06:11 -0700591 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700592 }
Ihab Awadf8b69882014-07-25 15:14:01 -0700593 case MSG_CREATE_CONNECTION: {
594 SomeArgs args = (SomeArgs) msg.obj;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700595 Log.continueSession((Session) args.arg4, SESSION_HANDLER + SESSION_CREATE_CONN);
Ihab Awadf8b69882014-07-25 15:14:01 -0700596 try {
Ihab Awad5d0410f2014-07-30 10:07:40 -0700597 final PhoneAccountHandle connectionManagerPhoneAccount =
Ihab Awadf8b69882014-07-25 15:14:01 -0700598 (PhoneAccountHandle) args.arg1;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700599 final String id = (String) args.arg2;
600 final ConnectionRequest request = (ConnectionRequest) args.arg3;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700601 final boolean isIncoming = args.argi1 == 1;
Yorke Leec3cf9822014-10-02 09:38:39 -0700602 final boolean isUnknown = args.argi2 == 1;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700603 if (!mAreAccountsInitialized) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700604 Log.d(this, "Enqueueing pre-init request %s", id);
Brad Ebinger0c3541b2016-11-01 14:11:38 -0700605 mPreInitializationConnectionRequests.add(
606 new android.telecom.Logging.Runnable(
607 SESSION_HANDLER + SESSION_CREATE_CONN + ".pICR",
608 null /*lock*/) {
Ihab Awad5d0410f2014-07-30 10:07:40 -0700609 @Override
Brad Ebinger0c3541b2016-11-01 14:11:38 -0700610 public void loggedRun() {
Ihab Awad5d0410f2014-07-30 10:07:40 -0700611 createConnection(
612 connectionManagerPhoneAccount,
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700613 id,
Ihab Awad5d0410f2014-07-30 10:07:40 -0700614 request,
Yorke Leec3cf9822014-10-02 09:38:39 -0700615 isIncoming,
616 isUnknown);
Ihab Awad5d0410f2014-07-30 10:07:40 -0700617 }
Brad Ebinger0c3541b2016-11-01 14:11:38 -0700618 }.prepare());
Ihab Awad5d0410f2014-07-30 10:07:40 -0700619 } else {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700620 createConnection(
621 connectionManagerPhoneAccount,
622 id,
623 request,
Yorke Leec3cf9822014-10-02 09:38:39 -0700624 isIncoming,
625 isUnknown);
Ihab Awad5d0410f2014-07-30 10:07:40 -0700626 }
Ihab Awadf8b69882014-07-25 15:14:01 -0700627 } finally {
628 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700629 Log.endSession();
Ihab Awadf8b69882014-07-25 15:14:01 -0700630 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700631 break;
Ihab Awadf8b69882014-07-25 15:14:01 -0700632 }
Tyler Gunn3edafc12017-01-31 10:49:05 -0800633 case MSG_CREATE_CONNECTION_FAILED: {
634 SomeArgs args = (SomeArgs) msg.obj;
635 Log.continueSession((Session) args.arg3, SESSION_HANDLER +
636 SESSION_CREATE_CONN_FAILED);
637 try {
638 final String id = (String) args.arg1;
639 final ConnectionRequest request = (ConnectionRequest) args.arg2;
640 final boolean isIncoming = args.argi1 == 1;
Tyler Gunn159f35c2017-03-02 09:28:37 -0800641 final PhoneAccountHandle connectionMgrPhoneAccount =
642 (PhoneAccountHandle) args.arg4;
Tyler Gunn3edafc12017-01-31 10:49:05 -0800643 if (!mAreAccountsInitialized) {
644 Log.d(this, "Enqueueing pre-init request %s", id);
645 mPreInitializationConnectionRequests.add(
646 new android.telecom.Logging.Runnable(
647 SESSION_HANDLER + SESSION_CREATE_CONN_FAILED + ".pICR",
648 null /*lock*/) {
649 @Override
650 public void loggedRun() {
Tyler Gunn159f35c2017-03-02 09:28:37 -0800651 createConnectionFailed(connectionMgrPhoneAccount, id,
652 request, isIncoming);
Tyler Gunn3edafc12017-01-31 10:49:05 -0800653 }
654 }.prepare());
655 } else {
656 Log.i(this, "createConnectionFailed %s", id);
Tyler Gunn159f35c2017-03-02 09:28:37 -0800657 createConnectionFailed(connectionMgrPhoneAccount, id, request,
658 isIncoming);
Tyler Gunn3edafc12017-01-31 10:49:05 -0800659 }
660 } finally {
661 args.recycle();
662 Log.endSession();
663 }
664 break;
665 }
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700666 case MSG_ABORT: {
667 SomeArgs args = (SomeArgs) msg.obj;
668 Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_ABORT);
669 try {
670 abort((String) args.arg1);
671 } finally {
672 args.recycle();
673 Log.endSession();
674 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700675 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700676 }
677 case MSG_ANSWER: {
678 SomeArgs args = (SomeArgs) msg.obj;
679 Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_ANSWER);
680 try {
681 answer((String) args.arg1);
682 } finally {
683 args.recycle();
684 Log.endSession();
685 }
Tyler Gunnbe74de02014-08-29 14:51:48 -0700686 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700687 }
Tyler Gunnbe74de02014-08-29 14:51:48 -0700688 case MSG_ANSWER_VIDEO: {
Andrew Lee8da4c3c2014-07-16 10:11:42 -0700689 SomeArgs args = (SomeArgs) msg.obj;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700690 Log.continueSession((Session) args.arg2,
691 SESSION_HANDLER + SESSION_ANSWER_VIDEO);
Andrew Lee8da4c3c2014-07-16 10:11:42 -0700692 try {
693 String callId = (String) args.arg1;
Evan Charltonbf11f982014-07-20 22:06:28 -0700694 int videoState = args.argi1;
Tyler Gunnbe74de02014-08-29 14:51:48 -0700695 answerVideo(callId, videoState);
Andrew Lee8da4c3c2014-07-16 10:11:42 -0700696 } finally {
697 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700698 Log.endSession();
Andrew Lee8da4c3c2014-07-16 10:11:42 -0700699 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700700 break;
Andrew Lee8da4c3c2014-07-16 10:11:42 -0700701 }
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700702 case MSG_REJECT: {
703 SomeArgs args = (SomeArgs) msg.obj;
704 Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_REJECT);
705 try {
706 reject((String) args.arg1);
707 } finally {
708 args.recycle();
709 Log.endSession();
710 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700711 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700712 }
Bryce Lee81901682015-08-28 16:38:02 -0700713 case MSG_REJECT_WITH_MESSAGE: {
714 SomeArgs args = (SomeArgs) msg.obj;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700715 Log.continueSession((Session) args.arg3,
716 SESSION_HANDLER + SESSION_REJECT_MESSAGE);
Bryce Lee81901682015-08-28 16:38:02 -0700717 try {
718 reject((String) args.arg1, (String) args.arg2);
719 } finally {
720 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700721 Log.endSession();
Bryce Lee81901682015-08-28 16:38:02 -0700722 }
723 break;
724 }
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700725 case MSG_DISCONNECT: {
726 SomeArgs args = (SomeArgs) msg.obj;
727 Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_DISCONNECT);
728 try {
729 disconnect((String) args.arg1);
730 } finally {
731 args.recycle();
732 Log.endSession();
733 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700734 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700735 }
736 case MSG_SILENCE: {
737 SomeArgs args = (SomeArgs) msg.obj;
738 Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_SILENCE);
739 try {
740 silence((String) args.arg1);
741 } finally {
742 args.recycle();
743 Log.endSession();
744 }
Bryce Leecac50772015-11-17 15:13:29 -0800745 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700746 }
747 case MSG_HOLD: {
748 SomeArgs args = (SomeArgs) msg.obj;
749 Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_REJECT);
750 try {
751 hold((String) args.arg1);
752 } finally {
753 args.recycle();
754 Log.endSession();
755 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700756 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700757 }
758 case MSG_UNHOLD: {
759 SomeArgs args = (SomeArgs) msg.obj;
760 Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_UNHOLD);
761 try {
762 unhold((String) args.arg1);
763 } finally {
764 args.recycle();
765 Log.endSession();
766 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700767 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700768 }
Yorke Lee4af59352015-05-13 14:14:54 -0700769 case MSG_ON_CALL_AUDIO_STATE_CHANGED: {
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700770 SomeArgs args = (SomeArgs) msg.obj;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700771 Log.continueSession((Session) args.arg3,
772 SESSION_HANDLER + SESSION_CALL_AUDIO_SC);
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700773 try {
774 String callId = (String) args.arg1;
Yorke Lee4af59352015-05-13 14:14:54 -0700775 CallAudioState audioState = (CallAudioState) args.arg2;
776 onCallAudioStateChanged(callId, new CallAudioState(audioState));
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700777 } finally {
778 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700779 Log.endSession();
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700780 }
781 break;
782 }
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700783 case MSG_PLAY_DTMF_TONE: {
784 SomeArgs args = (SomeArgs) msg.obj;
785 try {
786 Log.continueSession((Session) args.arg3,
787 SESSION_HANDLER + SESSION_PLAY_DTMF);
788 playDtmfTone((String) args.arg2, (char) args.arg1);
789 } finally {
790 args.recycle();
791 Log.endSession();
792 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700793 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700794 }
795 case MSG_STOP_DTMF_TONE: {
796 SomeArgs args = (SomeArgs) msg.obj;
797 try {
798 Log.continueSession((Session) args.arg2,
799 SESSION_HANDLER + SESSION_STOP_DTMF);
800 stopDtmfTone((String) args.arg1);
801 } finally {
802 args.recycle();
803 Log.endSession();
804 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700805 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700806 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700807 case MSG_CONFERENCE: {
808 SomeArgs args = (SomeArgs) msg.obj;
809 try {
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700810 Log.continueSession((Session) args.arg3,
811 SESSION_HANDLER + SESSION_CONFERENCE);
Santos Cordon823fd3c2014-08-07 18:35:18 -0700812 String callId1 = (String) args.arg1;
813 String callId2 = (String) args.arg2;
814 conference(callId1, callId2);
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700815 } finally {
816 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700817 Log.endSession();
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700818 }
819 break;
820 }
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700821 case MSG_SPLIT_FROM_CONFERENCE: {
822 SomeArgs args = (SomeArgs) msg.obj;
823 try {
824 Log.continueSession((Session) args.arg2,
825 SESSION_HANDLER + SESSION_SPLIT_CONFERENCE);
826 splitFromConference((String) args.arg1);
827 } finally {
828 args.recycle();
829 Log.endSession();
830 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700831 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700832 }
833 case MSG_MERGE_CONFERENCE: {
834 SomeArgs args = (SomeArgs) msg.obj;
835 try {
836 Log.continueSession((Session) args.arg2,
837 SESSION_HANDLER + SESSION_MERGE_CONFERENCE);
838 mergeConference((String) args.arg1);
839 } finally {
840 args.recycle();
841 Log.endSession();
842 }
Santos Cordona4868042014-09-04 17:39:22 -0700843 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700844 }
845 case MSG_SWAP_CONFERENCE: {
846 SomeArgs args = (SomeArgs) msg.obj;
847 try {
848 Log.continueSession((Session) args.arg2,
849 SESSION_HANDLER + SESSION_SWAP_CONFERENCE);
850 swapConference((String) args.arg1);
851 } finally {
852 args.recycle();
853 Log.endSession();
854 }
Santos Cordona4868042014-09-04 17:39:22 -0700855 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700856 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700857 case MSG_ON_POST_DIAL_CONTINUE: {
858 SomeArgs args = (SomeArgs) msg.obj;
859 try {
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700860 Log.continueSession((Session) args.arg2,
861 SESSION_HANDLER + SESSION_POST_DIAL_CONT);
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700862 String callId = (String) args.arg1;
863 boolean proceed = (args.argi1 == 1);
864 onPostDialContinue(callId, proceed);
865 } finally {
866 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700867 Log.endSession();
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700868 }
869 break;
870 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700871 case MSG_PULL_EXTERNAL_CALL: {
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700872 SomeArgs args = (SomeArgs) msg.obj;
873 try {
874 Log.continueSession((Session) args.arg2,
875 SESSION_HANDLER + SESSION_PULL_EXTERNAL_CALL);
876 pullExternalCall((String) args.arg1);
877 } finally {
878 args.recycle();
879 Log.endSession();
880 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700881 break;
882 }
883 case MSG_SEND_CALL_EVENT: {
884 SomeArgs args = (SomeArgs) msg.obj;
885 try {
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700886 Log.continueSession((Session) args.arg4,
887 SESSION_HANDLER + SESSION_SEND_CALL_EVENT);
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700888 String callId = (String) args.arg1;
889 String event = (String) args.arg2;
890 Bundle extras = (Bundle) args.arg3;
891 sendCallEvent(callId, event, extras);
892 } finally {
893 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700894 Log.endSession();
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700895 }
896 break;
897 }
Tyler Gunndee56a82016-03-23 16:06:34 -0700898 case MSG_ON_EXTRAS_CHANGED: {
899 SomeArgs args = (SomeArgs) msg.obj;
900 try {
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700901 Log.continueSession((Session) args.arg3,
902 SESSION_HANDLER + SESSION_EXTRAS_CHANGED);
Tyler Gunndee56a82016-03-23 16:06:34 -0700903 String callId = (String) args.arg1;
904 Bundle extras = (Bundle) args.arg2;
905 handleExtrasChanged(callId, extras);
906 } finally {
907 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700908 Log.endSession();
Tyler Gunndee56a82016-03-23 16:06:34 -0700909 }
910 break;
911 }
Hall Liu57006aa2017-02-06 10:49:48 -0800912 case MSG_ON_START_RTT: {
913 SomeArgs args = (SomeArgs) msg.obj;
914 try {
915 Log.continueSession((Session) args.arg3,
916 SESSION_HANDLER + SESSION_START_RTT);
917 String callId = (String) args.arg1;
918 Connection.RttTextStream rttTextStream =
919 (Connection.RttTextStream) args.arg2;
920 startRtt(callId, rttTextStream);
921 } finally {
922 args.recycle();
923 Log.endSession();
924 }
925 break;
926 }
927 case MSG_ON_STOP_RTT: {
928 SomeArgs args = (SomeArgs) msg.obj;
929 try {
930 Log.continueSession((Session) args.arg2,
931 SESSION_HANDLER + SESSION_STOP_RTT);
932 String callId = (String) args.arg1;
933 stopRtt(callId);
934 } finally {
935 args.recycle();
936 Log.endSession();
937 }
938 break;
939 }
940 case MSG_RTT_UPGRADE_RESPONSE: {
941 SomeArgs args = (SomeArgs) msg.obj;
942 try {
943 Log.continueSession((Session) args.arg3,
944 SESSION_HANDLER + SESSION_RTT_UPGRADE_RESPONSE);
945 String callId = (String) args.arg1;
946 Connection.RttTextStream rttTextStream =
947 (Connection.RttTextStream) args.arg2;
948 handleRttUpgradeResponse(callId, rttTextStream);
949 } finally {
950 args.recycle();
951 Log.endSession();
952 }
953 break;
954 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700955 default:
956 break;
957 }
958 }
959 };
960
Santos Cordon823fd3c2014-08-07 18:35:18 -0700961 private final Conference.Listener mConferenceListener = new Conference.Listener() {
962 @Override
963 public void onStateChanged(Conference conference, int oldState, int newState) {
964 String id = mIdByConference.get(conference);
965 switch (newState) {
966 case Connection.STATE_ACTIVE:
967 mAdapter.setActive(id);
968 break;
969 case Connection.STATE_HOLDING:
970 mAdapter.setOnHold(id);
971 break;
972 case Connection.STATE_DISCONNECTED:
973 // handled by onDisconnected
974 break;
975 }
976 }
977
978 @Override
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700979 public void onDisconnected(Conference conference, DisconnectCause disconnectCause) {
Santos Cordon823fd3c2014-08-07 18:35:18 -0700980 String id = mIdByConference.get(conference);
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700981 mAdapter.setDisconnected(id, disconnectCause);
Santos Cordon823fd3c2014-08-07 18:35:18 -0700982 }
983
984 @Override
985 public void onConnectionAdded(Conference conference, Connection connection) {
986 }
987
988 @Override
989 public void onConnectionRemoved(Conference conference, Connection connection) {
990 }
991
992 @Override
Ihab Awad50e35062014-09-30 09:17:03 -0700993 public void onConferenceableConnectionsChanged(
994 Conference conference, List<Connection> conferenceableConnections) {
995 mAdapter.setConferenceableConnections(
996 mIdByConference.get(conference),
997 createConnectionIdList(conferenceableConnections));
998 }
999
1000 @Override
Santos Cordon823fd3c2014-08-07 18:35:18 -07001001 public void onDestroyed(Conference conference) {
1002 removeConference(conference);
1003 }
1004
1005 @Override
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001006 public void onConnectionCapabilitiesChanged(
1007 Conference conference,
1008 int connectionCapabilities) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07001009 String id = mIdByConference.get(conference);
1010 Log.d(this, "call capabilities: conference: %s",
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001011 Connection.capabilitiesToString(connectionCapabilities));
1012 mAdapter.setConnectionCapabilities(id, connectionCapabilities);
Santos Cordon823fd3c2014-08-07 18:35:18 -07001013 }
Rekha Kumar07366812015-03-24 16:42:31 -07001014
1015 @Override
Tyler Gunn720c6642016-03-22 09:02:47 -07001016 public void onConnectionPropertiesChanged(
1017 Conference conference,
1018 int connectionProperties) {
1019 String id = mIdByConference.get(conference);
1020 Log.d(this, "call capabilities: conference: %s",
1021 Connection.propertiesToString(connectionProperties));
1022 mAdapter.setConnectionProperties(id, connectionProperties);
1023 }
1024
1025 @Override
Rekha Kumar07366812015-03-24 16:42:31 -07001026 public void onVideoStateChanged(Conference c, int videoState) {
1027 String id = mIdByConference.get(c);
1028 Log.d(this, "onVideoStateChanged set video state %d", videoState);
1029 mAdapter.setVideoState(id, videoState);
1030 }
1031
1032 @Override
1033 public void onVideoProviderChanged(Conference c, Connection.VideoProvider videoProvider) {
1034 String id = mIdByConference.get(c);
1035 Log.d(this, "onVideoProviderChanged: Connection: %s, VideoProvider: %s", c,
1036 videoProvider);
1037 mAdapter.setVideoProvider(id, videoProvider);
1038 }
Andrew Lee0f51da32015-04-16 13:11:55 -07001039
1040 @Override
Andrew Leeedc625f2015-04-14 13:38:12 -07001041 public void onStatusHintsChanged(Conference conference, StatusHints statusHints) {
1042 String id = mIdByConference.get(conference);
Tyler Gunndee56a82016-03-23 16:06:34 -07001043 if (id != null) {
1044 mAdapter.setStatusHints(id, statusHints);
1045 }
Andrew Leeedc625f2015-04-14 13:38:12 -07001046 }
Santos Cordon6b7f9552015-05-27 17:21:45 -07001047
1048 @Override
Tyler Gunndee56a82016-03-23 16:06:34 -07001049 public void onExtrasChanged(Conference c, Bundle extras) {
1050 String id = mIdByConference.get(c);
1051 if (id != null) {
1052 mAdapter.putExtras(id, extras);
1053 }
1054 }
1055
1056 @Override
1057 public void onExtrasRemoved(Conference c, List<String> keys) {
1058 String id = mIdByConference.get(c);
1059 if (id != null) {
1060 mAdapter.removeExtras(id, keys);
1061 }
Santos Cordon6b7f9552015-05-27 17:21:45 -07001062 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07001063 };
1064
Ihab Awad542e0ea2014-05-16 10:22:16 -07001065 private final Connection.Listener mConnectionListener = new Connection.Listener() {
1066 @Override
1067 public void onStateChanged(Connection c, int state) {
1068 String id = mIdByConnection.get(c);
Ihab Awad42b30e12014-05-22 09:49:34 -07001069 Log.d(this, "Adapter set state %s %s", id, Connection.stateToString(state));
Ihab Awad542e0ea2014-05-16 10:22:16 -07001070 switch (state) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001071 case Connection.STATE_ACTIVE:
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001072 mAdapter.setActive(id);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001073 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001074 case Connection.STATE_DIALING:
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001075 mAdapter.setDialing(id);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001076 break;
Tyler Gunnc96b5e02016-07-07 22:53:57 -07001077 case Connection.STATE_PULLING_CALL:
1078 mAdapter.setPulling(id);
1079 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001080 case Connection.STATE_DISCONNECTED:
Ihab Awad542e0ea2014-05-16 10:22:16 -07001081 // Handled in onDisconnected()
1082 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001083 case Connection.STATE_HOLDING:
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001084 mAdapter.setOnHold(id);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001085 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001086 case Connection.STATE_NEW:
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001087 // Nothing to tell Telecom
Ihab Awad542e0ea2014-05-16 10:22:16 -07001088 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001089 case Connection.STATE_RINGING:
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001090 mAdapter.setRinging(id);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001091 break;
1092 }
1093 }
1094
1095 @Override
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001096 public void onDisconnected(Connection c, DisconnectCause disconnectCause) {
Ihab Awad542e0ea2014-05-16 10:22:16 -07001097 String id = mIdByConnection.get(c);
Andrew Lee26786392014-09-16 18:14:59 -07001098 Log.d(this, "Adapter set disconnected %s", disconnectCause);
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001099 mAdapter.setDisconnected(id, disconnectCause);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001100 }
1101
1102 @Override
Tyler Gunnaa07df82014-07-17 07:50:22 -07001103 public void onVideoStateChanged(Connection c, int videoState) {
1104 String id = mIdByConnection.get(c);
1105 Log.d(this, "Adapter set video state %d", videoState);
1106 mAdapter.setVideoState(id, videoState);
1107 }
1108
1109 @Override
Andrew Lee100e2932014-09-08 15:34:24 -07001110 public void onAddressChanged(Connection c, Uri address, int presentation) {
Sailesh Nepal61203862014-07-11 14:50:13 -07001111 String id = mIdByConnection.get(c);
Andrew Lee100e2932014-09-08 15:34:24 -07001112 mAdapter.setAddress(id, address, presentation);
Sailesh Nepal61203862014-07-11 14:50:13 -07001113 }
1114
1115 @Override
1116 public void onCallerDisplayNameChanged(
1117 Connection c, String callerDisplayName, int presentation) {
1118 String id = mIdByConnection.get(c);
1119 mAdapter.setCallerDisplayName(id, callerDisplayName, presentation);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001120 }
1121
1122 @Override
Ihab Awad542e0ea2014-05-16 10:22:16 -07001123 public void onDestroyed(Connection c) {
1124 removeConnection(c);
1125 }
Ihab Awadf8358972014-05-28 16:46:42 -07001126
1127 @Override
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001128 public void onPostDialWait(Connection c, String remaining) {
Sailesh Nepal091768c2014-06-30 15:15:23 -07001129 String id = mIdByConnection.get(c);
1130 Log.d(this, "Adapter onPostDialWait %s, %s", c, remaining);
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001131 mAdapter.onPostDialWait(id, remaining);
Sailesh Nepal091768c2014-06-30 15:15:23 -07001132 }
1133
1134 @Override
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001135 public void onPostDialChar(Connection c, char nextChar) {
1136 String id = mIdByConnection.get(c);
1137 Log.d(this, "Adapter onPostDialChar %s, %s", c, nextChar);
1138 mAdapter.onPostDialChar(id, nextChar);
1139 }
1140
1141 @Override
Andrew Lee100e2932014-09-08 15:34:24 -07001142 public void onRingbackRequested(Connection c, boolean ringback) {
Ihab Awadf8358972014-05-28 16:46:42 -07001143 String id = mIdByConnection.get(c);
1144 Log.d(this, "Adapter onRingback %b", ringback);
Andrew Lee100e2932014-09-08 15:34:24 -07001145 mAdapter.setRingbackRequested(id, ringback);
Ihab Awadf8358972014-05-28 16:46:42 -07001146 }
Santos Cordonb6939982014-06-04 20:20:58 -07001147
1148 @Override
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001149 public void onConnectionCapabilitiesChanged(Connection c, int capabilities) {
Santos Cordonb6939982014-06-04 20:20:58 -07001150 String id = mIdByConnection.get(c);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001151 Log.d(this, "capabilities: parcelableconnection: %s",
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001152 Connection.capabilitiesToString(capabilities));
1153 mAdapter.setConnectionCapabilities(id, capabilities);
Santos Cordonb6939982014-06-04 20:20:58 -07001154 }
1155
Santos Cordonb6939982014-06-04 20:20:58 -07001156 @Override
Tyler Gunn720c6642016-03-22 09:02:47 -07001157 public void onConnectionPropertiesChanged(Connection c, int properties) {
1158 String id = mIdByConnection.get(c);
1159 Log.d(this, "properties: parcelableconnection: %s",
1160 Connection.propertiesToString(properties));
1161 mAdapter.setConnectionProperties(id, properties);
1162 }
1163
1164 @Override
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001165 public void onVideoProviderChanged(Connection c, Connection.VideoProvider videoProvider) {
Andrew Lee5ffbe8b2014-06-20 16:29:33 -07001166 String id = mIdByConnection.get(c);
Rekha Kumar07366812015-03-24 16:42:31 -07001167 Log.d(this, "onVideoProviderChanged: Connection: %s, VideoProvider: %s", c,
1168 videoProvider);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001169 mAdapter.setVideoProvider(id, videoProvider);
Andrew Lee5ffbe8b2014-06-20 16:29:33 -07001170 }
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001171
1172 @Override
Sailesh Nepal001bbbb2014-07-15 14:40:39 -07001173 public void onAudioModeIsVoipChanged(Connection c, boolean isVoip) {
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001174 String id = mIdByConnection.get(c);
Andrew Lee100e2932014-09-08 15:34:24 -07001175 mAdapter.setIsVoipAudioMode(id, isVoip);
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001176 }
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001177
1178 @Override
Sailesh Nepal001bbbb2014-07-15 14:40:39 -07001179 public void onStatusHintsChanged(Connection c, StatusHints statusHints) {
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001180 String id = mIdByConnection.get(c);
1181 mAdapter.setStatusHints(id, statusHints);
1182 }
Sailesh Nepal2ab88cc2014-07-18 14:49:18 -07001183
1184 @Override
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001185 public void onConferenceablesChanged(
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001186 Connection connection, List<Conferenceable> conferenceables) {
Ihab Awadb8e85c72014-08-23 20:34:57 -07001187 mAdapter.setConferenceableConnections(
1188 mIdByConnection.get(connection),
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001189 createIdList(conferenceables));
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001190 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07001191
1192 @Override
1193 public void onConferenceChanged(Connection connection, Conference conference) {
1194 String id = mIdByConnection.get(connection);
1195 if (id != null) {
1196 String conferenceId = null;
1197 if (conference != null) {
1198 conferenceId = mIdByConference.get(conference);
1199 }
1200 mAdapter.setIsConferenced(id, conferenceId);
1201 }
1202 }
Anthony Lee17455a32015-04-24 15:25:29 -07001203
1204 @Override
1205 public void onConferenceMergeFailed(Connection connection) {
1206 String id = mIdByConnection.get(connection);
1207 if (id != null) {
1208 mAdapter.onConferenceMergeFailed(id);
1209 }
1210 }
Santos Cordon6b7f9552015-05-27 17:21:45 -07001211
1212 @Override
Tyler Gunndee56a82016-03-23 16:06:34 -07001213 public void onExtrasChanged(Connection c, Bundle extras) {
1214 String id = mIdByConnection.get(c);
Santos Cordon6b7f9552015-05-27 17:21:45 -07001215 if (id != null) {
Tyler Gunndee56a82016-03-23 16:06:34 -07001216 mAdapter.putExtras(id, extras);
Santos Cordon6b7f9552015-05-27 17:21:45 -07001217 }
1218 }
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001219
Tyler Gunnf5035432017-01-09 09:43:12 -08001220 @Override
Tyler Gunndee56a82016-03-23 16:06:34 -07001221 public void onExtrasRemoved(Connection c, List<String> keys) {
1222 String id = mIdByConnection.get(c);
1223 if (id != null) {
1224 mAdapter.removeExtras(id, keys);
1225 }
1226 }
1227
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08001228 @Override
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001229 public void onConnectionEvent(Connection connection, String event, Bundle extras) {
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08001230 String id = mIdByConnection.get(connection);
1231 if (id != null) {
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001232 mAdapter.onConnectionEvent(id, event, extras);
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08001233 }
1234 }
Tyler Gunnf5035432017-01-09 09:43:12 -08001235
1236 @Override
1237 public void onAudioRouteChanged(Connection c, int audioRoute) {
1238 String id = mIdByConnection.get(c);
1239 if (id != null) {
1240 mAdapter.setAudioRoute(id, audioRoute);
1241 }
1242 }
Hall Liu57006aa2017-02-06 10:49:48 -08001243
1244 @Override
1245 public void onRttInitiationSuccess(Connection c) {
1246 String id = mIdByConnection.get(c);
1247 if (id != null) {
1248 mAdapter.onRttInitiationSuccess(id);
1249 }
1250 }
1251
1252 @Override
1253 public void onRttInitiationFailure(Connection c, int reason) {
1254 String id = mIdByConnection.get(c);
1255 if (id != null) {
1256 mAdapter.onRttInitiationFailure(id, reason);
1257 }
1258 }
1259
1260 @Override
1261 public void onRttSessionRemotelyTerminated(Connection c) {
1262 String id = mIdByConnection.get(c);
1263 if (id != null) {
1264 mAdapter.onRttSessionRemotelyTerminated(id);
1265 }
1266 }
1267
1268 @Override
1269 public void onRemoteRttRequest(Connection c) {
1270 String id = mIdByConnection.get(c);
1271 if (id != null) {
1272 mAdapter.onRemoteRttRequest(id);
1273 }
1274 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001275 };
1276
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001277 /** {@inheritDoc} */
Ihab Awad542e0ea2014-05-16 10:22:16 -07001278 @Override
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001279 public final IBinder onBind(Intent intent) {
1280 return mBinder;
1281 }
1282
Santos Cordon29f2f2e2014-09-11 19:50:24 -07001283 /** {@inheritDoc} */
1284 @Override
1285 public boolean onUnbind(Intent intent) {
1286 endAllConnections();
1287 return super.onUnbind(intent);
1288 }
1289
Sailesh Nepalc5b01572014-07-14 16:29:44 -07001290 /**
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001291 * This can be used by telecom to either create a new outgoing call or attach to an existing
1292 * incoming call. In either case, telecom will cycle through a set of services and call
Sailesh Nepalc5b01572014-07-14 16:29:44 -07001293 * createConnection util a connection service cancels the process or completes it successfully.
1294 */
Ihab Awadf8b69882014-07-25 15:14:01 -07001295 private void createConnection(
1296 final PhoneAccountHandle callManagerAccount,
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001297 final String callId,
Ihab Awadf8b69882014-07-25 15:14:01 -07001298 final ConnectionRequest request,
Yorke Leec3cf9822014-10-02 09:38:39 -07001299 boolean isIncoming,
1300 boolean isUnknown) {
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001301 Log.d(this, "createConnection, callManagerAccount: %s, callId: %s, request: %s, " +
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001302 "isIncoming: %b, isUnknown: %b", callManagerAccount, callId, request,
1303 isIncoming,
Yorke Leec3cf9822014-10-02 09:38:39 -07001304 isUnknown);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001305
Yorke Leec3cf9822014-10-02 09:38:39 -07001306 Connection connection = isUnknown ? onCreateUnknownConnection(callManagerAccount, request)
1307 : isIncoming ? onCreateIncomingConnection(callManagerAccount, request)
Ihab Awad6107bab2014-08-18 09:23:25 -07001308 : onCreateOutgoingConnection(callManagerAccount, request);
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001309 Log.d(this, "createConnection, connection: %s", connection);
1310 if (connection == null) {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001311 connection = Connection.createFailedConnection(
1312 new DisconnectCause(DisconnectCause.ERROR));
Sailesh Nepalc5b01572014-07-14 16:29:44 -07001313 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001314
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001315 connection.setTelecomCallId(callId);
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001316 if (connection.getState() != Connection.STATE_DISCONNECTED) {
Ihab Awad6107bab2014-08-18 09:23:25 -07001317 addConnection(callId, connection);
1318 }
1319
Andrew Lee100e2932014-09-08 15:34:24 -07001320 Uri address = connection.getAddress();
1321 String number = address == null ? "null" : address.getSchemeSpecificPart();
Tyler Gunn720c6642016-03-22 09:02:47 -07001322 Log.v(this, "createConnection, number: %s, state: %s, capabilities: %s, properties: %s",
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001323 Connection.toLogSafePhoneNumber(number),
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001324 Connection.stateToString(connection.getState()),
Tyler Gunn720c6642016-03-22 09:02:47 -07001325 Connection.capabilitiesToString(connection.getConnectionCapabilities()),
1326 Connection.propertiesToString(connection.getConnectionProperties()));
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001327
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001328 Log.d(this, "createConnection, calling handleCreateConnectionSuccessful %s", callId);
Ihab Awad6107bab2014-08-18 09:23:25 -07001329 mAdapter.handleCreateConnectionComplete(
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001330 callId,
Evan Charltonbf11f982014-07-20 22:06:28 -07001331 request,
1332 new ParcelableConnection(
1333 request.getAccountHandle(),
1334 connection.getState(),
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001335 connection.getConnectionCapabilities(),
Tyler Gunn720c6642016-03-22 09:02:47 -07001336 connection.getConnectionProperties(),
Christine Hallstrom4e22d6d2016-11-30 16:06:42 -08001337 connection.getSupportedAudioRoutes(),
Andrew Lee100e2932014-09-08 15:34:24 -07001338 connection.getAddress(),
1339 connection.getAddressPresentation(),
Evan Charltonbf11f982014-07-20 22:06:28 -07001340 connection.getCallerDisplayName(),
1341 connection.getCallerDisplayNamePresentation(),
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001342 connection.getVideoProvider() == null ?
1343 null : connection.getVideoProvider().getInterface(),
Sailesh Nepal8b9d3ca2014-08-14 17:39:34 -07001344 connection.getVideoState(),
Andrew Lee100e2932014-09-08 15:34:24 -07001345 connection.isRingbackRequested(),
Sailesh Nepal8b9d3ca2014-08-14 17:39:34 -07001346 connection.getAudioModeIsVoip(),
Roshan Piuse927ec02015-07-15 15:47:21 -07001347 connection.getConnectTimeMillis(),
Ihab Awad6107bab2014-08-18 09:23:25 -07001348 connection.getStatusHints(),
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001349 connection.getDisconnectCause(),
Santos Cordon6b7f9552015-05-27 17:21:45 -07001350 createIdList(connection.getConferenceables()),
1351 connection.getExtras()));
Tyler Gunnf5035432017-01-09 09:43:12 -08001352
1353 if (isIncoming && request.shouldShowIncomingCallUi() &&
1354 (connection.getConnectionProperties() & Connection.PROPERTY_SELF_MANAGED) ==
1355 Connection.PROPERTY_SELF_MANAGED) {
1356 // Tell ConnectionService to show its incoming call UX.
1357 connection.onShowIncomingCallUi();
1358 }
Shriram Ganesh6bf35ac2014-12-11 17:53:38 -08001359 if (isUnknown) {
1360 triggerConferenceRecalculate();
1361 }
Evan Charltonbf11f982014-07-20 22:06:28 -07001362 }
1363
Tyler Gunn159f35c2017-03-02 09:28:37 -08001364 private void createConnectionFailed(final PhoneAccountHandle callManagerAccount,
1365 final String callId, final ConnectionRequest request,
1366 boolean isIncoming) {
Tyler Gunn3edafc12017-01-31 10:49:05 -08001367
1368 Log.i(this, "createConnectionFailed %s", callId);
1369 if (isIncoming) {
Tyler Gunn159f35c2017-03-02 09:28:37 -08001370 onCreateIncomingConnectionFailed(callManagerAccount, request);
Tyler Gunn3edafc12017-01-31 10:49:05 -08001371 } else {
Tyler Gunn159f35c2017-03-02 09:28:37 -08001372 onCreateOutgoingConnectionFailed(callManagerAccount, request);
Tyler Gunn3edafc12017-01-31 10:49:05 -08001373 }
1374 }
1375
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001376 private void abort(String callId) {
Ihab Awad60ac30b2014-05-20 22:32:12 -07001377 Log.d(this, "abort %s", callId);
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001378 findConnectionForAction(callId, "abort").onAbort();
Ihab Awad542e0ea2014-05-16 10:22:16 -07001379 }
1380
Tyler Gunnbe74de02014-08-29 14:51:48 -07001381 private void answerVideo(String callId, int videoState) {
1382 Log.d(this, "answerVideo %s", callId);
Andrew Lee8da4c3c2014-07-16 10:11:42 -07001383 findConnectionForAction(callId, "answer").onAnswer(videoState);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001384 }
1385
Tyler Gunnbe74de02014-08-29 14:51:48 -07001386 private void answer(String callId) {
1387 Log.d(this, "answer %s", callId);
1388 findConnectionForAction(callId, "answer").onAnswer();
1389 }
1390
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001391 private void reject(String callId) {
Ihab Awad60ac30b2014-05-20 22:32:12 -07001392 Log.d(this, "reject %s", callId);
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001393 findConnectionForAction(callId, "reject").onReject();
Ihab Awad542e0ea2014-05-16 10:22:16 -07001394 }
1395
Bryce Lee81901682015-08-28 16:38:02 -07001396 private void reject(String callId, String rejectWithMessage) {
1397 Log.d(this, "reject %s with message", callId);
1398 findConnectionForAction(callId, "reject").onReject(rejectWithMessage);
1399 }
1400
Bryce Leecac50772015-11-17 15:13:29 -08001401 private void silence(String callId) {
1402 Log.d(this, "silence %s", callId);
1403 findConnectionForAction(callId, "silence").onSilence();
1404 }
1405
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001406 private void disconnect(String callId) {
Ihab Awad60ac30b2014-05-20 22:32:12 -07001407 Log.d(this, "disconnect %s", callId);
Santos Cordon0159ac02014-08-21 14:28:11 -07001408 if (mConnectionById.containsKey(callId)) {
1409 findConnectionForAction(callId, "disconnect").onDisconnect();
1410 } else {
1411 findConferenceForAction(callId, "disconnect").onDisconnect();
1412 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001413 }
1414
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001415 private void hold(String callId) {
Ihab Awad60ac30b2014-05-20 22:32:12 -07001416 Log.d(this, "hold %s", callId);
Santos Cordon0159ac02014-08-21 14:28:11 -07001417 if (mConnectionById.containsKey(callId)) {
1418 findConnectionForAction(callId, "hold").onHold();
1419 } else {
1420 findConferenceForAction(callId, "hold").onHold();
1421 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001422 }
1423
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001424 private void unhold(String callId) {
Ihab Awad60ac30b2014-05-20 22:32:12 -07001425 Log.d(this, "unhold %s", callId);
Santos Cordon0159ac02014-08-21 14:28:11 -07001426 if (mConnectionById.containsKey(callId)) {
1427 findConnectionForAction(callId, "unhold").onUnhold();
1428 } else {
1429 findConferenceForAction(callId, "unhold").onUnhold();
1430 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001431 }
1432
Yorke Lee4af59352015-05-13 14:14:54 -07001433 private void onCallAudioStateChanged(String callId, CallAudioState callAudioState) {
1434 Log.d(this, "onAudioStateChanged %s %s", callId, callAudioState);
Yorke Leea0d3ca92014-09-15 19:18:13 -07001435 if (mConnectionById.containsKey(callId)) {
Yorke Lee4af59352015-05-13 14:14:54 -07001436 findConnectionForAction(callId, "onCallAudioStateChanged").setCallAudioState(
1437 callAudioState);
Yorke Leea0d3ca92014-09-15 19:18:13 -07001438 } else {
Yorke Lee4af59352015-05-13 14:14:54 -07001439 findConferenceForAction(callId, "onCallAudioStateChanged").setCallAudioState(
1440 callAudioState);
Yorke Leea0d3ca92014-09-15 19:18:13 -07001441 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001442 }
1443
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001444 private void playDtmfTone(String callId, char digit) {
1445 Log.d(this, "playDtmfTone %s %c", callId, digit);
Yorke Leea0d3ca92014-09-15 19:18:13 -07001446 if (mConnectionById.containsKey(callId)) {
1447 findConnectionForAction(callId, "playDtmfTone").onPlayDtmfTone(digit);
1448 } else {
1449 findConferenceForAction(callId, "playDtmfTone").onPlayDtmfTone(digit);
1450 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001451 }
1452
1453 private void stopDtmfTone(String callId) {
1454 Log.d(this, "stopDtmfTone %s", callId);
Yorke Leea0d3ca92014-09-15 19:18:13 -07001455 if (mConnectionById.containsKey(callId)) {
1456 findConnectionForAction(callId, "stopDtmfTone").onStopDtmfTone();
1457 } else {
1458 findConferenceForAction(callId, "stopDtmfTone").onStopDtmfTone();
1459 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001460 }
1461
Santos Cordon823fd3c2014-08-07 18:35:18 -07001462 private void conference(String callId1, String callId2) {
1463 Log.d(this, "conference %s, %s", callId1, callId2);
Santos Cordon980acb92014-05-31 10:31:19 -07001464
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001465 // Attempt to get second connection or conference.
Santos Cordon823fd3c2014-08-07 18:35:18 -07001466 Connection connection2 = findConnectionForAction(callId2, "conference");
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001467 Conference conference2 = getNullConference();
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001468 if (connection2 == getNullConnection()) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001469 conference2 = findConferenceForAction(callId2, "conference");
1470 if (conference2 == getNullConference()) {
1471 Log.w(this, "Connection2 or Conference2 missing in conference request %s.",
1472 callId2);
1473 return;
1474 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07001475 }
Santos Cordonb6939982014-06-04 20:20:58 -07001476
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001477 // Attempt to get first connection or conference and perform merge.
Ihab Awad50e35062014-09-30 09:17:03 -07001478 Connection connection1 = findConnectionForAction(callId1, "conference");
1479 if (connection1 == getNullConnection()) {
1480 Conference conference1 = findConferenceForAction(callId1, "addConnection");
1481 if (conference1 == getNullConference()) {
1482 Log.w(this,
1483 "Connection1 or Conference1 missing in conference request %s.",
1484 callId1);
1485 } else {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001486 // Call 1 is a conference.
1487 if (connection2 != getNullConnection()) {
1488 // Call 2 is a connection so merge via call 1 (conference).
1489 conference1.onMerge(connection2);
1490 } else {
1491 // Call 2 is ALSO a conference; this should never happen.
1492 Log.wtf(this, "There can only be one conference and an attempt was made to " +
1493 "merge two conferences.");
1494 return;
1495 }
Ihab Awad50e35062014-09-30 09:17:03 -07001496 }
1497 } else {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001498 // Call 1 is a connection.
1499 if (conference2 != getNullConference()) {
1500 // Call 2 is a conference, so merge via call 2.
1501 conference2.onMerge(connection1);
1502 } else {
1503 // Call 2 is a connection, so merge together.
1504 onConference(connection1, connection2);
1505 }
Ihab Awad50e35062014-09-30 09:17:03 -07001506 }
Santos Cordon980acb92014-05-31 10:31:19 -07001507 }
1508
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001509 private void splitFromConference(String callId) {
Santos Cordonb6939982014-06-04 20:20:58 -07001510 Log.d(this, "splitFromConference(%s)", callId);
Santos Cordon980acb92014-05-31 10:31:19 -07001511
1512 Connection connection = findConnectionForAction(callId, "splitFromConference");
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001513 if (connection == getNullConnection()) {
Santos Cordon980acb92014-05-31 10:31:19 -07001514 Log.w(this, "Connection missing in conference request %s.", callId);
1515 return;
1516 }
1517
Santos Cordon0159ac02014-08-21 14:28:11 -07001518 Conference conference = connection.getConference();
1519 if (conference != null) {
1520 conference.onSeparate(connection);
1521 }
Santos Cordon980acb92014-05-31 10:31:19 -07001522 }
1523
Santos Cordona4868042014-09-04 17:39:22 -07001524 private void mergeConference(String callId) {
1525 Log.d(this, "mergeConference(%s)", callId);
1526 Conference conference = findConferenceForAction(callId, "mergeConference");
1527 if (conference != null) {
1528 conference.onMerge();
1529 }
1530 }
1531
1532 private void swapConference(String callId) {
1533 Log.d(this, "swapConference(%s)", callId);
1534 Conference conference = findConferenceForAction(callId, "swapConference");
1535 if (conference != null) {
1536 conference.onSwap();
1537 }
1538 }
1539
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001540 /**
1541 * Notifies a {@link Connection} of a request to pull an external call.
1542 *
1543 * See {@link Call#pullExternalCall()}.
1544 *
1545 * @param callId The ID of the call to pull.
1546 */
1547 private void pullExternalCall(String callId) {
1548 Log.d(this, "pullExternalCall(%s)", callId);
1549 Connection connection = findConnectionForAction(callId, "pullExternalCall");
1550 if (connection != null) {
1551 connection.onPullExternalCall();
1552 }
1553 }
1554
1555 /**
1556 * Notifies a {@link Connection} of a call event.
1557 *
1558 * See {@link Call#sendCallEvent(String, Bundle)}.
1559 *
1560 * @param callId The ID of the call receiving the event.
1561 * @param event The event.
1562 * @param extras Extras associated with the event.
1563 */
1564 private void sendCallEvent(String callId, String event, Bundle extras) {
1565 Log.d(this, "sendCallEvent(%s, %s)", callId, event);
1566 Connection connection = findConnectionForAction(callId, "sendCallEvent");
1567 if (connection != null) {
1568 connection.onCallEvent(event, extras);
1569 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001570 }
1571
Tyler Gunndee56a82016-03-23 16:06:34 -07001572 /**
1573 * Notifies a {@link Connection} or {@link Conference} of a change to the extras from Telecom.
1574 * <p>
1575 * These extra changes can originate from Telecom itself, or from an {@link InCallService} via
1576 * the {@link android.telecom.Call#putExtra(String, boolean)},
1577 * {@link android.telecom.Call#putExtra(String, int)},
1578 * {@link android.telecom.Call#putExtra(String, String)},
1579 * {@link Call#removeExtras(List)}.
1580 *
1581 * @param callId The ID of the call receiving the event.
1582 * @param extras The new extras bundle.
1583 */
1584 private void handleExtrasChanged(String callId, Bundle extras) {
1585 Log.d(this, "handleExtrasChanged(%s, %s)", callId, extras);
1586 if (mConnectionById.containsKey(callId)) {
1587 findConnectionForAction(callId, "handleExtrasChanged").handleExtrasChanged(extras);
1588 } else if (mConferenceById.containsKey(callId)) {
1589 findConferenceForAction(callId, "handleExtrasChanged").handleExtrasChanged(extras);
1590 }
1591 }
1592
Hall Liu57006aa2017-02-06 10:49:48 -08001593 private void startRtt(String callId, Connection.RttTextStream rttTextStream) {
1594 Log.d(this, "startRtt(%s)", callId);
1595 if (mConnectionById.containsKey(callId)) {
1596 findConnectionForAction(callId, "startRtt").onStartRtt(rttTextStream);
1597 } else if (mConferenceById.containsKey(callId)) {
1598 Log.w(this, "startRtt called on a conference.");
1599 }
1600 }
1601
1602 private void stopRtt(String callId) {
1603 Log.d(this, "stopRtt(%s)", callId);
1604 if (mConnectionById.containsKey(callId)) {
1605 findConnectionForAction(callId, "stopRtt").onStopRtt();
1606 } else if (mConferenceById.containsKey(callId)) {
1607 Log.w(this, "stopRtt called on a conference.");
1608 }
1609 }
1610
1611 private void handleRttUpgradeResponse(String callId, Connection.RttTextStream rttTextStream) {
1612 Log.d(this, "handleRttUpgradeResponse(%s, %s)", callId, rttTextStream == null);
1613 if (mConnectionById.containsKey(callId)) {
1614 findConnectionForAction(callId, "handleRttUpgradeResponse")
1615 .handleRttUpgradeResponse(rttTextStream);
1616 } else if (mConferenceById.containsKey(callId)) {
1617 Log.w(this, "handleRttUpgradeResponse called on a conference.");
1618 }
1619 }
1620
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001621 private void onPostDialContinue(String callId, boolean proceed) {
Evan Charlton6dea4ac2014-06-03 14:07:13 -07001622 Log.d(this, "onPostDialContinue(%s)", callId);
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001623 findConnectionForAction(callId, "stopDtmfTone").onPostDialContinue(proceed);
Evan Charlton6dea4ac2014-06-03 14:07:13 -07001624 }
1625
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001626 private void onAdapterAttached() {
Ihab Awad9c3f1882014-06-30 21:17:13 -07001627 if (mAreAccountsInitialized) {
Santos Cordon52d8a152014-06-17 19:08:45 -07001628 // No need to query again if we already did it.
1629 return;
1630 }
1631
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001632 mAdapter.queryRemoteConnectionServices(new RemoteServiceCallback.Stub() {
Santos Cordon52d8a152014-06-17 19:08:45 -07001633 @Override
1634 public void onResult(
1635 final List<ComponentName> componentNames,
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001636 final List<IBinder> services) {
Brad Ebinger0c3541b2016-11-01 14:11:38 -07001637 mHandler.post(new android.telecom.Logging.Runnable("oAA.qRCS.oR", null /*lock*/) {
Ihab Awad6107bab2014-08-18 09:23:25 -07001638 @Override
Brad Ebinger0c3541b2016-11-01 14:11:38 -07001639 public void loggedRun() {
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001640 for (int i = 0; i < componentNames.size() && i < services.size(); i++) {
Santos Cordon52d8a152014-06-17 19:08:45 -07001641 mRemoteConnectionManager.addConnectionService(
1642 componentNames.get(i),
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001643 IConnectionService.Stub.asInterface(services.get(i)));
Santos Cordon52d8a152014-06-17 19:08:45 -07001644 }
Ihab Awad5d0410f2014-07-30 10:07:40 -07001645 onAccountsInitialized();
Sailesh Nepalc5b01572014-07-14 16:29:44 -07001646 Log.d(this, "remote connection services found: " + services);
Santos Cordon52d8a152014-06-17 19:08:45 -07001647 }
Brad Ebinger0c3541b2016-11-01 14:11:38 -07001648 }.prepare());
Santos Cordon52d8a152014-06-17 19:08:45 -07001649 }
1650
1651 @Override
1652 public void onError() {
Brad Ebinger0c3541b2016-11-01 14:11:38 -07001653 mHandler.post(new android.telecom.Logging.Runnable("oAA.qRCS.oE", null /*lock*/) {
Ihab Awad6107bab2014-08-18 09:23:25 -07001654 @Override
Brad Ebinger0c3541b2016-11-01 14:11:38 -07001655 public void loggedRun() {
Ihab Awad9c3f1882014-06-30 21:17:13 -07001656 mAreAccountsInitialized = true;
Santos Cordon52d8a152014-06-17 19:08:45 -07001657 }
Brad Ebinger0c3541b2016-11-01 14:11:38 -07001658 }.prepare());
Santos Cordon52d8a152014-06-17 19:08:45 -07001659 }
1660 });
1661 }
1662
Ihab Awadf8b69882014-07-25 15:14:01 -07001663 /**
1664 * Ask some other {@code ConnectionService} to create a {@code RemoteConnection} given an
Santos Cordona663f862014-10-29 13:49:58 -07001665 * incoming request. This is used by {@code ConnectionService}s that are registered with
1666 * {@link PhoneAccount#CAPABILITY_CONNECTION_MANAGER} and want to be able to manage
1667 * SIM-based incoming calls.
Ihab Awadf8b69882014-07-25 15:14:01 -07001668 *
1669 * @param connectionManagerPhoneAccount See description at
1670 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
1671 * @param request Details about the incoming call.
1672 * @return The {@code Connection} object to satisfy this call, or {@code null} to
1673 * not handle the call.
1674 */
1675 public final RemoteConnection createRemoteIncomingConnection(
1676 PhoneAccountHandle connectionManagerPhoneAccount,
1677 ConnectionRequest request) {
1678 return mRemoteConnectionManager.createRemoteConnection(
1679 connectionManagerPhoneAccount, request, true);
Santos Cordon52d8a152014-06-17 19:08:45 -07001680 }
1681
1682 /**
Ihab Awadf8b69882014-07-25 15:14:01 -07001683 * Ask some other {@code ConnectionService} to create a {@code RemoteConnection} given an
Santos Cordona663f862014-10-29 13:49:58 -07001684 * outgoing request. This is used by {@code ConnectionService}s that are registered with
1685 * {@link PhoneAccount#CAPABILITY_CONNECTION_MANAGER} and want to be able to use the
1686 * SIM-based {@code ConnectionService} to place its outgoing calls.
Ihab Awadf8b69882014-07-25 15:14:01 -07001687 *
1688 * @param connectionManagerPhoneAccount See description at
1689 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
Cuihtlauac ALVARADO0b3b2a52016-09-13 14:49:41 +02001690 * @param request Details about the outgoing call.
Ihab Awadf8b69882014-07-25 15:14:01 -07001691 * @return The {@code Connection} object to satisfy this call, or {@code null} to
1692 * not handle the call.
1693 */
1694 public final RemoteConnection createRemoteOutgoingConnection(
1695 PhoneAccountHandle connectionManagerPhoneAccount,
1696 ConnectionRequest request) {
1697 return mRemoteConnectionManager.createRemoteConnection(
1698 connectionManagerPhoneAccount, request, false);
1699 }
1700
1701 /**
Santos Cordona663f862014-10-29 13:49:58 -07001702 * Indicates to the relevant {@code RemoteConnectionService} that the specified
1703 * {@link RemoteConnection}s should be merged into a conference call.
1704 * <p>
1705 * If the conference request is successful, the method {@link #onRemoteConferenceAdded} will
1706 * be invoked.
1707 *
1708 * @param remoteConnection1 The first of the remote connections to conference.
1709 * @param remoteConnection2 The second of the remote connections to conference.
Ihab Awadb8e85c72014-08-23 20:34:57 -07001710 */
1711 public final void conferenceRemoteConnections(
Santos Cordona663f862014-10-29 13:49:58 -07001712 RemoteConnection remoteConnection1,
1713 RemoteConnection remoteConnection2) {
1714 mRemoteConnectionManager.conferenceRemoteConnections(remoteConnection1, remoteConnection2);
Ihab Awadb8e85c72014-08-23 20:34:57 -07001715 }
1716
1717 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07001718 * Adds a new conference call. When a conference call is created either as a result of an
1719 * explicit request via {@link #onConference} or otherwise, the connection service should supply
1720 * an instance of {@link Conference} by invoking this method. A conference call provided by this
1721 * method will persist until {@link Conference#destroy} is invoked on the conference instance.
1722 *
1723 * @param conference The new conference object.
1724 */
1725 public final void addConference(Conference conference) {
Rekha Kumar07366812015-03-24 16:42:31 -07001726 Log.d(this, "addConference: conference=%s", conference);
1727
Santos Cordon823fd3c2014-08-07 18:35:18 -07001728 String id = addConferenceInternal(conference);
1729 if (id != null) {
1730 List<String> connectionIds = new ArrayList<>(2);
1731 for (Connection connection : conference.getConnections()) {
1732 if (mIdByConnection.containsKey(connection)) {
1733 connectionIds.add(mIdByConnection.get(connection));
1734 }
1735 }
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001736 conference.setTelecomCallId(id);
Santos Cordon823fd3c2014-08-07 18:35:18 -07001737 ParcelableConference parcelableConference = new ParcelableConference(
Nancy Chenea38cca2014-09-05 16:38:49 -07001738 conference.getPhoneAccountHandle(),
Santos Cordon823fd3c2014-08-07 18:35:18 -07001739 conference.getState(),
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001740 conference.getConnectionCapabilities(),
Tyler Gunn720c6642016-03-22 09:02:47 -07001741 conference.getConnectionProperties(),
Tyler Gunncd5d33c2015-01-12 09:02:01 -08001742 connectionIds,
Rekha Kumar07366812015-03-24 16:42:31 -07001743 conference.getVideoProvider() == null ?
1744 null : conference.getVideoProvider().getInterface(),
1745 conference.getVideoState(),
Andrew Lee3e3e2f22015-04-16 13:48:43 -07001746 conference.getConnectTimeMillis(),
Santos Cordon6b7f9552015-05-27 17:21:45 -07001747 conference.getStatusHints(),
1748 conference.getExtras());
Andrew Lee0f51da32015-04-16 13:11:55 -07001749
Santos Cordon823fd3c2014-08-07 18:35:18 -07001750 mAdapter.addConferenceCall(id, parcelableConference);
Rekha Kumar07366812015-03-24 16:42:31 -07001751 mAdapter.setVideoProvider(id, conference.getVideoProvider());
1752 mAdapter.setVideoState(id, conference.getVideoState());
Santos Cordon823fd3c2014-08-07 18:35:18 -07001753
1754 // Go through any child calls and set the parent.
1755 for (Connection connection : conference.getConnections()) {
1756 String connectionId = mIdByConnection.get(connection);
1757 if (connectionId != null) {
1758 mAdapter.setIsConferenced(connectionId, id);
1759 }
1760 }
1761 }
1762 }
1763
1764 /**
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07001765 * Adds a connection created by the {@link ConnectionService} and informs telecom of the new
1766 * connection.
1767 *
1768 * @param phoneAccountHandle The phone account handle for the connection.
1769 * @param connection The connection to add.
1770 */
1771 public final void addExistingConnection(PhoneAccountHandle phoneAccountHandle,
1772 Connection connection) {
1773
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001774 String id = addExistingConnectionInternal(phoneAccountHandle, connection);
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07001775 if (id != null) {
1776 List<String> emptyList = new ArrayList<>(0);
1777
1778 ParcelableConnection parcelableConnection = new ParcelableConnection(
1779 phoneAccountHandle,
1780 connection.getState(),
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001781 connection.getConnectionCapabilities(),
Tyler Gunn720c6642016-03-22 09:02:47 -07001782 connection.getConnectionProperties(),
Christine Hallstrom4e22d6d2016-11-30 16:06:42 -08001783 connection.getSupportedAudioRoutes(),
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07001784 connection.getAddress(),
1785 connection.getAddressPresentation(),
1786 connection.getCallerDisplayName(),
1787 connection.getCallerDisplayNamePresentation(),
1788 connection.getVideoProvider() == null ?
1789 null : connection.getVideoProvider().getInterface(),
1790 connection.getVideoState(),
1791 connection.isRingbackRequested(),
1792 connection.getAudioModeIsVoip(),
Roshan Piuse927ec02015-07-15 15:47:21 -07001793 connection.getConnectTimeMillis(),
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07001794 connection.getStatusHints(),
1795 connection.getDisconnectCause(),
Santos Cordon6b7f9552015-05-27 17:21:45 -07001796 emptyList,
1797 connection.getExtras());
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07001798 mAdapter.addExistingConnection(id, parcelableConnection);
1799 }
1800 }
1801
1802 /**
Ihab Awadf8b69882014-07-25 15:14:01 -07001803 * Returns all the active {@code Connection}s for which this {@code ConnectionService}
1804 * has taken responsibility.
1805 *
1806 * @return A collection of {@code Connection}s created by this {@code ConnectionService}.
Santos Cordonb6939982014-06-04 20:20:58 -07001807 */
Sailesh Nepal091768c2014-06-30 15:15:23 -07001808 public final Collection<Connection> getAllConnections() {
Santos Cordonb6939982014-06-04 20:20:58 -07001809 return mConnectionById.values();
1810 }
1811
1812 /**
Santos Cordona6018b92016-02-16 14:23:12 -08001813 * Returns all the active {@code Conference}s for which this {@code ConnectionService}
1814 * has taken responsibility.
1815 *
1816 * @return A collection of {@code Conference}s created by this {@code ConnectionService}.
1817 */
1818 public final Collection<Conference> getAllConferences() {
1819 return mConferenceById.values();
1820 }
1821
1822 /**
Ihab Awadf8b69882014-07-25 15:14:01 -07001823 * Create a {@code Connection} given an incoming request. This is used to attach to existing
1824 * incoming calls.
Evan Charltonbf11f982014-07-20 22:06:28 -07001825 *
Ihab Awadf8b69882014-07-25 15:14:01 -07001826 * @param connectionManagerPhoneAccount See description at
1827 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
1828 * @param request Details about the incoming call.
1829 * @return The {@code Connection} object to satisfy this call, or {@code null} to
1830 * not handle the call.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001831 */
Ihab Awadf8b69882014-07-25 15:14:01 -07001832 public Connection onCreateIncomingConnection(
1833 PhoneAccountHandle connectionManagerPhoneAccount,
1834 ConnectionRequest request) {
1835 return null;
1836 }
Sailesh Nepalc5b01572014-07-14 16:29:44 -07001837
1838 /**
Tyler Gunnf5035432017-01-09 09:43:12 -08001839 * Called by Telecom to inform the {@link ConnectionService} that its request to create a new
1840 * incoming {@link Connection} was denied.
1841 * <p>
1842 * Used when a self-managed {@link ConnectionService} attempts to create a new incoming
1843 * {@link Connection}, but Telecom has determined that the call cannot be allowed at this time.
1844 * The {@link ConnectionService} is responsible for silently rejecting the new incoming
1845 * {@link Connection}.
1846 * <p>
1847 * See {@link TelecomManager#isIncomingCallPermitted(PhoneAccountHandle)} for more information.
1848 *
Tyler Gunn159f35c2017-03-02 09:28:37 -08001849 * @param connectionManagerPhoneAccount See description at
1850 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
Tyler Gunnf5035432017-01-09 09:43:12 -08001851 * @param request The incoming connection request.
1852 */
Tyler Gunn159f35c2017-03-02 09:28:37 -08001853 public void onCreateIncomingConnectionFailed(PhoneAccountHandle connectionManagerPhoneAccount,
1854 ConnectionRequest request) {
Tyler Gunnf5035432017-01-09 09:43:12 -08001855 }
1856
1857 /**
1858 * Called by Telecom to inform the {@link ConnectionService} that its request to create a new
1859 * outgoing {@link Connection} was denied.
1860 * <p>
1861 * Used when a self-managed {@link ConnectionService} attempts to create a new outgoing
1862 * {@link Connection}, but Telecom has determined that the call cannot be placed at this time.
1863 * The {@link ConnectionService} is responisible for informing the user that the
1864 * {@link Connection} cannot be made at this time.
1865 * <p>
1866 * See {@link TelecomManager#isOutgoingCallPermitted(PhoneAccountHandle)} for more information.
1867 *
Tyler Gunn159f35c2017-03-02 09:28:37 -08001868 * @param connectionManagerPhoneAccount See description at
1869 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
Tyler Gunnf5035432017-01-09 09:43:12 -08001870 * @param request The outgoing connection request.
1871 */
Tyler Gunn159f35c2017-03-02 09:28:37 -08001872 public void onCreateOutgoingConnectionFailed(PhoneAccountHandle connectionManagerPhoneAccount,
1873 ConnectionRequest request) {
Tyler Gunnf5035432017-01-09 09:43:12 -08001874 }
1875
1876 /**
Shriram Ganesh6bf35ac2014-12-11 17:53:38 -08001877 * Trigger recalculate functinality for conference calls. This is used when a Telephony
1878 * Connection is part of a conference controller but is not yet added to Connection
1879 * Service and hence cannot be added to the conference call.
1880 *
1881 * @hide
1882 */
1883 public void triggerConferenceRecalculate() {
1884 }
1885
1886 /**
Ihab Awadf8b69882014-07-25 15:14:01 -07001887 * Create a {@code Connection} given an outgoing request. This is used to initiate new
1888 * outgoing calls.
Sailesh Nepalc5b01572014-07-14 16:29:44 -07001889 *
Ihab Awadf8b69882014-07-25 15:14:01 -07001890 * @param connectionManagerPhoneAccount The connection manager account to use for managing
1891 * this call.
1892 * <p>
1893 * If this parameter is not {@code null}, it means that this {@code ConnectionService}
1894 * has registered one or more {@code PhoneAccount}s having
1895 * {@link PhoneAccount#CAPABILITY_CONNECTION_MANAGER}. This parameter will contain
1896 * one of these {@code PhoneAccount}s, while the {@code request} will contain another
1897 * (usually but not always distinct) {@code PhoneAccount} to be used for actually
1898 * making the connection.
1899 * <p>
1900 * If this parameter is {@code null}, it means that this {@code ConnectionService} is
1901 * being asked to make a direct connection. The
1902 * {@link ConnectionRequest#getAccountHandle()} of parameter {@code request} will be
1903 * a {@code PhoneAccount} registered by this {@code ConnectionService} to use for
1904 * making the connection.
1905 * @param request Details about the outgoing call.
1906 * @return The {@code Connection} object to satisfy this call, or the result of an invocation
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001907 * of {@link Connection#createFailedConnection(DisconnectCause)} to not handle the call.
Sailesh Nepalc5b01572014-07-14 16:29:44 -07001908 */
Ihab Awadf8b69882014-07-25 15:14:01 -07001909 public Connection onCreateOutgoingConnection(
1910 PhoneAccountHandle connectionManagerPhoneAccount,
1911 ConnectionRequest request) {
1912 return null;
1913 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001914
1915 /**
Yorke Leec3cf9822014-10-02 09:38:39 -07001916 * Create a {@code Connection} for a new unknown call. An unknown call is a call originating
1917 * from the ConnectionService that was neither a user-initiated outgoing call, nor an incoming
1918 * call created using
1919 * {@code TelecomManager#addNewIncomingCall(PhoneAccountHandle, android.os.Bundle)}.
1920 *
Yorke Lee770ed6e2014-10-06 18:58:52 -07001921 * @hide
Yorke Leec3cf9822014-10-02 09:38:39 -07001922 */
1923 public Connection onCreateUnknownConnection(PhoneAccountHandle connectionManagerPhoneAccount,
1924 ConnectionRequest request) {
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001925 return null;
Yorke Leec3cf9822014-10-02 09:38:39 -07001926 }
1927
1928 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07001929 * Conference two specified connections. Invoked when the user has made a request to merge the
1930 * specified connections into a conference call. In response, the connection service should
1931 * create an instance of {@link Conference} and pass it into {@link #addConference}.
Santos Cordonb6939982014-06-04 20:20:58 -07001932 *
Santos Cordon823fd3c2014-08-07 18:35:18 -07001933 * @param connection1 A connection to merge into a conference call.
1934 * @param connection2 A connection to merge into a conference call.
Santos Cordonb6939982014-06-04 20:20:58 -07001935 */
Santos Cordon823fd3c2014-08-07 18:35:18 -07001936 public void onConference(Connection connection1, Connection connection2) {}
Santos Cordonb6939982014-06-04 20:20:58 -07001937
Santos Cordona663f862014-10-29 13:49:58 -07001938 /**
1939 * Indicates that a remote conference has been created for existing {@link RemoteConnection}s.
1940 * When this method is invoked, this {@link ConnectionService} should create its own
1941 * representation of the conference call and send it to telecom using {@link #addConference}.
1942 * <p>
1943 * This is only relevant to {@link ConnectionService}s which are registered with
1944 * {@link PhoneAccount#CAPABILITY_CONNECTION_MANAGER}.
1945 *
1946 * @param conference The remote conference call.
1947 */
Ihab Awadb8e85c72014-08-23 20:34:57 -07001948 public void onRemoteConferenceAdded(RemoteConference conference) {}
1949
Santos Cordon823fd3c2014-08-07 18:35:18 -07001950 /**
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07001951 * Called when an existing connection is added remotely.
1952 * @param connection The existing connection which was added.
1953 */
1954 public void onRemoteExistingConnectionAdded(RemoteConnection connection) {}
1955
1956 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07001957 * @hide
1958 */
1959 public boolean containsConference(Conference conference) {
1960 return mIdByConference.containsKey(conference);
1961 }
1962
Ihab Awadb8e85c72014-08-23 20:34:57 -07001963 /** {@hide} */
1964 void addRemoteConference(RemoteConference remoteConference) {
1965 onRemoteConferenceAdded(remoteConference);
1966 }
1967
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07001968 /** {@hide} */
1969 void addRemoteExistingConnection(RemoteConnection remoteConnection) {
1970 onRemoteExistingConnectionAdded(remoteConnection);
1971 }
1972
Ihab Awad5d0410f2014-07-30 10:07:40 -07001973 private void onAccountsInitialized() {
1974 mAreAccountsInitialized = true;
1975 for (Runnable r : mPreInitializationConnectionRequests) {
1976 r.run();
1977 }
1978 mPreInitializationConnectionRequests.clear();
1979 }
1980
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07001981 /**
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001982 * Adds an existing connection to the list of connections, identified by a new call ID unique
1983 * to this connection service.
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07001984 *
1985 * @param connection The connection.
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001986 * @return The ID of the connection (e.g. the call-id).
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07001987 */
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001988 private String addExistingConnectionInternal(PhoneAccountHandle handle, Connection connection) {
1989 String id;
Tyler Gunn2282bb92016-10-17 15:48:19 -07001990
1991 if (connection.getExtras() != null && connection.getExtras()
1992 .containsKey(Connection.EXTRA_ORIGINAL_CONNECTION_ID)) {
1993 id = connection.getExtras().getString(Connection.EXTRA_ORIGINAL_CONNECTION_ID);
1994 Log.d(this, "addExistingConnectionInternal - conn %s reusing original id %s",
1995 connection.getTelecomCallId(), id);
1996 } else if (handle == null) {
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001997 // If no phone account handle was provided, we cannot be sure the call ID is unique,
1998 // so just use a random UUID.
1999 id = UUID.randomUUID().toString();
2000 } else {
2001 // Phone account handle was provided, so use the ConnectionService class name as a
2002 // prefix for a unique incremental call ID.
2003 id = handle.getComponentName().getClassName() + "@" + getNextCallId();
2004 }
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002005 addConnection(id, connection);
2006 return id;
2007 }
2008
Ihab Awad542e0ea2014-05-16 10:22:16 -07002009 private void addConnection(String callId, Connection connection) {
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002010 connection.setTelecomCallId(callId);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002011 mConnectionById.put(callId, connection);
2012 mIdByConnection.put(connection, callId);
2013 connection.addConnectionListener(mConnectionListener);
Santos Cordon823fd3c2014-08-07 18:35:18 -07002014 connection.setConnectionService(this);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002015 }
2016
Anthony Lee30e65842014-11-06 16:30:53 -08002017 /** {@hide} */
2018 protected void removeConnection(Connection connection) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07002019 connection.unsetConnectionService(this);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002020 connection.removeConnectionListener(mConnectionListener);
Chenjie Luoe370b532016-05-12 16:59:43 -07002021 String id = mIdByConnection.get(connection);
2022 if (id != null) {
2023 mConnectionById.remove(id);
2024 mIdByConnection.remove(connection);
2025 mAdapter.removeCall(id);
2026 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002027 }
2028
Santos Cordon823fd3c2014-08-07 18:35:18 -07002029 private String addConferenceInternal(Conference conference) {
Tyler Gunn2282bb92016-10-17 15:48:19 -07002030 String originalId = null;
2031 if (conference.getExtras() != null && conference.getExtras()
2032 .containsKey(Connection.EXTRA_ORIGINAL_CONNECTION_ID)) {
2033 originalId = conference.getExtras().getString(Connection.EXTRA_ORIGINAL_CONNECTION_ID);
2034 Log.d(this, "addConferenceInternal: conf %s reusing original id %s",
2035 conference.getTelecomCallId(),
2036 originalId);
2037 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07002038 if (mIdByConference.containsKey(conference)) {
2039 Log.w(this, "Re-adding an existing conference: %s.", conference);
2040 } else if (conference != null) {
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002041 // Conferences do not (yet) have a PhoneAccountHandle associated with them, so we
2042 // cannot determine a ConnectionService class name to associate with the ID, so use
2043 // a unique UUID (for now).
Tyler Gunn2282bb92016-10-17 15:48:19 -07002044 String id = originalId == null ? UUID.randomUUID().toString() : originalId;
Santos Cordon823fd3c2014-08-07 18:35:18 -07002045 mConferenceById.put(id, conference);
2046 mIdByConference.put(conference, id);
2047 conference.addListener(mConferenceListener);
2048 return id;
2049 }
2050
2051 return null;
2052 }
2053
2054 private void removeConference(Conference conference) {
2055 if (mIdByConference.containsKey(conference)) {
2056 conference.removeListener(mConferenceListener);
2057
2058 String id = mIdByConference.get(conference);
2059 mConferenceById.remove(id);
2060 mIdByConference.remove(conference);
2061 mAdapter.removeCall(id);
2062 }
2063 }
2064
Ihab Awad542e0ea2014-05-16 10:22:16 -07002065 private Connection findConnectionForAction(String callId, String action) {
2066 if (mConnectionById.containsKey(callId)) {
2067 return mConnectionById.get(callId);
2068 }
Ihab Awad60ac30b2014-05-20 22:32:12 -07002069 Log.w(this, "%s - Cannot find Connection %s", action, callId);
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07002070 return getNullConnection();
2071 }
2072
2073 static synchronized Connection getNullConnection() {
2074 if (sNullConnection == null) {
2075 sNullConnection = new Connection() {};
2076 }
2077 return sNullConnection;
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002078 }
Santos Cordon0159ac02014-08-21 14:28:11 -07002079
2080 private Conference findConferenceForAction(String conferenceId, String action) {
2081 if (mConferenceById.containsKey(conferenceId)) {
2082 return mConferenceById.get(conferenceId);
2083 }
2084 Log.w(this, "%s - Cannot find conference %s", action, conferenceId);
2085 return getNullConference();
2086 }
2087
Ihab Awadb8e85c72014-08-23 20:34:57 -07002088 private List<String> createConnectionIdList(List<Connection> connections) {
2089 List<String> ids = new ArrayList<>();
2090 for (Connection c : connections) {
2091 if (mIdByConnection.containsKey(c)) {
2092 ids.add(mIdByConnection.get(c));
2093 }
2094 }
2095 Collections.sort(ids);
2096 return ids;
2097 }
2098
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002099 /**
2100 * Builds a list of {@link Connection} and {@link Conference} IDs based on the list of
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002101 * {@link Conferenceable}s passed in.
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002102 *
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002103 * @param conferenceables The {@link Conferenceable} connections and conferences.
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002104 * @return List of string conference and call Ids.
2105 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002106 private List<String> createIdList(List<Conferenceable> conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002107 List<String> ids = new ArrayList<>();
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002108 for (Conferenceable c : conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002109 // Only allow Connection and Conference conferenceables.
2110 if (c instanceof Connection) {
2111 Connection connection = (Connection) c;
2112 if (mIdByConnection.containsKey(connection)) {
2113 ids.add(mIdByConnection.get(connection));
2114 }
2115 } else if (c instanceof Conference) {
2116 Conference conference = (Conference) c;
2117 if (mIdByConference.containsKey(conference)) {
2118 ids.add(mIdByConference.get(conference));
2119 }
2120 }
2121 }
2122 Collections.sort(ids);
2123 return ids;
2124 }
2125
Santos Cordon0159ac02014-08-21 14:28:11 -07002126 private Conference getNullConference() {
2127 if (sNullConference == null) {
2128 sNullConference = new Conference(null) {};
2129 }
2130 return sNullConference;
2131 }
Santos Cordon29f2f2e2014-09-11 19:50:24 -07002132
2133 private void endAllConnections() {
2134 // Unbound from telecomm. We should end all connections and conferences.
2135 for (Connection connection : mIdByConnection.keySet()) {
2136 // only operate on top-level calls. Conference calls will be removed on their own.
2137 if (connection.getConference() == null) {
2138 connection.onDisconnect();
2139 }
2140 }
2141 for (Conference conference : mIdByConference.keySet()) {
2142 conference.onDisconnect();
2143 }
2144 }
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002145
2146 /**
2147 * Retrieves the next call ID as maintainted by the connection service.
2148 *
2149 * @return The call ID.
2150 */
2151 private int getNextCallId() {
Brad Ebingerb32d4f82016-10-24 16:40:49 -07002152 synchronized (mIdSyncRoot) {
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002153 return ++mId;
2154 }
2155 }
Santos Cordon980acb92014-05-31 10:31:19 -07002156}