blob: 00c2918837acb1114043ac4f6746a7a33a04ef59 [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
Tyler Gunn5567d742019-10-31 13:04:37 -070019import android.annotation.NonNull;
20import android.annotation.Nullable;
21import android.annotation.RequiresPermission;
Santos Cordon5c6fa952014-07-20 17:47:12 -070022import android.annotation.SdkConstant;
Tyler Gunn5567d742019-10-31 13:04:37 -070023import android.annotation.SystemApi;
Sailesh Nepal2a46b902014-07-04 17:21:07 -070024import android.app.Service;
Santos Cordon52d8a152014-06-17 19:08:45 -070025import android.content.ComponentName;
Santos Cordon5c6fa952014-07-20 17:47:12 -070026import android.content.Intent;
Ihab Awad542e0ea2014-05-16 10:22:16 -070027import android.net.Uri;
Santos Cordon6b7f9552015-05-27 17:21:45 -070028import android.os.Bundle;
Santos Cordon52d8a152014-06-17 19:08:45 -070029import android.os.Handler;
30import android.os.IBinder;
31import android.os.Looper;
Sailesh Nepal2a46b902014-07-04 17:21:07 -070032import android.os.Message;
Hall Liub64ac4c2017-02-06 10:49:48 -080033import android.os.ParcelFileDescriptor;
34import android.os.RemoteException;
Brad Ebingerb32d4f82016-10-24 16:40:49 -070035import android.telecom.Logging.Session;
Andrew Lee14185762014-07-25 09:41:56 -070036
Brad Ebinger99f17ce2019-09-11 18:06:51 -070037import com.android.internal.annotations.VisibleForTesting;
Sailesh Nepal2a46b902014-07-04 17:21:07 -070038import com.android.internal.os.SomeArgs;
Tyler Gunnef9f6f92014-09-12 22:16:17 -070039import com.android.internal.telecom.IConnectionService;
40import com.android.internal.telecom.IConnectionServiceAdapter;
41import com.android.internal.telecom.RemoteServiceCallback;
Santos Cordon52d8a152014-06-17 19:08:45 -070042
Ihab Awad5d0410f2014-07-30 10:07:40 -070043import java.util.ArrayList;
Santos Cordonb6939982014-06-04 20:20:58 -070044import java.util.Collection;
Santos Cordon7c7bc7f2014-07-28 18:15:48 -070045import java.util.Collections;
Santos Cordon52d8a152014-06-17 19:08:45 -070046import java.util.List;
Ihab Awad542e0ea2014-05-16 10:22:16 -070047import java.util.Map;
Santos Cordon823fd3c2014-08-07 18:35:18 -070048import java.util.UUID;
mike dooley95e80702014-09-18 14:07:52 -070049import java.util.concurrent.ConcurrentHashMap;
Ihab Awad542e0ea2014-05-16 10:22:16 -070050
51/**
Tyler Gunnf5035432017-01-09 09:43:12 -080052 * An abstract service that should be implemented by any apps which either:
53 * <ol>
54 * <li>Can make phone calls (VoIP or otherwise) and want those calls to be integrated into the
55 * built-in phone app. Referred to as a <b>system managed</b> {@link ConnectionService}.</li>
56 * <li>Are a standalone calling app and don't want their calls to be integrated into the
57 * built-in phone app. Referred to as a <b>self managed</b> {@link ConnectionService}.</li>
58 * </ol>
59 * Once implemented, the {@link ConnectionService} needs to take the following steps so that Telecom
60 * will bind to it:
Santos Cordona663f862014-10-29 13:49:58 -070061 * <p>
62 * 1. <i>Registration in AndroidManifest.xml</i>
63 * <br/>
64 * <pre>
65 * &lt;service android:name="com.example.package.MyConnectionService"
66 * android:label="@string/some_label_for_my_connection_service"
Yorke Lee249c12e2015-05-13 15:59:29 -070067 * android:permission="android.permission.BIND_TELECOM_CONNECTION_SERVICE"&gt;
Santos Cordona663f862014-10-29 13:49:58 -070068 * &lt;intent-filter&gt;
69 * &lt;action android:name="android.telecom.ConnectionService" /&gt;
70 * &lt;/intent-filter&gt;
71 * &lt;/service&gt;
72 * </pre>
73 * <p>
74 * 2. <i> Registration of {@link PhoneAccount} with {@link TelecomManager}.</i>
75 * <br/>
76 * See {@link PhoneAccount} and {@link TelecomManager#registerPhoneAccount} for more information.
77 * <p>
Tyler Gunnf5035432017-01-09 09:43:12 -080078 * System managed {@link ConnectionService}s must be enabled by the user in the phone app settings
kopriva82c591b2018-10-08 15:57:00 -070079 * before Telecom will bind to them. Self-managed {@link ConnectionService}s must be granted the
Tyler Gunnf5035432017-01-09 09:43:12 -080080 * appropriate permission before Telecom will bind to them.
81 * <p>
82 * Once registered and enabled by the user in the phone app settings or granted permission, telecom
83 * will bind to a {@link ConnectionService} implementation when it wants that
84 * {@link ConnectionService} to place a call or the service has indicated that is has an incoming
85 * call through {@link TelecomManager#addNewIncomingCall}. The {@link ConnectionService} can then
86 * expect a call to {@link #onCreateIncomingConnection} or {@link #onCreateOutgoingConnection}
87 * wherein it should provide a new instance of a {@link Connection} object. It is through this
88 * {@link Connection} object that telecom receives state updates and the {@link ConnectionService}
Santos Cordona663f862014-10-29 13:49:58 -070089 * receives call-commands such as answer, reject, hold and disconnect.
90 * <p>
Tyler Gunnf5035432017-01-09 09:43:12 -080091 * When there are no more live calls, telecom will unbind from the {@link ConnectionService}.
Ihab Awad542e0ea2014-05-16 10:22:16 -070092 */
Sailesh Nepal2a46b902014-07-04 17:21:07 -070093public abstract class ConnectionService extends Service {
Santos Cordon5c6fa952014-07-20 17:47:12 -070094 /**
95 * The {@link Intent} that must be declared as handled by the service.
96 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -070097 @SdkConstant(SdkConstant.SdkConstantType.SERVICE_ACTION)
Tyler Gunnef9f6f92014-09-12 22:16:17 -070098 public static final String SERVICE_INTERFACE = "android.telecom.ConnectionService";
Santos Cordon5c6fa952014-07-20 17:47:12 -070099
Tyler Gunn8bf76572017-04-06 15:30:08 -0700100 /**
101 * Boolean extra used by Telecom to inform a {@link ConnectionService} that the purpose of it
102 * being asked to create a new outgoing {@link Connection} is to perform a handover of an
103 * ongoing call on the device from another {@link PhoneAccount}/{@link ConnectionService}. Will
104 * be specified in the {@link ConnectionRequest#getExtras()} passed by Telecom when
105 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)} is called.
106 * <p>
Tyler Gunn727c6bd2017-04-11 09:51:40 -0700107 * When your {@link ConnectionService} receives this extra, it should communicate the fact that
108 * this is a handover to the other device's matching {@link ConnectionService}. That
Tyler Gunn8bf76572017-04-06 15:30:08 -0700109 * {@link ConnectionService} will continue the handover using
110 * {@link TelecomManager#addNewIncomingCall(PhoneAccountHandle, Bundle)}, specifying
Tyler Gunn727c6bd2017-04-11 09:51:40 -0700111 * {@link TelecomManager#EXTRA_IS_HANDOVER}. Telecom will match the phone numbers of the
112 * handover call on the other device with ongoing calls for {@link ConnectionService}s which
113 * support {@link PhoneAccount#EXTRA_SUPPORTS_HANDOVER_FROM}.
Tyler Gunn8bf76572017-04-06 15:30:08 -0700114 * @hide
115 */
116 public static final String EXTRA_IS_HANDOVER = TelecomManager.EXTRA_IS_HANDOVER;
117
Ihab Awad542e0ea2014-05-16 10:22:16 -0700118 // Flag controlling whether PII is emitted into the logs
Ihab Awad60ac30b2014-05-20 22:32:12 -0700119 private static final boolean PII_DEBUG = Log.isLoggable(android.util.Log.DEBUG);
Ihab Awad542e0ea2014-05-16 10:22:16 -0700120
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700121 // Session Definitions
122 private static final String SESSION_HANDLER = "H.";
123 private static final String SESSION_ADD_CS_ADAPTER = "CS.aCSA";
124 private static final String SESSION_REMOVE_CS_ADAPTER = "CS.rCSA";
125 private static final String SESSION_CREATE_CONN = "CS.crCo";
Tyler Gunn041a1fe2017-05-12 10:04:49 -0700126 private static final String SESSION_CREATE_CONN_COMPLETE = "CS.crCoC";
Tyler Gunn44e01912017-01-31 10:49:05 -0800127 private static final String SESSION_CREATE_CONN_FAILED = "CS.crCoF";
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700128 private static final String SESSION_ABORT = "CS.ab";
129 private static final String SESSION_ANSWER = "CS.an";
130 private static final String SESSION_ANSWER_VIDEO = "CS.anV";
Pooja Jaind34698d2017-12-28 14:15:31 +0530131 private static final String SESSION_DEFLECT = "CS.def";
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700132 private static final String SESSION_REJECT = "CS.r";
133 private static final String SESSION_REJECT_MESSAGE = "CS.rWM";
134 private static final String SESSION_SILENCE = "CS.s";
135 private static final String SESSION_DISCONNECT = "CS.d";
136 private static final String SESSION_HOLD = "CS.h";
137 private static final String SESSION_UNHOLD = "CS.u";
138 private static final String SESSION_CALL_AUDIO_SC = "CS.cASC";
139 private static final String SESSION_PLAY_DTMF = "CS.pDT";
140 private static final String SESSION_STOP_DTMF = "CS.sDT";
141 private static final String SESSION_CONFERENCE = "CS.c";
142 private static final String SESSION_SPLIT_CONFERENCE = "CS.sFC";
143 private static final String SESSION_MERGE_CONFERENCE = "CS.mC";
144 private static final String SESSION_SWAP_CONFERENCE = "CS.sC";
145 private static final String SESSION_POST_DIAL_CONT = "CS.oPDC";
146 private static final String SESSION_PULL_EXTERNAL_CALL = "CS.pEC";
147 private static final String SESSION_SEND_CALL_EVENT = "CS.sCE";
Tyler Gunn79bc1ec2018-01-22 15:17:54 -0800148 private static final String SESSION_HANDOVER_COMPLETE = "CS.hC";
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700149 private static final String SESSION_EXTRAS_CHANGED = "CS.oEC";
Hall Liub64ac4c2017-02-06 10:49:48 -0800150 private static final String SESSION_START_RTT = "CS.+RTT";
Hall Liua549fed2018-02-09 16:40:03 -0800151 private static final String SESSION_UPDATE_RTT_PIPES = "CS.uRTT";
Hall Liub64ac4c2017-02-06 10:49:48 -0800152 private static final String SESSION_STOP_RTT = "CS.-RTT";
153 private static final String SESSION_RTT_UPGRADE_RESPONSE = "CS.rTRUR";
Pengquan Meng731c1a32017-11-21 18:01:13 -0800154 private static final String SESSION_CONNECTION_SERVICE_FOCUS_LOST = "CS.cSFL";
155 private static final String SESSION_CONNECTION_SERVICE_FOCUS_GAINED = "CS.cSFG";
Sanket Padawe4cc8ed52017-12-04 16:22:20 -0800156 private static final String SESSION_HANDOVER_FAILED = "CS.haF";
Ravi Paluri80aa2142019-12-02 11:57:37 +0530157 private static final String SESSION_CREATE_CONF = "CS.crConf";
158 private static final String SESSION_CREATE_CONF_COMPLETE = "CS.crConfC";
159 private static final String SESSION_CREATE_CONF_FAILED = "CS.crConfF";
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700160
Ihab Awad8aecfed2014-08-08 17:06:11 -0700161 private static final int MSG_ADD_CONNECTION_SERVICE_ADAPTER = 1;
Sailesh Nepalc5b01572014-07-14 16:29:44 -0700162 private static final int MSG_CREATE_CONNECTION = 2;
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700163 private static final int MSG_ABORT = 3;
Sailesh Nepalc5b01572014-07-14 16:29:44 -0700164 private static final int MSG_ANSWER = 4;
165 private static final int MSG_REJECT = 5;
166 private static final int MSG_DISCONNECT = 6;
167 private static final int MSG_HOLD = 7;
168 private static final int MSG_UNHOLD = 8;
Yorke Lee4af59352015-05-13 14:14:54 -0700169 private static final int MSG_ON_CALL_AUDIO_STATE_CHANGED = 9;
Sailesh Nepalc5b01572014-07-14 16:29:44 -0700170 private static final int MSG_PLAY_DTMF_TONE = 10;
171 private static final int MSG_STOP_DTMF_TONE = 11;
172 private static final int MSG_CONFERENCE = 12;
173 private static final int MSG_SPLIT_FROM_CONFERENCE = 13;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700174 private static final int MSG_ON_POST_DIAL_CONTINUE = 14;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700175 private static final int MSG_REMOVE_CONNECTION_SERVICE_ADAPTER = 16;
Tyler Gunnbe74de02014-08-29 14:51:48 -0700176 private static final int MSG_ANSWER_VIDEO = 17;
Santos Cordona4868042014-09-04 17:39:22 -0700177 private static final int MSG_MERGE_CONFERENCE = 18;
178 private static final int MSG_SWAP_CONFERENCE = 19;
Bryce Lee81901682015-08-28 16:38:02 -0700179 private static final int MSG_REJECT_WITH_MESSAGE = 20;
Bryce Leecac50772015-11-17 15:13:29 -0800180 private static final int MSG_SILENCE = 21;
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700181 private static final int MSG_PULL_EXTERNAL_CALL = 22;
182 private static final int MSG_SEND_CALL_EVENT = 23;
Tyler Gunndee56a82016-03-23 16:06:34 -0700183 private static final int MSG_ON_EXTRAS_CHANGED = 24;
Tyler Gunn44e01912017-01-31 10:49:05 -0800184 private static final int MSG_CREATE_CONNECTION_FAILED = 25;
Hall Liub64ac4c2017-02-06 10:49:48 -0800185 private static final int MSG_ON_START_RTT = 26;
186 private static final int MSG_ON_STOP_RTT = 27;
187 private static final int MSG_RTT_UPGRADE_RESPONSE = 28;
Tyler Gunn041a1fe2017-05-12 10:04:49 -0700188 private static final int MSG_CREATE_CONNECTION_COMPLETE = 29;
Pengquan Meng731c1a32017-11-21 18:01:13 -0800189 private static final int MSG_CONNECTION_SERVICE_FOCUS_LOST = 30;
190 private static final int MSG_CONNECTION_SERVICE_FOCUS_GAINED = 31;
Sanket Padawe4cc8ed52017-12-04 16:22:20 -0800191 private static final int MSG_HANDOVER_FAILED = 32;
Tyler Gunn79bc1ec2018-01-22 15:17:54 -0800192 private static final int MSG_HANDOVER_COMPLETE = 33;
Pooja Jaind34698d2017-12-28 14:15:31 +0530193 private static final int MSG_DEFLECT = 34;
Ravi Paluri80aa2142019-12-02 11:57:37 +0530194 private static final int MSG_CREATE_CONFERENCE = 35;
195 private static final int MSG_CREATE_CONFERENCE_COMPLETE = 36;
196 private static final int MSG_CREATE_CONFERENCE_FAILED = 37;
Tyler Gunnfacfdee2020-01-23 13:10:37 -0800197 private static final int MSG_REJECT_WITH_REASON = 38;
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700198
Sailesh Nepalcf7020b2014-08-20 10:07:19 -0700199 private static Connection sNullConnection;
200
mike dooley95e80702014-09-18 14:07:52 -0700201 private final Map<String, Connection> mConnectionById = new ConcurrentHashMap<>();
202 private final Map<Connection, String> mIdByConnection = new ConcurrentHashMap<>();
203 private final Map<String, Conference> mConferenceById = new ConcurrentHashMap<>();
204 private final Map<Conference, String> mIdByConference = new ConcurrentHashMap<>();
Ihab Awadb8e85c72014-08-23 20:34:57 -0700205 private final RemoteConnectionManager mRemoteConnectionManager =
206 new RemoteConnectionManager(this);
Ihab Awad5d0410f2014-07-30 10:07:40 -0700207 private final List<Runnable> mPreInitializationConnectionRequests = new ArrayList<>();
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700208 private final ConnectionServiceAdapter mAdapter = new ConnectionServiceAdapter();
Ihab Awad542e0ea2014-05-16 10:22:16 -0700209
Santos Cordon823fd3c2014-08-07 18:35:18 -0700210 private boolean mAreAccountsInitialized = false;
Santos Cordon0159ac02014-08-21 14:28:11 -0700211 private Conference sNullConference;
Tyler Gunnf0500bd2015-09-01 10:59:48 -0700212 private Object mIdSyncRoot = new Object();
213 private int mId = 0;
Santos Cordon823fd3c2014-08-07 18:35:18 -0700214
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700215 private final IBinder mBinder = new IConnectionService.Stub() {
216 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700217 public void addConnectionServiceAdapter(IConnectionServiceAdapter adapter,
218 Session.Info sessionInfo) {
219 Log.startSession(sessionInfo, SESSION_ADD_CS_ADAPTER);
220 try {
221 SomeArgs args = SomeArgs.obtain();
222 args.arg1 = adapter;
223 args.arg2 = Log.createSubsession();
224 mHandler.obtainMessage(MSG_ADD_CONNECTION_SERVICE_ADAPTER, args).sendToTarget();
225 } finally {
226 Log.endSession();
227 }
Ihab Awad8aecfed2014-08-08 17:06:11 -0700228 }
229
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700230 public void removeConnectionServiceAdapter(IConnectionServiceAdapter adapter,
231 Session.Info sessionInfo) {
232 Log.startSession(sessionInfo, SESSION_REMOVE_CS_ADAPTER);
233 try {
234 SomeArgs args = SomeArgs.obtain();
235 args.arg1 = adapter;
236 args.arg2 = Log.createSubsession();
237 mHandler.obtainMessage(MSG_REMOVE_CONNECTION_SERVICE_ADAPTER, args).sendToTarget();
238 } finally {
239 Log.endSession();
240 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700241 }
242
243 @Override
Ihab Awadf8b69882014-07-25 15:14:01 -0700244 public void createConnection(
245 PhoneAccountHandle connectionManagerPhoneAccount,
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700246 String id,
Ihab Awadf8b69882014-07-25 15:14:01 -0700247 ConnectionRequest request,
Yorke Leec3cf9822014-10-02 09:38:39 -0700248 boolean isIncoming,
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700249 boolean isUnknown,
250 Session.Info sessionInfo) {
251 Log.startSession(sessionInfo, SESSION_CREATE_CONN);
252 try {
253 SomeArgs args = SomeArgs.obtain();
254 args.arg1 = connectionManagerPhoneAccount;
255 args.arg2 = id;
256 args.arg3 = request;
257 args.arg4 = Log.createSubsession();
258 args.argi1 = isIncoming ? 1 : 0;
259 args.argi2 = isUnknown ? 1 : 0;
260 mHandler.obtainMessage(MSG_CREATE_CONNECTION, args).sendToTarget();
261 } finally {
262 Log.endSession();
263 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700264 }
265
266 @Override
Tyler Gunn041a1fe2017-05-12 10:04:49 -0700267 public void createConnectionComplete(String id, Session.Info sessionInfo) {
268 Log.startSession(sessionInfo, SESSION_CREATE_CONN_COMPLETE);
269 try {
270 SomeArgs args = SomeArgs.obtain();
271 args.arg1 = id;
272 args.arg2 = Log.createSubsession();
273 mHandler.obtainMessage(MSG_CREATE_CONNECTION_COMPLETE, args).sendToTarget();
274 } finally {
275 Log.endSession();
276 }
277 }
278
279 @Override
Tyler Gunn44e01912017-01-31 10:49:05 -0800280 public void createConnectionFailed(
Tyler Gunn159f35c2017-03-02 09:28:37 -0800281 PhoneAccountHandle connectionManagerPhoneAccount,
Tyler Gunn44e01912017-01-31 10:49:05 -0800282 String callId,
283 ConnectionRequest request,
284 boolean isIncoming,
285 Session.Info sessionInfo) {
286 Log.startSession(sessionInfo, SESSION_CREATE_CONN_FAILED);
287 try {
288 SomeArgs args = SomeArgs.obtain();
289 args.arg1 = callId;
290 args.arg2 = request;
291 args.arg3 = Log.createSubsession();
Tyler Gunn159f35c2017-03-02 09:28:37 -0800292 args.arg4 = connectionManagerPhoneAccount;
Tyler Gunn44e01912017-01-31 10:49:05 -0800293 args.argi1 = isIncoming ? 1 : 0;
294 mHandler.obtainMessage(MSG_CREATE_CONNECTION_FAILED, args).sendToTarget();
295 } finally {
296 Log.endSession();
297 }
298 }
299
300 @Override
Ravi Paluri80aa2142019-12-02 11:57:37 +0530301 public void createConference(
302 PhoneAccountHandle connectionManagerPhoneAccount,
303 String id,
304 ConnectionRequest request,
305 boolean isIncoming,
306 boolean isUnknown,
307 Session.Info sessionInfo) {
308 Log.startSession(sessionInfo, SESSION_CREATE_CONF);
309 try {
310 SomeArgs args = SomeArgs.obtain();
311 args.arg1 = connectionManagerPhoneAccount;
312 args.arg2 = id;
313 args.arg3 = request;
314 args.arg4 = Log.createSubsession();
315 args.argi1 = isIncoming ? 1 : 0;
316 args.argi2 = isUnknown ? 1 : 0;
317 mHandler.obtainMessage(MSG_CREATE_CONFERENCE, args).sendToTarget();
318 } finally {
319 Log.endSession();
320 }
321 }
322
323 @Override
324 public void createConferenceComplete(String id, Session.Info sessionInfo) {
325 Log.startSession(sessionInfo, SESSION_CREATE_CONF_COMPLETE);
326 try {
327 SomeArgs args = SomeArgs.obtain();
328 args.arg1 = id;
329 args.arg2 = Log.createSubsession();
330 mHandler.obtainMessage(MSG_CREATE_CONFERENCE_COMPLETE, args).sendToTarget();
331 } finally {
332 Log.endSession();
333 }
334 }
335
336 @Override
337 public void createConferenceFailed(
338 PhoneAccountHandle connectionManagerPhoneAccount,
339 String callId,
340 ConnectionRequest request,
341 boolean isIncoming,
342 Session.Info sessionInfo) {
343 Log.startSession(sessionInfo, SESSION_CREATE_CONF_FAILED);
344 try {
345 SomeArgs args = SomeArgs.obtain();
346 args.arg1 = callId;
347 args.arg2 = request;
348 args.arg3 = Log.createSubsession();
349 args.arg4 = connectionManagerPhoneAccount;
350 args.argi1 = isIncoming ? 1 : 0;
351 mHandler.obtainMessage(MSG_CREATE_CONFERENCE_FAILED, args).sendToTarget();
352 } finally {
353 Log.endSession();
354 }
355 }
356
357 @Override
Sanket Padawe4cc8ed52017-12-04 16:22:20 -0800358 public void handoverFailed(String callId, ConnectionRequest request, int reason,
359 Session.Info sessionInfo) {
360 Log.startSession(sessionInfo, SESSION_HANDOVER_FAILED);
361 try {
362 SomeArgs args = SomeArgs.obtain();
363 args.arg1 = callId;
364 args.arg2 = request;
365 args.arg3 = Log.createSubsession();
366 args.arg4 = reason;
367 mHandler.obtainMessage(MSG_HANDOVER_FAILED, args).sendToTarget();
368 } finally {
369 Log.endSession();
370 }
371 }
372
373 @Override
Tyler Gunn79bc1ec2018-01-22 15:17:54 -0800374 public void handoverComplete(String callId, Session.Info sessionInfo) {
375 Log.startSession(sessionInfo, SESSION_HANDOVER_COMPLETE);
376 try {
377 SomeArgs args = SomeArgs.obtain();
378 args.arg1 = callId;
379 args.arg2 = Log.createSubsession();
380 mHandler.obtainMessage(MSG_HANDOVER_COMPLETE, args).sendToTarget();
381 } finally {
382 Log.endSession();
383 }
384 }
385
386 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700387 public void abort(String callId, Session.Info sessionInfo) {
388 Log.startSession(sessionInfo, SESSION_ABORT);
389 try {
390 SomeArgs args = SomeArgs.obtain();
391 args.arg1 = callId;
392 args.arg2 = Log.createSubsession();
393 mHandler.obtainMessage(MSG_ABORT, args).sendToTarget();
394 } finally {
395 Log.endSession();
396 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700397 }
398
399 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700400 public void answerVideo(String callId, int videoState, Session.Info sessionInfo) {
401 Log.startSession(sessionInfo, SESSION_ANSWER_VIDEO);
402 try {
403 SomeArgs args = SomeArgs.obtain();
404 args.arg1 = callId;
405 args.arg2 = Log.createSubsession();
406 args.argi1 = videoState;
407 mHandler.obtainMessage(MSG_ANSWER_VIDEO, args).sendToTarget();
408 } finally {
409 Log.endSession();
410 }
Tyler Gunnbe74de02014-08-29 14:51:48 -0700411 }
412
413 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700414 public void answer(String callId, Session.Info sessionInfo) {
415 Log.startSession(sessionInfo, SESSION_ANSWER);
416 try {
417 SomeArgs args = SomeArgs.obtain();
418 args.arg1 = callId;
419 args.arg2 = Log.createSubsession();
420 mHandler.obtainMessage(MSG_ANSWER, args).sendToTarget();
421 } finally {
422 Log.endSession();
423 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700424 }
425
426 @Override
Pooja Jaind34698d2017-12-28 14:15:31 +0530427 public void deflect(String callId, Uri address, Session.Info sessionInfo) {
428 Log.startSession(sessionInfo, SESSION_DEFLECT);
429 try {
430 SomeArgs args = SomeArgs.obtain();
431 args.arg1 = callId;
432 args.arg2 = address;
433 args.arg3 = Log.createSubsession();
434 mHandler.obtainMessage(MSG_DEFLECT, args).sendToTarget();
435 } finally {
436 Log.endSession();
437 }
438 }
439
440 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700441 public void reject(String callId, Session.Info sessionInfo) {
442 Log.startSession(sessionInfo, SESSION_REJECT);
443 try {
444 SomeArgs args = SomeArgs.obtain();
445 args.arg1 = callId;
446 args.arg2 = Log.createSubsession();
447 mHandler.obtainMessage(MSG_REJECT, args).sendToTarget();
448 } finally {
449 Log.endSession();
450 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700451 }
452
453 @Override
Tyler Gunnfacfdee2020-01-23 13:10:37 -0800454 public void rejectWithReason(String callId,
455 @android.telecom.Call.RejectReason int rejectReason, Session.Info sessionInfo) {
456 Log.startSession(sessionInfo, SESSION_REJECT);
457 try {
458 SomeArgs args = SomeArgs.obtain();
459 args.arg1 = callId;
460 args.argi1 = rejectReason;
461 args.arg2 = Log.createSubsession();
462 mHandler.obtainMessage(MSG_REJECT_WITH_REASON, args).sendToTarget();
463 } finally {
464 Log.endSession();
465 }
466 }
467
468 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700469 public void rejectWithMessage(String callId, String message, Session.Info sessionInfo) {
470 Log.startSession(sessionInfo, SESSION_REJECT_MESSAGE);
471 try {
472 SomeArgs args = SomeArgs.obtain();
473 args.arg1 = callId;
474 args.arg2 = message;
475 args.arg3 = Log.createSubsession();
476 mHandler.obtainMessage(MSG_REJECT_WITH_MESSAGE, args).sendToTarget();
477 } finally {
478 Log.endSession();
479 }
Bryce Lee81901682015-08-28 16:38:02 -0700480 }
481
482 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700483 public void silence(String callId, Session.Info sessionInfo) {
484 Log.startSession(sessionInfo, SESSION_SILENCE);
485 try {
486 SomeArgs args = SomeArgs.obtain();
487 args.arg1 = callId;
488 args.arg2 = Log.createSubsession();
489 mHandler.obtainMessage(MSG_SILENCE, args).sendToTarget();
490 } finally {
491 Log.endSession();
492 }
Bryce Leecac50772015-11-17 15:13:29 -0800493 }
494
495 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700496 public void disconnect(String callId, Session.Info sessionInfo) {
497 Log.startSession(sessionInfo, SESSION_DISCONNECT);
498 try {
499 SomeArgs args = SomeArgs.obtain();
500 args.arg1 = callId;
501 args.arg2 = Log.createSubsession();
502 mHandler.obtainMessage(MSG_DISCONNECT, args).sendToTarget();
503 } finally {
504 Log.endSession();
505 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700506 }
507
508 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700509 public void hold(String callId, Session.Info sessionInfo) {
510 Log.startSession(sessionInfo, SESSION_HOLD);
511 try {
512 SomeArgs args = SomeArgs.obtain();
513 args.arg1 = callId;
514 args.arg2 = Log.createSubsession();
515 mHandler.obtainMessage(MSG_HOLD, args).sendToTarget();
516 } finally {
517 Log.endSession();
518 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700519 }
520
521 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700522 public void unhold(String callId, Session.Info sessionInfo) {
523 Log.startSession(sessionInfo, SESSION_UNHOLD);
524 try {
525 SomeArgs args = SomeArgs.obtain();
526 args.arg1 = callId;
527 args.arg2 = Log.createSubsession();
528 mHandler.obtainMessage(MSG_UNHOLD, args).sendToTarget();
529 } finally {
530 Log.endSession();
531 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700532 }
533
534 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700535 public void onCallAudioStateChanged(String callId, CallAudioState callAudioState,
536 Session.Info sessionInfo) {
537 Log.startSession(sessionInfo, SESSION_CALL_AUDIO_SC);
538 try {
539 SomeArgs args = SomeArgs.obtain();
540 args.arg1 = callId;
541 args.arg2 = callAudioState;
542 args.arg3 = Log.createSubsession();
543 mHandler.obtainMessage(MSG_ON_CALL_AUDIO_STATE_CHANGED, args).sendToTarget();
544 } finally {
545 Log.endSession();
546 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700547 }
548
549 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700550 public void playDtmfTone(String callId, char digit, Session.Info sessionInfo) {
551 Log.startSession(sessionInfo, SESSION_PLAY_DTMF);
552 try {
553 SomeArgs args = SomeArgs.obtain();
554 args.arg1 = digit;
555 args.arg2 = callId;
556 args.arg3 = Log.createSubsession();
557 mHandler.obtainMessage(MSG_PLAY_DTMF_TONE, args).sendToTarget();
558 } finally {
559 Log.endSession();
560 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700561 }
562
563 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700564 public void stopDtmfTone(String callId, Session.Info sessionInfo) {
565 Log.startSession(sessionInfo, SESSION_STOP_DTMF);
566 try {
567 SomeArgs args = SomeArgs.obtain();
568 args.arg1 = callId;
569 args.arg2 = Log.createSubsession();
570 mHandler.obtainMessage(MSG_STOP_DTMF_TONE, args).sendToTarget();
571 } finally {
572 Log.endSession();
573 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700574 }
575
576 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700577 public void conference(String callId1, String callId2, Session.Info sessionInfo) {
578 Log.startSession(sessionInfo, SESSION_CONFERENCE);
579 try {
580 SomeArgs args = SomeArgs.obtain();
581 args.arg1 = callId1;
582 args.arg2 = callId2;
583 args.arg3 = Log.createSubsession();
584 mHandler.obtainMessage(MSG_CONFERENCE, args).sendToTarget();
585 } finally {
586 Log.endSession();
587 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700588 }
589
590 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700591 public void splitFromConference(String callId, Session.Info sessionInfo) {
592 Log.startSession(sessionInfo, SESSION_SPLIT_CONFERENCE);
593 try {
594 SomeArgs args = SomeArgs.obtain();
595 args.arg1 = callId;
596 args.arg2 = Log.createSubsession();
597 mHandler.obtainMessage(MSG_SPLIT_FROM_CONFERENCE, args).sendToTarget();
598 } finally {
599 Log.endSession();
600 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700601 }
602
603 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700604 public void mergeConference(String callId, Session.Info sessionInfo) {
605 Log.startSession(sessionInfo, SESSION_MERGE_CONFERENCE);
606 try {
607 SomeArgs args = SomeArgs.obtain();
608 args.arg1 = callId;
609 args.arg2 = Log.createSubsession();
610 mHandler.obtainMessage(MSG_MERGE_CONFERENCE, args).sendToTarget();
611 } finally {
612 Log.endSession();
613 }
Santos Cordona4868042014-09-04 17:39:22 -0700614 }
615
616 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700617 public void swapConference(String callId, Session.Info sessionInfo) {
618 Log.startSession(sessionInfo, SESSION_SWAP_CONFERENCE);
619 try {
620 SomeArgs args = SomeArgs.obtain();
621 args.arg1 = callId;
622 args.arg2 = Log.createSubsession();
623 mHandler.obtainMessage(MSG_SWAP_CONFERENCE, args).sendToTarget();
624 } finally {
625 Log.endSession();
626 }
Santos Cordona4868042014-09-04 17:39:22 -0700627 }
628
629 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700630 public void onPostDialContinue(String callId, boolean proceed, Session.Info sessionInfo) {
631 Log.startSession(sessionInfo, SESSION_POST_DIAL_CONT);
632 try {
633 SomeArgs args = SomeArgs.obtain();
634 args.arg1 = callId;
635 args.arg2 = Log.createSubsession();
636 args.argi1 = proceed ? 1 : 0;
637 mHandler.obtainMessage(MSG_ON_POST_DIAL_CONTINUE, args).sendToTarget();
638 } finally {
639 Log.endSession();
640 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700641 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700642
643 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700644 public void pullExternalCall(String callId, Session.Info sessionInfo) {
645 Log.startSession(sessionInfo, SESSION_PULL_EXTERNAL_CALL);
646 try {
647 SomeArgs args = SomeArgs.obtain();
648 args.arg1 = callId;
649 args.arg2 = Log.createSubsession();
650 mHandler.obtainMessage(MSG_PULL_EXTERNAL_CALL, args).sendToTarget();
651 } finally {
652 Log.endSession();
653 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700654 }
655
656 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700657 public void sendCallEvent(String callId, String event, Bundle extras,
658 Session.Info sessionInfo) {
659 Log.startSession(sessionInfo, SESSION_SEND_CALL_EVENT);
660 try {
661 SomeArgs args = SomeArgs.obtain();
662 args.arg1 = callId;
663 args.arg2 = event;
664 args.arg3 = extras;
665 args.arg4 = Log.createSubsession();
666 mHandler.obtainMessage(MSG_SEND_CALL_EVENT, args).sendToTarget();
667 } finally {
668 Log.endSession();
669 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700670 }
Tyler Gunndee56a82016-03-23 16:06:34 -0700671
672 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700673 public void onExtrasChanged(String callId, Bundle extras, Session.Info sessionInfo) {
674 Log.startSession(sessionInfo, SESSION_EXTRAS_CHANGED);
675 try {
676 SomeArgs args = SomeArgs.obtain();
677 args.arg1 = callId;
678 args.arg2 = extras;
679 args.arg3 = Log.createSubsession();
680 mHandler.obtainMessage(MSG_ON_EXTRAS_CHANGED, args).sendToTarget();
681 } finally {
682 Log.endSession();
683 }
Tyler Gunndee56a82016-03-23 16:06:34 -0700684 }
Hall Liub64ac4c2017-02-06 10:49:48 -0800685
686 @Override
687 public void startRtt(String callId, ParcelFileDescriptor fromInCall,
688 ParcelFileDescriptor toInCall, Session.Info sessionInfo) throws RemoteException {
689 Log.startSession(sessionInfo, SESSION_START_RTT);
690 try {
691 SomeArgs args = SomeArgs.obtain();
692 args.arg1 = callId;
693 args.arg2 = new Connection.RttTextStream(toInCall, fromInCall);
694 args.arg3 = Log.createSubsession();
695 mHandler.obtainMessage(MSG_ON_START_RTT, args).sendToTarget();
696 } finally {
697 Log.endSession();
698 }
699 }
700
701 @Override
702 public void stopRtt(String callId, Session.Info sessionInfo) throws RemoteException {
703 Log.startSession(sessionInfo, SESSION_STOP_RTT);
704 try {
705 SomeArgs args = SomeArgs.obtain();
706 args.arg1 = callId;
707 args.arg2 = Log.createSubsession();
708 mHandler.obtainMessage(MSG_ON_STOP_RTT, args).sendToTarget();
709 } finally {
710 Log.endSession();
711 }
712 }
713
714 @Override
715 public void respondToRttUpgradeRequest(String callId, ParcelFileDescriptor fromInCall,
716 ParcelFileDescriptor toInCall, Session.Info sessionInfo) throws RemoteException {
717 Log.startSession(sessionInfo, SESSION_RTT_UPGRADE_RESPONSE);
718 try {
719 SomeArgs args = SomeArgs.obtain();
720 args.arg1 = callId;
721 if (toInCall == null || fromInCall == null) {
722 args.arg2 = null;
723 } else {
724 args.arg2 = new Connection.RttTextStream(toInCall, fromInCall);
725 }
726 args.arg3 = Log.createSubsession();
727 mHandler.obtainMessage(MSG_RTT_UPGRADE_RESPONSE, args).sendToTarget();
728 } finally {
729 Log.endSession();
730 }
731 }
Pengquan Meng731c1a32017-11-21 18:01:13 -0800732
733 @Override
734 public void connectionServiceFocusLost(Session.Info sessionInfo) throws RemoteException {
735 Log.startSession(sessionInfo, SESSION_CONNECTION_SERVICE_FOCUS_LOST);
736 try {
737 mHandler.obtainMessage(MSG_CONNECTION_SERVICE_FOCUS_LOST).sendToTarget();
738 } finally {
739 Log.endSession();
740 }
741 }
742
743 @Override
744 public void connectionServiceFocusGained(Session.Info sessionInfo) throws RemoteException {
745 Log.startSession(sessionInfo, SESSION_CONNECTION_SERVICE_FOCUS_GAINED);
746 try {
747 mHandler.obtainMessage(MSG_CONNECTION_SERVICE_FOCUS_GAINED).sendToTarget();
748 } finally {
749 Log.endSession();
750 }
751 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700752 };
753
754 private final Handler mHandler = new Handler(Looper.getMainLooper()) {
755 @Override
756 public void handleMessage(Message msg) {
757 switch (msg.what) {
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700758 case MSG_ADD_CONNECTION_SERVICE_ADAPTER: {
759 SomeArgs args = (SomeArgs) msg.obj;
760 try {
761 IConnectionServiceAdapter adapter = (IConnectionServiceAdapter) args.arg1;
762 Log.continueSession((Session) args.arg2,
763 SESSION_HANDLER + SESSION_ADD_CS_ADAPTER);
764 mAdapter.addAdapter(adapter);
765 onAdapterAttached();
766 } finally {
767 args.recycle();
768 Log.endSession();
769 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700770 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700771 }
772 case MSG_REMOVE_CONNECTION_SERVICE_ADAPTER: {
773 SomeArgs args = (SomeArgs) msg.obj;
774 try {
775 Log.continueSession((Session) args.arg2,
776 SESSION_HANDLER + SESSION_REMOVE_CS_ADAPTER);
777 mAdapter.removeAdapter((IConnectionServiceAdapter) args.arg1);
778 } finally {
779 args.recycle();
780 Log.endSession();
781 }
Ihab Awad8aecfed2014-08-08 17:06:11 -0700782 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700783 }
Ihab Awadf8b69882014-07-25 15:14:01 -0700784 case MSG_CREATE_CONNECTION: {
785 SomeArgs args = (SomeArgs) msg.obj;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700786 Log.continueSession((Session) args.arg4, SESSION_HANDLER + SESSION_CREATE_CONN);
Ihab Awadf8b69882014-07-25 15:14:01 -0700787 try {
Ihab Awad5d0410f2014-07-30 10:07:40 -0700788 final PhoneAccountHandle connectionManagerPhoneAccount =
Ihab Awadf8b69882014-07-25 15:14:01 -0700789 (PhoneAccountHandle) args.arg1;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700790 final String id = (String) args.arg2;
791 final ConnectionRequest request = (ConnectionRequest) args.arg3;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700792 final boolean isIncoming = args.argi1 == 1;
Yorke Leec3cf9822014-10-02 09:38:39 -0700793 final boolean isUnknown = args.argi2 == 1;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700794 if (!mAreAccountsInitialized) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700795 Log.d(this, "Enqueueing pre-init request %s", id);
Brad Ebinger0c3541b2016-11-01 14:11:38 -0700796 mPreInitializationConnectionRequests.add(
797 new android.telecom.Logging.Runnable(
798 SESSION_HANDLER + SESSION_CREATE_CONN + ".pICR",
799 null /*lock*/) {
Ihab Awad5d0410f2014-07-30 10:07:40 -0700800 @Override
Brad Ebinger0c3541b2016-11-01 14:11:38 -0700801 public void loggedRun() {
Ihab Awad5d0410f2014-07-30 10:07:40 -0700802 createConnection(
803 connectionManagerPhoneAccount,
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700804 id,
Ihab Awad5d0410f2014-07-30 10:07:40 -0700805 request,
Yorke Leec3cf9822014-10-02 09:38:39 -0700806 isIncoming,
807 isUnknown);
Ihab Awad5d0410f2014-07-30 10:07:40 -0700808 }
Brad Ebinger0c3541b2016-11-01 14:11:38 -0700809 }.prepare());
Ihab Awad5d0410f2014-07-30 10:07:40 -0700810 } else {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700811 createConnection(
812 connectionManagerPhoneAccount,
813 id,
814 request,
Yorke Leec3cf9822014-10-02 09:38:39 -0700815 isIncoming,
816 isUnknown);
Ihab Awad5d0410f2014-07-30 10:07:40 -0700817 }
Ihab Awadf8b69882014-07-25 15:14:01 -0700818 } finally {
819 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700820 Log.endSession();
Ihab Awadf8b69882014-07-25 15:14:01 -0700821 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700822 break;
Ihab Awadf8b69882014-07-25 15:14:01 -0700823 }
Tyler Gunn041a1fe2017-05-12 10:04:49 -0700824 case MSG_CREATE_CONNECTION_COMPLETE: {
825 SomeArgs args = (SomeArgs) msg.obj;
826 Log.continueSession((Session) args.arg2,
827 SESSION_HANDLER + SESSION_CREATE_CONN_COMPLETE);
828 try {
829 final String id = (String) args.arg1;
830 if (!mAreAccountsInitialized) {
831 Log.d(this, "Enqueueing pre-init request %s", id);
832 mPreInitializationConnectionRequests.add(
833 new android.telecom.Logging.Runnable(
834 SESSION_HANDLER + SESSION_CREATE_CONN_COMPLETE
835 + ".pICR",
836 null /*lock*/) {
837 @Override
838 public void loggedRun() {
839 notifyCreateConnectionComplete(id);
840 }
841 }.prepare());
842 } else {
843 notifyCreateConnectionComplete(id);
844 }
845 } finally {
846 args.recycle();
847 Log.endSession();
848 }
849 break;
850 }
Tyler Gunn44e01912017-01-31 10:49:05 -0800851 case MSG_CREATE_CONNECTION_FAILED: {
852 SomeArgs args = (SomeArgs) msg.obj;
853 Log.continueSession((Session) args.arg3, SESSION_HANDLER +
854 SESSION_CREATE_CONN_FAILED);
855 try {
856 final String id = (String) args.arg1;
857 final ConnectionRequest request = (ConnectionRequest) args.arg2;
858 final boolean isIncoming = args.argi1 == 1;
Tyler Gunn159f35c2017-03-02 09:28:37 -0800859 final PhoneAccountHandle connectionMgrPhoneAccount =
860 (PhoneAccountHandle) args.arg4;
Tyler Gunn44e01912017-01-31 10:49:05 -0800861 if (!mAreAccountsInitialized) {
862 Log.d(this, "Enqueueing pre-init request %s", id);
863 mPreInitializationConnectionRequests.add(
864 new android.telecom.Logging.Runnable(
865 SESSION_HANDLER + SESSION_CREATE_CONN_FAILED + ".pICR",
866 null /*lock*/) {
867 @Override
868 public void loggedRun() {
Tyler Gunn159f35c2017-03-02 09:28:37 -0800869 createConnectionFailed(connectionMgrPhoneAccount, id,
870 request, isIncoming);
Tyler Gunn44e01912017-01-31 10:49:05 -0800871 }
872 }.prepare());
873 } else {
874 Log.i(this, "createConnectionFailed %s", id);
Tyler Gunn159f35c2017-03-02 09:28:37 -0800875 createConnectionFailed(connectionMgrPhoneAccount, id, request,
876 isIncoming);
Tyler Gunn44e01912017-01-31 10:49:05 -0800877 }
878 } finally {
879 args.recycle();
880 Log.endSession();
881 }
882 break;
883 }
Ravi Paluri80aa2142019-12-02 11:57:37 +0530884 case MSG_CREATE_CONFERENCE: {
885 SomeArgs args = (SomeArgs) msg.obj;
886 Log.continueSession((Session) args.arg4, SESSION_HANDLER + SESSION_CREATE_CONN);
887 try {
888 final PhoneAccountHandle connectionManagerPhoneAccount =
889 (PhoneAccountHandle) args.arg1;
890 final String id = (String) args.arg2;
891 final ConnectionRequest request = (ConnectionRequest) args.arg3;
892 final boolean isIncoming = args.argi1 == 1;
893 final boolean isUnknown = args.argi2 == 1;
894 if (!mAreAccountsInitialized) {
895 Log.d(this, "Enqueueing pre-initconference request %s", id);
896 mPreInitializationConnectionRequests.add(
897 new android.telecom.Logging.Runnable(
898 SESSION_HANDLER + SESSION_CREATE_CONF + ".pIConfR",
899 null /*lock*/) {
900 @Override
901 public void loggedRun() {
902 createConference(connectionManagerPhoneAccount,
903 id,
904 request,
905 isIncoming,
906 isUnknown);
907 }
908 }.prepare());
909 } else {
910 createConference(connectionManagerPhoneAccount,
911 id,
912 request,
913 isIncoming,
914 isUnknown);
915 }
916 } finally {
917 args.recycle();
918 Log.endSession();
919 }
920 break;
921 }
922 case MSG_CREATE_CONFERENCE_COMPLETE: {
923 SomeArgs args = (SomeArgs) msg.obj;
924 Log.continueSession((Session) args.arg2,
925 SESSION_HANDLER + SESSION_CREATE_CONN_COMPLETE);
926 try {
927 final String id = (String) args.arg1;
928 if (!mAreAccountsInitialized) {
929 Log.d(this, "Enqueueing pre-init conference request %s", id);
930 mPreInitializationConnectionRequests.add(
931 new android.telecom.Logging.Runnable(
932 SESSION_HANDLER + SESSION_CREATE_CONF_COMPLETE
933 + ".pIConfR",
934 null /*lock*/) {
935 @Override
936 public void loggedRun() {
937 notifyCreateConferenceComplete(id);
938 }
939 }.prepare());
940 } else {
941 notifyCreateConferenceComplete(id);
942 }
943 } finally {
944 args.recycle();
945 Log.endSession();
946 }
947 break;
948 }
949 case MSG_CREATE_CONFERENCE_FAILED: {
950 SomeArgs args = (SomeArgs) msg.obj;
951 Log.continueSession((Session) args.arg3, SESSION_HANDLER +
952 SESSION_CREATE_CONN_FAILED);
953 try {
954 final String id = (String) args.arg1;
955 final ConnectionRequest request = (ConnectionRequest) args.arg2;
956 final boolean isIncoming = args.argi1 == 1;
957 final PhoneAccountHandle connectionMgrPhoneAccount =
958 (PhoneAccountHandle) args.arg4;
959 if (!mAreAccountsInitialized) {
960 Log.d(this, "Enqueueing pre-init conference request %s", id);
961 mPreInitializationConnectionRequests.add(
962 new android.telecom.Logging.Runnable(
963 SESSION_HANDLER + SESSION_CREATE_CONF_FAILED
964 + ".pIConfR",
965 null /*lock*/) {
966 @Override
967 public void loggedRun() {
968 createConferenceFailed(connectionMgrPhoneAccount, id,
969 request, isIncoming);
970 }
971 }.prepare());
972 } else {
973 Log.i(this, "createConferenceFailed %s", id);
974 createConferenceFailed(connectionMgrPhoneAccount, id, request,
975 isIncoming);
976 }
977 } finally {
978 args.recycle();
979 Log.endSession();
980 }
981 break;
982 }
983
Sanket Padawe4cc8ed52017-12-04 16:22:20 -0800984 case MSG_HANDOVER_FAILED: {
985 SomeArgs args = (SomeArgs) msg.obj;
986 Log.continueSession((Session) args.arg3, SESSION_HANDLER +
987 SESSION_HANDOVER_FAILED);
988 try {
989 final String id = (String) args.arg1;
990 final ConnectionRequest request = (ConnectionRequest) args.arg2;
991 final int reason = (int) args.arg4;
992 if (!mAreAccountsInitialized) {
993 Log.d(this, "Enqueueing pre-init request %s", id);
994 mPreInitializationConnectionRequests.add(
995 new android.telecom.Logging.Runnable(
996 SESSION_HANDLER
997 + SESSION_HANDOVER_FAILED + ".pICR",
998 null /*lock*/) {
999 @Override
1000 public void loggedRun() {
1001 handoverFailed(id, request, reason);
1002 }
1003 }.prepare());
1004 } else {
1005 Log.i(this, "createConnectionFailed %s", id);
1006 handoverFailed(id, request, reason);
1007 }
1008 } finally {
1009 args.recycle();
1010 Log.endSession();
1011 }
1012 break;
1013 }
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001014 case MSG_ABORT: {
1015 SomeArgs args = (SomeArgs) msg.obj;
1016 Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_ABORT);
1017 try {
1018 abort((String) args.arg1);
1019 } finally {
1020 args.recycle();
1021 Log.endSession();
1022 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001023 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001024 }
1025 case MSG_ANSWER: {
1026 SomeArgs args = (SomeArgs) msg.obj;
1027 Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_ANSWER);
1028 try {
1029 answer((String) args.arg1);
1030 } finally {
1031 args.recycle();
1032 Log.endSession();
1033 }
Tyler Gunnbe74de02014-08-29 14:51:48 -07001034 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001035 }
Tyler Gunnbe74de02014-08-29 14:51:48 -07001036 case MSG_ANSWER_VIDEO: {
Andrew Lee8da4c3c2014-07-16 10:11:42 -07001037 SomeArgs args = (SomeArgs) msg.obj;
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001038 Log.continueSession((Session) args.arg2,
1039 SESSION_HANDLER + SESSION_ANSWER_VIDEO);
Andrew Lee8da4c3c2014-07-16 10:11:42 -07001040 try {
1041 String callId = (String) args.arg1;
Evan Charltonbf11f982014-07-20 22:06:28 -07001042 int videoState = args.argi1;
Tyler Gunnbe74de02014-08-29 14:51:48 -07001043 answerVideo(callId, videoState);
Andrew Lee8da4c3c2014-07-16 10:11:42 -07001044 } finally {
1045 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001046 Log.endSession();
Andrew Lee8da4c3c2014-07-16 10:11:42 -07001047 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001048 break;
Andrew Lee8da4c3c2014-07-16 10:11:42 -07001049 }
Pooja Jaind34698d2017-12-28 14:15:31 +05301050 case MSG_DEFLECT: {
1051 SomeArgs args = (SomeArgs) msg.obj;
1052 Log.continueSession((Session) args.arg3, SESSION_HANDLER + SESSION_DEFLECT);
1053 try {
1054 deflect((String) args.arg1, (Uri) args.arg2);
1055 } finally {
1056 args.recycle();
1057 Log.endSession();
1058 }
1059 break;
1060 }
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001061 case MSG_REJECT: {
1062 SomeArgs args = (SomeArgs) msg.obj;
1063 Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_REJECT);
1064 try {
1065 reject((String) args.arg1);
1066 } finally {
1067 args.recycle();
1068 Log.endSession();
1069 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001070 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001071 }
Tyler Gunnfacfdee2020-01-23 13:10:37 -08001072 case MSG_REJECT_WITH_REASON: {
1073 SomeArgs args = (SomeArgs) msg.obj;
1074 Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_REJECT);
1075 try {
1076 reject((String) args.arg1, args.argi1);
1077 } finally {
1078 args.recycle();
1079 Log.endSession();
1080 }
1081 break;
1082 }
Bryce Lee81901682015-08-28 16:38:02 -07001083 case MSG_REJECT_WITH_MESSAGE: {
1084 SomeArgs args = (SomeArgs) msg.obj;
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001085 Log.continueSession((Session) args.arg3,
1086 SESSION_HANDLER + SESSION_REJECT_MESSAGE);
Bryce Lee81901682015-08-28 16:38:02 -07001087 try {
1088 reject((String) args.arg1, (String) args.arg2);
1089 } finally {
1090 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001091 Log.endSession();
Bryce Lee81901682015-08-28 16:38:02 -07001092 }
1093 break;
1094 }
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001095 case MSG_DISCONNECT: {
1096 SomeArgs args = (SomeArgs) msg.obj;
1097 Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_DISCONNECT);
1098 try {
1099 disconnect((String) args.arg1);
1100 } finally {
1101 args.recycle();
1102 Log.endSession();
1103 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001104 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001105 }
1106 case MSG_SILENCE: {
1107 SomeArgs args = (SomeArgs) msg.obj;
1108 Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_SILENCE);
1109 try {
1110 silence((String) args.arg1);
1111 } finally {
1112 args.recycle();
1113 Log.endSession();
1114 }
Bryce Leecac50772015-11-17 15:13:29 -08001115 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001116 }
1117 case MSG_HOLD: {
1118 SomeArgs args = (SomeArgs) msg.obj;
1119 Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_REJECT);
1120 try {
1121 hold((String) args.arg1);
1122 } finally {
1123 args.recycle();
1124 Log.endSession();
1125 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001126 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001127 }
1128 case MSG_UNHOLD: {
1129 SomeArgs args = (SomeArgs) msg.obj;
1130 Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_UNHOLD);
1131 try {
1132 unhold((String) args.arg1);
1133 } finally {
1134 args.recycle();
1135 Log.endSession();
1136 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001137 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001138 }
Yorke Lee4af59352015-05-13 14:14:54 -07001139 case MSG_ON_CALL_AUDIO_STATE_CHANGED: {
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001140 SomeArgs args = (SomeArgs) msg.obj;
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001141 Log.continueSession((Session) args.arg3,
1142 SESSION_HANDLER + SESSION_CALL_AUDIO_SC);
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001143 try {
1144 String callId = (String) args.arg1;
Yorke Lee4af59352015-05-13 14:14:54 -07001145 CallAudioState audioState = (CallAudioState) args.arg2;
1146 onCallAudioStateChanged(callId, new CallAudioState(audioState));
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001147 } finally {
1148 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001149 Log.endSession();
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001150 }
1151 break;
1152 }
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001153 case MSG_PLAY_DTMF_TONE: {
1154 SomeArgs args = (SomeArgs) msg.obj;
1155 try {
1156 Log.continueSession((Session) args.arg3,
1157 SESSION_HANDLER + SESSION_PLAY_DTMF);
1158 playDtmfTone((String) args.arg2, (char) args.arg1);
1159 } finally {
1160 args.recycle();
1161 Log.endSession();
1162 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001163 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001164 }
1165 case MSG_STOP_DTMF_TONE: {
1166 SomeArgs args = (SomeArgs) msg.obj;
1167 try {
1168 Log.continueSession((Session) args.arg2,
1169 SESSION_HANDLER + SESSION_STOP_DTMF);
1170 stopDtmfTone((String) args.arg1);
1171 } finally {
1172 args.recycle();
1173 Log.endSession();
1174 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001175 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001176 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001177 case MSG_CONFERENCE: {
1178 SomeArgs args = (SomeArgs) msg.obj;
1179 try {
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001180 Log.continueSession((Session) args.arg3,
1181 SESSION_HANDLER + SESSION_CONFERENCE);
Santos Cordon823fd3c2014-08-07 18:35:18 -07001182 String callId1 = (String) args.arg1;
1183 String callId2 = (String) args.arg2;
1184 conference(callId1, callId2);
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001185 } finally {
1186 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001187 Log.endSession();
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001188 }
1189 break;
1190 }
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001191 case MSG_SPLIT_FROM_CONFERENCE: {
1192 SomeArgs args = (SomeArgs) msg.obj;
1193 try {
1194 Log.continueSession((Session) args.arg2,
1195 SESSION_HANDLER + SESSION_SPLIT_CONFERENCE);
1196 splitFromConference((String) args.arg1);
1197 } finally {
1198 args.recycle();
1199 Log.endSession();
1200 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001201 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001202 }
1203 case MSG_MERGE_CONFERENCE: {
1204 SomeArgs args = (SomeArgs) msg.obj;
1205 try {
1206 Log.continueSession((Session) args.arg2,
1207 SESSION_HANDLER + SESSION_MERGE_CONFERENCE);
1208 mergeConference((String) args.arg1);
1209 } finally {
1210 args.recycle();
1211 Log.endSession();
1212 }
Santos Cordona4868042014-09-04 17:39:22 -07001213 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001214 }
1215 case MSG_SWAP_CONFERENCE: {
1216 SomeArgs args = (SomeArgs) msg.obj;
1217 try {
1218 Log.continueSession((Session) args.arg2,
1219 SESSION_HANDLER + SESSION_SWAP_CONFERENCE);
1220 swapConference((String) args.arg1);
1221 } finally {
1222 args.recycle();
1223 Log.endSession();
1224 }
Santos Cordona4868042014-09-04 17:39:22 -07001225 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001226 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001227 case MSG_ON_POST_DIAL_CONTINUE: {
1228 SomeArgs args = (SomeArgs) msg.obj;
1229 try {
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001230 Log.continueSession((Session) args.arg2,
1231 SESSION_HANDLER + SESSION_POST_DIAL_CONT);
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001232 String callId = (String) args.arg1;
1233 boolean proceed = (args.argi1 == 1);
1234 onPostDialContinue(callId, proceed);
1235 } finally {
1236 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001237 Log.endSession();
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001238 }
1239 break;
1240 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001241 case MSG_PULL_EXTERNAL_CALL: {
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001242 SomeArgs args = (SomeArgs) msg.obj;
1243 try {
1244 Log.continueSession((Session) args.arg2,
1245 SESSION_HANDLER + SESSION_PULL_EXTERNAL_CALL);
1246 pullExternalCall((String) args.arg1);
1247 } finally {
1248 args.recycle();
1249 Log.endSession();
1250 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001251 break;
1252 }
1253 case MSG_SEND_CALL_EVENT: {
1254 SomeArgs args = (SomeArgs) msg.obj;
1255 try {
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001256 Log.continueSession((Session) args.arg4,
1257 SESSION_HANDLER + SESSION_SEND_CALL_EVENT);
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001258 String callId = (String) args.arg1;
1259 String event = (String) args.arg2;
1260 Bundle extras = (Bundle) args.arg3;
1261 sendCallEvent(callId, event, extras);
1262 } finally {
1263 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001264 Log.endSession();
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001265 }
1266 break;
1267 }
Tyler Gunn79bc1ec2018-01-22 15:17:54 -08001268 case MSG_HANDOVER_COMPLETE: {
1269 SomeArgs args = (SomeArgs) msg.obj;
1270 try {
1271 Log.continueSession((Session) args.arg2,
1272 SESSION_HANDLER + SESSION_HANDOVER_COMPLETE);
1273 String callId = (String) args.arg1;
1274 notifyHandoverComplete(callId);
1275 } finally {
1276 args.recycle();
1277 Log.endSession();
1278 }
1279 break;
1280 }
Tyler Gunndee56a82016-03-23 16:06:34 -07001281 case MSG_ON_EXTRAS_CHANGED: {
1282 SomeArgs args = (SomeArgs) msg.obj;
1283 try {
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001284 Log.continueSession((Session) args.arg3,
1285 SESSION_HANDLER + SESSION_EXTRAS_CHANGED);
Tyler Gunndee56a82016-03-23 16:06:34 -07001286 String callId = (String) args.arg1;
1287 Bundle extras = (Bundle) args.arg2;
1288 handleExtrasChanged(callId, extras);
1289 } finally {
1290 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001291 Log.endSession();
Tyler Gunndee56a82016-03-23 16:06:34 -07001292 }
1293 break;
1294 }
Hall Liub64ac4c2017-02-06 10:49:48 -08001295 case MSG_ON_START_RTT: {
1296 SomeArgs args = (SomeArgs) msg.obj;
1297 try {
1298 Log.continueSession((Session) args.arg3,
1299 SESSION_HANDLER + SESSION_START_RTT);
1300 String callId = (String) args.arg1;
1301 Connection.RttTextStream rttTextStream =
1302 (Connection.RttTextStream) args.arg2;
1303 startRtt(callId, rttTextStream);
1304 } finally {
1305 args.recycle();
1306 Log.endSession();
1307 }
1308 break;
1309 }
1310 case MSG_ON_STOP_RTT: {
1311 SomeArgs args = (SomeArgs) msg.obj;
1312 try {
1313 Log.continueSession((Session) args.arg2,
1314 SESSION_HANDLER + SESSION_STOP_RTT);
1315 String callId = (String) args.arg1;
1316 stopRtt(callId);
1317 } finally {
1318 args.recycle();
1319 Log.endSession();
1320 }
1321 break;
1322 }
1323 case MSG_RTT_UPGRADE_RESPONSE: {
1324 SomeArgs args = (SomeArgs) msg.obj;
1325 try {
1326 Log.continueSession((Session) args.arg3,
1327 SESSION_HANDLER + SESSION_RTT_UPGRADE_RESPONSE);
1328 String callId = (String) args.arg1;
1329 Connection.RttTextStream rttTextStream =
1330 (Connection.RttTextStream) args.arg2;
1331 handleRttUpgradeResponse(callId, rttTextStream);
1332 } finally {
1333 args.recycle();
1334 Log.endSession();
1335 }
1336 break;
1337 }
Pengquan Meng731c1a32017-11-21 18:01:13 -08001338 case MSG_CONNECTION_SERVICE_FOCUS_GAINED:
1339 onConnectionServiceFocusGained();
1340 break;
1341 case MSG_CONNECTION_SERVICE_FOCUS_LOST:
1342 onConnectionServiceFocusLost();
1343 break;
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001344 default:
1345 break;
1346 }
1347 }
1348 };
1349
Santos Cordon823fd3c2014-08-07 18:35:18 -07001350 private final Conference.Listener mConferenceListener = new Conference.Listener() {
1351 @Override
1352 public void onStateChanged(Conference conference, int oldState, int newState) {
1353 String id = mIdByConference.get(conference);
1354 switch (newState) {
Ravi Paluri80aa2142019-12-02 11:57:37 +05301355 case Connection.STATE_RINGING:
1356 mAdapter.setRinging(id);
1357 break;
1358 case Connection.STATE_DIALING:
1359 mAdapter.setDialing(id);
1360 break;
Santos Cordon823fd3c2014-08-07 18:35:18 -07001361 case Connection.STATE_ACTIVE:
1362 mAdapter.setActive(id);
1363 break;
1364 case Connection.STATE_HOLDING:
1365 mAdapter.setOnHold(id);
1366 break;
1367 case Connection.STATE_DISCONNECTED:
1368 // handled by onDisconnected
1369 break;
1370 }
1371 }
1372
1373 @Override
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001374 public void onDisconnected(Conference conference, DisconnectCause disconnectCause) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07001375 String id = mIdByConference.get(conference);
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001376 mAdapter.setDisconnected(id, disconnectCause);
Santos Cordon823fd3c2014-08-07 18:35:18 -07001377 }
1378
1379 @Override
1380 public void onConnectionAdded(Conference conference, Connection connection) {
1381 }
1382
1383 @Override
1384 public void onConnectionRemoved(Conference conference, Connection connection) {
1385 }
1386
1387 @Override
Ihab Awad50e35062014-09-30 09:17:03 -07001388 public void onConferenceableConnectionsChanged(
1389 Conference conference, List<Connection> conferenceableConnections) {
1390 mAdapter.setConferenceableConnections(
1391 mIdByConference.get(conference),
1392 createConnectionIdList(conferenceableConnections));
1393 }
1394
1395 @Override
Santos Cordon823fd3c2014-08-07 18:35:18 -07001396 public void onDestroyed(Conference conference) {
1397 removeConference(conference);
1398 }
1399
1400 @Override
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001401 public void onConnectionCapabilitiesChanged(
1402 Conference conference,
1403 int connectionCapabilities) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07001404 String id = mIdByConference.get(conference);
1405 Log.d(this, "call capabilities: conference: %s",
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001406 Connection.capabilitiesToString(connectionCapabilities));
1407 mAdapter.setConnectionCapabilities(id, connectionCapabilities);
Santos Cordon823fd3c2014-08-07 18:35:18 -07001408 }
Rekha Kumar07366812015-03-24 16:42:31 -07001409
1410 @Override
Tyler Gunn720c6642016-03-22 09:02:47 -07001411 public void onConnectionPropertiesChanged(
1412 Conference conference,
1413 int connectionProperties) {
1414 String id = mIdByConference.get(conference);
1415 Log.d(this, "call capabilities: conference: %s",
1416 Connection.propertiesToString(connectionProperties));
1417 mAdapter.setConnectionProperties(id, connectionProperties);
1418 }
1419
1420 @Override
Rekha Kumar07366812015-03-24 16:42:31 -07001421 public void onVideoStateChanged(Conference c, int videoState) {
1422 String id = mIdByConference.get(c);
1423 Log.d(this, "onVideoStateChanged set video state %d", videoState);
1424 mAdapter.setVideoState(id, videoState);
1425 }
1426
1427 @Override
1428 public void onVideoProviderChanged(Conference c, Connection.VideoProvider videoProvider) {
1429 String id = mIdByConference.get(c);
1430 Log.d(this, "onVideoProviderChanged: Connection: %s, VideoProvider: %s", c,
1431 videoProvider);
1432 mAdapter.setVideoProvider(id, videoProvider);
1433 }
Andrew Lee0f51da32015-04-16 13:11:55 -07001434
1435 @Override
Andrew Leeedc625f2015-04-14 13:38:12 -07001436 public void onStatusHintsChanged(Conference conference, StatusHints statusHints) {
1437 String id = mIdByConference.get(conference);
Tyler Gunndee56a82016-03-23 16:06:34 -07001438 if (id != null) {
1439 mAdapter.setStatusHints(id, statusHints);
1440 }
Andrew Leeedc625f2015-04-14 13:38:12 -07001441 }
Santos Cordon6b7f9552015-05-27 17:21:45 -07001442
1443 @Override
Tyler Gunndee56a82016-03-23 16:06:34 -07001444 public void onExtrasChanged(Conference c, Bundle extras) {
1445 String id = mIdByConference.get(c);
1446 if (id != null) {
1447 mAdapter.putExtras(id, extras);
1448 }
1449 }
1450
1451 @Override
1452 public void onExtrasRemoved(Conference c, List<String> keys) {
1453 String id = mIdByConference.get(c);
1454 if (id != null) {
1455 mAdapter.removeExtras(id, keys);
1456 }
Santos Cordon6b7f9552015-05-27 17:21:45 -07001457 }
Tyler Gunn68a73a42018-10-03 15:38:57 -07001458
1459 @Override
1460 public void onConferenceStateChanged(Conference c, boolean isConference) {
1461 String id = mIdByConference.get(c);
1462 if (id != null) {
1463 mAdapter.setConferenceState(id, isConference);
1464 }
1465 }
1466
1467 @Override
1468 public void onAddressChanged(Conference c, Uri newAddress, int presentation) {
1469 String id = mIdByConference.get(c);
1470 if (id != null) {
1471 mAdapter.setAddress(id, newAddress, presentation);
1472 }
1473 }
1474
1475 @Override
1476 public void onCallerDisplayNameChanged(Conference c, String callerDisplayName,
1477 int presentation) {
1478 String id = mIdByConference.get(c);
1479 if (id != null) {
1480 mAdapter.setCallerDisplayName(id, callerDisplayName, presentation);
1481 }
1482 }
Hall Liuc9bc1c62019-04-16 14:00:55 -07001483
1484 @Override
1485 public void onConnectionEvent(Conference c, String event, Bundle extras) {
1486 String id = mIdByConference.get(c);
1487 if (id != null) {
1488 mAdapter.onConnectionEvent(id, event, extras);
1489 }
1490 }
Ravi Paluri80aa2142019-12-02 11:57:37 +05301491
1492 @Override
1493 public void onRingbackRequested(Conference c, boolean ringback) {
1494 String id = mIdByConference.get(c);
1495 Log.d(this, "Adapter conference onRingback %b", ringback);
1496 mAdapter.setRingbackRequested(id, ringback);
1497 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07001498 };
1499
Ihab Awad542e0ea2014-05-16 10:22:16 -07001500 private final Connection.Listener mConnectionListener = new Connection.Listener() {
1501 @Override
1502 public void onStateChanged(Connection c, int state) {
1503 String id = mIdByConnection.get(c);
Ihab Awad42b30e12014-05-22 09:49:34 -07001504 Log.d(this, "Adapter set state %s %s", id, Connection.stateToString(state));
Ihab Awad542e0ea2014-05-16 10:22:16 -07001505 switch (state) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001506 case Connection.STATE_ACTIVE:
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001507 mAdapter.setActive(id);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001508 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001509 case Connection.STATE_DIALING:
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001510 mAdapter.setDialing(id);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001511 break;
Tyler Gunnc96b5e02016-07-07 22:53:57 -07001512 case Connection.STATE_PULLING_CALL:
1513 mAdapter.setPulling(id);
1514 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001515 case Connection.STATE_DISCONNECTED:
Ihab Awad542e0ea2014-05-16 10:22:16 -07001516 // Handled in onDisconnected()
1517 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001518 case Connection.STATE_HOLDING:
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001519 mAdapter.setOnHold(id);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001520 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001521 case Connection.STATE_NEW:
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001522 // Nothing to tell Telecom
Ihab Awad542e0ea2014-05-16 10:22:16 -07001523 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001524 case Connection.STATE_RINGING:
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001525 mAdapter.setRinging(id);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001526 break;
1527 }
1528 }
1529
1530 @Override
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001531 public void onDisconnected(Connection c, DisconnectCause disconnectCause) {
Ihab Awad542e0ea2014-05-16 10:22:16 -07001532 String id = mIdByConnection.get(c);
Andrew Lee26786392014-09-16 18:14:59 -07001533 Log.d(this, "Adapter set disconnected %s", disconnectCause);
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001534 mAdapter.setDisconnected(id, disconnectCause);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001535 }
1536
1537 @Override
Tyler Gunnaa07df82014-07-17 07:50:22 -07001538 public void onVideoStateChanged(Connection c, int videoState) {
1539 String id = mIdByConnection.get(c);
1540 Log.d(this, "Adapter set video state %d", videoState);
1541 mAdapter.setVideoState(id, videoState);
1542 }
1543
1544 @Override
Andrew Lee100e2932014-09-08 15:34:24 -07001545 public void onAddressChanged(Connection c, Uri address, int presentation) {
Sailesh Nepal61203862014-07-11 14:50:13 -07001546 String id = mIdByConnection.get(c);
Andrew Lee100e2932014-09-08 15:34:24 -07001547 mAdapter.setAddress(id, address, presentation);
Sailesh Nepal61203862014-07-11 14:50:13 -07001548 }
1549
1550 @Override
1551 public void onCallerDisplayNameChanged(
1552 Connection c, String callerDisplayName, int presentation) {
1553 String id = mIdByConnection.get(c);
1554 mAdapter.setCallerDisplayName(id, callerDisplayName, presentation);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001555 }
1556
1557 @Override
Ihab Awad542e0ea2014-05-16 10:22:16 -07001558 public void onDestroyed(Connection c) {
1559 removeConnection(c);
1560 }
Ihab Awadf8358972014-05-28 16:46:42 -07001561
1562 @Override
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001563 public void onPostDialWait(Connection c, String remaining) {
Sailesh Nepal091768c2014-06-30 15:15:23 -07001564 String id = mIdByConnection.get(c);
1565 Log.d(this, "Adapter onPostDialWait %s, %s", c, remaining);
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001566 mAdapter.onPostDialWait(id, remaining);
Sailesh Nepal091768c2014-06-30 15:15:23 -07001567 }
1568
1569 @Override
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001570 public void onPostDialChar(Connection c, char nextChar) {
1571 String id = mIdByConnection.get(c);
1572 Log.d(this, "Adapter onPostDialChar %s, %s", c, nextChar);
1573 mAdapter.onPostDialChar(id, nextChar);
1574 }
1575
1576 @Override
Andrew Lee100e2932014-09-08 15:34:24 -07001577 public void onRingbackRequested(Connection c, boolean ringback) {
Ihab Awadf8358972014-05-28 16:46:42 -07001578 String id = mIdByConnection.get(c);
1579 Log.d(this, "Adapter onRingback %b", ringback);
Andrew Lee100e2932014-09-08 15:34:24 -07001580 mAdapter.setRingbackRequested(id, ringback);
Ihab Awadf8358972014-05-28 16:46:42 -07001581 }
Santos Cordonb6939982014-06-04 20:20:58 -07001582
1583 @Override
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001584 public void onConnectionCapabilitiesChanged(Connection c, int capabilities) {
Santos Cordonb6939982014-06-04 20:20:58 -07001585 String id = mIdByConnection.get(c);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001586 Log.d(this, "capabilities: parcelableconnection: %s",
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001587 Connection.capabilitiesToString(capabilities));
1588 mAdapter.setConnectionCapabilities(id, capabilities);
Santos Cordonb6939982014-06-04 20:20:58 -07001589 }
1590
Santos Cordonb6939982014-06-04 20:20:58 -07001591 @Override
Tyler Gunn720c6642016-03-22 09:02:47 -07001592 public void onConnectionPropertiesChanged(Connection c, int properties) {
1593 String id = mIdByConnection.get(c);
1594 Log.d(this, "properties: parcelableconnection: %s",
1595 Connection.propertiesToString(properties));
1596 mAdapter.setConnectionProperties(id, properties);
1597 }
1598
1599 @Override
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001600 public void onVideoProviderChanged(Connection c, Connection.VideoProvider videoProvider) {
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07001601 String id = mIdByConnection.get(c);
Rekha Kumar07366812015-03-24 16:42:31 -07001602 Log.d(this, "onVideoProviderChanged: Connection: %s, VideoProvider: %s", c,
1603 videoProvider);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001604 mAdapter.setVideoProvider(id, videoProvider);
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07001605 }
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001606
1607 @Override
Sailesh Nepal001bbbb2014-07-15 14:40:39 -07001608 public void onAudioModeIsVoipChanged(Connection c, boolean isVoip) {
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001609 String id = mIdByConnection.get(c);
Andrew Lee100e2932014-09-08 15:34:24 -07001610 mAdapter.setIsVoipAudioMode(id, isVoip);
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001611 }
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001612
1613 @Override
Sailesh Nepal001bbbb2014-07-15 14:40:39 -07001614 public void onStatusHintsChanged(Connection c, StatusHints statusHints) {
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001615 String id = mIdByConnection.get(c);
1616 mAdapter.setStatusHints(id, statusHints);
1617 }
Sailesh Nepal2ab88cc2014-07-18 14:49:18 -07001618
1619 @Override
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001620 public void onConferenceablesChanged(
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001621 Connection connection, List<Conferenceable> conferenceables) {
Ihab Awadb8e85c72014-08-23 20:34:57 -07001622 mAdapter.setConferenceableConnections(
1623 mIdByConnection.get(connection),
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001624 createIdList(conferenceables));
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001625 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07001626
1627 @Override
1628 public void onConferenceChanged(Connection connection, Conference conference) {
1629 String id = mIdByConnection.get(connection);
1630 if (id != null) {
1631 String conferenceId = null;
1632 if (conference != null) {
1633 conferenceId = mIdByConference.get(conference);
1634 }
1635 mAdapter.setIsConferenced(id, conferenceId);
1636 }
1637 }
Anthony Lee17455a32015-04-24 15:25:29 -07001638
1639 @Override
1640 public void onConferenceMergeFailed(Connection connection) {
1641 String id = mIdByConnection.get(connection);
1642 if (id != null) {
1643 mAdapter.onConferenceMergeFailed(id);
1644 }
1645 }
Santos Cordon6b7f9552015-05-27 17:21:45 -07001646
1647 @Override
Tyler Gunndee56a82016-03-23 16:06:34 -07001648 public void onExtrasChanged(Connection c, Bundle extras) {
1649 String id = mIdByConnection.get(c);
Santos Cordon6b7f9552015-05-27 17:21:45 -07001650 if (id != null) {
Tyler Gunndee56a82016-03-23 16:06:34 -07001651 mAdapter.putExtras(id, extras);
Santos Cordon6b7f9552015-05-27 17:21:45 -07001652 }
1653 }
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001654
Tyler Gunnf5035432017-01-09 09:43:12 -08001655 @Override
Tyler Gunndee56a82016-03-23 16:06:34 -07001656 public void onExtrasRemoved(Connection c, List<String> keys) {
1657 String id = mIdByConnection.get(c);
1658 if (id != null) {
1659 mAdapter.removeExtras(id, keys);
1660 }
1661 }
1662
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08001663 @Override
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001664 public void onConnectionEvent(Connection connection, String event, Bundle extras) {
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08001665 String id = mIdByConnection.get(connection);
1666 if (id != null) {
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001667 mAdapter.onConnectionEvent(id, event, extras);
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08001668 }
1669 }
Tyler Gunnf5035432017-01-09 09:43:12 -08001670
1671 @Override
Hall Liua98f58b52017-11-07 17:59:28 -08001672 public void onAudioRouteChanged(Connection c, int audioRoute, String bluetoothAddress) {
Tyler Gunnf5035432017-01-09 09:43:12 -08001673 String id = mIdByConnection.get(c);
1674 if (id != null) {
Hall Liua98f58b52017-11-07 17:59:28 -08001675 mAdapter.setAudioRoute(id, audioRoute, bluetoothAddress);
Tyler Gunnf5035432017-01-09 09:43:12 -08001676 }
1677 }
Hall Liub64ac4c2017-02-06 10:49:48 -08001678
1679 @Override
1680 public void onRttInitiationSuccess(Connection c) {
1681 String id = mIdByConnection.get(c);
1682 if (id != null) {
1683 mAdapter.onRttInitiationSuccess(id);
1684 }
1685 }
1686
1687 @Override
1688 public void onRttInitiationFailure(Connection c, int reason) {
1689 String id = mIdByConnection.get(c);
1690 if (id != null) {
1691 mAdapter.onRttInitiationFailure(id, reason);
1692 }
1693 }
1694
1695 @Override
1696 public void onRttSessionRemotelyTerminated(Connection c) {
1697 String id = mIdByConnection.get(c);
1698 if (id != null) {
1699 mAdapter.onRttSessionRemotelyTerminated(id);
1700 }
1701 }
1702
1703 @Override
1704 public void onRemoteRttRequest(Connection c) {
1705 String id = mIdByConnection.get(c);
1706 if (id != null) {
1707 mAdapter.onRemoteRttRequest(id);
1708 }
1709 }
Srikanth Chintalafcb15012017-05-04 20:58:34 +05301710
1711 @Override
1712 public void onPhoneAccountChanged(Connection c, PhoneAccountHandle pHandle) {
1713 String id = mIdByConnection.get(c);
1714 if (id != null) {
1715 mAdapter.onPhoneAccountChanged(id, pHandle);
1716 }
1717 }
Mengjun Leng25707742017-07-04 11:10:37 +08001718
1719 public void onConnectionTimeReset(Connection c) {
1720 String id = mIdByConnection.get(c);
1721 if (id != null) {
1722 mAdapter.resetConnectionTime(id);
1723 }
1724 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001725 };
1726
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001727 /** {@inheritDoc} */
Ihab Awad542e0ea2014-05-16 10:22:16 -07001728 @Override
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001729 public final IBinder onBind(Intent intent) {
1730 return mBinder;
1731 }
1732
Santos Cordon29f2f2e2014-09-11 19:50:24 -07001733 /** {@inheritDoc} */
1734 @Override
1735 public boolean onUnbind(Intent intent) {
1736 endAllConnections();
1737 return super.onUnbind(intent);
1738 }
1739
Ravi Paluri80aa2142019-12-02 11:57:37 +05301740
1741 /**
1742 * This can be used by telecom to either create a new outgoing conference call or attach
1743 * to an existing incoming conference call. In either case, telecom will cycle through a
1744 * set of services and call createConference until a connection service cancels the process
1745 * or completes it successfully.
1746 */
1747 private void createConference(
1748 final PhoneAccountHandle callManagerAccount,
1749 final String callId,
1750 final ConnectionRequest request,
1751 boolean isIncoming,
1752 boolean isUnknown) {
1753
1754 Conference conference = null;
1755 conference = isIncoming ? onCreateIncomingConference(callManagerAccount, request)
1756 : onCreateOutgoingConference(callManagerAccount, request);
1757
1758 Log.d(this, "createConference, conference: %s", conference);
1759 if (conference == null) {
1760 Log.i(this, "createConference, implementation returned null conference.");
1761 conference = Conference.createFailedConference(
1762 new DisconnectCause(DisconnectCause.ERROR, "IMPL_RETURNED_NULL_CONFERENCE"),
1763 request.getAccountHandle());
1764 }
1765 if (conference.getExtras() != null) {
1766 conference.getExtras().putString(Connection.EXTRA_ORIGINAL_CONNECTION_ID, callId);
1767 }
1768 mConferenceById.put(callId, conference);
1769 mIdByConference.put(conference, callId);
1770 conference.addListener(mConferenceListener);
1771 ParcelableConference parcelableConference = new ParcelableConference(
1772 request.getAccountHandle(),
1773 conference.getState(),
1774 conference.getConnectionCapabilities(),
1775 conference.getConnectionProperties(),
1776 Collections.<String>emptyList(), //connectionIds
1777 conference.getVideoProvider() == null ?
1778 null : conference.getVideoProvider().getInterface(),
1779 conference.getVideoState(),
1780 conference.getConnectTimeMillis(),
1781 conference.getConnectionStartElapsedRealTime(),
1782 conference.getStatusHints(),
1783 conference.getExtras(),
1784 conference.getAddress(),
1785 conference.getAddressPresentation(),
1786 conference.getCallerDisplayName(),
1787 conference.getCallerDisplayNamePresentation(),
1788 conference.getDisconnectCause(),
1789 conference.isRingbackRequested());
1790 if (conference.getState() != Connection.STATE_DISCONNECTED) {
1791 conference.setTelecomCallId(callId);
1792 mAdapter.setVideoProvider(callId, conference.getVideoProvider());
1793 mAdapter.setVideoState(callId, conference.getVideoState());
1794 onConferenceAdded(conference);
1795 }
1796
1797 Log.d(this, "createConference, calling handleCreateConferenceSuccessful %s", callId);
1798 mAdapter.handleCreateConferenceComplete(
1799 callId,
1800 request,
1801 parcelableConference);
1802 }
1803
Sailesh Nepalc5b01572014-07-14 16:29:44 -07001804 /**
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001805 * This can be used by telecom to either create a new outgoing call or attach to an existing
1806 * incoming call. In either case, telecom will cycle through a set of services and call
Sailesh Nepalc5b01572014-07-14 16:29:44 -07001807 * createConnection util a connection service cancels the process or completes it successfully.
1808 */
Ihab Awadf8b69882014-07-25 15:14:01 -07001809 private void createConnection(
1810 final PhoneAccountHandle callManagerAccount,
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001811 final String callId,
Ihab Awadf8b69882014-07-25 15:14:01 -07001812 final ConnectionRequest request,
Yorke Leec3cf9822014-10-02 09:38:39 -07001813 boolean isIncoming,
1814 boolean isUnknown) {
Tyler Gunn79bc1ec2018-01-22 15:17:54 -08001815 boolean isLegacyHandover = request.getExtras() != null &&
1816 request.getExtras().getBoolean(TelecomManager.EXTRA_IS_HANDOVER, false);
1817 boolean isHandover = request.getExtras() != null && request.getExtras().getBoolean(
1818 TelecomManager.EXTRA_IS_HANDOVER_CONNECTION, false);
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001819 Log.d(this, "createConnection, callManagerAccount: %s, callId: %s, request: %s, " +
Tyler Gunn79bc1ec2018-01-22 15:17:54 -08001820 "isIncoming: %b, isUnknown: %b, isLegacyHandover: %b, isHandover: %b",
1821 callManagerAccount, callId, request, isIncoming, isUnknown, isLegacyHandover,
1822 isHandover);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001823
Sanket Padawee29a2662017-12-01 13:59:27 -08001824 Connection connection = null;
Tyler Gunn79bc1ec2018-01-22 15:17:54 -08001825 if (isHandover) {
1826 PhoneAccountHandle fromPhoneAccountHandle = request.getExtras() != null
1827 ? (PhoneAccountHandle) request.getExtras().getParcelable(
1828 TelecomManager.EXTRA_HANDOVER_FROM_PHONE_ACCOUNT) : null;
Sanket Padawee29a2662017-12-01 13:59:27 -08001829 if (!isIncoming) {
Tyler Gunn79bc1ec2018-01-22 15:17:54 -08001830 connection = onCreateOutgoingHandoverConnection(fromPhoneAccountHandle, request);
Sanket Padawee29a2662017-12-01 13:59:27 -08001831 } else {
Tyler Gunn79bc1ec2018-01-22 15:17:54 -08001832 connection = onCreateIncomingHandoverConnection(fromPhoneAccountHandle, request);
Sanket Padawee29a2662017-12-01 13:59:27 -08001833 }
1834 } else {
1835 connection = isUnknown ? onCreateUnknownConnection(callManagerAccount, request)
1836 : isIncoming ? onCreateIncomingConnection(callManagerAccount, request)
1837 : onCreateOutgoingConnection(callManagerAccount, request);
1838 }
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001839 Log.d(this, "createConnection, connection: %s", connection);
1840 if (connection == null) {
Tyler Gunnfba1a8e2017-12-19 15:23:59 -08001841 Log.i(this, "createConnection, implementation returned null connection.");
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001842 connection = Connection.createFailedConnection(
Tyler Gunnfba1a8e2017-12-19 15:23:59 -08001843 new DisconnectCause(DisconnectCause.ERROR, "IMPL_RETURNED_NULL_CONNECTION"));
Sailesh Nepalc5b01572014-07-14 16:29:44 -07001844 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001845
Tyler Gunnf2e08b42018-05-24 10:44:44 -07001846 boolean isSelfManaged =
1847 (connection.getConnectionProperties() & Connection.PROPERTY_SELF_MANAGED)
1848 == Connection.PROPERTY_SELF_MANAGED;
1849 // Self-managed Connections should always use voip audio mode; we default here so that the
1850 // local state within the ConnectionService matches the default we assume in Telecom.
1851 if (isSelfManaged) {
1852 connection.setAudioModeIsVoip(true);
1853 }
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001854 connection.setTelecomCallId(callId);
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001855 if (connection.getState() != Connection.STATE_DISCONNECTED) {
Pengquan Meng70c9885332017-10-02 18:09:03 -07001856 addConnection(request.getAccountHandle(), callId, connection);
Ihab Awad6107bab2014-08-18 09:23:25 -07001857 }
1858
Andrew Lee100e2932014-09-08 15:34:24 -07001859 Uri address = connection.getAddress();
1860 String number = address == null ? "null" : address.getSchemeSpecificPart();
Tyler Gunn720c6642016-03-22 09:02:47 -07001861 Log.v(this, "createConnection, number: %s, state: %s, capabilities: %s, properties: %s",
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001862 Connection.toLogSafePhoneNumber(number),
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001863 Connection.stateToString(connection.getState()),
Tyler Gunn720c6642016-03-22 09:02:47 -07001864 Connection.capabilitiesToString(connection.getConnectionCapabilities()),
1865 Connection.propertiesToString(connection.getConnectionProperties()));
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001866
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001867 Log.d(this, "createConnection, calling handleCreateConnectionSuccessful %s", callId);
Ihab Awad6107bab2014-08-18 09:23:25 -07001868 mAdapter.handleCreateConnectionComplete(
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001869 callId,
Evan Charltonbf11f982014-07-20 22:06:28 -07001870 request,
1871 new ParcelableConnection(
1872 request.getAccountHandle(),
1873 connection.getState(),
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001874 connection.getConnectionCapabilities(),
Tyler Gunn720c6642016-03-22 09:02:47 -07001875 connection.getConnectionProperties(),
Christine Hallstrom2830ce92016-11-30 16:06:42 -08001876 connection.getSupportedAudioRoutes(),
Andrew Lee100e2932014-09-08 15:34:24 -07001877 connection.getAddress(),
1878 connection.getAddressPresentation(),
Evan Charltonbf11f982014-07-20 22:06:28 -07001879 connection.getCallerDisplayName(),
1880 connection.getCallerDisplayNamePresentation(),
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001881 connection.getVideoProvider() == null ?
1882 null : connection.getVideoProvider().getInterface(),
Sailesh Nepal8b9d3ca2014-08-14 17:39:34 -07001883 connection.getVideoState(),
Andrew Lee100e2932014-09-08 15:34:24 -07001884 connection.isRingbackRequested(),
Sailesh Nepal8b9d3ca2014-08-14 17:39:34 -07001885 connection.getAudioModeIsVoip(),
Roshan Piuse927ec02015-07-15 15:47:21 -07001886 connection.getConnectTimeMillis(),
Tyler Gunn3fa819c2017-08-04 09:27:26 -07001887 connection.getConnectElapsedTimeMillis(),
Ihab Awad6107bab2014-08-18 09:23:25 -07001888 connection.getStatusHints(),
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001889 connection.getDisconnectCause(),
Santos Cordon6b7f9552015-05-27 17:21:45 -07001890 createIdList(connection.getConferenceables()),
Tyler Gunnd57d76c2019-09-24 14:53:23 -07001891 connection.getExtras(),
1892 connection.getCallerNumberVerificationStatus()));
Tyler Gunnf5035432017-01-09 09:43:12 -08001893
Tyler Gunnf2e08b42018-05-24 10:44:44 -07001894 if (isIncoming && request.shouldShowIncomingCallUi() && isSelfManaged) {
Tyler Gunnf5035432017-01-09 09:43:12 -08001895 // Tell ConnectionService to show its incoming call UX.
1896 connection.onShowIncomingCallUi();
1897 }
Shriram Ganesh6bf35ac2014-12-11 17:53:38 -08001898 if (isUnknown) {
1899 triggerConferenceRecalculate();
1900 }
Evan Charltonbf11f982014-07-20 22:06:28 -07001901 }
1902
Tyler Gunn159f35c2017-03-02 09:28:37 -08001903 private void createConnectionFailed(final PhoneAccountHandle callManagerAccount,
1904 final String callId, final ConnectionRequest request,
1905 boolean isIncoming) {
Tyler Gunn44e01912017-01-31 10:49:05 -08001906
1907 Log.i(this, "createConnectionFailed %s", callId);
1908 if (isIncoming) {
Tyler Gunn159f35c2017-03-02 09:28:37 -08001909 onCreateIncomingConnectionFailed(callManagerAccount, request);
Tyler Gunn44e01912017-01-31 10:49:05 -08001910 } else {
Tyler Gunn159f35c2017-03-02 09:28:37 -08001911 onCreateOutgoingConnectionFailed(callManagerAccount, request);
Tyler Gunn44e01912017-01-31 10:49:05 -08001912 }
1913 }
1914
Ravi Paluri80aa2142019-12-02 11:57:37 +05301915 private void createConferenceFailed(final PhoneAccountHandle callManagerAccount,
1916 final String callId, final ConnectionRequest request,
1917 boolean isIncoming) {
1918
1919 Log.i(this, "createConferenceFailed %s", callId);
1920 if (isIncoming) {
1921 onCreateIncomingConferenceFailed(callManagerAccount, request);
1922 } else {
1923 onCreateOutgoingConferenceFailed(callManagerAccount, request);
1924 }
1925 }
1926
Sanket Padawe4cc8ed52017-12-04 16:22:20 -08001927 private void handoverFailed(final String callId, final ConnectionRequest request,
1928 int reason) {
1929
1930 Log.i(this, "handoverFailed %s", callId);
1931 onHandoverFailed(request, reason);
1932 }
1933
Tyler Gunn041a1fe2017-05-12 10:04:49 -07001934 /**
1935 * Called by Telecom when the creation of a new Connection has completed and it is now added
1936 * to Telecom.
1937 * @param callId The ID of the connection.
1938 */
1939 private void notifyCreateConnectionComplete(final String callId) {
1940 Log.i(this, "notifyCreateConnectionComplete %s", callId);
Tyler Gunn0a88f2e2017-06-16 20:20:34 -07001941 if (callId == null) {
1942 // This could happen if the connection fails quickly and is removed from the
1943 // ConnectionService before Telecom sends the create connection complete callback.
1944 Log.w(this, "notifyCreateConnectionComplete: callId is null.");
1945 return;
1946 }
Tyler Gunn041a1fe2017-05-12 10:04:49 -07001947 onCreateConnectionComplete(findConnectionForAction(callId,
1948 "notifyCreateConnectionComplete"));
1949 }
1950
Ravi Paluri80aa2142019-12-02 11:57:37 +05301951 /**
1952 * Called by Telecom when the creation of a new Conference has completed and it is now added
1953 * to Telecom.
1954 * @param callId The ID of the connection.
1955 */
1956 private void notifyCreateConferenceComplete(final String callId) {
1957 Log.i(this, "notifyCreateConferenceComplete %s", callId);
1958 if (callId == null) {
1959 // This could happen if the conference fails quickly and is removed from the
1960 // ConnectionService before Telecom sends the create conference complete callback.
1961 Log.w(this, "notifyCreateConferenceComplete: callId is null.");
1962 return;
1963 }
1964 onCreateConferenceComplete(findConferenceForAction(callId,
1965 "notifyCreateConferenceComplete"));
1966 }
1967
1968
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001969 private void abort(String callId) {
Ihab Awad60ac30b2014-05-20 22:32:12 -07001970 Log.d(this, "abort %s", callId);
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001971 findConnectionForAction(callId, "abort").onAbort();
Ihab Awad542e0ea2014-05-16 10:22:16 -07001972 }
1973
Tyler Gunnbe74de02014-08-29 14:51:48 -07001974 private void answerVideo(String callId, int videoState) {
1975 Log.d(this, "answerVideo %s", callId);
Ravi Paluri80aa2142019-12-02 11:57:37 +05301976 if (mConnectionById.containsKey(callId)) {
1977 findConnectionForAction(callId, "answer").onAnswer(videoState);
1978 } else {
1979 findConferenceForAction(callId, "answer").onAnswer(videoState);
1980 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001981 }
1982
Tyler Gunnbe74de02014-08-29 14:51:48 -07001983 private void answer(String callId) {
1984 Log.d(this, "answer %s", callId);
Ravi Paluri80aa2142019-12-02 11:57:37 +05301985 if (mConnectionById.containsKey(callId)) {
1986 findConnectionForAction(callId, "answer").onAnswer();
1987 } else {
1988 findConferenceForAction(callId, "answer").onAnswer();
1989 }
Tyler Gunnbe74de02014-08-29 14:51:48 -07001990 }
1991
Pooja Jaind34698d2017-12-28 14:15:31 +05301992 private void deflect(String callId, Uri address) {
1993 Log.d(this, "deflect %s", callId);
1994 findConnectionForAction(callId, "deflect").onDeflect(address);
1995 }
1996
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001997 private void reject(String callId) {
Ihab Awad60ac30b2014-05-20 22:32:12 -07001998 Log.d(this, "reject %s", callId);
Ravi Paluri80aa2142019-12-02 11:57:37 +05301999 if (mConnectionById.containsKey(callId)) {
2000 findConnectionForAction(callId, "reject").onReject();
2001 } else {
2002 findConferenceForAction(callId, "reject").onReject();
2003 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002004 }
2005
Bryce Lee81901682015-08-28 16:38:02 -07002006 private void reject(String callId, String rejectWithMessage) {
2007 Log.d(this, "reject %s with message", callId);
2008 findConnectionForAction(callId, "reject").onReject(rejectWithMessage);
2009 }
2010
Tyler Gunnfacfdee2020-01-23 13:10:37 -08002011 private void reject(String callId, @android.telecom.Call.RejectReason int rejectReason) {
2012 Log.d(this, "reject %s with reason %d", callId, rejectReason);
2013 findConnectionForAction(callId, "reject").onReject(rejectReason);
2014 }
2015
Bryce Leecac50772015-11-17 15:13:29 -08002016 private void silence(String callId) {
2017 Log.d(this, "silence %s", callId);
2018 findConnectionForAction(callId, "silence").onSilence();
2019 }
2020
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002021 private void disconnect(String callId) {
Ihab Awad60ac30b2014-05-20 22:32:12 -07002022 Log.d(this, "disconnect %s", callId);
Santos Cordon0159ac02014-08-21 14:28:11 -07002023 if (mConnectionById.containsKey(callId)) {
2024 findConnectionForAction(callId, "disconnect").onDisconnect();
2025 } else {
2026 findConferenceForAction(callId, "disconnect").onDisconnect();
2027 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002028 }
2029
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002030 private void hold(String callId) {
Ihab Awad60ac30b2014-05-20 22:32:12 -07002031 Log.d(this, "hold %s", callId);
Santos Cordon0159ac02014-08-21 14:28:11 -07002032 if (mConnectionById.containsKey(callId)) {
2033 findConnectionForAction(callId, "hold").onHold();
2034 } else {
2035 findConferenceForAction(callId, "hold").onHold();
2036 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002037 }
2038
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002039 private void unhold(String callId) {
Ihab Awad60ac30b2014-05-20 22:32:12 -07002040 Log.d(this, "unhold %s", callId);
Santos Cordon0159ac02014-08-21 14:28:11 -07002041 if (mConnectionById.containsKey(callId)) {
2042 findConnectionForAction(callId, "unhold").onUnhold();
2043 } else {
2044 findConferenceForAction(callId, "unhold").onUnhold();
2045 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002046 }
2047
Yorke Lee4af59352015-05-13 14:14:54 -07002048 private void onCallAudioStateChanged(String callId, CallAudioState callAudioState) {
2049 Log.d(this, "onAudioStateChanged %s %s", callId, callAudioState);
Yorke Leea0d3ca92014-09-15 19:18:13 -07002050 if (mConnectionById.containsKey(callId)) {
Yorke Lee4af59352015-05-13 14:14:54 -07002051 findConnectionForAction(callId, "onCallAudioStateChanged").setCallAudioState(
2052 callAudioState);
Yorke Leea0d3ca92014-09-15 19:18:13 -07002053 } else {
Yorke Lee4af59352015-05-13 14:14:54 -07002054 findConferenceForAction(callId, "onCallAudioStateChanged").setCallAudioState(
2055 callAudioState);
Yorke Leea0d3ca92014-09-15 19:18:13 -07002056 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002057 }
2058
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002059 private void playDtmfTone(String callId, char digit) {
2060 Log.d(this, "playDtmfTone %s %c", callId, digit);
Yorke Leea0d3ca92014-09-15 19:18:13 -07002061 if (mConnectionById.containsKey(callId)) {
2062 findConnectionForAction(callId, "playDtmfTone").onPlayDtmfTone(digit);
2063 } else {
2064 findConferenceForAction(callId, "playDtmfTone").onPlayDtmfTone(digit);
2065 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002066 }
2067
2068 private void stopDtmfTone(String callId) {
2069 Log.d(this, "stopDtmfTone %s", callId);
Yorke Leea0d3ca92014-09-15 19:18:13 -07002070 if (mConnectionById.containsKey(callId)) {
2071 findConnectionForAction(callId, "stopDtmfTone").onStopDtmfTone();
2072 } else {
2073 findConferenceForAction(callId, "stopDtmfTone").onStopDtmfTone();
2074 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002075 }
2076
Santos Cordon823fd3c2014-08-07 18:35:18 -07002077 private void conference(String callId1, String callId2) {
2078 Log.d(this, "conference %s, %s", callId1, callId2);
Santos Cordon980acb92014-05-31 10:31:19 -07002079
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002080 // Attempt to get second connection or conference.
Santos Cordon823fd3c2014-08-07 18:35:18 -07002081 Connection connection2 = findConnectionForAction(callId2, "conference");
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002082 Conference conference2 = getNullConference();
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07002083 if (connection2 == getNullConnection()) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002084 conference2 = findConferenceForAction(callId2, "conference");
2085 if (conference2 == getNullConference()) {
2086 Log.w(this, "Connection2 or Conference2 missing in conference request %s.",
2087 callId2);
2088 return;
2089 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07002090 }
Santos Cordonb6939982014-06-04 20:20:58 -07002091
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002092 // Attempt to get first connection or conference and perform merge.
Ihab Awad50e35062014-09-30 09:17:03 -07002093 Connection connection1 = findConnectionForAction(callId1, "conference");
2094 if (connection1 == getNullConnection()) {
2095 Conference conference1 = findConferenceForAction(callId1, "addConnection");
2096 if (conference1 == getNullConference()) {
2097 Log.w(this,
2098 "Connection1 or Conference1 missing in conference request %s.",
2099 callId1);
2100 } else {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002101 // Call 1 is a conference.
2102 if (connection2 != getNullConnection()) {
2103 // Call 2 is a connection so merge via call 1 (conference).
2104 conference1.onMerge(connection2);
2105 } else {
2106 // Call 2 is ALSO a conference; this should never happen.
2107 Log.wtf(this, "There can only be one conference and an attempt was made to " +
2108 "merge two conferences.");
2109 return;
2110 }
Ihab Awad50e35062014-09-30 09:17:03 -07002111 }
2112 } else {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002113 // Call 1 is a connection.
2114 if (conference2 != getNullConference()) {
2115 // Call 2 is a conference, so merge via call 2.
2116 conference2.onMerge(connection1);
2117 } else {
2118 // Call 2 is a connection, so merge together.
2119 onConference(connection1, connection2);
2120 }
Ihab Awad50e35062014-09-30 09:17:03 -07002121 }
Santos Cordon980acb92014-05-31 10:31:19 -07002122 }
2123
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002124 private void splitFromConference(String callId) {
Santos Cordonb6939982014-06-04 20:20:58 -07002125 Log.d(this, "splitFromConference(%s)", callId);
Santos Cordon980acb92014-05-31 10:31:19 -07002126
2127 Connection connection = findConnectionForAction(callId, "splitFromConference");
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07002128 if (connection == getNullConnection()) {
Santos Cordon980acb92014-05-31 10:31:19 -07002129 Log.w(this, "Connection missing in conference request %s.", callId);
2130 return;
2131 }
2132
Santos Cordon0159ac02014-08-21 14:28:11 -07002133 Conference conference = connection.getConference();
2134 if (conference != null) {
2135 conference.onSeparate(connection);
2136 }
Santos Cordon980acb92014-05-31 10:31:19 -07002137 }
2138
Santos Cordona4868042014-09-04 17:39:22 -07002139 private void mergeConference(String callId) {
2140 Log.d(this, "mergeConference(%s)", callId);
2141 Conference conference = findConferenceForAction(callId, "mergeConference");
2142 if (conference != null) {
2143 conference.onMerge();
2144 }
2145 }
2146
2147 private void swapConference(String callId) {
2148 Log.d(this, "swapConference(%s)", callId);
2149 Conference conference = findConferenceForAction(callId, "swapConference");
2150 if (conference != null) {
2151 conference.onSwap();
2152 }
2153 }
2154
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002155 /**
2156 * Notifies a {@link Connection} of a request to pull an external call.
2157 *
2158 * See {@link Call#pullExternalCall()}.
2159 *
2160 * @param callId The ID of the call to pull.
2161 */
2162 private void pullExternalCall(String callId) {
2163 Log.d(this, "pullExternalCall(%s)", callId);
2164 Connection connection = findConnectionForAction(callId, "pullExternalCall");
2165 if (connection != null) {
2166 connection.onPullExternalCall();
2167 }
2168 }
2169
2170 /**
2171 * Notifies a {@link Connection} of a call event.
2172 *
2173 * See {@link Call#sendCallEvent(String, Bundle)}.
2174 *
2175 * @param callId The ID of the call receiving the event.
2176 * @param event The event.
2177 * @param extras Extras associated with the event.
2178 */
2179 private void sendCallEvent(String callId, String event, Bundle extras) {
2180 Log.d(this, "sendCallEvent(%s, %s)", callId, event);
2181 Connection connection = findConnectionForAction(callId, "sendCallEvent");
2182 if (connection != null) {
2183 connection.onCallEvent(event, extras);
2184 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002185 }
2186
Tyler Gunndee56a82016-03-23 16:06:34 -07002187 /**
Tyler Gunn79bc1ec2018-01-22 15:17:54 -08002188 * Notifies a {@link Connection} that a handover has completed.
2189 *
2190 * @param callId The ID of the call which completed handover.
2191 */
2192 private void notifyHandoverComplete(String callId) {
2193 Log.d(this, "notifyHandoverComplete(%s)", callId);
2194 Connection connection = findConnectionForAction(callId, "notifyHandoverComplete");
2195 if (connection != null) {
2196 connection.onHandoverComplete();
2197 }
2198 }
2199
2200 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07002201 * Notifies a {@link Connection} or {@link Conference} of a change to the extras from Telecom.
2202 * <p>
2203 * These extra changes can originate from Telecom itself, or from an {@link InCallService} via
2204 * the {@link android.telecom.Call#putExtra(String, boolean)},
2205 * {@link android.telecom.Call#putExtra(String, int)},
2206 * {@link android.telecom.Call#putExtra(String, String)},
2207 * {@link Call#removeExtras(List)}.
2208 *
2209 * @param callId The ID of the call receiving the event.
2210 * @param extras The new extras bundle.
2211 */
2212 private void handleExtrasChanged(String callId, Bundle extras) {
2213 Log.d(this, "handleExtrasChanged(%s, %s)", callId, extras);
2214 if (mConnectionById.containsKey(callId)) {
2215 findConnectionForAction(callId, "handleExtrasChanged").handleExtrasChanged(extras);
2216 } else if (mConferenceById.containsKey(callId)) {
2217 findConferenceForAction(callId, "handleExtrasChanged").handleExtrasChanged(extras);
2218 }
2219 }
2220
Hall Liub64ac4c2017-02-06 10:49:48 -08002221 private void startRtt(String callId, Connection.RttTextStream rttTextStream) {
2222 Log.d(this, "startRtt(%s)", callId);
2223 if (mConnectionById.containsKey(callId)) {
2224 findConnectionForAction(callId, "startRtt").onStartRtt(rttTextStream);
2225 } else if (mConferenceById.containsKey(callId)) {
2226 Log.w(this, "startRtt called on a conference.");
2227 }
2228 }
2229
2230 private void stopRtt(String callId) {
2231 Log.d(this, "stopRtt(%s)", callId);
2232 if (mConnectionById.containsKey(callId)) {
2233 findConnectionForAction(callId, "stopRtt").onStopRtt();
2234 } else if (mConferenceById.containsKey(callId)) {
2235 Log.w(this, "stopRtt called on a conference.");
2236 }
2237 }
2238
2239 private void handleRttUpgradeResponse(String callId, Connection.RttTextStream rttTextStream) {
2240 Log.d(this, "handleRttUpgradeResponse(%s, %s)", callId, rttTextStream == null);
2241 if (mConnectionById.containsKey(callId)) {
2242 findConnectionForAction(callId, "handleRttUpgradeResponse")
2243 .handleRttUpgradeResponse(rttTextStream);
2244 } else if (mConferenceById.containsKey(callId)) {
2245 Log.w(this, "handleRttUpgradeResponse called on a conference.");
2246 }
2247 }
2248
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002249 private void onPostDialContinue(String callId, boolean proceed) {
Evan Charlton6dea4ac2014-06-03 14:07:13 -07002250 Log.d(this, "onPostDialContinue(%s)", callId);
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002251 findConnectionForAction(callId, "stopDtmfTone").onPostDialContinue(proceed);
Evan Charlton6dea4ac2014-06-03 14:07:13 -07002252 }
2253
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002254 private void onAdapterAttached() {
Ihab Awad9c3f1882014-06-30 21:17:13 -07002255 if (mAreAccountsInitialized) {
Santos Cordon52d8a152014-06-17 19:08:45 -07002256 // No need to query again if we already did it.
2257 return;
2258 }
2259
Tyler Gunn4c69fb32019-05-17 10:49:16 -07002260 String callingPackage = getOpPackageName();
2261
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002262 mAdapter.queryRemoteConnectionServices(new RemoteServiceCallback.Stub() {
Santos Cordon52d8a152014-06-17 19:08:45 -07002263 @Override
2264 public void onResult(
2265 final List<ComponentName> componentNames,
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002266 final List<IBinder> services) {
Brad Ebinger0c3541b2016-11-01 14:11:38 -07002267 mHandler.post(new android.telecom.Logging.Runnable("oAA.qRCS.oR", null /*lock*/) {
Ihab Awad6107bab2014-08-18 09:23:25 -07002268 @Override
Brad Ebinger0c3541b2016-11-01 14:11:38 -07002269 public void loggedRun() {
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002270 for (int i = 0; i < componentNames.size() && i < services.size(); i++) {
Santos Cordon52d8a152014-06-17 19:08:45 -07002271 mRemoteConnectionManager.addConnectionService(
2272 componentNames.get(i),
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002273 IConnectionService.Stub.asInterface(services.get(i)));
Santos Cordon52d8a152014-06-17 19:08:45 -07002274 }
Ihab Awad5d0410f2014-07-30 10:07:40 -07002275 onAccountsInitialized();
Sailesh Nepalc5b01572014-07-14 16:29:44 -07002276 Log.d(this, "remote connection services found: " + services);
Santos Cordon52d8a152014-06-17 19:08:45 -07002277 }
Brad Ebinger0c3541b2016-11-01 14:11:38 -07002278 }.prepare());
Santos Cordon52d8a152014-06-17 19:08:45 -07002279 }
2280
2281 @Override
2282 public void onError() {
Brad Ebinger0c3541b2016-11-01 14:11:38 -07002283 mHandler.post(new android.telecom.Logging.Runnable("oAA.qRCS.oE", null /*lock*/) {
Ihab Awad6107bab2014-08-18 09:23:25 -07002284 @Override
Brad Ebinger0c3541b2016-11-01 14:11:38 -07002285 public void loggedRun() {
Ihab Awad9c3f1882014-06-30 21:17:13 -07002286 mAreAccountsInitialized = true;
Santos Cordon52d8a152014-06-17 19:08:45 -07002287 }
Brad Ebinger0c3541b2016-11-01 14:11:38 -07002288 }.prepare());
Santos Cordon52d8a152014-06-17 19:08:45 -07002289 }
Tyler Gunn4c69fb32019-05-17 10:49:16 -07002290 }, callingPackage);
Santos Cordon52d8a152014-06-17 19:08:45 -07002291 }
2292
Ihab Awadf8b69882014-07-25 15:14:01 -07002293 /**
2294 * Ask some other {@code ConnectionService} to create a {@code RemoteConnection} given an
Santos Cordona663f862014-10-29 13:49:58 -07002295 * incoming request. This is used by {@code ConnectionService}s that are registered with
2296 * {@link PhoneAccount#CAPABILITY_CONNECTION_MANAGER} and want to be able to manage
2297 * SIM-based incoming calls.
Ihab Awadf8b69882014-07-25 15:14:01 -07002298 *
2299 * @param connectionManagerPhoneAccount See description at
2300 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
2301 * @param request Details about the incoming call.
2302 * @return The {@code Connection} object to satisfy this call, or {@code null} to
2303 * not handle the call.
2304 */
2305 public final RemoteConnection createRemoteIncomingConnection(
2306 PhoneAccountHandle connectionManagerPhoneAccount,
2307 ConnectionRequest request) {
2308 return mRemoteConnectionManager.createRemoteConnection(
2309 connectionManagerPhoneAccount, request, true);
Santos Cordon52d8a152014-06-17 19:08:45 -07002310 }
2311
2312 /**
Ihab Awadf8b69882014-07-25 15:14:01 -07002313 * Ask some other {@code ConnectionService} to create a {@code RemoteConnection} given an
Santos Cordona663f862014-10-29 13:49:58 -07002314 * outgoing request. This is used by {@code ConnectionService}s that are registered with
2315 * {@link PhoneAccount#CAPABILITY_CONNECTION_MANAGER} and want to be able to use the
2316 * SIM-based {@code ConnectionService} to place its outgoing calls.
Ihab Awadf8b69882014-07-25 15:14:01 -07002317 *
2318 * @param connectionManagerPhoneAccount See description at
2319 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
Cuihtlauac ALVARADO0b3b2a52016-09-13 14:49:41 +02002320 * @param request Details about the outgoing call.
Ihab Awadf8b69882014-07-25 15:14:01 -07002321 * @return The {@code Connection} object to satisfy this call, or {@code null} to
2322 * not handle the call.
2323 */
2324 public final RemoteConnection createRemoteOutgoingConnection(
2325 PhoneAccountHandle connectionManagerPhoneAccount,
2326 ConnectionRequest request) {
2327 return mRemoteConnectionManager.createRemoteConnection(
2328 connectionManagerPhoneAccount, request, false);
2329 }
2330
2331 /**
Santos Cordona663f862014-10-29 13:49:58 -07002332 * Indicates to the relevant {@code RemoteConnectionService} that the specified
2333 * {@link RemoteConnection}s should be merged into a conference call.
2334 * <p>
2335 * If the conference request is successful, the method {@link #onRemoteConferenceAdded} will
2336 * be invoked.
2337 *
2338 * @param remoteConnection1 The first of the remote connections to conference.
2339 * @param remoteConnection2 The second of the remote connections to conference.
Ihab Awadb8e85c72014-08-23 20:34:57 -07002340 */
2341 public final void conferenceRemoteConnections(
Santos Cordona663f862014-10-29 13:49:58 -07002342 RemoteConnection remoteConnection1,
2343 RemoteConnection remoteConnection2) {
2344 mRemoteConnectionManager.conferenceRemoteConnections(remoteConnection1, remoteConnection2);
Ihab Awadb8e85c72014-08-23 20:34:57 -07002345 }
2346
2347 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07002348 * Adds a new conference call. When a conference call is created either as a result of an
2349 * explicit request via {@link #onConference} or otherwise, the connection service should supply
2350 * an instance of {@link Conference} by invoking this method. A conference call provided by this
2351 * method will persist until {@link Conference#destroy} is invoked on the conference instance.
2352 *
2353 * @param conference The new conference object.
2354 */
2355 public final void addConference(Conference conference) {
Rekha Kumar07366812015-03-24 16:42:31 -07002356 Log.d(this, "addConference: conference=%s", conference);
2357
Santos Cordon823fd3c2014-08-07 18:35:18 -07002358 String id = addConferenceInternal(conference);
2359 if (id != null) {
2360 List<String> connectionIds = new ArrayList<>(2);
2361 for (Connection connection : conference.getConnections()) {
2362 if (mIdByConnection.containsKey(connection)) {
2363 connectionIds.add(mIdByConnection.get(connection));
2364 }
2365 }
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002366 conference.setTelecomCallId(id);
Santos Cordon823fd3c2014-08-07 18:35:18 -07002367 ParcelableConference parcelableConference = new ParcelableConference(
Nancy Chenea38cca2014-09-05 16:38:49 -07002368 conference.getPhoneAccountHandle(),
Santos Cordon823fd3c2014-08-07 18:35:18 -07002369 conference.getState(),
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002370 conference.getConnectionCapabilities(),
Tyler Gunn720c6642016-03-22 09:02:47 -07002371 conference.getConnectionProperties(),
Tyler Gunncd5d33c2015-01-12 09:02:01 -08002372 connectionIds,
Rekha Kumar07366812015-03-24 16:42:31 -07002373 conference.getVideoProvider() == null ?
2374 null : conference.getVideoProvider().getInterface(),
2375 conference.getVideoState(),
Andrew Lee3e3e2f22015-04-16 13:48:43 -07002376 conference.getConnectTimeMillis(),
Tyler Gunn17541392018-02-01 08:58:38 -08002377 conference.getConnectionStartElapsedRealTime(),
Santos Cordon6b7f9552015-05-27 17:21:45 -07002378 conference.getStatusHints(),
Tyler Gunnac60f952019-05-31 07:23:16 -07002379 conference.getExtras(),
2380 conference.getAddress(),
2381 conference.getAddressPresentation(),
2382 conference.getCallerDisplayName(),
2383 conference.getCallerDisplayNamePresentation());
Andrew Lee0f51da32015-04-16 13:11:55 -07002384
Santos Cordon823fd3c2014-08-07 18:35:18 -07002385 mAdapter.addConferenceCall(id, parcelableConference);
Rekha Kumar07366812015-03-24 16:42:31 -07002386 mAdapter.setVideoProvider(id, conference.getVideoProvider());
2387 mAdapter.setVideoState(id, conference.getVideoState());
Santos Cordon823fd3c2014-08-07 18:35:18 -07002388
2389 // Go through any child calls and set the parent.
2390 for (Connection connection : conference.getConnections()) {
2391 String connectionId = mIdByConnection.get(connection);
2392 if (connectionId != null) {
2393 mAdapter.setIsConferenced(connectionId, id);
2394 }
2395 }
Pengquan Meng70c9885332017-10-02 18:09:03 -07002396 onConferenceAdded(conference);
Santos Cordon823fd3c2014-08-07 18:35:18 -07002397 }
2398 }
2399
2400 /**
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002401 * Adds a connection created by the {@link ConnectionService} and informs telecom of the new
2402 * connection.
2403 *
2404 * @param phoneAccountHandle The phone account handle for the connection.
2405 * @param connection The connection to add.
2406 */
2407 public final void addExistingConnection(PhoneAccountHandle phoneAccountHandle,
2408 Connection connection) {
Tyler Gunn78da7812017-05-09 14:34:57 -07002409 addExistingConnection(phoneAccountHandle, connection, null /* conference */);
2410 }
2411
2412 /**
Pengquan Meng731c1a32017-11-21 18:01:13 -08002413 * Call to inform Telecom that your {@link ConnectionService} has released call resources (e.g
2414 * microphone, camera).
2415 *
Pengquan Menge3bf7e22018-02-22 17:30:04 -08002416 * <p>
2417 * The {@link ConnectionService} will be disconnected when it failed to call this method within
2418 * 5 seconds after {@link #onConnectionServiceFocusLost()} is called.
2419 *
Pengquan Meng731c1a32017-11-21 18:01:13 -08002420 * @see ConnectionService#onConnectionServiceFocusLost()
2421 */
2422 public final void connectionServiceFocusReleased() {
2423 mAdapter.onConnectionServiceFocusReleased();
2424 }
2425
2426 /**
Tyler Gunn78da7812017-05-09 14:34:57 -07002427 * Adds a connection created by the {@link ConnectionService} and informs telecom of the new
Tyler Gunn5567d742019-10-31 13:04:37 -07002428 * connection, as well as adding that connection to the specified conference.
2429 * <p>
2430 * Note: This API is intended ONLY for use by the Telephony stack to provide an easy way to add
2431 * IMS conference participants to be added to a conference in a single step; this helps ensure
2432 * UI updates happen atomically, rather than adding the connection and then adding it to
2433 * the conference in another step.
Tyler Gunn78da7812017-05-09 14:34:57 -07002434 *
2435 * @param phoneAccountHandle The phone account handle for the connection.
2436 * @param connection The connection to add.
2437 * @param conference The parent conference of the new connection.
2438 * @hide
2439 */
Tyler Gunn5567d742019-10-31 13:04:37 -07002440 @SystemApi
2441 public final void addExistingConnection(@NonNull PhoneAccountHandle phoneAccountHandle,
2442 @NonNull Connection connection, @NonNull Conference conference) {
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002443
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002444 String id = addExistingConnectionInternal(phoneAccountHandle, connection);
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002445 if (id != null) {
2446 List<String> emptyList = new ArrayList<>(0);
Tyler Gunn78da7812017-05-09 14:34:57 -07002447 String conferenceId = null;
2448 if (conference != null) {
2449 conferenceId = mIdByConference.get(conference);
2450 }
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002451
2452 ParcelableConnection parcelableConnection = new ParcelableConnection(
2453 phoneAccountHandle,
2454 connection.getState(),
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002455 connection.getConnectionCapabilities(),
Tyler Gunn720c6642016-03-22 09:02:47 -07002456 connection.getConnectionProperties(),
Christine Hallstrom2830ce92016-11-30 16:06:42 -08002457 connection.getSupportedAudioRoutes(),
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002458 connection.getAddress(),
2459 connection.getAddressPresentation(),
2460 connection.getCallerDisplayName(),
2461 connection.getCallerDisplayNamePresentation(),
2462 connection.getVideoProvider() == null ?
2463 null : connection.getVideoProvider().getInterface(),
2464 connection.getVideoState(),
2465 connection.isRingbackRequested(),
2466 connection.getAudioModeIsVoip(),
Roshan Piuse927ec02015-07-15 15:47:21 -07002467 connection.getConnectTimeMillis(),
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002468 connection.getConnectElapsedTimeMillis(),
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002469 connection.getStatusHints(),
2470 connection.getDisconnectCause(),
Santos Cordon6b7f9552015-05-27 17:21:45 -07002471 emptyList,
Tyler Gunn78da7812017-05-09 14:34:57 -07002472 connection.getExtras(),
Tyler Gunn6986a632019-06-25 13:45:32 -07002473 conferenceId,
Tyler Gunnd57d76c2019-09-24 14:53:23 -07002474 connection.getCallDirection(),
2475 Connection.VERIFICATION_STATUS_NOT_VERIFIED);
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002476 mAdapter.addExistingConnection(id, parcelableConnection);
2477 }
2478 }
2479
2480 /**
Ihab Awadf8b69882014-07-25 15:14:01 -07002481 * Returns all the active {@code Connection}s for which this {@code ConnectionService}
2482 * has taken responsibility.
2483 *
2484 * @return A collection of {@code Connection}s created by this {@code ConnectionService}.
Santos Cordonb6939982014-06-04 20:20:58 -07002485 */
Sailesh Nepal091768c2014-06-30 15:15:23 -07002486 public final Collection<Connection> getAllConnections() {
Santos Cordonb6939982014-06-04 20:20:58 -07002487 return mConnectionById.values();
2488 }
2489
2490 /**
Santos Cordona6018b92016-02-16 14:23:12 -08002491 * Returns all the active {@code Conference}s for which this {@code ConnectionService}
2492 * has taken responsibility.
2493 *
2494 * @return A collection of {@code Conference}s created by this {@code ConnectionService}.
2495 */
2496 public final Collection<Conference> getAllConferences() {
2497 return mConferenceById.values();
2498 }
2499
2500 /**
Ihab Awadf8b69882014-07-25 15:14:01 -07002501 * Create a {@code Connection} given an incoming request. This is used to attach to existing
2502 * incoming calls.
Evan Charltonbf11f982014-07-20 22:06:28 -07002503 *
Ihab Awadf8b69882014-07-25 15:14:01 -07002504 * @param connectionManagerPhoneAccount See description at
2505 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
2506 * @param request Details about the incoming call.
2507 * @return The {@code Connection} object to satisfy this call, or {@code null} to
2508 * not handle the call.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002509 */
Ihab Awadf8b69882014-07-25 15:14:01 -07002510 public Connection onCreateIncomingConnection(
2511 PhoneAccountHandle connectionManagerPhoneAccount,
2512 ConnectionRequest request) {
2513 return null;
2514 }
Ravi Paluri80aa2142019-12-02 11:57:37 +05302515 /**
2516 * Create a {@code Connection} given an incoming request. This is used to attach to existing
2517 * incoming conference call.
2518 *
2519 * @param connectionManagerPhoneAccount See description at
2520 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
2521 * @param request Details about the incoming call.
2522 * @return The {@code Connection} object to satisfy this call, or {@code null} to
2523 * not handle the call.
2524 */
2525 public @Nullable Conference onCreateIncomingConference(
2526 @Nullable PhoneAccountHandle connectionManagerPhoneAccount,
2527 @Nullable ConnectionRequest request) {
2528 return null;
2529 }
Sailesh Nepalc5b01572014-07-14 16:29:44 -07002530
2531 /**
Tyler Gunn041a1fe2017-05-12 10:04:49 -07002532 * Called after the {@link Connection} returned by
2533 * {@link #onCreateIncomingConnection(PhoneAccountHandle, ConnectionRequest)}
2534 * or {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)} has been
2535 * added to the {@link ConnectionService} and sent to Telecom.
2536 *
2537 * @param connection the {@link Connection}.
2538 * @hide
2539 */
2540 public void onCreateConnectionComplete(Connection connection) {
2541 }
2542
2543 /**
Ravi Paluri80aa2142019-12-02 11:57:37 +05302544 * Called after the {@link Conference} returned by
2545 * {@link #onCreateIncomingConference(PhoneAccountHandle, ConnectionRequest)}
2546 * or {@link #onCreateOutgoingConference(PhoneAccountHandle, ConnectionRequest)} has been
2547 * added to the {@link ConnectionService} and sent to Telecom.
2548 *
2549 * @param conference the {@link Conference}.
2550 * @hide
2551 */
2552 public void onCreateConferenceComplete(Conference conference) {
2553 }
2554
2555
2556 /**
Tyler Gunnf5035432017-01-09 09:43:12 -08002557 * Called by Telecom to inform the {@link ConnectionService} that its request to create a new
2558 * incoming {@link Connection} was denied.
2559 * <p>
2560 * Used when a self-managed {@link ConnectionService} attempts to create a new incoming
2561 * {@link Connection}, but Telecom has determined that the call cannot be allowed at this time.
2562 * The {@link ConnectionService} is responsible for silently rejecting the new incoming
2563 * {@link Connection}.
2564 * <p>
2565 * See {@link TelecomManager#isIncomingCallPermitted(PhoneAccountHandle)} for more information.
2566 *
Tyler Gunn159f35c2017-03-02 09:28:37 -08002567 * @param connectionManagerPhoneAccount See description at
2568 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
Tyler Gunnf5035432017-01-09 09:43:12 -08002569 * @param request The incoming connection request.
2570 */
Tyler Gunn159f35c2017-03-02 09:28:37 -08002571 public void onCreateIncomingConnectionFailed(PhoneAccountHandle connectionManagerPhoneAccount,
2572 ConnectionRequest request) {
Tyler Gunnf5035432017-01-09 09:43:12 -08002573 }
2574
2575 /**
2576 * Called by Telecom to inform the {@link ConnectionService} that its request to create a new
2577 * outgoing {@link Connection} was denied.
2578 * <p>
2579 * Used when a self-managed {@link ConnectionService} attempts to create a new outgoing
2580 * {@link Connection}, but Telecom has determined that the call cannot be placed at this time.
2581 * The {@link ConnectionService} is responisible for informing the user that the
2582 * {@link Connection} cannot be made at this time.
2583 * <p>
2584 * See {@link TelecomManager#isOutgoingCallPermitted(PhoneAccountHandle)} for more information.
2585 *
Tyler Gunn159f35c2017-03-02 09:28:37 -08002586 * @param connectionManagerPhoneAccount See description at
2587 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
Tyler Gunnf5035432017-01-09 09:43:12 -08002588 * @param request The outgoing connection request.
2589 */
Tyler Gunn159f35c2017-03-02 09:28:37 -08002590 public void onCreateOutgoingConnectionFailed(PhoneAccountHandle connectionManagerPhoneAccount,
2591 ConnectionRequest request) {
Tyler Gunnf5035432017-01-09 09:43:12 -08002592 }
2593
2594 /**
Ravi Paluri80aa2142019-12-02 11:57:37 +05302595 * Called by Telecom to inform the {@link ConnectionService} that its request to create a new
2596 * incoming {@link Conference} was denied.
2597 * <p>
2598 * Used when a self-managed {@link ConnectionService} attempts to create a new incoming
2599 * {@link Conference}, but Telecom has determined that the call cannot be allowed at this time.
2600 * The {@link ConnectionService} is responsible for silently rejecting the new incoming
2601 * {@link Conference}.
2602 * <p>
2603 * See {@link TelecomManager#isIncomingCallPermitted(PhoneAccountHandle)} for more information.
2604 *
2605 * @param connectionManagerPhoneAccount See description at
2606 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
2607 * @param request The incoming connection request.
2608 */
2609 public void onCreateIncomingConferenceFailed(
2610 @Nullable PhoneAccountHandle connectionManagerPhoneAccount,
2611 @Nullable ConnectionRequest request) {
2612 }
2613
2614 /**
2615 * Called by Telecom to inform the {@link ConnectionService} that its request to create a new
2616 * outgoing {@link Conference} was denied.
2617 * <p>
2618 * Used when a self-managed {@link ConnectionService} attempts to create a new outgoing
2619 * {@link Conference}, but Telecom has determined that the call cannot be placed at this time.
2620 * The {@link ConnectionService} is responisible for informing the user that the
2621 * {@link Conference} cannot be made at this time.
2622 * <p>
2623 * See {@link TelecomManager#isOutgoingCallPermitted(PhoneAccountHandle)} for more information.
2624 *
2625 * @param connectionManagerPhoneAccount See description at
2626 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
2627 * @param request The outgoing connection request.
2628 */
2629 public void onCreateOutgoingConferenceFailed(
2630 @Nullable PhoneAccountHandle connectionManagerPhoneAccount,
2631 @Nullable ConnectionRequest request) {
2632 }
2633
2634
2635 /**
Shriram Ganesh6bf35ac2014-12-11 17:53:38 -08002636 * Trigger recalculate functinality for conference calls. This is used when a Telephony
2637 * Connection is part of a conference controller but is not yet added to Connection
2638 * Service and hence cannot be added to the conference call.
2639 *
2640 * @hide
2641 */
2642 public void triggerConferenceRecalculate() {
2643 }
2644
2645 /**
Ihab Awadf8b69882014-07-25 15:14:01 -07002646 * Create a {@code Connection} given an outgoing request. This is used to initiate new
2647 * outgoing calls.
Sailesh Nepalc5b01572014-07-14 16:29:44 -07002648 *
Ihab Awadf8b69882014-07-25 15:14:01 -07002649 * @param connectionManagerPhoneAccount The connection manager account to use for managing
2650 * this call.
2651 * <p>
2652 * If this parameter is not {@code null}, it means that this {@code ConnectionService}
2653 * has registered one or more {@code PhoneAccount}s having
2654 * {@link PhoneAccount#CAPABILITY_CONNECTION_MANAGER}. This parameter will contain
2655 * one of these {@code PhoneAccount}s, while the {@code request} will contain another
2656 * (usually but not always distinct) {@code PhoneAccount} to be used for actually
2657 * making the connection.
2658 * <p>
2659 * If this parameter is {@code null}, it means that this {@code ConnectionService} is
2660 * being asked to make a direct connection. The
2661 * {@link ConnectionRequest#getAccountHandle()} of parameter {@code request} will be
2662 * a {@code PhoneAccount} registered by this {@code ConnectionService} to use for
2663 * making the connection.
2664 * @param request Details about the outgoing call.
2665 * @return The {@code Connection} object to satisfy this call, or the result of an invocation
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002666 * of {@link Connection#createFailedConnection(DisconnectCause)} to not handle the call.
Sailesh Nepalc5b01572014-07-14 16:29:44 -07002667 */
Ihab Awadf8b69882014-07-25 15:14:01 -07002668 public Connection onCreateOutgoingConnection(
2669 PhoneAccountHandle connectionManagerPhoneAccount,
2670 ConnectionRequest request) {
2671 return null;
2672 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002673
2674 /**
Ravi Paluri80aa2142019-12-02 11:57:37 +05302675 * Create a {@code Conference} given an outgoing request. This is used to initiate new
2676 * outgoing conference call.
2677 *
2678 * @param connectionManagerPhoneAccount The connection manager account to use for managing
2679 * this call.
2680 * <p>
2681 * If this parameter is not {@code null}, it means that this {@code ConnectionService}
2682 * has registered one or more {@code PhoneAccount}s having
2683 * {@link PhoneAccount#CAPABILITY_CONNECTION_MANAGER}. This parameter will contain
2684 * one of these {@code PhoneAccount}s, while the {@code request} will contain another
2685 * (usually but not always distinct) {@code PhoneAccount} to be used for actually
2686 * making the connection.
2687 * <p>
2688 * If this parameter is {@code null}, it means that this {@code ConnectionService} is
2689 * being asked to make a direct connection. The
2690 * {@link ConnectionRequest#getAccountHandle()} of parameter {@code request} will be
2691 * a {@code PhoneAccount} registered by this {@code ConnectionService} to use for
2692 * making the connection.
2693 * @param request Details about the outgoing call.
2694 * @return The {@code Conference} object to satisfy this call, or the result of an invocation
2695 * of {@link Connection#createFailedConnection(DisconnectCause)} to not handle the call.
2696 */
2697 public @Nullable Conference onCreateOutgoingConference(
2698 @Nullable PhoneAccountHandle connectionManagerPhoneAccount,
2699 @Nullable ConnectionRequest request) {
2700 return null;
2701 }
2702
2703
2704 /**
Tyler Gunn9d127732018-03-02 15:45:51 -08002705 * Called by Telecom to request that a {@link ConnectionService} creates an instance of an
2706 * outgoing handover {@link Connection}.
2707 * <p>
2708 * A call handover is the process where an ongoing call is transferred from one app (i.e.
2709 * {@link ConnectionService} to another app. The user could, for example, choose to continue a
2710 * mobile network call in a video calling app. The mobile network call via the Telephony stack
2711 * is referred to as the source of the handover, and the video calling app is referred to as the
2712 * destination.
2713 * <p>
2714 * When considering a handover scenario the <em>initiating</em> device is where a user initiated
2715 * the handover process (e.g. by calling {@link android.telecom.Call#handoverTo(
2716 * PhoneAccountHandle, int, Bundle)}, and the other device is considered the <em>receiving</em>
2717 * device.
2718 * <p>
2719 * This method is called on the destination {@link ConnectionService} on <em>initiating</em>
2720 * device when the user initiates a handover request from one app to another. The user request
2721 * originates in the {@link InCallService} via
2722 * {@link android.telecom.Call#handoverTo(PhoneAccountHandle, int, Bundle)}.
2723 * <p>
2724 * For a full discussion of the handover process and the APIs involved, see
2725 * {@link android.telecom.Call#handoverTo(PhoneAccountHandle, int, Bundle)}.
2726 * <p>
2727 * Implementations of this method should return an instance of {@link Connection} which
2728 * represents the handover. If your app does not wish to accept a handover to it at this time,
2729 * you can return {@code null}. The code below shows an example of how this is done.
2730 * <pre>
2731 * {@code
2732 * public Connection onCreateIncomingHandoverConnection(PhoneAccountHandle
2733 * fromPhoneAccountHandle, ConnectionRequest request) {
2734 * if (!isHandoverAvailable()) {
2735 * return null;
2736 * }
2737 * MyConnection connection = new MyConnection();
2738 * connection.setAddress(request.getAddress(), TelecomManager.PRESENTATION_ALLOWED);
2739 * connection.setVideoState(request.getVideoState());
2740 * return connection;
2741 * }
2742 * }
2743 * </pre>
2744 *
Sanket Padawea8eddd42017-11-03 11:07:35 -07002745 * @param fromPhoneAccountHandle {@link PhoneAccountHandle} associated with the
2746 * ConnectionService which needs to handover the call.
Tyler Gunn9d127732018-03-02 15:45:51 -08002747 * @param request Details about the call to handover.
2748 * @return {@link Connection} instance corresponding to the handover call.
Sanket Padawea8eddd42017-11-03 11:07:35 -07002749 */
2750 public Connection onCreateOutgoingHandoverConnection(PhoneAccountHandle fromPhoneAccountHandle,
2751 ConnectionRequest request) {
2752 return null;
2753 }
2754
2755 /**
Tyler Gunn9d127732018-03-02 15:45:51 -08002756 * Called by Telecom to request that a {@link ConnectionService} creates an instance of an
2757 * incoming handover {@link Connection}.
2758 * <p>
2759 * A call handover is the process where an ongoing call is transferred from one app (i.e.
2760 * {@link ConnectionService} to another app. The user could, for example, choose to continue a
2761 * mobile network call in a video calling app. The mobile network call via the Telephony stack
2762 * is referred to as the source of the handover, and the video calling app is referred to as the
2763 * destination.
2764 * <p>
2765 * When considering a handover scenario the <em>initiating</em> device is where a user initiated
2766 * the handover process (e.g. by calling {@link android.telecom.Call#handoverTo(
2767 * PhoneAccountHandle, int, Bundle)}, and the other device is considered the <em>receiving</em>
2768 * device.
2769 * <p>
2770 * This method is called on the destination app on the <em>receiving</em> device when the
2771 * destination app calls {@link TelecomManager#acceptHandover(Uri, int, PhoneAccountHandle)} to
2772 * accept an incoming handover from the <em>initiating</em> device.
2773 * <p>
2774 * For a full discussion of the handover process and the APIs involved, see
2775 * {@link android.telecom.Call#handoverTo(PhoneAccountHandle, int, Bundle)}.
2776 * <p>
2777 * Implementations of this method should return an instance of {@link Connection} which
2778 * represents the handover. The code below shows an example of how this is done.
2779 * <pre>
2780 * {@code
2781 * public Connection onCreateIncomingHandoverConnection(PhoneAccountHandle
2782 * fromPhoneAccountHandle, ConnectionRequest request) {
2783 * // Given that your app requested to accept the handover, you should not return null here.
2784 * MyConnection connection = new MyConnection();
2785 * connection.setAddress(request.getAddress(), TelecomManager.PRESENTATION_ALLOWED);
2786 * connection.setVideoState(request.getVideoState());
2787 * return connection;
2788 * }
2789 * }
2790 * </pre>
2791 *
Sanket Padawea8eddd42017-11-03 11:07:35 -07002792 * @param fromPhoneAccountHandle {@link PhoneAccountHandle} associated with the
2793 * ConnectionService which needs to handover the call.
2794 * @param request Details about the call which needs to be handover.
Tyler Gunn9d127732018-03-02 15:45:51 -08002795 * @return {@link Connection} instance corresponding to the handover call.
Sanket Padawea8eddd42017-11-03 11:07:35 -07002796 */
2797 public Connection onCreateIncomingHandoverConnection(PhoneAccountHandle fromPhoneAccountHandle,
2798 ConnectionRequest request) {
2799 return null;
2800 }
2801
2802 /**
2803 * Called by Telecom in response to a {@code TelecomManager#acceptHandover()}
2804 * invocation which failed.
Tyler Gunn9d127732018-03-02 15:45:51 -08002805 * <p>
2806 * For a full discussion of the handover process and the APIs involved, see
2807 * {@link android.telecom.Call#handoverTo(PhoneAccountHandle, int, Bundle)}
2808 *
2809 * @param request Details about the call which failed to handover.
2810 * @param error Reason for handover failure. Will be one of the
Sanket Padawea8eddd42017-11-03 11:07:35 -07002811 */
Tyler Gunn9d127732018-03-02 15:45:51 -08002812 public void onHandoverFailed(ConnectionRequest request,
2813 @Call.Callback.HandoverFailureErrors int error) {
Sanket Padawea8eddd42017-11-03 11:07:35 -07002814 return;
2815 }
2816
2817 /**
Yorke Leec3cf9822014-10-02 09:38:39 -07002818 * Create a {@code Connection} for a new unknown call. An unknown call is a call originating
2819 * from the ConnectionService that was neither a user-initiated outgoing call, nor an incoming
2820 * call created using
2821 * {@code TelecomManager#addNewIncomingCall(PhoneAccountHandle, android.os.Bundle)}.
2822 *
Yorke Lee770ed6e2014-10-06 18:58:52 -07002823 * @hide
Yorke Leec3cf9822014-10-02 09:38:39 -07002824 */
2825 public Connection onCreateUnknownConnection(PhoneAccountHandle connectionManagerPhoneAccount,
2826 ConnectionRequest request) {
Brad Ebingerb32d4f82016-10-24 16:40:49 -07002827 return null;
Yorke Leec3cf9822014-10-02 09:38:39 -07002828 }
2829
2830 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07002831 * Conference two specified connections. Invoked when the user has made a request to merge the
2832 * specified connections into a conference call. In response, the connection service should
2833 * create an instance of {@link Conference} and pass it into {@link #addConference}.
Santos Cordonb6939982014-06-04 20:20:58 -07002834 *
Santos Cordon823fd3c2014-08-07 18:35:18 -07002835 * @param connection1 A connection to merge into a conference call.
2836 * @param connection2 A connection to merge into a conference call.
Santos Cordonb6939982014-06-04 20:20:58 -07002837 */
Santos Cordon823fd3c2014-08-07 18:35:18 -07002838 public void onConference(Connection connection1, Connection connection2) {}
Santos Cordonb6939982014-06-04 20:20:58 -07002839
Santos Cordona663f862014-10-29 13:49:58 -07002840 /**
Pengquan Meng70c9885332017-10-02 18:09:03 -07002841 * Called when a connection is added.
2842 * @hide
2843 */
2844 public void onConnectionAdded(Connection connection) {}
2845
2846 /**
2847 * Called when a connection is removed.
2848 * @hide
2849 */
2850 public void onConnectionRemoved(Connection connection) {}
2851
2852 /**
2853 * Called when a conference is added.
2854 * @hide
2855 */
2856 public void onConferenceAdded(Conference conference) {}
2857
2858 /**
2859 * Called when a conference is removed.
2860 * @hide
2861 */
2862 public void onConferenceRemoved(Conference conference) {}
2863
2864 /**
Santos Cordona663f862014-10-29 13:49:58 -07002865 * Indicates that a remote conference has been created for existing {@link RemoteConnection}s.
2866 * When this method is invoked, this {@link ConnectionService} should create its own
2867 * representation of the conference call and send it to telecom using {@link #addConference}.
2868 * <p>
2869 * This is only relevant to {@link ConnectionService}s which are registered with
2870 * {@link PhoneAccount#CAPABILITY_CONNECTION_MANAGER}.
2871 *
2872 * @param conference The remote conference call.
2873 */
Ihab Awadb8e85c72014-08-23 20:34:57 -07002874 public void onRemoteConferenceAdded(RemoteConference conference) {}
2875
Santos Cordon823fd3c2014-08-07 18:35:18 -07002876 /**
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002877 * Called when an existing connection is added remotely.
2878 * @param connection The existing connection which was added.
2879 */
2880 public void onRemoteExistingConnectionAdded(RemoteConnection connection) {}
2881
2882 /**
Pengquan Meng731c1a32017-11-21 18:01:13 -08002883 * Called when the {@link ConnectionService} has lost the call focus.
2884 * The {@link ConnectionService} should release the call resources and invokes
2885 * {@link ConnectionService#connectionServiceFocusReleased()} to inform telecom that it has
2886 * released the call resources.
2887 */
2888 public void onConnectionServiceFocusLost() {}
2889
2890 /**
2891 * Called when the {@link ConnectionService} has gained the call focus. The
2892 * {@link ConnectionService} can acquire the call resources at this time.
2893 */
2894 public void onConnectionServiceFocusGained() {}
2895
2896 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07002897 * @hide
2898 */
2899 public boolean containsConference(Conference conference) {
2900 return mIdByConference.containsKey(conference);
2901 }
2902
Ihab Awadb8e85c72014-08-23 20:34:57 -07002903 /** {@hide} */
2904 void addRemoteConference(RemoteConference remoteConference) {
2905 onRemoteConferenceAdded(remoteConference);
2906 }
2907
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002908 /** {@hide} */
2909 void addRemoteExistingConnection(RemoteConnection remoteConnection) {
2910 onRemoteExistingConnectionAdded(remoteConnection);
2911 }
2912
Ihab Awad5d0410f2014-07-30 10:07:40 -07002913 private void onAccountsInitialized() {
2914 mAreAccountsInitialized = true;
2915 for (Runnable r : mPreInitializationConnectionRequests) {
2916 r.run();
2917 }
2918 mPreInitializationConnectionRequests.clear();
2919 }
2920
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002921 /**
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002922 * Adds an existing connection to the list of connections, identified by a new call ID unique
2923 * to this connection service.
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002924 *
2925 * @param connection The connection.
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002926 * @return The ID of the connection (e.g. the call-id).
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002927 */
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002928 private String addExistingConnectionInternal(PhoneAccountHandle handle, Connection connection) {
2929 String id;
Tyler Gunncd6ccfd2016-10-17 15:48:19 -07002930
2931 if (connection.getExtras() != null && connection.getExtras()
2932 .containsKey(Connection.EXTRA_ORIGINAL_CONNECTION_ID)) {
2933 id = connection.getExtras().getString(Connection.EXTRA_ORIGINAL_CONNECTION_ID);
2934 Log.d(this, "addExistingConnectionInternal - conn %s reusing original id %s",
2935 connection.getTelecomCallId(), id);
2936 } else if (handle == null) {
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002937 // If no phone account handle was provided, we cannot be sure the call ID is unique,
2938 // so just use a random UUID.
2939 id = UUID.randomUUID().toString();
2940 } else {
2941 // Phone account handle was provided, so use the ConnectionService class name as a
2942 // prefix for a unique incremental call ID.
2943 id = handle.getComponentName().getClassName() + "@" + getNextCallId();
2944 }
Pengquan Meng70c9885332017-10-02 18:09:03 -07002945 addConnection(handle, id, connection);
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002946 return id;
2947 }
2948
Pengquan Meng70c9885332017-10-02 18:09:03 -07002949 private void addConnection(PhoneAccountHandle handle, String callId, Connection connection) {
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002950 connection.setTelecomCallId(callId);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002951 mConnectionById.put(callId, connection);
2952 mIdByConnection.put(connection, callId);
2953 connection.addConnectionListener(mConnectionListener);
Santos Cordon823fd3c2014-08-07 18:35:18 -07002954 connection.setConnectionService(this);
Pengquan Meng70c9885332017-10-02 18:09:03 -07002955 connection.setPhoneAccountHandle(handle);
2956 onConnectionAdded(connection);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002957 }
2958
Anthony Lee30e65842014-11-06 16:30:53 -08002959 /** {@hide} */
2960 protected void removeConnection(Connection connection) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07002961 connection.unsetConnectionService(this);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002962 connection.removeConnectionListener(mConnectionListener);
Chenjie Luoe370b532016-05-12 16:59:43 -07002963 String id = mIdByConnection.get(connection);
2964 if (id != null) {
2965 mConnectionById.remove(id);
2966 mIdByConnection.remove(connection);
2967 mAdapter.removeCall(id);
Pengquan Meng70c9885332017-10-02 18:09:03 -07002968 onConnectionRemoved(connection);
Chenjie Luoe370b532016-05-12 16:59:43 -07002969 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002970 }
2971
Santos Cordon823fd3c2014-08-07 18:35:18 -07002972 private String addConferenceInternal(Conference conference) {
Tyler Gunncd6ccfd2016-10-17 15:48:19 -07002973 String originalId = null;
2974 if (conference.getExtras() != null && conference.getExtras()
2975 .containsKey(Connection.EXTRA_ORIGINAL_CONNECTION_ID)) {
2976 originalId = conference.getExtras().getString(Connection.EXTRA_ORIGINAL_CONNECTION_ID);
2977 Log.d(this, "addConferenceInternal: conf %s reusing original id %s",
2978 conference.getTelecomCallId(),
2979 originalId);
2980 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07002981 if (mIdByConference.containsKey(conference)) {
2982 Log.w(this, "Re-adding an existing conference: %s.", conference);
2983 } else if (conference != null) {
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002984 // Conferences do not (yet) have a PhoneAccountHandle associated with them, so we
2985 // cannot determine a ConnectionService class name to associate with the ID, so use
2986 // a unique UUID (for now).
Tyler Gunncd6ccfd2016-10-17 15:48:19 -07002987 String id = originalId == null ? UUID.randomUUID().toString() : originalId;
Santos Cordon823fd3c2014-08-07 18:35:18 -07002988 mConferenceById.put(id, conference);
2989 mIdByConference.put(conference, id);
2990 conference.addListener(mConferenceListener);
2991 return id;
2992 }
2993
2994 return null;
2995 }
2996
2997 private void removeConference(Conference conference) {
2998 if (mIdByConference.containsKey(conference)) {
2999 conference.removeListener(mConferenceListener);
3000
3001 String id = mIdByConference.get(conference);
3002 mConferenceById.remove(id);
3003 mIdByConference.remove(conference);
3004 mAdapter.removeCall(id);
Pengquan Meng70c9885332017-10-02 18:09:03 -07003005
3006 onConferenceRemoved(conference);
Santos Cordon823fd3c2014-08-07 18:35:18 -07003007 }
3008 }
3009
Ihab Awad542e0ea2014-05-16 10:22:16 -07003010 private Connection findConnectionForAction(String callId, String action) {
Tyler Gunn0a88f2e2017-06-16 20:20:34 -07003011 if (callId != null && mConnectionById.containsKey(callId)) {
Ihab Awad542e0ea2014-05-16 10:22:16 -07003012 return mConnectionById.get(callId);
3013 }
Ihab Awad60ac30b2014-05-20 22:32:12 -07003014 Log.w(this, "%s - Cannot find Connection %s", action, callId);
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07003015 return getNullConnection();
3016 }
3017
3018 static synchronized Connection getNullConnection() {
3019 if (sNullConnection == null) {
3020 sNullConnection = new Connection() {};
3021 }
3022 return sNullConnection;
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003023 }
Santos Cordon0159ac02014-08-21 14:28:11 -07003024
3025 private Conference findConferenceForAction(String conferenceId, String action) {
3026 if (mConferenceById.containsKey(conferenceId)) {
3027 return mConferenceById.get(conferenceId);
3028 }
3029 Log.w(this, "%s - Cannot find conference %s", action, conferenceId);
3030 return getNullConference();
3031 }
3032
Ihab Awadb8e85c72014-08-23 20:34:57 -07003033 private List<String> createConnectionIdList(List<Connection> connections) {
3034 List<String> ids = new ArrayList<>();
3035 for (Connection c : connections) {
3036 if (mIdByConnection.containsKey(c)) {
3037 ids.add(mIdByConnection.get(c));
3038 }
3039 }
3040 Collections.sort(ids);
3041 return ids;
3042 }
3043
Tyler Gunn6d76ca02014-11-17 15:49:51 -08003044 /**
3045 * Builds a list of {@link Connection} and {@link Conference} IDs based on the list of
Tyler Gunndf2cbc82015-04-20 09:13:01 -07003046 * {@link Conferenceable}s passed in.
Tyler Gunn6d76ca02014-11-17 15:49:51 -08003047 *
Tyler Gunndf2cbc82015-04-20 09:13:01 -07003048 * @param conferenceables The {@link Conferenceable} connections and conferences.
Tyler Gunn6d76ca02014-11-17 15:49:51 -08003049 * @return List of string conference and call Ids.
3050 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07003051 private List<String> createIdList(List<Conferenceable> conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08003052 List<String> ids = new ArrayList<>();
Tyler Gunndf2cbc82015-04-20 09:13:01 -07003053 for (Conferenceable c : conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08003054 // Only allow Connection and Conference conferenceables.
3055 if (c instanceof Connection) {
3056 Connection connection = (Connection) c;
3057 if (mIdByConnection.containsKey(connection)) {
3058 ids.add(mIdByConnection.get(connection));
3059 }
3060 } else if (c instanceof Conference) {
3061 Conference conference = (Conference) c;
3062 if (mIdByConference.containsKey(conference)) {
3063 ids.add(mIdByConference.get(conference));
3064 }
3065 }
3066 }
3067 Collections.sort(ids);
3068 return ids;
3069 }
3070
Santos Cordon0159ac02014-08-21 14:28:11 -07003071 private Conference getNullConference() {
3072 if (sNullConference == null) {
3073 sNullConference = new Conference(null) {};
3074 }
3075 return sNullConference;
3076 }
Santos Cordon29f2f2e2014-09-11 19:50:24 -07003077
3078 private void endAllConnections() {
3079 // Unbound from telecomm. We should end all connections and conferences.
3080 for (Connection connection : mIdByConnection.keySet()) {
3081 // only operate on top-level calls. Conference calls will be removed on their own.
3082 if (connection.getConference() == null) {
3083 connection.onDisconnect();
3084 }
3085 }
3086 for (Conference conference : mIdByConference.keySet()) {
3087 conference.onDisconnect();
3088 }
3089 }
Tyler Gunnf0500bd2015-09-01 10:59:48 -07003090
3091 /**
3092 * Retrieves the next call ID as maintainted by the connection service.
3093 *
3094 * @return The call ID.
3095 */
3096 private int getNextCallId() {
Brad Ebingerb32d4f82016-10-24 16:40:49 -07003097 synchronized (mIdSyncRoot) {
Tyler Gunnf0500bd2015-09-01 10:59:48 -07003098 return ++mId;
3099 }
3100 }
Brad Ebinger99f17ce2019-09-11 18:06:51 -07003101
3102 /**
3103 * Returns this handler, ONLY FOR TESTING.
3104 * @hide
3105 */
3106 @VisibleForTesting
3107 public Handler getHandler() {
3108 return mHandler;
3109 }
Santos Cordon980acb92014-05-31 10:31:19 -07003110}