blob: 58e80b474ef9e5f2c98303af153c0997e398abdd [file] [log] [blame]
Ihab Awad542e0ea2014-05-16 10:22:16 -07001/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Tyler Gunnef9f6f92014-09-12 22:16:17 -070017package android.telecom;
Ihab Awad542e0ea2014-05-16 10:22:16 -070018
Santos Cordon5c6fa952014-07-20 17:47:12 -070019import android.annotation.SdkConstant;
Sailesh Nepal2a46b902014-07-04 17:21:07 -070020import android.app.Service;
Santos Cordon52d8a152014-06-17 19:08:45 -070021import android.content.ComponentName;
Santos Cordon5c6fa952014-07-20 17:47:12 -070022import android.content.Intent;
Ihab Awad542e0ea2014-05-16 10:22:16 -070023import android.net.Uri;
Santos Cordon6b7f9552015-05-27 17:21:45 -070024import android.os.Bundle;
Santos Cordon52d8a152014-06-17 19:08:45 -070025import android.os.Handler;
26import android.os.IBinder;
27import android.os.Looper;
Sailesh Nepal2a46b902014-07-04 17:21:07 -070028import android.os.Message;
Hall Liub64ac4c2017-02-06 10:49:48 -080029import android.os.ParcelFileDescriptor;
30import android.os.RemoteException;
Brad Ebingerb32d4f82016-10-24 16:40:49 -070031import android.telecom.Logging.Session;
Andrew Lee14185762014-07-25 09:41:56 -070032
Sailesh Nepal2a46b902014-07-04 17:21:07 -070033import com.android.internal.os.SomeArgs;
Tyler Gunnef9f6f92014-09-12 22:16:17 -070034import com.android.internal.telecom.IConnectionService;
35import com.android.internal.telecom.IConnectionServiceAdapter;
36import com.android.internal.telecom.RemoteServiceCallback;
Santos Cordon52d8a152014-06-17 19:08:45 -070037
Ihab Awad5d0410f2014-07-30 10:07:40 -070038import java.util.ArrayList;
Santos Cordonb6939982014-06-04 20:20:58 -070039import java.util.Collection;
Santos Cordon7c7bc7f2014-07-28 18:15:48 -070040import java.util.Collections;
Santos Cordon52d8a152014-06-17 19:08:45 -070041import java.util.List;
Ihab Awad542e0ea2014-05-16 10:22:16 -070042import java.util.Map;
Santos Cordon823fd3c2014-08-07 18:35:18 -070043import java.util.UUID;
mike dooley95e80702014-09-18 14:07:52 -070044import java.util.concurrent.ConcurrentHashMap;
Ihab Awad542e0ea2014-05-16 10:22:16 -070045
46/**
Tyler Gunnf5035432017-01-09 09:43:12 -080047 * An abstract service that should be implemented by any apps which either:
48 * <ol>
49 * <li>Can make phone calls (VoIP or otherwise) and want those calls to be integrated into the
50 * built-in phone app. Referred to as a <b>system managed</b> {@link ConnectionService}.</li>
51 * <li>Are a standalone calling app and don't want their calls to be integrated into the
52 * built-in phone app. Referred to as a <b>self managed</b> {@link ConnectionService}.</li>
53 * </ol>
54 * Once implemented, the {@link ConnectionService} needs to take the following steps so that Telecom
55 * will bind to it:
Santos Cordona663f862014-10-29 13:49:58 -070056 * <p>
57 * 1. <i>Registration in AndroidManifest.xml</i>
58 * <br/>
59 * <pre>
60 * &lt;service android:name="com.example.package.MyConnectionService"
61 * android:label="@string/some_label_for_my_connection_service"
Yorke Lee249c12e2015-05-13 15:59:29 -070062 * android:permission="android.permission.BIND_TELECOM_CONNECTION_SERVICE"&gt;
Santos Cordona663f862014-10-29 13:49:58 -070063 * &lt;intent-filter&gt;
64 * &lt;action android:name="android.telecom.ConnectionService" /&gt;
65 * &lt;/intent-filter&gt;
66 * &lt;/service&gt;
67 * </pre>
68 * <p>
69 * 2. <i> Registration of {@link PhoneAccount} with {@link TelecomManager}.</i>
70 * <br/>
71 * See {@link PhoneAccount} and {@link TelecomManager#registerPhoneAccount} for more information.
72 * <p>
Tyler Gunnf5035432017-01-09 09:43:12 -080073 * System managed {@link ConnectionService}s must be enabled by the user in the phone app settings
kopriva82c591b2018-10-08 15:57:00 -070074 * before Telecom will bind to them. Self-managed {@link ConnectionService}s must be granted the
Tyler Gunnf5035432017-01-09 09:43:12 -080075 * appropriate permission before Telecom will bind to them.
76 * <p>
77 * Once registered and enabled by the user in the phone app settings or granted permission, telecom
78 * will bind to a {@link ConnectionService} implementation when it wants that
79 * {@link ConnectionService} to place a call or the service has indicated that is has an incoming
80 * call through {@link TelecomManager#addNewIncomingCall}. The {@link ConnectionService} can then
81 * expect a call to {@link #onCreateIncomingConnection} or {@link #onCreateOutgoingConnection}
82 * wherein it should provide a new instance of a {@link Connection} object. It is through this
83 * {@link Connection} object that telecom receives state updates and the {@link ConnectionService}
Santos Cordona663f862014-10-29 13:49:58 -070084 * receives call-commands such as answer, reject, hold and disconnect.
85 * <p>
Tyler Gunnf5035432017-01-09 09:43:12 -080086 * When there are no more live calls, telecom will unbind from the {@link ConnectionService}.
Ihab Awad542e0ea2014-05-16 10:22:16 -070087 */
Sailesh Nepal2a46b902014-07-04 17:21:07 -070088public abstract class ConnectionService extends Service {
Santos Cordon5c6fa952014-07-20 17:47:12 -070089 /**
90 * The {@link Intent} that must be declared as handled by the service.
91 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -070092 @SdkConstant(SdkConstant.SdkConstantType.SERVICE_ACTION)
Tyler Gunnef9f6f92014-09-12 22:16:17 -070093 public static final String SERVICE_INTERFACE = "android.telecom.ConnectionService";
Santos Cordon5c6fa952014-07-20 17:47:12 -070094
Tyler Gunn8bf76572017-04-06 15:30:08 -070095 /**
96 * Boolean extra used by Telecom to inform a {@link ConnectionService} that the purpose of it
97 * being asked to create a new outgoing {@link Connection} is to perform a handover of an
98 * ongoing call on the device from another {@link PhoneAccount}/{@link ConnectionService}. Will
99 * be specified in the {@link ConnectionRequest#getExtras()} passed by Telecom when
100 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)} is called.
101 * <p>
Tyler Gunn727c6bd2017-04-11 09:51:40 -0700102 * When your {@link ConnectionService} receives this extra, it should communicate the fact that
103 * this is a handover to the other device's matching {@link ConnectionService}. That
Tyler Gunn8bf76572017-04-06 15:30:08 -0700104 * {@link ConnectionService} will continue the handover using
105 * {@link TelecomManager#addNewIncomingCall(PhoneAccountHandle, Bundle)}, specifying
Tyler Gunn727c6bd2017-04-11 09:51:40 -0700106 * {@link TelecomManager#EXTRA_IS_HANDOVER}. Telecom will match the phone numbers of the
107 * handover call on the other device with ongoing calls for {@link ConnectionService}s which
108 * support {@link PhoneAccount#EXTRA_SUPPORTS_HANDOVER_FROM}.
Tyler Gunn8bf76572017-04-06 15:30:08 -0700109 * @hide
110 */
111 public static final String EXTRA_IS_HANDOVER = TelecomManager.EXTRA_IS_HANDOVER;
112
Ihab Awad542e0ea2014-05-16 10:22:16 -0700113 // Flag controlling whether PII is emitted into the logs
Ihab Awad60ac30b2014-05-20 22:32:12 -0700114 private static final boolean PII_DEBUG = Log.isLoggable(android.util.Log.DEBUG);
Ihab Awad542e0ea2014-05-16 10:22:16 -0700115
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700116 // Session Definitions
117 private static final String SESSION_HANDLER = "H.";
118 private static final String SESSION_ADD_CS_ADAPTER = "CS.aCSA";
119 private static final String SESSION_REMOVE_CS_ADAPTER = "CS.rCSA";
120 private static final String SESSION_CREATE_CONN = "CS.crCo";
Tyler Gunn041a1fe2017-05-12 10:04:49 -0700121 private static final String SESSION_CREATE_CONN_COMPLETE = "CS.crCoC";
Tyler Gunn44e01912017-01-31 10:49:05 -0800122 private static final String SESSION_CREATE_CONN_FAILED = "CS.crCoF";
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700123 private static final String SESSION_ABORT = "CS.ab";
124 private static final String SESSION_ANSWER = "CS.an";
125 private static final String SESSION_ANSWER_VIDEO = "CS.anV";
Pooja Jaind34698d2017-12-28 14:15:31 +0530126 private static final String SESSION_DEFLECT = "CS.def";
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700127 private static final String SESSION_REJECT = "CS.r";
128 private static final String SESSION_REJECT_MESSAGE = "CS.rWM";
129 private static final String SESSION_SILENCE = "CS.s";
130 private static final String SESSION_DISCONNECT = "CS.d";
131 private static final String SESSION_HOLD = "CS.h";
132 private static final String SESSION_UNHOLD = "CS.u";
133 private static final String SESSION_CALL_AUDIO_SC = "CS.cASC";
134 private static final String SESSION_PLAY_DTMF = "CS.pDT";
135 private static final String SESSION_STOP_DTMF = "CS.sDT";
136 private static final String SESSION_CONFERENCE = "CS.c";
137 private static final String SESSION_SPLIT_CONFERENCE = "CS.sFC";
138 private static final String SESSION_MERGE_CONFERENCE = "CS.mC";
139 private static final String SESSION_SWAP_CONFERENCE = "CS.sC";
140 private static final String SESSION_POST_DIAL_CONT = "CS.oPDC";
141 private static final String SESSION_PULL_EXTERNAL_CALL = "CS.pEC";
142 private static final String SESSION_SEND_CALL_EVENT = "CS.sCE";
Tyler Gunn79bc1ec2018-01-22 15:17:54 -0800143 private static final String SESSION_HANDOVER_COMPLETE = "CS.hC";
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700144 private static final String SESSION_EXTRAS_CHANGED = "CS.oEC";
Hall Liub64ac4c2017-02-06 10:49:48 -0800145 private static final String SESSION_START_RTT = "CS.+RTT";
Hall Liua549fed2018-02-09 16:40:03 -0800146 private static final String SESSION_UPDATE_RTT_PIPES = "CS.uRTT";
Hall Liub64ac4c2017-02-06 10:49:48 -0800147 private static final String SESSION_STOP_RTT = "CS.-RTT";
148 private static final String SESSION_RTT_UPGRADE_RESPONSE = "CS.rTRUR";
Pengquan Meng731c1a32017-11-21 18:01:13 -0800149 private static final String SESSION_CONNECTION_SERVICE_FOCUS_LOST = "CS.cSFL";
150 private static final String SESSION_CONNECTION_SERVICE_FOCUS_GAINED = "CS.cSFG";
Sanket Padawe4cc8ed532017-12-04 16:22:20 -0800151 private static final String SESSION_HANDOVER_FAILED = "CS.haF";
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700152
Ihab Awad8aecfed2014-08-08 17:06:11 -0700153 private static final int MSG_ADD_CONNECTION_SERVICE_ADAPTER = 1;
Sailesh Nepalc5b01572014-07-14 16:29:44 -0700154 private static final int MSG_CREATE_CONNECTION = 2;
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700155 private static final int MSG_ABORT = 3;
Sailesh Nepalc5b01572014-07-14 16:29:44 -0700156 private static final int MSG_ANSWER = 4;
157 private static final int MSG_REJECT = 5;
158 private static final int MSG_DISCONNECT = 6;
159 private static final int MSG_HOLD = 7;
160 private static final int MSG_UNHOLD = 8;
Yorke Lee4af59352015-05-13 14:14:54 -0700161 private static final int MSG_ON_CALL_AUDIO_STATE_CHANGED = 9;
Sailesh Nepalc5b01572014-07-14 16:29:44 -0700162 private static final int MSG_PLAY_DTMF_TONE = 10;
163 private static final int MSG_STOP_DTMF_TONE = 11;
164 private static final int MSG_CONFERENCE = 12;
165 private static final int MSG_SPLIT_FROM_CONFERENCE = 13;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700166 private static final int MSG_ON_POST_DIAL_CONTINUE = 14;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700167 private static final int MSG_REMOVE_CONNECTION_SERVICE_ADAPTER = 16;
Tyler Gunnbe74de02014-08-29 14:51:48 -0700168 private static final int MSG_ANSWER_VIDEO = 17;
Santos Cordona4868042014-09-04 17:39:22 -0700169 private static final int MSG_MERGE_CONFERENCE = 18;
170 private static final int MSG_SWAP_CONFERENCE = 19;
Bryce Lee81901682015-08-28 16:38:02 -0700171 private static final int MSG_REJECT_WITH_MESSAGE = 20;
Bryce Leecac50772015-11-17 15:13:29 -0800172 private static final int MSG_SILENCE = 21;
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700173 private static final int MSG_PULL_EXTERNAL_CALL = 22;
174 private static final int MSG_SEND_CALL_EVENT = 23;
Tyler Gunndee56a82016-03-23 16:06:34 -0700175 private static final int MSG_ON_EXTRAS_CHANGED = 24;
Tyler Gunn44e01912017-01-31 10:49:05 -0800176 private static final int MSG_CREATE_CONNECTION_FAILED = 25;
Hall Liub64ac4c2017-02-06 10:49:48 -0800177 private static final int MSG_ON_START_RTT = 26;
178 private static final int MSG_ON_STOP_RTT = 27;
179 private static final int MSG_RTT_UPGRADE_RESPONSE = 28;
Tyler Gunn041a1fe2017-05-12 10:04:49 -0700180 private static final int MSG_CREATE_CONNECTION_COMPLETE = 29;
Pengquan Meng731c1a32017-11-21 18:01:13 -0800181 private static final int MSG_CONNECTION_SERVICE_FOCUS_LOST = 30;
182 private static final int MSG_CONNECTION_SERVICE_FOCUS_GAINED = 31;
Sanket Padawe4cc8ed532017-12-04 16:22:20 -0800183 private static final int MSG_HANDOVER_FAILED = 32;
Tyler Gunn79bc1ec2018-01-22 15:17:54 -0800184 private static final int MSG_HANDOVER_COMPLETE = 33;
Pooja Jaind34698d2017-12-28 14:15:31 +0530185 private static final int MSG_DEFLECT = 34;
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700186
Sailesh Nepalcf7020b2014-08-20 10:07:19 -0700187 private static Connection sNullConnection;
188
mike dooley95e80702014-09-18 14:07:52 -0700189 private final Map<String, Connection> mConnectionById = new ConcurrentHashMap<>();
190 private final Map<Connection, String> mIdByConnection = new ConcurrentHashMap<>();
191 private final Map<String, Conference> mConferenceById = new ConcurrentHashMap<>();
192 private final Map<Conference, String> mIdByConference = new ConcurrentHashMap<>();
Ihab Awadb8e85c72014-08-23 20:34:57 -0700193 private final RemoteConnectionManager mRemoteConnectionManager =
194 new RemoteConnectionManager(this);
Ihab Awad5d0410f2014-07-30 10:07:40 -0700195 private final List<Runnable> mPreInitializationConnectionRequests = new ArrayList<>();
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700196 private final ConnectionServiceAdapter mAdapter = new ConnectionServiceAdapter();
Ihab Awad542e0ea2014-05-16 10:22:16 -0700197
Santos Cordon823fd3c2014-08-07 18:35:18 -0700198 private boolean mAreAccountsInitialized = false;
Santos Cordon0159ac02014-08-21 14:28:11 -0700199 private Conference sNullConference;
Tyler Gunnf0500bd2015-09-01 10:59:48 -0700200 private Object mIdSyncRoot = new Object();
201 private int mId = 0;
Santos Cordon823fd3c2014-08-07 18:35:18 -0700202
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700203 private final IBinder mBinder = new IConnectionService.Stub() {
204 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700205 public void addConnectionServiceAdapter(IConnectionServiceAdapter adapter,
206 Session.Info sessionInfo) {
207 Log.startSession(sessionInfo, SESSION_ADD_CS_ADAPTER);
208 try {
209 SomeArgs args = SomeArgs.obtain();
210 args.arg1 = adapter;
211 args.arg2 = Log.createSubsession();
212 mHandler.obtainMessage(MSG_ADD_CONNECTION_SERVICE_ADAPTER, args).sendToTarget();
213 } finally {
214 Log.endSession();
215 }
Ihab Awad8aecfed2014-08-08 17:06:11 -0700216 }
217
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700218 public void removeConnectionServiceAdapter(IConnectionServiceAdapter adapter,
219 Session.Info sessionInfo) {
220 Log.startSession(sessionInfo, SESSION_REMOVE_CS_ADAPTER);
221 try {
222 SomeArgs args = SomeArgs.obtain();
223 args.arg1 = adapter;
224 args.arg2 = Log.createSubsession();
225 mHandler.obtainMessage(MSG_REMOVE_CONNECTION_SERVICE_ADAPTER, args).sendToTarget();
226 } finally {
227 Log.endSession();
228 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700229 }
230
231 @Override
Ihab Awadf8b69882014-07-25 15:14:01 -0700232 public void createConnection(
233 PhoneAccountHandle connectionManagerPhoneAccount,
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700234 String id,
Ihab Awadf8b69882014-07-25 15:14:01 -0700235 ConnectionRequest request,
Yorke Leec3cf9822014-10-02 09:38:39 -0700236 boolean isIncoming,
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700237 boolean isUnknown,
238 Session.Info sessionInfo) {
239 Log.startSession(sessionInfo, SESSION_CREATE_CONN);
240 try {
241 SomeArgs args = SomeArgs.obtain();
242 args.arg1 = connectionManagerPhoneAccount;
243 args.arg2 = id;
244 args.arg3 = request;
245 args.arg4 = Log.createSubsession();
246 args.argi1 = isIncoming ? 1 : 0;
247 args.argi2 = isUnknown ? 1 : 0;
248 mHandler.obtainMessage(MSG_CREATE_CONNECTION, args).sendToTarget();
249 } finally {
250 Log.endSession();
251 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700252 }
253
254 @Override
Tyler Gunn041a1fe2017-05-12 10:04:49 -0700255 public void createConnectionComplete(String id, Session.Info sessionInfo) {
256 Log.startSession(sessionInfo, SESSION_CREATE_CONN_COMPLETE);
257 try {
258 SomeArgs args = SomeArgs.obtain();
259 args.arg1 = id;
260 args.arg2 = Log.createSubsession();
261 mHandler.obtainMessage(MSG_CREATE_CONNECTION_COMPLETE, args).sendToTarget();
262 } finally {
263 Log.endSession();
264 }
265 }
266
267 @Override
Tyler Gunn44e01912017-01-31 10:49:05 -0800268 public void createConnectionFailed(
Tyler Gunn159f35c2017-03-02 09:28:37 -0800269 PhoneAccountHandle connectionManagerPhoneAccount,
Tyler Gunn44e01912017-01-31 10:49:05 -0800270 String callId,
271 ConnectionRequest request,
272 boolean isIncoming,
273 Session.Info sessionInfo) {
274 Log.startSession(sessionInfo, SESSION_CREATE_CONN_FAILED);
275 try {
276 SomeArgs args = SomeArgs.obtain();
277 args.arg1 = callId;
278 args.arg2 = request;
279 args.arg3 = Log.createSubsession();
Tyler Gunn159f35c2017-03-02 09:28:37 -0800280 args.arg4 = connectionManagerPhoneAccount;
Tyler Gunn44e01912017-01-31 10:49:05 -0800281 args.argi1 = isIncoming ? 1 : 0;
282 mHandler.obtainMessage(MSG_CREATE_CONNECTION_FAILED, args).sendToTarget();
283 } finally {
284 Log.endSession();
285 }
286 }
287
288 @Override
Sanket Padawe4cc8ed532017-12-04 16:22:20 -0800289 public void handoverFailed(String callId, ConnectionRequest request, int reason,
290 Session.Info sessionInfo) {
291 Log.startSession(sessionInfo, SESSION_HANDOVER_FAILED);
292 try {
293 SomeArgs args = SomeArgs.obtain();
294 args.arg1 = callId;
295 args.arg2 = request;
296 args.arg3 = Log.createSubsession();
297 args.arg4 = reason;
298 mHandler.obtainMessage(MSG_HANDOVER_FAILED, args).sendToTarget();
299 } finally {
300 Log.endSession();
301 }
302 }
303
304 @Override
Tyler Gunn79bc1ec2018-01-22 15:17:54 -0800305 public void handoverComplete(String callId, Session.Info sessionInfo) {
306 Log.startSession(sessionInfo, SESSION_HANDOVER_COMPLETE);
307 try {
308 SomeArgs args = SomeArgs.obtain();
309 args.arg1 = callId;
310 args.arg2 = Log.createSubsession();
311 mHandler.obtainMessage(MSG_HANDOVER_COMPLETE, args).sendToTarget();
312 } finally {
313 Log.endSession();
314 }
315 }
316
317 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700318 public void abort(String callId, Session.Info sessionInfo) {
319 Log.startSession(sessionInfo, SESSION_ABORT);
320 try {
321 SomeArgs args = SomeArgs.obtain();
322 args.arg1 = callId;
323 args.arg2 = Log.createSubsession();
324 mHandler.obtainMessage(MSG_ABORT, args).sendToTarget();
325 } finally {
326 Log.endSession();
327 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700328 }
329
330 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700331 public void answerVideo(String callId, int videoState, Session.Info sessionInfo) {
332 Log.startSession(sessionInfo, SESSION_ANSWER_VIDEO);
333 try {
334 SomeArgs args = SomeArgs.obtain();
335 args.arg1 = callId;
336 args.arg2 = Log.createSubsession();
337 args.argi1 = videoState;
338 mHandler.obtainMessage(MSG_ANSWER_VIDEO, args).sendToTarget();
339 } finally {
340 Log.endSession();
341 }
Tyler Gunnbe74de02014-08-29 14:51:48 -0700342 }
343
344 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700345 public void answer(String callId, Session.Info sessionInfo) {
346 Log.startSession(sessionInfo, SESSION_ANSWER);
347 try {
348 SomeArgs args = SomeArgs.obtain();
349 args.arg1 = callId;
350 args.arg2 = Log.createSubsession();
351 mHandler.obtainMessage(MSG_ANSWER, args).sendToTarget();
352 } finally {
353 Log.endSession();
354 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700355 }
356
357 @Override
Pooja Jaind34698d2017-12-28 14:15:31 +0530358 public void deflect(String callId, Uri address, Session.Info sessionInfo) {
359 Log.startSession(sessionInfo, SESSION_DEFLECT);
360 try {
361 SomeArgs args = SomeArgs.obtain();
362 args.arg1 = callId;
363 args.arg2 = address;
364 args.arg3 = Log.createSubsession();
365 mHandler.obtainMessage(MSG_DEFLECT, args).sendToTarget();
366 } finally {
367 Log.endSession();
368 }
369 }
370
371 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700372 public void reject(String callId, Session.Info sessionInfo) {
373 Log.startSession(sessionInfo, SESSION_REJECT);
374 try {
375 SomeArgs args = SomeArgs.obtain();
376 args.arg1 = callId;
377 args.arg2 = Log.createSubsession();
378 mHandler.obtainMessage(MSG_REJECT, args).sendToTarget();
379 } finally {
380 Log.endSession();
381 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700382 }
383
384 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700385 public void rejectWithMessage(String callId, String message, Session.Info sessionInfo) {
386 Log.startSession(sessionInfo, SESSION_REJECT_MESSAGE);
387 try {
388 SomeArgs args = SomeArgs.obtain();
389 args.arg1 = callId;
390 args.arg2 = message;
391 args.arg3 = Log.createSubsession();
392 mHandler.obtainMessage(MSG_REJECT_WITH_MESSAGE, args).sendToTarget();
393 } finally {
394 Log.endSession();
395 }
Bryce Lee81901682015-08-28 16:38:02 -0700396 }
397
398 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700399 public void silence(String callId, Session.Info sessionInfo) {
400 Log.startSession(sessionInfo, SESSION_SILENCE);
401 try {
402 SomeArgs args = SomeArgs.obtain();
403 args.arg1 = callId;
404 args.arg2 = Log.createSubsession();
405 mHandler.obtainMessage(MSG_SILENCE, args).sendToTarget();
406 } finally {
407 Log.endSession();
408 }
Bryce Leecac50772015-11-17 15:13:29 -0800409 }
410
411 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700412 public void disconnect(String callId, Session.Info sessionInfo) {
413 Log.startSession(sessionInfo, SESSION_DISCONNECT);
414 try {
415 SomeArgs args = SomeArgs.obtain();
416 args.arg1 = callId;
417 args.arg2 = Log.createSubsession();
418 mHandler.obtainMessage(MSG_DISCONNECT, args).sendToTarget();
419 } finally {
420 Log.endSession();
421 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700422 }
423
424 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700425 public void hold(String callId, Session.Info sessionInfo) {
426 Log.startSession(sessionInfo, SESSION_HOLD);
427 try {
428 SomeArgs args = SomeArgs.obtain();
429 args.arg1 = callId;
430 args.arg2 = Log.createSubsession();
431 mHandler.obtainMessage(MSG_HOLD, args).sendToTarget();
432 } finally {
433 Log.endSession();
434 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700435 }
436
437 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700438 public void unhold(String callId, Session.Info sessionInfo) {
439 Log.startSession(sessionInfo, SESSION_UNHOLD);
440 try {
441 SomeArgs args = SomeArgs.obtain();
442 args.arg1 = callId;
443 args.arg2 = Log.createSubsession();
444 mHandler.obtainMessage(MSG_UNHOLD, args).sendToTarget();
445 } finally {
446 Log.endSession();
447 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700448 }
449
450 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700451 public void onCallAudioStateChanged(String callId, CallAudioState callAudioState,
452 Session.Info sessionInfo) {
453 Log.startSession(sessionInfo, SESSION_CALL_AUDIO_SC);
454 try {
455 SomeArgs args = SomeArgs.obtain();
456 args.arg1 = callId;
457 args.arg2 = callAudioState;
458 args.arg3 = Log.createSubsession();
459 mHandler.obtainMessage(MSG_ON_CALL_AUDIO_STATE_CHANGED, args).sendToTarget();
460 } finally {
461 Log.endSession();
462 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700463 }
464
465 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700466 public void playDtmfTone(String callId, char digit, Session.Info sessionInfo) {
467 Log.startSession(sessionInfo, SESSION_PLAY_DTMF);
468 try {
469 SomeArgs args = SomeArgs.obtain();
470 args.arg1 = digit;
471 args.arg2 = callId;
472 args.arg3 = Log.createSubsession();
473 mHandler.obtainMessage(MSG_PLAY_DTMF_TONE, args).sendToTarget();
474 } finally {
475 Log.endSession();
476 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700477 }
478
479 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700480 public void stopDtmfTone(String callId, Session.Info sessionInfo) {
481 Log.startSession(sessionInfo, SESSION_STOP_DTMF);
482 try {
483 SomeArgs args = SomeArgs.obtain();
484 args.arg1 = callId;
485 args.arg2 = Log.createSubsession();
486 mHandler.obtainMessage(MSG_STOP_DTMF_TONE, args).sendToTarget();
487 } finally {
488 Log.endSession();
489 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700490 }
491
492 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700493 public void conference(String callId1, String callId2, Session.Info sessionInfo) {
494 Log.startSession(sessionInfo, SESSION_CONFERENCE);
495 try {
496 SomeArgs args = SomeArgs.obtain();
497 args.arg1 = callId1;
498 args.arg2 = callId2;
499 args.arg3 = Log.createSubsession();
500 mHandler.obtainMessage(MSG_CONFERENCE, args).sendToTarget();
501 } finally {
502 Log.endSession();
503 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700504 }
505
506 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700507 public void splitFromConference(String callId, Session.Info sessionInfo) {
508 Log.startSession(sessionInfo, SESSION_SPLIT_CONFERENCE);
509 try {
510 SomeArgs args = SomeArgs.obtain();
511 args.arg1 = callId;
512 args.arg2 = Log.createSubsession();
513 mHandler.obtainMessage(MSG_SPLIT_FROM_CONFERENCE, args).sendToTarget();
514 } finally {
515 Log.endSession();
516 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700517 }
518
519 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700520 public void mergeConference(String callId, Session.Info sessionInfo) {
521 Log.startSession(sessionInfo, SESSION_MERGE_CONFERENCE);
522 try {
523 SomeArgs args = SomeArgs.obtain();
524 args.arg1 = callId;
525 args.arg2 = Log.createSubsession();
526 mHandler.obtainMessage(MSG_MERGE_CONFERENCE, args).sendToTarget();
527 } finally {
528 Log.endSession();
529 }
Santos Cordona4868042014-09-04 17:39:22 -0700530 }
531
532 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700533 public void swapConference(String callId, Session.Info sessionInfo) {
534 Log.startSession(sessionInfo, SESSION_SWAP_CONFERENCE);
535 try {
536 SomeArgs args = SomeArgs.obtain();
537 args.arg1 = callId;
538 args.arg2 = Log.createSubsession();
539 mHandler.obtainMessage(MSG_SWAP_CONFERENCE, args).sendToTarget();
540 } finally {
541 Log.endSession();
542 }
Santos Cordona4868042014-09-04 17:39:22 -0700543 }
544
545 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700546 public void onPostDialContinue(String callId, boolean proceed, Session.Info sessionInfo) {
547 Log.startSession(sessionInfo, SESSION_POST_DIAL_CONT);
548 try {
549 SomeArgs args = SomeArgs.obtain();
550 args.arg1 = callId;
551 args.arg2 = Log.createSubsession();
552 args.argi1 = proceed ? 1 : 0;
553 mHandler.obtainMessage(MSG_ON_POST_DIAL_CONTINUE, args).sendToTarget();
554 } finally {
555 Log.endSession();
556 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700557 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700558
559 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700560 public void pullExternalCall(String callId, Session.Info sessionInfo) {
561 Log.startSession(sessionInfo, SESSION_PULL_EXTERNAL_CALL);
562 try {
563 SomeArgs args = SomeArgs.obtain();
564 args.arg1 = callId;
565 args.arg2 = Log.createSubsession();
566 mHandler.obtainMessage(MSG_PULL_EXTERNAL_CALL, args).sendToTarget();
567 } finally {
568 Log.endSession();
569 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700570 }
571
572 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700573 public void sendCallEvent(String callId, String event, Bundle extras,
574 Session.Info sessionInfo) {
575 Log.startSession(sessionInfo, SESSION_SEND_CALL_EVENT);
576 try {
577 SomeArgs args = SomeArgs.obtain();
578 args.arg1 = callId;
579 args.arg2 = event;
580 args.arg3 = extras;
581 args.arg4 = Log.createSubsession();
582 mHandler.obtainMessage(MSG_SEND_CALL_EVENT, args).sendToTarget();
583 } finally {
584 Log.endSession();
585 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700586 }
Tyler Gunndee56a82016-03-23 16:06:34 -0700587
588 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700589 public void onExtrasChanged(String callId, Bundle extras, Session.Info sessionInfo) {
590 Log.startSession(sessionInfo, SESSION_EXTRAS_CHANGED);
591 try {
592 SomeArgs args = SomeArgs.obtain();
593 args.arg1 = callId;
594 args.arg2 = extras;
595 args.arg3 = Log.createSubsession();
596 mHandler.obtainMessage(MSG_ON_EXTRAS_CHANGED, args).sendToTarget();
597 } finally {
598 Log.endSession();
599 }
Tyler Gunndee56a82016-03-23 16:06:34 -0700600 }
Hall Liub64ac4c2017-02-06 10:49:48 -0800601
602 @Override
603 public void startRtt(String callId, ParcelFileDescriptor fromInCall,
604 ParcelFileDescriptor toInCall, Session.Info sessionInfo) throws RemoteException {
605 Log.startSession(sessionInfo, SESSION_START_RTT);
606 try {
607 SomeArgs args = SomeArgs.obtain();
608 args.arg1 = callId;
609 args.arg2 = new Connection.RttTextStream(toInCall, fromInCall);
610 args.arg3 = Log.createSubsession();
611 mHandler.obtainMessage(MSG_ON_START_RTT, args).sendToTarget();
612 } finally {
613 Log.endSession();
614 }
615 }
616
617 @Override
618 public void stopRtt(String callId, Session.Info sessionInfo) throws RemoteException {
619 Log.startSession(sessionInfo, SESSION_STOP_RTT);
620 try {
621 SomeArgs args = SomeArgs.obtain();
622 args.arg1 = callId;
623 args.arg2 = Log.createSubsession();
624 mHandler.obtainMessage(MSG_ON_STOP_RTT, args).sendToTarget();
625 } finally {
626 Log.endSession();
627 }
628 }
629
630 @Override
631 public void respondToRttUpgradeRequest(String callId, ParcelFileDescriptor fromInCall,
632 ParcelFileDescriptor toInCall, Session.Info sessionInfo) throws RemoteException {
633 Log.startSession(sessionInfo, SESSION_RTT_UPGRADE_RESPONSE);
634 try {
635 SomeArgs args = SomeArgs.obtain();
636 args.arg1 = callId;
637 if (toInCall == null || fromInCall == null) {
638 args.arg2 = null;
639 } else {
640 args.arg2 = new Connection.RttTextStream(toInCall, fromInCall);
641 }
642 args.arg3 = Log.createSubsession();
643 mHandler.obtainMessage(MSG_RTT_UPGRADE_RESPONSE, args).sendToTarget();
644 } finally {
645 Log.endSession();
646 }
647 }
Pengquan Meng731c1a32017-11-21 18:01:13 -0800648
649 @Override
650 public void connectionServiceFocusLost(Session.Info sessionInfo) throws RemoteException {
651 Log.startSession(sessionInfo, SESSION_CONNECTION_SERVICE_FOCUS_LOST);
652 try {
653 mHandler.obtainMessage(MSG_CONNECTION_SERVICE_FOCUS_LOST).sendToTarget();
654 } finally {
655 Log.endSession();
656 }
657 }
658
659 @Override
660 public void connectionServiceFocusGained(Session.Info sessionInfo) throws RemoteException {
661 Log.startSession(sessionInfo, SESSION_CONNECTION_SERVICE_FOCUS_GAINED);
662 try {
663 mHandler.obtainMessage(MSG_CONNECTION_SERVICE_FOCUS_GAINED).sendToTarget();
664 } finally {
665 Log.endSession();
666 }
667 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700668 };
669
670 private final Handler mHandler = new Handler(Looper.getMainLooper()) {
671 @Override
672 public void handleMessage(Message msg) {
673 switch (msg.what) {
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700674 case MSG_ADD_CONNECTION_SERVICE_ADAPTER: {
675 SomeArgs args = (SomeArgs) msg.obj;
676 try {
677 IConnectionServiceAdapter adapter = (IConnectionServiceAdapter) args.arg1;
678 Log.continueSession((Session) args.arg2,
679 SESSION_HANDLER + SESSION_ADD_CS_ADAPTER);
680 mAdapter.addAdapter(adapter);
681 onAdapterAttached();
682 } finally {
683 args.recycle();
684 Log.endSession();
685 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700686 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700687 }
688 case MSG_REMOVE_CONNECTION_SERVICE_ADAPTER: {
689 SomeArgs args = (SomeArgs) msg.obj;
690 try {
691 Log.continueSession((Session) args.arg2,
692 SESSION_HANDLER + SESSION_REMOVE_CS_ADAPTER);
693 mAdapter.removeAdapter((IConnectionServiceAdapter) args.arg1);
694 } finally {
695 args.recycle();
696 Log.endSession();
697 }
Ihab Awad8aecfed2014-08-08 17:06:11 -0700698 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700699 }
Ihab Awadf8b69882014-07-25 15:14:01 -0700700 case MSG_CREATE_CONNECTION: {
701 SomeArgs args = (SomeArgs) msg.obj;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700702 Log.continueSession((Session) args.arg4, SESSION_HANDLER + SESSION_CREATE_CONN);
Ihab Awadf8b69882014-07-25 15:14:01 -0700703 try {
Ihab Awad5d0410f2014-07-30 10:07:40 -0700704 final PhoneAccountHandle connectionManagerPhoneAccount =
Ihab Awadf8b69882014-07-25 15:14:01 -0700705 (PhoneAccountHandle) args.arg1;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700706 final String id = (String) args.arg2;
707 final ConnectionRequest request = (ConnectionRequest) args.arg3;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700708 final boolean isIncoming = args.argi1 == 1;
Yorke Leec3cf9822014-10-02 09:38:39 -0700709 final boolean isUnknown = args.argi2 == 1;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700710 if (!mAreAccountsInitialized) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700711 Log.d(this, "Enqueueing pre-init request %s", id);
Brad Ebinger0c3541b2016-11-01 14:11:38 -0700712 mPreInitializationConnectionRequests.add(
713 new android.telecom.Logging.Runnable(
714 SESSION_HANDLER + SESSION_CREATE_CONN + ".pICR",
715 null /*lock*/) {
Ihab Awad5d0410f2014-07-30 10:07:40 -0700716 @Override
Brad Ebinger0c3541b2016-11-01 14:11:38 -0700717 public void loggedRun() {
Ihab Awad5d0410f2014-07-30 10:07:40 -0700718 createConnection(
719 connectionManagerPhoneAccount,
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700720 id,
Ihab Awad5d0410f2014-07-30 10:07:40 -0700721 request,
Yorke Leec3cf9822014-10-02 09:38:39 -0700722 isIncoming,
723 isUnknown);
Ihab Awad5d0410f2014-07-30 10:07:40 -0700724 }
Brad Ebinger0c3541b2016-11-01 14:11:38 -0700725 }.prepare());
Ihab Awad5d0410f2014-07-30 10:07:40 -0700726 } else {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700727 createConnection(
728 connectionManagerPhoneAccount,
729 id,
730 request,
Yorke Leec3cf9822014-10-02 09:38:39 -0700731 isIncoming,
732 isUnknown);
Ihab Awad5d0410f2014-07-30 10:07:40 -0700733 }
Ihab Awadf8b69882014-07-25 15:14:01 -0700734 } finally {
735 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700736 Log.endSession();
Ihab Awadf8b69882014-07-25 15:14:01 -0700737 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700738 break;
Ihab Awadf8b69882014-07-25 15:14:01 -0700739 }
Tyler Gunn041a1fe2017-05-12 10:04:49 -0700740 case MSG_CREATE_CONNECTION_COMPLETE: {
741 SomeArgs args = (SomeArgs) msg.obj;
742 Log.continueSession((Session) args.arg2,
743 SESSION_HANDLER + SESSION_CREATE_CONN_COMPLETE);
744 try {
745 final String id = (String) args.arg1;
746 if (!mAreAccountsInitialized) {
747 Log.d(this, "Enqueueing pre-init request %s", id);
748 mPreInitializationConnectionRequests.add(
749 new android.telecom.Logging.Runnable(
750 SESSION_HANDLER + SESSION_CREATE_CONN_COMPLETE
751 + ".pICR",
752 null /*lock*/) {
753 @Override
754 public void loggedRun() {
755 notifyCreateConnectionComplete(id);
756 }
757 }.prepare());
758 } else {
759 notifyCreateConnectionComplete(id);
760 }
761 } finally {
762 args.recycle();
763 Log.endSession();
764 }
765 break;
766 }
Tyler Gunn44e01912017-01-31 10:49:05 -0800767 case MSG_CREATE_CONNECTION_FAILED: {
768 SomeArgs args = (SomeArgs) msg.obj;
769 Log.continueSession((Session) args.arg3, SESSION_HANDLER +
770 SESSION_CREATE_CONN_FAILED);
771 try {
772 final String id = (String) args.arg1;
773 final ConnectionRequest request = (ConnectionRequest) args.arg2;
774 final boolean isIncoming = args.argi1 == 1;
Tyler Gunn159f35c2017-03-02 09:28:37 -0800775 final PhoneAccountHandle connectionMgrPhoneAccount =
776 (PhoneAccountHandle) args.arg4;
Tyler Gunn44e01912017-01-31 10:49:05 -0800777 if (!mAreAccountsInitialized) {
778 Log.d(this, "Enqueueing pre-init request %s", id);
779 mPreInitializationConnectionRequests.add(
780 new android.telecom.Logging.Runnable(
781 SESSION_HANDLER + SESSION_CREATE_CONN_FAILED + ".pICR",
782 null /*lock*/) {
783 @Override
784 public void loggedRun() {
Tyler Gunn159f35c2017-03-02 09:28:37 -0800785 createConnectionFailed(connectionMgrPhoneAccount, id,
786 request, isIncoming);
Tyler Gunn44e01912017-01-31 10:49:05 -0800787 }
788 }.prepare());
789 } else {
790 Log.i(this, "createConnectionFailed %s", id);
Tyler Gunn159f35c2017-03-02 09:28:37 -0800791 createConnectionFailed(connectionMgrPhoneAccount, id, request,
792 isIncoming);
Tyler Gunn44e01912017-01-31 10:49:05 -0800793 }
794 } finally {
795 args.recycle();
796 Log.endSession();
797 }
798 break;
799 }
Sanket Padawe4cc8ed532017-12-04 16:22:20 -0800800 case MSG_HANDOVER_FAILED: {
801 SomeArgs args = (SomeArgs) msg.obj;
802 Log.continueSession((Session) args.arg3, SESSION_HANDLER +
803 SESSION_HANDOVER_FAILED);
804 try {
805 final String id = (String) args.arg1;
806 final ConnectionRequest request = (ConnectionRequest) args.arg2;
807 final int reason = (int) args.arg4;
808 if (!mAreAccountsInitialized) {
809 Log.d(this, "Enqueueing pre-init request %s", id);
810 mPreInitializationConnectionRequests.add(
811 new android.telecom.Logging.Runnable(
812 SESSION_HANDLER
813 + SESSION_HANDOVER_FAILED + ".pICR",
814 null /*lock*/) {
815 @Override
816 public void loggedRun() {
817 handoverFailed(id, request, reason);
818 }
819 }.prepare());
820 } else {
821 Log.i(this, "createConnectionFailed %s", id);
822 handoverFailed(id, request, reason);
823 }
824 } finally {
825 args.recycle();
826 Log.endSession();
827 }
828 break;
829 }
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700830 case MSG_ABORT: {
831 SomeArgs args = (SomeArgs) msg.obj;
832 Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_ABORT);
833 try {
834 abort((String) args.arg1);
835 } finally {
836 args.recycle();
837 Log.endSession();
838 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700839 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700840 }
841 case MSG_ANSWER: {
842 SomeArgs args = (SomeArgs) msg.obj;
843 Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_ANSWER);
844 try {
845 answer((String) args.arg1);
846 } finally {
847 args.recycle();
848 Log.endSession();
849 }
Tyler Gunnbe74de02014-08-29 14:51:48 -0700850 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700851 }
Tyler Gunnbe74de02014-08-29 14:51:48 -0700852 case MSG_ANSWER_VIDEO: {
Andrew Lee8da4c3c2014-07-16 10:11:42 -0700853 SomeArgs args = (SomeArgs) msg.obj;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700854 Log.continueSession((Session) args.arg2,
855 SESSION_HANDLER + SESSION_ANSWER_VIDEO);
Andrew Lee8da4c3c2014-07-16 10:11:42 -0700856 try {
857 String callId = (String) args.arg1;
Evan Charltonbf11f982014-07-20 22:06:28 -0700858 int videoState = args.argi1;
Tyler Gunnbe74de02014-08-29 14:51:48 -0700859 answerVideo(callId, videoState);
Andrew Lee8da4c3c2014-07-16 10:11:42 -0700860 } finally {
861 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700862 Log.endSession();
Andrew Lee8da4c3c2014-07-16 10:11:42 -0700863 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700864 break;
Andrew Lee8da4c3c2014-07-16 10:11:42 -0700865 }
Pooja Jaind34698d2017-12-28 14:15:31 +0530866 case MSG_DEFLECT: {
867 SomeArgs args = (SomeArgs) msg.obj;
868 Log.continueSession((Session) args.arg3, SESSION_HANDLER + SESSION_DEFLECT);
869 try {
870 deflect((String) args.arg1, (Uri) args.arg2);
871 } finally {
872 args.recycle();
873 Log.endSession();
874 }
875 break;
876 }
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700877 case MSG_REJECT: {
878 SomeArgs args = (SomeArgs) msg.obj;
879 Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_REJECT);
880 try {
881 reject((String) args.arg1);
882 } finally {
883 args.recycle();
884 Log.endSession();
885 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700886 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700887 }
Bryce Lee81901682015-08-28 16:38:02 -0700888 case MSG_REJECT_WITH_MESSAGE: {
889 SomeArgs args = (SomeArgs) msg.obj;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700890 Log.continueSession((Session) args.arg3,
891 SESSION_HANDLER + SESSION_REJECT_MESSAGE);
Bryce Lee81901682015-08-28 16:38:02 -0700892 try {
893 reject((String) args.arg1, (String) args.arg2);
894 } finally {
895 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700896 Log.endSession();
Bryce Lee81901682015-08-28 16:38:02 -0700897 }
898 break;
899 }
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700900 case MSG_DISCONNECT: {
901 SomeArgs args = (SomeArgs) msg.obj;
902 Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_DISCONNECT);
903 try {
904 disconnect((String) args.arg1);
905 } finally {
906 args.recycle();
907 Log.endSession();
908 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700909 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700910 }
911 case MSG_SILENCE: {
912 SomeArgs args = (SomeArgs) msg.obj;
913 Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_SILENCE);
914 try {
915 silence((String) args.arg1);
916 } finally {
917 args.recycle();
918 Log.endSession();
919 }
Bryce Leecac50772015-11-17 15:13:29 -0800920 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700921 }
922 case MSG_HOLD: {
923 SomeArgs args = (SomeArgs) msg.obj;
924 Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_REJECT);
925 try {
926 hold((String) args.arg1);
927 } finally {
928 args.recycle();
929 Log.endSession();
930 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700931 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700932 }
933 case MSG_UNHOLD: {
934 SomeArgs args = (SomeArgs) msg.obj;
935 Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_UNHOLD);
936 try {
937 unhold((String) args.arg1);
938 } finally {
939 args.recycle();
940 Log.endSession();
941 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700942 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700943 }
Yorke Lee4af59352015-05-13 14:14:54 -0700944 case MSG_ON_CALL_AUDIO_STATE_CHANGED: {
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700945 SomeArgs args = (SomeArgs) msg.obj;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700946 Log.continueSession((Session) args.arg3,
947 SESSION_HANDLER + SESSION_CALL_AUDIO_SC);
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700948 try {
949 String callId = (String) args.arg1;
Yorke Lee4af59352015-05-13 14:14:54 -0700950 CallAudioState audioState = (CallAudioState) args.arg2;
951 onCallAudioStateChanged(callId, new CallAudioState(audioState));
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700952 } finally {
953 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700954 Log.endSession();
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700955 }
956 break;
957 }
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700958 case MSG_PLAY_DTMF_TONE: {
959 SomeArgs args = (SomeArgs) msg.obj;
960 try {
961 Log.continueSession((Session) args.arg3,
962 SESSION_HANDLER + SESSION_PLAY_DTMF);
963 playDtmfTone((String) args.arg2, (char) args.arg1);
964 } finally {
965 args.recycle();
966 Log.endSession();
967 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700968 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700969 }
970 case MSG_STOP_DTMF_TONE: {
971 SomeArgs args = (SomeArgs) msg.obj;
972 try {
973 Log.continueSession((Session) args.arg2,
974 SESSION_HANDLER + SESSION_STOP_DTMF);
975 stopDtmfTone((String) args.arg1);
976 } finally {
977 args.recycle();
978 Log.endSession();
979 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700980 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700981 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700982 case MSG_CONFERENCE: {
983 SomeArgs args = (SomeArgs) msg.obj;
984 try {
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700985 Log.continueSession((Session) args.arg3,
986 SESSION_HANDLER + SESSION_CONFERENCE);
Santos Cordon823fd3c2014-08-07 18:35:18 -0700987 String callId1 = (String) args.arg1;
988 String callId2 = (String) args.arg2;
989 conference(callId1, callId2);
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700990 } finally {
991 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700992 Log.endSession();
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700993 }
994 break;
995 }
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700996 case MSG_SPLIT_FROM_CONFERENCE: {
997 SomeArgs args = (SomeArgs) msg.obj;
998 try {
999 Log.continueSession((Session) args.arg2,
1000 SESSION_HANDLER + SESSION_SPLIT_CONFERENCE);
1001 splitFromConference((String) args.arg1);
1002 } finally {
1003 args.recycle();
1004 Log.endSession();
1005 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001006 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001007 }
1008 case MSG_MERGE_CONFERENCE: {
1009 SomeArgs args = (SomeArgs) msg.obj;
1010 try {
1011 Log.continueSession((Session) args.arg2,
1012 SESSION_HANDLER + SESSION_MERGE_CONFERENCE);
1013 mergeConference((String) args.arg1);
1014 } finally {
1015 args.recycle();
1016 Log.endSession();
1017 }
Santos Cordona4868042014-09-04 17:39:22 -07001018 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001019 }
1020 case MSG_SWAP_CONFERENCE: {
1021 SomeArgs args = (SomeArgs) msg.obj;
1022 try {
1023 Log.continueSession((Session) args.arg2,
1024 SESSION_HANDLER + SESSION_SWAP_CONFERENCE);
1025 swapConference((String) args.arg1);
1026 } finally {
1027 args.recycle();
1028 Log.endSession();
1029 }
Santos Cordona4868042014-09-04 17:39:22 -07001030 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001031 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001032 case MSG_ON_POST_DIAL_CONTINUE: {
1033 SomeArgs args = (SomeArgs) msg.obj;
1034 try {
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001035 Log.continueSession((Session) args.arg2,
1036 SESSION_HANDLER + SESSION_POST_DIAL_CONT);
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001037 String callId = (String) args.arg1;
1038 boolean proceed = (args.argi1 == 1);
1039 onPostDialContinue(callId, proceed);
1040 } finally {
1041 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001042 Log.endSession();
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001043 }
1044 break;
1045 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001046 case MSG_PULL_EXTERNAL_CALL: {
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001047 SomeArgs args = (SomeArgs) msg.obj;
1048 try {
1049 Log.continueSession((Session) args.arg2,
1050 SESSION_HANDLER + SESSION_PULL_EXTERNAL_CALL);
1051 pullExternalCall((String) args.arg1);
1052 } finally {
1053 args.recycle();
1054 Log.endSession();
1055 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001056 break;
1057 }
1058 case MSG_SEND_CALL_EVENT: {
1059 SomeArgs args = (SomeArgs) msg.obj;
1060 try {
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001061 Log.continueSession((Session) args.arg4,
1062 SESSION_HANDLER + SESSION_SEND_CALL_EVENT);
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001063 String callId = (String) args.arg1;
1064 String event = (String) args.arg2;
1065 Bundle extras = (Bundle) args.arg3;
1066 sendCallEvent(callId, event, extras);
1067 } finally {
1068 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001069 Log.endSession();
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001070 }
1071 break;
1072 }
Tyler Gunn79bc1ec2018-01-22 15:17:54 -08001073 case MSG_HANDOVER_COMPLETE: {
1074 SomeArgs args = (SomeArgs) msg.obj;
1075 try {
1076 Log.continueSession((Session) args.arg2,
1077 SESSION_HANDLER + SESSION_HANDOVER_COMPLETE);
1078 String callId = (String) args.arg1;
1079 notifyHandoverComplete(callId);
1080 } finally {
1081 args.recycle();
1082 Log.endSession();
1083 }
1084 break;
1085 }
Tyler Gunndee56a82016-03-23 16:06:34 -07001086 case MSG_ON_EXTRAS_CHANGED: {
1087 SomeArgs args = (SomeArgs) msg.obj;
1088 try {
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001089 Log.continueSession((Session) args.arg3,
1090 SESSION_HANDLER + SESSION_EXTRAS_CHANGED);
Tyler Gunndee56a82016-03-23 16:06:34 -07001091 String callId = (String) args.arg1;
1092 Bundle extras = (Bundle) args.arg2;
1093 handleExtrasChanged(callId, extras);
1094 } finally {
1095 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001096 Log.endSession();
Tyler Gunndee56a82016-03-23 16:06:34 -07001097 }
1098 break;
1099 }
Hall Liub64ac4c2017-02-06 10:49:48 -08001100 case MSG_ON_START_RTT: {
1101 SomeArgs args = (SomeArgs) msg.obj;
1102 try {
1103 Log.continueSession((Session) args.arg3,
1104 SESSION_HANDLER + SESSION_START_RTT);
1105 String callId = (String) args.arg1;
1106 Connection.RttTextStream rttTextStream =
1107 (Connection.RttTextStream) args.arg2;
1108 startRtt(callId, rttTextStream);
1109 } finally {
1110 args.recycle();
1111 Log.endSession();
1112 }
1113 break;
1114 }
1115 case MSG_ON_STOP_RTT: {
1116 SomeArgs args = (SomeArgs) msg.obj;
1117 try {
1118 Log.continueSession((Session) args.arg2,
1119 SESSION_HANDLER + SESSION_STOP_RTT);
1120 String callId = (String) args.arg1;
1121 stopRtt(callId);
1122 } finally {
1123 args.recycle();
1124 Log.endSession();
1125 }
1126 break;
1127 }
1128 case MSG_RTT_UPGRADE_RESPONSE: {
1129 SomeArgs args = (SomeArgs) msg.obj;
1130 try {
1131 Log.continueSession((Session) args.arg3,
1132 SESSION_HANDLER + SESSION_RTT_UPGRADE_RESPONSE);
1133 String callId = (String) args.arg1;
1134 Connection.RttTextStream rttTextStream =
1135 (Connection.RttTextStream) args.arg2;
1136 handleRttUpgradeResponse(callId, rttTextStream);
1137 } finally {
1138 args.recycle();
1139 Log.endSession();
1140 }
1141 break;
1142 }
Pengquan Meng731c1a32017-11-21 18:01:13 -08001143 case MSG_CONNECTION_SERVICE_FOCUS_GAINED:
1144 onConnectionServiceFocusGained();
1145 break;
1146 case MSG_CONNECTION_SERVICE_FOCUS_LOST:
1147 onConnectionServiceFocusLost();
1148 break;
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001149 default:
1150 break;
1151 }
1152 }
1153 };
1154
Santos Cordon823fd3c2014-08-07 18:35:18 -07001155 private final Conference.Listener mConferenceListener = new Conference.Listener() {
1156 @Override
1157 public void onStateChanged(Conference conference, int oldState, int newState) {
1158 String id = mIdByConference.get(conference);
1159 switch (newState) {
1160 case Connection.STATE_ACTIVE:
1161 mAdapter.setActive(id);
1162 break;
1163 case Connection.STATE_HOLDING:
1164 mAdapter.setOnHold(id);
1165 break;
1166 case Connection.STATE_DISCONNECTED:
1167 // handled by onDisconnected
1168 break;
1169 }
1170 }
1171
1172 @Override
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001173 public void onDisconnected(Conference conference, DisconnectCause disconnectCause) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07001174 String id = mIdByConference.get(conference);
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001175 mAdapter.setDisconnected(id, disconnectCause);
Santos Cordon823fd3c2014-08-07 18:35:18 -07001176 }
1177
1178 @Override
1179 public void onConnectionAdded(Conference conference, Connection connection) {
1180 }
1181
1182 @Override
1183 public void onConnectionRemoved(Conference conference, Connection connection) {
1184 }
1185
1186 @Override
Ihab Awad50e35062014-09-30 09:17:03 -07001187 public void onConferenceableConnectionsChanged(
1188 Conference conference, List<Connection> conferenceableConnections) {
1189 mAdapter.setConferenceableConnections(
1190 mIdByConference.get(conference),
1191 createConnectionIdList(conferenceableConnections));
1192 }
1193
1194 @Override
Santos Cordon823fd3c2014-08-07 18:35:18 -07001195 public void onDestroyed(Conference conference) {
1196 removeConference(conference);
1197 }
1198
1199 @Override
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001200 public void onConnectionCapabilitiesChanged(
1201 Conference conference,
1202 int connectionCapabilities) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07001203 String id = mIdByConference.get(conference);
1204 Log.d(this, "call capabilities: conference: %s",
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001205 Connection.capabilitiesToString(connectionCapabilities));
1206 mAdapter.setConnectionCapabilities(id, connectionCapabilities);
Santos Cordon823fd3c2014-08-07 18:35:18 -07001207 }
Rekha Kumar07366812015-03-24 16:42:31 -07001208
1209 @Override
Tyler Gunn720c6642016-03-22 09:02:47 -07001210 public void onConnectionPropertiesChanged(
1211 Conference conference,
1212 int connectionProperties) {
1213 String id = mIdByConference.get(conference);
1214 Log.d(this, "call capabilities: conference: %s",
1215 Connection.propertiesToString(connectionProperties));
1216 mAdapter.setConnectionProperties(id, connectionProperties);
1217 }
1218
1219 @Override
Rekha Kumar07366812015-03-24 16:42:31 -07001220 public void onVideoStateChanged(Conference c, int videoState) {
1221 String id = mIdByConference.get(c);
1222 Log.d(this, "onVideoStateChanged set video state %d", videoState);
1223 mAdapter.setVideoState(id, videoState);
1224 }
1225
1226 @Override
1227 public void onVideoProviderChanged(Conference c, Connection.VideoProvider videoProvider) {
1228 String id = mIdByConference.get(c);
1229 Log.d(this, "onVideoProviderChanged: Connection: %s, VideoProvider: %s", c,
1230 videoProvider);
1231 mAdapter.setVideoProvider(id, videoProvider);
1232 }
Andrew Lee0f51da32015-04-16 13:11:55 -07001233
1234 @Override
Andrew Leeedc625f2015-04-14 13:38:12 -07001235 public void onStatusHintsChanged(Conference conference, StatusHints statusHints) {
1236 String id = mIdByConference.get(conference);
Tyler Gunndee56a82016-03-23 16:06:34 -07001237 if (id != null) {
1238 mAdapter.setStatusHints(id, statusHints);
1239 }
Andrew Leeedc625f2015-04-14 13:38:12 -07001240 }
Santos Cordon6b7f9552015-05-27 17:21:45 -07001241
1242 @Override
Tyler Gunndee56a82016-03-23 16:06:34 -07001243 public void onExtrasChanged(Conference c, Bundle extras) {
1244 String id = mIdByConference.get(c);
1245 if (id != null) {
1246 mAdapter.putExtras(id, extras);
1247 }
1248 }
1249
1250 @Override
1251 public void onExtrasRemoved(Conference c, List<String> keys) {
1252 String id = mIdByConference.get(c);
1253 if (id != null) {
1254 mAdapter.removeExtras(id, keys);
1255 }
Santos Cordon6b7f9552015-05-27 17:21:45 -07001256 }
Tyler Gunn68a73a42018-10-03 15:38:57 -07001257
1258 @Override
1259 public void onConferenceStateChanged(Conference c, boolean isConference) {
1260 String id = mIdByConference.get(c);
1261 if (id != null) {
1262 mAdapter.setConferenceState(id, isConference);
1263 }
1264 }
1265
1266 @Override
1267 public void onAddressChanged(Conference c, Uri newAddress, int presentation) {
1268 String id = mIdByConference.get(c);
1269 if (id != null) {
1270 mAdapter.setAddress(id, newAddress, presentation);
1271 }
1272 }
1273
1274 @Override
1275 public void onCallerDisplayNameChanged(Conference c, String callerDisplayName,
1276 int presentation) {
1277 String id = mIdByConference.get(c);
1278 if (id != null) {
1279 mAdapter.setCallerDisplayName(id, callerDisplayName, presentation);
1280 }
1281 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07001282 };
1283
Ihab Awad542e0ea2014-05-16 10:22:16 -07001284 private final Connection.Listener mConnectionListener = new Connection.Listener() {
1285 @Override
1286 public void onStateChanged(Connection c, int state) {
1287 String id = mIdByConnection.get(c);
Ihab Awad42b30e12014-05-22 09:49:34 -07001288 Log.d(this, "Adapter set state %s %s", id, Connection.stateToString(state));
Ihab Awad542e0ea2014-05-16 10:22:16 -07001289 switch (state) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001290 case Connection.STATE_ACTIVE:
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001291 mAdapter.setActive(id);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001292 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001293 case Connection.STATE_DIALING:
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001294 mAdapter.setDialing(id);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001295 break;
Tyler Gunnc96b5e02016-07-07 22:53:57 -07001296 case Connection.STATE_PULLING_CALL:
1297 mAdapter.setPulling(id);
1298 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001299 case Connection.STATE_DISCONNECTED:
Ihab Awad542e0ea2014-05-16 10:22:16 -07001300 // Handled in onDisconnected()
1301 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001302 case Connection.STATE_HOLDING:
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001303 mAdapter.setOnHold(id);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001304 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001305 case Connection.STATE_NEW:
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001306 // Nothing to tell Telecom
Ihab Awad542e0ea2014-05-16 10:22:16 -07001307 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001308 case Connection.STATE_RINGING:
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001309 mAdapter.setRinging(id);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001310 break;
1311 }
1312 }
1313
1314 @Override
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001315 public void onDisconnected(Connection c, DisconnectCause disconnectCause) {
Ihab Awad542e0ea2014-05-16 10:22:16 -07001316 String id = mIdByConnection.get(c);
Andrew Lee26786392014-09-16 18:14:59 -07001317 Log.d(this, "Adapter set disconnected %s", disconnectCause);
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001318 mAdapter.setDisconnected(id, disconnectCause);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001319 }
1320
1321 @Override
Tyler Gunnaa07df82014-07-17 07:50:22 -07001322 public void onVideoStateChanged(Connection c, int videoState) {
1323 String id = mIdByConnection.get(c);
1324 Log.d(this, "Adapter set video state %d", videoState);
1325 mAdapter.setVideoState(id, videoState);
1326 }
1327
1328 @Override
Andrew Lee100e2932014-09-08 15:34:24 -07001329 public void onAddressChanged(Connection c, Uri address, int presentation) {
Sailesh Nepal61203862014-07-11 14:50:13 -07001330 String id = mIdByConnection.get(c);
Andrew Lee100e2932014-09-08 15:34:24 -07001331 mAdapter.setAddress(id, address, presentation);
Sailesh Nepal61203862014-07-11 14:50:13 -07001332 }
1333
1334 @Override
1335 public void onCallerDisplayNameChanged(
1336 Connection c, String callerDisplayName, int presentation) {
1337 String id = mIdByConnection.get(c);
1338 mAdapter.setCallerDisplayName(id, callerDisplayName, presentation);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001339 }
1340
1341 @Override
Ihab Awad542e0ea2014-05-16 10:22:16 -07001342 public void onDestroyed(Connection c) {
1343 removeConnection(c);
1344 }
Ihab Awadf8358972014-05-28 16:46:42 -07001345
1346 @Override
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001347 public void onPostDialWait(Connection c, String remaining) {
Sailesh Nepal091768c2014-06-30 15:15:23 -07001348 String id = mIdByConnection.get(c);
1349 Log.d(this, "Adapter onPostDialWait %s, %s", c, remaining);
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001350 mAdapter.onPostDialWait(id, remaining);
Sailesh Nepal091768c2014-06-30 15:15:23 -07001351 }
1352
1353 @Override
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001354 public void onPostDialChar(Connection c, char nextChar) {
1355 String id = mIdByConnection.get(c);
1356 Log.d(this, "Adapter onPostDialChar %s, %s", c, nextChar);
1357 mAdapter.onPostDialChar(id, nextChar);
1358 }
1359
1360 @Override
Andrew Lee100e2932014-09-08 15:34:24 -07001361 public void onRingbackRequested(Connection c, boolean ringback) {
Ihab Awadf8358972014-05-28 16:46:42 -07001362 String id = mIdByConnection.get(c);
1363 Log.d(this, "Adapter onRingback %b", ringback);
Andrew Lee100e2932014-09-08 15:34:24 -07001364 mAdapter.setRingbackRequested(id, ringback);
Ihab Awadf8358972014-05-28 16:46:42 -07001365 }
Santos Cordonb6939982014-06-04 20:20:58 -07001366
1367 @Override
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001368 public void onConnectionCapabilitiesChanged(Connection c, int capabilities) {
Santos Cordonb6939982014-06-04 20:20:58 -07001369 String id = mIdByConnection.get(c);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001370 Log.d(this, "capabilities: parcelableconnection: %s",
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001371 Connection.capabilitiesToString(capabilities));
1372 mAdapter.setConnectionCapabilities(id, capabilities);
Santos Cordonb6939982014-06-04 20:20:58 -07001373 }
1374
Santos Cordonb6939982014-06-04 20:20:58 -07001375 @Override
Tyler Gunn720c6642016-03-22 09:02:47 -07001376 public void onConnectionPropertiesChanged(Connection c, int properties) {
1377 String id = mIdByConnection.get(c);
1378 Log.d(this, "properties: parcelableconnection: %s",
1379 Connection.propertiesToString(properties));
1380 mAdapter.setConnectionProperties(id, properties);
1381 }
1382
1383 @Override
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001384 public void onVideoProviderChanged(Connection c, Connection.VideoProvider videoProvider) {
Andrew Lee5ffbe8b2014-06-20 16:29:33 -07001385 String id = mIdByConnection.get(c);
Rekha Kumar07366812015-03-24 16:42:31 -07001386 Log.d(this, "onVideoProviderChanged: Connection: %s, VideoProvider: %s", c,
1387 videoProvider);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001388 mAdapter.setVideoProvider(id, videoProvider);
Andrew Lee5ffbe8b2014-06-20 16:29:33 -07001389 }
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001390
1391 @Override
Sailesh Nepal001bbbb2014-07-15 14:40:39 -07001392 public void onAudioModeIsVoipChanged(Connection c, boolean isVoip) {
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001393 String id = mIdByConnection.get(c);
Andrew Lee100e2932014-09-08 15:34:24 -07001394 mAdapter.setIsVoipAudioMode(id, isVoip);
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001395 }
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001396
1397 @Override
Sailesh Nepal001bbbb2014-07-15 14:40:39 -07001398 public void onStatusHintsChanged(Connection c, StatusHints statusHints) {
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001399 String id = mIdByConnection.get(c);
1400 mAdapter.setStatusHints(id, statusHints);
1401 }
Sailesh Nepal2ab88cc2014-07-18 14:49:18 -07001402
1403 @Override
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001404 public void onConferenceablesChanged(
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001405 Connection connection, List<Conferenceable> conferenceables) {
Ihab Awadb8e85c72014-08-23 20:34:57 -07001406 mAdapter.setConferenceableConnections(
1407 mIdByConnection.get(connection),
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001408 createIdList(conferenceables));
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001409 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07001410
1411 @Override
1412 public void onConferenceChanged(Connection connection, Conference conference) {
1413 String id = mIdByConnection.get(connection);
1414 if (id != null) {
1415 String conferenceId = null;
1416 if (conference != null) {
1417 conferenceId = mIdByConference.get(conference);
1418 }
1419 mAdapter.setIsConferenced(id, conferenceId);
1420 }
1421 }
Anthony Lee17455a32015-04-24 15:25:29 -07001422
1423 @Override
1424 public void onConferenceMergeFailed(Connection connection) {
1425 String id = mIdByConnection.get(connection);
1426 if (id != null) {
1427 mAdapter.onConferenceMergeFailed(id);
1428 }
1429 }
Santos Cordon6b7f9552015-05-27 17:21:45 -07001430
1431 @Override
Tyler Gunndee56a82016-03-23 16:06:34 -07001432 public void onExtrasChanged(Connection c, Bundle extras) {
1433 String id = mIdByConnection.get(c);
Santos Cordon6b7f9552015-05-27 17:21:45 -07001434 if (id != null) {
Tyler Gunndee56a82016-03-23 16:06:34 -07001435 mAdapter.putExtras(id, extras);
Santos Cordon6b7f9552015-05-27 17:21:45 -07001436 }
1437 }
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001438
Tyler Gunnf5035432017-01-09 09:43:12 -08001439 @Override
Tyler Gunndee56a82016-03-23 16:06:34 -07001440 public void onExtrasRemoved(Connection c, List<String> keys) {
1441 String id = mIdByConnection.get(c);
1442 if (id != null) {
1443 mAdapter.removeExtras(id, keys);
1444 }
1445 }
1446
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08001447 @Override
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001448 public void onConnectionEvent(Connection connection, String event, Bundle extras) {
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08001449 String id = mIdByConnection.get(connection);
1450 if (id != null) {
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001451 mAdapter.onConnectionEvent(id, event, extras);
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08001452 }
1453 }
Tyler Gunnf5035432017-01-09 09:43:12 -08001454
1455 @Override
Hall Liua98f58b2017-11-07 17:59:28 -08001456 public void onAudioRouteChanged(Connection c, int audioRoute, String bluetoothAddress) {
Tyler Gunnf5035432017-01-09 09:43:12 -08001457 String id = mIdByConnection.get(c);
1458 if (id != null) {
Hall Liua98f58b2017-11-07 17:59:28 -08001459 mAdapter.setAudioRoute(id, audioRoute, bluetoothAddress);
Tyler Gunnf5035432017-01-09 09:43:12 -08001460 }
1461 }
Hall Liub64ac4c2017-02-06 10:49:48 -08001462
1463 @Override
1464 public void onRttInitiationSuccess(Connection c) {
1465 String id = mIdByConnection.get(c);
1466 if (id != null) {
1467 mAdapter.onRttInitiationSuccess(id);
1468 }
1469 }
1470
1471 @Override
1472 public void onRttInitiationFailure(Connection c, int reason) {
1473 String id = mIdByConnection.get(c);
1474 if (id != null) {
1475 mAdapter.onRttInitiationFailure(id, reason);
1476 }
1477 }
1478
1479 @Override
1480 public void onRttSessionRemotelyTerminated(Connection c) {
1481 String id = mIdByConnection.get(c);
1482 if (id != null) {
1483 mAdapter.onRttSessionRemotelyTerminated(id);
1484 }
1485 }
1486
1487 @Override
1488 public void onRemoteRttRequest(Connection c) {
1489 String id = mIdByConnection.get(c);
1490 if (id != null) {
1491 mAdapter.onRemoteRttRequest(id);
1492 }
1493 }
Srikanth Chintalafcb15012017-05-04 20:58:34 +05301494
1495 @Override
1496 public void onPhoneAccountChanged(Connection c, PhoneAccountHandle pHandle) {
1497 String id = mIdByConnection.get(c);
1498 if (id != null) {
1499 mAdapter.onPhoneAccountChanged(id, pHandle);
1500 }
1501 }
Mengjun Leng25707742017-07-04 11:10:37 +08001502
1503 public void onConnectionTimeReset(Connection c) {
1504 String id = mIdByConnection.get(c);
1505 if (id != null) {
1506 mAdapter.resetConnectionTime(id);
1507 }
1508 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001509 };
1510
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001511 /** {@inheritDoc} */
Ihab Awad542e0ea2014-05-16 10:22:16 -07001512 @Override
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001513 public final IBinder onBind(Intent intent) {
1514 return mBinder;
1515 }
1516
Santos Cordon29f2f2e2014-09-11 19:50:24 -07001517 /** {@inheritDoc} */
1518 @Override
1519 public boolean onUnbind(Intent intent) {
1520 endAllConnections();
1521 return super.onUnbind(intent);
1522 }
1523
Sailesh Nepalc5b01572014-07-14 16:29:44 -07001524 /**
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001525 * This can be used by telecom to either create a new outgoing call or attach to an existing
1526 * incoming call. In either case, telecom will cycle through a set of services and call
Sailesh Nepalc5b01572014-07-14 16:29:44 -07001527 * createConnection util a connection service cancels the process or completes it successfully.
1528 */
Ihab Awadf8b69882014-07-25 15:14:01 -07001529 private void createConnection(
1530 final PhoneAccountHandle callManagerAccount,
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001531 final String callId,
Ihab Awadf8b69882014-07-25 15:14:01 -07001532 final ConnectionRequest request,
Yorke Leec3cf9822014-10-02 09:38:39 -07001533 boolean isIncoming,
1534 boolean isUnknown) {
Tyler Gunn79bc1ec2018-01-22 15:17:54 -08001535 boolean isLegacyHandover = request.getExtras() != null &&
1536 request.getExtras().getBoolean(TelecomManager.EXTRA_IS_HANDOVER, false);
1537 boolean isHandover = request.getExtras() != null && request.getExtras().getBoolean(
1538 TelecomManager.EXTRA_IS_HANDOVER_CONNECTION, false);
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001539 Log.d(this, "createConnection, callManagerAccount: %s, callId: %s, request: %s, " +
Tyler Gunn79bc1ec2018-01-22 15:17:54 -08001540 "isIncoming: %b, isUnknown: %b, isLegacyHandover: %b, isHandover: %b",
1541 callManagerAccount, callId, request, isIncoming, isUnknown, isLegacyHandover,
1542 isHandover);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001543
Sanket Padawee29a2662017-12-01 13:59:27 -08001544 Connection connection = null;
Tyler Gunn79bc1ec2018-01-22 15:17:54 -08001545 if (isHandover) {
1546 PhoneAccountHandle fromPhoneAccountHandle = request.getExtras() != null
1547 ? (PhoneAccountHandle) request.getExtras().getParcelable(
1548 TelecomManager.EXTRA_HANDOVER_FROM_PHONE_ACCOUNT) : null;
Sanket Padawee29a2662017-12-01 13:59:27 -08001549 if (!isIncoming) {
Tyler Gunn79bc1ec2018-01-22 15:17:54 -08001550 connection = onCreateOutgoingHandoverConnection(fromPhoneAccountHandle, request);
Sanket Padawee29a2662017-12-01 13:59:27 -08001551 } else {
Tyler Gunn79bc1ec2018-01-22 15:17:54 -08001552 connection = onCreateIncomingHandoverConnection(fromPhoneAccountHandle, request);
Sanket Padawee29a2662017-12-01 13:59:27 -08001553 }
1554 } else {
1555 connection = isUnknown ? onCreateUnknownConnection(callManagerAccount, request)
1556 : isIncoming ? onCreateIncomingConnection(callManagerAccount, request)
1557 : onCreateOutgoingConnection(callManagerAccount, request);
1558 }
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001559 Log.d(this, "createConnection, connection: %s", connection);
1560 if (connection == null) {
Tyler Gunnfba1a8e2017-12-19 15:23:59 -08001561 Log.i(this, "createConnection, implementation returned null connection.");
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001562 connection = Connection.createFailedConnection(
Tyler Gunnfba1a8e2017-12-19 15:23:59 -08001563 new DisconnectCause(DisconnectCause.ERROR, "IMPL_RETURNED_NULL_CONNECTION"));
Sailesh Nepalc5b01572014-07-14 16:29:44 -07001564 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001565
Tyler Gunnf2e08b42018-05-24 10:44:44 -07001566 boolean isSelfManaged =
1567 (connection.getConnectionProperties() & Connection.PROPERTY_SELF_MANAGED)
1568 == Connection.PROPERTY_SELF_MANAGED;
1569 // Self-managed Connections should always use voip audio mode; we default here so that the
1570 // local state within the ConnectionService matches the default we assume in Telecom.
1571 if (isSelfManaged) {
1572 connection.setAudioModeIsVoip(true);
1573 }
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001574 connection.setTelecomCallId(callId);
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001575 if (connection.getState() != Connection.STATE_DISCONNECTED) {
Pengquan Meng70c9885332017-10-02 18:09:03 -07001576 addConnection(request.getAccountHandle(), callId, connection);
Ihab Awad6107bab2014-08-18 09:23:25 -07001577 }
1578
Andrew Lee100e2932014-09-08 15:34:24 -07001579 Uri address = connection.getAddress();
1580 String number = address == null ? "null" : address.getSchemeSpecificPart();
Tyler Gunn720c6642016-03-22 09:02:47 -07001581 Log.v(this, "createConnection, number: %s, state: %s, capabilities: %s, properties: %s",
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001582 Connection.toLogSafePhoneNumber(number),
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001583 Connection.stateToString(connection.getState()),
Tyler Gunn720c6642016-03-22 09:02:47 -07001584 Connection.capabilitiesToString(connection.getConnectionCapabilities()),
1585 Connection.propertiesToString(connection.getConnectionProperties()));
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001586
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001587 Log.d(this, "createConnection, calling handleCreateConnectionSuccessful %s", callId);
Ihab Awad6107bab2014-08-18 09:23:25 -07001588 mAdapter.handleCreateConnectionComplete(
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001589 callId,
Evan Charltonbf11f982014-07-20 22:06:28 -07001590 request,
1591 new ParcelableConnection(
1592 request.getAccountHandle(),
1593 connection.getState(),
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001594 connection.getConnectionCapabilities(),
Tyler Gunn720c6642016-03-22 09:02:47 -07001595 connection.getConnectionProperties(),
Christine Hallstrom2830ce92016-11-30 16:06:42 -08001596 connection.getSupportedAudioRoutes(),
Andrew Lee100e2932014-09-08 15:34:24 -07001597 connection.getAddress(),
1598 connection.getAddressPresentation(),
Evan Charltonbf11f982014-07-20 22:06:28 -07001599 connection.getCallerDisplayName(),
1600 connection.getCallerDisplayNamePresentation(),
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001601 connection.getVideoProvider() == null ?
1602 null : connection.getVideoProvider().getInterface(),
Sailesh Nepal8b9d3ca2014-08-14 17:39:34 -07001603 connection.getVideoState(),
Andrew Lee100e2932014-09-08 15:34:24 -07001604 connection.isRingbackRequested(),
Sailesh Nepal8b9d3ca2014-08-14 17:39:34 -07001605 connection.getAudioModeIsVoip(),
Roshan Piuse927ec02015-07-15 15:47:21 -07001606 connection.getConnectTimeMillis(),
Tyler Gunn3fa819c2017-08-04 09:27:26 -07001607 connection.getConnectElapsedTimeMillis(),
Ihab Awad6107bab2014-08-18 09:23:25 -07001608 connection.getStatusHints(),
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001609 connection.getDisconnectCause(),
Santos Cordon6b7f9552015-05-27 17:21:45 -07001610 createIdList(connection.getConferenceables()),
1611 connection.getExtras()));
Tyler Gunnf5035432017-01-09 09:43:12 -08001612
Tyler Gunnf2e08b42018-05-24 10:44:44 -07001613 if (isIncoming && request.shouldShowIncomingCallUi() && isSelfManaged) {
Tyler Gunnf5035432017-01-09 09:43:12 -08001614 // Tell ConnectionService to show its incoming call UX.
1615 connection.onShowIncomingCallUi();
1616 }
Shriram Ganesh6bf35ac2014-12-11 17:53:38 -08001617 if (isUnknown) {
1618 triggerConferenceRecalculate();
1619 }
Evan Charltonbf11f982014-07-20 22:06:28 -07001620 }
1621
Tyler Gunn159f35c2017-03-02 09:28:37 -08001622 private void createConnectionFailed(final PhoneAccountHandle callManagerAccount,
1623 final String callId, final ConnectionRequest request,
1624 boolean isIncoming) {
Tyler Gunn44e01912017-01-31 10:49:05 -08001625
1626 Log.i(this, "createConnectionFailed %s", callId);
1627 if (isIncoming) {
Tyler Gunn159f35c2017-03-02 09:28:37 -08001628 onCreateIncomingConnectionFailed(callManagerAccount, request);
Tyler Gunn44e01912017-01-31 10:49:05 -08001629 } else {
Tyler Gunn159f35c2017-03-02 09:28:37 -08001630 onCreateOutgoingConnectionFailed(callManagerAccount, request);
Tyler Gunn44e01912017-01-31 10:49:05 -08001631 }
1632 }
1633
Sanket Padawe4cc8ed532017-12-04 16:22:20 -08001634 private void handoverFailed(final String callId, final ConnectionRequest request,
1635 int reason) {
1636
1637 Log.i(this, "handoverFailed %s", callId);
1638 onHandoverFailed(request, reason);
1639 }
1640
Tyler Gunn041a1fe2017-05-12 10:04:49 -07001641 /**
1642 * Called by Telecom when the creation of a new Connection has completed and it is now added
1643 * to Telecom.
1644 * @param callId The ID of the connection.
1645 */
1646 private void notifyCreateConnectionComplete(final String callId) {
1647 Log.i(this, "notifyCreateConnectionComplete %s", callId);
Tyler Gunn0a88f2e2017-06-16 20:20:34 -07001648 if (callId == null) {
1649 // This could happen if the connection fails quickly and is removed from the
1650 // ConnectionService before Telecom sends the create connection complete callback.
1651 Log.w(this, "notifyCreateConnectionComplete: callId is null.");
1652 return;
1653 }
Tyler Gunn041a1fe2017-05-12 10:04:49 -07001654 onCreateConnectionComplete(findConnectionForAction(callId,
1655 "notifyCreateConnectionComplete"));
1656 }
1657
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001658 private void abort(String callId) {
Ihab Awad60ac30b2014-05-20 22:32:12 -07001659 Log.d(this, "abort %s", callId);
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001660 findConnectionForAction(callId, "abort").onAbort();
Ihab Awad542e0ea2014-05-16 10:22:16 -07001661 }
1662
Tyler Gunnbe74de02014-08-29 14:51:48 -07001663 private void answerVideo(String callId, int videoState) {
1664 Log.d(this, "answerVideo %s", callId);
Andrew Lee8da4c3c2014-07-16 10:11:42 -07001665 findConnectionForAction(callId, "answer").onAnswer(videoState);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001666 }
1667
Tyler Gunnbe74de02014-08-29 14:51:48 -07001668 private void answer(String callId) {
1669 Log.d(this, "answer %s", callId);
1670 findConnectionForAction(callId, "answer").onAnswer();
1671 }
1672
Pooja Jaind34698d2017-12-28 14:15:31 +05301673 private void deflect(String callId, Uri address) {
1674 Log.d(this, "deflect %s", callId);
1675 findConnectionForAction(callId, "deflect").onDeflect(address);
1676 }
1677
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001678 private void reject(String callId) {
Ihab Awad60ac30b2014-05-20 22:32:12 -07001679 Log.d(this, "reject %s", callId);
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001680 findConnectionForAction(callId, "reject").onReject();
Ihab Awad542e0ea2014-05-16 10:22:16 -07001681 }
1682
Bryce Lee81901682015-08-28 16:38:02 -07001683 private void reject(String callId, String rejectWithMessage) {
1684 Log.d(this, "reject %s with message", callId);
1685 findConnectionForAction(callId, "reject").onReject(rejectWithMessage);
1686 }
1687
Bryce Leecac50772015-11-17 15:13:29 -08001688 private void silence(String callId) {
1689 Log.d(this, "silence %s", callId);
1690 findConnectionForAction(callId, "silence").onSilence();
1691 }
1692
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001693 private void disconnect(String callId) {
Ihab Awad60ac30b2014-05-20 22:32:12 -07001694 Log.d(this, "disconnect %s", callId);
Santos Cordon0159ac02014-08-21 14:28:11 -07001695 if (mConnectionById.containsKey(callId)) {
1696 findConnectionForAction(callId, "disconnect").onDisconnect();
1697 } else {
1698 findConferenceForAction(callId, "disconnect").onDisconnect();
1699 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001700 }
1701
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001702 private void hold(String callId) {
Ihab Awad60ac30b2014-05-20 22:32:12 -07001703 Log.d(this, "hold %s", callId);
Santos Cordon0159ac02014-08-21 14:28:11 -07001704 if (mConnectionById.containsKey(callId)) {
1705 findConnectionForAction(callId, "hold").onHold();
1706 } else {
1707 findConferenceForAction(callId, "hold").onHold();
1708 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001709 }
1710
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001711 private void unhold(String callId) {
Ihab Awad60ac30b2014-05-20 22:32:12 -07001712 Log.d(this, "unhold %s", callId);
Santos Cordon0159ac02014-08-21 14:28:11 -07001713 if (mConnectionById.containsKey(callId)) {
1714 findConnectionForAction(callId, "unhold").onUnhold();
1715 } else {
1716 findConferenceForAction(callId, "unhold").onUnhold();
1717 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001718 }
1719
Yorke Lee4af59352015-05-13 14:14:54 -07001720 private void onCallAudioStateChanged(String callId, CallAudioState callAudioState) {
1721 Log.d(this, "onAudioStateChanged %s %s", callId, callAudioState);
Yorke Leea0d3ca92014-09-15 19:18:13 -07001722 if (mConnectionById.containsKey(callId)) {
Yorke Lee4af59352015-05-13 14:14:54 -07001723 findConnectionForAction(callId, "onCallAudioStateChanged").setCallAudioState(
1724 callAudioState);
Yorke Leea0d3ca92014-09-15 19:18:13 -07001725 } else {
Yorke Lee4af59352015-05-13 14:14:54 -07001726 findConferenceForAction(callId, "onCallAudioStateChanged").setCallAudioState(
1727 callAudioState);
Yorke Leea0d3ca92014-09-15 19:18:13 -07001728 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001729 }
1730
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001731 private void playDtmfTone(String callId, char digit) {
1732 Log.d(this, "playDtmfTone %s %c", callId, digit);
Yorke Leea0d3ca92014-09-15 19:18:13 -07001733 if (mConnectionById.containsKey(callId)) {
1734 findConnectionForAction(callId, "playDtmfTone").onPlayDtmfTone(digit);
1735 } else {
1736 findConferenceForAction(callId, "playDtmfTone").onPlayDtmfTone(digit);
1737 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001738 }
1739
1740 private void stopDtmfTone(String callId) {
1741 Log.d(this, "stopDtmfTone %s", callId);
Yorke Leea0d3ca92014-09-15 19:18:13 -07001742 if (mConnectionById.containsKey(callId)) {
1743 findConnectionForAction(callId, "stopDtmfTone").onStopDtmfTone();
1744 } else {
1745 findConferenceForAction(callId, "stopDtmfTone").onStopDtmfTone();
1746 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001747 }
1748
Santos Cordon823fd3c2014-08-07 18:35:18 -07001749 private void conference(String callId1, String callId2) {
1750 Log.d(this, "conference %s, %s", callId1, callId2);
Santos Cordon980acb92014-05-31 10:31:19 -07001751
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001752 // Attempt to get second connection or conference.
Santos Cordon823fd3c2014-08-07 18:35:18 -07001753 Connection connection2 = findConnectionForAction(callId2, "conference");
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001754 Conference conference2 = getNullConference();
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001755 if (connection2 == getNullConnection()) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001756 conference2 = findConferenceForAction(callId2, "conference");
1757 if (conference2 == getNullConference()) {
1758 Log.w(this, "Connection2 or Conference2 missing in conference request %s.",
1759 callId2);
1760 return;
1761 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07001762 }
Santos Cordonb6939982014-06-04 20:20:58 -07001763
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001764 // Attempt to get first connection or conference and perform merge.
Ihab Awad50e35062014-09-30 09:17:03 -07001765 Connection connection1 = findConnectionForAction(callId1, "conference");
1766 if (connection1 == getNullConnection()) {
1767 Conference conference1 = findConferenceForAction(callId1, "addConnection");
1768 if (conference1 == getNullConference()) {
1769 Log.w(this,
1770 "Connection1 or Conference1 missing in conference request %s.",
1771 callId1);
1772 } else {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001773 // Call 1 is a conference.
1774 if (connection2 != getNullConnection()) {
1775 // Call 2 is a connection so merge via call 1 (conference).
1776 conference1.onMerge(connection2);
1777 } else {
1778 // Call 2 is ALSO a conference; this should never happen.
1779 Log.wtf(this, "There can only be one conference and an attempt was made to " +
1780 "merge two conferences.");
1781 return;
1782 }
Ihab Awad50e35062014-09-30 09:17:03 -07001783 }
1784 } else {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001785 // Call 1 is a connection.
1786 if (conference2 != getNullConference()) {
1787 // Call 2 is a conference, so merge via call 2.
1788 conference2.onMerge(connection1);
1789 } else {
1790 // Call 2 is a connection, so merge together.
1791 onConference(connection1, connection2);
1792 }
Ihab Awad50e35062014-09-30 09:17:03 -07001793 }
Santos Cordon980acb92014-05-31 10:31:19 -07001794 }
1795
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001796 private void splitFromConference(String callId) {
Santos Cordonb6939982014-06-04 20:20:58 -07001797 Log.d(this, "splitFromConference(%s)", callId);
Santos Cordon980acb92014-05-31 10:31:19 -07001798
1799 Connection connection = findConnectionForAction(callId, "splitFromConference");
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001800 if (connection == getNullConnection()) {
Santos Cordon980acb92014-05-31 10:31:19 -07001801 Log.w(this, "Connection missing in conference request %s.", callId);
1802 return;
1803 }
1804
Santos Cordon0159ac02014-08-21 14:28:11 -07001805 Conference conference = connection.getConference();
1806 if (conference != null) {
1807 conference.onSeparate(connection);
1808 }
Santos Cordon980acb92014-05-31 10:31:19 -07001809 }
1810
Santos Cordona4868042014-09-04 17:39:22 -07001811 private void mergeConference(String callId) {
1812 Log.d(this, "mergeConference(%s)", callId);
1813 Conference conference = findConferenceForAction(callId, "mergeConference");
1814 if (conference != null) {
1815 conference.onMerge();
1816 }
1817 }
1818
1819 private void swapConference(String callId) {
1820 Log.d(this, "swapConference(%s)", callId);
1821 Conference conference = findConferenceForAction(callId, "swapConference");
1822 if (conference != null) {
1823 conference.onSwap();
1824 }
1825 }
1826
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001827 /**
1828 * Notifies a {@link Connection} of a request to pull an external call.
1829 *
1830 * See {@link Call#pullExternalCall()}.
1831 *
1832 * @param callId The ID of the call to pull.
1833 */
1834 private void pullExternalCall(String callId) {
1835 Log.d(this, "pullExternalCall(%s)", callId);
1836 Connection connection = findConnectionForAction(callId, "pullExternalCall");
1837 if (connection != null) {
1838 connection.onPullExternalCall();
1839 }
1840 }
1841
1842 /**
1843 * Notifies a {@link Connection} of a call event.
1844 *
1845 * See {@link Call#sendCallEvent(String, Bundle)}.
1846 *
1847 * @param callId The ID of the call receiving the event.
1848 * @param event The event.
1849 * @param extras Extras associated with the event.
1850 */
1851 private void sendCallEvent(String callId, String event, Bundle extras) {
1852 Log.d(this, "sendCallEvent(%s, %s)", callId, event);
1853 Connection connection = findConnectionForAction(callId, "sendCallEvent");
1854 if (connection != null) {
1855 connection.onCallEvent(event, extras);
1856 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001857 }
1858
Tyler Gunndee56a82016-03-23 16:06:34 -07001859 /**
Tyler Gunn79bc1ec2018-01-22 15:17:54 -08001860 * Notifies a {@link Connection} that a handover has completed.
1861 *
1862 * @param callId The ID of the call which completed handover.
1863 */
1864 private void notifyHandoverComplete(String callId) {
1865 Log.d(this, "notifyHandoverComplete(%s)", callId);
1866 Connection connection = findConnectionForAction(callId, "notifyHandoverComplete");
1867 if (connection != null) {
1868 connection.onHandoverComplete();
1869 }
1870 }
1871
1872 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001873 * Notifies a {@link Connection} or {@link Conference} of a change to the extras from Telecom.
1874 * <p>
1875 * These extra changes can originate from Telecom itself, or from an {@link InCallService} via
1876 * the {@link android.telecom.Call#putExtra(String, boolean)},
1877 * {@link android.telecom.Call#putExtra(String, int)},
1878 * {@link android.telecom.Call#putExtra(String, String)},
1879 * {@link Call#removeExtras(List)}.
1880 *
1881 * @param callId The ID of the call receiving the event.
1882 * @param extras The new extras bundle.
1883 */
1884 private void handleExtrasChanged(String callId, Bundle extras) {
1885 Log.d(this, "handleExtrasChanged(%s, %s)", callId, extras);
1886 if (mConnectionById.containsKey(callId)) {
1887 findConnectionForAction(callId, "handleExtrasChanged").handleExtrasChanged(extras);
1888 } else if (mConferenceById.containsKey(callId)) {
1889 findConferenceForAction(callId, "handleExtrasChanged").handleExtrasChanged(extras);
1890 }
1891 }
1892
Hall Liub64ac4c2017-02-06 10:49:48 -08001893 private void startRtt(String callId, Connection.RttTextStream rttTextStream) {
1894 Log.d(this, "startRtt(%s)", callId);
1895 if (mConnectionById.containsKey(callId)) {
1896 findConnectionForAction(callId, "startRtt").onStartRtt(rttTextStream);
1897 } else if (mConferenceById.containsKey(callId)) {
1898 Log.w(this, "startRtt called on a conference.");
1899 }
1900 }
1901
1902 private void stopRtt(String callId) {
1903 Log.d(this, "stopRtt(%s)", callId);
1904 if (mConnectionById.containsKey(callId)) {
1905 findConnectionForAction(callId, "stopRtt").onStopRtt();
1906 } else if (mConferenceById.containsKey(callId)) {
1907 Log.w(this, "stopRtt called on a conference.");
1908 }
1909 }
1910
1911 private void handleRttUpgradeResponse(String callId, Connection.RttTextStream rttTextStream) {
1912 Log.d(this, "handleRttUpgradeResponse(%s, %s)", callId, rttTextStream == null);
1913 if (mConnectionById.containsKey(callId)) {
1914 findConnectionForAction(callId, "handleRttUpgradeResponse")
1915 .handleRttUpgradeResponse(rttTextStream);
1916 } else if (mConferenceById.containsKey(callId)) {
1917 Log.w(this, "handleRttUpgradeResponse called on a conference.");
1918 }
1919 }
1920
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001921 private void onPostDialContinue(String callId, boolean proceed) {
Evan Charlton6dea4ac2014-06-03 14:07:13 -07001922 Log.d(this, "onPostDialContinue(%s)", callId);
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001923 findConnectionForAction(callId, "stopDtmfTone").onPostDialContinue(proceed);
Evan Charlton6dea4ac2014-06-03 14:07:13 -07001924 }
1925
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001926 private void onAdapterAttached() {
Ihab Awad9c3f1882014-06-30 21:17:13 -07001927 if (mAreAccountsInitialized) {
Santos Cordon52d8a152014-06-17 19:08:45 -07001928 // No need to query again if we already did it.
1929 return;
1930 }
1931
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001932 mAdapter.queryRemoteConnectionServices(new RemoteServiceCallback.Stub() {
Santos Cordon52d8a152014-06-17 19:08:45 -07001933 @Override
1934 public void onResult(
1935 final List<ComponentName> componentNames,
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001936 final List<IBinder> services) {
Brad Ebinger0c3541b2016-11-01 14:11:38 -07001937 mHandler.post(new android.telecom.Logging.Runnable("oAA.qRCS.oR", null /*lock*/) {
Ihab Awad6107bab2014-08-18 09:23:25 -07001938 @Override
Brad Ebinger0c3541b2016-11-01 14:11:38 -07001939 public void loggedRun() {
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001940 for (int i = 0; i < componentNames.size() && i < services.size(); i++) {
Santos Cordon52d8a152014-06-17 19:08:45 -07001941 mRemoteConnectionManager.addConnectionService(
1942 componentNames.get(i),
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001943 IConnectionService.Stub.asInterface(services.get(i)));
Santos Cordon52d8a152014-06-17 19:08:45 -07001944 }
Ihab Awad5d0410f2014-07-30 10:07:40 -07001945 onAccountsInitialized();
Sailesh Nepalc5b01572014-07-14 16:29:44 -07001946 Log.d(this, "remote connection services found: " + services);
Santos Cordon52d8a152014-06-17 19:08:45 -07001947 }
Brad Ebinger0c3541b2016-11-01 14:11:38 -07001948 }.prepare());
Santos Cordon52d8a152014-06-17 19:08:45 -07001949 }
1950
1951 @Override
1952 public void onError() {
Brad Ebinger0c3541b2016-11-01 14:11:38 -07001953 mHandler.post(new android.telecom.Logging.Runnable("oAA.qRCS.oE", null /*lock*/) {
Ihab Awad6107bab2014-08-18 09:23:25 -07001954 @Override
Brad Ebinger0c3541b2016-11-01 14:11:38 -07001955 public void loggedRun() {
Ihab Awad9c3f1882014-06-30 21:17:13 -07001956 mAreAccountsInitialized = true;
Santos Cordon52d8a152014-06-17 19:08:45 -07001957 }
Brad Ebinger0c3541b2016-11-01 14:11:38 -07001958 }.prepare());
Santos Cordon52d8a152014-06-17 19:08:45 -07001959 }
1960 });
1961 }
1962
Ihab Awadf8b69882014-07-25 15:14:01 -07001963 /**
1964 * Ask some other {@code ConnectionService} to create a {@code RemoteConnection} given an
Santos Cordona663f862014-10-29 13:49:58 -07001965 * incoming request. This is used by {@code ConnectionService}s that are registered with
1966 * {@link PhoneAccount#CAPABILITY_CONNECTION_MANAGER} and want to be able to manage
1967 * SIM-based incoming calls.
Ihab Awadf8b69882014-07-25 15:14:01 -07001968 *
1969 * @param connectionManagerPhoneAccount See description at
1970 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
1971 * @param request Details about the incoming call.
1972 * @return The {@code Connection} object to satisfy this call, or {@code null} to
1973 * not handle the call.
1974 */
1975 public final RemoteConnection createRemoteIncomingConnection(
1976 PhoneAccountHandle connectionManagerPhoneAccount,
1977 ConnectionRequest request) {
1978 return mRemoteConnectionManager.createRemoteConnection(
1979 connectionManagerPhoneAccount, request, true);
Santos Cordon52d8a152014-06-17 19:08:45 -07001980 }
1981
1982 /**
Ihab Awadf8b69882014-07-25 15:14:01 -07001983 * Ask some other {@code ConnectionService} to create a {@code RemoteConnection} given an
Santos Cordona663f862014-10-29 13:49:58 -07001984 * outgoing request. This is used by {@code ConnectionService}s that are registered with
1985 * {@link PhoneAccount#CAPABILITY_CONNECTION_MANAGER} and want to be able to use the
1986 * SIM-based {@code ConnectionService} to place its outgoing calls.
Ihab Awadf8b69882014-07-25 15:14:01 -07001987 *
1988 * @param connectionManagerPhoneAccount See description at
1989 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
Cuihtlauac ALVARADO0b3b2a52016-09-13 14:49:41 +02001990 * @param request Details about the outgoing call.
Ihab Awadf8b69882014-07-25 15:14:01 -07001991 * @return The {@code Connection} object to satisfy this call, or {@code null} to
1992 * not handle the call.
1993 */
1994 public final RemoteConnection createRemoteOutgoingConnection(
1995 PhoneAccountHandle connectionManagerPhoneAccount,
1996 ConnectionRequest request) {
1997 return mRemoteConnectionManager.createRemoteConnection(
1998 connectionManagerPhoneAccount, request, false);
1999 }
2000
2001 /**
Santos Cordona663f862014-10-29 13:49:58 -07002002 * Indicates to the relevant {@code RemoteConnectionService} that the specified
2003 * {@link RemoteConnection}s should be merged into a conference call.
2004 * <p>
2005 * If the conference request is successful, the method {@link #onRemoteConferenceAdded} will
2006 * be invoked.
2007 *
2008 * @param remoteConnection1 The first of the remote connections to conference.
2009 * @param remoteConnection2 The second of the remote connections to conference.
Ihab Awadb8e85c72014-08-23 20:34:57 -07002010 */
2011 public final void conferenceRemoteConnections(
Santos Cordona663f862014-10-29 13:49:58 -07002012 RemoteConnection remoteConnection1,
2013 RemoteConnection remoteConnection2) {
2014 mRemoteConnectionManager.conferenceRemoteConnections(remoteConnection1, remoteConnection2);
Ihab Awadb8e85c72014-08-23 20:34:57 -07002015 }
2016
2017 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07002018 * Adds a new conference call. When a conference call is created either as a result of an
2019 * explicit request via {@link #onConference} or otherwise, the connection service should supply
2020 * an instance of {@link Conference} by invoking this method. A conference call provided by this
2021 * method will persist until {@link Conference#destroy} is invoked on the conference instance.
2022 *
2023 * @param conference The new conference object.
2024 */
2025 public final void addConference(Conference conference) {
Rekha Kumar07366812015-03-24 16:42:31 -07002026 Log.d(this, "addConference: conference=%s", conference);
2027
Santos Cordon823fd3c2014-08-07 18:35:18 -07002028 String id = addConferenceInternal(conference);
2029 if (id != null) {
2030 List<String> connectionIds = new ArrayList<>(2);
2031 for (Connection connection : conference.getConnections()) {
2032 if (mIdByConnection.containsKey(connection)) {
2033 connectionIds.add(mIdByConnection.get(connection));
2034 }
2035 }
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002036 conference.setTelecomCallId(id);
Santos Cordon823fd3c2014-08-07 18:35:18 -07002037 ParcelableConference parcelableConference = new ParcelableConference(
Nancy Chenea38cca2014-09-05 16:38:49 -07002038 conference.getPhoneAccountHandle(),
Santos Cordon823fd3c2014-08-07 18:35:18 -07002039 conference.getState(),
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002040 conference.getConnectionCapabilities(),
Tyler Gunn720c6642016-03-22 09:02:47 -07002041 conference.getConnectionProperties(),
Tyler Gunncd5d33c2015-01-12 09:02:01 -08002042 connectionIds,
Rekha Kumar07366812015-03-24 16:42:31 -07002043 conference.getVideoProvider() == null ?
2044 null : conference.getVideoProvider().getInterface(),
2045 conference.getVideoState(),
Andrew Lee3e3e2f22015-04-16 13:48:43 -07002046 conference.getConnectTimeMillis(),
Tyler Gunn17541392018-02-01 08:58:38 -08002047 conference.getConnectionStartElapsedRealTime(),
Santos Cordon6b7f9552015-05-27 17:21:45 -07002048 conference.getStatusHints(),
2049 conference.getExtras());
Andrew Lee0f51da32015-04-16 13:11:55 -07002050
Santos Cordon823fd3c2014-08-07 18:35:18 -07002051 mAdapter.addConferenceCall(id, parcelableConference);
Rekha Kumar07366812015-03-24 16:42:31 -07002052 mAdapter.setVideoProvider(id, conference.getVideoProvider());
2053 mAdapter.setVideoState(id, conference.getVideoState());
Santos Cordon823fd3c2014-08-07 18:35:18 -07002054
2055 // Go through any child calls and set the parent.
2056 for (Connection connection : conference.getConnections()) {
2057 String connectionId = mIdByConnection.get(connection);
2058 if (connectionId != null) {
2059 mAdapter.setIsConferenced(connectionId, id);
2060 }
2061 }
Pengquan Meng70c9885332017-10-02 18:09:03 -07002062 onConferenceAdded(conference);
Santos Cordon823fd3c2014-08-07 18:35:18 -07002063 }
2064 }
2065
2066 /**
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002067 * Adds a connection created by the {@link ConnectionService} and informs telecom of the new
2068 * connection.
2069 *
2070 * @param phoneAccountHandle The phone account handle for the connection.
2071 * @param connection The connection to add.
2072 */
2073 public final void addExistingConnection(PhoneAccountHandle phoneAccountHandle,
2074 Connection connection) {
Tyler Gunn78da7812017-05-09 14:34:57 -07002075 addExistingConnection(phoneAccountHandle, connection, null /* conference */);
2076 }
2077
2078 /**
Pengquan Meng731c1a32017-11-21 18:01:13 -08002079 * Call to inform Telecom that your {@link ConnectionService} has released call resources (e.g
2080 * microphone, camera).
2081 *
2082 * @see ConnectionService#onConnectionServiceFocusLost()
2083 */
2084 public final void connectionServiceFocusReleased() {
2085 mAdapter.onConnectionServiceFocusReleased();
2086 }
2087
2088 /**
Tyler Gunn78da7812017-05-09 14:34:57 -07002089 * Adds a connection created by the {@link ConnectionService} and informs telecom of the new
2090 * connection.
2091 *
2092 * @param phoneAccountHandle The phone account handle for the connection.
2093 * @param connection The connection to add.
2094 * @param conference The parent conference of the new connection.
2095 * @hide
2096 */
2097 public final void addExistingConnection(PhoneAccountHandle phoneAccountHandle,
2098 Connection connection, Conference conference) {
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002099
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002100 String id = addExistingConnectionInternal(phoneAccountHandle, connection);
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002101 if (id != null) {
2102 List<String> emptyList = new ArrayList<>(0);
Tyler Gunn78da7812017-05-09 14:34:57 -07002103 String conferenceId = null;
2104 if (conference != null) {
2105 conferenceId = mIdByConference.get(conference);
2106 }
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002107
2108 ParcelableConnection parcelableConnection = new ParcelableConnection(
2109 phoneAccountHandle,
2110 connection.getState(),
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002111 connection.getConnectionCapabilities(),
Tyler Gunn720c6642016-03-22 09:02:47 -07002112 connection.getConnectionProperties(),
Christine Hallstrom2830ce92016-11-30 16:06:42 -08002113 connection.getSupportedAudioRoutes(),
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002114 connection.getAddress(),
2115 connection.getAddressPresentation(),
2116 connection.getCallerDisplayName(),
2117 connection.getCallerDisplayNamePresentation(),
2118 connection.getVideoProvider() == null ?
2119 null : connection.getVideoProvider().getInterface(),
2120 connection.getVideoState(),
2121 connection.isRingbackRequested(),
2122 connection.getAudioModeIsVoip(),
Roshan Piuse927ec02015-07-15 15:47:21 -07002123 connection.getConnectTimeMillis(),
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002124 connection.getConnectElapsedTimeMillis(),
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002125 connection.getStatusHints(),
2126 connection.getDisconnectCause(),
Santos Cordon6b7f9552015-05-27 17:21:45 -07002127 emptyList,
Tyler Gunn78da7812017-05-09 14:34:57 -07002128 connection.getExtras(),
2129 conferenceId);
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002130 mAdapter.addExistingConnection(id, parcelableConnection);
2131 }
2132 }
2133
2134 /**
Ihab Awadf8b69882014-07-25 15:14:01 -07002135 * Returns all the active {@code Connection}s for which this {@code ConnectionService}
2136 * has taken responsibility.
2137 *
2138 * @return A collection of {@code Connection}s created by this {@code ConnectionService}.
Santos Cordonb6939982014-06-04 20:20:58 -07002139 */
Sailesh Nepal091768c2014-06-30 15:15:23 -07002140 public final Collection<Connection> getAllConnections() {
Santos Cordonb6939982014-06-04 20:20:58 -07002141 return mConnectionById.values();
2142 }
2143
2144 /**
Santos Cordona6018b92016-02-16 14:23:12 -08002145 * Returns all the active {@code Conference}s for which this {@code ConnectionService}
2146 * has taken responsibility.
2147 *
2148 * @return A collection of {@code Conference}s created by this {@code ConnectionService}.
2149 */
2150 public final Collection<Conference> getAllConferences() {
2151 return mConferenceById.values();
2152 }
2153
2154 /**
Ihab Awadf8b69882014-07-25 15:14:01 -07002155 * Create a {@code Connection} given an incoming request. This is used to attach to existing
2156 * incoming calls.
Evan Charltonbf11f982014-07-20 22:06:28 -07002157 *
Ihab Awadf8b69882014-07-25 15:14:01 -07002158 * @param connectionManagerPhoneAccount See description at
2159 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
2160 * @param request Details about the incoming call.
2161 * @return The {@code Connection} object to satisfy this call, or {@code null} to
2162 * not handle the call.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002163 */
Ihab Awadf8b69882014-07-25 15:14:01 -07002164 public Connection onCreateIncomingConnection(
2165 PhoneAccountHandle connectionManagerPhoneAccount,
2166 ConnectionRequest request) {
2167 return null;
2168 }
Sailesh Nepalc5b01572014-07-14 16:29:44 -07002169
2170 /**
Tyler Gunn041a1fe2017-05-12 10:04:49 -07002171 * Called after the {@link Connection} returned by
2172 * {@link #onCreateIncomingConnection(PhoneAccountHandle, ConnectionRequest)}
2173 * or {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)} has been
2174 * added to the {@link ConnectionService} and sent to Telecom.
2175 *
2176 * @param connection the {@link Connection}.
2177 * @hide
2178 */
2179 public void onCreateConnectionComplete(Connection connection) {
2180 }
2181
2182 /**
Tyler Gunnf5035432017-01-09 09:43:12 -08002183 * Called by Telecom to inform the {@link ConnectionService} that its request to create a new
2184 * incoming {@link Connection} was denied.
2185 * <p>
2186 * Used when a self-managed {@link ConnectionService} attempts to create a new incoming
2187 * {@link Connection}, but Telecom has determined that the call cannot be allowed at this time.
2188 * The {@link ConnectionService} is responsible for silently rejecting the new incoming
2189 * {@link Connection}.
2190 * <p>
2191 * See {@link TelecomManager#isIncomingCallPermitted(PhoneAccountHandle)} for more information.
2192 *
Tyler Gunn159f35c2017-03-02 09:28:37 -08002193 * @param connectionManagerPhoneAccount See description at
2194 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
Tyler Gunnf5035432017-01-09 09:43:12 -08002195 * @param request The incoming connection request.
2196 */
Tyler Gunn159f35c2017-03-02 09:28:37 -08002197 public void onCreateIncomingConnectionFailed(PhoneAccountHandle connectionManagerPhoneAccount,
2198 ConnectionRequest request) {
Tyler Gunnf5035432017-01-09 09:43:12 -08002199 }
2200
2201 /**
2202 * Called by Telecom to inform the {@link ConnectionService} that its request to create a new
2203 * outgoing {@link Connection} was denied.
2204 * <p>
2205 * Used when a self-managed {@link ConnectionService} attempts to create a new outgoing
2206 * {@link Connection}, but Telecom has determined that the call cannot be placed at this time.
2207 * The {@link ConnectionService} is responisible for informing the user that the
2208 * {@link Connection} cannot be made at this time.
2209 * <p>
2210 * See {@link TelecomManager#isOutgoingCallPermitted(PhoneAccountHandle)} for more information.
2211 *
Tyler Gunn159f35c2017-03-02 09:28:37 -08002212 * @param connectionManagerPhoneAccount See description at
2213 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
Tyler Gunnf5035432017-01-09 09:43:12 -08002214 * @param request The outgoing connection request.
2215 */
Tyler Gunn159f35c2017-03-02 09:28:37 -08002216 public void onCreateOutgoingConnectionFailed(PhoneAccountHandle connectionManagerPhoneAccount,
2217 ConnectionRequest request) {
Tyler Gunnf5035432017-01-09 09:43:12 -08002218 }
2219
2220 /**
Shriram Ganesh6bf35ac2014-12-11 17:53:38 -08002221 * Trigger recalculate functinality for conference calls. This is used when a Telephony
2222 * Connection is part of a conference controller but is not yet added to Connection
2223 * Service and hence cannot be added to the conference call.
2224 *
2225 * @hide
2226 */
2227 public void triggerConferenceRecalculate() {
2228 }
2229
2230 /**
Ihab Awadf8b69882014-07-25 15:14:01 -07002231 * Create a {@code Connection} given an outgoing request. This is used to initiate new
2232 * outgoing calls.
Sailesh Nepalc5b01572014-07-14 16:29:44 -07002233 *
Ihab Awadf8b69882014-07-25 15:14:01 -07002234 * @param connectionManagerPhoneAccount The connection manager account to use for managing
2235 * this call.
2236 * <p>
2237 * If this parameter is not {@code null}, it means that this {@code ConnectionService}
2238 * has registered one or more {@code PhoneAccount}s having
2239 * {@link PhoneAccount#CAPABILITY_CONNECTION_MANAGER}. This parameter will contain
2240 * one of these {@code PhoneAccount}s, while the {@code request} will contain another
2241 * (usually but not always distinct) {@code PhoneAccount} to be used for actually
2242 * making the connection.
2243 * <p>
2244 * If this parameter is {@code null}, it means that this {@code ConnectionService} is
2245 * being asked to make a direct connection. The
2246 * {@link ConnectionRequest#getAccountHandle()} of parameter {@code request} will be
2247 * a {@code PhoneAccount} registered by this {@code ConnectionService} to use for
2248 * making the connection.
2249 * @param request Details about the outgoing call.
2250 * @return The {@code Connection} object to satisfy this call, or the result of an invocation
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002251 * of {@link Connection#createFailedConnection(DisconnectCause)} to not handle the call.
Sailesh Nepalc5b01572014-07-14 16:29:44 -07002252 */
Ihab Awadf8b69882014-07-25 15:14:01 -07002253 public Connection onCreateOutgoingConnection(
2254 PhoneAccountHandle connectionManagerPhoneAccount,
2255 ConnectionRequest request) {
2256 return null;
2257 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002258
2259 /**
Tyler Gunn9d127732018-03-02 15:45:51 -08002260 * Called by Telecom to request that a {@link ConnectionService} creates an instance of an
2261 * outgoing handover {@link Connection}.
2262 * <p>
2263 * A call handover is the process where an ongoing call is transferred from one app (i.e.
2264 * {@link ConnectionService} to another app. The user could, for example, choose to continue a
2265 * mobile network call in a video calling app. The mobile network call via the Telephony stack
2266 * is referred to as the source of the handover, and the video calling app is referred to as the
2267 * destination.
2268 * <p>
2269 * When considering a handover scenario the <em>initiating</em> device is where a user initiated
2270 * the handover process (e.g. by calling {@link android.telecom.Call#handoverTo(
2271 * PhoneAccountHandle, int, Bundle)}, and the other device is considered the <em>receiving</em>
2272 * device.
2273 * <p>
2274 * This method is called on the destination {@link ConnectionService} on <em>initiating</em>
2275 * device when the user initiates a handover request from one app to another. The user request
2276 * originates in the {@link InCallService} via
2277 * {@link android.telecom.Call#handoverTo(PhoneAccountHandle, int, Bundle)}.
2278 * <p>
2279 * For a full discussion of the handover process and the APIs involved, see
2280 * {@link android.telecom.Call#handoverTo(PhoneAccountHandle, int, Bundle)}.
2281 * <p>
2282 * Implementations of this method should return an instance of {@link Connection} which
2283 * represents the handover. If your app does not wish to accept a handover to it at this time,
2284 * you can return {@code null}. The code below shows an example of how this is done.
2285 * <pre>
2286 * {@code
2287 * public Connection onCreateIncomingHandoverConnection(PhoneAccountHandle
2288 * fromPhoneAccountHandle, ConnectionRequest request) {
2289 * if (!isHandoverAvailable()) {
2290 * return null;
2291 * }
2292 * MyConnection connection = new MyConnection();
2293 * connection.setAddress(request.getAddress(), TelecomManager.PRESENTATION_ALLOWED);
2294 * connection.setVideoState(request.getVideoState());
2295 * return connection;
2296 * }
2297 * }
2298 * </pre>
2299 *
Sanket Padawea8eddd42017-11-03 11:07:35 -07002300 * @param fromPhoneAccountHandle {@link PhoneAccountHandle} associated with the
2301 * ConnectionService which needs to handover the call.
Tyler Gunn9d127732018-03-02 15:45:51 -08002302 * @param request Details about the call to handover.
2303 * @return {@link Connection} instance corresponding to the handover call.
Sanket Padawea8eddd42017-11-03 11:07:35 -07002304 */
2305 public Connection onCreateOutgoingHandoverConnection(PhoneAccountHandle fromPhoneAccountHandle,
2306 ConnectionRequest request) {
2307 return null;
2308 }
2309
2310 /**
Tyler Gunn9d127732018-03-02 15:45:51 -08002311 * Called by Telecom to request that a {@link ConnectionService} creates an instance of an
2312 * incoming handover {@link Connection}.
2313 * <p>
2314 * A call handover is the process where an ongoing call is transferred from one app (i.e.
2315 * {@link ConnectionService} to another app. The user could, for example, choose to continue a
2316 * mobile network call in a video calling app. The mobile network call via the Telephony stack
2317 * is referred to as the source of the handover, and the video calling app is referred to as the
2318 * destination.
2319 * <p>
2320 * When considering a handover scenario the <em>initiating</em> device is where a user initiated
2321 * the handover process (e.g. by calling {@link android.telecom.Call#handoverTo(
2322 * PhoneAccountHandle, int, Bundle)}, and the other device is considered the <em>receiving</em>
2323 * device.
2324 * <p>
2325 * This method is called on the destination app on the <em>receiving</em> device when the
2326 * destination app calls {@link TelecomManager#acceptHandover(Uri, int, PhoneAccountHandle)} to
2327 * accept an incoming handover from the <em>initiating</em> device.
2328 * <p>
2329 * For a full discussion of the handover process and the APIs involved, see
2330 * {@link android.telecom.Call#handoverTo(PhoneAccountHandle, int, Bundle)}.
2331 * <p>
2332 * Implementations of this method should return an instance of {@link Connection} which
2333 * represents the handover. The code below shows an example of how this is done.
2334 * <pre>
2335 * {@code
2336 * public Connection onCreateIncomingHandoverConnection(PhoneAccountHandle
2337 * fromPhoneAccountHandle, ConnectionRequest request) {
2338 * // Given that your app requested to accept the handover, you should not return null here.
2339 * MyConnection connection = new MyConnection();
2340 * connection.setAddress(request.getAddress(), TelecomManager.PRESENTATION_ALLOWED);
2341 * connection.setVideoState(request.getVideoState());
2342 * return connection;
2343 * }
2344 * }
2345 * </pre>
2346 *
Sanket Padawea8eddd42017-11-03 11:07:35 -07002347 * @param fromPhoneAccountHandle {@link PhoneAccountHandle} associated with the
2348 * ConnectionService which needs to handover the call.
2349 * @param request Details about the call which needs to be handover.
Tyler Gunn9d127732018-03-02 15:45:51 -08002350 * @return {@link Connection} instance corresponding to the handover call.
Sanket Padawea8eddd42017-11-03 11:07:35 -07002351 */
2352 public Connection onCreateIncomingHandoverConnection(PhoneAccountHandle fromPhoneAccountHandle,
2353 ConnectionRequest request) {
2354 return null;
2355 }
2356
2357 /**
2358 * Called by Telecom in response to a {@code TelecomManager#acceptHandover()}
2359 * invocation which failed.
Tyler Gunn9d127732018-03-02 15:45:51 -08002360 * <p>
2361 * For a full discussion of the handover process and the APIs involved, see
2362 * {@link android.telecom.Call#handoverTo(PhoneAccountHandle, int, Bundle)}
2363 *
2364 * @param request Details about the call which failed to handover.
2365 * @param error Reason for handover failure. Will be one of the
Sanket Padawea8eddd42017-11-03 11:07:35 -07002366 */
Tyler Gunn9d127732018-03-02 15:45:51 -08002367 public void onHandoverFailed(ConnectionRequest request,
2368 @Call.Callback.HandoverFailureErrors int error) {
Sanket Padawea8eddd42017-11-03 11:07:35 -07002369 return;
2370 }
2371
2372 /**
Yorke Leec3cf9822014-10-02 09:38:39 -07002373 * Create a {@code Connection} for a new unknown call. An unknown call is a call originating
2374 * from the ConnectionService that was neither a user-initiated outgoing call, nor an incoming
2375 * call created using
2376 * {@code TelecomManager#addNewIncomingCall(PhoneAccountHandle, android.os.Bundle)}.
2377 *
Yorke Lee770ed6e2014-10-06 18:58:52 -07002378 * @hide
Yorke Leec3cf9822014-10-02 09:38:39 -07002379 */
2380 public Connection onCreateUnknownConnection(PhoneAccountHandle connectionManagerPhoneAccount,
2381 ConnectionRequest request) {
Brad Ebingerb32d4f82016-10-24 16:40:49 -07002382 return null;
Yorke Leec3cf9822014-10-02 09:38:39 -07002383 }
2384
2385 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07002386 * Conference two specified connections. Invoked when the user has made a request to merge the
2387 * specified connections into a conference call. In response, the connection service should
2388 * create an instance of {@link Conference} and pass it into {@link #addConference}.
Santos Cordonb6939982014-06-04 20:20:58 -07002389 *
Santos Cordon823fd3c2014-08-07 18:35:18 -07002390 * @param connection1 A connection to merge into a conference call.
2391 * @param connection2 A connection to merge into a conference call.
Santos Cordonb6939982014-06-04 20:20:58 -07002392 */
Santos Cordon823fd3c2014-08-07 18:35:18 -07002393 public void onConference(Connection connection1, Connection connection2) {}
Santos Cordonb6939982014-06-04 20:20:58 -07002394
Santos Cordona663f862014-10-29 13:49:58 -07002395 /**
Pengquan Meng70c9885332017-10-02 18:09:03 -07002396 * Called when a connection is added.
2397 * @hide
2398 */
2399 public void onConnectionAdded(Connection connection) {}
2400
2401 /**
2402 * Called when a connection is removed.
2403 * @hide
2404 */
2405 public void onConnectionRemoved(Connection connection) {}
2406
2407 /**
2408 * Called when a conference is added.
2409 * @hide
2410 */
2411 public void onConferenceAdded(Conference conference) {}
2412
2413 /**
2414 * Called when a conference is removed.
2415 * @hide
2416 */
2417 public void onConferenceRemoved(Conference conference) {}
2418
2419 /**
Santos Cordona663f862014-10-29 13:49:58 -07002420 * Indicates that a remote conference has been created for existing {@link RemoteConnection}s.
2421 * When this method is invoked, this {@link ConnectionService} should create its own
2422 * representation of the conference call and send it to telecom using {@link #addConference}.
2423 * <p>
2424 * This is only relevant to {@link ConnectionService}s which are registered with
2425 * {@link PhoneAccount#CAPABILITY_CONNECTION_MANAGER}.
2426 *
2427 * @param conference The remote conference call.
2428 */
Ihab Awadb8e85c72014-08-23 20:34:57 -07002429 public void onRemoteConferenceAdded(RemoteConference conference) {}
2430
Santos Cordon823fd3c2014-08-07 18:35:18 -07002431 /**
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002432 * Called when an existing connection is added remotely.
2433 * @param connection The existing connection which was added.
2434 */
2435 public void onRemoteExistingConnectionAdded(RemoteConnection connection) {}
2436
2437 /**
Pengquan Meng731c1a32017-11-21 18:01:13 -08002438 * Called when the {@link ConnectionService} has lost the call focus.
2439 * The {@link ConnectionService} should release the call resources and invokes
2440 * {@link ConnectionService#connectionServiceFocusReleased()} to inform telecom that it has
2441 * released the call resources.
2442 */
2443 public void onConnectionServiceFocusLost() {}
2444
2445 /**
2446 * Called when the {@link ConnectionService} has gained the call focus. The
2447 * {@link ConnectionService} can acquire the call resources at this time.
2448 */
2449 public void onConnectionServiceFocusGained() {}
2450
2451 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07002452 * @hide
2453 */
2454 public boolean containsConference(Conference conference) {
2455 return mIdByConference.containsKey(conference);
2456 }
2457
Ihab Awadb8e85c72014-08-23 20:34:57 -07002458 /** {@hide} */
2459 void addRemoteConference(RemoteConference remoteConference) {
2460 onRemoteConferenceAdded(remoteConference);
2461 }
2462
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002463 /** {@hide} */
2464 void addRemoteExistingConnection(RemoteConnection remoteConnection) {
2465 onRemoteExistingConnectionAdded(remoteConnection);
2466 }
2467
Ihab Awad5d0410f2014-07-30 10:07:40 -07002468 private void onAccountsInitialized() {
2469 mAreAccountsInitialized = true;
2470 for (Runnable r : mPreInitializationConnectionRequests) {
2471 r.run();
2472 }
2473 mPreInitializationConnectionRequests.clear();
2474 }
2475
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002476 /**
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002477 * Adds an existing connection to the list of connections, identified by a new call ID unique
2478 * to this connection service.
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002479 *
2480 * @param connection The connection.
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002481 * @return The ID of the connection (e.g. the call-id).
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002482 */
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002483 private String addExistingConnectionInternal(PhoneAccountHandle handle, Connection connection) {
2484 String id;
Tyler Gunncd6ccfd2016-10-17 15:48:19 -07002485
2486 if (connection.getExtras() != null && connection.getExtras()
2487 .containsKey(Connection.EXTRA_ORIGINAL_CONNECTION_ID)) {
2488 id = connection.getExtras().getString(Connection.EXTRA_ORIGINAL_CONNECTION_ID);
2489 Log.d(this, "addExistingConnectionInternal - conn %s reusing original id %s",
2490 connection.getTelecomCallId(), id);
2491 } else if (handle == null) {
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002492 // If no phone account handle was provided, we cannot be sure the call ID is unique,
2493 // so just use a random UUID.
2494 id = UUID.randomUUID().toString();
2495 } else {
2496 // Phone account handle was provided, so use the ConnectionService class name as a
2497 // prefix for a unique incremental call ID.
2498 id = handle.getComponentName().getClassName() + "@" + getNextCallId();
2499 }
Pengquan Meng70c9885332017-10-02 18:09:03 -07002500 addConnection(handle, id, connection);
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002501 return id;
2502 }
2503
Pengquan Meng70c9885332017-10-02 18:09:03 -07002504 private void addConnection(PhoneAccountHandle handle, String callId, Connection connection) {
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002505 connection.setTelecomCallId(callId);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002506 mConnectionById.put(callId, connection);
2507 mIdByConnection.put(connection, callId);
2508 connection.addConnectionListener(mConnectionListener);
Santos Cordon823fd3c2014-08-07 18:35:18 -07002509 connection.setConnectionService(this);
Pengquan Meng70c9885332017-10-02 18:09:03 -07002510 connection.setPhoneAccountHandle(handle);
2511 onConnectionAdded(connection);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002512 }
2513
Anthony Lee30e65842014-11-06 16:30:53 -08002514 /** {@hide} */
2515 protected void removeConnection(Connection connection) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07002516 connection.unsetConnectionService(this);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002517 connection.removeConnectionListener(mConnectionListener);
Chenjie Luoe370b532016-05-12 16:59:43 -07002518 String id = mIdByConnection.get(connection);
2519 if (id != null) {
2520 mConnectionById.remove(id);
2521 mIdByConnection.remove(connection);
2522 mAdapter.removeCall(id);
Pengquan Meng70c9885332017-10-02 18:09:03 -07002523 onConnectionRemoved(connection);
Chenjie Luoe370b532016-05-12 16:59:43 -07002524 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002525 }
2526
Santos Cordon823fd3c2014-08-07 18:35:18 -07002527 private String addConferenceInternal(Conference conference) {
Tyler Gunncd6ccfd2016-10-17 15:48:19 -07002528 String originalId = null;
2529 if (conference.getExtras() != null && conference.getExtras()
2530 .containsKey(Connection.EXTRA_ORIGINAL_CONNECTION_ID)) {
2531 originalId = conference.getExtras().getString(Connection.EXTRA_ORIGINAL_CONNECTION_ID);
2532 Log.d(this, "addConferenceInternal: conf %s reusing original id %s",
2533 conference.getTelecomCallId(),
2534 originalId);
2535 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07002536 if (mIdByConference.containsKey(conference)) {
2537 Log.w(this, "Re-adding an existing conference: %s.", conference);
2538 } else if (conference != null) {
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002539 // Conferences do not (yet) have a PhoneAccountHandle associated with them, so we
2540 // cannot determine a ConnectionService class name to associate with the ID, so use
2541 // a unique UUID (for now).
Tyler Gunncd6ccfd2016-10-17 15:48:19 -07002542 String id = originalId == null ? UUID.randomUUID().toString() : originalId;
Santos Cordon823fd3c2014-08-07 18:35:18 -07002543 mConferenceById.put(id, conference);
2544 mIdByConference.put(conference, id);
2545 conference.addListener(mConferenceListener);
2546 return id;
2547 }
2548
2549 return null;
2550 }
2551
2552 private void removeConference(Conference conference) {
2553 if (mIdByConference.containsKey(conference)) {
2554 conference.removeListener(mConferenceListener);
2555
2556 String id = mIdByConference.get(conference);
2557 mConferenceById.remove(id);
2558 mIdByConference.remove(conference);
2559 mAdapter.removeCall(id);
Pengquan Meng70c9885332017-10-02 18:09:03 -07002560
2561 onConferenceRemoved(conference);
Santos Cordon823fd3c2014-08-07 18:35:18 -07002562 }
2563 }
2564
Ihab Awad542e0ea2014-05-16 10:22:16 -07002565 private Connection findConnectionForAction(String callId, String action) {
Tyler Gunn0a88f2e2017-06-16 20:20:34 -07002566 if (callId != null && mConnectionById.containsKey(callId)) {
Ihab Awad542e0ea2014-05-16 10:22:16 -07002567 return mConnectionById.get(callId);
2568 }
Ihab Awad60ac30b2014-05-20 22:32:12 -07002569 Log.w(this, "%s - Cannot find Connection %s", action, callId);
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07002570 return getNullConnection();
2571 }
2572
2573 static synchronized Connection getNullConnection() {
2574 if (sNullConnection == null) {
2575 sNullConnection = new Connection() {};
2576 }
2577 return sNullConnection;
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002578 }
Santos Cordon0159ac02014-08-21 14:28:11 -07002579
2580 private Conference findConferenceForAction(String conferenceId, String action) {
2581 if (mConferenceById.containsKey(conferenceId)) {
2582 return mConferenceById.get(conferenceId);
2583 }
2584 Log.w(this, "%s - Cannot find conference %s", action, conferenceId);
2585 return getNullConference();
2586 }
2587
Ihab Awadb8e85c72014-08-23 20:34:57 -07002588 private List<String> createConnectionIdList(List<Connection> connections) {
2589 List<String> ids = new ArrayList<>();
2590 for (Connection c : connections) {
2591 if (mIdByConnection.containsKey(c)) {
2592 ids.add(mIdByConnection.get(c));
2593 }
2594 }
2595 Collections.sort(ids);
2596 return ids;
2597 }
2598
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002599 /**
2600 * Builds a list of {@link Connection} and {@link Conference} IDs based on the list of
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002601 * {@link Conferenceable}s passed in.
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002602 *
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002603 * @param conferenceables The {@link Conferenceable} connections and conferences.
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002604 * @return List of string conference and call Ids.
2605 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002606 private List<String> createIdList(List<Conferenceable> conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002607 List<String> ids = new ArrayList<>();
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002608 for (Conferenceable c : conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002609 // Only allow Connection and Conference conferenceables.
2610 if (c instanceof Connection) {
2611 Connection connection = (Connection) c;
2612 if (mIdByConnection.containsKey(connection)) {
2613 ids.add(mIdByConnection.get(connection));
2614 }
2615 } else if (c instanceof Conference) {
2616 Conference conference = (Conference) c;
2617 if (mIdByConference.containsKey(conference)) {
2618 ids.add(mIdByConference.get(conference));
2619 }
2620 }
2621 }
2622 Collections.sort(ids);
2623 return ids;
2624 }
2625
Santos Cordon0159ac02014-08-21 14:28:11 -07002626 private Conference getNullConference() {
2627 if (sNullConference == null) {
2628 sNullConference = new Conference(null) {};
2629 }
2630 return sNullConference;
2631 }
Santos Cordon29f2f2e2014-09-11 19:50:24 -07002632
2633 private void endAllConnections() {
2634 // Unbound from telecomm. We should end all connections and conferences.
2635 for (Connection connection : mIdByConnection.keySet()) {
2636 // only operate on top-level calls. Conference calls will be removed on their own.
2637 if (connection.getConference() == null) {
2638 connection.onDisconnect();
2639 }
2640 }
2641 for (Conference conference : mIdByConference.keySet()) {
2642 conference.onDisconnect();
2643 }
2644 }
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002645
2646 /**
2647 * Retrieves the next call ID as maintainted by the connection service.
2648 *
2649 * @return The call ID.
2650 */
2651 private int getNextCallId() {
Brad Ebingerb32d4f82016-10-24 16:40:49 -07002652 synchronized (mIdSyncRoot) {
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002653 return ++mId;
2654 }
2655 }
Santos Cordon980acb92014-05-31 10:31:19 -07002656}