blob: 35488100fb580cd622053e5fe3f4a01ab6be398f [file] [log] [blame]
Ihab Awad542e0ea2014-05-16 10:22:16 -07001/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Tyler Gunnef9f6f92014-09-12 22:16:17 -070017package android.telecom;
Ihab Awad542e0ea2014-05-16 10:22:16 -070018
Santos Cordon5c6fa952014-07-20 17:47:12 -070019import android.annotation.SdkConstant;
Sailesh Nepal2a46b902014-07-04 17:21:07 -070020import android.app.Service;
Santos Cordon52d8a152014-06-17 19:08:45 -070021import android.content.ComponentName;
Santos Cordon5c6fa952014-07-20 17:47:12 -070022import android.content.Intent;
Ihab Awad542e0ea2014-05-16 10:22:16 -070023import android.net.Uri;
Santos Cordon6b7f9552015-05-27 17:21:45 -070024import android.os.Bundle;
Santos Cordon52d8a152014-06-17 19:08:45 -070025import android.os.Handler;
26import android.os.IBinder;
27import android.os.Looper;
Sailesh Nepal2a46b902014-07-04 17:21:07 -070028import android.os.Message;
Hall Liub64ac4c2017-02-06 10:49:48 -080029import android.os.ParcelFileDescriptor;
30import android.os.RemoteException;
Brad Ebingerb32d4f82016-10-24 16:40:49 -070031import android.telecom.Logging.Session;
Andrew Lee14185762014-07-25 09:41:56 -070032
Sailesh Nepal2a46b902014-07-04 17:21:07 -070033import com.android.internal.os.SomeArgs;
Tyler Gunnef9f6f92014-09-12 22:16:17 -070034import com.android.internal.telecom.IConnectionService;
35import com.android.internal.telecom.IConnectionServiceAdapter;
36import com.android.internal.telecom.RemoteServiceCallback;
Santos Cordon52d8a152014-06-17 19:08:45 -070037
Ihab Awad5d0410f2014-07-30 10:07:40 -070038import java.util.ArrayList;
Santos Cordonb6939982014-06-04 20:20:58 -070039import java.util.Collection;
Santos Cordon7c7bc7f2014-07-28 18:15:48 -070040import java.util.Collections;
Santos Cordon52d8a152014-06-17 19:08:45 -070041import java.util.List;
Ihab Awad542e0ea2014-05-16 10:22:16 -070042import java.util.Map;
Santos Cordon823fd3c2014-08-07 18:35:18 -070043import java.util.UUID;
mike dooley95e80702014-09-18 14:07:52 -070044import java.util.concurrent.ConcurrentHashMap;
Ihab Awad542e0ea2014-05-16 10:22:16 -070045
46/**
Tyler Gunnf5035432017-01-09 09:43:12 -080047 * An abstract service that should be implemented by any apps which either:
48 * <ol>
49 * <li>Can make phone calls (VoIP or otherwise) and want those calls to be integrated into the
50 * built-in phone app. Referred to as a <b>system managed</b> {@link ConnectionService}.</li>
51 * <li>Are a standalone calling app and don't want their calls to be integrated into the
52 * built-in phone app. Referred to as a <b>self managed</b> {@link ConnectionService}.</li>
53 * </ol>
54 * Once implemented, the {@link ConnectionService} needs to take the following steps so that Telecom
55 * will bind to it:
Santos Cordona663f862014-10-29 13:49:58 -070056 * <p>
57 * 1. <i>Registration in AndroidManifest.xml</i>
58 * <br/>
59 * <pre>
60 * &lt;service android:name="com.example.package.MyConnectionService"
61 * android:label="@string/some_label_for_my_connection_service"
Yorke Lee249c12e2015-05-13 15:59:29 -070062 * android:permission="android.permission.BIND_TELECOM_CONNECTION_SERVICE"&gt;
Santos Cordona663f862014-10-29 13:49:58 -070063 * &lt;intent-filter&gt;
64 * &lt;action android:name="android.telecom.ConnectionService" /&gt;
65 * &lt;/intent-filter&gt;
66 * &lt;/service&gt;
67 * </pre>
68 * <p>
69 * 2. <i> Registration of {@link PhoneAccount} with {@link TelecomManager}.</i>
70 * <br/>
71 * See {@link PhoneAccount} and {@link TelecomManager#registerPhoneAccount} for more information.
72 * <p>
Tyler Gunnf5035432017-01-09 09:43:12 -080073 * System managed {@link ConnectionService}s must be enabled by the user in the phone app settings
kopriva82c591b2018-10-08 15:57:00 -070074 * before Telecom will bind to them. Self-managed {@link ConnectionService}s must be granted the
Tyler Gunnf5035432017-01-09 09:43:12 -080075 * appropriate permission before Telecom will bind to them.
76 * <p>
77 * Once registered and enabled by the user in the phone app settings or granted permission, telecom
78 * will bind to a {@link ConnectionService} implementation when it wants that
79 * {@link ConnectionService} to place a call or the service has indicated that is has an incoming
80 * call through {@link TelecomManager#addNewIncomingCall}. The {@link ConnectionService} can then
81 * expect a call to {@link #onCreateIncomingConnection} or {@link #onCreateOutgoingConnection}
82 * wherein it should provide a new instance of a {@link Connection} object. It is through this
83 * {@link Connection} object that telecom receives state updates and the {@link ConnectionService}
Santos Cordona663f862014-10-29 13:49:58 -070084 * receives call-commands such as answer, reject, hold and disconnect.
85 * <p>
Tyler Gunnf5035432017-01-09 09:43:12 -080086 * When there are no more live calls, telecom will unbind from the {@link ConnectionService}.
Ihab Awad542e0ea2014-05-16 10:22:16 -070087 */
Sailesh Nepal2a46b902014-07-04 17:21:07 -070088public abstract class ConnectionService extends Service {
Santos Cordon5c6fa952014-07-20 17:47:12 -070089 /**
90 * The {@link Intent} that must be declared as handled by the service.
91 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -070092 @SdkConstant(SdkConstant.SdkConstantType.SERVICE_ACTION)
Tyler Gunnef9f6f92014-09-12 22:16:17 -070093 public static final String SERVICE_INTERFACE = "android.telecom.ConnectionService";
Santos Cordon5c6fa952014-07-20 17:47:12 -070094
Tyler Gunn8bf76572017-04-06 15:30:08 -070095 /**
96 * Boolean extra used by Telecom to inform a {@link ConnectionService} that the purpose of it
97 * being asked to create a new outgoing {@link Connection} is to perform a handover of an
98 * ongoing call on the device from another {@link PhoneAccount}/{@link ConnectionService}. Will
99 * be specified in the {@link ConnectionRequest#getExtras()} passed by Telecom when
100 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)} is called.
101 * <p>
Tyler Gunn727c6bd2017-04-11 09:51:40 -0700102 * When your {@link ConnectionService} receives this extra, it should communicate the fact that
103 * this is a handover to the other device's matching {@link ConnectionService}. That
Tyler Gunn8bf76572017-04-06 15:30:08 -0700104 * {@link ConnectionService} will continue the handover using
105 * {@link TelecomManager#addNewIncomingCall(PhoneAccountHandle, Bundle)}, specifying
Tyler Gunn727c6bd2017-04-11 09:51:40 -0700106 * {@link TelecomManager#EXTRA_IS_HANDOVER}. Telecom will match the phone numbers of the
107 * handover call on the other device with ongoing calls for {@link ConnectionService}s which
108 * support {@link PhoneAccount#EXTRA_SUPPORTS_HANDOVER_FROM}.
Tyler Gunn8bf76572017-04-06 15:30:08 -0700109 * @hide
110 */
111 public static final String EXTRA_IS_HANDOVER = TelecomManager.EXTRA_IS_HANDOVER;
112
Ihab Awad542e0ea2014-05-16 10:22:16 -0700113 // Flag controlling whether PII is emitted into the logs
Ihab Awad60ac30b2014-05-20 22:32:12 -0700114 private static final boolean PII_DEBUG = Log.isLoggable(android.util.Log.DEBUG);
Ihab Awad542e0ea2014-05-16 10:22:16 -0700115
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700116 // Session Definitions
117 private static final String SESSION_HANDLER = "H.";
118 private static final String SESSION_ADD_CS_ADAPTER = "CS.aCSA";
119 private static final String SESSION_REMOVE_CS_ADAPTER = "CS.rCSA";
120 private static final String SESSION_CREATE_CONN = "CS.crCo";
Tyler Gunn041a1fe2017-05-12 10:04:49 -0700121 private static final String SESSION_CREATE_CONN_COMPLETE = "CS.crCoC";
Tyler Gunn44e01912017-01-31 10:49:05 -0800122 private static final String SESSION_CREATE_CONN_FAILED = "CS.crCoF";
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700123 private static final String SESSION_ABORT = "CS.ab";
124 private static final String SESSION_ANSWER = "CS.an";
125 private static final String SESSION_ANSWER_VIDEO = "CS.anV";
Pooja Jaind34698d2017-12-28 14:15:31 +0530126 private static final String SESSION_DEFLECT = "CS.def";
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700127 private static final String SESSION_REJECT = "CS.r";
128 private static final String SESSION_REJECT_MESSAGE = "CS.rWM";
129 private static final String SESSION_SILENCE = "CS.s";
130 private static final String SESSION_DISCONNECT = "CS.d";
131 private static final String SESSION_HOLD = "CS.h";
132 private static final String SESSION_UNHOLD = "CS.u";
133 private static final String SESSION_CALL_AUDIO_SC = "CS.cASC";
134 private static final String SESSION_PLAY_DTMF = "CS.pDT";
135 private static final String SESSION_STOP_DTMF = "CS.sDT";
136 private static final String SESSION_CONFERENCE = "CS.c";
137 private static final String SESSION_SPLIT_CONFERENCE = "CS.sFC";
138 private static final String SESSION_MERGE_CONFERENCE = "CS.mC";
139 private static final String SESSION_SWAP_CONFERENCE = "CS.sC";
140 private static final String SESSION_POST_DIAL_CONT = "CS.oPDC";
141 private static final String SESSION_PULL_EXTERNAL_CALL = "CS.pEC";
142 private static final String SESSION_SEND_CALL_EVENT = "CS.sCE";
Tyler Gunn79bc1ec2018-01-22 15:17:54 -0800143 private static final String SESSION_HANDOVER_COMPLETE = "CS.hC";
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700144 private static final String SESSION_EXTRAS_CHANGED = "CS.oEC";
Hall Liub64ac4c2017-02-06 10:49:48 -0800145 private static final String SESSION_START_RTT = "CS.+RTT";
Hall Liua549fed2018-02-09 16:40:03 -0800146 private static final String SESSION_UPDATE_RTT_PIPES = "CS.uRTT";
Hall Liub64ac4c2017-02-06 10:49:48 -0800147 private static final String SESSION_STOP_RTT = "CS.-RTT";
148 private static final String SESSION_RTT_UPGRADE_RESPONSE = "CS.rTRUR";
Pengquan Meng731c1a32017-11-21 18:01:13 -0800149 private static final String SESSION_CONNECTION_SERVICE_FOCUS_LOST = "CS.cSFL";
150 private static final String SESSION_CONNECTION_SERVICE_FOCUS_GAINED = "CS.cSFG";
Sanket Padawe4cc8ed52017-12-04 16:22:20 -0800151 private static final String SESSION_HANDOVER_FAILED = "CS.haF";
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700152
Ihab Awad8aecfed2014-08-08 17:06:11 -0700153 private static final int MSG_ADD_CONNECTION_SERVICE_ADAPTER = 1;
Sailesh Nepalc5b01572014-07-14 16:29:44 -0700154 private static final int MSG_CREATE_CONNECTION = 2;
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700155 private static final int MSG_ABORT = 3;
Sailesh Nepalc5b01572014-07-14 16:29:44 -0700156 private static final int MSG_ANSWER = 4;
157 private static final int MSG_REJECT = 5;
158 private static final int MSG_DISCONNECT = 6;
159 private static final int MSG_HOLD = 7;
160 private static final int MSG_UNHOLD = 8;
Yorke Lee4af59352015-05-13 14:14:54 -0700161 private static final int MSG_ON_CALL_AUDIO_STATE_CHANGED = 9;
Sailesh Nepalc5b01572014-07-14 16:29:44 -0700162 private static final int MSG_PLAY_DTMF_TONE = 10;
163 private static final int MSG_STOP_DTMF_TONE = 11;
164 private static final int MSG_CONFERENCE = 12;
165 private static final int MSG_SPLIT_FROM_CONFERENCE = 13;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700166 private static final int MSG_ON_POST_DIAL_CONTINUE = 14;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700167 private static final int MSG_REMOVE_CONNECTION_SERVICE_ADAPTER = 16;
Tyler Gunnbe74de02014-08-29 14:51:48 -0700168 private static final int MSG_ANSWER_VIDEO = 17;
Santos Cordona4868042014-09-04 17:39:22 -0700169 private static final int MSG_MERGE_CONFERENCE = 18;
170 private static final int MSG_SWAP_CONFERENCE = 19;
Bryce Lee81901682015-08-28 16:38:02 -0700171 private static final int MSG_REJECT_WITH_MESSAGE = 20;
Bryce Leecac50772015-11-17 15:13:29 -0800172 private static final int MSG_SILENCE = 21;
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700173 private static final int MSG_PULL_EXTERNAL_CALL = 22;
174 private static final int MSG_SEND_CALL_EVENT = 23;
Tyler Gunndee56a82016-03-23 16:06:34 -0700175 private static final int MSG_ON_EXTRAS_CHANGED = 24;
Tyler Gunn44e01912017-01-31 10:49:05 -0800176 private static final int MSG_CREATE_CONNECTION_FAILED = 25;
Hall Liub64ac4c2017-02-06 10:49:48 -0800177 private static final int MSG_ON_START_RTT = 26;
178 private static final int MSG_ON_STOP_RTT = 27;
179 private static final int MSG_RTT_UPGRADE_RESPONSE = 28;
Tyler Gunn041a1fe2017-05-12 10:04:49 -0700180 private static final int MSG_CREATE_CONNECTION_COMPLETE = 29;
Pengquan Meng731c1a32017-11-21 18:01:13 -0800181 private static final int MSG_CONNECTION_SERVICE_FOCUS_LOST = 30;
182 private static final int MSG_CONNECTION_SERVICE_FOCUS_GAINED = 31;
Sanket Padawe4cc8ed52017-12-04 16:22:20 -0800183 private static final int MSG_HANDOVER_FAILED = 32;
Tyler Gunn79bc1ec2018-01-22 15:17:54 -0800184 private static final int MSG_HANDOVER_COMPLETE = 33;
Pooja Jaind34698d2017-12-28 14:15:31 +0530185 private static final int MSG_DEFLECT = 34;
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700186
Sailesh Nepalcf7020b2014-08-20 10:07:19 -0700187 private static Connection sNullConnection;
188
mike dooley95e80702014-09-18 14:07:52 -0700189 private final Map<String, Connection> mConnectionById = new ConcurrentHashMap<>();
190 private final Map<Connection, String> mIdByConnection = new ConcurrentHashMap<>();
191 private final Map<String, Conference> mConferenceById = new ConcurrentHashMap<>();
192 private final Map<Conference, String> mIdByConference = new ConcurrentHashMap<>();
Ihab Awadb8e85c72014-08-23 20:34:57 -0700193 private final RemoteConnectionManager mRemoteConnectionManager =
194 new RemoteConnectionManager(this);
Ihab Awad5d0410f2014-07-30 10:07:40 -0700195 private final List<Runnable> mPreInitializationConnectionRequests = new ArrayList<>();
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700196 private final ConnectionServiceAdapter mAdapter = new ConnectionServiceAdapter();
Ihab Awad542e0ea2014-05-16 10:22:16 -0700197
Santos Cordon823fd3c2014-08-07 18:35:18 -0700198 private boolean mAreAccountsInitialized = false;
Santos Cordon0159ac02014-08-21 14:28:11 -0700199 private Conference sNullConference;
Tyler Gunnf0500bd2015-09-01 10:59:48 -0700200 private Object mIdSyncRoot = new Object();
201 private int mId = 0;
Santos Cordon823fd3c2014-08-07 18:35:18 -0700202
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700203 private final IBinder mBinder = new IConnectionService.Stub() {
204 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700205 public void addConnectionServiceAdapter(IConnectionServiceAdapter adapter,
206 Session.Info sessionInfo) {
207 Log.startSession(sessionInfo, SESSION_ADD_CS_ADAPTER);
208 try {
209 SomeArgs args = SomeArgs.obtain();
210 args.arg1 = adapter;
211 args.arg2 = Log.createSubsession();
212 mHandler.obtainMessage(MSG_ADD_CONNECTION_SERVICE_ADAPTER, args).sendToTarget();
213 } finally {
214 Log.endSession();
215 }
Ihab Awad8aecfed2014-08-08 17:06:11 -0700216 }
217
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700218 public void removeConnectionServiceAdapter(IConnectionServiceAdapter adapter,
219 Session.Info sessionInfo) {
220 Log.startSession(sessionInfo, SESSION_REMOVE_CS_ADAPTER);
221 try {
222 SomeArgs args = SomeArgs.obtain();
223 args.arg1 = adapter;
224 args.arg2 = Log.createSubsession();
225 mHandler.obtainMessage(MSG_REMOVE_CONNECTION_SERVICE_ADAPTER, args).sendToTarget();
226 } finally {
227 Log.endSession();
228 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700229 }
230
231 @Override
Ihab Awadf8b69882014-07-25 15:14:01 -0700232 public void createConnection(
233 PhoneAccountHandle connectionManagerPhoneAccount,
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700234 String id,
Ihab Awadf8b69882014-07-25 15:14:01 -0700235 ConnectionRequest request,
Yorke Leec3cf9822014-10-02 09:38:39 -0700236 boolean isIncoming,
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700237 boolean isUnknown,
238 Session.Info sessionInfo) {
239 Log.startSession(sessionInfo, SESSION_CREATE_CONN);
240 try {
241 SomeArgs args = SomeArgs.obtain();
242 args.arg1 = connectionManagerPhoneAccount;
243 args.arg2 = id;
244 args.arg3 = request;
245 args.arg4 = Log.createSubsession();
246 args.argi1 = isIncoming ? 1 : 0;
247 args.argi2 = isUnknown ? 1 : 0;
248 mHandler.obtainMessage(MSG_CREATE_CONNECTION, args).sendToTarget();
249 } finally {
250 Log.endSession();
251 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700252 }
253
254 @Override
Tyler Gunn041a1fe2017-05-12 10:04:49 -0700255 public void createConnectionComplete(String id, Session.Info sessionInfo) {
256 Log.startSession(sessionInfo, SESSION_CREATE_CONN_COMPLETE);
257 try {
258 SomeArgs args = SomeArgs.obtain();
259 args.arg1 = id;
260 args.arg2 = Log.createSubsession();
261 mHandler.obtainMessage(MSG_CREATE_CONNECTION_COMPLETE, args).sendToTarget();
262 } finally {
263 Log.endSession();
264 }
265 }
266
267 @Override
Tyler Gunn44e01912017-01-31 10:49:05 -0800268 public void createConnectionFailed(
Tyler Gunn159f35c2017-03-02 09:28:37 -0800269 PhoneAccountHandle connectionManagerPhoneAccount,
Tyler Gunn44e01912017-01-31 10:49:05 -0800270 String callId,
271 ConnectionRequest request,
272 boolean isIncoming,
273 Session.Info sessionInfo) {
274 Log.startSession(sessionInfo, SESSION_CREATE_CONN_FAILED);
275 try {
276 SomeArgs args = SomeArgs.obtain();
277 args.arg1 = callId;
278 args.arg2 = request;
279 args.arg3 = Log.createSubsession();
Tyler Gunn159f35c2017-03-02 09:28:37 -0800280 args.arg4 = connectionManagerPhoneAccount;
Tyler Gunn44e01912017-01-31 10:49:05 -0800281 args.argi1 = isIncoming ? 1 : 0;
282 mHandler.obtainMessage(MSG_CREATE_CONNECTION_FAILED, args).sendToTarget();
283 } finally {
284 Log.endSession();
285 }
286 }
287
288 @Override
Sanket Padawe4cc8ed52017-12-04 16:22:20 -0800289 public void handoverFailed(String callId, ConnectionRequest request, int reason,
290 Session.Info sessionInfo) {
291 Log.startSession(sessionInfo, SESSION_HANDOVER_FAILED);
292 try {
293 SomeArgs args = SomeArgs.obtain();
294 args.arg1 = callId;
295 args.arg2 = request;
296 args.arg3 = Log.createSubsession();
297 args.arg4 = reason;
298 mHandler.obtainMessage(MSG_HANDOVER_FAILED, args).sendToTarget();
299 } finally {
300 Log.endSession();
301 }
302 }
303
304 @Override
Tyler Gunn79bc1ec2018-01-22 15:17:54 -0800305 public void handoverComplete(String callId, Session.Info sessionInfo) {
306 Log.startSession(sessionInfo, SESSION_HANDOVER_COMPLETE);
307 try {
308 SomeArgs args = SomeArgs.obtain();
309 args.arg1 = callId;
310 args.arg2 = Log.createSubsession();
311 mHandler.obtainMessage(MSG_HANDOVER_COMPLETE, args).sendToTarget();
312 } finally {
313 Log.endSession();
314 }
315 }
316
317 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700318 public void abort(String callId, Session.Info sessionInfo) {
319 Log.startSession(sessionInfo, SESSION_ABORT);
320 try {
321 SomeArgs args = SomeArgs.obtain();
322 args.arg1 = callId;
323 args.arg2 = Log.createSubsession();
324 mHandler.obtainMessage(MSG_ABORT, args).sendToTarget();
325 } finally {
326 Log.endSession();
327 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700328 }
329
330 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700331 public void answerVideo(String callId, int videoState, Session.Info sessionInfo) {
332 Log.startSession(sessionInfo, SESSION_ANSWER_VIDEO);
333 try {
334 SomeArgs args = SomeArgs.obtain();
335 args.arg1 = callId;
336 args.arg2 = Log.createSubsession();
337 args.argi1 = videoState;
338 mHandler.obtainMessage(MSG_ANSWER_VIDEO, args).sendToTarget();
339 } finally {
340 Log.endSession();
341 }
Tyler Gunnbe74de02014-08-29 14:51:48 -0700342 }
343
344 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700345 public void answer(String callId, Session.Info sessionInfo) {
346 Log.startSession(sessionInfo, SESSION_ANSWER);
347 try {
348 SomeArgs args = SomeArgs.obtain();
349 args.arg1 = callId;
350 args.arg2 = Log.createSubsession();
351 mHandler.obtainMessage(MSG_ANSWER, args).sendToTarget();
352 } finally {
353 Log.endSession();
354 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700355 }
356
357 @Override
Pooja Jaind34698d2017-12-28 14:15:31 +0530358 public void deflect(String callId, Uri address, Session.Info sessionInfo) {
359 Log.startSession(sessionInfo, SESSION_DEFLECT);
360 try {
361 SomeArgs args = SomeArgs.obtain();
362 args.arg1 = callId;
363 args.arg2 = address;
364 args.arg3 = Log.createSubsession();
365 mHandler.obtainMessage(MSG_DEFLECT, args).sendToTarget();
366 } finally {
367 Log.endSession();
368 }
369 }
370
371 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700372 public void reject(String callId, Session.Info sessionInfo) {
373 Log.startSession(sessionInfo, SESSION_REJECT);
374 try {
375 SomeArgs args = SomeArgs.obtain();
376 args.arg1 = callId;
377 args.arg2 = Log.createSubsession();
378 mHandler.obtainMessage(MSG_REJECT, args).sendToTarget();
379 } finally {
380 Log.endSession();
381 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700382 }
383
384 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700385 public void rejectWithMessage(String callId, String message, Session.Info sessionInfo) {
386 Log.startSession(sessionInfo, SESSION_REJECT_MESSAGE);
387 try {
388 SomeArgs args = SomeArgs.obtain();
389 args.arg1 = callId;
390 args.arg2 = message;
391 args.arg3 = Log.createSubsession();
392 mHandler.obtainMessage(MSG_REJECT_WITH_MESSAGE, args).sendToTarget();
393 } finally {
394 Log.endSession();
395 }
Bryce Lee81901682015-08-28 16:38:02 -0700396 }
397
398 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700399 public void silence(String callId, Session.Info sessionInfo) {
400 Log.startSession(sessionInfo, SESSION_SILENCE);
401 try {
402 SomeArgs args = SomeArgs.obtain();
403 args.arg1 = callId;
404 args.arg2 = Log.createSubsession();
405 mHandler.obtainMessage(MSG_SILENCE, args).sendToTarget();
406 } finally {
407 Log.endSession();
408 }
Bryce Leecac50772015-11-17 15:13:29 -0800409 }
410
411 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700412 public void disconnect(String callId, Session.Info sessionInfo) {
413 Log.startSession(sessionInfo, SESSION_DISCONNECT);
414 try {
415 SomeArgs args = SomeArgs.obtain();
416 args.arg1 = callId;
417 args.arg2 = Log.createSubsession();
418 mHandler.obtainMessage(MSG_DISCONNECT, args).sendToTarget();
419 } finally {
420 Log.endSession();
421 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700422 }
423
424 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700425 public void hold(String callId, Session.Info sessionInfo) {
426 Log.startSession(sessionInfo, SESSION_HOLD);
427 try {
428 SomeArgs args = SomeArgs.obtain();
429 args.arg1 = callId;
430 args.arg2 = Log.createSubsession();
431 mHandler.obtainMessage(MSG_HOLD, args).sendToTarget();
432 } finally {
433 Log.endSession();
434 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700435 }
436
437 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700438 public void unhold(String callId, Session.Info sessionInfo) {
439 Log.startSession(sessionInfo, SESSION_UNHOLD);
440 try {
441 SomeArgs args = SomeArgs.obtain();
442 args.arg1 = callId;
443 args.arg2 = Log.createSubsession();
444 mHandler.obtainMessage(MSG_UNHOLD, args).sendToTarget();
445 } finally {
446 Log.endSession();
447 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700448 }
449
450 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700451 public void onCallAudioStateChanged(String callId, CallAudioState callAudioState,
452 Session.Info sessionInfo) {
453 Log.startSession(sessionInfo, SESSION_CALL_AUDIO_SC);
454 try {
455 SomeArgs args = SomeArgs.obtain();
456 args.arg1 = callId;
457 args.arg2 = callAudioState;
458 args.arg3 = Log.createSubsession();
459 mHandler.obtainMessage(MSG_ON_CALL_AUDIO_STATE_CHANGED, args).sendToTarget();
460 } finally {
461 Log.endSession();
462 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700463 }
464
465 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700466 public void playDtmfTone(String callId, char digit, Session.Info sessionInfo) {
467 Log.startSession(sessionInfo, SESSION_PLAY_DTMF);
468 try {
469 SomeArgs args = SomeArgs.obtain();
470 args.arg1 = digit;
471 args.arg2 = callId;
472 args.arg3 = Log.createSubsession();
473 mHandler.obtainMessage(MSG_PLAY_DTMF_TONE, args).sendToTarget();
474 } finally {
475 Log.endSession();
476 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700477 }
478
479 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700480 public void stopDtmfTone(String callId, Session.Info sessionInfo) {
481 Log.startSession(sessionInfo, SESSION_STOP_DTMF);
482 try {
483 SomeArgs args = SomeArgs.obtain();
484 args.arg1 = callId;
485 args.arg2 = Log.createSubsession();
486 mHandler.obtainMessage(MSG_STOP_DTMF_TONE, args).sendToTarget();
487 } finally {
488 Log.endSession();
489 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700490 }
491
492 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700493 public void conference(String callId1, String callId2, Session.Info sessionInfo) {
494 Log.startSession(sessionInfo, SESSION_CONFERENCE);
495 try {
496 SomeArgs args = SomeArgs.obtain();
497 args.arg1 = callId1;
498 args.arg2 = callId2;
499 args.arg3 = Log.createSubsession();
500 mHandler.obtainMessage(MSG_CONFERENCE, args).sendToTarget();
501 } finally {
502 Log.endSession();
503 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700504 }
505
506 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700507 public void splitFromConference(String callId, Session.Info sessionInfo) {
508 Log.startSession(sessionInfo, SESSION_SPLIT_CONFERENCE);
509 try {
510 SomeArgs args = SomeArgs.obtain();
511 args.arg1 = callId;
512 args.arg2 = Log.createSubsession();
513 mHandler.obtainMessage(MSG_SPLIT_FROM_CONFERENCE, args).sendToTarget();
514 } finally {
515 Log.endSession();
516 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700517 }
518
519 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700520 public void mergeConference(String callId, Session.Info sessionInfo) {
521 Log.startSession(sessionInfo, SESSION_MERGE_CONFERENCE);
522 try {
523 SomeArgs args = SomeArgs.obtain();
524 args.arg1 = callId;
525 args.arg2 = Log.createSubsession();
526 mHandler.obtainMessage(MSG_MERGE_CONFERENCE, args).sendToTarget();
527 } finally {
528 Log.endSession();
529 }
Santos Cordona4868042014-09-04 17:39:22 -0700530 }
531
532 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700533 public void swapConference(String callId, Session.Info sessionInfo) {
534 Log.startSession(sessionInfo, SESSION_SWAP_CONFERENCE);
535 try {
536 SomeArgs args = SomeArgs.obtain();
537 args.arg1 = callId;
538 args.arg2 = Log.createSubsession();
539 mHandler.obtainMessage(MSG_SWAP_CONFERENCE, args).sendToTarget();
540 } finally {
541 Log.endSession();
542 }
Santos Cordona4868042014-09-04 17:39:22 -0700543 }
544
545 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700546 public void onPostDialContinue(String callId, boolean proceed, Session.Info sessionInfo) {
547 Log.startSession(sessionInfo, SESSION_POST_DIAL_CONT);
548 try {
549 SomeArgs args = SomeArgs.obtain();
550 args.arg1 = callId;
551 args.arg2 = Log.createSubsession();
552 args.argi1 = proceed ? 1 : 0;
553 mHandler.obtainMessage(MSG_ON_POST_DIAL_CONTINUE, args).sendToTarget();
554 } finally {
555 Log.endSession();
556 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700557 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700558
559 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700560 public void pullExternalCall(String callId, Session.Info sessionInfo) {
561 Log.startSession(sessionInfo, SESSION_PULL_EXTERNAL_CALL);
562 try {
563 SomeArgs args = SomeArgs.obtain();
564 args.arg1 = callId;
565 args.arg2 = Log.createSubsession();
566 mHandler.obtainMessage(MSG_PULL_EXTERNAL_CALL, args).sendToTarget();
567 } finally {
568 Log.endSession();
569 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700570 }
571
572 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700573 public void sendCallEvent(String callId, String event, Bundle extras,
574 Session.Info sessionInfo) {
575 Log.startSession(sessionInfo, SESSION_SEND_CALL_EVENT);
576 try {
577 SomeArgs args = SomeArgs.obtain();
578 args.arg1 = callId;
579 args.arg2 = event;
580 args.arg3 = extras;
581 args.arg4 = Log.createSubsession();
582 mHandler.obtainMessage(MSG_SEND_CALL_EVENT, args).sendToTarget();
583 } finally {
584 Log.endSession();
585 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700586 }
Tyler Gunndee56a82016-03-23 16:06:34 -0700587
588 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700589 public void onExtrasChanged(String callId, Bundle extras, Session.Info sessionInfo) {
590 Log.startSession(sessionInfo, SESSION_EXTRAS_CHANGED);
591 try {
592 SomeArgs args = SomeArgs.obtain();
593 args.arg1 = callId;
594 args.arg2 = extras;
595 args.arg3 = Log.createSubsession();
596 mHandler.obtainMessage(MSG_ON_EXTRAS_CHANGED, args).sendToTarget();
597 } finally {
598 Log.endSession();
599 }
Tyler Gunndee56a82016-03-23 16:06:34 -0700600 }
Hall Liub64ac4c2017-02-06 10:49:48 -0800601
602 @Override
603 public void startRtt(String callId, ParcelFileDescriptor fromInCall,
604 ParcelFileDescriptor toInCall, Session.Info sessionInfo) throws RemoteException {
605 Log.startSession(sessionInfo, SESSION_START_RTT);
606 try {
607 SomeArgs args = SomeArgs.obtain();
608 args.arg1 = callId;
609 args.arg2 = new Connection.RttTextStream(toInCall, fromInCall);
610 args.arg3 = Log.createSubsession();
611 mHandler.obtainMessage(MSG_ON_START_RTT, args).sendToTarget();
612 } finally {
613 Log.endSession();
614 }
615 }
616
617 @Override
618 public void stopRtt(String callId, Session.Info sessionInfo) throws RemoteException {
619 Log.startSession(sessionInfo, SESSION_STOP_RTT);
620 try {
621 SomeArgs args = SomeArgs.obtain();
622 args.arg1 = callId;
623 args.arg2 = Log.createSubsession();
624 mHandler.obtainMessage(MSG_ON_STOP_RTT, args).sendToTarget();
625 } finally {
626 Log.endSession();
627 }
628 }
629
630 @Override
631 public void respondToRttUpgradeRequest(String callId, ParcelFileDescriptor fromInCall,
632 ParcelFileDescriptor toInCall, Session.Info sessionInfo) throws RemoteException {
633 Log.startSession(sessionInfo, SESSION_RTT_UPGRADE_RESPONSE);
634 try {
635 SomeArgs args = SomeArgs.obtain();
636 args.arg1 = callId;
637 if (toInCall == null || fromInCall == null) {
638 args.arg2 = null;
639 } else {
640 args.arg2 = new Connection.RttTextStream(toInCall, fromInCall);
641 }
642 args.arg3 = Log.createSubsession();
643 mHandler.obtainMessage(MSG_RTT_UPGRADE_RESPONSE, args).sendToTarget();
644 } finally {
645 Log.endSession();
646 }
647 }
Pengquan Meng731c1a32017-11-21 18:01:13 -0800648
649 @Override
650 public void connectionServiceFocusLost(Session.Info sessionInfo) throws RemoteException {
651 Log.startSession(sessionInfo, SESSION_CONNECTION_SERVICE_FOCUS_LOST);
652 try {
653 mHandler.obtainMessage(MSG_CONNECTION_SERVICE_FOCUS_LOST).sendToTarget();
654 } finally {
655 Log.endSession();
656 }
657 }
658
659 @Override
660 public void connectionServiceFocusGained(Session.Info sessionInfo) throws RemoteException {
661 Log.startSession(sessionInfo, SESSION_CONNECTION_SERVICE_FOCUS_GAINED);
662 try {
663 mHandler.obtainMessage(MSG_CONNECTION_SERVICE_FOCUS_GAINED).sendToTarget();
664 } finally {
665 Log.endSession();
666 }
667 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700668 };
669
670 private final Handler mHandler = new Handler(Looper.getMainLooper()) {
671 @Override
672 public void handleMessage(Message msg) {
673 switch (msg.what) {
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700674 case MSG_ADD_CONNECTION_SERVICE_ADAPTER: {
675 SomeArgs args = (SomeArgs) msg.obj;
676 try {
677 IConnectionServiceAdapter adapter = (IConnectionServiceAdapter) args.arg1;
678 Log.continueSession((Session) args.arg2,
679 SESSION_HANDLER + SESSION_ADD_CS_ADAPTER);
680 mAdapter.addAdapter(adapter);
681 onAdapterAttached();
682 } finally {
683 args.recycle();
684 Log.endSession();
685 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700686 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700687 }
688 case MSG_REMOVE_CONNECTION_SERVICE_ADAPTER: {
689 SomeArgs args = (SomeArgs) msg.obj;
690 try {
691 Log.continueSession((Session) args.arg2,
692 SESSION_HANDLER + SESSION_REMOVE_CS_ADAPTER);
693 mAdapter.removeAdapter((IConnectionServiceAdapter) args.arg1);
694 } finally {
695 args.recycle();
696 Log.endSession();
697 }
Ihab Awad8aecfed2014-08-08 17:06:11 -0700698 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700699 }
Ihab Awadf8b69882014-07-25 15:14:01 -0700700 case MSG_CREATE_CONNECTION: {
701 SomeArgs args = (SomeArgs) msg.obj;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700702 Log.continueSession((Session) args.arg4, SESSION_HANDLER + SESSION_CREATE_CONN);
Ihab Awadf8b69882014-07-25 15:14:01 -0700703 try {
Ihab Awad5d0410f2014-07-30 10:07:40 -0700704 final PhoneAccountHandle connectionManagerPhoneAccount =
Ihab Awadf8b69882014-07-25 15:14:01 -0700705 (PhoneAccountHandle) args.arg1;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700706 final String id = (String) args.arg2;
707 final ConnectionRequest request = (ConnectionRequest) args.arg3;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700708 final boolean isIncoming = args.argi1 == 1;
Yorke Leec3cf9822014-10-02 09:38:39 -0700709 final boolean isUnknown = args.argi2 == 1;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700710 if (!mAreAccountsInitialized) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700711 Log.d(this, "Enqueueing pre-init request %s", id);
Brad Ebinger0c3541b2016-11-01 14:11:38 -0700712 mPreInitializationConnectionRequests.add(
713 new android.telecom.Logging.Runnable(
714 SESSION_HANDLER + SESSION_CREATE_CONN + ".pICR",
715 null /*lock*/) {
Ihab Awad5d0410f2014-07-30 10:07:40 -0700716 @Override
Brad Ebinger0c3541b2016-11-01 14:11:38 -0700717 public void loggedRun() {
Ihab Awad5d0410f2014-07-30 10:07:40 -0700718 createConnection(
719 connectionManagerPhoneAccount,
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700720 id,
Ihab Awad5d0410f2014-07-30 10:07:40 -0700721 request,
Yorke Leec3cf9822014-10-02 09:38:39 -0700722 isIncoming,
723 isUnknown);
Ihab Awad5d0410f2014-07-30 10:07:40 -0700724 }
Brad Ebinger0c3541b2016-11-01 14:11:38 -0700725 }.prepare());
Ihab Awad5d0410f2014-07-30 10:07:40 -0700726 } else {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700727 createConnection(
728 connectionManagerPhoneAccount,
729 id,
730 request,
Yorke Leec3cf9822014-10-02 09:38:39 -0700731 isIncoming,
732 isUnknown);
Ihab Awad5d0410f2014-07-30 10:07:40 -0700733 }
Ihab Awadf8b69882014-07-25 15:14:01 -0700734 } finally {
735 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700736 Log.endSession();
Ihab Awadf8b69882014-07-25 15:14:01 -0700737 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700738 break;
Ihab Awadf8b69882014-07-25 15:14:01 -0700739 }
Tyler Gunn041a1fe2017-05-12 10:04:49 -0700740 case MSG_CREATE_CONNECTION_COMPLETE: {
741 SomeArgs args = (SomeArgs) msg.obj;
742 Log.continueSession((Session) args.arg2,
743 SESSION_HANDLER + SESSION_CREATE_CONN_COMPLETE);
744 try {
745 final String id = (String) args.arg1;
746 if (!mAreAccountsInitialized) {
747 Log.d(this, "Enqueueing pre-init request %s", id);
748 mPreInitializationConnectionRequests.add(
749 new android.telecom.Logging.Runnable(
750 SESSION_HANDLER + SESSION_CREATE_CONN_COMPLETE
751 + ".pICR",
752 null /*lock*/) {
753 @Override
754 public void loggedRun() {
755 notifyCreateConnectionComplete(id);
756 }
757 }.prepare());
758 } else {
759 notifyCreateConnectionComplete(id);
760 }
761 } finally {
762 args.recycle();
763 Log.endSession();
764 }
765 break;
766 }
Tyler Gunn44e01912017-01-31 10:49:05 -0800767 case MSG_CREATE_CONNECTION_FAILED: {
768 SomeArgs args = (SomeArgs) msg.obj;
769 Log.continueSession((Session) args.arg3, SESSION_HANDLER +
770 SESSION_CREATE_CONN_FAILED);
771 try {
772 final String id = (String) args.arg1;
773 final ConnectionRequest request = (ConnectionRequest) args.arg2;
774 final boolean isIncoming = args.argi1 == 1;
Tyler Gunn159f35c2017-03-02 09:28:37 -0800775 final PhoneAccountHandle connectionMgrPhoneAccount =
776 (PhoneAccountHandle) args.arg4;
Tyler Gunn44e01912017-01-31 10:49:05 -0800777 if (!mAreAccountsInitialized) {
778 Log.d(this, "Enqueueing pre-init request %s", id);
779 mPreInitializationConnectionRequests.add(
780 new android.telecom.Logging.Runnable(
781 SESSION_HANDLER + SESSION_CREATE_CONN_FAILED + ".pICR",
782 null /*lock*/) {
783 @Override
784 public void loggedRun() {
Tyler Gunn159f35c2017-03-02 09:28:37 -0800785 createConnectionFailed(connectionMgrPhoneAccount, id,
786 request, isIncoming);
Tyler Gunn44e01912017-01-31 10:49:05 -0800787 }
788 }.prepare());
789 } else {
790 Log.i(this, "createConnectionFailed %s", id);
Tyler Gunn159f35c2017-03-02 09:28:37 -0800791 createConnectionFailed(connectionMgrPhoneAccount, id, request,
792 isIncoming);
Tyler Gunn44e01912017-01-31 10:49:05 -0800793 }
794 } finally {
795 args.recycle();
796 Log.endSession();
797 }
798 break;
799 }
Sanket Padawe4cc8ed52017-12-04 16:22:20 -0800800 case MSG_HANDOVER_FAILED: {
801 SomeArgs args = (SomeArgs) msg.obj;
802 Log.continueSession((Session) args.arg3, SESSION_HANDLER +
803 SESSION_HANDOVER_FAILED);
804 try {
805 final String id = (String) args.arg1;
806 final ConnectionRequest request = (ConnectionRequest) args.arg2;
807 final int reason = (int) args.arg4;
808 if (!mAreAccountsInitialized) {
809 Log.d(this, "Enqueueing pre-init request %s", id);
810 mPreInitializationConnectionRequests.add(
811 new android.telecom.Logging.Runnable(
812 SESSION_HANDLER
813 + SESSION_HANDOVER_FAILED + ".pICR",
814 null /*lock*/) {
815 @Override
816 public void loggedRun() {
817 handoverFailed(id, request, reason);
818 }
819 }.prepare());
820 } else {
821 Log.i(this, "createConnectionFailed %s", id);
822 handoverFailed(id, request, reason);
823 }
824 } finally {
825 args.recycle();
826 Log.endSession();
827 }
828 break;
829 }
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700830 case MSG_ABORT: {
831 SomeArgs args = (SomeArgs) msg.obj;
832 Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_ABORT);
833 try {
834 abort((String) args.arg1);
835 } finally {
836 args.recycle();
837 Log.endSession();
838 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700839 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700840 }
841 case MSG_ANSWER: {
842 SomeArgs args = (SomeArgs) msg.obj;
843 Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_ANSWER);
844 try {
845 answer((String) args.arg1);
846 } finally {
847 args.recycle();
848 Log.endSession();
849 }
Tyler Gunnbe74de02014-08-29 14:51:48 -0700850 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700851 }
Tyler Gunnbe74de02014-08-29 14:51:48 -0700852 case MSG_ANSWER_VIDEO: {
Andrew Lee8da4c3c2014-07-16 10:11:42 -0700853 SomeArgs args = (SomeArgs) msg.obj;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700854 Log.continueSession((Session) args.arg2,
855 SESSION_HANDLER + SESSION_ANSWER_VIDEO);
Andrew Lee8da4c3c2014-07-16 10:11:42 -0700856 try {
857 String callId = (String) args.arg1;
Evan Charltonbf11f982014-07-20 22:06:28 -0700858 int videoState = args.argi1;
Tyler Gunnbe74de02014-08-29 14:51:48 -0700859 answerVideo(callId, videoState);
Andrew Lee8da4c3c2014-07-16 10:11:42 -0700860 } finally {
861 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700862 Log.endSession();
Andrew Lee8da4c3c2014-07-16 10:11:42 -0700863 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700864 break;
Andrew Lee8da4c3c2014-07-16 10:11:42 -0700865 }
Pooja Jaind34698d2017-12-28 14:15:31 +0530866 case MSG_DEFLECT: {
867 SomeArgs args = (SomeArgs) msg.obj;
868 Log.continueSession((Session) args.arg3, SESSION_HANDLER + SESSION_DEFLECT);
869 try {
870 deflect((String) args.arg1, (Uri) args.arg2);
871 } finally {
872 args.recycle();
873 Log.endSession();
874 }
875 break;
876 }
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700877 case MSG_REJECT: {
878 SomeArgs args = (SomeArgs) msg.obj;
879 Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_REJECT);
880 try {
881 reject((String) args.arg1);
882 } finally {
883 args.recycle();
884 Log.endSession();
885 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700886 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700887 }
Bryce Lee81901682015-08-28 16:38:02 -0700888 case MSG_REJECT_WITH_MESSAGE: {
889 SomeArgs args = (SomeArgs) msg.obj;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700890 Log.continueSession((Session) args.arg3,
891 SESSION_HANDLER + SESSION_REJECT_MESSAGE);
Bryce Lee81901682015-08-28 16:38:02 -0700892 try {
893 reject((String) args.arg1, (String) args.arg2);
894 } finally {
895 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700896 Log.endSession();
Bryce Lee81901682015-08-28 16:38:02 -0700897 }
898 break;
899 }
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700900 case MSG_DISCONNECT: {
901 SomeArgs args = (SomeArgs) msg.obj;
902 Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_DISCONNECT);
903 try {
904 disconnect((String) args.arg1);
905 } finally {
906 args.recycle();
907 Log.endSession();
908 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700909 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700910 }
911 case MSG_SILENCE: {
912 SomeArgs args = (SomeArgs) msg.obj;
913 Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_SILENCE);
914 try {
915 silence((String) args.arg1);
916 } finally {
917 args.recycle();
918 Log.endSession();
919 }
Bryce Leecac50772015-11-17 15:13:29 -0800920 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700921 }
922 case MSG_HOLD: {
923 SomeArgs args = (SomeArgs) msg.obj;
924 Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_REJECT);
925 try {
926 hold((String) args.arg1);
927 } finally {
928 args.recycle();
929 Log.endSession();
930 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700931 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700932 }
933 case MSG_UNHOLD: {
934 SomeArgs args = (SomeArgs) msg.obj;
935 Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_UNHOLD);
936 try {
937 unhold((String) args.arg1);
938 } finally {
939 args.recycle();
940 Log.endSession();
941 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700942 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700943 }
Yorke Lee4af59352015-05-13 14:14:54 -0700944 case MSG_ON_CALL_AUDIO_STATE_CHANGED: {
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700945 SomeArgs args = (SomeArgs) msg.obj;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700946 Log.continueSession((Session) args.arg3,
947 SESSION_HANDLER + SESSION_CALL_AUDIO_SC);
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700948 try {
949 String callId = (String) args.arg1;
Yorke Lee4af59352015-05-13 14:14:54 -0700950 CallAudioState audioState = (CallAudioState) args.arg2;
951 onCallAudioStateChanged(callId, new CallAudioState(audioState));
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700952 } finally {
953 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700954 Log.endSession();
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700955 }
956 break;
957 }
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700958 case MSG_PLAY_DTMF_TONE: {
959 SomeArgs args = (SomeArgs) msg.obj;
960 try {
961 Log.continueSession((Session) args.arg3,
962 SESSION_HANDLER + SESSION_PLAY_DTMF);
963 playDtmfTone((String) args.arg2, (char) args.arg1);
964 } finally {
965 args.recycle();
966 Log.endSession();
967 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700968 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700969 }
970 case MSG_STOP_DTMF_TONE: {
971 SomeArgs args = (SomeArgs) msg.obj;
972 try {
973 Log.continueSession((Session) args.arg2,
974 SESSION_HANDLER + SESSION_STOP_DTMF);
975 stopDtmfTone((String) args.arg1);
976 } finally {
977 args.recycle();
978 Log.endSession();
979 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700980 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700981 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700982 case MSG_CONFERENCE: {
983 SomeArgs args = (SomeArgs) msg.obj;
984 try {
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700985 Log.continueSession((Session) args.arg3,
986 SESSION_HANDLER + SESSION_CONFERENCE);
Santos Cordon823fd3c2014-08-07 18:35:18 -0700987 String callId1 = (String) args.arg1;
988 String callId2 = (String) args.arg2;
989 conference(callId1, callId2);
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700990 } finally {
991 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700992 Log.endSession();
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700993 }
994 break;
995 }
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700996 case MSG_SPLIT_FROM_CONFERENCE: {
997 SomeArgs args = (SomeArgs) msg.obj;
998 try {
999 Log.continueSession((Session) args.arg2,
1000 SESSION_HANDLER + SESSION_SPLIT_CONFERENCE);
1001 splitFromConference((String) args.arg1);
1002 } finally {
1003 args.recycle();
1004 Log.endSession();
1005 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001006 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001007 }
1008 case MSG_MERGE_CONFERENCE: {
1009 SomeArgs args = (SomeArgs) msg.obj;
1010 try {
1011 Log.continueSession((Session) args.arg2,
1012 SESSION_HANDLER + SESSION_MERGE_CONFERENCE);
1013 mergeConference((String) args.arg1);
1014 } finally {
1015 args.recycle();
1016 Log.endSession();
1017 }
Santos Cordona4868042014-09-04 17:39:22 -07001018 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001019 }
1020 case MSG_SWAP_CONFERENCE: {
1021 SomeArgs args = (SomeArgs) msg.obj;
1022 try {
1023 Log.continueSession((Session) args.arg2,
1024 SESSION_HANDLER + SESSION_SWAP_CONFERENCE);
1025 swapConference((String) args.arg1);
1026 } finally {
1027 args.recycle();
1028 Log.endSession();
1029 }
Santos Cordona4868042014-09-04 17:39:22 -07001030 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001031 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001032 case MSG_ON_POST_DIAL_CONTINUE: {
1033 SomeArgs args = (SomeArgs) msg.obj;
1034 try {
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001035 Log.continueSession((Session) args.arg2,
1036 SESSION_HANDLER + SESSION_POST_DIAL_CONT);
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001037 String callId = (String) args.arg1;
1038 boolean proceed = (args.argi1 == 1);
1039 onPostDialContinue(callId, proceed);
1040 } finally {
1041 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001042 Log.endSession();
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001043 }
1044 break;
1045 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001046 case MSG_PULL_EXTERNAL_CALL: {
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001047 SomeArgs args = (SomeArgs) msg.obj;
1048 try {
1049 Log.continueSession((Session) args.arg2,
1050 SESSION_HANDLER + SESSION_PULL_EXTERNAL_CALL);
1051 pullExternalCall((String) args.arg1);
1052 } finally {
1053 args.recycle();
1054 Log.endSession();
1055 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001056 break;
1057 }
1058 case MSG_SEND_CALL_EVENT: {
1059 SomeArgs args = (SomeArgs) msg.obj;
1060 try {
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001061 Log.continueSession((Session) args.arg4,
1062 SESSION_HANDLER + SESSION_SEND_CALL_EVENT);
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001063 String callId = (String) args.arg1;
1064 String event = (String) args.arg2;
1065 Bundle extras = (Bundle) args.arg3;
1066 sendCallEvent(callId, event, extras);
1067 } finally {
1068 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001069 Log.endSession();
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001070 }
1071 break;
1072 }
Tyler Gunn79bc1ec2018-01-22 15:17:54 -08001073 case MSG_HANDOVER_COMPLETE: {
1074 SomeArgs args = (SomeArgs) msg.obj;
1075 try {
1076 Log.continueSession((Session) args.arg2,
1077 SESSION_HANDLER + SESSION_HANDOVER_COMPLETE);
1078 String callId = (String) args.arg1;
1079 notifyHandoverComplete(callId);
1080 } finally {
1081 args.recycle();
1082 Log.endSession();
1083 }
1084 break;
1085 }
Tyler Gunndee56a82016-03-23 16:06:34 -07001086 case MSG_ON_EXTRAS_CHANGED: {
1087 SomeArgs args = (SomeArgs) msg.obj;
1088 try {
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001089 Log.continueSession((Session) args.arg3,
1090 SESSION_HANDLER + SESSION_EXTRAS_CHANGED);
Tyler Gunndee56a82016-03-23 16:06:34 -07001091 String callId = (String) args.arg1;
1092 Bundle extras = (Bundle) args.arg2;
1093 handleExtrasChanged(callId, extras);
1094 } finally {
1095 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001096 Log.endSession();
Tyler Gunndee56a82016-03-23 16:06:34 -07001097 }
1098 break;
1099 }
Hall Liub64ac4c2017-02-06 10:49:48 -08001100 case MSG_ON_START_RTT: {
1101 SomeArgs args = (SomeArgs) msg.obj;
1102 try {
1103 Log.continueSession((Session) args.arg3,
1104 SESSION_HANDLER + SESSION_START_RTT);
1105 String callId = (String) args.arg1;
1106 Connection.RttTextStream rttTextStream =
1107 (Connection.RttTextStream) args.arg2;
1108 startRtt(callId, rttTextStream);
1109 } finally {
1110 args.recycle();
1111 Log.endSession();
1112 }
1113 break;
1114 }
1115 case MSG_ON_STOP_RTT: {
1116 SomeArgs args = (SomeArgs) msg.obj;
1117 try {
1118 Log.continueSession((Session) args.arg2,
1119 SESSION_HANDLER + SESSION_STOP_RTT);
1120 String callId = (String) args.arg1;
1121 stopRtt(callId);
1122 } finally {
1123 args.recycle();
1124 Log.endSession();
1125 }
1126 break;
1127 }
1128 case MSG_RTT_UPGRADE_RESPONSE: {
1129 SomeArgs args = (SomeArgs) msg.obj;
1130 try {
1131 Log.continueSession((Session) args.arg3,
1132 SESSION_HANDLER + SESSION_RTT_UPGRADE_RESPONSE);
1133 String callId = (String) args.arg1;
1134 Connection.RttTextStream rttTextStream =
1135 (Connection.RttTextStream) args.arg2;
1136 handleRttUpgradeResponse(callId, rttTextStream);
1137 } finally {
1138 args.recycle();
1139 Log.endSession();
1140 }
1141 break;
1142 }
Pengquan Meng731c1a32017-11-21 18:01:13 -08001143 case MSG_CONNECTION_SERVICE_FOCUS_GAINED:
1144 onConnectionServiceFocusGained();
1145 break;
1146 case MSG_CONNECTION_SERVICE_FOCUS_LOST:
1147 onConnectionServiceFocusLost();
1148 break;
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001149 default:
1150 break;
1151 }
1152 }
1153 };
1154
Santos Cordon823fd3c2014-08-07 18:35:18 -07001155 private final Conference.Listener mConferenceListener = new Conference.Listener() {
1156 @Override
1157 public void onStateChanged(Conference conference, int oldState, int newState) {
1158 String id = mIdByConference.get(conference);
1159 switch (newState) {
1160 case Connection.STATE_ACTIVE:
1161 mAdapter.setActive(id);
1162 break;
1163 case Connection.STATE_HOLDING:
1164 mAdapter.setOnHold(id);
1165 break;
1166 case Connection.STATE_DISCONNECTED:
1167 // handled by onDisconnected
1168 break;
1169 }
1170 }
1171
1172 @Override
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001173 public void onDisconnected(Conference conference, DisconnectCause disconnectCause) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07001174 String id = mIdByConference.get(conference);
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001175 mAdapter.setDisconnected(id, disconnectCause);
Santos Cordon823fd3c2014-08-07 18:35:18 -07001176 }
1177
1178 @Override
1179 public void onConnectionAdded(Conference conference, Connection connection) {
1180 }
1181
1182 @Override
1183 public void onConnectionRemoved(Conference conference, Connection connection) {
1184 }
1185
1186 @Override
Ihab Awad50e35062014-09-30 09:17:03 -07001187 public void onConferenceableConnectionsChanged(
1188 Conference conference, List<Connection> conferenceableConnections) {
1189 mAdapter.setConferenceableConnections(
1190 mIdByConference.get(conference),
1191 createConnectionIdList(conferenceableConnections));
1192 }
1193
1194 @Override
Santos Cordon823fd3c2014-08-07 18:35:18 -07001195 public void onDestroyed(Conference conference) {
1196 removeConference(conference);
1197 }
1198
1199 @Override
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001200 public void onConnectionCapabilitiesChanged(
1201 Conference conference,
1202 int connectionCapabilities) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07001203 String id = mIdByConference.get(conference);
1204 Log.d(this, "call capabilities: conference: %s",
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001205 Connection.capabilitiesToString(connectionCapabilities));
1206 mAdapter.setConnectionCapabilities(id, connectionCapabilities);
Santos Cordon823fd3c2014-08-07 18:35:18 -07001207 }
Rekha Kumar07366812015-03-24 16:42:31 -07001208
1209 @Override
Tyler Gunn720c6642016-03-22 09:02:47 -07001210 public void onConnectionPropertiesChanged(
1211 Conference conference,
1212 int connectionProperties) {
1213 String id = mIdByConference.get(conference);
1214 Log.d(this, "call capabilities: conference: %s",
1215 Connection.propertiesToString(connectionProperties));
1216 mAdapter.setConnectionProperties(id, connectionProperties);
1217 }
1218
1219 @Override
Rekha Kumar07366812015-03-24 16:42:31 -07001220 public void onVideoStateChanged(Conference c, int videoState) {
1221 String id = mIdByConference.get(c);
1222 Log.d(this, "onVideoStateChanged set video state %d", videoState);
1223 mAdapter.setVideoState(id, videoState);
1224 }
1225
1226 @Override
1227 public void onVideoProviderChanged(Conference c, Connection.VideoProvider videoProvider) {
1228 String id = mIdByConference.get(c);
1229 Log.d(this, "onVideoProviderChanged: Connection: %s, VideoProvider: %s", c,
1230 videoProvider);
1231 mAdapter.setVideoProvider(id, videoProvider);
1232 }
Andrew Lee0f51da32015-04-16 13:11:55 -07001233
1234 @Override
Andrew Leeedc625f2015-04-14 13:38:12 -07001235 public void onStatusHintsChanged(Conference conference, StatusHints statusHints) {
1236 String id = mIdByConference.get(conference);
Tyler Gunndee56a82016-03-23 16:06:34 -07001237 if (id != null) {
1238 mAdapter.setStatusHints(id, statusHints);
1239 }
Andrew Leeedc625f2015-04-14 13:38:12 -07001240 }
Santos Cordon6b7f9552015-05-27 17:21:45 -07001241
1242 @Override
Tyler Gunndee56a82016-03-23 16:06:34 -07001243 public void onExtrasChanged(Conference c, Bundle extras) {
1244 String id = mIdByConference.get(c);
1245 if (id != null) {
1246 mAdapter.putExtras(id, extras);
1247 }
1248 }
1249
1250 @Override
1251 public void onExtrasRemoved(Conference c, List<String> keys) {
1252 String id = mIdByConference.get(c);
1253 if (id != null) {
1254 mAdapter.removeExtras(id, keys);
1255 }
Santos Cordon6b7f9552015-05-27 17:21:45 -07001256 }
Tyler Gunn68a73a42018-10-03 15:38:57 -07001257
1258 @Override
1259 public void onConferenceStateChanged(Conference c, boolean isConference) {
1260 String id = mIdByConference.get(c);
1261 if (id != null) {
1262 mAdapter.setConferenceState(id, isConference);
1263 }
1264 }
1265
1266 @Override
1267 public void onAddressChanged(Conference c, Uri newAddress, int presentation) {
1268 String id = mIdByConference.get(c);
1269 if (id != null) {
1270 mAdapter.setAddress(id, newAddress, presentation);
1271 }
1272 }
1273
1274 @Override
1275 public void onCallerDisplayNameChanged(Conference c, String callerDisplayName,
1276 int presentation) {
1277 String id = mIdByConference.get(c);
1278 if (id != null) {
1279 mAdapter.setCallerDisplayName(id, callerDisplayName, presentation);
1280 }
1281 }
Hall Liuc9bc1c62019-04-16 14:00:55 -07001282
1283 @Override
1284 public void onConnectionEvent(Conference c, String event, Bundle extras) {
1285 String id = mIdByConference.get(c);
1286 if (id != null) {
1287 mAdapter.onConnectionEvent(id, event, extras);
1288 }
1289 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07001290 };
1291
Ihab Awad542e0ea2014-05-16 10:22:16 -07001292 private final Connection.Listener mConnectionListener = new Connection.Listener() {
1293 @Override
1294 public void onStateChanged(Connection c, int state) {
1295 String id = mIdByConnection.get(c);
Ihab Awad42b30e12014-05-22 09:49:34 -07001296 Log.d(this, "Adapter set state %s %s", id, Connection.stateToString(state));
Ihab Awad542e0ea2014-05-16 10:22:16 -07001297 switch (state) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001298 case Connection.STATE_ACTIVE:
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001299 mAdapter.setActive(id);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001300 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001301 case Connection.STATE_DIALING:
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001302 mAdapter.setDialing(id);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001303 break;
Tyler Gunnc96b5e02016-07-07 22:53:57 -07001304 case Connection.STATE_PULLING_CALL:
1305 mAdapter.setPulling(id);
1306 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001307 case Connection.STATE_DISCONNECTED:
Ihab Awad542e0ea2014-05-16 10:22:16 -07001308 // Handled in onDisconnected()
1309 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001310 case Connection.STATE_HOLDING:
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001311 mAdapter.setOnHold(id);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001312 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001313 case Connection.STATE_NEW:
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001314 // Nothing to tell Telecom
Ihab Awad542e0ea2014-05-16 10:22:16 -07001315 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001316 case Connection.STATE_RINGING:
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001317 mAdapter.setRinging(id);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001318 break;
1319 }
1320 }
1321
1322 @Override
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001323 public void onDisconnected(Connection c, DisconnectCause disconnectCause) {
Ihab Awad542e0ea2014-05-16 10:22:16 -07001324 String id = mIdByConnection.get(c);
Andrew Lee26786392014-09-16 18:14:59 -07001325 Log.d(this, "Adapter set disconnected %s", disconnectCause);
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001326 mAdapter.setDisconnected(id, disconnectCause);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001327 }
1328
1329 @Override
Tyler Gunnaa07df82014-07-17 07:50:22 -07001330 public void onVideoStateChanged(Connection c, int videoState) {
1331 String id = mIdByConnection.get(c);
1332 Log.d(this, "Adapter set video state %d", videoState);
1333 mAdapter.setVideoState(id, videoState);
1334 }
1335
1336 @Override
Andrew Lee100e2932014-09-08 15:34:24 -07001337 public void onAddressChanged(Connection c, Uri address, int presentation) {
Sailesh Nepal61203862014-07-11 14:50:13 -07001338 String id = mIdByConnection.get(c);
Andrew Lee100e2932014-09-08 15:34:24 -07001339 mAdapter.setAddress(id, address, presentation);
Sailesh Nepal61203862014-07-11 14:50:13 -07001340 }
1341
1342 @Override
1343 public void onCallerDisplayNameChanged(
1344 Connection c, String callerDisplayName, int presentation) {
1345 String id = mIdByConnection.get(c);
1346 mAdapter.setCallerDisplayName(id, callerDisplayName, presentation);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001347 }
1348
1349 @Override
Ihab Awad542e0ea2014-05-16 10:22:16 -07001350 public void onDestroyed(Connection c) {
1351 removeConnection(c);
1352 }
Ihab Awadf8358972014-05-28 16:46:42 -07001353
1354 @Override
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001355 public void onPostDialWait(Connection c, String remaining) {
Sailesh Nepal091768c2014-06-30 15:15:23 -07001356 String id = mIdByConnection.get(c);
1357 Log.d(this, "Adapter onPostDialWait %s, %s", c, remaining);
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001358 mAdapter.onPostDialWait(id, remaining);
Sailesh Nepal091768c2014-06-30 15:15:23 -07001359 }
1360
1361 @Override
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001362 public void onPostDialChar(Connection c, char nextChar) {
1363 String id = mIdByConnection.get(c);
1364 Log.d(this, "Adapter onPostDialChar %s, %s", c, nextChar);
1365 mAdapter.onPostDialChar(id, nextChar);
1366 }
1367
1368 @Override
Andrew Lee100e2932014-09-08 15:34:24 -07001369 public void onRingbackRequested(Connection c, boolean ringback) {
Ihab Awadf8358972014-05-28 16:46:42 -07001370 String id = mIdByConnection.get(c);
1371 Log.d(this, "Adapter onRingback %b", ringback);
Andrew Lee100e2932014-09-08 15:34:24 -07001372 mAdapter.setRingbackRequested(id, ringback);
Ihab Awadf8358972014-05-28 16:46:42 -07001373 }
Santos Cordonb6939982014-06-04 20:20:58 -07001374
1375 @Override
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001376 public void onConnectionCapabilitiesChanged(Connection c, int capabilities) {
Santos Cordonb6939982014-06-04 20:20:58 -07001377 String id = mIdByConnection.get(c);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001378 Log.d(this, "capabilities: parcelableconnection: %s",
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001379 Connection.capabilitiesToString(capabilities));
1380 mAdapter.setConnectionCapabilities(id, capabilities);
Santos Cordonb6939982014-06-04 20:20:58 -07001381 }
1382
Santos Cordonb6939982014-06-04 20:20:58 -07001383 @Override
Tyler Gunn720c6642016-03-22 09:02:47 -07001384 public void onConnectionPropertiesChanged(Connection c, int properties) {
1385 String id = mIdByConnection.get(c);
1386 Log.d(this, "properties: parcelableconnection: %s",
1387 Connection.propertiesToString(properties));
1388 mAdapter.setConnectionProperties(id, properties);
1389 }
1390
1391 @Override
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001392 public void onVideoProviderChanged(Connection c, Connection.VideoProvider videoProvider) {
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07001393 String id = mIdByConnection.get(c);
Rekha Kumar07366812015-03-24 16:42:31 -07001394 Log.d(this, "onVideoProviderChanged: Connection: %s, VideoProvider: %s", c,
1395 videoProvider);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001396 mAdapter.setVideoProvider(id, videoProvider);
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07001397 }
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001398
1399 @Override
Sailesh Nepal001bbbb2014-07-15 14:40:39 -07001400 public void onAudioModeIsVoipChanged(Connection c, boolean isVoip) {
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001401 String id = mIdByConnection.get(c);
Andrew Lee100e2932014-09-08 15:34:24 -07001402 mAdapter.setIsVoipAudioMode(id, isVoip);
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001403 }
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001404
1405 @Override
Sailesh Nepal001bbbb2014-07-15 14:40:39 -07001406 public void onStatusHintsChanged(Connection c, StatusHints statusHints) {
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001407 String id = mIdByConnection.get(c);
1408 mAdapter.setStatusHints(id, statusHints);
1409 }
Sailesh Nepal2ab88cc2014-07-18 14:49:18 -07001410
1411 @Override
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001412 public void onConferenceablesChanged(
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001413 Connection connection, List<Conferenceable> conferenceables) {
Ihab Awadb8e85c72014-08-23 20:34:57 -07001414 mAdapter.setConferenceableConnections(
1415 mIdByConnection.get(connection),
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001416 createIdList(conferenceables));
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001417 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07001418
1419 @Override
1420 public void onConferenceChanged(Connection connection, Conference conference) {
1421 String id = mIdByConnection.get(connection);
1422 if (id != null) {
1423 String conferenceId = null;
1424 if (conference != null) {
1425 conferenceId = mIdByConference.get(conference);
1426 }
1427 mAdapter.setIsConferenced(id, conferenceId);
1428 }
1429 }
Anthony Lee17455a32015-04-24 15:25:29 -07001430
1431 @Override
1432 public void onConferenceMergeFailed(Connection connection) {
1433 String id = mIdByConnection.get(connection);
1434 if (id != null) {
1435 mAdapter.onConferenceMergeFailed(id);
1436 }
1437 }
Santos Cordon6b7f9552015-05-27 17:21:45 -07001438
1439 @Override
Tyler Gunndee56a82016-03-23 16:06:34 -07001440 public void onExtrasChanged(Connection c, Bundle extras) {
1441 String id = mIdByConnection.get(c);
Santos Cordon6b7f9552015-05-27 17:21:45 -07001442 if (id != null) {
Tyler Gunndee56a82016-03-23 16:06:34 -07001443 mAdapter.putExtras(id, extras);
Santos Cordon6b7f9552015-05-27 17:21:45 -07001444 }
1445 }
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001446
Tyler Gunnf5035432017-01-09 09:43:12 -08001447 @Override
Tyler Gunndee56a82016-03-23 16:06:34 -07001448 public void onExtrasRemoved(Connection c, List<String> keys) {
1449 String id = mIdByConnection.get(c);
1450 if (id != null) {
1451 mAdapter.removeExtras(id, keys);
1452 }
1453 }
1454
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08001455 @Override
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001456 public void onConnectionEvent(Connection connection, String event, Bundle extras) {
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08001457 String id = mIdByConnection.get(connection);
1458 if (id != null) {
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001459 mAdapter.onConnectionEvent(id, event, extras);
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08001460 }
1461 }
Tyler Gunnf5035432017-01-09 09:43:12 -08001462
1463 @Override
Hall Liua98f58b52017-11-07 17:59:28 -08001464 public void onAudioRouteChanged(Connection c, int audioRoute, String bluetoothAddress) {
Tyler Gunnf5035432017-01-09 09:43:12 -08001465 String id = mIdByConnection.get(c);
1466 if (id != null) {
Hall Liua98f58b52017-11-07 17:59:28 -08001467 mAdapter.setAudioRoute(id, audioRoute, bluetoothAddress);
Tyler Gunnf5035432017-01-09 09:43:12 -08001468 }
1469 }
Hall Liub64ac4c2017-02-06 10:49:48 -08001470
1471 @Override
1472 public void onRttInitiationSuccess(Connection c) {
1473 String id = mIdByConnection.get(c);
1474 if (id != null) {
1475 mAdapter.onRttInitiationSuccess(id);
1476 }
1477 }
1478
1479 @Override
1480 public void onRttInitiationFailure(Connection c, int reason) {
1481 String id = mIdByConnection.get(c);
1482 if (id != null) {
1483 mAdapter.onRttInitiationFailure(id, reason);
1484 }
1485 }
1486
1487 @Override
1488 public void onRttSessionRemotelyTerminated(Connection c) {
1489 String id = mIdByConnection.get(c);
1490 if (id != null) {
1491 mAdapter.onRttSessionRemotelyTerminated(id);
1492 }
1493 }
1494
1495 @Override
1496 public void onRemoteRttRequest(Connection c) {
1497 String id = mIdByConnection.get(c);
1498 if (id != null) {
1499 mAdapter.onRemoteRttRequest(id);
1500 }
1501 }
Srikanth Chintalafcb15012017-05-04 20:58:34 +05301502
1503 @Override
1504 public void onPhoneAccountChanged(Connection c, PhoneAccountHandle pHandle) {
1505 String id = mIdByConnection.get(c);
1506 if (id != null) {
1507 mAdapter.onPhoneAccountChanged(id, pHandle);
1508 }
1509 }
Mengjun Leng25707742017-07-04 11:10:37 +08001510
1511 public void onConnectionTimeReset(Connection c) {
1512 String id = mIdByConnection.get(c);
1513 if (id != null) {
1514 mAdapter.resetConnectionTime(id);
1515 }
1516 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001517 };
1518
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001519 /** {@inheritDoc} */
Ihab Awad542e0ea2014-05-16 10:22:16 -07001520 @Override
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001521 public final IBinder onBind(Intent intent) {
1522 return mBinder;
1523 }
1524
Santos Cordon29f2f2e2014-09-11 19:50:24 -07001525 /** {@inheritDoc} */
1526 @Override
1527 public boolean onUnbind(Intent intent) {
1528 endAllConnections();
1529 return super.onUnbind(intent);
1530 }
1531
Sailesh Nepalc5b01572014-07-14 16:29:44 -07001532 /**
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001533 * This can be used by telecom to either create a new outgoing call or attach to an existing
1534 * incoming call. In either case, telecom will cycle through a set of services and call
Sailesh Nepalc5b01572014-07-14 16:29:44 -07001535 * createConnection util a connection service cancels the process or completes it successfully.
1536 */
Ihab Awadf8b69882014-07-25 15:14:01 -07001537 private void createConnection(
1538 final PhoneAccountHandle callManagerAccount,
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001539 final String callId,
Ihab Awadf8b69882014-07-25 15:14:01 -07001540 final ConnectionRequest request,
Yorke Leec3cf9822014-10-02 09:38:39 -07001541 boolean isIncoming,
1542 boolean isUnknown) {
Tyler Gunn79bc1ec2018-01-22 15:17:54 -08001543 boolean isLegacyHandover = request.getExtras() != null &&
1544 request.getExtras().getBoolean(TelecomManager.EXTRA_IS_HANDOVER, false);
1545 boolean isHandover = request.getExtras() != null && request.getExtras().getBoolean(
1546 TelecomManager.EXTRA_IS_HANDOVER_CONNECTION, false);
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001547 Log.d(this, "createConnection, callManagerAccount: %s, callId: %s, request: %s, " +
Tyler Gunn79bc1ec2018-01-22 15:17:54 -08001548 "isIncoming: %b, isUnknown: %b, isLegacyHandover: %b, isHandover: %b",
1549 callManagerAccount, callId, request, isIncoming, isUnknown, isLegacyHandover,
1550 isHandover);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001551
Sanket Padawee29a2662017-12-01 13:59:27 -08001552 Connection connection = null;
Tyler Gunn79bc1ec2018-01-22 15:17:54 -08001553 if (isHandover) {
1554 PhoneAccountHandle fromPhoneAccountHandle = request.getExtras() != null
1555 ? (PhoneAccountHandle) request.getExtras().getParcelable(
1556 TelecomManager.EXTRA_HANDOVER_FROM_PHONE_ACCOUNT) : null;
Sanket Padawee29a2662017-12-01 13:59:27 -08001557 if (!isIncoming) {
Tyler Gunn79bc1ec2018-01-22 15:17:54 -08001558 connection = onCreateOutgoingHandoverConnection(fromPhoneAccountHandle, request);
Sanket Padawee29a2662017-12-01 13:59:27 -08001559 } else {
Tyler Gunn79bc1ec2018-01-22 15:17:54 -08001560 connection = onCreateIncomingHandoverConnection(fromPhoneAccountHandle, request);
Sanket Padawee29a2662017-12-01 13:59:27 -08001561 }
1562 } else {
1563 connection = isUnknown ? onCreateUnknownConnection(callManagerAccount, request)
1564 : isIncoming ? onCreateIncomingConnection(callManagerAccount, request)
1565 : onCreateOutgoingConnection(callManagerAccount, request);
1566 }
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001567 Log.d(this, "createConnection, connection: %s", connection);
1568 if (connection == null) {
Tyler Gunnfba1a8e2017-12-19 15:23:59 -08001569 Log.i(this, "createConnection, implementation returned null connection.");
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001570 connection = Connection.createFailedConnection(
Tyler Gunnfba1a8e2017-12-19 15:23:59 -08001571 new DisconnectCause(DisconnectCause.ERROR, "IMPL_RETURNED_NULL_CONNECTION"));
Sailesh Nepalc5b01572014-07-14 16:29:44 -07001572 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001573
Tyler Gunnf2e08b42018-05-24 10:44:44 -07001574 boolean isSelfManaged =
1575 (connection.getConnectionProperties() & Connection.PROPERTY_SELF_MANAGED)
1576 == Connection.PROPERTY_SELF_MANAGED;
1577 // Self-managed Connections should always use voip audio mode; we default here so that the
1578 // local state within the ConnectionService matches the default we assume in Telecom.
1579 if (isSelfManaged) {
1580 connection.setAudioModeIsVoip(true);
1581 }
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001582 connection.setTelecomCallId(callId);
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001583 if (connection.getState() != Connection.STATE_DISCONNECTED) {
Pengquan Meng70c9885332017-10-02 18:09:03 -07001584 addConnection(request.getAccountHandle(), callId, connection);
Ihab Awad6107bab2014-08-18 09:23:25 -07001585 }
1586
Andrew Lee100e2932014-09-08 15:34:24 -07001587 Uri address = connection.getAddress();
1588 String number = address == null ? "null" : address.getSchemeSpecificPart();
Tyler Gunn720c6642016-03-22 09:02:47 -07001589 Log.v(this, "createConnection, number: %s, state: %s, capabilities: %s, properties: %s",
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001590 Connection.toLogSafePhoneNumber(number),
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001591 Connection.stateToString(connection.getState()),
Tyler Gunn720c6642016-03-22 09:02:47 -07001592 Connection.capabilitiesToString(connection.getConnectionCapabilities()),
1593 Connection.propertiesToString(connection.getConnectionProperties()));
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001594
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001595 Log.d(this, "createConnection, calling handleCreateConnectionSuccessful %s", callId);
Ihab Awad6107bab2014-08-18 09:23:25 -07001596 mAdapter.handleCreateConnectionComplete(
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001597 callId,
Evan Charltonbf11f982014-07-20 22:06:28 -07001598 request,
1599 new ParcelableConnection(
1600 request.getAccountHandle(),
1601 connection.getState(),
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001602 connection.getConnectionCapabilities(),
Tyler Gunn720c6642016-03-22 09:02:47 -07001603 connection.getConnectionProperties(),
Christine Hallstrom2830ce92016-11-30 16:06:42 -08001604 connection.getSupportedAudioRoutes(),
Andrew Lee100e2932014-09-08 15:34:24 -07001605 connection.getAddress(),
1606 connection.getAddressPresentation(),
Evan Charltonbf11f982014-07-20 22:06:28 -07001607 connection.getCallerDisplayName(),
1608 connection.getCallerDisplayNamePresentation(),
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001609 connection.getVideoProvider() == null ?
1610 null : connection.getVideoProvider().getInterface(),
Sailesh Nepal8b9d3ca2014-08-14 17:39:34 -07001611 connection.getVideoState(),
Andrew Lee100e2932014-09-08 15:34:24 -07001612 connection.isRingbackRequested(),
Sailesh Nepal8b9d3ca2014-08-14 17:39:34 -07001613 connection.getAudioModeIsVoip(),
Roshan Piuse927ec02015-07-15 15:47:21 -07001614 connection.getConnectTimeMillis(),
Tyler Gunn3fa819c2017-08-04 09:27:26 -07001615 connection.getConnectElapsedTimeMillis(),
Ihab Awad6107bab2014-08-18 09:23:25 -07001616 connection.getStatusHints(),
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001617 connection.getDisconnectCause(),
Santos Cordon6b7f9552015-05-27 17:21:45 -07001618 createIdList(connection.getConferenceables()),
1619 connection.getExtras()));
Tyler Gunnf5035432017-01-09 09:43:12 -08001620
Tyler Gunnf2e08b42018-05-24 10:44:44 -07001621 if (isIncoming && request.shouldShowIncomingCallUi() && isSelfManaged) {
Tyler Gunnf5035432017-01-09 09:43:12 -08001622 // Tell ConnectionService to show its incoming call UX.
1623 connection.onShowIncomingCallUi();
1624 }
Shriram Ganesh6bf35ac2014-12-11 17:53:38 -08001625 if (isUnknown) {
1626 triggerConferenceRecalculate();
1627 }
Evan Charltonbf11f982014-07-20 22:06:28 -07001628 }
1629
Tyler Gunn159f35c2017-03-02 09:28:37 -08001630 private void createConnectionFailed(final PhoneAccountHandle callManagerAccount,
1631 final String callId, final ConnectionRequest request,
1632 boolean isIncoming) {
Tyler Gunn44e01912017-01-31 10:49:05 -08001633
1634 Log.i(this, "createConnectionFailed %s", callId);
1635 if (isIncoming) {
Tyler Gunn159f35c2017-03-02 09:28:37 -08001636 onCreateIncomingConnectionFailed(callManagerAccount, request);
Tyler Gunn44e01912017-01-31 10:49:05 -08001637 } else {
Tyler Gunn159f35c2017-03-02 09:28:37 -08001638 onCreateOutgoingConnectionFailed(callManagerAccount, request);
Tyler Gunn44e01912017-01-31 10:49:05 -08001639 }
1640 }
1641
Sanket Padawe4cc8ed52017-12-04 16:22:20 -08001642 private void handoverFailed(final String callId, final ConnectionRequest request,
1643 int reason) {
1644
1645 Log.i(this, "handoverFailed %s", callId);
1646 onHandoverFailed(request, reason);
1647 }
1648
Tyler Gunn041a1fe2017-05-12 10:04:49 -07001649 /**
1650 * Called by Telecom when the creation of a new Connection has completed and it is now added
1651 * to Telecom.
1652 * @param callId The ID of the connection.
1653 */
1654 private void notifyCreateConnectionComplete(final String callId) {
1655 Log.i(this, "notifyCreateConnectionComplete %s", callId);
Tyler Gunn0a88f2e2017-06-16 20:20:34 -07001656 if (callId == null) {
1657 // This could happen if the connection fails quickly and is removed from the
1658 // ConnectionService before Telecom sends the create connection complete callback.
1659 Log.w(this, "notifyCreateConnectionComplete: callId is null.");
1660 return;
1661 }
Tyler Gunn041a1fe2017-05-12 10:04:49 -07001662 onCreateConnectionComplete(findConnectionForAction(callId,
1663 "notifyCreateConnectionComplete"));
1664 }
1665
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001666 private void abort(String callId) {
Ihab Awad60ac30b2014-05-20 22:32:12 -07001667 Log.d(this, "abort %s", callId);
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001668 findConnectionForAction(callId, "abort").onAbort();
Ihab Awad542e0ea2014-05-16 10:22:16 -07001669 }
1670
Tyler Gunnbe74de02014-08-29 14:51:48 -07001671 private void answerVideo(String callId, int videoState) {
1672 Log.d(this, "answerVideo %s", callId);
Andrew Lee8da4c3c2014-07-16 10:11:42 -07001673 findConnectionForAction(callId, "answer").onAnswer(videoState);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001674 }
1675
Tyler Gunnbe74de02014-08-29 14:51:48 -07001676 private void answer(String callId) {
1677 Log.d(this, "answer %s", callId);
1678 findConnectionForAction(callId, "answer").onAnswer();
1679 }
1680
Pooja Jaind34698d2017-12-28 14:15:31 +05301681 private void deflect(String callId, Uri address) {
1682 Log.d(this, "deflect %s", callId);
1683 findConnectionForAction(callId, "deflect").onDeflect(address);
1684 }
1685
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001686 private void reject(String callId) {
Ihab Awad60ac30b2014-05-20 22:32:12 -07001687 Log.d(this, "reject %s", callId);
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001688 findConnectionForAction(callId, "reject").onReject();
Ihab Awad542e0ea2014-05-16 10:22:16 -07001689 }
1690
Bryce Lee81901682015-08-28 16:38:02 -07001691 private void reject(String callId, String rejectWithMessage) {
1692 Log.d(this, "reject %s with message", callId);
1693 findConnectionForAction(callId, "reject").onReject(rejectWithMessage);
1694 }
1695
Bryce Leecac50772015-11-17 15:13:29 -08001696 private void silence(String callId) {
1697 Log.d(this, "silence %s", callId);
1698 findConnectionForAction(callId, "silence").onSilence();
1699 }
1700
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001701 private void disconnect(String callId) {
Ihab Awad60ac30b2014-05-20 22:32:12 -07001702 Log.d(this, "disconnect %s", callId);
Santos Cordon0159ac02014-08-21 14:28:11 -07001703 if (mConnectionById.containsKey(callId)) {
1704 findConnectionForAction(callId, "disconnect").onDisconnect();
1705 } else {
1706 findConferenceForAction(callId, "disconnect").onDisconnect();
1707 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001708 }
1709
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001710 private void hold(String callId) {
Ihab Awad60ac30b2014-05-20 22:32:12 -07001711 Log.d(this, "hold %s", callId);
Santos Cordon0159ac02014-08-21 14:28:11 -07001712 if (mConnectionById.containsKey(callId)) {
1713 findConnectionForAction(callId, "hold").onHold();
1714 } else {
1715 findConferenceForAction(callId, "hold").onHold();
1716 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001717 }
1718
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001719 private void unhold(String callId) {
Ihab Awad60ac30b2014-05-20 22:32:12 -07001720 Log.d(this, "unhold %s", callId);
Santos Cordon0159ac02014-08-21 14:28:11 -07001721 if (mConnectionById.containsKey(callId)) {
1722 findConnectionForAction(callId, "unhold").onUnhold();
1723 } else {
1724 findConferenceForAction(callId, "unhold").onUnhold();
1725 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001726 }
1727
Yorke Lee4af59352015-05-13 14:14:54 -07001728 private void onCallAudioStateChanged(String callId, CallAudioState callAudioState) {
1729 Log.d(this, "onAudioStateChanged %s %s", callId, callAudioState);
Yorke Leea0d3ca92014-09-15 19:18:13 -07001730 if (mConnectionById.containsKey(callId)) {
Yorke Lee4af59352015-05-13 14:14:54 -07001731 findConnectionForAction(callId, "onCallAudioStateChanged").setCallAudioState(
1732 callAudioState);
Yorke Leea0d3ca92014-09-15 19:18:13 -07001733 } else {
Yorke Lee4af59352015-05-13 14:14:54 -07001734 findConferenceForAction(callId, "onCallAudioStateChanged").setCallAudioState(
1735 callAudioState);
Yorke Leea0d3ca92014-09-15 19:18:13 -07001736 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001737 }
1738
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001739 private void playDtmfTone(String callId, char digit) {
1740 Log.d(this, "playDtmfTone %s %c", callId, digit);
Yorke Leea0d3ca92014-09-15 19:18:13 -07001741 if (mConnectionById.containsKey(callId)) {
1742 findConnectionForAction(callId, "playDtmfTone").onPlayDtmfTone(digit);
1743 } else {
1744 findConferenceForAction(callId, "playDtmfTone").onPlayDtmfTone(digit);
1745 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001746 }
1747
1748 private void stopDtmfTone(String callId) {
1749 Log.d(this, "stopDtmfTone %s", callId);
Yorke Leea0d3ca92014-09-15 19:18:13 -07001750 if (mConnectionById.containsKey(callId)) {
1751 findConnectionForAction(callId, "stopDtmfTone").onStopDtmfTone();
1752 } else {
1753 findConferenceForAction(callId, "stopDtmfTone").onStopDtmfTone();
1754 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001755 }
1756
Santos Cordon823fd3c2014-08-07 18:35:18 -07001757 private void conference(String callId1, String callId2) {
1758 Log.d(this, "conference %s, %s", callId1, callId2);
Santos Cordon980acb92014-05-31 10:31:19 -07001759
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001760 // Attempt to get second connection or conference.
Santos Cordon823fd3c2014-08-07 18:35:18 -07001761 Connection connection2 = findConnectionForAction(callId2, "conference");
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001762 Conference conference2 = getNullConference();
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001763 if (connection2 == getNullConnection()) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001764 conference2 = findConferenceForAction(callId2, "conference");
1765 if (conference2 == getNullConference()) {
1766 Log.w(this, "Connection2 or Conference2 missing in conference request %s.",
1767 callId2);
1768 return;
1769 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07001770 }
Santos Cordonb6939982014-06-04 20:20:58 -07001771
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001772 // Attempt to get first connection or conference and perform merge.
Ihab Awad50e35062014-09-30 09:17:03 -07001773 Connection connection1 = findConnectionForAction(callId1, "conference");
1774 if (connection1 == getNullConnection()) {
1775 Conference conference1 = findConferenceForAction(callId1, "addConnection");
1776 if (conference1 == getNullConference()) {
1777 Log.w(this,
1778 "Connection1 or Conference1 missing in conference request %s.",
1779 callId1);
1780 } else {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001781 // Call 1 is a conference.
1782 if (connection2 != getNullConnection()) {
1783 // Call 2 is a connection so merge via call 1 (conference).
1784 conference1.onMerge(connection2);
1785 } else {
1786 // Call 2 is ALSO a conference; this should never happen.
1787 Log.wtf(this, "There can only be one conference and an attempt was made to " +
1788 "merge two conferences.");
1789 return;
1790 }
Ihab Awad50e35062014-09-30 09:17:03 -07001791 }
1792 } else {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001793 // Call 1 is a connection.
1794 if (conference2 != getNullConference()) {
1795 // Call 2 is a conference, so merge via call 2.
1796 conference2.onMerge(connection1);
1797 } else {
1798 // Call 2 is a connection, so merge together.
1799 onConference(connection1, connection2);
1800 }
Ihab Awad50e35062014-09-30 09:17:03 -07001801 }
Santos Cordon980acb92014-05-31 10:31:19 -07001802 }
1803
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001804 private void splitFromConference(String callId) {
Santos Cordonb6939982014-06-04 20:20:58 -07001805 Log.d(this, "splitFromConference(%s)", callId);
Santos Cordon980acb92014-05-31 10:31:19 -07001806
1807 Connection connection = findConnectionForAction(callId, "splitFromConference");
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001808 if (connection == getNullConnection()) {
Santos Cordon980acb92014-05-31 10:31:19 -07001809 Log.w(this, "Connection missing in conference request %s.", callId);
1810 return;
1811 }
1812
Santos Cordon0159ac02014-08-21 14:28:11 -07001813 Conference conference = connection.getConference();
1814 if (conference != null) {
1815 conference.onSeparate(connection);
1816 }
Santos Cordon980acb92014-05-31 10:31:19 -07001817 }
1818
Santos Cordona4868042014-09-04 17:39:22 -07001819 private void mergeConference(String callId) {
1820 Log.d(this, "mergeConference(%s)", callId);
1821 Conference conference = findConferenceForAction(callId, "mergeConference");
1822 if (conference != null) {
1823 conference.onMerge();
1824 }
1825 }
1826
1827 private void swapConference(String callId) {
1828 Log.d(this, "swapConference(%s)", callId);
1829 Conference conference = findConferenceForAction(callId, "swapConference");
1830 if (conference != null) {
1831 conference.onSwap();
1832 }
1833 }
1834
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001835 /**
1836 * Notifies a {@link Connection} of a request to pull an external call.
1837 *
1838 * See {@link Call#pullExternalCall()}.
1839 *
1840 * @param callId The ID of the call to pull.
1841 */
1842 private void pullExternalCall(String callId) {
1843 Log.d(this, "pullExternalCall(%s)", callId);
1844 Connection connection = findConnectionForAction(callId, "pullExternalCall");
1845 if (connection != null) {
1846 connection.onPullExternalCall();
1847 }
1848 }
1849
1850 /**
1851 * Notifies a {@link Connection} of a call event.
1852 *
1853 * See {@link Call#sendCallEvent(String, Bundle)}.
1854 *
1855 * @param callId The ID of the call receiving the event.
1856 * @param event The event.
1857 * @param extras Extras associated with the event.
1858 */
1859 private void sendCallEvent(String callId, String event, Bundle extras) {
1860 Log.d(this, "sendCallEvent(%s, %s)", callId, event);
1861 Connection connection = findConnectionForAction(callId, "sendCallEvent");
1862 if (connection != null) {
1863 connection.onCallEvent(event, extras);
1864 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001865 }
1866
Tyler Gunndee56a82016-03-23 16:06:34 -07001867 /**
Tyler Gunn79bc1ec2018-01-22 15:17:54 -08001868 * Notifies a {@link Connection} that a handover has completed.
1869 *
1870 * @param callId The ID of the call which completed handover.
1871 */
1872 private void notifyHandoverComplete(String callId) {
1873 Log.d(this, "notifyHandoverComplete(%s)", callId);
1874 Connection connection = findConnectionForAction(callId, "notifyHandoverComplete");
1875 if (connection != null) {
1876 connection.onHandoverComplete();
1877 }
1878 }
1879
1880 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001881 * Notifies a {@link Connection} or {@link Conference} of a change to the extras from Telecom.
1882 * <p>
1883 * These extra changes can originate from Telecom itself, or from an {@link InCallService} via
1884 * the {@link android.telecom.Call#putExtra(String, boolean)},
1885 * {@link android.telecom.Call#putExtra(String, int)},
1886 * {@link android.telecom.Call#putExtra(String, String)},
1887 * {@link Call#removeExtras(List)}.
1888 *
1889 * @param callId The ID of the call receiving the event.
1890 * @param extras The new extras bundle.
1891 */
1892 private void handleExtrasChanged(String callId, Bundle extras) {
1893 Log.d(this, "handleExtrasChanged(%s, %s)", callId, extras);
1894 if (mConnectionById.containsKey(callId)) {
1895 findConnectionForAction(callId, "handleExtrasChanged").handleExtrasChanged(extras);
1896 } else if (mConferenceById.containsKey(callId)) {
1897 findConferenceForAction(callId, "handleExtrasChanged").handleExtrasChanged(extras);
1898 }
1899 }
1900
Hall Liub64ac4c2017-02-06 10:49:48 -08001901 private void startRtt(String callId, Connection.RttTextStream rttTextStream) {
1902 Log.d(this, "startRtt(%s)", callId);
1903 if (mConnectionById.containsKey(callId)) {
1904 findConnectionForAction(callId, "startRtt").onStartRtt(rttTextStream);
1905 } else if (mConferenceById.containsKey(callId)) {
1906 Log.w(this, "startRtt called on a conference.");
1907 }
1908 }
1909
1910 private void stopRtt(String callId) {
1911 Log.d(this, "stopRtt(%s)", callId);
1912 if (mConnectionById.containsKey(callId)) {
1913 findConnectionForAction(callId, "stopRtt").onStopRtt();
1914 } else if (mConferenceById.containsKey(callId)) {
1915 Log.w(this, "stopRtt called on a conference.");
1916 }
1917 }
1918
1919 private void handleRttUpgradeResponse(String callId, Connection.RttTextStream rttTextStream) {
1920 Log.d(this, "handleRttUpgradeResponse(%s, %s)", callId, rttTextStream == null);
1921 if (mConnectionById.containsKey(callId)) {
1922 findConnectionForAction(callId, "handleRttUpgradeResponse")
1923 .handleRttUpgradeResponse(rttTextStream);
1924 } else if (mConferenceById.containsKey(callId)) {
1925 Log.w(this, "handleRttUpgradeResponse called on a conference.");
1926 }
1927 }
1928
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001929 private void onPostDialContinue(String callId, boolean proceed) {
Evan Charlton6dea4ac2014-06-03 14:07:13 -07001930 Log.d(this, "onPostDialContinue(%s)", callId);
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001931 findConnectionForAction(callId, "stopDtmfTone").onPostDialContinue(proceed);
Evan Charlton6dea4ac2014-06-03 14:07:13 -07001932 }
1933
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001934 private void onAdapterAttached() {
Ihab Awad9c3f1882014-06-30 21:17:13 -07001935 if (mAreAccountsInitialized) {
Santos Cordon52d8a152014-06-17 19:08:45 -07001936 // No need to query again if we already did it.
1937 return;
1938 }
1939
Tyler Gunn4c69fb32019-05-17 10:49:16 -07001940 String callingPackage = getOpPackageName();
1941
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001942 mAdapter.queryRemoteConnectionServices(new RemoteServiceCallback.Stub() {
Santos Cordon52d8a152014-06-17 19:08:45 -07001943 @Override
1944 public void onResult(
1945 final List<ComponentName> componentNames,
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001946 final List<IBinder> services) {
Brad Ebinger0c3541b2016-11-01 14:11:38 -07001947 mHandler.post(new android.telecom.Logging.Runnable("oAA.qRCS.oR", null /*lock*/) {
Ihab Awad6107bab2014-08-18 09:23:25 -07001948 @Override
Brad Ebinger0c3541b2016-11-01 14:11:38 -07001949 public void loggedRun() {
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001950 for (int i = 0; i < componentNames.size() && i < services.size(); i++) {
Santos Cordon52d8a152014-06-17 19:08:45 -07001951 mRemoteConnectionManager.addConnectionService(
1952 componentNames.get(i),
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001953 IConnectionService.Stub.asInterface(services.get(i)));
Santos Cordon52d8a152014-06-17 19:08:45 -07001954 }
Ihab Awad5d0410f2014-07-30 10:07:40 -07001955 onAccountsInitialized();
Sailesh Nepalc5b01572014-07-14 16:29:44 -07001956 Log.d(this, "remote connection services found: " + services);
Santos Cordon52d8a152014-06-17 19:08:45 -07001957 }
Brad Ebinger0c3541b2016-11-01 14:11:38 -07001958 }.prepare());
Santos Cordon52d8a152014-06-17 19:08:45 -07001959 }
1960
1961 @Override
1962 public void onError() {
Brad Ebinger0c3541b2016-11-01 14:11:38 -07001963 mHandler.post(new android.telecom.Logging.Runnable("oAA.qRCS.oE", null /*lock*/) {
Ihab Awad6107bab2014-08-18 09:23:25 -07001964 @Override
Brad Ebinger0c3541b2016-11-01 14:11:38 -07001965 public void loggedRun() {
Ihab Awad9c3f1882014-06-30 21:17:13 -07001966 mAreAccountsInitialized = true;
Santos Cordon52d8a152014-06-17 19:08:45 -07001967 }
Brad Ebinger0c3541b2016-11-01 14:11:38 -07001968 }.prepare());
Santos Cordon52d8a152014-06-17 19:08:45 -07001969 }
Tyler Gunn4c69fb32019-05-17 10:49:16 -07001970 }, callingPackage);
Santos Cordon52d8a152014-06-17 19:08:45 -07001971 }
1972
Ihab Awadf8b69882014-07-25 15:14:01 -07001973 /**
1974 * Ask some other {@code ConnectionService} to create a {@code RemoteConnection} given an
Santos Cordona663f862014-10-29 13:49:58 -07001975 * incoming request. This is used by {@code ConnectionService}s that are registered with
1976 * {@link PhoneAccount#CAPABILITY_CONNECTION_MANAGER} and want to be able to manage
1977 * SIM-based incoming calls.
Ihab Awadf8b69882014-07-25 15:14:01 -07001978 *
1979 * @param connectionManagerPhoneAccount See description at
1980 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
1981 * @param request Details about the incoming call.
1982 * @return The {@code Connection} object to satisfy this call, or {@code null} to
1983 * not handle the call.
1984 */
1985 public final RemoteConnection createRemoteIncomingConnection(
1986 PhoneAccountHandle connectionManagerPhoneAccount,
1987 ConnectionRequest request) {
1988 return mRemoteConnectionManager.createRemoteConnection(
1989 connectionManagerPhoneAccount, request, true);
Santos Cordon52d8a152014-06-17 19:08:45 -07001990 }
1991
1992 /**
Ihab Awadf8b69882014-07-25 15:14:01 -07001993 * Ask some other {@code ConnectionService} to create a {@code RemoteConnection} given an
Santos Cordona663f862014-10-29 13:49:58 -07001994 * outgoing request. This is used by {@code ConnectionService}s that are registered with
1995 * {@link PhoneAccount#CAPABILITY_CONNECTION_MANAGER} and want to be able to use the
1996 * SIM-based {@code ConnectionService} to place its outgoing calls.
Ihab Awadf8b69882014-07-25 15:14:01 -07001997 *
1998 * @param connectionManagerPhoneAccount See description at
1999 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
Cuihtlauac ALVARADO0b3b2a52016-09-13 14:49:41 +02002000 * @param request Details about the outgoing call.
Ihab Awadf8b69882014-07-25 15:14:01 -07002001 * @return The {@code Connection} object to satisfy this call, or {@code null} to
2002 * not handle the call.
2003 */
2004 public final RemoteConnection createRemoteOutgoingConnection(
2005 PhoneAccountHandle connectionManagerPhoneAccount,
2006 ConnectionRequest request) {
2007 return mRemoteConnectionManager.createRemoteConnection(
2008 connectionManagerPhoneAccount, request, false);
2009 }
2010
2011 /**
Santos Cordona663f862014-10-29 13:49:58 -07002012 * Indicates to the relevant {@code RemoteConnectionService} that the specified
2013 * {@link RemoteConnection}s should be merged into a conference call.
2014 * <p>
2015 * If the conference request is successful, the method {@link #onRemoteConferenceAdded} will
2016 * be invoked.
2017 *
2018 * @param remoteConnection1 The first of the remote connections to conference.
2019 * @param remoteConnection2 The second of the remote connections to conference.
Ihab Awadb8e85c72014-08-23 20:34:57 -07002020 */
2021 public final void conferenceRemoteConnections(
Santos Cordona663f862014-10-29 13:49:58 -07002022 RemoteConnection remoteConnection1,
2023 RemoteConnection remoteConnection2) {
2024 mRemoteConnectionManager.conferenceRemoteConnections(remoteConnection1, remoteConnection2);
Ihab Awadb8e85c72014-08-23 20:34:57 -07002025 }
2026
2027 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07002028 * Adds a new conference call. When a conference call is created either as a result of an
2029 * explicit request via {@link #onConference} or otherwise, the connection service should supply
2030 * an instance of {@link Conference} by invoking this method. A conference call provided by this
2031 * method will persist until {@link Conference#destroy} is invoked on the conference instance.
2032 *
2033 * @param conference The new conference object.
2034 */
2035 public final void addConference(Conference conference) {
Rekha Kumar07366812015-03-24 16:42:31 -07002036 Log.d(this, "addConference: conference=%s", conference);
2037
Santos Cordon823fd3c2014-08-07 18:35:18 -07002038 String id = addConferenceInternal(conference);
2039 if (id != null) {
2040 List<String> connectionIds = new ArrayList<>(2);
2041 for (Connection connection : conference.getConnections()) {
2042 if (mIdByConnection.containsKey(connection)) {
2043 connectionIds.add(mIdByConnection.get(connection));
2044 }
2045 }
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002046 conference.setTelecomCallId(id);
Santos Cordon823fd3c2014-08-07 18:35:18 -07002047 ParcelableConference parcelableConference = new ParcelableConference(
Nancy Chenea38cca2014-09-05 16:38:49 -07002048 conference.getPhoneAccountHandle(),
Santos Cordon823fd3c2014-08-07 18:35:18 -07002049 conference.getState(),
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002050 conference.getConnectionCapabilities(),
Tyler Gunn720c6642016-03-22 09:02:47 -07002051 conference.getConnectionProperties(),
Tyler Gunncd5d33c2015-01-12 09:02:01 -08002052 connectionIds,
Rekha Kumar07366812015-03-24 16:42:31 -07002053 conference.getVideoProvider() == null ?
2054 null : conference.getVideoProvider().getInterface(),
2055 conference.getVideoState(),
Andrew Lee3e3e2f22015-04-16 13:48:43 -07002056 conference.getConnectTimeMillis(),
Tyler Gunn17541392018-02-01 08:58:38 -08002057 conference.getConnectionStartElapsedRealTime(),
Santos Cordon6b7f9552015-05-27 17:21:45 -07002058 conference.getStatusHints(),
Tyler Gunnac60f952019-05-31 07:23:16 -07002059 conference.getExtras(),
2060 conference.getAddress(),
2061 conference.getAddressPresentation(),
2062 conference.getCallerDisplayName(),
2063 conference.getCallerDisplayNamePresentation());
Andrew Lee0f51da32015-04-16 13:11:55 -07002064
Santos Cordon823fd3c2014-08-07 18:35:18 -07002065 mAdapter.addConferenceCall(id, parcelableConference);
Rekha Kumar07366812015-03-24 16:42:31 -07002066 mAdapter.setVideoProvider(id, conference.getVideoProvider());
2067 mAdapter.setVideoState(id, conference.getVideoState());
Santos Cordon823fd3c2014-08-07 18:35:18 -07002068
2069 // Go through any child calls and set the parent.
2070 for (Connection connection : conference.getConnections()) {
2071 String connectionId = mIdByConnection.get(connection);
2072 if (connectionId != null) {
2073 mAdapter.setIsConferenced(connectionId, id);
2074 }
2075 }
Pengquan Meng70c9885332017-10-02 18:09:03 -07002076 onConferenceAdded(conference);
Santos Cordon823fd3c2014-08-07 18:35:18 -07002077 }
2078 }
2079
2080 /**
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002081 * Adds a connection created by the {@link ConnectionService} and informs telecom of the new
2082 * connection.
2083 *
2084 * @param phoneAccountHandle The phone account handle for the connection.
2085 * @param connection The connection to add.
2086 */
2087 public final void addExistingConnection(PhoneAccountHandle phoneAccountHandle,
2088 Connection connection) {
Tyler Gunn78da7812017-05-09 14:34:57 -07002089 addExistingConnection(phoneAccountHandle, connection, null /* conference */);
2090 }
2091
2092 /**
Pengquan Meng731c1a32017-11-21 18:01:13 -08002093 * Call to inform Telecom that your {@link ConnectionService} has released call resources (e.g
2094 * microphone, camera).
2095 *
Pengquan Menge3bf7e22018-02-22 17:30:04 -08002096 * <p>
2097 * The {@link ConnectionService} will be disconnected when it failed to call this method within
2098 * 5 seconds after {@link #onConnectionServiceFocusLost()} is called.
2099 *
Pengquan Meng731c1a32017-11-21 18:01:13 -08002100 * @see ConnectionService#onConnectionServiceFocusLost()
2101 */
2102 public final void connectionServiceFocusReleased() {
2103 mAdapter.onConnectionServiceFocusReleased();
2104 }
2105
2106 /**
Tyler Gunn78da7812017-05-09 14:34:57 -07002107 * Adds a connection created by the {@link ConnectionService} and informs telecom of the new
2108 * connection.
2109 *
2110 * @param phoneAccountHandle The phone account handle for the connection.
2111 * @param connection The connection to add.
2112 * @param conference The parent conference of the new connection.
2113 * @hide
2114 */
2115 public final void addExistingConnection(PhoneAccountHandle phoneAccountHandle,
2116 Connection connection, Conference conference) {
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002117
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002118 String id = addExistingConnectionInternal(phoneAccountHandle, connection);
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002119 if (id != null) {
2120 List<String> emptyList = new ArrayList<>(0);
Tyler Gunn78da7812017-05-09 14:34:57 -07002121 String conferenceId = null;
2122 if (conference != null) {
2123 conferenceId = mIdByConference.get(conference);
2124 }
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002125
2126 ParcelableConnection parcelableConnection = new ParcelableConnection(
2127 phoneAccountHandle,
2128 connection.getState(),
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002129 connection.getConnectionCapabilities(),
Tyler Gunn720c6642016-03-22 09:02:47 -07002130 connection.getConnectionProperties(),
Christine Hallstrom2830ce92016-11-30 16:06:42 -08002131 connection.getSupportedAudioRoutes(),
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002132 connection.getAddress(),
2133 connection.getAddressPresentation(),
2134 connection.getCallerDisplayName(),
2135 connection.getCallerDisplayNamePresentation(),
2136 connection.getVideoProvider() == null ?
2137 null : connection.getVideoProvider().getInterface(),
2138 connection.getVideoState(),
2139 connection.isRingbackRequested(),
2140 connection.getAudioModeIsVoip(),
Roshan Piuse927ec02015-07-15 15:47:21 -07002141 connection.getConnectTimeMillis(),
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002142 connection.getConnectElapsedTimeMillis(),
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002143 connection.getStatusHints(),
2144 connection.getDisconnectCause(),
Santos Cordon6b7f9552015-05-27 17:21:45 -07002145 emptyList,
Tyler Gunn78da7812017-05-09 14:34:57 -07002146 connection.getExtras(),
Tyler Gunn6986a632019-06-25 13:45:32 -07002147 conferenceId,
2148 connection.getCallDirection());
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002149 mAdapter.addExistingConnection(id, parcelableConnection);
2150 }
2151 }
2152
2153 /**
Ihab Awadf8b69882014-07-25 15:14:01 -07002154 * Returns all the active {@code Connection}s for which this {@code ConnectionService}
2155 * has taken responsibility.
2156 *
2157 * @return A collection of {@code Connection}s created by this {@code ConnectionService}.
Santos Cordonb6939982014-06-04 20:20:58 -07002158 */
Sailesh Nepal091768c2014-06-30 15:15:23 -07002159 public final Collection<Connection> getAllConnections() {
Santos Cordonb6939982014-06-04 20:20:58 -07002160 return mConnectionById.values();
2161 }
2162
2163 /**
Santos Cordona6018b92016-02-16 14:23:12 -08002164 * Returns all the active {@code Conference}s for which this {@code ConnectionService}
2165 * has taken responsibility.
2166 *
2167 * @return A collection of {@code Conference}s created by this {@code ConnectionService}.
2168 */
2169 public final Collection<Conference> getAllConferences() {
2170 return mConferenceById.values();
2171 }
2172
2173 /**
Ihab Awadf8b69882014-07-25 15:14:01 -07002174 * Create a {@code Connection} given an incoming request. This is used to attach to existing
2175 * incoming calls.
Evan Charltonbf11f982014-07-20 22:06:28 -07002176 *
Ihab Awadf8b69882014-07-25 15:14:01 -07002177 * @param connectionManagerPhoneAccount See description at
2178 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
2179 * @param request Details about the incoming call.
2180 * @return The {@code Connection} object to satisfy this call, or {@code null} to
2181 * not handle the call.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002182 */
Ihab Awadf8b69882014-07-25 15:14:01 -07002183 public Connection onCreateIncomingConnection(
2184 PhoneAccountHandle connectionManagerPhoneAccount,
2185 ConnectionRequest request) {
2186 return null;
2187 }
Sailesh Nepalc5b01572014-07-14 16:29:44 -07002188
2189 /**
Tyler Gunn041a1fe2017-05-12 10:04:49 -07002190 * Called after the {@link Connection} returned by
2191 * {@link #onCreateIncomingConnection(PhoneAccountHandle, ConnectionRequest)}
2192 * or {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)} has been
2193 * added to the {@link ConnectionService} and sent to Telecom.
2194 *
2195 * @param connection the {@link Connection}.
2196 * @hide
2197 */
2198 public void onCreateConnectionComplete(Connection connection) {
2199 }
2200
2201 /**
Tyler Gunnf5035432017-01-09 09:43:12 -08002202 * Called by Telecom to inform the {@link ConnectionService} that its request to create a new
2203 * incoming {@link Connection} was denied.
2204 * <p>
2205 * Used when a self-managed {@link ConnectionService} attempts to create a new incoming
2206 * {@link Connection}, but Telecom has determined that the call cannot be allowed at this time.
2207 * The {@link ConnectionService} is responsible for silently rejecting the new incoming
2208 * {@link Connection}.
2209 * <p>
2210 * See {@link TelecomManager#isIncomingCallPermitted(PhoneAccountHandle)} for more information.
2211 *
Tyler Gunn159f35c2017-03-02 09:28:37 -08002212 * @param connectionManagerPhoneAccount See description at
2213 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
Tyler Gunnf5035432017-01-09 09:43:12 -08002214 * @param request The incoming connection request.
2215 */
Tyler Gunn159f35c2017-03-02 09:28:37 -08002216 public void onCreateIncomingConnectionFailed(PhoneAccountHandle connectionManagerPhoneAccount,
2217 ConnectionRequest request) {
Tyler Gunnf5035432017-01-09 09:43:12 -08002218 }
2219
2220 /**
2221 * Called by Telecom to inform the {@link ConnectionService} that its request to create a new
2222 * outgoing {@link Connection} was denied.
2223 * <p>
2224 * Used when a self-managed {@link ConnectionService} attempts to create a new outgoing
2225 * {@link Connection}, but Telecom has determined that the call cannot be placed at this time.
2226 * The {@link ConnectionService} is responisible for informing the user that the
2227 * {@link Connection} cannot be made at this time.
2228 * <p>
2229 * See {@link TelecomManager#isOutgoingCallPermitted(PhoneAccountHandle)} for more information.
2230 *
Tyler Gunn159f35c2017-03-02 09:28:37 -08002231 * @param connectionManagerPhoneAccount See description at
2232 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
Tyler Gunnf5035432017-01-09 09:43:12 -08002233 * @param request The outgoing connection request.
2234 */
Tyler Gunn159f35c2017-03-02 09:28:37 -08002235 public void onCreateOutgoingConnectionFailed(PhoneAccountHandle connectionManagerPhoneAccount,
2236 ConnectionRequest request) {
Tyler Gunnf5035432017-01-09 09:43:12 -08002237 }
2238
2239 /**
Shriram Ganesh6bf35ac2014-12-11 17:53:38 -08002240 * Trigger recalculate functinality for conference calls. This is used when a Telephony
2241 * Connection is part of a conference controller but is not yet added to Connection
2242 * Service and hence cannot be added to the conference call.
2243 *
2244 * @hide
2245 */
2246 public void triggerConferenceRecalculate() {
2247 }
2248
2249 /**
Ihab Awadf8b69882014-07-25 15:14:01 -07002250 * Create a {@code Connection} given an outgoing request. This is used to initiate new
2251 * outgoing calls.
Sailesh Nepalc5b01572014-07-14 16:29:44 -07002252 *
Ihab Awadf8b69882014-07-25 15:14:01 -07002253 * @param connectionManagerPhoneAccount The connection manager account to use for managing
2254 * this call.
2255 * <p>
2256 * If this parameter is not {@code null}, it means that this {@code ConnectionService}
2257 * has registered one or more {@code PhoneAccount}s having
2258 * {@link PhoneAccount#CAPABILITY_CONNECTION_MANAGER}. This parameter will contain
2259 * one of these {@code PhoneAccount}s, while the {@code request} will contain another
2260 * (usually but not always distinct) {@code PhoneAccount} to be used for actually
2261 * making the connection.
2262 * <p>
2263 * If this parameter is {@code null}, it means that this {@code ConnectionService} is
2264 * being asked to make a direct connection. The
2265 * {@link ConnectionRequest#getAccountHandle()} of parameter {@code request} will be
2266 * a {@code PhoneAccount} registered by this {@code ConnectionService} to use for
2267 * making the connection.
2268 * @param request Details about the outgoing call.
2269 * @return The {@code Connection} object to satisfy this call, or the result of an invocation
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002270 * of {@link Connection#createFailedConnection(DisconnectCause)} to not handle the call.
Sailesh Nepalc5b01572014-07-14 16:29:44 -07002271 */
Ihab Awadf8b69882014-07-25 15:14:01 -07002272 public Connection onCreateOutgoingConnection(
2273 PhoneAccountHandle connectionManagerPhoneAccount,
2274 ConnectionRequest request) {
2275 return null;
2276 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002277
2278 /**
Tyler Gunn9d127732018-03-02 15:45:51 -08002279 * Called by Telecom to request that a {@link ConnectionService} creates an instance of an
2280 * outgoing handover {@link Connection}.
2281 * <p>
2282 * A call handover is the process where an ongoing call is transferred from one app (i.e.
2283 * {@link ConnectionService} to another app. The user could, for example, choose to continue a
2284 * mobile network call in a video calling app. The mobile network call via the Telephony stack
2285 * is referred to as the source of the handover, and the video calling app is referred to as the
2286 * destination.
2287 * <p>
2288 * When considering a handover scenario the <em>initiating</em> device is where a user initiated
2289 * the handover process (e.g. by calling {@link android.telecom.Call#handoverTo(
2290 * PhoneAccountHandle, int, Bundle)}, and the other device is considered the <em>receiving</em>
2291 * device.
2292 * <p>
2293 * This method is called on the destination {@link ConnectionService} on <em>initiating</em>
2294 * device when the user initiates a handover request from one app to another. The user request
2295 * originates in the {@link InCallService} via
2296 * {@link android.telecom.Call#handoverTo(PhoneAccountHandle, int, Bundle)}.
2297 * <p>
2298 * For a full discussion of the handover process and the APIs involved, see
2299 * {@link android.telecom.Call#handoverTo(PhoneAccountHandle, int, Bundle)}.
2300 * <p>
2301 * Implementations of this method should return an instance of {@link Connection} which
2302 * represents the handover. If your app does not wish to accept a handover to it at this time,
2303 * you can return {@code null}. The code below shows an example of how this is done.
2304 * <pre>
2305 * {@code
2306 * public Connection onCreateIncomingHandoverConnection(PhoneAccountHandle
2307 * fromPhoneAccountHandle, ConnectionRequest request) {
2308 * if (!isHandoverAvailable()) {
2309 * return null;
2310 * }
2311 * MyConnection connection = new MyConnection();
2312 * connection.setAddress(request.getAddress(), TelecomManager.PRESENTATION_ALLOWED);
2313 * connection.setVideoState(request.getVideoState());
2314 * return connection;
2315 * }
2316 * }
2317 * </pre>
2318 *
Sanket Padawea8eddd42017-11-03 11:07:35 -07002319 * @param fromPhoneAccountHandle {@link PhoneAccountHandle} associated with the
2320 * ConnectionService which needs to handover the call.
Tyler Gunn9d127732018-03-02 15:45:51 -08002321 * @param request Details about the call to handover.
2322 * @return {@link Connection} instance corresponding to the handover call.
Sanket Padawea8eddd42017-11-03 11:07:35 -07002323 */
2324 public Connection onCreateOutgoingHandoverConnection(PhoneAccountHandle fromPhoneAccountHandle,
2325 ConnectionRequest request) {
2326 return null;
2327 }
2328
2329 /**
Tyler Gunn9d127732018-03-02 15:45:51 -08002330 * Called by Telecom to request that a {@link ConnectionService} creates an instance of an
2331 * incoming handover {@link Connection}.
2332 * <p>
2333 * A call handover is the process where an ongoing call is transferred from one app (i.e.
2334 * {@link ConnectionService} to another app. The user could, for example, choose to continue a
2335 * mobile network call in a video calling app. The mobile network call via the Telephony stack
2336 * is referred to as the source of the handover, and the video calling app is referred to as the
2337 * destination.
2338 * <p>
2339 * When considering a handover scenario the <em>initiating</em> device is where a user initiated
2340 * the handover process (e.g. by calling {@link android.telecom.Call#handoverTo(
2341 * PhoneAccountHandle, int, Bundle)}, and the other device is considered the <em>receiving</em>
2342 * device.
2343 * <p>
2344 * This method is called on the destination app on the <em>receiving</em> device when the
2345 * destination app calls {@link TelecomManager#acceptHandover(Uri, int, PhoneAccountHandle)} to
2346 * accept an incoming handover from the <em>initiating</em> device.
2347 * <p>
2348 * For a full discussion of the handover process and the APIs involved, see
2349 * {@link android.telecom.Call#handoverTo(PhoneAccountHandle, int, Bundle)}.
2350 * <p>
2351 * Implementations of this method should return an instance of {@link Connection} which
2352 * represents the handover. The code below shows an example of how this is done.
2353 * <pre>
2354 * {@code
2355 * public Connection onCreateIncomingHandoverConnection(PhoneAccountHandle
2356 * fromPhoneAccountHandle, ConnectionRequest request) {
2357 * // Given that your app requested to accept the handover, you should not return null here.
2358 * MyConnection connection = new MyConnection();
2359 * connection.setAddress(request.getAddress(), TelecomManager.PRESENTATION_ALLOWED);
2360 * connection.setVideoState(request.getVideoState());
2361 * return connection;
2362 * }
2363 * }
2364 * </pre>
2365 *
Sanket Padawea8eddd42017-11-03 11:07:35 -07002366 * @param fromPhoneAccountHandle {@link PhoneAccountHandle} associated with the
2367 * ConnectionService which needs to handover the call.
2368 * @param request Details about the call which needs to be handover.
Tyler Gunn9d127732018-03-02 15:45:51 -08002369 * @return {@link Connection} instance corresponding to the handover call.
Sanket Padawea8eddd42017-11-03 11:07:35 -07002370 */
2371 public Connection onCreateIncomingHandoverConnection(PhoneAccountHandle fromPhoneAccountHandle,
2372 ConnectionRequest request) {
2373 return null;
2374 }
2375
2376 /**
2377 * Called by Telecom in response to a {@code TelecomManager#acceptHandover()}
2378 * invocation which failed.
Tyler Gunn9d127732018-03-02 15:45:51 -08002379 * <p>
2380 * For a full discussion of the handover process and the APIs involved, see
2381 * {@link android.telecom.Call#handoverTo(PhoneAccountHandle, int, Bundle)}
2382 *
2383 * @param request Details about the call which failed to handover.
2384 * @param error Reason for handover failure. Will be one of the
Sanket Padawea8eddd42017-11-03 11:07:35 -07002385 */
Tyler Gunn9d127732018-03-02 15:45:51 -08002386 public void onHandoverFailed(ConnectionRequest request,
2387 @Call.Callback.HandoverFailureErrors int error) {
Sanket Padawea8eddd42017-11-03 11:07:35 -07002388 return;
2389 }
2390
2391 /**
Yorke Leec3cf9822014-10-02 09:38:39 -07002392 * Create a {@code Connection} for a new unknown call. An unknown call is a call originating
2393 * from the ConnectionService that was neither a user-initiated outgoing call, nor an incoming
2394 * call created using
2395 * {@code TelecomManager#addNewIncomingCall(PhoneAccountHandle, android.os.Bundle)}.
2396 *
Yorke Lee770ed6e2014-10-06 18:58:52 -07002397 * @hide
Yorke Leec3cf9822014-10-02 09:38:39 -07002398 */
2399 public Connection onCreateUnknownConnection(PhoneAccountHandle connectionManagerPhoneAccount,
2400 ConnectionRequest request) {
Brad Ebingerb32d4f82016-10-24 16:40:49 -07002401 return null;
Yorke Leec3cf9822014-10-02 09:38:39 -07002402 }
2403
2404 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07002405 * Conference two specified connections. Invoked when the user has made a request to merge the
2406 * specified connections into a conference call. In response, the connection service should
2407 * create an instance of {@link Conference} and pass it into {@link #addConference}.
Santos Cordonb6939982014-06-04 20:20:58 -07002408 *
Santos Cordon823fd3c2014-08-07 18:35:18 -07002409 * @param connection1 A connection to merge into a conference call.
2410 * @param connection2 A connection to merge into a conference call.
Santos Cordonb6939982014-06-04 20:20:58 -07002411 */
Santos Cordon823fd3c2014-08-07 18:35:18 -07002412 public void onConference(Connection connection1, Connection connection2) {}
Santos Cordonb6939982014-06-04 20:20:58 -07002413
Santos Cordona663f862014-10-29 13:49:58 -07002414 /**
Pengquan Meng70c9885332017-10-02 18:09:03 -07002415 * Called when a connection is added.
2416 * @hide
2417 */
2418 public void onConnectionAdded(Connection connection) {}
2419
2420 /**
2421 * Called when a connection is removed.
2422 * @hide
2423 */
2424 public void onConnectionRemoved(Connection connection) {}
2425
2426 /**
2427 * Called when a conference is added.
2428 * @hide
2429 */
2430 public void onConferenceAdded(Conference conference) {}
2431
2432 /**
2433 * Called when a conference is removed.
2434 * @hide
2435 */
2436 public void onConferenceRemoved(Conference conference) {}
2437
2438 /**
Santos Cordona663f862014-10-29 13:49:58 -07002439 * Indicates that a remote conference has been created for existing {@link RemoteConnection}s.
2440 * When this method is invoked, this {@link ConnectionService} should create its own
2441 * representation of the conference call and send it to telecom using {@link #addConference}.
2442 * <p>
2443 * This is only relevant to {@link ConnectionService}s which are registered with
2444 * {@link PhoneAccount#CAPABILITY_CONNECTION_MANAGER}.
2445 *
2446 * @param conference The remote conference call.
2447 */
Ihab Awadb8e85c72014-08-23 20:34:57 -07002448 public void onRemoteConferenceAdded(RemoteConference conference) {}
2449
Santos Cordon823fd3c2014-08-07 18:35:18 -07002450 /**
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002451 * Called when an existing connection is added remotely.
2452 * @param connection The existing connection which was added.
2453 */
2454 public void onRemoteExistingConnectionAdded(RemoteConnection connection) {}
2455
2456 /**
Pengquan Meng731c1a32017-11-21 18:01:13 -08002457 * Called when the {@link ConnectionService} has lost the call focus.
2458 * The {@link ConnectionService} should release the call resources and invokes
2459 * {@link ConnectionService#connectionServiceFocusReleased()} to inform telecom that it has
2460 * released the call resources.
2461 */
2462 public void onConnectionServiceFocusLost() {}
2463
2464 /**
2465 * Called when the {@link ConnectionService} has gained the call focus. The
2466 * {@link ConnectionService} can acquire the call resources at this time.
2467 */
2468 public void onConnectionServiceFocusGained() {}
2469
2470 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07002471 * @hide
2472 */
2473 public boolean containsConference(Conference conference) {
2474 return mIdByConference.containsKey(conference);
2475 }
2476
Ihab Awadb8e85c72014-08-23 20:34:57 -07002477 /** {@hide} */
2478 void addRemoteConference(RemoteConference remoteConference) {
2479 onRemoteConferenceAdded(remoteConference);
2480 }
2481
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002482 /** {@hide} */
2483 void addRemoteExistingConnection(RemoteConnection remoteConnection) {
2484 onRemoteExistingConnectionAdded(remoteConnection);
2485 }
2486
Ihab Awad5d0410f2014-07-30 10:07:40 -07002487 private void onAccountsInitialized() {
2488 mAreAccountsInitialized = true;
2489 for (Runnable r : mPreInitializationConnectionRequests) {
2490 r.run();
2491 }
2492 mPreInitializationConnectionRequests.clear();
2493 }
2494
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002495 /**
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002496 * Adds an existing connection to the list of connections, identified by a new call ID unique
2497 * to this connection service.
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002498 *
2499 * @param connection The connection.
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002500 * @return The ID of the connection (e.g. the call-id).
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002501 */
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002502 private String addExistingConnectionInternal(PhoneAccountHandle handle, Connection connection) {
2503 String id;
Tyler Gunncd6ccfd2016-10-17 15:48:19 -07002504
2505 if (connection.getExtras() != null && connection.getExtras()
2506 .containsKey(Connection.EXTRA_ORIGINAL_CONNECTION_ID)) {
2507 id = connection.getExtras().getString(Connection.EXTRA_ORIGINAL_CONNECTION_ID);
2508 Log.d(this, "addExistingConnectionInternal - conn %s reusing original id %s",
2509 connection.getTelecomCallId(), id);
2510 } else if (handle == null) {
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002511 // If no phone account handle was provided, we cannot be sure the call ID is unique,
2512 // so just use a random UUID.
2513 id = UUID.randomUUID().toString();
2514 } else {
2515 // Phone account handle was provided, so use the ConnectionService class name as a
2516 // prefix for a unique incremental call ID.
2517 id = handle.getComponentName().getClassName() + "@" + getNextCallId();
2518 }
Pengquan Meng70c9885332017-10-02 18:09:03 -07002519 addConnection(handle, id, connection);
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002520 return id;
2521 }
2522
Pengquan Meng70c9885332017-10-02 18:09:03 -07002523 private void addConnection(PhoneAccountHandle handle, String callId, Connection connection) {
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002524 connection.setTelecomCallId(callId);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002525 mConnectionById.put(callId, connection);
2526 mIdByConnection.put(connection, callId);
2527 connection.addConnectionListener(mConnectionListener);
Santos Cordon823fd3c2014-08-07 18:35:18 -07002528 connection.setConnectionService(this);
Pengquan Meng70c9885332017-10-02 18:09:03 -07002529 connection.setPhoneAccountHandle(handle);
2530 onConnectionAdded(connection);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002531 }
2532
Anthony Lee30e65842014-11-06 16:30:53 -08002533 /** {@hide} */
2534 protected void removeConnection(Connection connection) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07002535 connection.unsetConnectionService(this);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002536 connection.removeConnectionListener(mConnectionListener);
Chenjie Luoe370b532016-05-12 16:59:43 -07002537 String id = mIdByConnection.get(connection);
2538 if (id != null) {
2539 mConnectionById.remove(id);
2540 mIdByConnection.remove(connection);
2541 mAdapter.removeCall(id);
Pengquan Meng70c9885332017-10-02 18:09:03 -07002542 onConnectionRemoved(connection);
Chenjie Luoe370b532016-05-12 16:59:43 -07002543 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002544 }
2545
Santos Cordon823fd3c2014-08-07 18:35:18 -07002546 private String addConferenceInternal(Conference conference) {
Tyler Gunncd6ccfd2016-10-17 15:48:19 -07002547 String originalId = null;
2548 if (conference.getExtras() != null && conference.getExtras()
2549 .containsKey(Connection.EXTRA_ORIGINAL_CONNECTION_ID)) {
2550 originalId = conference.getExtras().getString(Connection.EXTRA_ORIGINAL_CONNECTION_ID);
2551 Log.d(this, "addConferenceInternal: conf %s reusing original id %s",
2552 conference.getTelecomCallId(),
2553 originalId);
2554 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07002555 if (mIdByConference.containsKey(conference)) {
2556 Log.w(this, "Re-adding an existing conference: %s.", conference);
2557 } else if (conference != null) {
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002558 // Conferences do not (yet) have a PhoneAccountHandle associated with them, so we
2559 // cannot determine a ConnectionService class name to associate with the ID, so use
2560 // a unique UUID (for now).
Tyler Gunncd6ccfd2016-10-17 15:48:19 -07002561 String id = originalId == null ? UUID.randomUUID().toString() : originalId;
Santos Cordon823fd3c2014-08-07 18:35:18 -07002562 mConferenceById.put(id, conference);
2563 mIdByConference.put(conference, id);
2564 conference.addListener(mConferenceListener);
2565 return id;
2566 }
2567
2568 return null;
2569 }
2570
2571 private void removeConference(Conference conference) {
2572 if (mIdByConference.containsKey(conference)) {
2573 conference.removeListener(mConferenceListener);
2574
2575 String id = mIdByConference.get(conference);
2576 mConferenceById.remove(id);
2577 mIdByConference.remove(conference);
2578 mAdapter.removeCall(id);
Pengquan Meng70c9885332017-10-02 18:09:03 -07002579
2580 onConferenceRemoved(conference);
Santos Cordon823fd3c2014-08-07 18:35:18 -07002581 }
2582 }
2583
Ihab Awad542e0ea2014-05-16 10:22:16 -07002584 private Connection findConnectionForAction(String callId, String action) {
Tyler Gunn0a88f2e2017-06-16 20:20:34 -07002585 if (callId != null && mConnectionById.containsKey(callId)) {
Ihab Awad542e0ea2014-05-16 10:22:16 -07002586 return mConnectionById.get(callId);
2587 }
Ihab Awad60ac30b2014-05-20 22:32:12 -07002588 Log.w(this, "%s - Cannot find Connection %s", action, callId);
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07002589 return getNullConnection();
2590 }
2591
2592 static synchronized Connection getNullConnection() {
2593 if (sNullConnection == null) {
2594 sNullConnection = new Connection() {};
2595 }
2596 return sNullConnection;
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002597 }
Santos Cordon0159ac02014-08-21 14:28:11 -07002598
2599 private Conference findConferenceForAction(String conferenceId, String action) {
2600 if (mConferenceById.containsKey(conferenceId)) {
2601 return mConferenceById.get(conferenceId);
2602 }
2603 Log.w(this, "%s - Cannot find conference %s", action, conferenceId);
2604 return getNullConference();
2605 }
2606
Ihab Awadb8e85c72014-08-23 20:34:57 -07002607 private List<String> createConnectionIdList(List<Connection> connections) {
2608 List<String> ids = new ArrayList<>();
2609 for (Connection c : connections) {
2610 if (mIdByConnection.containsKey(c)) {
2611 ids.add(mIdByConnection.get(c));
2612 }
2613 }
2614 Collections.sort(ids);
2615 return ids;
2616 }
2617
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002618 /**
2619 * Builds a list of {@link Connection} and {@link Conference} IDs based on the list of
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002620 * {@link Conferenceable}s passed in.
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002621 *
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002622 * @param conferenceables The {@link Conferenceable} connections and conferences.
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002623 * @return List of string conference and call Ids.
2624 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002625 private List<String> createIdList(List<Conferenceable> conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002626 List<String> ids = new ArrayList<>();
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002627 for (Conferenceable c : conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002628 // Only allow Connection and Conference conferenceables.
2629 if (c instanceof Connection) {
2630 Connection connection = (Connection) c;
2631 if (mIdByConnection.containsKey(connection)) {
2632 ids.add(mIdByConnection.get(connection));
2633 }
2634 } else if (c instanceof Conference) {
2635 Conference conference = (Conference) c;
2636 if (mIdByConference.containsKey(conference)) {
2637 ids.add(mIdByConference.get(conference));
2638 }
2639 }
2640 }
2641 Collections.sort(ids);
2642 return ids;
2643 }
2644
Santos Cordon0159ac02014-08-21 14:28:11 -07002645 private Conference getNullConference() {
2646 if (sNullConference == null) {
2647 sNullConference = new Conference(null) {};
2648 }
2649 return sNullConference;
2650 }
Santos Cordon29f2f2e2014-09-11 19:50:24 -07002651
2652 private void endAllConnections() {
2653 // Unbound from telecomm. We should end all connections and conferences.
2654 for (Connection connection : mIdByConnection.keySet()) {
2655 // only operate on top-level calls. Conference calls will be removed on their own.
2656 if (connection.getConference() == null) {
2657 connection.onDisconnect();
2658 }
2659 }
2660 for (Conference conference : mIdByConference.keySet()) {
2661 conference.onDisconnect();
2662 }
2663 }
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002664
2665 /**
2666 * Retrieves the next call ID as maintainted by the connection service.
2667 *
2668 * @return The call ID.
2669 */
2670 private int getNextCallId() {
Brad Ebingerb32d4f82016-10-24 16:40:49 -07002671 synchronized (mIdSyncRoot) {
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002672 return ++mId;
2673 }
2674 }
Santos Cordon980acb92014-05-31 10:31:19 -07002675}