blob: 0abd9fc62b1469af59f751b8b79fcfdec8f51a78 [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
Brad Ebinger99f17ce2019-09-11 18:06:51 -070033import com.android.internal.annotations.VisibleForTesting;
Sailesh Nepal2a46b902014-07-04 17:21:07 -070034import com.android.internal.os.SomeArgs;
Tyler Gunnef9f6f92014-09-12 22:16:17 -070035import com.android.internal.telecom.IConnectionService;
36import com.android.internal.telecom.IConnectionServiceAdapter;
37import com.android.internal.telecom.RemoteServiceCallback;
Santos Cordon52d8a152014-06-17 19:08:45 -070038
Ihab Awad5d0410f2014-07-30 10:07:40 -070039import java.util.ArrayList;
Santos Cordonb6939982014-06-04 20:20:58 -070040import java.util.Collection;
Santos Cordon7c7bc7f2014-07-28 18:15:48 -070041import java.util.Collections;
Santos Cordon52d8a152014-06-17 19:08:45 -070042import java.util.List;
Ihab Awad542e0ea2014-05-16 10:22:16 -070043import java.util.Map;
Santos Cordon823fd3c2014-08-07 18:35:18 -070044import java.util.UUID;
mike dooley95e80702014-09-18 14:07:52 -070045import java.util.concurrent.ConcurrentHashMap;
Ihab Awad542e0ea2014-05-16 10:22:16 -070046
47/**
Tyler Gunnf5035432017-01-09 09:43:12 -080048 * An abstract service that should be implemented by any apps which either:
49 * <ol>
50 * <li>Can make phone calls (VoIP or otherwise) and want those calls to be integrated into the
51 * built-in phone app. Referred to as a <b>system managed</b> {@link ConnectionService}.</li>
52 * <li>Are a standalone calling app and don't want their calls to be integrated into the
53 * built-in phone app. Referred to as a <b>self managed</b> {@link ConnectionService}.</li>
54 * </ol>
55 * Once implemented, the {@link ConnectionService} needs to take the following steps so that Telecom
56 * will bind to it:
Santos Cordona663f862014-10-29 13:49:58 -070057 * <p>
58 * 1. <i>Registration in AndroidManifest.xml</i>
59 * <br/>
60 * <pre>
61 * &lt;service android:name="com.example.package.MyConnectionService"
62 * android:label="@string/some_label_for_my_connection_service"
Yorke Lee249c12e2015-05-13 15:59:29 -070063 * android:permission="android.permission.BIND_TELECOM_CONNECTION_SERVICE"&gt;
Santos Cordona663f862014-10-29 13:49:58 -070064 * &lt;intent-filter&gt;
65 * &lt;action android:name="android.telecom.ConnectionService" /&gt;
66 * &lt;/intent-filter&gt;
67 * &lt;/service&gt;
68 * </pre>
69 * <p>
70 * 2. <i> Registration of {@link PhoneAccount} with {@link TelecomManager}.</i>
71 * <br/>
72 * See {@link PhoneAccount} and {@link TelecomManager#registerPhoneAccount} for more information.
73 * <p>
Tyler Gunnf5035432017-01-09 09:43:12 -080074 * System managed {@link ConnectionService}s must be enabled by the user in the phone app settings
kopriva82c591b2018-10-08 15:57:00 -070075 * before Telecom will bind to them. Self-managed {@link ConnectionService}s must be granted the
Tyler Gunnf5035432017-01-09 09:43:12 -080076 * appropriate permission before Telecom will bind to them.
77 * <p>
78 * Once registered and enabled by the user in the phone app settings or granted permission, telecom
79 * will bind to a {@link ConnectionService} implementation when it wants that
80 * {@link ConnectionService} to place a call or the service has indicated that is has an incoming
81 * call through {@link TelecomManager#addNewIncomingCall}. The {@link ConnectionService} can then
82 * expect a call to {@link #onCreateIncomingConnection} or {@link #onCreateOutgoingConnection}
83 * wherein it should provide a new instance of a {@link Connection} object. It is through this
84 * {@link Connection} object that telecom receives state updates and the {@link ConnectionService}
Santos Cordona663f862014-10-29 13:49:58 -070085 * receives call-commands such as answer, reject, hold and disconnect.
86 * <p>
Tyler Gunnf5035432017-01-09 09:43:12 -080087 * When there are no more live calls, telecom will unbind from the {@link ConnectionService}.
Ihab Awad542e0ea2014-05-16 10:22:16 -070088 */
Sailesh Nepal2a46b902014-07-04 17:21:07 -070089public abstract class ConnectionService extends Service {
Santos Cordon5c6fa952014-07-20 17:47:12 -070090 /**
91 * The {@link Intent} that must be declared as handled by the service.
92 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -070093 @SdkConstant(SdkConstant.SdkConstantType.SERVICE_ACTION)
Tyler Gunnef9f6f92014-09-12 22:16:17 -070094 public static final String SERVICE_INTERFACE = "android.telecom.ConnectionService";
Santos Cordon5c6fa952014-07-20 17:47:12 -070095
Tyler Gunn8bf76572017-04-06 15:30:08 -070096 /**
97 * Boolean extra used by Telecom to inform a {@link ConnectionService} that the purpose of it
98 * being asked to create a new outgoing {@link Connection} is to perform a handover of an
99 * ongoing call on the device from another {@link PhoneAccount}/{@link ConnectionService}. Will
100 * be specified in the {@link ConnectionRequest#getExtras()} passed by Telecom when
101 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)} is called.
102 * <p>
Tyler Gunn727c6bd2017-04-11 09:51:40 -0700103 * When your {@link ConnectionService} receives this extra, it should communicate the fact that
104 * this is a handover to the other device's matching {@link ConnectionService}. That
Tyler Gunn8bf76572017-04-06 15:30:08 -0700105 * {@link ConnectionService} will continue the handover using
106 * {@link TelecomManager#addNewIncomingCall(PhoneAccountHandle, Bundle)}, specifying
Tyler Gunn727c6bd2017-04-11 09:51:40 -0700107 * {@link TelecomManager#EXTRA_IS_HANDOVER}. Telecom will match the phone numbers of the
108 * handover call on the other device with ongoing calls for {@link ConnectionService}s which
109 * support {@link PhoneAccount#EXTRA_SUPPORTS_HANDOVER_FROM}.
Tyler Gunn8bf76572017-04-06 15:30:08 -0700110 * @hide
111 */
112 public static final String EXTRA_IS_HANDOVER = TelecomManager.EXTRA_IS_HANDOVER;
113
Ihab Awad542e0ea2014-05-16 10:22:16 -0700114 // Flag controlling whether PII is emitted into the logs
Ihab Awad60ac30b2014-05-20 22:32:12 -0700115 private static final boolean PII_DEBUG = Log.isLoggable(android.util.Log.DEBUG);
Ihab Awad542e0ea2014-05-16 10:22:16 -0700116
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700117 // Session Definitions
118 private static final String SESSION_HANDLER = "H.";
119 private static final String SESSION_ADD_CS_ADAPTER = "CS.aCSA";
120 private static final String SESSION_REMOVE_CS_ADAPTER = "CS.rCSA";
121 private static final String SESSION_CREATE_CONN = "CS.crCo";
Tyler Gunn041a1fe2017-05-12 10:04:49 -0700122 private static final String SESSION_CREATE_CONN_COMPLETE = "CS.crCoC";
Tyler Gunn44e01912017-01-31 10:49:05 -0800123 private static final String SESSION_CREATE_CONN_FAILED = "CS.crCoF";
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700124 private static final String SESSION_ABORT = "CS.ab";
125 private static final String SESSION_ANSWER = "CS.an";
126 private static final String SESSION_ANSWER_VIDEO = "CS.anV";
Pooja Jaind34698d2017-12-28 14:15:31 +0530127 private static final String SESSION_DEFLECT = "CS.def";
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700128 private static final String SESSION_REJECT = "CS.r";
129 private static final String SESSION_REJECT_MESSAGE = "CS.rWM";
130 private static final String SESSION_SILENCE = "CS.s";
131 private static final String SESSION_DISCONNECT = "CS.d";
132 private static final String SESSION_HOLD = "CS.h";
133 private static final String SESSION_UNHOLD = "CS.u";
134 private static final String SESSION_CALL_AUDIO_SC = "CS.cASC";
135 private static final String SESSION_PLAY_DTMF = "CS.pDT";
136 private static final String SESSION_STOP_DTMF = "CS.sDT";
137 private static final String SESSION_CONFERENCE = "CS.c";
138 private static final String SESSION_SPLIT_CONFERENCE = "CS.sFC";
139 private static final String SESSION_MERGE_CONFERENCE = "CS.mC";
140 private static final String SESSION_SWAP_CONFERENCE = "CS.sC";
141 private static final String SESSION_POST_DIAL_CONT = "CS.oPDC";
142 private static final String SESSION_PULL_EXTERNAL_CALL = "CS.pEC";
143 private static final String SESSION_SEND_CALL_EVENT = "CS.sCE";
Tyler Gunn79bc1ec2018-01-22 15:17:54 -0800144 private static final String SESSION_HANDOVER_COMPLETE = "CS.hC";
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700145 private static final String SESSION_EXTRAS_CHANGED = "CS.oEC";
Hall Liub64ac4c2017-02-06 10:49:48 -0800146 private static final String SESSION_START_RTT = "CS.+RTT";
Hall Liua549fed2018-02-09 16:40:03 -0800147 private static final String SESSION_UPDATE_RTT_PIPES = "CS.uRTT";
Hall Liub64ac4c2017-02-06 10:49:48 -0800148 private static final String SESSION_STOP_RTT = "CS.-RTT";
149 private static final String SESSION_RTT_UPGRADE_RESPONSE = "CS.rTRUR";
Pengquan Meng731c1a32017-11-21 18:01:13 -0800150 private static final String SESSION_CONNECTION_SERVICE_FOCUS_LOST = "CS.cSFL";
151 private static final String SESSION_CONNECTION_SERVICE_FOCUS_GAINED = "CS.cSFG";
Sanket Padawe4cc8ed52017-12-04 16:22:20 -0800152 private static final String SESSION_HANDOVER_FAILED = "CS.haF";
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700153
Ihab Awad8aecfed2014-08-08 17:06:11 -0700154 private static final int MSG_ADD_CONNECTION_SERVICE_ADAPTER = 1;
Sailesh Nepalc5b01572014-07-14 16:29:44 -0700155 private static final int MSG_CREATE_CONNECTION = 2;
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700156 private static final int MSG_ABORT = 3;
Sailesh Nepalc5b01572014-07-14 16:29:44 -0700157 private static final int MSG_ANSWER = 4;
158 private static final int MSG_REJECT = 5;
159 private static final int MSG_DISCONNECT = 6;
160 private static final int MSG_HOLD = 7;
161 private static final int MSG_UNHOLD = 8;
Yorke Lee4af59352015-05-13 14:14:54 -0700162 private static final int MSG_ON_CALL_AUDIO_STATE_CHANGED = 9;
Sailesh Nepalc5b01572014-07-14 16:29:44 -0700163 private static final int MSG_PLAY_DTMF_TONE = 10;
164 private static final int MSG_STOP_DTMF_TONE = 11;
165 private static final int MSG_CONFERENCE = 12;
166 private static final int MSG_SPLIT_FROM_CONFERENCE = 13;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700167 private static final int MSG_ON_POST_DIAL_CONTINUE = 14;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700168 private static final int MSG_REMOVE_CONNECTION_SERVICE_ADAPTER = 16;
Tyler Gunnbe74de02014-08-29 14:51:48 -0700169 private static final int MSG_ANSWER_VIDEO = 17;
Santos Cordona4868042014-09-04 17:39:22 -0700170 private static final int MSG_MERGE_CONFERENCE = 18;
171 private static final int MSG_SWAP_CONFERENCE = 19;
Bryce Lee81901682015-08-28 16:38:02 -0700172 private static final int MSG_REJECT_WITH_MESSAGE = 20;
Bryce Leecac50772015-11-17 15:13:29 -0800173 private static final int MSG_SILENCE = 21;
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700174 private static final int MSG_PULL_EXTERNAL_CALL = 22;
175 private static final int MSG_SEND_CALL_EVENT = 23;
Tyler Gunndee56a82016-03-23 16:06:34 -0700176 private static final int MSG_ON_EXTRAS_CHANGED = 24;
Tyler Gunn44e01912017-01-31 10:49:05 -0800177 private static final int MSG_CREATE_CONNECTION_FAILED = 25;
Hall Liub64ac4c2017-02-06 10:49:48 -0800178 private static final int MSG_ON_START_RTT = 26;
179 private static final int MSG_ON_STOP_RTT = 27;
180 private static final int MSG_RTT_UPGRADE_RESPONSE = 28;
Tyler Gunn041a1fe2017-05-12 10:04:49 -0700181 private static final int MSG_CREATE_CONNECTION_COMPLETE = 29;
Pengquan Meng731c1a32017-11-21 18:01:13 -0800182 private static final int MSG_CONNECTION_SERVICE_FOCUS_LOST = 30;
183 private static final int MSG_CONNECTION_SERVICE_FOCUS_GAINED = 31;
Sanket Padawe4cc8ed52017-12-04 16:22:20 -0800184 private static final int MSG_HANDOVER_FAILED = 32;
Tyler Gunn79bc1ec2018-01-22 15:17:54 -0800185 private static final int MSG_HANDOVER_COMPLETE = 33;
Pooja Jaind34698d2017-12-28 14:15:31 +0530186 private static final int MSG_DEFLECT = 34;
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700187
Sailesh Nepalcf7020b2014-08-20 10:07:19 -0700188 private static Connection sNullConnection;
189
mike dooley95e80702014-09-18 14:07:52 -0700190 private final Map<String, Connection> mConnectionById = new ConcurrentHashMap<>();
191 private final Map<Connection, String> mIdByConnection = new ConcurrentHashMap<>();
192 private final Map<String, Conference> mConferenceById = new ConcurrentHashMap<>();
193 private final Map<Conference, String> mIdByConference = new ConcurrentHashMap<>();
Ihab Awadb8e85c72014-08-23 20:34:57 -0700194 private final RemoteConnectionManager mRemoteConnectionManager =
195 new RemoteConnectionManager(this);
Ihab Awad5d0410f2014-07-30 10:07:40 -0700196 private final List<Runnable> mPreInitializationConnectionRequests = new ArrayList<>();
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700197 private final ConnectionServiceAdapter mAdapter = new ConnectionServiceAdapter();
Ihab Awad542e0ea2014-05-16 10:22:16 -0700198
Santos Cordon823fd3c2014-08-07 18:35:18 -0700199 private boolean mAreAccountsInitialized = false;
Santos Cordon0159ac02014-08-21 14:28:11 -0700200 private Conference sNullConference;
Tyler Gunnf0500bd2015-09-01 10:59:48 -0700201 private Object mIdSyncRoot = new Object();
202 private int mId = 0;
Santos Cordon823fd3c2014-08-07 18:35:18 -0700203
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700204 private final IBinder mBinder = new IConnectionService.Stub() {
205 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700206 public void addConnectionServiceAdapter(IConnectionServiceAdapter adapter,
207 Session.Info sessionInfo) {
208 Log.startSession(sessionInfo, SESSION_ADD_CS_ADAPTER);
209 try {
210 SomeArgs args = SomeArgs.obtain();
211 args.arg1 = adapter;
212 args.arg2 = Log.createSubsession();
213 mHandler.obtainMessage(MSG_ADD_CONNECTION_SERVICE_ADAPTER, args).sendToTarget();
214 } finally {
215 Log.endSession();
216 }
Ihab Awad8aecfed2014-08-08 17:06:11 -0700217 }
218
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700219 public void removeConnectionServiceAdapter(IConnectionServiceAdapter adapter,
220 Session.Info sessionInfo) {
221 Log.startSession(sessionInfo, SESSION_REMOVE_CS_ADAPTER);
222 try {
223 SomeArgs args = SomeArgs.obtain();
224 args.arg1 = adapter;
225 args.arg2 = Log.createSubsession();
226 mHandler.obtainMessage(MSG_REMOVE_CONNECTION_SERVICE_ADAPTER, args).sendToTarget();
227 } finally {
228 Log.endSession();
229 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700230 }
231
232 @Override
Ihab Awadf8b69882014-07-25 15:14:01 -0700233 public void createConnection(
234 PhoneAccountHandle connectionManagerPhoneAccount,
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700235 String id,
Ihab Awadf8b69882014-07-25 15:14:01 -0700236 ConnectionRequest request,
Yorke Leec3cf9822014-10-02 09:38:39 -0700237 boolean isIncoming,
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700238 boolean isUnknown,
239 Session.Info sessionInfo) {
240 Log.startSession(sessionInfo, SESSION_CREATE_CONN);
241 try {
242 SomeArgs args = SomeArgs.obtain();
243 args.arg1 = connectionManagerPhoneAccount;
244 args.arg2 = id;
245 args.arg3 = request;
246 args.arg4 = Log.createSubsession();
247 args.argi1 = isIncoming ? 1 : 0;
248 args.argi2 = isUnknown ? 1 : 0;
249 mHandler.obtainMessage(MSG_CREATE_CONNECTION, args).sendToTarget();
250 } finally {
251 Log.endSession();
252 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700253 }
254
255 @Override
Tyler Gunn041a1fe2017-05-12 10:04:49 -0700256 public void createConnectionComplete(String id, Session.Info sessionInfo) {
257 Log.startSession(sessionInfo, SESSION_CREATE_CONN_COMPLETE);
258 try {
259 SomeArgs args = SomeArgs.obtain();
260 args.arg1 = id;
261 args.arg2 = Log.createSubsession();
262 mHandler.obtainMessage(MSG_CREATE_CONNECTION_COMPLETE, args).sendToTarget();
263 } finally {
264 Log.endSession();
265 }
266 }
267
268 @Override
Tyler Gunn44e01912017-01-31 10:49:05 -0800269 public void createConnectionFailed(
Tyler Gunn159f35c2017-03-02 09:28:37 -0800270 PhoneAccountHandle connectionManagerPhoneAccount,
Tyler Gunn44e01912017-01-31 10:49:05 -0800271 String callId,
272 ConnectionRequest request,
273 boolean isIncoming,
274 Session.Info sessionInfo) {
275 Log.startSession(sessionInfo, SESSION_CREATE_CONN_FAILED);
276 try {
277 SomeArgs args = SomeArgs.obtain();
278 args.arg1 = callId;
279 args.arg2 = request;
280 args.arg3 = Log.createSubsession();
Tyler Gunn159f35c2017-03-02 09:28:37 -0800281 args.arg4 = connectionManagerPhoneAccount;
Tyler Gunn44e01912017-01-31 10:49:05 -0800282 args.argi1 = isIncoming ? 1 : 0;
283 mHandler.obtainMessage(MSG_CREATE_CONNECTION_FAILED, args).sendToTarget();
284 } finally {
285 Log.endSession();
286 }
287 }
288
289 @Override
Sanket Padawe4cc8ed52017-12-04 16:22:20 -0800290 public void handoverFailed(String callId, ConnectionRequest request, int reason,
291 Session.Info sessionInfo) {
292 Log.startSession(sessionInfo, SESSION_HANDOVER_FAILED);
293 try {
294 SomeArgs args = SomeArgs.obtain();
295 args.arg1 = callId;
296 args.arg2 = request;
297 args.arg3 = Log.createSubsession();
298 args.arg4 = reason;
299 mHandler.obtainMessage(MSG_HANDOVER_FAILED, args).sendToTarget();
300 } finally {
301 Log.endSession();
302 }
303 }
304
305 @Override
Tyler Gunn79bc1ec2018-01-22 15:17:54 -0800306 public void handoverComplete(String callId, Session.Info sessionInfo) {
307 Log.startSession(sessionInfo, SESSION_HANDOVER_COMPLETE);
308 try {
309 SomeArgs args = SomeArgs.obtain();
310 args.arg1 = callId;
311 args.arg2 = Log.createSubsession();
312 mHandler.obtainMessage(MSG_HANDOVER_COMPLETE, args).sendToTarget();
313 } finally {
314 Log.endSession();
315 }
316 }
317
318 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700319 public void abort(String callId, Session.Info sessionInfo) {
320 Log.startSession(sessionInfo, SESSION_ABORT);
321 try {
322 SomeArgs args = SomeArgs.obtain();
323 args.arg1 = callId;
324 args.arg2 = Log.createSubsession();
325 mHandler.obtainMessage(MSG_ABORT, args).sendToTarget();
326 } finally {
327 Log.endSession();
328 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700329 }
330
331 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700332 public void answerVideo(String callId, int videoState, Session.Info sessionInfo) {
333 Log.startSession(sessionInfo, SESSION_ANSWER_VIDEO);
334 try {
335 SomeArgs args = SomeArgs.obtain();
336 args.arg1 = callId;
337 args.arg2 = Log.createSubsession();
338 args.argi1 = videoState;
339 mHandler.obtainMessage(MSG_ANSWER_VIDEO, args).sendToTarget();
340 } finally {
341 Log.endSession();
342 }
Tyler Gunnbe74de02014-08-29 14:51:48 -0700343 }
344
345 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700346 public void answer(String callId, Session.Info sessionInfo) {
347 Log.startSession(sessionInfo, SESSION_ANSWER);
348 try {
349 SomeArgs args = SomeArgs.obtain();
350 args.arg1 = callId;
351 args.arg2 = Log.createSubsession();
352 mHandler.obtainMessage(MSG_ANSWER, args).sendToTarget();
353 } finally {
354 Log.endSession();
355 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700356 }
357
358 @Override
Pooja Jaind34698d2017-12-28 14:15:31 +0530359 public void deflect(String callId, Uri address, Session.Info sessionInfo) {
360 Log.startSession(sessionInfo, SESSION_DEFLECT);
361 try {
362 SomeArgs args = SomeArgs.obtain();
363 args.arg1 = callId;
364 args.arg2 = address;
365 args.arg3 = Log.createSubsession();
366 mHandler.obtainMessage(MSG_DEFLECT, args).sendToTarget();
367 } finally {
368 Log.endSession();
369 }
370 }
371
372 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700373 public void reject(String callId, Session.Info sessionInfo) {
374 Log.startSession(sessionInfo, SESSION_REJECT);
375 try {
376 SomeArgs args = SomeArgs.obtain();
377 args.arg1 = callId;
378 args.arg2 = Log.createSubsession();
379 mHandler.obtainMessage(MSG_REJECT, args).sendToTarget();
380 } finally {
381 Log.endSession();
382 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700383 }
384
385 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700386 public void rejectWithMessage(String callId, String message, Session.Info sessionInfo) {
387 Log.startSession(sessionInfo, SESSION_REJECT_MESSAGE);
388 try {
389 SomeArgs args = SomeArgs.obtain();
390 args.arg1 = callId;
391 args.arg2 = message;
392 args.arg3 = Log.createSubsession();
393 mHandler.obtainMessage(MSG_REJECT_WITH_MESSAGE, args).sendToTarget();
394 } finally {
395 Log.endSession();
396 }
Bryce Lee81901682015-08-28 16:38:02 -0700397 }
398
399 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700400 public void silence(String callId, Session.Info sessionInfo) {
401 Log.startSession(sessionInfo, SESSION_SILENCE);
402 try {
403 SomeArgs args = SomeArgs.obtain();
404 args.arg1 = callId;
405 args.arg2 = Log.createSubsession();
406 mHandler.obtainMessage(MSG_SILENCE, args).sendToTarget();
407 } finally {
408 Log.endSession();
409 }
Bryce Leecac50772015-11-17 15:13:29 -0800410 }
411
412 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700413 public void disconnect(String callId, Session.Info sessionInfo) {
414 Log.startSession(sessionInfo, SESSION_DISCONNECT);
415 try {
416 SomeArgs args = SomeArgs.obtain();
417 args.arg1 = callId;
418 args.arg2 = Log.createSubsession();
419 mHandler.obtainMessage(MSG_DISCONNECT, args).sendToTarget();
420 } finally {
421 Log.endSession();
422 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700423 }
424
425 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700426 public void hold(String callId, Session.Info sessionInfo) {
427 Log.startSession(sessionInfo, SESSION_HOLD);
428 try {
429 SomeArgs args = SomeArgs.obtain();
430 args.arg1 = callId;
431 args.arg2 = Log.createSubsession();
432 mHandler.obtainMessage(MSG_HOLD, args).sendToTarget();
433 } finally {
434 Log.endSession();
435 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700436 }
437
438 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700439 public void unhold(String callId, Session.Info sessionInfo) {
440 Log.startSession(sessionInfo, SESSION_UNHOLD);
441 try {
442 SomeArgs args = SomeArgs.obtain();
443 args.arg1 = callId;
444 args.arg2 = Log.createSubsession();
445 mHandler.obtainMessage(MSG_UNHOLD, args).sendToTarget();
446 } finally {
447 Log.endSession();
448 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700449 }
450
451 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700452 public void onCallAudioStateChanged(String callId, CallAudioState callAudioState,
453 Session.Info sessionInfo) {
454 Log.startSession(sessionInfo, SESSION_CALL_AUDIO_SC);
455 try {
456 SomeArgs args = SomeArgs.obtain();
457 args.arg1 = callId;
458 args.arg2 = callAudioState;
459 args.arg3 = Log.createSubsession();
460 mHandler.obtainMessage(MSG_ON_CALL_AUDIO_STATE_CHANGED, args).sendToTarget();
461 } finally {
462 Log.endSession();
463 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700464 }
465
466 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700467 public void playDtmfTone(String callId, char digit, Session.Info sessionInfo) {
468 Log.startSession(sessionInfo, SESSION_PLAY_DTMF);
469 try {
470 SomeArgs args = SomeArgs.obtain();
471 args.arg1 = digit;
472 args.arg2 = callId;
473 args.arg3 = Log.createSubsession();
474 mHandler.obtainMessage(MSG_PLAY_DTMF_TONE, args).sendToTarget();
475 } finally {
476 Log.endSession();
477 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700478 }
479
480 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700481 public void stopDtmfTone(String callId, Session.Info sessionInfo) {
482 Log.startSession(sessionInfo, SESSION_STOP_DTMF);
483 try {
484 SomeArgs args = SomeArgs.obtain();
485 args.arg1 = callId;
486 args.arg2 = Log.createSubsession();
487 mHandler.obtainMessage(MSG_STOP_DTMF_TONE, args).sendToTarget();
488 } finally {
489 Log.endSession();
490 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700491 }
492
493 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700494 public void conference(String callId1, String callId2, Session.Info sessionInfo) {
495 Log.startSession(sessionInfo, SESSION_CONFERENCE);
496 try {
497 SomeArgs args = SomeArgs.obtain();
498 args.arg1 = callId1;
499 args.arg2 = callId2;
500 args.arg3 = Log.createSubsession();
501 mHandler.obtainMessage(MSG_CONFERENCE, args).sendToTarget();
502 } finally {
503 Log.endSession();
504 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700505 }
506
507 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700508 public void splitFromConference(String callId, Session.Info sessionInfo) {
509 Log.startSession(sessionInfo, SESSION_SPLIT_CONFERENCE);
510 try {
511 SomeArgs args = SomeArgs.obtain();
512 args.arg1 = callId;
513 args.arg2 = Log.createSubsession();
514 mHandler.obtainMessage(MSG_SPLIT_FROM_CONFERENCE, args).sendToTarget();
515 } finally {
516 Log.endSession();
517 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700518 }
519
520 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700521 public void mergeConference(String callId, Session.Info sessionInfo) {
522 Log.startSession(sessionInfo, SESSION_MERGE_CONFERENCE);
523 try {
524 SomeArgs args = SomeArgs.obtain();
525 args.arg1 = callId;
526 args.arg2 = Log.createSubsession();
527 mHandler.obtainMessage(MSG_MERGE_CONFERENCE, args).sendToTarget();
528 } finally {
529 Log.endSession();
530 }
Santos Cordona4868042014-09-04 17:39:22 -0700531 }
532
533 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700534 public void swapConference(String callId, Session.Info sessionInfo) {
535 Log.startSession(sessionInfo, SESSION_SWAP_CONFERENCE);
536 try {
537 SomeArgs args = SomeArgs.obtain();
538 args.arg1 = callId;
539 args.arg2 = Log.createSubsession();
540 mHandler.obtainMessage(MSG_SWAP_CONFERENCE, args).sendToTarget();
541 } finally {
542 Log.endSession();
543 }
Santos Cordona4868042014-09-04 17:39:22 -0700544 }
545
546 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700547 public void onPostDialContinue(String callId, boolean proceed, Session.Info sessionInfo) {
548 Log.startSession(sessionInfo, SESSION_POST_DIAL_CONT);
549 try {
550 SomeArgs args = SomeArgs.obtain();
551 args.arg1 = callId;
552 args.arg2 = Log.createSubsession();
553 args.argi1 = proceed ? 1 : 0;
554 mHandler.obtainMessage(MSG_ON_POST_DIAL_CONTINUE, args).sendToTarget();
555 } finally {
556 Log.endSession();
557 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700558 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700559
560 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700561 public void pullExternalCall(String callId, Session.Info sessionInfo) {
562 Log.startSession(sessionInfo, SESSION_PULL_EXTERNAL_CALL);
563 try {
564 SomeArgs args = SomeArgs.obtain();
565 args.arg1 = callId;
566 args.arg2 = Log.createSubsession();
567 mHandler.obtainMessage(MSG_PULL_EXTERNAL_CALL, args).sendToTarget();
568 } finally {
569 Log.endSession();
570 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700571 }
572
573 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700574 public void sendCallEvent(String callId, String event, Bundle extras,
575 Session.Info sessionInfo) {
576 Log.startSession(sessionInfo, SESSION_SEND_CALL_EVENT);
577 try {
578 SomeArgs args = SomeArgs.obtain();
579 args.arg1 = callId;
580 args.arg2 = event;
581 args.arg3 = extras;
582 args.arg4 = Log.createSubsession();
583 mHandler.obtainMessage(MSG_SEND_CALL_EVENT, args).sendToTarget();
584 } finally {
585 Log.endSession();
586 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700587 }
Tyler Gunndee56a82016-03-23 16:06:34 -0700588
589 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700590 public void onExtrasChanged(String callId, Bundle extras, Session.Info sessionInfo) {
591 Log.startSession(sessionInfo, SESSION_EXTRAS_CHANGED);
592 try {
593 SomeArgs args = SomeArgs.obtain();
594 args.arg1 = callId;
595 args.arg2 = extras;
596 args.arg3 = Log.createSubsession();
597 mHandler.obtainMessage(MSG_ON_EXTRAS_CHANGED, args).sendToTarget();
598 } finally {
599 Log.endSession();
600 }
Tyler Gunndee56a82016-03-23 16:06:34 -0700601 }
Hall Liub64ac4c2017-02-06 10:49:48 -0800602
603 @Override
604 public void startRtt(String callId, ParcelFileDescriptor fromInCall,
605 ParcelFileDescriptor toInCall, Session.Info sessionInfo) throws RemoteException {
606 Log.startSession(sessionInfo, SESSION_START_RTT);
607 try {
608 SomeArgs args = SomeArgs.obtain();
609 args.arg1 = callId;
610 args.arg2 = new Connection.RttTextStream(toInCall, fromInCall);
611 args.arg3 = Log.createSubsession();
612 mHandler.obtainMessage(MSG_ON_START_RTT, args).sendToTarget();
613 } finally {
614 Log.endSession();
615 }
616 }
617
618 @Override
619 public void stopRtt(String callId, Session.Info sessionInfo) throws RemoteException {
620 Log.startSession(sessionInfo, SESSION_STOP_RTT);
621 try {
622 SomeArgs args = SomeArgs.obtain();
623 args.arg1 = callId;
624 args.arg2 = Log.createSubsession();
625 mHandler.obtainMessage(MSG_ON_STOP_RTT, args).sendToTarget();
626 } finally {
627 Log.endSession();
628 }
629 }
630
631 @Override
632 public void respondToRttUpgradeRequest(String callId, ParcelFileDescriptor fromInCall,
633 ParcelFileDescriptor toInCall, Session.Info sessionInfo) throws RemoteException {
634 Log.startSession(sessionInfo, SESSION_RTT_UPGRADE_RESPONSE);
635 try {
636 SomeArgs args = SomeArgs.obtain();
637 args.arg1 = callId;
638 if (toInCall == null || fromInCall == null) {
639 args.arg2 = null;
640 } else {
641 args.arg2 = new Connection.RttTextStream(toInCall, fromInCall);
642 }
643 args.arg3 = Log.createSubsession();
644 mHandler.obtainMessage(MSG_RTT_UPGRADE_RESPONSE, args).sendToTarget();
645 } finally {
646 Log.endSession();
647 }
648 }
Pengquan Meng731c1a32017-11-21 18:01:13 -0800649
650 @Override
651 public void connectionServiceFocusLost(Session.Info sessionInfo) throws RemoteException {
652 Log.startSession(sessionInfo, SESSION_CONNECTION_SERVICE_FOCUS_LOST);
653 try {
654 mHandler.obtainMessage(MSG_CONNECTION_SERVICE_FOCUS_LOST).sendToTarget();
655 } finally {
656 Log.endSession();
657 }
658 }
659
660 @Override
661 public void connectionServiceFocusGained(Session.Info sessionInfo) throws RemoteException {
662 Log.startSession(sessionInfo, SESSION_CONNECTION_SERVICE_FOCUS_GAINED);
663 try {
664 mHandler.obtainMessage(MSG_CONNECTION_SERVICE_FOCUS_GAINED).sendToTarget();
665 } finally {
666 Log.endSession();
667 }
668 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700669 };
670
671 private final Handler mHandler = new Handler(Looper.getMainLooper()) {
672 @Override
673 public void handleMessage(Message msg) {
674 switch (msg.what) {
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700675 case MSG_ADD_CONNECTION_SERVICE_ADAPTER: {
676 SomeArgs args = (SomeArgs) msg.obj;
677 try {
678 IConnectionServiceAdapter adapter = (IConnectionServiceAdapter) args.arg1;
679 Log.continueSession((Session) args.arg2,
680 SESSION_HANDLER + SESSION_ADD_CS_ADAPTER);
681 mAdapter.addAdapter(adapter);
682 onAdapterAttached();
683 } finally {
684 args.recycle();
685 Log.endSession();
686 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700687 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700688 }
689 case MSG_REMOVE_CONNECTION_SERVICE_ADAPTER: {
690 SomeArgs args = (SomeArgs) msg.obj;
691 try {
692 Log.continueSession((Session) args.arg2,
693 SESSION_HANDLER + SESSION_REMOVE_CS_ADAPTER);
694 mAdapter.removeAdapter((IConnectionServiceAdapter) args.arg1);
695 } finally {
696 args.recycle();
697 Log.endSession();
698 }
Ihab Awad8aecfed2014-08-08 17:06:11 -0700699 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700700 }
Ihab Awadf8b69882014-07-25 15:14:01 -0700701 case MSG_CREATE_CONNECTION: {
702 SomeArgs args = (SomeArgs) msg.obj;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700703 Log.continueSession((Session) args.arg4, SESSION_HANDLER + SESSION_CREATE_CONN);
Ihab Awadf8b69882014-07-25 15:14:01 -0700704 try {
Ihab Awad5d0410f2014-07-30 10:07:40 -0700705 final PhoneAccountHandle connectionManagerPhoneAccount =
Ihab Awadf8b69882014-07-25 15:14:01 -0700706 (PhoneAccountHandle) args.arg1;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700707 final String id = (String) args.arg2;
708 final ConnectionRequest request = (ConnectionRequest) args.arg3;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700709 final boolean isIncoming = args.argi1 == 1;
Yorke Leec3cf9822014-10-02 09:38:39 -0700710 final boolean isUnknown = args.argi2 == 1;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700711 if (!mAreAccountsInitialized) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700712 Log.d(this, "Enqueueing pre-init request %s", id);
Brad Ebinger0c3541b2016-11-01 14:11:38 -0700713 mPreInitializationConnectionRequests.add(
714 new android.telecom.Logging.Runnable(
715 SESSION_HANDLER + SESSION_CREATE_CONN + ".pICR",
716 null /*lock*/) {
Ihab Awad5d0410f2014-07-30 10:07:40 -0700717 @Override
Brad Ebinger0c3541b2016-11-01 14:11:38 -0700718 public void loggedRun() {
Ihab Awad5d0410f2014-07-30 10:07:40 -0700719 createConnection(
720 connectionManagerPhoneAccount,
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700721 id,
Ihab Awad5d0410f2014-07-30 10:07:40 -0700722 request,
Yorke Leec3cf9822014-10-02 09:38:39 -0700723 isIncoming,
724 isUnknown);
Ihab Awad5d0410f2014-07-30 10:07:40 -0700725 }
Brad Ebinger0c3541b2016-11-01 14:11:38 -0700726 }.prepare());
Ihab Awad5d0410f2014-07-30 10:07:40 -0700727 } else {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700728 createConnection(
729 connectionManagerPhoneAccount,
730 id,
731 request,
Yorke Leec3cf9822014-10-02 09:38:39 -0700732 isIncoming,
733 isUnknown);
Ihab Awad5d0410f2014-07-30 10:07:40 -0700734 }
Ihab Awadf8b69882014-07-25 15:14:01 -0700735 } finally {
736 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700737 Log.endSession();
Ihab Awadf8b69882014-07-25 15:14:01 -0700738 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700739 break;
Ihab Awadf8b69882014-07-25 15:14:01 -0700740 }
Tyler Gunn041a1fe2017-05-12 10:04:49 -0700741 case MSG_CREATE_CONNECTION_COMPLETE: {
742 SomeArgs args = (SomeArgs) msg.obj;
743 Log.continueSession((Session) args.arg2,
744 SESSION_HANDLER + SESSION_CREATE_CONN_COMPLETE);
745 try {
746 final String id = (String) args.arg1;
747 if (!mAreAccountsInitialized) {
748 Log.d(this, "Enqueueing pre-init request %s", id);
749 mPreInitializationConnectionRequests.add(
750 new android.telecom.Logging.Runnable(
751 SESSION_HANDLER + SESSION_CREATE_CONN_COMPLETE
752 + ".pICR",
753 null /*lock*/) {
754 @Override
755 public void loggedRun() {
756 notifyCreateConnectionComplete(id);
757 }
758 }.prepare());
759 } else {
760 notifyCreateConnectionComplete(id);
761 }
762 } finally {
763 args.recycle();
764 Log.endSession();
765 }
766 break;
767 }
Tyler Gunn44e01912017-01-31 10:49:05 -0800768 case MSG_CREATE_CONNECTION_FAILED: {
769 SomeArgs args = (SomeArgs) msg.obj;
770 Log.continueSession((Session) args.arg3, SESSION_HANDLER +
771 SESSION_CREATE_CONN_FAILED);
772 try {
773 final String id = (String) args.arg1;
774 final ConnectionRequest request = (ConnectionRequest) args.arg2;
775 final boolean isIncoming = args.argi1 == 1;
Tyler Gunn159f35c2017-03-02 09:28:37 -0800776 final PhoneAccountHandle connectionMgrPhoneAccount =
777 (PhoneAccountHandle) args.arg4;
Tyler Gunn44e01912017-01-31 10:49:05 -0800778 if (!mAreAccountsInitialized) {
779 Log.d(this, "Enqueueing pre-init request %s", id);
780 mPreInitializationConnectionRequests.add(
781 new android.telecom.Logging.Runnable(
782 SESSION_HANDLER + SESSION_CREATE_CONN_FAILED + ".pICR",
783 null /*lock*/) {
784 @Override
785 public void loggedRun() {
Tyler Gunn159f35c2017-03-02 09:28:37 -0800786 createConnectionFailed(connectionMgrPhoneAccount, id,
787 request, isIncoming);
Tyler Gunn44e01912017-01-31 10:49:05 -0800788 }
789 }.prepare());
790 } else {
791 Log.i(this, "createConnectionFailed %s", id);
Tyler Gunn159f35c2017-03-02 09:28:37 -0800792 createConnectionFailed(connectionMgrPhoneAccount, id, request,
793 isIncoming);
Tyler Gunn44e01912017-01-31 10:49:05 -0800794 }
795 } finally {
796 args.recycle();
797 Log.endSession();
798 }
799 break;
800 }
Sanket Padawe4cc8ed52017-12-04 16:22:20 -0800801 case MSG_HANDOVER_FAILED: {
802 SomeArgs args = (SomeArgs) msg.obj;
803 Log.continueSession((Session) args.arg3, SESSION_HANDLER +
804 SESSION_HANDOVER_FAILED);
805 try {
806 final String id = (String) args.arg1;
807 final ConnectionRequest request = (ConnectionRequest) args.arg2;
808 final int reason = (int) args.arg4;
809 if (!mAreAccountsInitialized) {
810 Log.d(this, "Enqueueing pre-init request %s", id);
811 mPreInitializationConnectionRequests.add(
812 new android.telecom.Logging.Runnable(
813 SESSION_HANDLER
814 + SESSION_HANDOVER_FAILED + ".pICR",
815 null /*lock*/) {
816 @Override
817 public void loggedRun() {
818 handoverFailed(id, request, reason);
819 }
820 }.prepare());
821 } else {
822 Log.i(this, "createConnectionFailed %s", id);
823 handoverFailed(id, request, reason);
824 }
825 } finally {
826 args.recycle();
827 Log.endSession();
828 }
829 break;
830 }
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700831 case MSG_ABORT: {
832 SomeArgs args = (SomeArgs) msg.obj;
833 Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_ABORT);
834 try {
835 abort((String) args.arg1);
836 } finally {
837 args.recycle();
838 Log.endSession();
839 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700840 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700841 }
842 case MSG_ANSWER: {
843 SomeArgs args = (SomeArgs) msg.obj;
844 Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_ANSWER);
845 try {
846 answer((String) args.arg1);
847 } finally {
848 args.recycle();
849 Log.endSession();
850 }
Tyler Gunnbe74de02014-08-29 14:51:48 -0700851 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700852 }
Tyler Gunnbe74de02014-08-29 14:51:48 -0700853 case MSG_ANSWER_VIDEO: {
Andrew Lee8da4c3c2014-07-16 10:11:42 -0700854 SomeArgs args = (SomeArgs) msg.obj;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700855 Log.continueSession((Session) args.arg2,
856 SESSION_HANDLER + SESSION_ANSWER_VIDEO);
Andrew Lee8da4c3c2014-07-16 10:11:42 -0700857 try {
858 String callId = (String) args.arg1;
Evan Charltonbf11f982014-07-20 22:06:28 -0700859 int videoState = args.argi1;
Tyler Gunnbe74de02014-08-29 14:51:48 -0700860 answerVideo(callId, videoState);
Andrew Lee8da4c3c2014-07-16 10:11:42 -0700861 } finally {
862 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700863 Log.endSession();
Andrew Lee8da4c3c2014-07-16 10:11:42 -0700864 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700865 break;
Andrew Lee8da4c3c2014-07-16 10:11:42 -0700866 }
Pooja Jaind34698d2017-12-28 14:15:31 +0530867 case MSG_DEFLECT: {
868 SomeArgs args = (SomeArgs) msg.obj;
869 Log.continueSession((Session) args.arg3, SESSION_HANDLER + SESSION_DEFLECT);
870 try {
871 deflect((String) args.arg1, (Uri) args.arg2);
872 } finally {
873 args.recycle();
874 Log.endSession();
875 }
876 break;
877 }
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700878 case MSG_REJECT: {
879 SomeArgs args = (SomeArgs) msg.obj;
880 Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_REJECT);
881 try {
882 reject((String) args.arg1);
883 } finally {
884 args.recycle();
885 Log.endSession();
886 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700887 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700888 }
Bryce Lee81901682015-08-28 16:38:02 -0700889 case MSG_REJECT_WITH_MESSAGE: {
890 SomeArgs args = (SomeArgs) msg.obj;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700891 Log.continueSession((Session) args.arg3,
892 SESSION_HANDLER + SESSION_REJECT_MESSAGE);
Bryce Lee81901682015-08-28 16:38:02 -0700893 try {
894 reject((String) args.arg1, (String) args.arg2);
895 } finally {
896 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700897 Log.endSession();
Bryce Lee81901682015-08-28 16:38:02 -0700898 }
899 break;
900 }
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700901 case MSG_DISCONNECT: {
902 SomeArgs args = (SomeArgs) msg.obj;
903 Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_DISCONNECT);
904 try {
905 disconnect((String) args.arg1);
906 } finally {
907 args.recycle();
908 Log.endSession();
909 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700910 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700911 }
912 case MSG_SILENCE: {
913 SomeArgs args = (SomeArgs) msg.obj;
914 Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_SILENCE);
915 try {
916 silence((String) args.arg1);
917 } finally {
918 args.recycle();
919 Log.endSession();
920 }
Bryce Leecac50772015-11-17 15:13:29 -0800921 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700922 }
923 case MSG_HOLD: {
924 SomeArgs args = (SomeArgs) msg.obj;
925 Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_REJECT);
926 try {
927 hold((String) args.arg1);
928 } finally {
929 args.recycle();
930 Log.endSession();
931 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700932 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700933 }
934 case MSG_UNHOLD: {
935 SomeArgs args = (SomeArgs) msg.obj;
936 Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_UNHOLD);
937 try {
938 unhold((String) args.arg1);
939 } finally {
940 args.recycle();
941 Log.endSession();
942 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700943 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700944 }
Yorke Lee4af59352015-05-13 14:14:54 -0700945 case MSG_ON_CALL_AUDIO_STATE_CHANGED: {
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700946 SomeArgs args = (SomeArgs) msg.obj;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700947 Log.continueSession((Session) args.arg3,
948 SESSION_HANDLER + SESSION_CALL_AUDIO_SC);
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700949 try {
950 String callId = (String) args.arg1;
Yorke Lee4af59352015-05-13 14:14:54 -0700951 CallAudioState audioState = (CallAudioState) args.arg2;
952 onCallAudioStateChanged(callId, new CallAudioState(audioState));
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700953 } finally {
954 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700955 Log.endSession();
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700956 }
957 break;
958 }
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700959 case MSG_PLAY_DTMF_TONE: {
960 SomeArgs args = (SomeArgs) msg.obj;
961 try {
962 Log.continueSession((Session) args.arg3,
963 SESSION_HANDLER + SESSION_PLAY_DTMF);
964 playDtmfTone((String) args.arg2, (char) args.arg1);
965 } finally {
966 args.recycle();
967 Log.endSession();
968 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700969 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700970 }
971 case MSG_STOP_DTMF_TONE: {
972 SomeArgs args = (SomeArgs) msg.obj;
973 try {
974 Log.continueSession((Session) args.arg2,
975 SESSION_HANDLER + SESSION_STOP_DTMF);
976 stopDtmfTone((String) args.arg1);
977 } finally {
978 args.recycle();
979 Log.endSession();
980 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700981 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700982 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700983 case MSG_CONFERENCE: {
984 SomeArgs args = (SomeArgs) msg.obj;
985 try {
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700986 Log.continueSession((Session) args.arg3,
987 SESSION_HANDLER + SESSION_CONFERENCE);
Santos Cordon823fd3c2014-08-07 18:35:18 -0700988 String callId1 = (String) args.arg1;
989 String callId2 = (String) args.arg2;
990 conference(callId1, callId2);
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700991 } finally {
992 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700993 Log.endSession();
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700994 }
995 break;
996 }
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700997 case MSG_SPLIT_FROM_CONFERENCE: {
998 SomeArgs args = (SomeArgs) msg.obj;
999 try {
1000 Log.continueSession((Session) args.arg2,
1001 SESSION_HANDLER + SESSION_SPLIT_CONFERENCE);
1002 splitFromConference((String) args.arg1);
1003 } finally {
1004 args.recycle();
1005 Log.endSession();
1006 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001007 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001008 }
1009 case MSG_MERGE_CONFERENCE: {
1010 SomeArgs args = (SomeArgs) msg.obj;
1011 try {
1012 Log.continueSession((Session) args.arg2,
1013 SESSION_HANDLER + SESSION_MERGE_CONFERENCE);
1014 mergeConference((String) args.arg1);
1015 } finally {
1016 args.recycle();
1017 Log.endSession();
1018 }
Santos Cordona4868042014-09-04 17:39:22 -07001019 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001020 }
1021 case MSG_SWAP_CONFERENCE: {
1022 SomeArgs args = (SomeArgs) msg.obj;
1023 try {
1024 Log.continueSession((Session) args.arg2,
1025 SESSION_HANDLER + SESSION_SWAP_CONFERENCE);
1026 swapConference((String) args.arg1);
1027 } finally {
1028 args.recycle();
1029 Log.endSession();
1030 }
Santos Cordona4868042014-09-04 17:39:22 -07001031 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001032 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001033 case MSG_ON_POST_DIAL_CONTINUE: {
1034 SomeArgs args = (SomeArgs) msg.obj;
1035 try {
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001036 Log.continueSession((Session) args.arg2,
1037 SESSION_HANDLER + SESSION_POST_DIAL_CONT);
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001038 String callId = (String) args.arg1;
1039 boolean proceed = (args.argi1 == 1);
1040 onPostDialContinue(callId, proceed);
1041 } finally {
1042 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001043 Log.endSession();
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001044 }
1045 break;
1046 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001047 case MSG_PULL_EXTERNAL_CALL: {
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001048 SomeArgs args = (SomeArgs) msg.obj;
1049 try {
1050 Log.continueSession((Session) args.arg2,
1051 SESSION_HANDLER + SESSION_PULL_EXTERNAL_CALL);
1052 pullExternalCall((String) args.arg1);
1053 } finally {
1054 args.recycle();
1055 Log.endSession();
1056 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001057 break;
1058 }
1059 case MSG_SEND_CALL_EVENT: {
1060 SomeArgs args = (SomeArgs) msg.obj;
1061 try {
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001062 Log.continueSession((Session) args.arg4,
1063 SESSION_HANDLER + SESSION_SEND_CALL_EVENT);
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001064 String callId = (String) args.arg1;
1065 String event = (String) args.arg2;
1066 Bundle extras = (Bundle) args.arg3;
1067 sendCallEvent(callId, event, extras);
1068 } finally {
1069 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001070 Log.endSession();
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001071 }
1072 break;
1073 }
Tyler Gunn79bc1ec2018-01-22 15:17:54 -08001074 case MSG_HANDOVER_COMPLETE: {
1075 SomeArgs args = (SomeArgs) msg.obj;
1076 try {
1077 Log.continueSession((Session) args.arg2,
1078 SESSION_HANDLER + SESSION_HANDOVER_COMPLETE);
1079 String callId = (String) args.arg1;
1080 notifyHandoverComplete(callId);
1081 } finally {
1082 args.recycle();
1083 Log.endSession();
1084 }
1085 break;
1086 }
Tyler Gunndee56a82016-03-23 16:06:34 -07001087 case MSG_ON_EXTRAS_CHANGED: {
1088 SomeArgs args = (SomeArgs) msg.obj;
1089 try {
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001090 Log.continueSession((Session) args.arg3,
1091 SESSION_HANDLER + SESSION_EXTRAS_CHANGED);
Tyler Gunndee56a82016-03-23 16:06:34 -07001092 String callId = (String) args.arg1;
1093 Bundle extras = (Bundle) args.arg2;
1094 handleExtrasChanged(callId, extras);
1095 } finally {
1096 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001097 Log.endSession();
Tyler Gunndee56a82016-03-23 16:06:34 -07001098 }
1099 break;
1100 }
Hall Liub64ac4c2017-02-06 10:49:48 -08001101 case MSG_ON_START_RTT: {
1102 SomeArgs args = (SomeArgs) msg.obj;
1103 try {
1104 Log.continueSession((Session) args.arg3,
1105 SESSION_HANDLER + SESSION_START_RTT);
1106 String callId = (String) args.arg1;
1107 Connection.RttTextStream rttTextStream =
1108 (Connection.RttTextStream) args.arg2;
1109 startRtt(callId, rttTextStream);
1110 } finally {
1111 args.recycle();
1112 Log.endSession();
1113 }
1114 break;
1115 }
1116 case MSG_ON_STOP_RTT: {
1117 SomeArgs args = (SomeArgs) msg.obj;
1118 try {
1119 Log.continueSession((Session) args.arg2,
1120 SESSION_HANDLER + SESSION_STOP_RTT);
1121 String callId = (String) args.arg1;
1122 stopRtt(callId);
1123 } finally {
1124 args.recycle();
1125 Log.endSession();
1126 }
1127 break;
1128 }
1129 case MSG_RTT_UPGRADE_RESPONSE: {
1130 SomeArgs args = (SomeArgs) msg.obj;
1131 try {
1132 Log.continueSession((Session) args.arg3,
1133 SESSION_HANDLER + SESSION_RTT_UPGRADE_RESPONSE);
1134 String callId = (String) args.arg1;
1135 Connection.RttTextStream rttTextStream =
1136 (Connection.RttTextStream) args.arg2;
1137 handleRttUpgradeResponse(callId, rttTextStream);
1138 } finally {
1139 args.recycle();
1140 Log.endSession();
1141 }
1142 break;
1143 }
Pengquan Meng731c1a32017-11-21 18:01:13 -08001144 case MSG_CONNECTION_SERVICE_FOCUS_GAINED:
1145 onConnectionServiceFocusGained();
1146 break;
1147 case MSG_CONNECTION_SERVICE_FOCUS_LOST:
1148 onConnectionServiceFocusLost();
1149 break;
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001150 default:
1151 break;
1152 }
1153 }
1154 };
1155
Santos Cordon823fd3c2014-08-07 18:35:18 -07001156 private final Conference.Listener mConferenceListener = new Conference.Listener() {
1157 @Override
1158 public void onStateChanged(Conference conference, int oldState, int newState) {
1159 String id = mIdByConference.get(conference);
1160 switch (newState) {
1161 case Connection.STATE_ACTIVE:
1162 mAdapter.setActive(id);
1163 break;
1164 case Connection.STATE_HOLDING:
1165 mAdapter.setOnHold(id);
1166 break;
1167 case Connection.STATE_DISCONNECTED:
1168 // handled by onDisconnected
1169 break;
1170 }
1171 }
1172
1173 @Override
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001174 public void onDisconnected(Conference conference, DisconnectCause disconnectCause) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07001175 String id = mIdByConference.get(conference);
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001176 mAdapter.setDisconnected(id, disconnectCause);
Santos Cordon823fd3c2014-08-07 18:35:18 -07001177 }
1178
1179 @Override
1180 public void onConnectionAdded(Conference conference, Connection connection) {
1181 }
1182
1183 @Override
1184 public void onConnectionRemoved(Conference conference, Connection connection) {
1185 }
1186
1187 @Override
Ihab Awad50e35062014-09-30 09:17:03 -07001188 public void onConferenceableConnectionsChanged(
1189 Conference conference, List<Connection> conferenceableConnections) {
1190 mAdapter.setConferenceableConnections(
1191 mIdByConference.get(conference),
1192 createConnectionIdList(conferenceableConnections));
1193 }
1194
1195 @Override
Santos Cordon823fd3c2014-08-07 18:35:18 -07001196 public void onDestroyed(Conference conference) {
1197 removeConference(conference);
1198 }
1199
1200 @Override
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001201 public void onConnectionCapabilitiesChanged(
1202 Conference conference,
1203 int connectionCapabilities) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07001204 String id = mIdByConference.get(conference);
1205 Log.d(this, "call capabilities: conference: %s",
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001206 Connection.capabilitiesToString(connectionCapabilities));
1207 mAdapter.setConnectionCapabilities(id, connectionCapabilities);
Santos Cordon823fd3c2014-08-07 18:35:18 -07001208 }
Rekha Kumar07366812015-03-24 16:42:31 -07001209
1210 @Override
Tyler Gunn720c6642016-03-22 09:02:47 -07001211 public void onConnectionPropertiesChanged(
1212 Conference conference,
1213 int connectionProperties) {
1214 String id = mIdByConference.get(conference);
1215 Log.d(this, "call capabilities: conference: %s",
1216 Connection.propertiesToString(connectionProperties));
1217 mAdapter.setConnectionProperties(id, connectionProperties);
1218 }
1219
1220 @Override
Rekha Kumar07366812015-03-24 16:42:31 -07001221 public void onVideoStateChanged(Conference c, int videoState) {
1222 String id = mIdByConference.get(c);
1223 Log.d(this, "onVideoStateChanged set video state %d", videoState);
1224 mAdapter.setVideoState(id, videoState);
1225 }
1226
1227 @Override
1228 public void onVideoProviderChanged(Conference c, Connection.VideoProvider videoProvider) {
1229 String id = mIdByConference.get(c);
1230 Log.d(this, "onVideoProviderChanged: Connection: %s, VideoProvider: %s", c,
1231 videoProvider);
1232 mAdapter.setVideoProvider(id, videoProvider);
1233 }
Andrew Lee0f51da32015-04-16 13:11:55 -07001234
1235 @Override
Andrew Leeedc625f2015-04-14 13:38:12 -07001236 public void onStatusHintsChanged(Conference conference, StatusHints statusHints) {
1237 String id = mIdByConference.get(conference);
Tyler Gunndee56a82016-03-23 16:06:34 -07001238 if (id != null) {
1239 mAdapter.setStatusHints(id, statusHints);
1240 }
Andrew Leeedc625f2015-04-14 13:38:12 -07001241 }
Santos Cordon6b7f9552015-05-27 17:21:45 -07001242
1243 @Override
Tyler Gunndee56a82016-03-23 16:06:34 -07001244 public void onExtrasChanged(Conference c, Bundle extras) {
1245 String id = mIdByConference.get(c);
1246 if (id != null) {
1247 mAdapter.putExtras(id, extras);
1248 }
1249 }
1250
1251 @Override
1252 public void onExtrasRemoved(Conference c, List<String> keys) {
1253 String id = mIdByConference.get(c);
1254 if (id != null) {
1255 mAdapter.removeExtras(id, keys);
1256 }
Santos Cordon6b7f9552015-05-27 17:21:45 -07001257 }
Tyler Gunn68a73a42018-10-03 15:38:57 -07001258
1259 @Override
1260 public void onConferenceStateChanged(Conference c, boolean isConference) {
1261 String id = mIdByConference.get(c);
1262 if (id != null) {
1263 mAdapter.setConferenceState(id, isConference);
1264 }
1265 }
1266
1267 @Override
1268 public void onAddressChanged(Conference c, Uri newAddress, int presentation) {
1269 String id = mIdByConference.get(c);
1270 if (id != null) {
1271 mAdapter.setAddress(id, newAddress, presentation);
1272 }
1273 }
1274
1275 @Override
1276 public void onCallerDisplayNameChanged(Conference c, String callerDisplayName,
1277 int presentation) {
1278 String id = mIdByConference.get(c);
1279 if (id != null) {
1280 mAdapter.setCallerDisplayName(id, callerDisplayName, presentation);
1281 }
1282 }
Hall Liuc9bc1c62019-04-16 14:00:55 -07001283
1284 @Override
1285 public void onConnectionEvent(Conference c, String event, Bundle extras) {
1286 String id = mIdByConference.get(c);
1287 if (id != null) {
1288 mAdapter.onConnectionEvent(id, event, extras);
1289 }
1290 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07001291 };
1292
Ihab Awad542e0ea2014-05-16 10:22:16 -07001293 private final Connection.Listener mConnectionListener = new Connection.Listener() {
1294 @Override
1295 public void onStateChanged(Connection c, int state) {
1296 String id = mIdByConnection.get(c);
Ihab Awad42b30e12014-05-22 09:49:34 -07001297 Log.d(this, "Adapter set state %s %s", id, Connection.stateToString(state));
Ihab Awad542e0ea2014-05-16 10:22:16 -07001298 switch (state) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001299 case Connection.STATE_ACTIVE:
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001300 mAdapter.setActive(id);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001301 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001302 case Connection.STATE_DIALING:
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001303 mAdapter.setDialing(id);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001304 break;
Tyler Gunnc96b5e02016-07-07 22:53:57 -07001305 case Connection.STATE_PULLING_CALL:
1306 mAdapter.setPulling(id);
1307 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001308 case Connection.STATE_DISCONNECTED:
Ihab Awad542e0ea2014-05-16 10:22:16 -07001309 // Handled in onDisconnected()
1310 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001311 case Connection.STATE_HOLDING:
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001312 mAdapter.setOnHold(id);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001313 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001314 case Connection.STATE_NEW:
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001315 // Nothing to tell Telecom
Ihab Awad542e0ea2014-05-16 10:22:16 -07001316 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001317 case Connection.STATE_RINGING:
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001318 mAdapter.setRinging(id);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001319 break;
1320 }
1321 }
1322
1323 @Override
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001324 public void onDisconnected(Connection c, DisconnectCause disconnectCause) {
Ihab Awad542e0ea2014-05-16 10:22:16 -07001325 String id = mIdByConnection.get(c);
Andrew Lee26786392014-09-16 18:14:59 -07001326 Log.d(this, "Adapter set disconnected %s", disconnectCause);
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001327 mAdapter.setDisconnected(id, disconnectCause);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001328 }
1329
1330 @Override
Tyler Gunnaa07df82014-07-17 07:50:22 -07001331 public void onVideoStateChanged(Connection c, int videoState) {
1332 String id = mIdByConnection.get(c);
1333 Log.d(this, "Adapter set video state %d", videoState);
1334 mAdapter.setVideoState(id, videoState);
1335 }
1336
1337 @Override
Andrew Lee100e2932014-09-08 15:34:24 -07001338 public void onAddressChanged(Connection c, Uri address, int presentation) {
Sailesh Nepal61203862014-07-11 14:50:13 -07001339 String id = mIdByConnection.get(c);
Andrew Lee100e2932014-09-08 15:34:24 -07001340 mAdapter.setAddress(id, address, presentation);
Sailesh Nepal61203862014-07-11 14:50:13 -07001341 }
1342
1343 @Override
1344 public void onCallerDisplayNameChanged(
1345 Connection c, String callerDisplayName, int presentation) {
1346 String id = mIdByConnection.get(c);
1347 mAdapter.setCallerDisplayName(id, callerDisplayName, presentation);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001348 }
1349
1350 @Override
Ihab Awad542e0ea2014-05-16 10:22:16 -07001351 public void onDestroyed(Connection c) {
1352 removeConnection(c);
1353 }
Ihab Awadf8358972014-05-28 16:46:42 -07001354
1355 @Override
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001356 public void onPostDialWait(Connection c, String remaining) {
Sailesh Nepal091768c2014-06-30 15:15:23 -07001357 String id = mIdByConnection.get(c);
1358 Log.d(this, "Adapter onPostDialWait %s, %s", c, remaining);
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001359 mAdapter.onPostDialWait(id, remaining);
Sailesh Nepal091768c2014-06-30 15:15:23 -07001360 }
1361
1362 @Override
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001363 public void onPostDialChar(Connection c, char nextChar) {
1364 String id = mIdByConnection.get(c);
1365 Log.d(this, "Adapter onPostDialChar %s, %s", c, nextChar);
1366 mAdapter.onPostDialChar(id, nextChar);
1367 }
1368
1369 @Override
Andrew Lee100e2932014-09-08 15:34:24 -07001370 public void onRingbackRequested(Connection c, boolean ringback) {
Ihab Awadf8358972014-05-28 16:46:42 -07001371 String id = mIdByConnection.get(c);
1372 Log.d(this, "Adapter onRingback %b", ringback);
Andrew Lee100e2932014-09-08 15:34:24 -07001373 mAdapter.setRingbackRequested(id, ringback);
Ihab Awadf8358972014-05-28 16:46:42 -07001374 }
Santos Cordonb6939982014-06-04 20:20:58 -07001375
1376 @Override
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001377 public void onConnectionCapabilitiesChanged(Connection c, int capabilities) {
Santos Cordonb6939982014-06-04 20:20:58 -07001378 String id = mIdByConnection.get(c);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001379 Log.d(this, "capabilities: parcelableconnection: %s",
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001380 Connection.capabilitiesToString(capabilities));
1381 mAdapter.setConnectionCapabilities(id, capabilities);
Santos Cordonb6939982014-06-04 20:20:58 -07001382 }
1383
Santos Cordonb6939982014-06-04 20:20:58 -07001384 @Override
Tyler Gunn720c6642016-03-22 09:02:47 -07001385 public void onConnectionPropertiesChanged(Connection c, int properties) {
1386 String id = mIdByConnection.get(c);
1387 Log.d(this, "properties: parcelableconnection: %s",
1388 Connection.propertiesToString(properties));
1389 mAdapter.setConnectionProperties(id, properties);
1390 }
1391
1392 @Override
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001393 public void onVideoProviderChanged(Connection c, Connection.VideoProvider videoProvider) {
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07001394 String id = mIdByConnection.get(c);
Rekha Kumar07366812015-03-24 16:42:31 -07001395 Log.d(this, "onVideoProviderChanged: Connection: %s, VideoProvider: %s", c,
1396 videoProvider);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001397 mAdapter.setVideoProvider(id, videoProvider);
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07001398 }
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001399
1400 @Override
Sailesh Nepal001bbbb2014-07-15 14:40:39 -07001401 public void onAudioModeIsVoipChanged(Connection c, boolean isVoip) {
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001402 String id = mIdByConnection.get(c);
Andrew Lee100e2932014-09-08 15:34:24 -07001403 mAdapter.setIsVoipAudioMode(id, isVoip);
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001404 }
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001405
1406 @Override
Sailesh Nepal001bbbb2014-07-15 14:40:39 -07001407 public void onStatusHintsChanged(Connection c, StatusHints statusHints) {
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001408 String id = mIdByConnection.get(c);
1409 mAdapter.setStatusHints(id, statusHints);
1410 }
Sailesh Nepal2ab88cc2014-07-18 14:49:18 -07001411
1412 @Override
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001413 public void onConferenceablesChanged(
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001414 Connection connection, List<Conferenceable> conferenceables) {
Ihab Awadb8e85c72014-08-23 20:34:57 -07001415 mAdapter.setConferenceableConnections(
1416 mIdByConnection.get(connection),
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001417 createIdList(conferenceables));
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001418 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07001419
1420 @Override
1421 public void onConferenceChanged(Connection connection, Conference conference) {
1422 String id = mIdByConnection.get(connection);
1423 if (id != null) {
1424 String conferenceId = null;
1425 if (conference != null) {
1426 conferenceId = mIdByConference.get(conference);
1427 }
1428 mAdapter.setIsConferenced(id, conferenceId);
1429 }
1430 }
Anthony Lee17455a32015-04-24 15:25:29 -07001431
1432 @Override
1433 public void onConferenceMergeFailed(Connection connection) {
1434 String id = mIdByConnection.get(connection);
1435 if (id != null) {
1436 mAdapter.onConferenceMergeFailed(id);
1437 }
1438 }
Santos Cordon6b7f9552015-05-27 17:21:45 -07001439
1440 @Override
Tyler Gunndee56a82016-03-23 16:06:34 -07001441 public void onExtrasChanged(Connection c, Bundle extras) {
1442 String id = mIdByConnection.get(c);
Santos Cordon6b7f9552015-05-27 17:21:45 -07001443 if (id != null) {
Tyler Gunndee56a82016-03-23 16:06:34 -07001444 mAdapter.putExtras(id, extras);
Santos Cordon6b7f9552015-05-27 17:21:45 -07001445 }
1446 }
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001447
Tyler Gunnf5035432017-01-09 09:43:12 -08001448 @Override
Tyler Gunndee56a82016-03-23 16:06:34 -07001449 public void onExtrasRemoved(Connection c, List<String> keys) {
1450 String id = mIdByConnection.get(c);
1451 if (id != null) {
1452 mAdapter.removeExtras(id, keys);
1453 }
1454 }
1455
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08001456 @Override
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001457 public void onConnectionEvent(Connection connection, String event, Bundle extras) {
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08001458 String id = mIdByConnection.get(connection);
1459 if (id != null) {
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001460 mAdapter.onConnectionEvent(id, event, extras);
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08001461 }
1462 }
Tyler Gunnf5035432017-01-09 09:43:12 -08001463
1464 @Override
Hall Liua98f58b52017-11-07 17:59:28 -08001465 public void onAudioRouteChanged(Connection c, int audioRoute, String bluetoothAddress) {
Tyler Gunnf5035432017-01-09 09:43:12 -08001466 String id = mIdByConnection.get(c);
1467 if (id != null) {
Hall Liua98f58b52017-11-07 17:59:28 -08001468 mAdapter.setAudioRoute(id, audioRoute, bluetoothAddress);
Tyler Gunnf5035432017-01-09 09:43:12 -08001469 }
1470 }
Hall Liub64ac4c2017-02-06 10:49:48 -08001471
1472 @Override
1473 public void onRttInitiationSuccess(Connection c) {
1474 String id = mIdByConnection.get(c);
1475 if (id != null) {
1476 mAdapter.onRttInitiationSuccess(id);
1477 }
1478 }
1479
1480 @Override
1481 public void onRttInitiationFailure(Connection c, int reason) {
1482 String id = mIdByConnection.get(c);
1483 if (id != null) {
1484 mAdapter.onRttInitiationFailure(id, reason);
1485 }
1486 }
1487
1488 @Override
1489 public void onRttSessionRemotelyTerminated(Connection c) {
1490 String id = mIdByConnection.get(c);
1491 if (id != null) {
1492 mAdapter.onRttSessionRemotelyTerminated(id);
1493 }
1494 }
1495
1496 @Override
1497 public void onRemoteRttRequest(Connection c) {
1498 String id = mIdByConnection.get(c);
1499 if (id != null) {
1500 mAdapter.onRemoteRttRequest(id);
1501 }
1502 }
Srikanth Chintalafcb15012017-05-04 20:58:34 +05301503
1504 @Override
1505 public void onPhoneAccountChanged(Connection c, PhoneAccountHandle pHandle) {
1506 String id = mIdByConnection.get(c);
1507 if (id != null) {
1508 mAdapter.onPhoneAccountChanged(id, pHandle);
1509 }
1510 }
Mengjun Leng25707742017-07-04 11:10:37 +08001511
1512 public void onConnectionTimeReset(Connection c) {
1513 String id = mIdByConnection.get(c);
1514 if (id != null) {
1515 mAdapter.resetConnectionTime(id);
1516 }
1517 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001518 };
1519
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001520 /** {@inheritDoc} */
Ihab Awad542e0ea2014-05-16 10:22:16 -07001521 @Override
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001522 public final IBinder onBind(Intent intent) {
1523 return mBinder;
1524 }
1525
Santos Cordon29f2f2e2014-09-11 19:50:24 -07001526 /** {@inheritDoc} */
1527 @Override
1528 public boolean onUnbind(Intent intent) {
1529 endAllConnections();
1530 return super.onUnbind(intent);
1531 }
1532
Sailesh Nepalc5b01572014-07-14 16:29:44 -07001533 /**
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001534 * This can be used by telecom to either create a new outgoing call or attach to an existing
1535 * incoming call. In either case, telecom will cycle through a set of services and call
Sailesh Nepalc5b01572014-07-14 16:29:44 -07001536 * createConnection util a connection service cancels the process or completes it successfully.
1537 */
Ihab Awadf8b69882014-07-25 15:14:01 -07001538 private void createConnection(
1539 final PhoneAccountHandle callManagerAccount,
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001540 final String callId,
Ihab Awadf8b69882014-07-25 15:14:01 -07001541 final ConnectionRequest request,
Yorke Leec3cf9822014-10-02 09:38:39 -07001542 boolean isIncoming,
1543 boolean isUnknown) {
Tyler Gunn79bc1ec2018-01-22 15:17:54 -08001544 boolean isLegacyHandover = request.getExtras() != null &&
1545 request.getExtras().getBoolean(TelecomManager.EXTRA_IS_HANDOVER, false);
1546 boolean isHandover = request.getExtras() != null && request.getExtras().getBoolean(
1547 TelecomManager.EXTRA_IS_HANDOVER_CONNECTION, false);
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001548 Log.d(this, "createConnection, callManagerAccount: %s, callId: %s, request: %s, " +
Tyler Gunn79bc1ec2018-01-22 15:17:54 -08001549 "isIncoming: %b, isUnknown: %b, isLegacyHandover: %b, isHandover: %b",
1550 callManagerAccount, callId, request, isIncoming, isUnknown, isLegacyHandover,
1551 isHandover);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001552
Sanket Padawee29a2662017-12-01 13:59:27 -08001553 Connection connection = null;
Tyler Gunn79bc1ec2018-01-22 15:17:54 -08001554 if (isHandover) {
1555 PhoneAccountHandle fromPhoneAccountHandle = request.getExtras() != null
1556 ? (PhoneAccountHandle) request.getExtras().getParcelable(
1557 TelecomManager.EXTRA_HANDOVER_FROM_PHONE_ACCOUNT) : null;
Sanket Padawee29a2662017-12-01 13:59:27 -08001558 if (!isIncoming) {
Tyler Gunn79bc1ec2018-01-22 15:17:54 -08001559 connection = onCreateOutgoingHandoverConnection(fromPhoneAccountHandle, request);
Sanket Padawee29a2662017-12-01 13:59:27 -08001560 } else {
Tyler Gunn79bc1ec2018-01-22 15:17:54 -08001561 connection = onCreateIncomingHandoverConnection(fromPhoneAccountHandle, request);
Sanket Padawee29a2662017-12-01 13:59:27 -08001562 }
1563 } else {
1564 connection = isUnknown ? onCreateUnknownConnection(callManagerAccount, request)
1565 : isIncoming ? onCreateIncomingConnection(callManagerAccount, request)
1566 : onCreateOutgoingConnection(callManagerAccount, request);
1567 }
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001568 Log.d(this, "createConnection, connection: %s", connection);
1569 if (connection == null) {
Tyler Gunnfba1a8e2017-12-19 15:23:59 -08001570 Log.i(this, "createConnection, implementation returned null connection.");
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001571 connection = Connection.createFailedConnection(
Tyler Gunnfba1a8e2017-12-19 15:23:59 -08001572 new DisconnectCause(DisconnectCause.ERROR, "IMPL_RETURNED_NULL_CONNECTION"));
Sailesh Nepalc5b01572014-07-14 16:29:44 -07001573 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001574
Tyler Gunnf2e08b42018-05-24 10:44:44 -07001575 boolean isSelfManaged =
1576 (connection.getConnectionProperties() & Connection.PROPERTY_SELF_MANAGED)
1577 == Connection.PROPERTY_SELF_MANAGED;
1578 // Self-managed Connections should always use voip audio mode; we default here so that the
1579 // local state within the ConnectionService matches the default we assume in Telecom.
1580 if (isSelfManaged) {
1581 connection.setAudioModeIsVoip(true);
1582 }
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001583 connection.setTelecomCallId(callId);
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001584 if (connection.getState() != Connection.STATE_DISCONNECTED) {
Pengquan Meng70c9885332017-10-02 18:09:03 -07001585 addConnection(request.getAccountHandle(), callId, connection);
Ihab Awad6107bab2014-08-18 09:23:25 -07001586 }
1587
Andrew Lee100e2932014-09-08 15:34:24 -07001588 Uri address = connection.getAddress();
1589 String number = address == null ? "null" : address.getSchemeSpecificPart();
Tyler Gunn720c6642016-03-22 09:02:47 -07001590 Log.v(this, "createConnection, number: %s, state: %s, capabilities: %s, properties: %s",
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001591 Connection.toLogSafePhoneNumber(number),
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001592 Connection.stateToString(connection.getState()),
Tyler Gunn720c6642016-03-22 09:02:47 -07001593 Connection.capabilitiesToString(connection.getConnectionCapabilities()),
1594 Connection.propertiesToString(connection.getConnectionProperties()));
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001595
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001596 Log.d(this, "createConnection, calling handleCreateConnectionSuccessful %s", callId);
Ihab Awad6107bab2014-08-18 09:23:25 -07001597 mAdapter.handleCreateConnectionComplete(
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001598 callId,
Evan Charltonbf11f982014-07-20 22:06:28 -07001599 request,
1600 new ParcelableConnection(
1601 request.getAccountHandle(),
1602 connection.getState(),
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001603 connection.getConnectionCapabilities(),
Tyler Gunn720c6642016-03-22 09:02:47 -07001604 connection.getConnectionProperties(),
Christine Hallstrom2830ce92016-11-30 16:06:42 -08001605 connection.getSupportedAudioRoutes(),
Andrew Lee100e2932014-09-08 15:34:24 -07001606 connection.getAddress(),
1607 connection.getAddressPresentation(),
Evan Charltonbf11f982014-07-20 22:06:28 -07001608 connection.getCallerDisplayName(),
1609 connection.getCallerDisplayNamePresentation(),
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001610 connection.getVideoProvider() == null ?
1611 null : connection.getVideoProvider().getInterface(),
Sailesh Nepal8b9d3ca2014-08-14 17:39:34 -07001612 connection.getVideoState(),
Andrew Lee100e2932014-09-08 15:34:24 -07001613 connection.isRingbackRequested(),
Sailesh Nepal8b9d3ca2014-08-14 17:39:34 -07001614 connection.getAudioModeIsVoip(),
Roshan Piuse927ec02015-07-15 15:47:21 -07001615 connection.getConnectTimeMillis(),
Tyler Gunn3fa819c2017-08-04 09:27:26 -07001616 connection.getConnectElapsedTimeMillis(),
Ihab Awad6107bab2014-08-18 09:23:25 -07001617 connection.getStatusHints(),
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001618 connection.getDisconnectCause(),
Santos Cordon6b7f9552015-05-27 17:21:45 -07001619 createIdList(connection.getConferenceables()),
1620 connection.getExtras()));
Tyler Gunnf5035432017-01-09 09:43:12 -08001621
Tyler Gunnf2e08b42018-05-24 10:44:44 -07001622 if (isIncoming && request.shouldShowIncomingCallUi() && isSelfManaged) {
Tyler Gunnf5035432017-01-09 09:43:12 -08001623 // Tell ConnectionService to show its incoming call UX.
1624 connection.onShowIncomingCallUi();
1625 }
Shriram Ganesh6bf35ac2014-12-11 17:53:38 -08001626 if (isUnknown) {
1627 triggerConferenceRecalculate();
1628 }
Evan Charltonbf11f982014-07-20 22:06:28 -07001629 }
1630
Tyler Gunn159f35c2017-03-02 09:28:37 -08001631 private void createConnectionFailed(final PhoneAccountHandle callManagerAccount,
1632 final String callId, final ConnectionRequest request,
1633 boolean isIncoming) {
Tyler Gunn44e01912017-01-31 10:49:05 -08001634
1635 Log.i(this, "createConnectionFailed %s", callId);
1636 if (isIncoming) {
Tyler Gunn159f35c2017-03-02 09:28:37 -08001637 onCreateIncomingConnectionFailed(callManagerAccount, request);
Tyler Gunn44e01912017-01-31 10:49:05 -08001638 } else {
Tyler Gunn159f35c2017-03-02 09:28:37 -08001639 onCreateOutgoingConnectionFailed(callManagerAccount, request);
Tyler Gunn44e01912017-01-31 10:49:05 -08001640 }
1641 }
1642
Sanket Padawe4cc8ed52017-12-04 16:22:20 -08001643 private void handoverFailed(final String callId, final ConnectionRequest request,
1644 int reason) {
1645
1646 Log.i(this, "handoverFailed %s", callId);
1647 onHandoverFailed(request, reason);
1648 }
1649
Tyler Gunn041a1fe2017-05-12 10:04:49 -07001650 /**
1651 * Called by Telecom when the creation of a new Connection has completed and it is now added
1652 * to Telecom.
1653 * @param callId The ID of the connection.
1654 */
1655 private void notifyCreateConnectionComplete(final String callId) {
1656 Log.i(this, "notifyCreateConnectionComplete %s", callId);
Tyler Gunn0a88f2e2017-06-16 20:20:34 -07001657 if (callId == null) {
1658 // This could happen if the connection fails quickly and is removed from the
1659 // ConnectionService before Telecom sends the create connection complete callback.
1660 Log.w(this, "notifyCreateConnectionComplete: callId is null.");
1661 return;
1662 }
Tyler Gunn041a1fe2017-05-12 10:04:49 -07001663 onCreateConnectionComplete(findConnectionForAction(callId,
1664 "notifyCreateConnectionComplete"));
1665 }
1666
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001667 private void abort(String callId) {
Ihab Awad60ac30b2014-05-20 22:32:12 -07001668 Log.d(this, "abort %s", callId);
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001669 findConnectionForAction(callId, "abort").onAbort();
Ihab Awad542e0ea2014-05-16 10:22:16 -07001670 }
1671
Tyler Gunnbe74de02014-08-29 14:51:48 -07001672 private void answerVideo(String callId, int videoState) {
1673 Log.d(this, "answerVideo %s", callId);
Andrew Lee8da4c3c2014-07-16 10:11:42 -07001674 findConnectionForAction(callId, "answer").onAnswer(videoState);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001675 }
1676
Tyler Gunnbe74de02014-08-29 14:51:48 -07001677 private void answer(String callId) {
1678 Log.d(this, "answer %s", callId);
1679 findConnectionForAction(callId, "answer").onAnswer();
1680 }
1681
Pooja Jaind34698d2017-12-28 14:15:31 +05301682 private void deflect(String callId, Uri address) {
1683 Log.d(this, "deflect %s", callId);
1684 findConnectionForAction(callId, "deflect").onDeflect(address);
1685 }
1686
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001687 private void reject(String callId) {
Ihab Awad60ac30b2014-05-20 22:32:12 -07001688 Log.d(this, "reject %s", callId);
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001689 findConnectionForAction(callId, "reject").onReject();
Ihab Awad542e0ea2014-05-16 10:22:16 -07001690 }
1691
Bryce Lee81901682015-08-28 16:38:02 -07001692 private void reject(String callId, String rejectWithMessage) {
1693 Log.d(this, "reject %s with message", callId);
1694 findConnectionForAction(callId, "reject").onReject(rejectWithMessage);
1695 }
1696
Bryce Leecac50772015-11-17 15:13:29 -08001697 private void silence(String callId) {
1698 Log.d(this, "silence %s", callId);
1699 findConnectionForAction(callId, "silence").onSilence();
1700 }
1701
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001702 private void disconnect(String callId) {
Ihab Awad60ac30b2014-05-20 22:32:12 -07001703 Log.d(this, "disconnect %s", callId);
Santos Cordon0159ac02014-08-21 14:28:11 -07001704 if (mConnectionById.containsKey(callId)) {
1705 findConnectionForAction(callId, "disconnect").onDisconnect();
1706 } else {
1707 findConferenceForAction(callId, "disconnect").onDisconnect();
1708 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001709 }
1710
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001711 private void hold(String callId) {
Ihab Awad60ac30b2014-05-20 22:32:12 -07001712 Log.d(this, "hold %s", callId);
Santos Cordon0159ac02014-08-21 14:28:11 -07001713 if (mConnectionById.containsKey(callId)) {
1714 findConnectionForAction(callId, "hold").onHold();
1715 } else {
1716 findConferenceForAction(callId, "hold").onHold();
1717 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001718 }
1719
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001720 private void unhold(String callId) {
Ihab Awad60ac30b2014-05-20 22:32:12 -07001721 Log.d(this, "unhold %s", callId);
Santos Cordon0159ac02014-08-21 14:28:11 -07001722 if (mConnectionById.containsKey(callId)) {
1723 findConnectionForAction(callId, "unhold").onUnhold();
1724 } else {
1725 findConferenceForAction(callId, "unhold").onUnhold();
1726 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001727 }
1728
Yorke Lee4af59352015-05-13 14:14:54 -07001729 private void onCallAudioStateChanged(String callId, CallAudioState callAudioState) {
1730 Log.d(this, "onAudioStateChanged %s %s", callId, callAudioState);
Yorke Leea0d3ca92014-09-15 19:18:13 -07001731 if (mConnectionById.containsKey(callId)) {
Yorke Lee4af59352015-05-13 14:14:54 -07001732 findConnectionForAction(callId, "onCallAudioStateChanged").setCallAudioState(
1733 callAudioState);
Yorke Leea0d3ca92014-09-15 19:18:13 -07001734 } else {
Yorke Lee4af59352015-05-13 14:14:54 -07001735 findConferenceForAction(callId, "onCallAudioStateChanged").setCallAudioState(
1736 callAudioState);
Yorke Leea0d3ca92014-09-15 19:18:13 -07001737 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001738 }
1739
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001740 private void playDtmfTone(String callId, char digit) {
1741 Log.d(this, "playDtmfTone %s %c", callId, digit);
Yorke Leea0d3ca92014-09-15 19:18:13 -07001742 if (mConnectionById.containsKey(callId)) {
1743 findConnectionForAction(callId, "playDtmfTone").onPlayDtmfTone(digit);
1744 } else {
1745 findConferenceForAction(callId, "playDtmfTone").onPlayDtmfTone(digit);
1746 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001747 }
1748
1749 private void stopDtmfTone(String callId) {
1750 Log.d(this, "stopDtmfTone %s", callId);
Yorke Leea0d3ca92014-09-15 19:18:13 -07001751 if (mConnectionById.containsKey(callId)) {
1752 findConnectionForAction(callId, "stopDtmfTone").onStopDtmfTone();
1753 } else {
1754 findConferenceForAction(callId, "stopDtmfTone").onStopDtmfTone();
1755 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001756 }
1757
Santos Cordon823fd3c2014-08-07 18:35:18 -07001758 private void conference(String callId1, String callId2) {
1759 Log.d(this, "conference %s, %s", callId1, callId2);
Santos Cordon980acb92014-05-31 10:31:19 -07001760
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001761 // Attempt to get second connection or conference.
Santos Cordon823fd3c2014-08-07 18:35:18 -07001762 Connection connection2 = findConnectionForAction(callId2, "conference");
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001763 Conference conference2 = getNullConference();
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001764 if (connection2 == getNullConnection()) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001765 conference2 = findConferenceForAction(callId2, "conference");
1766 if (conference2 == getNullConference()) {
1767 Log.w(this, "Connection2 or Conference2 missing in conference request %s.",
1768 callId2);
1769 return;
1770 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07001771 }
Santos Cordonb6939982014-06-04 20:20:58 -07001772
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001773 // Attempt to get first connection or conference and perform merge.
Ihab Awad50e35062014-09-30 09:17:03 -07001774 Connection connection1 = findConnectionForAction(callId1, "conference");
1775 if (connection1 == getNullConnection()) {
1776 Conference conference1 = findConferenceForAction(callId1, "addConnection");
1777 if (conference1 == getNullConference()) {
1778 Log.w(this,
1779 "Connection1 or Conference1 missing in conference request %s.",
1780 callId1);
1781 } else {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001782 // Call 1 is a conference.
1783 if (connection2 != getNullConnection()) {
1784 // Call 2 is a connection so merge via call 1 (conference).
1785 conference1.onMerge(connection2);
1786 } else {
1787 // Call 2 is ALSO a conference; this should never happen.
1788 Log.wtf(this, "There can only be one conference and an attempt was made to " +
1789 "merge two conferences.");
1790 return;
1791 }
Ihab Awad50e35062014-09-30 09:17:03 -07001792 }
1793 } else {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001794 // Call 1 is a connection.
1795 if (conference2 != getNullConference()) {
1796 // Call 2 is a conference, so merge via call 2.
1797 conference2.onMerge(connection1);
1798 } else {
1799 // Call 2 is a connection, so merge together.
1800 onConference(connection1, connection2);
1801 }
Ihab Awad50e35062014-09-30 09:17:03 -07001802 }
Santos Cordon980acb92014-05-31 10:31:19 -07001803 }
1804
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001805 private void splitFromConference(String callId) {
Santos Cordonb6939982014-06-04 20:20:58 -07001806 Log.d(this, "splitFromConference(%s)", callId);
Santos Cordon980acb92014-05-31 10:31:19 -07001807
1808 Connection connection = findConnectionForAction(callId, "splitFromConference");
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001809 if (connection == getNullConnection()) {
Santos Cordon980acb92014-05-31 10:31:19 -07001810 Log.w(this, "Connection missing in conference request %s.", callId);
1811 return;
1812 }
1813
Santos Cordon0159ac02014-08-21 14:28:11 -07001814 Conference conference = connection.getConference();
1815 if (conference != null) {
1816 conference.onSeparate(connection);
1817 }
Santos Cordon980acb92014-05-31 10:31:19 -07001818 }
1819
Santos Cordona4868042014-09-04 17:39:22 -07001820 private void mergeConference(String callId) {
1821 Log.d(this, "mergeConference(%s)", callId);
1822 Conference conference = findConferenceForAction(callId, "mergeConference");
1823 if (conference != null) {
1824 conference.onMerge();
1825 }
1826 }
1827
1828 private void swapConference(String callId) {
1829 Log.d(this, "swapConference(%s)", callId);
1830 Conference conference = findConferenceForAction(callId, "swapConference");
1831 if (conference != null) {
1832 conference.onSwap();
1833 }
1834 }
1835
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001836 /**
1837 * Notifies a {@link Connection} of a request to pull an external call.
1838 *
1839 * See {@link Call#pullExternalCall()}.
1840 *
1841 * @param callId The ID of the call to pull.
1842 */
1843 private void pullExternalCall(String callId) {
1844 Log.d(this, "pullExternalCall(%s)", callId);
1845 Connection connection = findConnectionForAction(callId, "pullExternalCall");
1846 if (connection != null) {
1847 connection.onPullExternalCall();
1848 }
1849 }
1850
1851 /**
1852 * Notifies a {@link Connection} of a call event.
1853 *
1854 * See {@link Call#sendCallEvent(String, Bundle)}.
1855 *
1856 * @param callId The ID of the call receiving the event.
1857 * @param event The event.
1858 * @param extras Extras associated with the event.
1859 */
1860 private void sendCallEvent(String callId, String event, Bundle extras) {
1861 Log.d(this, "sendCallEvent(%s, %s)", callId, event);
1862 Connection connection = findConnectionForAction(callId, "sendCallEvent");
1863 if (connection != null) {
1864 connection.onCallEvent(event, extras);
1865 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001866 }
1867
Tyler Gunndee56a82016-03-23 16:06:34 -07001868 /**
Tyler Gunn79bc1ec2018-01-22 15:17:54 -08001869 * Notifies a {@link Connection} that a handover has completed.
1870 *
1871 * @param callId The ID of the call which completed handover.
1872 */
1873 private void notifyHandoverComplete(String callId) {
1874 Log.d(this, "notifyHandoverComplete(%s)", callId);
1875 Connection connection = findConnectionForAction(callId, "notifyHandoverComplete");
1876 if (connection != null) {
1877 connection.onHandoverComplete();
1878 }
1879 }
1880
1881 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001882 * Notifies a {@link Connection} or {@link Conference} of a change to the extras from Telecom.
1883 * <p>
1884 * These extra changes can originate from Telecom itself, or from an {@link InCallService} via
1885 * the {@link android.telecom.Call#putExtra(String, boolean)},
1886 * {@link android.telecom.Call#putExtra(String, int)},
1887 * {@link android.telecom.Call#putExtra(String, String)},
1888 * {@link Call#removeExtras(List)}.
1889 *
1890 * @param callId The ID of the call receiving the event.
1891 * @param extras The new extras bundle.
1892 */
1893 private void handleExtrasChanged(String callId, Bundle extras) {
1894 Log.d(this, "handleExtrasChanged(%s, %s)", callId, extras);
1895 if (mConnectionById.containsKey(callId)) {
1896 findConnectionForAction(callId, "handleExtrasChanged").handleExtrasChanged(extras);
1897 } else if (mConferenceById.containsKey(callId)) {
1898 findConferenceForAction(callId, "handleExtrasChanged").handleExtrasChanged(extras);
1899 }
1900 }
1901
Hall Liub64ac4c2017-02-06 10:49:48 -08001902 private void startRtt(String callId, Connection.RttTextStream rttTextStream) {
1903 Log.d(this, "startRtt(%s)", callId);
1904 if (mConnectionById.containsKey(callId)) {
1905 findConnectionForAction(callId, "startRtt").onStartRtt(rttTextStream);
1906 } else if (mConferenceById.containsKey(callId)) {
1907 Log.w(this, "startRtt called on a conference.");
1908 }
1909 }
1910
1911 private void stopRtt(String callId) {
1912 Log.d(this, "stopRtt(%s)", callId);
1913 if (mConnectionById.containsKey(callId)) {
1914 findConnectionForAction(callId, "stopRtt").onStopRtt();
1915 } else if (mConferenceById.containsKey(callId)) {
1916 Log.w(this, "stopRtt called on a conference.");
1917 }
1918 }
1919
1920 private void handleRttUpgradeResponse(String callId, Connection.RttTextStream rttTextStream) {
1921 Log.d(this, "handleRttUpgradeResponse(%s, %s)", callId, rttTextStream == null);
1922 if (mConnectionById.containsKey(callId)) {
1923 findConnectionForAction(callId, "handleRttUpgradeResponse")
1924 .handleRttUpgradeResponse(rttTextStream);
1925 } else if (mConferenceById.containsKey(callId)) {
1926 Log.w(this, "handleRttUpgradeResponse called on a conference.");
1927 }
1928 }
1929
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001930 private void onPostDialContinue(String callId, boolean proceed) {
Evan Charlton6dea4ac2014-06-03 14:07:13 -07001931 Log.d(this, "onPostDialContinue(%s)", callId);
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001932 findConnectionForAction(callId, "stopDtmfTone").onPostDialContinue(proceed);
Evan Charlton6dea4ac2014-06-03 14:07:13 -07001933 }
1934
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001935 private void onAdapterAttached() {
Ihab Awad9c3f1882014-06-30 21:17:13 -07001936 if (mAreAccountsInitialized) {
Santos Cordon52d8a152014-06-17 19:08:45 -07001937 // No need to query again if we already did it.
1938 return;
1939 }
1940
Tyler Gunn4c69fb32019-05-17 10:49:16 -07001941 String callingPackage = getOpPackageName();
1942
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001943 mAdapter.queryRemoteConnectionServices(new RemoteServiceCallback.Stub() {
Santos Cordon52d8a152014-06-17 19:08:45 -07001944 @Override
1945 public void onResult(
1946 final List<ComponentName> componentNames,
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001947 final List<IBinder> services) {
Brad Ebinger0c3541b2016-11-01 14:11:38 -07001948 mHandler.post(new android.telecom.Logging.Runnable("oAA.qRCS.oR", null /*lock*/) {
Ihab Awad6107bab2014-08-18 09:23:25 -07001949 @Override
Brad Ebinger0c3541b2016-11-01 14:11:38 -07001950 public void loggedRun() {
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001951 for (int i = 0; i < componentNames.size() && i < services.size(); i++) {
Santos Cordon52d8a152014-06-17 19:08:45 -07001952 mRemoteConnectionManager.addConnectionService(
1953 componentNames.get(i),
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001954 IConnectionService.Stub.asInterface(services.get(i)));
Santos Cordon52d8a152014-06-17 19:08:45 -07001955 }
Ihab Awad5d0410f2014-07-30 10:07:40 -07001956 onAccountsInitialized();
Sailesh Nepalc5b01572014-07-14 16:29:44 -07001957 Log.d(this, "remote connection services found: " + services);
Santos Cordon52d8a152014-06-17 19:08:45 -07001958 }
Brad Ebinger0c3541b2016-11-01 14:11:38 -07001959 }.prepare());
Santos Cordon52d8a152014-06-17 19:08:45 -07001960 }
1961
1962 @Override
1963 public void onError() {
Brad Ebinger0c3541b2016-11-01 14:11:38 -07001964 mHandler.post(new android.telecom.Logging.Runnable("oAA.qRCS.oE", null /*lock*/) {
Ihab Awad6107bab2014-08-18 09:23:25 -07001965 @Override
Brad Ebinger0c3541b2016-11-01 14:11:38 -07001966 public void loggedRun() {
Ihab Awad9c3f1882014-06-30 21:17:13 -07001967 mAreAccountsInitialized = true;
Santos Cordon52d8a152014-06-17 19:08:45 -07001968 }
Brad Ebinger0c3541b2016-11-01 14:11:38 -07001969 }.prepare());
Santos Cordon52d8a152014-06-17 19:08:45 -07001970 }
Tyler Gunn4c69fb32019-05-17 10:49:16 -07001971 }, callingPackage);
Santos Cordon52d8a152014-06-17 19:08:45 -07001972 }
1973
Ihab Awadf8b69882014-07-25 15:14:01 -07001974 /**
1975 * Ask some other {@code ConnectionService} to create a {@code RemoteConnection} given an
Santos Cordona663f862014-10-29 13:49:58 -07001976 * incoming request. This is used by {@code ConnectionService}s that are registered with
1977 * {@link PhoneAccount#CAPABILITY_CONNECTION_MANAGER} and want to be able to manage
1978 * SIM-based incoming calls.
Ihab Awadf8b69882014-07-25 15:14:01 -07001979 *
1980 * @param connectionManagerPhoneAccount See description at
1981 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
1982 * @param request Details about the incoming call.
1983 * @return The {@code Connection} object to satisfy this call, or {@code null} to
1984 * not handle the call.
1985 */
1986 public final RemoteConnection createRemoteIncomingConnection(
1987 PhoneAccountHandle connectionManagerPhoneAccount,
1988 ConnectionRequest request) {
1989 return mRemoteConnectionManager.createRemoteConnection(
1990 connectionManagerPhoneAccount, request, true);
Santos Cordon52d8a152014-06-17 19:08:45 -07001991 }
1992
1993 /**
Ihab Awadf8b69882014-07-25 15:14:01 -07001994 * Ask some other {@code ConnectionService} to create a {@code RemoteConnection} given an
Santos Cordona663f862014-10-29 13:49:58 -07001995 * outgoing request. This is used by {@code ConnectionService}s that are registered with
1996 * {@link PhoneAccount#CAPABILITY_CONNECTION_MANAGER} and want to be able to use the
1997 * SIM-based {@code ConnectionService} to place its outgoing calls.
Ihab Awadf8b69882014-07-25 15:14:01 -07001998 *
1999 * @param connectionManagerPhoneAccount See description at
2000 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
Cuihtlauac ALVARADO0b3b2a52016-09-13 14:49:41 +02002001 * @param request Details about the outgoing call.
Ihab Awadf8b69882014-07-25 15:14:01 -07002002 * @return The {@code Connection} object to satisfy this call, or {@code null} to
2003 * not handle the call.
2004 */
2005 public final RemoteConnection createRemoteOutgoingConnection(
2006 PhoneAccountHandle connectionManagerPhoneAccount,
2007 ConnectionRequest request) {
2008 return mRemoteConnectionManager.createRemoteConnection(
2009 connectionManagerPhoneAccount, request, false);
2010 }
2011
2012 /**
Santos Cordona663f862014-10-29 13:49:58 -07002013 * Indicates to the relevant {@code RemoteConnectionService} that the specified
2014 * {@link RemoteConnection}s should be merged into a conference call.
2015 * <p>
2016 * If the conference request is successful, the method {@link #onRemoteConferenceAdded} will
2017 * be invoked.
2018 *
2019 * @param remoteConnection1 The first of the remote connections to conference.
2020 * @param remoteConnection2 The second of the remote connections to conference.
Ihab Awadb8e85c72014-08-23 20:34:57 -07002021 */
2022 public final void conferenceRemoteConnections(
Santos Cordona663f862014-10-29 13:49:58 -07002023 RemoteConnection remoteConnection1,
2024 RemoteConnection remoteConnection2) {
2025 mRemoteConnectionManager.conferenceRemoteConnections(remoteConnection1, remoteConnection2);
Ihab Awadb8e85c72014-08-23 20:34:57 -07002026 }
2027
2028 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07002029 * Adds a new conference call. When a conference call is created either as a result of an
2030 * explicit request via {@link #onConference} or otherwise, the connection service should supply
2031 * an instance of {@link Conference} by invoking this method. A conference call provided by this
2032 * method will persist until {@link Conference#destroy} is invoked on the conference instance.
2033 *
2034 * @param conference The new conference object.
2035 */
2036 public final void addConference(Conference conference) {
Rekha Kumar07366812015-03-24 16:42:31 -07002037 Log.d(this, "addConference: conference=%s", conference);
2038
Santos Cordon823fd3c2014-08-07 18:35:18 -07002039 String id = addConferenceInternal(conference);
2040 if (id != null) {
2041 List<String> connectionIds = new ArrayList<>(2);
2042 for (Connection connection : conference.getConnections()) {
2043 if (mIdByConnection.containsKey(connection)) {
2044 connectionIds.add(mIdByConnection.get(connection));
2045 }
2046 }
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002047 conference.setTelecomCallId(id);
Santos Cordon823fd3c2014-08-07 18:35:18 -07002048 ParcelableConference parcelableConference = new ParcelableConference(
Nancy Chenea38cca2014-09-05 16:38:49 -07002049 conference.getPhoneAccountHandle(),
Santos Cordon823fd3c2014-08-07 18:35:18 -07002050 conference.getState(),
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002051 conference.getConnectionCapabilities(),
Tyler Gunn720c6642016-03-22 09:02:47 -07002052 conference.getConnectionProperties(),
Tyler Gunncd5d33c2015-01-12 09:02:01 -08002053 connectionIds,
Rekha Kumar07366812015-03-24 16:42:31 -07002054 conference.getVideoProvider() == null ?
2055 null : conference.getVideoProvider().getInterface(),
2056 conference.getVideoState(),
Andrew Lee3e3e2f22015-04-16 13:48:43 -07002057 conference.getConnectTimeMillis(),
Tyler Gunn17541392018-02-01 08:58:38 -08002058 conference.getConnectionStartElapsedRealTime(),
Santos Cordon6b7f9552015-05-27 17:21:45 -07002059 conference.getStatusHints(),
Tyler Gunnac60f952019-05-31 07:23:16 -07002060 conference.getExtras(),
2061 conference.getAddress(),
2062 conference.getAddressPresentation(),
2063 conference.getCallerDisplayName(),
2064 conference.getCallerDisplayNamePresentation());
Andrew Lee0f51da32015-04-16 13:11:55 -07002065
Santos Cordon823fd3c2014-08-07 18:35:18 -07002066 mAdapter.addConferenceCall(id, parcelableConference);
Rekha Kumar07366812015-03-24 16:42:31 -07002067 mAdapter.setVideoProvider(id, conference.getVideoProvider());
2068 mAdapter.setVideoState(id, conference.getVideoState());
Santos Cordon823fd3c2014-08-07 18:35:18 -07002069
2070 // Go through any child calls and set the parent.
2071 for (Connection connection : conference.getConnections()) {
2072 String connectionId = mIdByConnection.get(connection);
2073 if (connectionId != null) {
2074 mAdapter.setIsConferenced(connectionId, id);
2075 }
2076 }
Pengquan Meng70c9885332017-10-02 18:09:03 -07002077 onConferenceAdded(conference);
Santos Cordon823fd3c2014-08-07 18:35:18 -07002078 }
2079 }
2080
2081 /**
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002082 * Adds a connection created by the {@link ConnectionService} and informs telecom of the new
2083 * connection.
2084 *
2085 * @param phoneAccountHandle The phone account handle for the connection.
2086 * @param connection The connection to add.
2087 */
2088 public final void addExistingConnection(PhoneAccountHandle phoneAccountHandle,
2089 Connection connection) {
Tyler Gunn78da7812017-05-09 14:34:57 -07002090 addExistingConnection(phoneAccountHandle, connection, null /* conference */);
2091 }
2092
2093 /**
Pengquan Meng731c1a32017-11-21 18:01:13 -08002094 * Call to inform Telecom that your {@link ConnectionService} has released call resources (e.g
2095 * microphone, camera).
2096 *
Pengquan Menge3bf7e22018-02-22 17:30:04 -08002097 * <p>
2098 * The {@link ConnectionService} will be disconnected when it failed to call this method within
2099 * 5 seconds after {@link #onConnectionServiceFocusLost()} is called.
2100 *
Pengquan Meng731c1a32017-11-21 18:01:13 -08002101 * @see ConnectionService#onConnectionServiceFocusLost()
2102 */
2103 public final void connectionServiceFocusReleased() {
2104 mAdapter.onConnectionServiceFocusReleased();
2105 }
2106
2107 /**
Tyler Gunn78da7812017-05-09 14:34:57 -07002108 * Adds a connection created by the {@link ConnectionService} and informs telecom of the new
2109 * connection.
2110 *
2111 * @param phoneAccountHandle The phone account handle for the connection.
2112 * @param connection The connection to add.
2113 * @param conference The parent conference of the new connection.
2114 * @hide
2115 */
2116 public final void addExistingConnection(PhoneAccountHandle phoneAccountHandle,
2117 Connection connection, Conference conference) {
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002118
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002119 String id = addExistingConnectionInternal(phoneAccountHandle, connection);
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002120 if (id != null) {
2121 List<String> emptyList = new ArrayList<>(0);
Tyler Gunn78da7812017-05-09 14:34:57 -07002122 String conferenceId = null;
2123 if (conference != null) {
2124 conferenceId = mIdByConference.get(conference);
2125 }
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002126
2127 ParcelableConnection parcelableConnection = new ParcelableConnection(
2128 phoneAccountHandle,
2129 connection.getState(),
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002130 connection.getConnectionCapabilities(),
Tyler Gunn720c6642016-03-22 09:02:47 -07002131 connection.getConnectionProperties(),
Christine Hallstrom2830ce92016-11-30 16:06:42 -08002132 connection.getSupportedAudioRoutes(),
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002133 connection.getAddress(),
2134 connection.getAddressPresentation(),
2135 connection.getCallerDisplayName(),
2136 connection.getCallerDisplayNamePresentation(),
2137 connection.getVideoProvider() == null ?
2138 null : connection.getVideoProvider().getInterface(),
2139 connection.getVideoState(),
2140 connection.isRingbackRequested(),
2141 connection.getAudioModeIsVoip(),
Roshan Piuse927ec02015-07-15 15:47:21 -07002142 connection.getConnectTimeMillis(),
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002143 connection.getConnectElapsedTimeMillis(),
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002144 connection.getStatusHints(),
2145 connection.getDisconnectCause(),
Santos Cordon6b7f9552015-05-27 17:21:45 -07002146 emptyList,
Tyler Gunn78da7812017-05-09 14:34:57 -07002147 connection.getExtras(),
Tyler Gunn6986a632019-06-25 13:45:32 -07002148 conferenceId,
2149 connection.getCallDirection());
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002150 mAdapter.addExistingConnection(id, parcelableConnection);
2151 }
2152 }
2153
2154 /**
Ihab Awadf8b69882014-07-25 15:14:01 -07002155 * Returns all the active {@code Connection}s for which this {@code ConnectionService}
2156 * has taken responsibility.
2157 *
2158 * @return A collection of {@code Connection}s created by this {@code ConnectionService}.
Santos Cordonb6939982014-06-04 20:20:58 -07002159 */
Sailesh Nepal091768c2014-06-30 15:15:23 -07002160 public final Collection<Connection> getAllConnections() {
Santos Cordonb6939982014-06-04 20:20:58 -07002161 return mConnectionById.values();
2162 }
2163
2164 /**
Santos Cordona6018b92016-02-16 14:23:12 -08002165 * Returns all the active {@code Conference}s for which this {@code ConnectionService}
2166 * has taken responsibility.
2167 *
2168 * @return A collection of {@code Conference}s created by this {@code ConnectionService}.
2169 */
2170 public final Collection<Conference> getAllConferences() {
2171 return mConferenceById.values();
2172 }
2173
2174 /**
Ihab Awadf8b69882014-07-25 15:14:01 -07002175 * Create a {@code Connection} given an incoming request. This is used to attach to existing
2176 * incoming calls.
Evan Charltonbf11f982014-07-20 22:06:28 -07002177 *
Ihab Awadf8b69882014-07-25 15:14:01 -07002178 * @param connectionManagerPhoneAccount See description at
2179 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
2180 * @param request Details about the incoming call.
2181 * @return The {@code Connection} object to satisfy this call, or {@code null} to
2182 * not handle the call.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002183 */
Ihab Awadf8b69882014-07-25 15:14:01 -07002184 public Connection onCreateIncomingConnection(
2185 PhoneAccountHandle connectionManagerPhoneAccount,
2186 ConnectionRequest request) {
2187 return null;
2188 }
Sailesh Nepalc5b01572014-07-14 16:29:44 -07002189
2190 /**
Tyler Gunn041a1fe2017-05-12 10:04:49 -07002191 * Called after the {@link Connection} returned by
2192 * {@link #onCreateIncomingConnection(PhoneAccountHandle, ConnectionRequest)}
2193 * or {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)} has been
2194 * added to the {@link ConnectionService} and sent to Telecom.
2195 *
2196 * @param connection the {@link Connection}.
2197 * @hide
2198 */
2199 public void onCreateConnectionComplete(Connection connection) {
2200 }
2201
2202 /**
Tyler Gunnf5035432017-01-09 09:43:12 -08002203 * Called by Telecom to inform the {@link ConnectionService} that its request to create a new
2204 * incoming {@link Connection} was denied.
2205 * <p>
2206 * Used when a self-managed {@link ConnectionService} attempts to create a new incoming
2207 * {@link Connection}, but Telecom has determined that the call cannot be allowed at this time.
2208 * The {@link ConnectionService} is responsible for silently rejecting the new incoming
2209 * {@link Connection}.
2210 * <p>
2211 * See {@link TelecomManager#isIncomingCallPermitted(PhoneAccountHandle)} for more information.
2212 *
Tyler Gunn159f35c2017-03-02 09:28:37 -08002213 * @param connectionManagerPhoneAccount See description at
2214 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
Tyler Gunnf5035432017-01-09 09:43:12 -08002215 * @param request The incoming connection request.
2216 */
Tyler Gunn159f35c2017-03-02 09:28:37 -08002217 public void onCreateIncomingConnectionFailed(PhoneAccountHandle connectionManagerPhoneAccount,
2218 ConnectionRequest request) {
Tyler Gunnf5035432017-01-09 09:43:12 -08002219 }
2220
2221 /**
2222 * Called by Telecom to inform the {@link ConnectionService} that its request to create a new
2223 * outgoing {@link Connection} was denied.
2224 * <p>
2225 * Used when a self-managed {@link ConnectionService} attempts to create a new outgoing
2226 * {@link Connection}, but Telecom has determined that the call cannot be placed at this time.
2227 * The {@link ConnectionService} is responisible for informing the user that the
2228 * {@link Connection} cannot be made at this time.
2229 * <p>
2230 * See {@link TelecomManager#isOutgoingCallPermitted(PhoneAccountHandle)} for more information.
2231 *
Tyler Gunn159f35c2017-03-02 09:28:37 -08002232 * @param connectionManagerPhoneAccount See description at
2233 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
Tyler Gunnf5035432017-01-09 09:43:12 -08002234 * @param request The outgoing connection request.
2235 */
Tyler Gunn159f35c2017-03-02 09:28:37 -08002236 public void onCreateOutgoingConnectionFailed(PhoneAccountHandle connectionManagerPhoneAccount,
2237 ConnectionRequest request) {
Tyler Gunnf5035432017-01-09 09:43:12 -08002238 }
2239
2240 /**
Shriram Ganesh6bf35ac2014-12-11 17:53:38 -08002241 * Trigger recalculate functinality for conference calls. This is used when a Telephony
2242 * Connection is part of a conference controller but is not yet added to Connection
2243 * Service and hence cannot be added to the conference call.
2244 *
2245 * @hide
2246 */
2247 public void triggerConferenceRecalculate() {
2248 }
2249
2250 /**
Ihab Awadf8b69882014-07-25 15:14:01 -07002251 * Create a {@code Connection} given an outgoing request. This is used to initiate new
2252 * outgoing calls.
Sailesh Nepalc5b01572014-07-14 16:29:44 -07002253 *
Ihab Awadf8b69882014-07-25 15:14:01 -07002254 * @param connectionManagerPhoneAccount The connection manager account to use for managing
2255 * this call.
2256 * <p>
2257 * If this parameter is not {@code null}, it means that this {@code ConnectionService}
2258 * has registered one or more {@code PhoneAccount}s having
2259 * {@link PhoneAccount#CAPABILITY_CONNECTION_MANAGER}. This parameter will contain
2260 * one of these {@code PhoneAccount}s, while the {@code request} will contain another
2261 * (usually but not always distinct) {@code PhoneAccount} to be used for actually
2262 * making the connection.
2263 * <p>
2264 * If this parameter is {@code null}, it means that this {@code ConnectionService} is
2265 * being asked to make a direct connection. The
2266 * {@link ConnectionRequest#getAccountHandle()} of parameter {@code request} will be
2267 * a {@code PhoneAccount} registered by this {@code ConnectionService} to use for
2268 * making the connection.
2269 * @param request Details about the outgoing call.
2270 * @return The {@code Connection} object to satisfy this call, or the result of an invocation
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002271 * of {@link Connection#createFailedConnection(DisconnectCause)} to not handle the call.
Sailesh Nepalc5b01572014-07-14 16:29:44 -07002272 */
Ihab Awadf8b69882014-07-25 15:14:01 -07002273 public Connection onCreateOutgoingConnection(
2274 PhoneAccountHandle connectionManagerPhoneAccount,
2275 ConnectionRequest request) {
2276 return null;
2277 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002278
2279 /**
Tyler Gunn9d127732018-03-02 15:45:51 -08002280 * Called by Telecom to request that a {@link ConnectionService} creates an instance of an
2281 * outgoing handover {@link Connection}.
2282 * <p>
2283 * A call handover is the process where an ongoing call is transferred from one app (i.e.
2284 * {@link ConnectionService} to another app. The user could, for example, choose to continue a
2285 * mobile network call in a video calling app. The mobile network call via the Telephony stack
2286 * is referred to as the source of the handover, and the video calling app is referred to as the
2287 * destination.
2288 * <p>
2289 * When considering a handover scenario the <em>initiating</em> device is where a user initiated
2290 * the handover process (e.g. by calling {@link android.telecom.Call#handoverTo(
2291 * PhoneAccountHandle, int, Bundle)}, and the other device is considered the <em>receiving</em>
2292 * device.
2293 * <p>
2294 * This method is called on the destination {@link ConnectionService} on <em>initiating</em>
2295 * device when the user initiates a handover request from one app to another. The user request
2296 * originates in the {@link InCallService} via
2297 * {@link android.telecom.Call#handoverTo(PhoneAccountHandle, int, Bundle)}.
2298 * <p>
2299 * For a full discussion of the handover process and the APIs involved, see
2300 * {@link android.telecom.Call#handoverTo(PhoneAccountHandle, int, Bundle)}.
2301 * <p>
2302 * Implementations of this method should return an instance of {@link Connection} which
2303 * represents the handover. If your app does not wish to accept a handover to it at this time,
2304 * you can return {@code null}. The code below shows an example of how this is done.
2305 * <pre>
2306 * {@code
2307 * public Connection onCreateIncomingHandoverConnection(PhoneAccountHandle
2308 * fromPhoneAccountHandle, ConnectionRequest request) {
2309 * if (!isHandoverAvailable()) {
2310 * return null;
2311 * }
2312 * MyConnection connection = new MyConnection();
2313 * connection.setAddress(request.getAddress(), TelecomManager.PRESENTATION_ALLOWED);
2314 * connection.setVideoState(request.getVideoState());
2315 * return connection;
2316 * }
2317 * }
2318 * </pre>
2319 *
Sanket Padawea8eddd42017-11-03 11:07:35 -07002320 * @param fromPhoneAccountHandle {@link PhoneAccountHandle} associated with the
2321 * ConnectionService which needs to handover the call.
Tyler Gunn9d127732018-03-02 15:45:51 -08002322 * @param request Details about the call to handover.
2323 * @return {@link Connection} instance corresponding to the handover call.
Sanket Padawea8eddd42017-11-03 11:07:35 -07002324 */
2325 public Connection onCreateOutgoingHandoverConnection(PhoneAccountHandle fromPhoneAccountHandle,
2326 ConnectionRequest request) {
2327 return null;
2328 }
2329
2330 /**
Tyler Gunn9d127732018-03-02 15:45:51 -08002331 * Called by Telecom to request that a {@link ConnectionService} creates an instance of an
2332 * incoming handover {@link Connection}.
2333 * <p>
2334 * A call handover is the process where an ongoing call is transferred from one app (i.e.
2335 * {@link ConnectionService} to another app. The user could, for example, choose to continue a
2336 * mobile network call in a video calling app. The mobile network call via the Telephony stack
2337 * is referred to as the source of the handover, and the video calling app is referred to as the
2338 * destination.
2339 * <p>
2340 * When considering a handover scenario the <em>initiating</em> device is where a user initiated
2341 * the handover process (e.g. by calling {@link android.telecom.Call#handoverTo(
2342 * PhoneAccountHandle, int, Bundle)}, and the other device is considered the <em>receiving</em>
2343 * device.
2344 * <p>
2345 * This method is called on the destination app on the <em>receiving</em> device when the
2346 * destination app calls {@link TelecomManager#acceptHandover(Uri, int, PhoneAccountHandle)} to
2347 * accept an incoming handover from the <em>initiating</em> device.
2348 * <p>
2349 * For a full discussion of the handover process and the APIs involved, see
2350 * {@link android.telecom.Call#handoverTo(PhoneAccountHandle, int, Bundle)}.
2351 * <p>
2352 * Implementations of this method should return an instance of {@link Connection} which
2353 * represents the handover. The code below shows an example of how this is done.
2354 * <pre>
2355 * {@code
2356 * public Connection onCreateIncomingHandoverConnection(PhoneAccountHandle
2357 * fromPhoneAccountHandle, ConnectionRequest request) {
2358 * // Given that your app requested to accept the handover, you should not return null here.
2359 * MyConnection connection = new MyConnection();
2360 * connection.setAddress(request.getAddress(), TelecomManager.PRESENTATION_ALLOWED);
2361 * connection.setVideoState(request.getVideoState());
2362 * return connection;
2363 * }
2364 * }
2365 * </pre>
2366 *
Sanket Padawea8eddd42017-11-03 11:07:35 -07002367 * @param fromPhoneAccountHandle {@link PhoneAccountHandle} associated with the
2368 * ConnectionService which needs to handover the call.
2369 * @param request Details about the call which needs to be handover.
Tyler Gunn9d127732018-03-02 15:45:51 -08002370 * @return {@link Connection} instance corresponding to the handover call.
Sanket Padawea8eddd42017-11-03 11:07:35 -07002371 */
2372 public Connection onCreateIncomingHandoverConnection(PhoneAccountHandle fromPhoneAccountHandle,
2373 ConnectionRequest request) {
2374 return null;
2375 }
2376
2377 /**
2378 * Called by Telecom in response to a {@code TelecomManager#acceptHandover()}
2379 * invocation which failed.
Tyler Gunn9d127732018-03-02 15:45:51 -08002380 * <p>
2381 * For a full discussion of the handover process and the APIs involved, see
2382 * {@link android.telecom.Call#handoverTo(PhoneAccountHandle, int, Bundle)}
2383 *
2384 * @param request Details about the call which failed to handover.
2385 * @param error Reason for handover failure. Will be one of the
Sanket Padawea8eddd42017-11-03 11:07:35 -07002386 */
Tyler Gunn9d127732018-03-02 15:45:51 -08002387 public void onHandoverFailed(ConnectionRequest request,
2388 @Call.Callback.HandoverFailureErrors int error) {
Sanket Padawea8eddd42017-11-03 11:07:35 -07002389 return;
2390 }
2391
2392 /**
Yorke Leec3cf9822014-10-02 09:38:39 -07002393 * Create a {@code Connection} for a new unknown call. An unknown call is a call originating
2394 * from the ConnectionService that was neither a user-initiated outgoing call, nor an incoming
2395 * call created using
2396 * {@code TelecomManager#addNewIncomingCall(PhoneAccountHandle, android.os.Bundle)}.
2397 *
Yorke Lee770ed6e2014-10-06 18:58:52 -07002398 * @hide
Yorke Leec3cf9822014-10-02 09:38:39 -07002399 */
2400 public Connection onCreateUnknownConnection(PhoneAccountHandle connectionManagerPhoneAccount,
2401 ConnectionRequest request) {
Brad Ebingerb32d4f82016-10-24 16:40:49 -07002402 return null;
Yorke Leec3cf9822014-10-02 09:38:39 -07002403 }
2404
2405 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07002406 * Conference two specified connections. Invoked when the user has made a request to merge the
2407 * specified connections into a conference call. In response, the connection service should
2408 * create an instance of {@link Conference} and pass it into {@link #addConference}.
Santos Cordonb6939982014-06-04 20:20:58 -07002409 *
Santos Cordon823fd3c2014-08-07 18:35:18 -07002410 * @param connection1 A connection to merge into a conference call.
2411 * @param connection2 A connection to merge into a conference call.
Santos Cordonb6939982014-06-04 20:20:58 -07002412 */
Santos Cordon823fd3c2014-08-07 18:35:18 -07002413 public void onConference(Connection connection1, Connection connection2) {}
Santos Cordonb6939982014-06-04 20:20:58 -07002414
Santos Cordona663f862014-10-29 13:49:58 -07002415 /**
Pengquan Meng70c9885332017-10-02 18:09:03 -07002416 * Called when a connection is added.
2417 * @hide
2418 */
2419 public void onConnectionAdded(Connection connection) {}
2420
2421 /**
2422 * Called when a connection is removed.
2423 * @hide
2424 */
2425 public void onConnectionRemoved(Connection connection) {}
2426
2427 /**
2428 * Called when a conference is added.
2429 * @hide
2430 */
2431 public void onConferenceAdded(Conference conference) {}
2432
2433 /**
2434 * Called when a conference is removed.
2435 * @hide
2436 */
2437 public void onConferenceRemoved(Conference conference) {}
2438
2439 /**
Santos Cordona663f862014-10-29 13:49:58 -07002440 * Indicates that a remote conference has been created for existing {@link RemoteConnection}s.
2441 * When this method is invoked, this {@link ConnectionService} should create its own
2442 * representation of the conference call and send it to telecom using {@link #addConference}.
2443 * <p>
2444 * This is only relevant to {@link ConnectionService}s which are registered with
2445 * {@link PhoneAccount#CAPABILITY_CONNECTION_MANAGER}.
2446 *
2447 * @param conference The remote conference call.
2448 */
Ihab Awadb8e85c72014-08-23 20:34:57 -07002449 public void onRemoteConferenceAdded(RemoteConference conference) {}
2450
Santos Cordon823fd3c2014-08-07 18:35:18 -07002451 /**
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002452 * Called when an existing connection is added remotely.
2453 * @param connection The existing connection which was added.
2454 */
2455 public void onRemoteExistingConnectionAdded(RemoteConnection connection) {}
2456
2457 /**
Pengquan Meng731c1a32017-11-21 18:01:13 -08002458 * Called when the {@link ConnectionService} has lost the call focus.
2459 * The {@link ConnectionService} should release the call resources and invokes
2460 * {@link ConnectionService#connectionServiceFocusReleased()} to inform telecom that it has
2461 * released the call resources.
2462 */
2463 public void onConnectionServiceFocusLost() {}
2464
2465 /**
2466 * Called when the {@link ConnectionService} has gained the call focus. The
2467 * {@link ConnectionService} can acquire the call resources at this time.
2468 */
2469 public void onConnectionServiceFocusGained() {}
2470
2471 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07002472 * @hide
2473 */
2474 public boolean containsConference(Conference conference) {
2475 return mIdByConference.containsKey(conference);
2476 }
2477
Ihab Awadb8e85c72014-08-23 20:34:57 -07002478 /** {@hide} */
2479 void addRemoteConference(RemoteConference remoteConference) {
2480 onRemoteConferenceAdded(remoteConference);
2481 }
2482
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002483 /** {@hide} */
2484 void addRemoteExistingConnection(RemoteConnection remoteConnection) {
2485 onRemoteExistingConnectionAdded(remoteConnection);
2486 }
2487
Ihab Awad5d0410f2014-07-30 10:07:40 -07002488 private void onAccountsInitialized() {
2489 mAreAccountsInitialized = true;
2490 for (Runnable r : mPreInitializationConnectionRequests) {
2491 r.run();
2492 }
2493 mPreInitializationConnectionRequests.clear();
2494 }
2495
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002496 /**
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002497 * Adds an existing connection to the list of connections, identified by a new call ID unique
2498 * to this connection service.
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002499 *
2500 * @param connection The connection.
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002501 * @return The ID of the connection (e.g. the call-id).
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002502 */
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002503 private String addExistingConnectionInternal(PhoneAccountHandle handle, Connection connection) {
2504 String id;
Tyler Gunncd6ccfd2016-10-17 15:48:19 -07002505
2506 if (connection.getExtras() != null && connection.getExtras()
2507 .containsKey(Connection.EXTRA_ORIGINAL_CONNECTION_ID)) {
2508 id = connection.getExtras().getString(Connection.EXTRA_ORIGINAL_CONNECTION_ID);
2509 Log.d(this, "addExistingConnectionInternal - conn %s reusing original id %s",
2510 connection.getTelecomCallId(), id);
2511 } else if (handle == null) {
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002512 // If no phone account handle was provided, we cannot be sure the call ID is unique,
2513 // so just use a random UUID.
2514 id = UUID.randomUUID().toString();
2515 } else {
2516 // Phone account handle was provided, so use the ConnectionService class name as a
2517 // prefix for a unique incremental call ID.
2518 id = handle.getComponentName().getClassName() + "@" + getNextCallId();
2519 }
Pengquan Meng70c9885332017-10-02 18:09:03 -07002520 addConnection(handle, id, connection);
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002521 return id;
2522 }
2523
Pengquan Meng70c9885332017-10-02 18:09:03 -07002524 private void addConnection(PhoneAccountHandle handle, String callId, Connection connection) {
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002525 connection.setTelecomCallId(callId);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002526 mConnectionById.put(callId, connection);
2527 mIdByConnection.put(connection, callId);
2528 connection.addConnectionListener(mConnectionListener);
Santos Cordon823fd3c2014-08-07 18:35:18 -07002529 connection.setConnectionService(this);
Pengquan Meng70c9885332017-10-02 18:09:03 -07002530 connection.setPhoneAccountHandle(handle);
2531 onConnectionAdded(connection);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002532 }
2533
Anthony Lee30e65842014-11-06 16:30:53 -08002534 /** {@hide} */
2535 protected void removeConnection(Connection connection) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07002536 connection.unsetConnectionService(this);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002537 connection.removeConnectionListener(mConnectionListener);
Chenjie Luoe370b532016-05-12 16:59:43 -07002538 String id = mIdByConnection.get(connection);
2539 if (id != null) {
2540 mConnectionById.remove(id);
2541 mIdByConnection.remove(connection);
2542 mAdapter.removeCall(id);
Pengquan Meng70c9885332017-10-02 18:09:03 -07002543 onConnectionRemoved(connection);
Chenjie Luoe370b532016-05-12 16:59:43 -07002544 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002545 }
2546
Santos Cordon823fd3c2014-08-07 18:35:18 -07002547 private String addConferenceInternal(Conference conference) {
Tyler Gunncd6ccfd2016-10-17 15:48:19 -07002548 String originalId = null;
2549 if (conference.getExtras() != null && conference.getExtras()
2550 .containsKey(Connection.EXTRA_ORIGINAL_CONNECTION_ID)) {
2551 originalId = conference.getExtras().getString(Connection.EXTRA_ORIGINAL_CONNECTION_ID);
2552 Log.d(this, "addConferenceInternal: conf %s reusing original id %s",
2553 conference.getTelecomCallId(),
2554 originalId);
2555 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07002556 if (mIdByConference.containsKey(conference)) {
2557 Log.w(this, "Re-adding an existing conference: %s.", conference);
2558 } else if (conference != null) {
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002559 // Conferences do not (yet) have a PhoneAccountHandle associated with them, so we
2560 // cannot determine a ConnectionService class name to associate with the ID, so use
2561 // a unique UUID (for now).
Tyler Gunncd6ccfd2016-10-17 15:48:19 -07002562 String id = originalId == null ? UUID.randomUUID().toString() : originalId;
Santos Cordon823fd3c2014-08-07 18:35:18 -07002563 mConferenceById.put(id, conference);
2564 mIdByConference.put(conference, id);
2565 conference.addListener(mConferenceListener);
2566 return id;
2567 }
2568
2569 return null;
2570 }
2571
2572 private void removeConference(Conference conference) {
2573 if (mIdByConference.containsKey(conference)) {
2574 conference.removeListener(mConferenceListener);
2575
2576 String id = mIdByConference.get(conference);
2577 mConferenceById.remove(id);
2578 mIdByConference.remove(conference);
2579 mAdapter.removeCall(id);
Pengquan Meng70c9885332017-10-02 18:09:03 -07002580
2581 onConferenceRemoved(conference);
Santos Cordon823fd3c2014-08-07 18:35:18 -07002582 }
2583 }
2584
Ihab Awad542e0ea2014-05-16 10:22:16 -07002585 private Connection findConnectionForAction(String callId, String action) {
Tyler Gunn0a88f2e2017-06-16 20:20:34 -07002586 if (callId != null && mConnectionById.containsKey(callId)) {
Ihab Awad542e0ea2014-05-16 10:22:16 -07002587 return mConnectionById.get(callId);
2588 }
Ihab Awad60ac30b2014-05-20 22:32:12 -07002589 Log.w(this, "%s - Cannot find Connection %s", action, callId);
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07002590 return getNullConnection();
2591 }
2592
2593 static synchronized Connection getNullConnection() {
2594 if (sNullConnection == null) {
2595 sNullConnection = new Connection() {};
2596 }
2597 return sNullConnection;
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002598 }
Santos Cordon0159ac02014-08-21 14:28:11 -07002599
2600 private Conference findConferenceForAction(String conferenceId, String action) {
2601 if (mConferenceById.containsKey(conferenceId)) {
2602 return mConferenceById.get(conferenceId);
2603 }
2604 Log.w(this, "%s - Cannot find conference %s", action, conferenceId);
2605 return getNullConference();
2606 }
2607
Ihab Awadb8e85c72014-08-23 20:34:57 -07002608 private List<String> createConnectionIdList(List<Connection> connections) {
2609 List<String> ids = new ArrayList<>();
2610 for (Connection c : connections) {
2611 if (mIdByConnection.containsKey(c)) {
2612 ids.add(mIdByConnection.get(c));
2613 }
2614 }
2615 Collections.sort(ids);
2616 return ids;
2617 }
2618
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002619 /**
2620 * Builds a list of {@link Connection} and {@link Conference} IDs based on the list of
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002621 * {@link Conferenceable}s passed in.
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002622 *
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002623 * @param conferenceables The {@link Conferenceable} connections and conferences.
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002624 * @return List of string conference and call Ids.
2625 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002626 private List<String> createIdList(List<Conferenceable> conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002627 List<String> ids = new ArrayList<>();
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002628 for (Conferenceable c : conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002629 // Only allow Connection and Conference conferenceables.
2630 if (c instanceof Connection) {
2631 Connection connection = (Connection) c;
2632 if (mIdByConnection.containsKey(connection)) {
2633 ids.add(mIdByConnection.get(connection));
2634 }
2635 } else if (c instanceof Conference) {
2636 Conference conference = (Conference) c;
2637 if (mIdByConference.containsKey(conference)) {
2638 ids.add(mIdByConference.get(conference));
2639 }
2640 }
2641 }
2642 Collections.sort(ids);
2643 return ids;
2644 }
2645
Santos Cordon0159ac02014-08-21 14:28:11 -07002646 private Conference getNullConference() {
2647 if (sNullConference == null) {
2648 sNullConference = new Conference(null) {};
2649 }
2650 return sNullConference;
2651 }
Santos Cordon29f2f2e2014-09-11 19:50:24 -07002652
2653 private void endAllConnections() {
2654 // Unbound from telecomm. We should end all connections and conferences.
2655 for (Connection connection : mIdByConnection.keySet()) {
2656 // only operate on top-level calls. Conference calls will be removed on their own.
2657 if (connection.getConference() == null) {
2658 connection.onDisconnect();
2659 }
2660 }
2661 for (Conference conference : mIdByConference.keySet()) {
2662 conference.onDisconnect();
2663 }
2664 }
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002665
2666 /**
2667 * Retrieves the next call ID as maintainted by the connection service.
2668 *
2669 * @return The call ID.
2670 */
2671 private int getNextCallId() {
Brad Ebingerb32d4f82016-10-24 16:40:49 -07002672 synchronized (mIdSyncRoot) {
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002673 return ++mId;
2674 }
2675 }
Brad Ebinger99f17ce2019-09-11 18:06:51 -07002676
2677 /**
2678 * Returns this handler, ONLY FOR TESTING.
2679 * @hide
2680 */
2681 @VisibleForTesting
2682 public Handler getHandler() {
2683 return mHandler;
2684 }
Santos Cordon980acb92014-05-31 10:31:19 -07002685}