blob: f2141d31b596e2a065758152dbb0d87579d0cf19 [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";
Ravi Paluri404babb2020-01-23 19:02:44 +0530145 private static final String SESSION_ADD_PARTICIPANT = "CS.aP";
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700146 private static final String SESSION_POST_DIAL_CONT = "CS.oPDC";
147 private static final String SESSION_PULL_EXTERNAL_CALL = "CS.pEC";
148 private static final String SESSION_SEND_CALL_EVENT = "CS.sCE";
Tyler Gunn79bc1ec2018-01-22 15:17:54 -0800149 private static final String SESSION_HANDOVER_COMPLETE = "CS.hC";
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700150 private static final String SESSION_EXTRAS_CHANGED = "CS.oEC";
Hall Liub64ac4c2017-02-06 10:49:48 -0800151 private static final String SESSION_START_RTT = "CS.+RTT";
Hall Liua549fed2018-02-09 16:40:03 -0800152 private static final String SESSION_UPDATE_RTT_PIPES = "CS.uRTT";
Hall Liub64ac4c2017-02-06 10:49:48 -0800153 private static final String SESSION_STOP_RTT = "CS.-RTT";
154 private static final String SESSION_RTT_UPGRADE_RESPONSE = "CS.rTRUR";
Pengquan Meng731c1a32017-11-21 18:01:13 -0800155 private static final String SESSION_CONNECTION_SERVICE_FOCUS_LOST = "CS.cSFL";
156 private static final String SESSION_CONNECTION_SERVICE_FOCUS_GAINED = "CS.cSFG";
Sanket Padawe4cc8ed52017-12-04 16:22:20 -0800157 private static final String SESSION_HANDOVER_FAILED = "CS.haF";
Ravi Paluri80aa2142019-12-02 11:57:37 +0530158 private static final String SESSION_CREATE_CONF = "CS.crConf";
159 private static final String SESSION_CREATE_CONF_COMPLETE = "CS.crConfC";
160 private static final String SESSION_CREATE_CONF_FAILED = "CS.crConfF";
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700161
Ihab Awad8aecfed2014-08-08 17:06:11 -0700162 private static final int MSG_ADD_CONNECTION_SERVICE_ADAPTER = 1;
Sailesh Nepalc5b01572014-07-14 16:29:44 -0700163 private static final int MSG_CREATE_CONNECTION = 2;
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700164 private static final int MSG_ABORT = 3;
Sailesh Nepalc5b01572014-07-14 16:29:44 -0700165 private static final int MSG_ANSWER = 4;
166 private static final int MSG_REJECT = 5;
167 private static final int MSG_DISCONNECT = 6;
168 private static final int MSG_HOLD = 7;
169 private static final int MSG_UNHOLD = 8;
Yorke Lee4af59352015-05-13 14:14:54 -0700170 private static final int MSG_ON_CALL_AUDIO_STATE_CHANGED = 9;
Sailesh Nepalc5b01572014-07-14 16:29:44 -0700171 private static final int MSG_PLAY_DTMF_TONE = 10;
172 private static final int MSG_STOP_DTMF_TONE = 11;
173 private static final int MSG_CONFERENCE = 12;
174 private static final int MSG_SPLIT_FROM_CONFERENCE = 13;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700175 private static final int MSG_ON_POST_DIAL_CONTINUE = 14;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700176 private static final int MSG_REMOVE_CONNECTION_SERVICE_ADAPTER = 16;
Tyler Gunnbe74de02014-08-29 14:51:48 -0700177 private static final int MSG_ANSWER_VIDEO = 17;
Santos Cordona4868042014-09-04 17:39:22 -0700178 private static final int MSG_MERGE_CONFERENCE = 18;
179 private static final int MSG_SWAP_CONFERENCE = 19;
Bryce Lee81901682015-08-28 16:38:02 -0700180 private static final int MSG_REJECT_WITH_MESSAGE = 20;
Bryce Leecac50772015-11-17 15:13:29 -0800181 private static final int MSG_SILENCE = 21;
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700182 private static final int MSG_PULL_EXTERNAL_CALL = 22;
183 private static final int MSG_SEND_CALL_EVENT = 23;
Tyler Gunndee56a82016-03-23 16:06:34 -0700184 private static final int MSG_ON_EXTRAS_CHANGED = 24;
Tyler Gunn44e01912017-01-31 10:49:05 -0800185 private static final int MSG_CREATE_CONNECTION_FAILED = 25;
Hall Liub64ac4c2017-02-06 10:49:48 -0800186 private static final int MSG_ON_START_RTT = 26;
187 private static final int MSG_ON_STOP_RTT = 27;
188 private static final int MSG_RTT_UPGRADE_RESPONSE = 28;
Tyler Gunn041a1fe2017-05-12 10:04:49 -0700189 private static final int MSG_CREATE_CONNECTION_COMPLETE = 29;
Pengquan Meng731c1a32017-11-21 18:01:13 -0800190 private static final int MSG_CONNECTION_SERVICE_FOCUS_LOST = 30;
191 private static final int MSG_CONNECTION_SERVICE_FOCUS_GAINED = 31;
Sanket Padawe4cc8ed52017-12-04 16:22:20 -0800192 private static final int MSG_HANDOVER_FAILED = 32;
Tyler Gunn79bc1ec2018-01-22 15:17:54 -0800193 private static final int MSG_HANDOVER_COMPLETE = 33;
Pooja Jaind34698d2017-12-28 14:15:31 +0530194 private static final int MSG_DEFLECT = 34;
Ravi Paluri80aa2142019-12-02 11:57:37 +0530195 private static final int MSG_CREATE_CONFERENCE = 35;
196 private static final int MSG_CREATE_CONFERENCE_COMPLETE = 36;
197 private static final int MSG_CREATE_CONFERENCE_FAILED = 37;
Tyler Gunnfacfdee2020-01-23 13:10:37 -0800198 private static final int MSG_REJECT_WITH_REASON = 38;
Ravi Paluri404babb2020-01-23 19:02:44 +0530199 private static final int MSG_ADD_PARTICIPANT = 39;
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700200
Sailesh Nepalcf7020b2014-08-20 10:07:19 -0700201 private static Connection sNullConnection;
202
mike dooley95e80702014-09-18 14:07:52 -0700203 private final Map<String, Connection> mConnectionById = new ConcurrentHashMap<>();
204 private final Map<Connection, String> mIdByConnection = new ConcurrentHashMap<>();
205 private final Map<String, Conference> mConferenceById = new ConcurrentHashMap<>();
206 private final Map<Conference, String> mIdByConference = new ConcurrentHashMap<>();
Ihab Awadb8e85c72014-08-23 20:34:57 -0700207 private final RemoteConnectionManager mRemoteConnectionManager =
208 new RemoteConnectionManager(this);
Ihab Awad5d0410f2014-07-30 10:07:40 -0700209 private final List<Runnable> mPreInitializationConnectionRequests = new ArrayList<>();
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700210 private final ConnectionServiceAdapter mAdapter = new ConnectionServiceAdapter();
Ihab Awad542e0ea2014-05-16 10:22:16 -0700211
Santos Cordon823fd3c2014-08-07 18:35:18 -0700212 private boolean mAreAccountsInitialized = false;
Santos Cordon0159ac02014-08-21 14:28:11 -0700213 private Conference sNullConference;
Tyler Gunnf0500bd2015-09-01 10:59:48 -0700214 private Object mIdSyncRoot = new Object();
215 private int mId = 0;
Santos Cordon823fd3c2014-08-07 18:35:18 -0700216
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700217 private final IBinder mBinder = new IConnectionService.Stub() {
218 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700219 public void addConnectionServiceAdapter(IConnectionServiceAdapter adapter,
220 Session.Info sessionInfo) {
221 Log.startSession(sessionInfo, SESSION_ADD_CS_ADAPTER);
222 try {
223 SomeArgs args = SomeArgs.obtain();
224 args.arg1 = adapter;
225 args.arg2 = Log.createSubsession();
226 mHandler.obtainMessage(MSG_ADD_CONNECTION_SERVICE_ADAPTER, args).sendToTarget();
227 } finally {
228 Log.endSession();
229 }
Ihab Awad8aecfed2014-08-08 17:06:11 -0700230 }
231
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700232 public void removeConnectionServiceAdapter(IConnectionServiceAdapter adapter,
233 Session.Info sessionInfo) {
234 Log.startSession(sessionInfo, SESSION_REMOVE_CS_ADAPTER);
235 try {
236 SomeArgs args = SomeArgs.obtain();
237 args.arg1 = adapter;
238 args.arg2 = Log.createSubsession();
239 mHandler.obtainMessage(MSG_REMOVE_CONNECTION_SERVICE_ADAPTER, args).sendToTarget();
240 } finally {
241 Log.endSession();
242 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700243 }
244
245 @Override
Ihab Awadf8b69882014-07-25 15:14:01 -0700246 public void createConnection(
247 PhoneAccountHandle connectionManagerPhoneAccount,
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700248 String id,
Ihab Awadf8b69882014-07-25 15:14:01 -0700249 ConnectionRequest request,
Yorke Leec3cf9822014-10-02 09:38:39 -0700250 boolean isIncoming,
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700251 boolean isUnknown,
252 Session.Info sessionInfo) {
253 Log.startSession(sessionInfo, SESSION_CREATE_CONN);
254 try {
255 SomeArgs args = SomeArgs.obtain();
256 args.arg1 = connectionManagerPhoneAccount;
257 args.arg2 = id;
258 args.arg3 = request;
259 args.arg4 = Log.createSubsession();
260 args.argi1 = isIncoming ? 1 : 0;
261 args.argi2 = isUnknown ? 1 : 0;
262 mHandler.obtainMessage(MSG_CREATE_CONNECTION, args).sendToTarget();
263 } finally {
264 Log.endSession();
265 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700266 }
267
268 @Override
Tyler Gunn041a1fe2017-05-12 10:04:49 -0700269 public void createConnectionComplete(String id, Session.Info sessionInfo) {
270 Log.startSession(sessionInfo, SESSION_CREATE_CONN_COMPLETE);
271 try {
272 SomeArgs args = SomeArgs.obtain();
273 args.arg1 = id;
274 args.arg2 = Log.createSubsession();
275 mHandler.obtainMessage(MSG_CREATE_CONNECTION_COMPLETE, args).sendToTarget();
276 } finally {
277 Log.endSession();
278 }
279 }
280
281 @Override
Tyler Gunn44e01912017-01-31 10:49:05 -0800282 public void createConnectionFailed(
Tyler Gunn159f35c2017-03-02 09:28:37 -0800283 PhoneAccountHandle connectionManagerPhoneAccount,
Tyler Gunn44e01912017-01-31 10:49:05 -0800284 String callId,
285 ConnectionRequest request,
286 boolean isIncoming,
287 Session.Info sessionInfo) {
288 Log.startSession(sessionInfo, SESSION_CREATE_CONN_FAILED);
289 try {
290 SomeArgs args = SomeArgs.obtain();
291 args.arg1 = callId;
292 args.arg2 = request;
293 args.arg3 = Log.createSubsession();
Tyler Gunn159f35c2017-03-02 09:28:37 -0800294 args.arg4 = connectionManagerPhoneAccount;
Tyler Gunn44e01912017-01-31 10:49:05 -0800295 args.argi1 = isIncoming ? 1 : 0;
296 mHandler.obtainMessage(MSG_CREATE_CONNECTION_FAILED, args).sendToTarget();
297 } finally {
298 Log.endSession();
299 }
300 }
301
302 @Override
Ravi Paluri80aa2142019-12-02 11:57:37 +0530303 public void createConference(
304 PhoneAccountHandle connectionManagerPhoneAccount,
305 String id,
306 ConnectionRequest request,
307 boolean isIncoming,
308 boolean isUnknown,
309 Session.Info sessionInfo) {
310 Log.startSession(sessionInfo, SESSION_CREATE_CONF);
311 try {
312 SomeArgs args = SomeArgs.obtain();
313 args.arg1 = connectionManagerPhoneAccount;
314 args.arg2 = id;
315 args.arg3 = request;
316 args.arg4 = Log.createSubsession();
317 args.argi1 = isIncoming ? 1 : 0;
318 args.argi2 = isUnknown ? 1 : 0;
319 mHandler.obtainMessage(MSG_CREATE_CONFERENCE, args).sendToTarget();
320 } finally {
321 Log.endSession();
322 }
323 }
324
325 @Override
326 public void createConferenceComplete(String id, Session.Info sessionInfo) {
327 Log.startSession(sessionInfo, SESSION_CREATE_CONF_COMPLETE);
328 try {
329 SomeArgs args = SomeArgs.obtain();
330 args.arg1 = id;
331 args.arg2 = Log.createSubsession();
332 mHandler.obtainMessage(MSG_CREATE_CONFERENCE_COMPLETE, args).sendToTarget();
333 } finally {
334 Log.endSession();
335 }
336 }
337
338 @Override
339 public void createConferenceFailed(
340 PhoneAccountHandle connectionManagerPhoneAccount,
341 String callId,
342 ConnectionRequest request,
343 boolean isIncoming,
344 Session.Info sessionInfo) {
345 Log.startSession(sessionInfo, SESSION_CREATE_CONF_FAILED);
346 try {
347 SomeArgs args = SomeArgs.obtain();
348 args.arg1 = callId;
349 args.arg2 = request;
350 args.arg3 = Log.createSubsession();
351 args.arg4 = connectionManagerPhoneAccount;
352 args.argi1 = isIncoming ? 1 : 0;
353 mHandler.obtainMessage(MSG_CREATE_CONFERENCE_FAILED, args).sendToTarget();
354 } finally {
355 Log.endSession();
356 }
357 }
358
359 @Override
Sanket Padawe4cc8ed52017-12-04 16:22:20 -0800360 public void handoverFailed(String callId, ConnectionRequest request, int reason,
361 Session.Info sessionInfo) {
362 Log.startSession(sessionInfo, SESSION_HANDOVER_FAILED);
363 try {
364 SomeArgs args = SomeArgs.obtain();
365 args.arg1 = callId;
366 args.arg2 = request;
367 args.arg3 = Log.createSubsession();
368 args.arg4 = reason;
369 mHandler.obtainMessage(MSG_HANDOVER_FAILED, args).sendToTarget();
370 } finally {
371 Log.endSession();
372 }
373 }
374
375 @Override
Tyler Gunn79bc1ec2018-01-22 15:17:54 -0800376 public void handoverComplete(String callId, Session.Info sessionInfo) {
377 Log.startSession(sessionInfo, SESSION_HANDOVER_COMPLETE);
378 try {
379 SomeArgs args = SomeArgs.obtain();
380 args.arg1 = callId;
381 args.arg2 = Log.createSubsession();
382 mHandler.obtainMessage(MSG_HANDOVER_COMPLETE, args).sendToTarget();
383 } finally {
384 Log.endSession();
385 }
386 }
387
388 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700389 public void abort(String callId, Session.Info sessionInfo) {
390 Log.startSession(sessionInfo, SESSION_ABORT);
391 try {
392 SomeArgs args = SomeArgs.obtain();
393 args.arg1 = callId;
394 args.arg2 = Log.createSubsession();
395 mHandler.obtainMessage(MSG_ABORT, args).sendToTarget();
396 } finally {
397 Log.endSession();
398 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700399 }
400
401 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700402 public void answerVideo(String callId, int videoState, Session.Info sessionInfo) {
403 Log.startSession(sessionInfo, SESSION_ANSWER_VIDEO);
404 try {
405 SomeArgs args = SomeArgs.obtain();
406 args.arg1 = callId;
407 args.arg2 = Log.createSubsession();
408 args.argi1 = videoState;
409 mHandler.obtainMessage(MSG_ANSWER_VIDEO, args).sendToTarget();
410 } finally {
411 Log.endSession();
412 }
Tyler Gunnbe74de02014-08-29 14:51:48 -0700413 }
414
415 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700416 public void answer(String callId, Session.Info sessionInfo) {
417 Log.startSession(sessionInfo, SESSION_ANSWER);
418 try {
419 SomeArgs args = SomeArgs.obtain();
420 args.arg1 = callId;
421 args.arg2 = Log.createSubsession();
422 mHandler.obtainMessage(MSG_ANSWER, args).sendToTarget();
423 } finally {
424 Log.endSession();
425 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700426 }
427
428 @Override
Pooja Jaind34698d2017-12-28 14:15:31 +0530429 public void deflect(String callId, Uri address, Session.Info sessionInfo) {
430 Log.startSession(sessionInfo, SESSION_DEFLECT);
431 try {
432 SomeArgs args = SomeArgs.obtain();
433 args.arg1 = callId;
434 args.arg2 = address;
435 args.arg3 = Log.createSubsession();
436 mHandler.obtainMessage(MSG_DEFLECT, args).sendToTarget();
437 } finally {
438 Log.endSession();
439 }
440 }
441
442 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700443 public void reject(String callId, Session.Info sessionInfo) {
444 Log.startSession(sessionInfo, SESSION_REJECT);
445 try {
446 SomeArgs args = SomeArgs.obtain();
447 args.arg1 = callId;
448 args.arg2 = Log.createSubsession();
449 mHandler.obtainMessage(MSG_REJECT, args).sendToTarget();
450 } finally {
451 Log.endSession();
452 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700453 }
454
455 @Override
Tyler Gunnfacfdee2020-01-23 13:10:37 -0800456 public void rejectWithReason(String callId,
457 @android.telecom.Call.RejectReason int rejectReason, Session.Info sessionInfo) {
458 Log.startSession(sessionInfo, SESSION_REJECT);
459 try {
460 SomeArgs args = SomeArgs.obtain();
461 args.arg1 = callId;
462 args.argi1 = rejectReason;
463 args.arg2 = Log.createSubsession();
464 mHandler.obtainMessage(MSG_REJECT_WITH_REASON, args).sendToTarget();
465 } finally {
466 Log.endSession();
467 }
468 }
469
470 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700471 public void rejectWithMessage(String callId, String message, Session.Info sessionInfo) {
472 Log.startSession(sessionInfo, SESSION_REJECT_MESSAGE);
473 try {
474 SomeArgs args = SomeArgs.obtain();
475 args.arg1 = callId;
476 args.arg2 = message;
477 args.arg3 = Log.createSubsession();
478 mHandler.obtainMessage(MSG_REJECT_WITH_MESSAGE, args).sendToTarget();
479 } finally {
480 Log.endSession();
481 }
Bryce Lee81901682015-08-28 16:38:02 -0700482 }
483
484 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700485 public void silence(String callId, Session.Info sessionInfo) {
486 Log.startSession(sessionInfo, SESSION_SILENCE);
487 try {
488 SomeArgs args = SomeArgs.obtain();
489 args.arg1 = callId;
490 args.arg2 = Log.createSubsession();
491 mHandler.obtainMessage(MSG_SILENCE, args).sendToTarget();
492 } finally {
493 Log.endSession();
494 }
Bryce Leecac50772015-11-17 15:13:29 -0800495 }
496
497 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700498 public void disconnect(String callId, Session.Info sessionInfo) {
499 Log.startSession(sessionInfo, SESSION_DISCONNECT);
500 try {
501 SomeArgs args = SomeArgs.obtain();
502 args.arg1 = callId;
503 args.arg2 = Log.createSubsession();
504 mHandler.obtainMessage(MSG_DISCONNECT, args).sendToTarget();
505 } finally {
506 Log.endSession();
507 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700508 }
509
510 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700511 public void hold(String callId, Session.Info sessionInfo) {
512 Log.startSession(sessionInfo, SESSION_HOLD);
513 try {
514 SomeArgs args = SomeArgs.obtain();
515 args.arg1 = callId;
516 args.arg2 = Log.createSubsession();
517 mHandler.obtainMessage(MSG_HOLD, args).sendToTarget();
518 } finally {
519 Log.endSession();
520 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700521 }
522
523 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700524 public void unhold(String callId, Session.Info sessionInfo) {
525 Log.startSession(sessionInfo, SESSION_UNHOLD);
526 try {
527 SomeArgs args = SomeArgs.obtain();
528 args.arg1 = callId;
529 args.arg2 = Log.createSubsession();
530 mHandler.obtainMessage(MSG_UNHOLD, args).sendToTarget();
531 } finally {
532 Log.endSession();
533 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700534 }
535
536 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700537 public void onCallAudioStateChanged(String callId, CallAudioState callAudioState,
538 Session.Info sessionInfo) {
539 Log.startSession(sessionInfo, SESSION_CALL_AUDIO_SC);
540 try {
541 SomeArgs args = SomeArgs.obtain();
542 args.arg1 = callId;
543 args.arg2 = callAudioState;
544 args.arg3 = Log.createSubsession();
545 mHandler.obtainMessage(MSG_ON_CALL_AUDIO_STATE_CHANGED, args).sendToTarget();
546 } finally {
547 Log.endSession();
548 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700549 }
550
551 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700552 public void playDtmfTone(String callId, char digit, Session.Info sessionInfo) {
553 Log.startSession(sessionInfo, SESSION_PLAY_DTMF);
554 try {
555 SomeArgs args = SomeArgs.obtain();
556 args.arg1 = digit;
557 args.arg2 = callId;
558 args.arg3 = Log.createSubsession();
559 mHandler.obtainMessage(MSG_PLAY_DTMF_TONE, args).sendToTarget();
560 } finally {
561 Log.endSession();
562 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700563 }
564
565 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700566 public void stopDtmfTone(String callId, Session.Info sessionInfo) {
567 Log.startSession(sessionInfo, SESSION_STOP_DTMF);
568 try {
569 SomeArgs args = SomeArgs.obtain();
570 args.arg1 = callId;
571 args.arg2 = Log.createSubsession();
572 mHandler.obtainMessage(MSG_STOP_DTMF_TONE, args).sendToTarget();
573 } finally {
574 Log.endSession();
575 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700576 }
577
578 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700579 public void conference(String callId1, String callId2, Session.Info sessionInfo) {
580 Log.startSession(sessionInfo, SESSION_CONFERENCE);
581 try {
582 SomeArgs args = SomeArgs.obtain();
583 args.arg1 = callId1;
584 args.arg2 = callId2;
585 args.arg3 = Log.createSubsession();
586 mHandler.obtainMessage(MSG_CONFERENCE, args).sendToTarget();
587 } finally {
588 Log.endSession();
589 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700590 }
591
592 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700593 public void splitFromConference(String callId, Session.Info sessionInfo) {
594 Log.startSession(sessionInfo, SESSION_SPLIT_CONFERENCE);
595 try {
596 SomeArgs args = SomeArgs.obtain();
597 args.arg1 = callId;
598 args.arg2 = Log.createSubsession();
599 mHandler.obtainMessage(MSG_SPLIT_FROM_CONFERENCE, args).sendToTarget();
600 } finally {
601 Log.endSession();
602 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700603 }
604
605 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700606 public void mergeConference(String callId, Session.Info sessionInfo) {
607 Log.startSession(sessionInfo, SESSION_MERGE_CONFERENCE);
608 try {
609 SomeArgs args = SomeArgs.obtain();
610 args.arg1 = callId;
611 args.arg2 = Log.createSubsession();
612 mHandler.obtainMessage(MSG_MERGE_CONFERENCE, args).sendToTarget();
613 } finally {
614 Log.endSession();
615 }
Santos Cordona4868042014-09-04 17:39:22 -0700616 }
617
618 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700619 public void swapConference(String callId, Session.Info sessionInfo) {
620 Log.startSession(sessionInfo, SESSION_SWAP_CONFERENCE);
621 try {
622 SomeArgs args = SomeArgs.obtain();
623 args.arg1 = callId;
624 args.arg2 = Log.createSubsession();
625 mHandler.obtainMessage(MSG_SWAP_CONFERENCE, args).sendToTarget();
626 } finally {
627 Log.endSession();
628 }
Santos Cordona4868042014-09-04 17:39:22 -0700629 }
630
631 @Override
Ravi Paluri404babb2020-01-23 19:02:44 +0530632 public void addConferenceParticipants(String callId, List<Uri> participants,
633 Session.Info sessionInfo) {
634 Log.startSession(sessionInfo, SESSION_ADD_PARTICIPANT);
635 try {
636 SomeArgs args = SomeArgs.obtain();
637 args.arg1 = callId;
638 args.arg2 = participants;
639 args.arg3 = Log.createSubsession();
640 mHandler.obtainMessage(MSG_ADD_PARTICIPANT, args).sendToTarget();
641 } finally {
642 Log.endSession();
643 }
644 }
645
646 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700647 public void onPostDialContinue(String callId, boolean proceed, Session.Info sessionInfo) {
648 Log.startSession(sessionInfo, SESSION_POST_DIAL_CONT);
649 try {
650 SomeArgs args = SomeArgs.obtain();
651 args.arg1 = callId;
652 args.arg2 = Log.createSubsession();
653 args.argi1 = proceed ? 1 : 0;
654 mHandler.obtainMessage(MSG_ON_POST_DIAL_CONTINUE, args).sendToTarget();
655 } finally {
656 Log.endSession();
657 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700658 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700659
660 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700661 public void pullExternalCall(String callId, Session.Info sessionInfo) {
662 Log.startSession(sessionInfo, SESSION_PULL_EXTERNAL_CALL);
663 try {
664 SomeArgs args = SomeArgs.obtain();
665 args.arg1 = callId;
666 args.arg2 = Log.createSubsession();
667 mHandler.obtainMessage(MSG_PULL_EXTERNAL_CALL, args).sendToTarget();
668 } finally {
669 Log.endSession();
670 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700671 }
672
673 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700674 public void sendCallEvent(String callId, String event, Bundle extras,
675 Session.Info sessionInfo) {
676 Log.startSession(sessionInfo, SESSION_SEND_CALL_EVENT);
677 try {
678 SomeArgs args = SomeArgs.obtain();
679 args.arg1 = callId;
680 args.arg2 = event;
681 args.arg3 = extras;
682 args.arg4 = Log.createSubsession();
683 mHandler.obtainMessage(MSG_SEND_CALL_EVENT, args).sendToTarget();
684 } finally {
685 Log.endSession();
686 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700687 }
Tyler Gunndee56a82016-03-23 16:06:34 -0700688
689 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700690 public void onExtrasChanged(String callId, Bundle extras, Session.Info sessionInfo) {
691 Log.startSession(sessionInfo, SESSION_EXTRAS_CHANGED);
692 try {
693 SomeArgs args = SomeArgs.obtain();
694 args.arg1 = callId;
695 args.arg2 = extras;
696 args.arg3 = Log.createSubsession();
697 mHandler.obtainMessage(MSG_ON_EXTRAS_CHANGED, args).sendToTarget();
698 } finally {
699 Log.endSession();
700 }
Tyler Gunndee56a82016-03-23 16:06:34 -0700701 }
Hall Liub64ac4c2017-02-06 10:49:48 -0800702
703 @Override
704 public void startRtt(String callId, ParcelFileDescriptor fromInCall,
705 ParcelFileDescriptor toInCall, Session.Info sessionInfo) throws RemoteException {
706 Log.startSession(sessionInfo, SESSION_START_RTT);
707 try {
708 SomeArgs args = SomeArgs.obtain();
709 args.arg1 = callId;
710 args.arg2 = new Connection.RttTextStream(toInCall, fromInCall);
711 args.arg3 = Log.createSubsession();
712 mHandler.obtainMessage(MSG_ON_START_RTT, args).sendToTarget();
713 } finally {
714 Log.endSession();
715 }
716 }
717
718 @Override
719 public void stopRtt(String callId, Session.Info sessionInfo) throws RemoteException {
720 Log.startSession(sessionInfo, SESSION_STOP_RTT);
721 try {
722 SomeArgs args = SomeArgs.obtain();
723 args.arg1 = callId;
724 args.arg2 = Log.createSubsession();
725 mHandler.obtainMessage(MSG_ON_STOP_RTT, args).sendToTarget();
726 } finally {
727 Log.endSession();
728 }
729 }
730
731 @Override
732 public void respondToRttUpgradeRequest(String callId, ParcelFileDescriptor fromInCall,
733 ParcelFileDescriptor toInCall, Session.Info sessionInfo) throws RemoteException {
734 Log.startSession(sessionInfo, SESSION_RTT_UPGRADE_RESPONSE);
735 try {
736 SomeArgs args = SomeArgs.obtain();
737 args.arg1 = callId;
738 if (toInCall == null || fromInCall == null) {
739 args.arg2 = null;
740 } else {
741 args.arg2 = new Connection.RttTextStream(toInCall, fromInCall);
742 }
743 args.arg3 = Log.createSubsession();
744 mHandler.obtainMessage(MSG_RTT_UPGRADE_RESPONSE, args).sendToTarget();
745 } finally {
746 Log.endSession();
747 }
748 }
Pengquan Meng731c1a32017-11-21 18:01:13 -0800749
750 @Override
751 public void connectionServiceFocusLost(Session.Info sessionInfo) throws RemoteException {
752 Log.startSession(sessionInfo, SESSION_CONNECTION_SERVICE_FOCUS_LOST);
753 try {
754 mHandler.obtainMessage(MSG_CONNECTION_SERVICE_FOCUS_LOST).sendToTarget();
755 } finally {
756 Log.endSession();
757 }
758 }
759
760 @Override
761 public void connectionServiceFocusGained(Session.Info sessionInfo) throws RemoteException {
762 Log.startSession(sessionInfo, SESSION_CONNECTION_SERVICE_FOCUS_GAINED);
763 try {
764 mHandler.obtainMessage(MSG_CONNECTION_SERVICE_FOCUS_GAINED).sendToTarget();
765 } finally {
766 Log.endSession();
767 }
768 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700769 };
770
771 private final Handler mHandler = new Handler(Looper.getMainLooper()) {
772 @Override
773 public void handleMessage(Message msg) {
774 switch (msg.what) {
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700775 case MSG_ADD_CONNECTION_SERVICE_ADAPTER: {
776 SomeArgs args = (SomeArgs) msg.obj;
777 try {
778 IConnectionServiceAdapter adapter = (IConnectionServiceAdapter) args.arg1;
779 Log.continueSession((Session) args.arg2,
780 SESSION_HANDLER + SESSION_ADD_CS_ADAPTER);
781 mAdapter.addAdapter(adapter);
782 onAdapterAttached();
783 } finally {
784 args.recycle();
785 Log.endSession();
786 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700787 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700788 }
789 case MSG_REMOVE_CONNECTION_SERVICE_ADAPTER: {
790 SomeArgs args = (SomeArgs) msg.obj;
791 try {
792 Log.continueSession((Session) args.arg2,
793 SESSION_HANDLER + SESSION_REMOVE_CS_ADAPTER);
794 mAdapter.removeAdapter((IConnectionServiceAdapter) args.arg1);
795 } finally {
796 args.recycle();
797 Log.endSession();
798 }
Ihab Awad8aecfed2014-08-08 17:06:11 -0700799 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700800 }
Ihab Awadf8b69882014-07-25 15:14:01 -0700801 case MSG_CREATE_CONNECTION: {
802 SomeArgs args = (SomeArgs) msg.obj;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700803 Log.continueSession((Session) args.arg4, SESSION_HANDLER + SESSION_CREATE_CONN);
Ihab Awadf8b69882014-07-25 15:14:01 -0700804 try {
Ihab Awad5d0410f2014-07-30 10:07:40 -0700805 final PhoneAccountHandle connectionManagerPhoneAccount =
Ihab Awadf8b69882014-07-25 15:14:01 -0700806 (PhoneAccountHandle) args.arg1;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700807 final String id = (String) args.arg2;
808 final ConnectionRequest request = (ConnectionRequest) args.arg3;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700809 final boolean isIncoming = args.argi1 == 1;
Yorke Leec3cf9822014-10-02 09:38:39 -0700810 final boolean isUnknown = args.argi2 == 1;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700811 if (!mAreAccountsInitialized) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700812 Log.d(this, "Enqueueing pre-init request %s", id);
Brad Ebinger0c3541b2016-11-01 14:11:38 -0700813 mPreInitializationConnectionRequests.add(
814 new android.telecom.Logging.Runnable(
815 SESSION_HANDLER + SESSION_CREATE_CONN + ".pICR",
816 null /*lock*/) {
Ihab Awad5d0410f2014-07-30 10:07:40 -0700817 @Override
Brad Ebinger0c3541b2016-11-01 14:11:38 -0700818 public void loggedRun() {
Ihab Awad5d0410f2014-07-30 10:07:40 -0700819 createConnection(
820 connectionManagerPhoneAccount,
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700821 id,
Ihab Awad5d0410f2014-07-30 10:07:40 -0700822 request,
Yorke Leec3cf9822014-10-02 09:38:39 -0700823 isIncoming,
824 isUnknown);
Ihab Awad5d0410f2014-07-30 10:07:40 -0700825 }
Brad Ebinger0c3541b2016-11-01 14:11:38 -0700826 }.prepare());
Ihab Awad5d0410f2014-07-30 10:07:40 -0700827 } else {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700828 createConnection(
829 connectionManagerPhoneAccount,
830 id,
831 request,
Yorke Leec3cf9822014-10-02 09:38:39 -0700832 isIncoming,
833 isUnknown);
Ihab Awad5d0410f2014-07-30 10:07:40 -0700834 }
Ihab Awadf8b69882014-07-25 15:14:01 -0700835 } finally {
836 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700837 Log.endSession();
Ihab Awadf8b69882014-07-25 15:14:01 -0700838 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700839 break;
Ihab Awadf8b69882014-07-25 15:14:01 -0700840 }
Tyler Gunn041a1fe2017-05-12 10:04:49 -0700841 case MSG_CREATE_CONNECTION_COMPLETE: {
842 SomeArgs args = (SomeArgs) msg.obj;
843 Log.continueSession((Session) args.arg2,
844 SESSION_HANDLER + SESSION_CREATE_CONN_COMPLETE);
845 try {
846 final String id = (String) args.arg1;
847 if (!mAreAccountsInitialized) {
848 Log.d(this, "Enqueueing pre-init request %s", id);
849 mPreInitializationConnectionRequests.add(
850 new android.telecom.Logging.Runnable(
851 SESSION_HANDLER + SESSION_CREATE_CONN_COMPLETE
852 + ".pICR",
853 null /*lock*/) {
854 @Override
855 public void loggedRun() {
856 notifyCreateConnectionComplete(id);
857 }
858 }.prepare());
859 } else {
860 notifyCreateConnectionComplete(id);
861 }
862 } finally {
863 args.recycle();
864 Log.endSession();
865 }
866 break;
867 }
Tyler Gunn44e01912017-01-31 10:49:05 -0800868 case MSG_CREATE_CONNECTION_FAILED: {
869 SomeArgs args = (SomeArgs) msg.obj;
870 Log.continueSession((Session) args.arg3, SESSION_HANDLER +
871 SESSION_CREATE_CONN_FAILED);
872 try {
873 final String id = (String) args.arg1;
874 final ConnectionRequest request = (ConnectionRequest) args.arg2;
875 final boolean isIncoming = args.argi1 == 1;
Tyler Gunn159f35c2017-03-02 09:28:37 -0800876 final PhoneAccountHandle connectionMgrPhoneAccount =
877 (PhoneAccountHandle) args.arg4;
Tyler Gunn44e01912017-01-31 10:49:05 -0800878 if (!mAreAccountsInitialized) {
879 Log.d(this, "Enqueueing pre-init request %s", id);
880 mPreInitializationConnectionRequests.add(
881 new android.telecom.Logging.Runnable(
882 SESSION_HANDLER + SESSION_CREATE_CONN_FAILED + ".pICR",
883 null /*lock*/) {
884 @Override
885 public void loggedRun() {
Tyler Gunn159f35c2017-03-02 09:28:37 -0800886 createConnectionFailed(connectionMgrPhoneAccount, id,
887 request, isIncoming);
Tyler Gunn44e01912017-01-31 10:49:05 -0800888 }
889 }.prepare());
890 } else {
891 Log.i(this, "createConnectionFailed %s", id);
Tyler Gunn159f35c2017-03-02 09:28:37 -0800892 createConnectionFailed(connectionMgrPhoneAccount, id, request,
893 isIncoming);
Tyler Gunn44e01912017-01-31 10:49:05 -0800894 }
895 } finally {
896 args.recycle();
897 Log.endSession();
898 }
899 break;
900 }
Ravi Paluri80aa2142019-12-02 11:57:37 +0530901 case MSG_CREATE_CONFERENCE: {
902 SomeArgs args = (SomeArgs) msg.obj;
903 Log.continueSession((Session) args.arg4, SESSION_HANDLER + SESSION_CREATE_CONN);
904 try {
905 final PhoneAccountHandle connectionManagerPhoneAccount =
906 (PhoneAccountHandle) args.arg1;
907 final String id = (String) args.arg2;
908 final ConnectionRequest request = (ConnectionRequest) args.arg3;
909 final boolean isIncoming = args.argi1 == 1;
910 final boolean isUnknown = args.argi2 == 1;
911 if (!mAreAccountsInitialized) {
912 Log.d(this, "Enqueueing pre-initconference request %s", id);
913 mPreInitializationConnectionRequests.add(
914 new android.telecom.Logging.Runnable(
915 SESSION_HANDLER + SESSION_CREATE_CONF + ".pIConfR",
916 null /*lock*/) {
917 @Override
918 public void loggedRun() {
919 createConference(connectionManagerPhoneAccount,
920 id,
921 request,
922 isIncoming,
923 isUnknown);
924 }
925 }.prepare());
926 } else {
927 createConference(connectionManagerPhoneAccount,
928 id,
929 request,
930 isIncoming,
931 isUnknown);
932 }
933 } finally {
934 args.recycle();
935 Log.endSession();
936 }
937 break;
938 }
939 case MSG_CREATE_CONFERENCE_COMPLETE: {
940 SomeArgs args = (SomeArgs) msg.obj;
941 Log.continueSession((Session) args.arg2,
942 SESSION_HANDLER + SESSION_CREATE_CONN_COMPLETE);
943 try {
944 final String id = (String) args.arg1;
945 if (!mAreAccountsInitialized) {
946 Log.d(this, "Enqueueing pre-init conference request %s", id);
947 mPreInitializationConnectionRequests.add(
948 new android.telecom.Logging.Runnable(
949 SESSION_HANDLER + SESSION_CREATE_CONF_COMPLETE
950 + ".pIConfR",
951 null /*lock*/) {
952 @Override
953 public void loggedRun() {
954 notifyCreateConferenceComplete(id);
955 }
956 }.prepare());
957 } else {
958 notifyCreateConferenceComplete(id);
959 }
960 } finally {
961 args.recycle();
962 Log.endSession();
963 }
964 break;
965 }
966 case MSG_CREATE_CONFERENCE_FAILED: {
967 SomeArgs args = (SomeArgs) msg.obj;
968 Log.continueSession((Session) args.arg3, SESSION_HANDLER +
969 SESSION_CREATE_CONN_FAILED);
970 try {
971 final String id = (String) args.arg1;
972 final ConnectionRequest request = (ConnectionRequest) args.arg2;
973 final boolean isIncoming = args.argi1 == 1;
974 final PhoneAccountHandle connectionMgrPhoneAccount =
975 (PhoneAccountHandle) args.arg4;
976 if (!mAreAccountsInitialized) {
977 Log.d(this, "Enqueueing pre-init conference request %s", id);
978 mPreInitializationConnectionRequests.add(
979 new android.telecom.Logging.Runnable(
980 SESSION_HANDLER + SESSION_CREATE_CONF_FAILED
981 + ".pIConfR",
982 null /*lock*/) {
983 @Override
984 public void loggedRun() {
985 createConferenceFailed(connectionMgrPhoneAccount, id,
986 request, isIncoming);
987 }
988 }.prepare());
989 } else {
990 Log.i(this, "createConferenceFailed %s", id);
991 createConferenceFailed(connectionMgrPhoneAccount, id, request,
992 isIncoming);
993 }
994 } finally {
995 args.recycle();
996 Log.endSession();
997 }
998 break;
999 }
1000
Sanket Padawe4cc8ed52017-12-04 16:22:20 -08001001 case MSG_HANDOVER_FAILED: {
1002 SomeArgs args = (SomeArgs) msg.obj;
1003 Log.continueSession((Session) args.arg3, SESSION_HANDLER +
1004 SESSION_HANDOVER_FAILED);
1005 try {
1006 final String id = (String) args.arg1;
1007 final ConnectionRequest request = (ConnectionRequest) args.arg2;
1008 final int reason = (int) args.arg4;
1009 if (!mAreAccountsInitialized) {
1010 Log.d(this, "Enqueueing pre-init request %s", id);
1011 mPreInitializationConnectionRequests.add(
1012 new android.telecom.Logging.Runnable(
1013 SESSION_HANDLER
1014 + SESSION_HANDOVER_FAILED + ".pICR",
1015 null /*lock*/) {
1016 @Override
1017 public void loggedRun() {
1018 handoverFailed(id, request, reason);
1019 }
1020 }.prepare());
1021 } else {
1022 Log.i(this, "createConnectionFailed %s", id);
1023 handoverFailed(id, request, reason);
1024 }
1025 } finally {
1026 args.recycle();
1027 Log.endSession();
1028 }
1029 break;
1030 }
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001031 case MSG_ABORT: {
1032 SomeArgs args = (SomeArgs) msg.obj;
1033 Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_ABORT);
1034 try {
1035 abort((String) args.arg1);
1036 } finally {
1037 args.recycle();
1038 Log.endSession();
1039 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001040 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001041 }
1042 case MSG_ANSWER: {
1043 SomeArgs args = (SomeArgs) msg.obj;
1044 Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_ANSWER);
1045 try {
1046 answer((String) args.arg1);
1047 } finally {
1048 args.recycle();
1049 Log.endSession();
1050 }
Tyler Gunnbe74de02014-08-29 14:51:48 -07001051 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001052 }
Tyler Gunnbe74de02014-08-29 14:51:48 -07001053 case MSG_ANSWER_VIDEO: {
Andrew Lee8da4c3c2014-07-16 10:11:42 -07001054 SomeArgs args = (SomeArgs) msg.obj;
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001055 Log.continueSession((Session) args.arg2,
1056 SESSION_HANDLER + SESSION_ANSWER_VIDEO);
Andrew Lee8da4c3c2014-07-16 10:11:42 -07001057 try {
1058 String callId = (String) args.arg1;
Evan Charltonbf11f982014-07-20 22:06:28 -07001059 int videoState = args.argi1;
Tyler Gunnbe74de02014-08-29 14:51:48 -07001060 answerVideo(callId, videoState);
Andrew Lee8da4c3c2014-07-16 10:11:42 -07001061 } finally {
1062 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001063 Log.endSession();
Andrew Lee8da4c3c2014-07-16 10:11:42 -07001064 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001065 break;
Andrew Lee8da4c3c2014-07-16 10:11:42 -07001066 }
Pooja Jaind34698d2017-12-28 14:15:31 +05301067 case MSG_DEFLECT: {
1068 SomeArgs args = (SomeArgs) msg.obj;
1069 Log.continueSession((Session) args.arg3, SESSION_HANDLER + SESSION_DEFLECT);
1070 try {
1071 deflect((String) args.arg1, (Uri) args.arg2);
1072 } finally {
1073 args.recycle();
1074 Log.endSession();
1075 }
1076 break;
1077 }
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001078 case MSG_REJECT: {
1079 SomeArgs args = (SomeArgs) msg.obj;
1080 Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_REJECT);
1081 try {
1082 reject((String) args.arg1);
1083 } finally {
1084 args.recycle();
1085 Log.endSession();
1086 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001087 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001088 }
Tyler Gunnfacfdee2020-01-23 13:10:37 -08001089 case MSG_REJECT_WITH_REASON: {
1090 SomeArgs args = (SomeArgs) msg.obj;
1091 Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_REJECT);
1092 try {
1093 reject((String) args.arg1, args.argi1);
1094 } finally {
1095 args.recycle();
1096 Log.endSession();
1097 }
1098 break;
1099 }
Bryce Lee81901682015-08-28 16:38:02 -07001100 case MSG_REJECT_WITH_MESSAGE: {
1101 SomeArgs args = (SomeArgs) msg.obj;
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001102 Log.continueSession((Session) args.arg3,
1103 SESSION_HANDLER + SESSION_REJECT_MESSAGE);
Bryce Lee81901682015-08-28 16:38:02 -07001104 try {
1105 reject((String) args.arg1, (String) args.arg2);
1106 } finally {
1107 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001108 Log.endSession();
Bryce Lee81901682015-08-28 16:38:02 -07001109 }
1110 break;
1111 }
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001112 case MSG_DISCONNECT: {
1113 SomeArgs args = (SomeArgs) msg.obj;
1114 Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_DISCONNECT);
1115 try {
1116 disconnect((String) args.arg1);
1117 } finally {
1118 args.recycle();
1119 Log.endSession();
1120 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001121 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001122 }
1123 case MSG_SILENCE: {
1124 SomeArgs args = (SomeArgs) msg.obj;
1125 Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_SILENCE);
1126 try {
1127 silence((String) args.arg1);
1128 } finally {
1129 args.recycle();
1130 Log.endSession();
1131 }
Bryce Leecac50772015-11-17 15:13:29 -08001132 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001133 }
1134 case MSG_HOLD: {
1135 SomeArgs args = (SomeArgs) msg.obj;
1136 Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_REJECT);
1137 try {
1138 hold((String) args.arg1);
1139 } finally {
1140 args.recycle();
1141 Log.endSession();
1142 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001143 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001144 }
1145 case MSG_UNHOLD: {
1146 SomeArgs args = (SomeArgs) msg.obj;
1147 Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_UNHOLD);
1148 try {
1149 unhold((String) args.arg1);
1150 } finally {
1151 args.recycle();
1152 Log.endSession();
1153 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001154 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001155 }
Yorke Lee4af59352015-05-13 14:14:54 -07001156 case MSG_ON_CALL_AUDIO_STATE_CHANGED: {
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001157 SomeArgs args = (SomeArgs) msg.obj;
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001158 Log.continueSession((Session) args.arg3,
1159 SESSION_HANDLER + SESSION_CALL_AUDIO_SC);
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001160 try {
1161 String callId = (String) args.arg1;
Yorke Lee4af59352015-05-13 14:14:54 -07001162 CallAudioState audioState = (CallAudioState) args.arg2;
1163 onCallAudioStateChanged(callId, new CallAudioState(audioState));
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001164 } finally {
1165 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001166 Log.endSession();
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001167 }
1168 break;
1169 }
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001170 case MSG_PLAY_DTMF_TONE: {
1171 SomeArgs args = (SomeArgs) msg.obj;
1172 try {
1173 Log.continueSession((Session) args.arg3,
1174 SESSION_HANDLER + SESSION_PLAY_DTMF);
1175 playDtmfTone((String) args.arg2, (char) args.arg1);
1176 } finally {
1177 args.recycle();
1178 Log.endSession();
1179 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001180 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001181 }
1182 case MSG_STOP_DTMF_TONE: {
1183 SomeArgs args = (SomeArgs) msg.obj;
1184 try {
1185 Log.continueSession((Session) args.arg2,
1186 SESSION_HANDLER + SESSION_STOP_DTMF);
1187 stopDtmfTone((String) args.arg1);
1188 } finally {
1189 args.recycle();
1190 Log.endSession();
1191 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001192 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001193 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001194 case MSG_CONFERENCE: {
1195 SomeArgs args = (SomeArgs) msg.obj;
1196 try {
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001197 Log.continueSession((Session) args.arg3,
1198 SESSION_HANDLER + SESSION_CONFERENCE);
Santos Cordon823fd3c2014-08-07 18:35:18 -07001199 String callId1 = (String) args.arg1;
1200 String callId2 = (String) args.arg2;
1201 conference(callId1, callId2);
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001202 } finally {
1203 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001204 Log.endSession();
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001205 }
1206 break;
1207 }
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001208 case MSG_SPLIT_FROM_CONFERENCE: {
1209 SomeArgs args = (SomeArgs) msg.obj;
1210 try {
1211 Log.continueSession((Session) args.arg2,
1212 SESSION_HANDLER + SESSION_SPLIT_CONFERENCE);
1213 splitFromConference((String) args.arg1);
1214 } finally {
1215 args.recycle();
1216 Log.endSession();
1217 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001218 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001219 }
1220 case MSG_MERGE_CONFERENCE: {
1221 SomeArgs args = (SomeArgs) msg.obj;
1222 try {
1223 Log.continueSession((Session) args.arg2,
1224 SESSION_HANDLER + SESSION_MERGE_CONFERENCE);
1225 mergeConference((String) args.arg1);
1226 } finally {
1227 args.recycle();
1228 Log.endSession();
1229 }
Santos Cordona4868042014-09-04 17:39:22 -07001230 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001231 }
1232 case MSG_SWAP_CONFERENCE: {
1233 SomeArgs args = (SomeArgs) msg.obj;
1234 try {
1235 Log.continueSession((Session) args.arg2,
1236 SESSION_HANDLER + SESSION_SWAP_CONFERENCE);
1237 swapConference((String) args.arg1);
1238 } finally {
1239 args.recycle();
1240 Log.endSession();
1241 }
Santos Cordona4868042014-09-04 17:39:22 -07001242 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001243 }
Ravi Paluri404babb2020-01-23 19:02:44 +05301244 case MSG_ADD_PARTICIPANT: {
1245 SomeArgs args = (SomeArgs) msg.obj;
1246 try {
1247 Log.continueSession((Session) args.arg3,
1248 SESSION_HANDLER + SESSION_ADD_PARTICIPANT);
1249 addConferenceParticipants((String) args.arg1, (List<Uri>)args.arg2);
1250 } finally {
1251 args.recycle();
1252 Log.endSession();
1253 }
1254 break;
1255 }
1256
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001257 case MSG_ON_POST_DIAL_CONTINUE: {
1258 SomeArgs args = (SomeArgs) msg.obj;
1259 try {
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001260 Log.continueSession((Session) args.arg2,
1261 SESSION_HANDLER + SESSION_POST_DIAL_CONT);
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001262 String callId = (String) args.arg1;
1263 boolean proceed = (args.argi1 == 1);
1264 onPostDialContinue(callId, proceed);
1265 } finally {
1266 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001267 Log.endSession();
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001268 }
1269 break;
1270 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001271 case MSG_PULL_EXTERNAL_CALL: {
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001272 SomeArgs args = (SomeArgs) msg.obj;
1273 try {
1274 Log.continueSession((Session) args.arg2,
1275 SESSION_HANDLER + SESSION_PULL_EXTERNAL_CALL);
1276 pullExternalCall((String) args.arg1);
1277 } finally {
1278 args.recycle();
1279 Log.endSession();
1280 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001281 break;
1282 }
1283 case MSG_SEND_CALL_EVENT: {
1284 SomeArgs args = (SomeArgs) msg.obj;
1285 try {
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001286 Log.continueSession((Session) args.arg4,
1287 SESSION_HANDLER + SESSION_SEND_CALL_EVENT);
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001288 String callId = (String) args.arg1;
1289 String event = (String) args.arg2;
1290 Bundle extras = (Bundle) args.arg3;
1291 sendCallEvent(callId, event, extras);
1292 } finally {
1293 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001294 Log.endSession();
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001295 }
1296 break;
1297 }
Tyler Gunn79bc1ec2018-01-22 15:17:54 -08001298 case MSG_HANDOVER_COMPLETE: {
1299 SomeArgs args = (SomeArgs) msg.obj;
1300 try {
1301 Log.continueSession((Session) args.arg2,
1302 SESSION_HANDLER + SESSION_HANDOVER_COMPLETE);
1303 String callId = (String) args.arg1;
1304 notifyHandoverComplete(callId);
1305 } finally {
1306 args.recycle();
1307 Log.endSession();
1308 }
1309 break;
1310 }
Tyler Gunndee56a82016-03-23 16:06:34 -07001311 case MSG_ON_EXTRAS_CHANGED: {
1312 SomeArgs args = (SomeArgs) msg.obj;
1313 try {
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001314 Log.continueSession((Session) args.arg3,
1315 SESSION_HANDLER + SESSION_EXTRAS_CHANGED);
Tyler Gunndee56a82016-03-23 16:06:34 -07001316 String callId = (String) args.arg1;
1317 Bundle extras = (Bundle) args.arg2;
1318 handleExtrasChanged(callId, extras);
1319 } finally {
1320 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001321 Log.endSession();
Tyler Gunndee56a82016-03-23 16:06:34 -07001322 }
1323 break;
1324 }
Hall Liub64ac4c2017-02-06 10:49:48 -08001325 case MSG_ON_START_RTT: {
1326 SomeArgs args = (SomeArgs) msg.obj;
1327 try {
1328 Log.continueSession((Session) args.arg3,
1329 SESSION_HANDLER + SESSION_START_RTT);
1330 String callId = (String) args.arg1;
1331 Connection.RttTextStream rttTextStream =
1332 (Connection.RttTextStream) args.arg2;
1333 startRtt(callId, rttTextStream);
1334 } finally {
1335 args.recycle();
1336 Log.endSession();
1337 }
1338 break;
1339 }
1340 case MSG_ON_STOP_RTT: {
1341 SomeArgs args = (SomeArgs) msg.obj;
1342 try {
1343 Log.continueSession((Session) args.arg2,
1344 SESSION_HANDLER + SESSION_STOP_RTT);
1345 String callId = (String) args.arg1;
1346 stopRtt(callId);
1347 } finally {
1348 args.recycle();
1349 Log.endSession();
1350 }
1351 break;
1352 }
1353 case MSG_RTT_UPGRADE_RESPONSE: {
1354 SomeArgs args = (SomeArgs) msg.obj;
1355 try {
1356 Log.continueSession((Session) args.arg3,
1357 SESSION_HANDLER + SESSION_RTT_UPGRADE_RESPONSE);
1358 String callId = (String) args.arg1;
1359 Connection.RttTextStream rttTextStream =
1360 (Connection.RttTextStream) args.arg2;
1361 handleRttUpgradeResponse(callId, rttTextStream);
1362 } finally {
1363 args.recycle();
1364 Log.endSession();
1365 }
1366 break;
1367 }
Pengquan Meng731c1a32017-11-21 18:01:13 -08001368 case MSG_CONNECTION_SERVICE_FOCUS_GAINED:
1369 onConnectionServiceFocusGained();
1370 break;
1371 case MSG_CONNECTION_SERVICE_FOCUS_LOST:
1372 onConnectionServiceFocusLost();
1373 break;
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001374 default:
1375 break;
1376 }
1377 }
1378 };
1379
Santos Cordon823fd3c2014-08-07 18:35:18 -07001380 private final Conference.Listener mConferenceListener = new Conference.Listener() {
1381 @Override
1382 public void onStateChanged(Conference conference, int oldState, int newState) {
1383 String id = mIdByConference.get(conference);
1384 switch (newState) {
Ravi Paluri80aa2142019-12-02 11:57:37 +05301385 case Connection.STATE_RINGING:
1386 mAdapter.setRinging(id);
1387 break;
1388 case Connection.STATE_DIALING:
1389 mAdapter.setDialing(id);
1390 break;
Santos Cordon823fd3c2014-08-07 18:35:18 -07001391 case Connection.STATE_ACTIVE:
1392 mAdapter.setActive(id);
1393 break;
1394 case Connection.STATE_HOLDING:
1395 mAdapter.setOnHold(id);
1396 break;
1397 case Connection.STATE_DISCONNECTED:
1398 // handled by onDisconnected
1399 break;
1400 }
1401 }
1402
1403 @Override
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001404 public void onDisconnected(Conference conference, DisconnectCause disconnectCause) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07001405 String id = mIdByConference.get(conference);
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001406 mAdapter.setDisconnected(id, disconnectCause);
Santos Cordon823fd3c2014-08-07 18:35:18 -07001407 }
1408
1409 @Override
1410 public void onConnectionAdded(Conference conference, Connection connection) {
1411 }
1412
1413 @Override
1414 public void onConnectionRemoved(Conference conference, Connection connection) {
1415 }
1416
1417 @Override
Ihab Awad50e35062014-09-30 09:17:03 -07001418 public void onConferenceableConnectionsChanged(
1419 Conference conference, List<Connection> conferenceableConnections) {
1420 mAdapter.setConferenceableConnections(
1421 mIdByConference.get(conference),
1422 createConnectionIdList(conferenceableConnections));
1423 }
1424
1425 @Override
Santos Cordon823fd3c2014-08-07 18:35:18 -07001426 public void onDestroyed(Conference conference) {
1427 removeConference(conference);
1428 }
1429
1430 @Override
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001431 public void onConnectionCapabilitiesChanged(
1432 Conference conference,
1433 int connectionCapabilities) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07001434 String id = mIdByConference.get(conference);
1435 Log.d(this, "call capabilities: conference: %s",
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001436 Connection.capabilitiesToString(connectionCapabilities));
1437 mAdapter.setConnectionCapabilities(id, connectionCapabilities);
Santos Cordon823fd3c2014-08-07 18:35:18 -07001438 }
Rekha Kumar07366812015-03-24 16:42:31 -07001439
1440 @Override
Tyler Gunn720c6642016-03-22 09:02:47 -07001441 public void onConnectionPropertiesChanged(
1442 Conference conference,
1443 int connectionProperties) {
1444 String id = mIdByConference.get(conference);
1445 Log.d(this, "call capabilities: conference: %s",
1446 Connection.propertiesToString(connectionProperties));
1447 mAdapter.setConnectionProperties(id, connectionProperties);
1448 }
1449
1450 @Override
Rekha Kumar07366812015-03-24 16:42:31 -07001451 public void onVideoStateChanged(Conference c, int videoState) {
1452 String id = mIdByConference.get(c);
1453 Log.d(this, "onVideoStateChanged set video state %d", videoState);
1454 mAdapter.setVideoState(id, videoState);
1455 }
1456
1457 @Override
1458 public void onVideoProviderChanged(Conference c, Connection.VideoProvider videoProvider) {
1459 String id = mIdByConference.get(c);
1460 Log.d(this, "onVideoProviderChanged: Connection: %s, VideoProvider: %s", c,
1461 videoProvider);
1462 mAdapter.setVideoProvider(id, videoProvider);
1463 }
Andrew Lee0f51da32015-04-16 13:11:55 -07001464
1465 @Override
Andrew Leeedc625f2015-04-14 13:38:12 -07001466 public void onStatusHintsChanged(Conference conference, StatusHints statusHints) {
1467 String id = mIdByConference.get(conference);
Tyler Gunndee56a82016-03-23 16:06:34 -07001468 if (id != null) {
1469 mAdapter.setStatusHints(id, statusHints);
1470 }
Andrew Leeedc625f2015-04-14 13:38:12 -07001471 }
Santos Cordon6b7f9552015-05-27 17:21:45 -07001472
1473 @Override
Tyler Gunndee56a82016-03-23 16:06:34 -07001474 public void onExtrasChanged(Conference c, Bundle extras) {
1475 String id = mIdByConference.get(c);
1476 if (id != null) {
1477 mAdapter.putExtras(id, extras);
1478 }
1479 }
1480
1481 @Override
1482 public void onExtrasRemoved(Conference c, List<String> keys) {
1483 String id = mIdByConference.get(c);
1484 if (id != null) {
1485 mAdapter.removeExtras(id, keys);
1486 }
Santos Cordon6b7f9552015-05-27 17:21:45 -07001487 }
Tyler Gunn68a73a42018-10-03 15:38:57 -07001488
1489 @Override
1490 public void onConferenceStateChanged(Conference c, boolean isConference) {
1491 String id = mIdByConference.get(c);
1492 if (id != null) {
1493 mAdapter.setConferenceState(id, isConference);
1494 }
1495 }
1496
1497 @Override
1498 public void onAddressChanged(Conference c, Uri newAddress, int presentation) {
1499 String id = mIdByConference.get(c);
1500 if (id != null) {
1501 mAdapter.setAddress(id, newAddress, presentation);
1502 }
1503 }
1504
1505 @Override
1506 public void onCallerDisplayNameChanged(Conference c, String callerDisplayName,
1507 int presentation) {
1508 String id = mIdByConference.get(c);
1509 if (id != null) {
1510 mAdapter.setCallerDisplayName(id, callerDisplayName, presentation);
1511 }
1512 }
Hall Liuc9bc1c62019-04-16 14:00:55 -07001513
1514 @Override
1515 public void onConnectionEvent(Conference c, String event, Bundle extras) {
1516 String id = mIdByConference.get(c);
1517 if (id != null) {
1518 mAdapter.onConnectionEvent(id, event, extras);
1519 }
1520 }
Ravi Paluri80aa2142019-12-02 11:57:37 +05301521
1522 @Override
1523 public void onRingbackRequested(Conference c, boolean ringback) {
1524 String id = mIdByConference.get(c);
1525 Log.d(this, "Adapter conference onRingback %b", ringback);
1526 mAdapter.setRingbackRequested(id, ringback);
1527 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07001528 };
1529
Ihab Awad542e0ea2014-05-16 10:22:16 -07001530 private final Connection.Listener mConnectionListener = new Connection.Listener() {
1531 @Override
1532 public void onStateChanged(Connection c, int state) {
1533 String id = mIdByConnection.get(c);
Ihab Awad42b30e12014-05-22 09:49:34 -07001534 Log.d(this, "Adapter set state %s %s", id, Connection.stateToString(state));
Ihab Awad542e0ea2014-05-16 10:22:16 -07001535 switch (state) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001536 case Connection.STATE_ACTIVE:
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001537 mAdapter.setActive(id);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001538 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001539 case Connection.STATE_DIALING:
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001540 mAdapter.setDialing(id);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001541 break;
Tyler Gunnc96b5e02016-07-07 22:53:57 -07001542 case Connection.STATE_PULLING_CALL:
1543 mAdapter.setPulling(id);
1544 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001545 case Connection.STATE_DISCONNECTED:
Ihab Awad542e0ea2014-05-16 10:22:16 -07001546 // Handled in onDisconnected()
1547 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001548 case Connection.STATE_HOLDING:
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001549 mAdapter.setOnHold(id);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001550 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001551 case Connection.STATE_NEW:
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001552 // Nothing to tell Telecom
Ihab Awad542e0ea2014-05-16 10:22:16 -07001553 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001554 case Connection.STATE_RINGING:
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001555 mAdapter.setRinging(id);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001556 break;
1557 }
1558 }
1559
1560 @Override
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001561 public void onDisconnected(Connection c, DisconnectCause disconnectCause) {
Ihab Awad542e0ea2014-05-16 10:22:16 -07001562 String id = mIdByConnection.get(c);
Andrew Lee26786392014-09-16 18:14:59 -07001563 Log.d(this, "Adapter set disconnected %s", disconnectCause);
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001564 mAdapter.setDisconnected(id, disconnectCause);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001565 }
1566
1567 @Override
Tyler Gunnaa07df82014-07-17 07:50:22 -07001568 public void onVideoStateChanged(Connection c, int videoState) {
1569 String id = mIdByConnection.get(c);
1570 Log.d(this, "Adapter set video state %d", videoState);
1571 mAdapter.setVideoState(id, videoState);
1572 }
1573
1574 @Override
Andrew Lee100e2932014-09-08 15:34:24 -07001575 public void onAddressChanged(Connection c, Uri address, int presentation) {
Sailesh Nepal61203862014-07-11 14:50:13 -07001576 String id = mIdByConnection.get(c);
Andrew Lee100e2932014-09-08 15:34:24 -07001577 mAdapter.setAddress(id, address, presentation);
Sailesh Nepal61203862014-07-11 14:50:13 -07001578 }
1579
1580 @Override
1581 public void onCallerDisplayNameChanged(
1582 Connection c, String callerDisplayName, int presentation) {
1583 String id = mIdByConnection.get(c);
1584 mAdapter.setCallerDisplayName(id, callerDisplayName, presentation);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001585 }
1586
1587 @Override
Ihab Awad542e0ea2014-05-16 10:22:16 -07001588 public void onDestroyed(Connection c) {
1589 removeConnection(c);
1590 }
Ihab Awadf8358972014-05-28 16:46:42 -07001591
1592 @Override
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001593 public void onPostDialWait(Connection c, String remaining) {
Sailesh Nepal091768c2014-06-30 15:15:23 -07001594 String id = mIdByConnection.get(c);
1595 Log.d(this, "Adapter onPostDialWait %s, %s", c, remaining);
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001596 mAdapter.onPostDialWait(id, remaining);
Sailesh Nepal091768c2014-06-30 15:15:23 -07001597 }
1598
1599 @Override
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001600 public void onPostDialChar(Connection c, char nextChar) {
1601 String id = mIdByConnection.get(c);
1602 Log.d(this, "Adapter onPostDialChar %s, %s", c, nextChar);
1603 mAdapter.onPostDialChar(id, nextChar);
1604 }
1605
1606 @Override
Andrew Lee100e2932014-09-08 15:34:24 -07001607 public void onRingbackRequested(Connection c, boolean ringback) {
Ihab Awadf8358972014-05-28 16:46:42 -07001608 String id = mIdByConnection.get(c);
1609 Log.d(this, "Adapter onRingback %b", ringback);
Andrew Lee100e2932014-09-08 15:34:24 -07001610 mAdapter.setRingbackRequested(id, ringback);
Ihab Awadf8358972014-05-28 16:46:42 -07001611 }
Santos Cordonb6939982014-06-04 20:20:58 -07001612
1613 @Override
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001614 public void onConnectionCapabilitiesChanged(Connection c, int capabilities) {
Santos Cordonb6939982014-06-04 20:20:58 -07001615 String id = mIdByConnection.get(c);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001616 Log.d(this, "capabilities: parcelableconnection: %s",
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001617 Connection.capabilitiesToString(capabilities));
1618 mAdapter.setConnectionCapabilities(id, capabilities);
Santos Cordonb6939982014-06-04 20:20:58 -07001619 }
1620
Santos Cordonb6939982014-06-04 20:20:58 -07001621 @Override
Tyler Gunn720c6642016-03-22 09:02:47 -07001622 public void onConnectionPropertiesChanged(Connection c, int properties) {
1623 String id = mIdByConnection.get(c);
1624 Log.d(this, "properties: parcelableconnection: %s",
1625 Connection.propertiesToString(properties));
1626 mAdapter.setConnectionProperties(id, properties);
1627 }
1628
1629 @Override
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001630 public void onVideoProviderChanged(Connection c, Connection.VideoProvider videoProvider) {
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07001631 String id = mIdByConnection.get(c);
Rekha Kumar07366812015-03-24 16:42:31 -07001632 Log.d(this, "onVideoProviderChanged: Connection: %s, VideoProvider: %s", c,
1633 videoProvider);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001634 mAdapter.setVideoProvider(id, videoProvider);
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07001635 }
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001636
1637 @Override
Sailesh Nepal001bbbb2014-07-15 14:40:39 -07001638 public void onAudioModeIsVoipChanged(Connection c, boolean isVoip) {
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001639 String id = mIdByConnection.get(c);
Andrew Lee100e2932014-09-08 15:34:24 -07001640 mAdapter.setIsVoipAudioMode(id, isVoip);
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001641 }
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001642
1643 @Override
Sailesh Nepal001bbbb2014-07-15 14:40:39 -07001644 public void onStatusHintsChanged(Connection c, StatusHints statusHints) {
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001645 String id = mIdByConnection.get(c);
1646 mAdapter.setStatusHints(id, statusHints);
1647 }
Sailesh Nepal2ab88cc2014-07-18 14:49:18 -07001648
1649 @Override
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001650 public void onConferenceablesChanged(
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001651 Connection connection, List<Conferenceable> conferenceables) {
Ihab Awadb8e85c72014-08-23 20:34:57 -07001652 mAdapter.setConferenceableConnections(
1653 mIdByConnection.get(connection),
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001654 createIdList(conferenceables));
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001655 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07001656
1657 @Override
1658 public void onConferenceChanged(Connection connection, Conference conference) {
1659 String id = mIdByConnection.get(connection);
1660 if (id != null) {
1661 String conferenceId = null;
1662 if (conference != null) {
1663 conferenceId = mIdByConference.get(conference);
1664 }
1665 mAdapter.setIsConferenced(id, conferenceId);
1666 }
1667 }
Anthony Lee17455a32015-04-24 15:25:29 -07001668
1669 @Override
1670 public void onConferenceMergeFailed(Connection connection) {
1671 String id = mIdByConnection.get(connection);
1672 if (id != null) {
1673 mAdapter.onConferenceMergeFailed(id);
1674 }
1675 }
Santos Cordon6b7f9552015-05-27 17:21:45 -07001676
1677 @Override
Tyler Gunndee56a82016-03-23 16:06:34 -07001678 public void onExtrasChanged(Connection c, Bundle extras) {
1679 String id = mIdByConnection.get(c);
Santos Cordon6b7f9552015-05-27 17:21:45 -07001680 if (id != null) {
Tyler Gunndee56a82016-03-23 16:06:34 -07001681 mAdapter.putExtras(id, extras);
Santos Cordon6b7f9552015-05-27 17:21:45 -07001682 }
1683 }
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001684
Tyler Gunnf5035432017-01-09 09:43:12 -08001685 @Override
Tyler Gunndee56a82016-03-23 16:06:34 -07001686 public void onExtrasRemoved(Connection c, List<String> keys) {
1687 String id = mIdByConnection.get(c);
1688 if (id != null) {
1689 mAdapter.removeExtras(id, keys);
1690 }
1691 }
1692
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08001693 @Override
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001694 public void onConnectionEvent(Connection connection, String event, Bundle extras) {
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08001695 String id = mIdByConnection.get(connection);
1696 if (id != null) {
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001697 mAdapter.onConnectionEvent(id, event, extras);
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08001698 }
1699 }
Tyler Gunnf5035432017-01-09 09:43:12 -08001700
1701 @Override
Hall Liua98f58b52017-11-07 17:59:28 -08001702 public void onAudioRouteChanged(Connection c, int audioRoute, String bluetoothAddress) {
Tyler Gunnf5035432017-01-09 09:43:12 -08001703 String id = mIdByConnection.get(c);
1704 if (id != null) {
Hall Liua98f58b52017-11-07 17:59:28 -08001705 mAdapter.setAudioRoute(id, audioRoute, bluetoothAddress);
Tyler Gunnf5035432017-01-09 09:43:12 -08001706 }
1707 }
Hall Liub64ac4c2017-02-06 10:49:48 -08001708
1709 @Override
1710 public void onRttInitiationSuccess(Connection c) {
1711 String id = mIdByConnection.get(c);
1712 if (id != null) {
1713 mAdapter.onRttInitiationSuccess(id);
1714 }
1715 }
1716
1717 @Override
1718 public void onRttInitiationFailure(Connection c, int reason) {
1719 String id = mIdByConnection.get(c);
1720 if (id != null) {
1721 mAdapter.onRttInitiationFailure(id, reason);
1722 }
1723 }
1724
1725 @Override
1726 public void onRttSessionRemotelyTerminated(Connection c) {
1727 String id = mIdByConnection.get(c);
1728 if (id != null) {
1729 mAdapter.onRttSessionRemotelyTerminated(id);
1730 }
1731 }
1732
1733 @Override
1734 public void onRemoteRttRequest(Connection c) {
1735 String id = mIdByConnection.get(c);
1736 if (id != null) {
1737 mAdapter.onRemoteRttRequest(id);
1738 }
1739 }
Srikanth Chintalafcb15012017-05-04 20:58:34 +05301740
1741 @Override
1742 public void onPhoneAccountChanged(Connection c, PhoneAccountHandle pHandle) {
1743 String id = mIdByConnection.get(c);
1744 if (id != null) {
1745 mAdapter.onPhoneAccountChanged(id, pHandle);
1746 }
1747 }
Mengjun Leng25707742017-07-04 11:10:37 +08001748
1749 public void onConnectionTimeReset(Connection c) {
1750 String id = mIdByConnection.get(c);
1751 if (id != null) {
1752 mAdapter.resetConnectionTime(id);
1753 }
1754 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001755 };
1756
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001757 /** {@inheritDoc} */
Ihab Awad542e0ea2014-05-16 10:22:16 -07001758 @Override
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001759 public final IBinder onBind(Intent intent) {
1760 return mBinder;
1761 }
1762
Santos Cordon29f2f2e2014-09-11 19:50:24 -07001763 /** {@inheritDoc} */
1764 @Override
1765 public boolean onUnbind(Intent intent) {
1766 endAllConnections();
1767 return super.onUnbind(intent);
1768 }
1769
Ravi Paluri80aa2142019-12-02 11:57:37 +05301770
1771 /**
1772 * This can be used by telecom to either create a new outgoing conference call or attach
1773 * to an existing incoming conference call. In either case, telecom will cycle through a
1774 * set of services and call createConference until a connection service cancels the process
1775 * or completes it successfully.
1776 */
1777 private void createConference(
1778 final PhoneAccountHandle callManagerAccount,
1779 final String callId,
1780 final ConnectionRequest request,
1781 boolean isIncoming,
1782 boolean isUnknown) {
1783
1784 Conference conference = null;
1785 conference = isIncoming ? onCreateIncomingConference(callManagerAccount, request)
1786 : onCreateOutgoingConference(callManagerAccount, request);
1787
1788 Log.d(this, "createConference, conference: %s", conference);
1789 if (conference == null) {
1790 Log.i(this, "createConference, implementation returned null conference.");
1791 conference = Conference.createFailedConference(
1792 new DisconnectCause(DisconnectCause.ERROR, "IMPL_RETURNED_NULL_CONFERENCE"),
1793 request.getAccountHandle());
1794 }
1795 if (conference.getExtras() != null) {
1796 conference.getExtras().putString(Connection.EXTRA_ORIGINAL_CONNECTION_ID, callId);
1797 }
1798 mConferenceById.put(callId, conference);
1799 mIdByConference.put(conference, callId);
1800 conference.addListener(mConferenceListener);
1801 ParcelableConference parcelableConference = new ParcelableConference(
1802 request.getAccountHandle(),
1803 conference.getState(),
1804 conference.getConnectionCapabilities(),
1805 conference.getConnectionProperties(),
1806 Collections.<String>emptyList(), //connectionIds
1807 conference.getVideoProvider() == null ?
1808 null : conference.getVideoProvider().getInterface(),
1809 conference.getVideoState(),
1810 conference.getConnectTimeMillis(),
1811 conference.getConnectionStartElapsedRealTime(),
1812 conference.getStatusHints(),
1813 conference.getExtras(),
1814 conference.getAddress(),
1815 conference.getAddressPresentation(),
1816 conference.getCallerDisplayName(),
1817 conference.getCallerDisplayNamePresentation(),
1818 conference.getDisconnectCause(),
1819 conference.isRingbackRequested());
1820 if (conference.getState() != Connection.STATE_DISCONNECTED) {
1821 conference.setTelecomCallId(callId);
1822 mAdapter.setVideoProvider(callId, conference.getVideoProvider());
1823 mAdapter.setVideoState(callId, conference.getVideoState());
1824 onConferenceAdded(conference);
1825 }
1826
1827 Log.d(this, "createConference, calling handleCreateConferenceSuccessful %s", callId);
1828 mAdapter.handleCreateConferenceComplete(
1829 callId,
1830 request,
1831 parcelableConference);
1832 }
1833
Sailesh Nepalc5b01572014-07-14 16:29:44 -07001834 /**
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001835 * This can be used by telecom to either create a new outgoing call or attach to an existing
1836 * incoming call. In either case, telecom will cycle through a set of services and call
Sailesh Nepalc5b01572014-07-14 16:29:44 -07001837 * createConnection util a connection service cancels the process or completes it successfully.
1838 */
Ihab Awadf8b69882014-07-25 15:14:01 -07001839 private void createConnection(
1840 final PhoneAccountHandle callManagerAccount,
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001841 final String callId,
Ihab Awadf8b69882014-07-25 15:14:01 -07001842 final ConnectionRequest request,
Yorke Leec3cf9822014-10-02 09:38:39 -07001843 boolean isIncoming,
1844 boolean isUnknown) {
Tyler Gunn79bc1ec2018-01-22 15:17:54 -08001845 boolean isLegacyHandover = request.getExtras() != null &&
1846 request.getExtras().getBoolean(TelecomManager.EXTRA_IS_HANDOVER, false);
1847 boolean isHandover = request.getExtras() != null && request.getExtras().getBoolean(
1848 TelecomManager.EXTRA_IS_HANDOVER_CONNECTION, false);
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001849 Log.d(this, "createConnection, callManagerAccount: %s, callId: %s, request: %s, " +
Tyler Gunn79bc1ec2018-01-22 15:17:54 -08001850 "isIncoming: %b, isUnknown: %b, isLegacyHandover: %b, isHandover: %b",
1851 callManagerAccount, callId, request, isIncoming, isUnknown, isLegacyHandover,
1852 isHandover);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001853
Sanket Padawee29a2662017-12-01 13:59:27 -08001854 Connection connection = null;
Tyler Gunn79bc1ec2018-01-22 15:17:54 -08001855 if (isHandover) {
1856 PhoneAccountHandle fromPhoneAccountHandle = request.getExtras() != null
1857 ? (PhoneAccountHandle) request.getExtras().getParcelable(
1858 TelecomManager.EXTRA_HANDOVER_FROM_PHONE_ACCOUNT) : null;
Sanket Padawee29a2662017-12-01 13:59:27 -08001859 if (!isIncoming) {
Tyler Gunn79bc1ec2018-01-22 15:17:54 -08001860 connection = onCreateOutgoingHandoverConnection(fromPhoneAccountHandle, request);
Sanket Padawee29a2662017-12-01 13:59:27 -08001861 } else {
Tyler Gunn79bc1ec2018-01-22 15:17:54 -08001862 connection = onCreateIncomingHandoverConnection(fromPhoneAccountHandle, request);
Sanket Padawee29a2662017-12-01 13:59:27 -08001863 }
1864 } else {
1865 connection = isUnknown ? onCreateUnknownConnection(callManagerAccount, request)
1866 : isIncoming ? onCreateIncomingConnection(callManagerAccount, request)
1867 : onCreateOutgoingConnection(callManagerAccount, request);
1868 }
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001869 Log.d(this, "createConnection, connection: %s", connection);
1870 if (connection == null) {
Tyler Gunnfba1a8e2017-12-19 15:23:59 -08001871 Log.i(this, "createConnection, implementation returned null connection.");
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001872 connection = Connection.createFailedConnection(
Tyler Gunnfba1a8e2017-12-19 15:23:59 -08001873 new DisconnectCause(DisconnectCause.ERROR, "IMPL_RETURNED_NULL_CONNECTION"));
Sailesh Nepalc5b01572014-07-14 16:29:44 -07001874 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001875
Tyler Gunnf2e08b42018-05-24 10:44:44 -07001876 boolean isSelfManaged =
1877 (connection.getConnectionProperties() & Connection.PROPERTY_SELF_MANAGED)
1878 == Connection.PROPERTY_SELF_MANAGED;
1879 // Self-managed Connections should always use voip audio mode; we default here so that the
1880 // local state within the ConnectionService matches the default we assume in Telecom.
1881 if (isSelfManaged) {
1882 connection.setAudioModeIsVoip(true);
1883 }
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001884 connection.setTelecomCallId(callId);
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001885 if (connection.getState() != Connection.STATE_DISCONNECTED) {
Pengquan Meng70c9885332017-10-02 18:09:03 -07001886 addConnection(request.getAccountHandle(), callId, connection);
Ihab Awad6107bab2014-08-18 09:23:25 -07001887 }
1888
Andrew Lee100e2932014-09-08 15:34:24 -07001889 Uri address = connection.getAddress();
1890 String number = address == null ? "null" : address.getSchemeSpecificPart();
Tyler Gunn720c6642016-03-22 09:02:47 -07001891 Log.v(this, "createConnection, number: %s, state: %s, capabilities: %s, properties: %s",
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001892 Connection.toLogSafePhoneNumber(number),
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001893 Connection.stateToString(connection.getState()),
Tyler Gunn720c6642016-03-22 09:02:47 -07001894 Connection.capabilitiesToString(connection.getConnectionCapabilities()),
1895 Connection.propertiesToString(connection.getConnectionProperties()));
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001896
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001897 Log.d(this, "createConnection, calling handleCreateConnectionSuccessful %s", callId);
Ihab Awad6107bab2014-08-18 09:23:25 -07001898 mAdapter.handleCreateConnectionComplete(
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001899 callId,
Evan Charltonbf11f982014-07-20 22:06:28 -07001900 request,
1901 new ParcelableConnection(
1902 request.getAccountHandle(),
1903 connection.getState(),
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001904 connection.getConnectionCapabilities(),
Tyler Gunn720c6642016-03-22 09:02:47 -07001905 connection.getConnectionProperties(),
Christine Hallstrom2830ce92016-11-30 16:06:42 -08001906 connection.getSupportedAudioRoutes(),
Andrew Lee100e2932014-09-08 15:34:24 -07001907 connection.getAddress(),
1908 connection.getAddressPresentation(),
Evan Charltonbf11f982014-07-20 22:06:28 -07001909 connection.getCallerDisplayName(),
1910 connection.getCallerDisplayNamePresentation(),
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001911 connection.getVideoProvider() == null ?
1912 null : connection.getVideoProvider().getInterface(),
Sailesh Nepal8b9d3ca2014-08-14 17:39:34 -07001913 connection.getVideoState(),
Andrew Lee100e2932014-09-08 15:34:24 -07001914 connection.isRingbackRequested(),
Sailesh Nepal8b9d3ca2014-08-14 17:39:34 -07001915 connection.getAudioModeIsVoip(),
Roshan Piuse927ec02015-07-15 15:47:21 -07001916 connection.getConnectTimeMillis(),
Tyler Gunn3fa819c2017-08-04 09:27:26 -07001917 connection.getConnectElapsedTimeMillis(),
Ihab Awad6107bab2014-08-18 09:23:25 -07001918 connection.getStatusHints(),
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001919 connection.getDisconnectCause(),
Santos Cordon6b7f9552015-05-27 17:21:45 -07001920 createIdList(connection.getConferenceables()),
Tyler Gunnd57d76c2019-09-24 14:53:23 -07001921 connection.getExtras(),
1922 connection.getCallerNumberVerificationStatus()));
Tyler Gunnf5035432017-01-09 09:43:12 -08001923
Tyler Gunnf2e08b42018-05-24 10:44:44 -07001924 if (isIncoming && request.shouldShowIncomingCallUi() && isSelfManaged) {
Tyler Gunnf5035432017-01-09 09:43:12 -08001925 // Tell ConnectionService to show its incoming call UX.
1926 connection.onShowIncomingCallUi();
1927 }
Shriram Ganesh6bf35ac2014-12-11 17:53:38 -08001928 if (isUnknown) {
1929 triggerConferenceRecalculate();
1930 }
Evan Charltonbf11f982014-07-20 22:06:28 -07001931 }
1932
Tyler Gunn159f35c2017-03-02 09:28:37 -08001933 private void createConnectionFailed(final PhoneAccountHandle callManagerAccount,
1934 final String callId, final ConnectionRequest request,
1935 boolean isIncoming) {
Tyler Gunn44e01912017-01-31 10:49:05 -08001936
1937 Log.i(this, "createConnectionFailed %s", callId);
1938 if (isIncoming) {
Tyler Gunn159f35c2017-03-02 09:28:37 -08001939 onCreateIncomingConnectionFailed(callManagerAccount, request);
Tyler Gunn44e01912017-01-31 10:49:05 -08001940 } else {
Tyler Gunn159f35c2017-03-02 09:28:37 -08001941 onCreateOutgoingConnectionFailed(callManagerAccount, request);
Tyler Gunn44e01912017-01-31 10:49:05 -08001942 }
1943 }
1944
Ravi Paluri80aa2142019-12-02 11:57:37 +05301945 private void createConferenceFailed(final PhoneAccountHandle callManagerAccount,
1946 final String callId, final ConnectionRequest request,
1947 boolean isIncoming) {
1948
1949 Log.i(this, "createConferenceFailed %s", callId);
1950 if (isIncoming) {
1951 onCreateIncomingConferenceFailed(callManagerAccount, request);
1952 } else {
1953 onCreateOutgoingConferenceFailed(callManagerAccount, request);
1954 }
1955 }
1956
Sanket Padawe4cc8ed52017-12-04 16:22:20 -08001957 private void handoverFailed(final String callId, final ConnectionRequest request,
1958 int reason) {
1959
1960 Log.i(this, "handoverFailed %s", callId);
1961 onHandoverFailed(request, reason);
1962 }
1963
Tyler Gunn041a1fe2017-05-12 10:04:49 -07001964 /**
1965 * Called by Telecom when the creation of a new Connection has completed and it is now added
1966 * to Telecom.
1967 * @param callId The ID of the connection.
1968 */
1969 private void notifyCreateConnectionComplete(final String callId) {
1970 Log.i(this, "notifyCreateConnectionComplete %s", callId);
Tyler Gunn0a88f2e2017-06-16 20:20:34 -07001971 if (callId == null) {
1972 // This could happen if the connection fails quickly and is removed from the
1973 // ConnectionService before Telecom sends the create connection complete callback.
1974 Log.w(this, "notifyCreateConnectionComplete: callId is null.");
1975 return;
1976 }
Tyler Gunn041a1fe2017-05-12 10:04:49 -07001977 onCreateConnectionComplete(findConnectionForAction(callId,
1978 "notifyCreateConnectionComplete"));
1979 }
1980
Ravi Paluri80aa2142019-12-02 11:57:37 +05301981 /**
1982 * Called by Telecom when the creation of a new Conference has completed and it is now added
1983 * to Telecom.
1984 * @param callId The ID of the connection.
1985 */
1986 private void notifyCreateConferenceComplete(final String callId) {
1987 Log.i(this, "notifyCreateConferenceComplete %s", callId);
1988 if (callId == null) {
1989 // This could happen if the conference fails quickly and is removed from the
1990 // ConnectionService before Telecom sends the create conference complete callback.
1991 Log.w(this, "notifyCreateConferenceComplete: callId is null.");
1992 return;
1993 }
1994 onCreateConferenceComplete(findConferenceForAction(callId,
1995 "notifyCreateConferenceComplete"));
1996 }
1997
1998
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001999 private void abort(String callId) {
Ihab Awad60ac30b2014-05-20 22:32:12 -07002000 Log.d(this, "abort %s", callId);
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002001 findConnectionForAction(callId, "abort").onAbort();
Ihab Awad542e0ea2014-05-16 10:22:16 -07002002 }
2003
Tyler Gunnbe74de02014-08-29 14:51:48 -07002004 private void answerVideo(String callId, int videoState) {
2005 Log.d(this, "answerVideo %s", callId);
Ravi Paluri80aa2142019-12-02 11:57:37 +05302006 if (mConnectionById.containsKey(callId)) {
2007 findConnectionForAction(callId, "answer").onAnswer(videoState);
2008 } else {
2009 findConferenceForAction(callId, "answer").onAnswer(videoState);
2010 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002011 }
2012
Tyler Gunnbe74de02014-08-29 14:51:48 -07002013 private void answer(String callId) {
2014 Log.d(this, "answer %s", callId);
Ravi Paluri80aa2142019-12-02 11:57:37 +05302015 if (mConnectionById.containsKey(callId)) {
2016 findConnectionForAction(callId, "answer").onAnswer();
2017 } else {
2018 findConferenceForAction(callId, "answer").onAnswer();
2019 }
Tyler Gunnbe74de02014-08-29 14:51:48 -07002020 }
2021
Pooja Jaind34698d2017-12-28 14:15:31 +05302022 private void deflect(String callId, Uri address) {
2023 Log.d(this, "deflect %s", callId);
2024 findConnectionForAction(callId, "deflect").onDeflect(address);
2025 }
2026
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002027 private void reject(String callId) {
Ihab Awad60ac30b2014-05-20 22:32:12 -07002028 Log.d(this, "reject %s", callId);
Ravi Paluri80aa2142019-12-02 11:57:37 +05302029 if (mConnectionById.containsKey(callId)) {
2030 findConnectionForAction(callId, "reject").onReject();
2031 } else {
2032 findConferenceForAction(callId, "reject").onReject();
2033 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002034 }
2035
Bryce Lee81901682015-08-28 16:38:02 -07002036 private void reject(String callId, String rejectWithMessage) {
2037 Log.d(this, "reject %s with message", callId);
2038 findConnectionForAction(callId, "reject").onReject(rejectWithMessage);
2039 }
2040
Tyler Gunnfacfdee2020-01-23 13:10:37 -08002041 private void reject(String callId, @android.telecom.Call.RejectReason int rejectReason) {
2042 Log.d(this, "reject %s with reason %d", callId, rejectReason);
2043 findConnectionForAction(callId, "reject").onReject(rejectReason);
2044 }
2045
Bryce Leecac50772015-11-17 15:13:29 -08002046 private void silence(String callId) {
2047 Log.d(this, "silence %s", callId);
2048 findConnectionForAction(callId, "silence").onSilence();
2049 }
2050
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002051 private void disconnect(String callId) {
Ihab Awad60ac30b2014-05-20 22:32:12 -07002052 Log.d(this, "disconnect %s", callId);
Santos Cordon0159ac02014-08-21 14:28:11 -07002053 if (mConnectionById.containsKey(callId)) {
2054 findConnectionForAction(callId, "disconnect").onDisconnect();
2055 } else {
2056 findConferenceForAction(callId, "disconnect").onDisconnect();
2057 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002058 }
2059
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002060 private void hold(String callId) {
Ihab Awad60ac30b2014-05-20 22:32:12 -07002061 Log.d(this, "hold %s", callId);
Santos Cordon0159ac02014-08-21 14:28:11 -07002062 if (mConnectionById.containsKey(callId)) {
2063 findConnectionForAction(callId, "hold").onHold();
2064 } else {
2065 findConferenceForAction(callId, "hold").onHold();
2066 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002067 }
2068
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002069 private void unhold(String callId) {
Ihab Awad60ac30b2014-05-20 22:32:12 -07002070 Log.d(this, "unhold %s", callId);
Santos Cordon0159ac02014-08-21 14:28:11 -07002071 if (mConnectionById.containsKey(callId)) {
2072 findConnectionForAction(callId, "unhold").onUnhold();
2073 } else {
2074 findConferenceForAction(callId, "unhold").onUnhold();
2075 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002076 }
2077
Yorke Lee4af59352015-05-13 14:14:54 -07002078 private void onCallAudioStateChanged(String callId, CallAudioState callAudioState) {
2079 Log.d(this, "onAudioStateChanged %s %s", callId, callAudioState);
Yorke Leea0d3ca92014-09-15 19:18:13 -07002080 if (mConnectionById.containsKey(callId)) {
Yorke Lee4af59352015-05-13 14:14:54 -07002081 findConnectionForAction(callId, "onCallAudioStateChanged").setCallAudioState(
2082 callAudioState);
Yorke Leea0d3ca92014-09-15 19:18:13 -07002083 } else {
Yorke Lee4af59352015-05-13 14:14:54 -07002084 findConferenceForAction(callId, "onCallAudioStateChanged").setCallAudioState(
2085 callAudioState);
Yorke Leea0d3ca92014-09-15 19:18:13 -07002086 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002087 }
2088
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002089 private void playDtmfTone(String callId, char digit) {
2090 Log.d(this, "playDtmfTone %s %c", callId, digit);
Yorke Leea0d3ca92014-09-15 19:18:13 -07002091 if (mConnectionById.containsKey(callId)) {
2092 findConnectionForAction(callId, "playDtmfTone").onPlayDtmfTone(digit);
2093 } else {
2094 findConferenceForAction(callId, "playDtmfTone").onPlayDtmfTone(digit);
2095 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002096 }
2097
2098 private void stopDtmfTone(String callId) {
2099 Log.d(this, "stopDtmfTone %s", callId);
Yorke Leea0d3ca92014-09-15 19:18:13 -07002100 if (mConnectionById.containsKey(callId)) {
2101 findConnectionForAction(callId, "stopDtmfTone").onStopDtmfTone();
2102 } else {
2103 findConferenceForAction(callId, "stopDtmfTone").onStopDtmfTone();
2104 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002105 }
2106
Santos Cordon823fd3c2014-08-07 18:35:18 -07002107 private void conference(String callId1, String callId2) {
2108 Log.d(this, "conference %s, %s", callId1, callId2);
Santos Cordon980acb92014-05-31 10:31:19 -07002109
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002110 // Attempt to get second connection or conference.
Santos Cordon823fd3c2014-08-07 18:35:18 -07002111 Connection connection2 = findConnectionForAction(callId2, "conference");
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002112 Conference conference2 = getNullConference();
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07002113 if (connection2 == getNullConnection()) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002114 conference2 = findConferenceForAction(callId2, "conference");
2115 if (conference2 == getNullConference()) {
2116 Log.w(this, "Connection2 or Conference2 missing in conference request %s.",
2117 callId2);
2118 return;
2119 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07002120 }
Santos Cordonb6939982014-06-04 20:20:58 -07002121
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002122 // Attempt to get first connection or conference and perform merge.
Ihab Awad50e35062014-09-30 09:17:03 -07002123 Connection connection1 = findConnectionForAction(callId1, "conference");
2124 if (connection1 == getNullConnection()) {
2125 Conference conference1 = findConferenceForAction(callId1, "addConnection");
2126 if (conference1 == getNullConference()) {
2127 Log.w(this,
2128 "Connection1 or Conference1 missing in conference request %s.",
2129 callId1);
2130 } else {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002131 // Call 1 is a conference.
2132 if (connection2 != getNullConnection()) {
2133 // Call 2 is a connection so merge via call 1 (conference).
2134 conference1.onMerge(connection2);
2135 } else {
2136 // Call 2 is ALSO a conference; this should never happen.
2137 Log.wtf(this, "There can only be one conference and an attempt was made to " +
2138 "merge two conferences.");
2139 return;
2140 }
Ihab Awad50e35062014-09-30 09:17:03 -07002141 }
2142 } else {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002143 // Call 1 is a connection.
2144 if (conference2 != getNullConference()) {
2145 // Call 2 is a conference, so merge via call 2.
2146 conference2.onMerge(connection1);
2147 } else {
2148 // Call 2 is a connection, so merge together.
2149 onConference(connection1, connection2);
2150 }
Ihab Awad50e35062014-09-30 09:17:03 -07002151 }
Santos Cordon980acb92014-05-31 10:31:19 -07002152 }
2153
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002154 private void splitFromConference(String callId) {
Santos Cordonb6939982014-06-04 20:20:58 -07002155 Log.d(this, "splitFromConference(%s)", callId);
Santos Cordon980acb92014-05-31 10:31:19 -07002156
2157 Connection connection = findConnectionForAction(callId, "splitFromConference");
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07002158 if (connection == getNullConnection()) {
Santos Cordon980acb92014-05-31 10:31:19 -07002159 Log.w(this, "Connection missing in conference request %s.", callId);
2160 return;
2161 }
2162
Santos Cordon0159ac02014-08-21 14:28:11 -07002163 Conference conference = connection.getConference();
2164 if (conference != null) {
2165 conference.onSeparate(connection);
2166 }
Santos Cordon980acb92014-05-31 10:31:19 -07002167 }
2168
Santos Cordona4868042014-09-04 17:39:22 -07002169 private void mergeConference(String callId) {
2170 Log.d(this, "mergeConference(%s)", callId);
2171 Conference conference = findConferenceForAction(callId, "mergeConference");
2172 if (conference != null) {
2173 conference.onMerge();
2174 }
2175 }
2176
2177 private void swapConference(String callId) {
2178 Log.d(this, "swapConference(%s)", callId);
2179 Conference conference = findConferenceForAction(callId, "swapConference");
2180 if (conference != null) {
2181 conference.onSwap();
2182 }
2183 }
2184
Ravi Paluri404babb2020-01-23 19:02:44 +05302185 private void addConferenceParticipants(String callId, List<Uri> participants) {
2186 Log.d(this, "addConferenceParticipants(%s)", callId);
2187 if (mConnectionById.containsKey(callId)) {
2188 findConnectionForAction(callId, "addConferenceParticipants")
2189 .onAddConferenceParticipants(participants);
2190 } else {
2191 findConferenceForAction(callId, "addConferenceParticipants")
2192 .onAddConferenceParticipants(participants);
2193 }
2194 }
2195
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002196 /**
2197 * Notifies a {@link Connection} of a request to pull an external call.
2198 *
2199 * See {@link Call#pullExternalCall()}.
2200 *
2201 * @param callId The ID of the call to pull.
2202 */
2203 private void pullExternalCall(String callId) {
2204 Log.d(this, "pullExternalCall(%s)", callId);
2205 Connection connection = findConnectionForAction(callId, "pullExternalCall");
2206 if (connection != null) {
2207 connection.onPullExternalCall();
2208 }
2209 }
2210
2211 /**
2212 * Notifies a {@link Connection} of a call event.
2213 *
2214 * See {@link Call#sendCallEvent(String, Bundle)}.
2215 *
2216 * @param callId The ID of the call receiving the event.
2217 * @param event The event.
2218 * @param extras Extras associated with the event.
2219 */
2220 private void sendCallEvent(String callId, String event, Bundle extras) {
2221 Log.d(this, "sendCallEvent(%s, %s)", callId, event);
2222 Connection connection = findConnectionForAction(callId, "sendCallEvent");
2223 if (connection != null) {
2224 connection.onCallEvent(event, extras);
2225 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002226 }
2227
Tyler Gunndee56a82016-03-23 16:06:34 -07002228 /**
Tyler Gunn79bc1ec2018-01-22 15:17:54 -08002229 * Notifies a {@link Connection} that a handover has completed.
2230 *
2231 * @param callId The ID of the call which completed handover.
2232 */
2233 private void notifyHandoverComplete(String callId) {
2234 Log.d(this, "notifyHandoverComplete(%s)", callId);
2235 Connection connection = findConnectionForAction(callId, "notifyHandoverComplete");
2236 if (connection != null) {
2237 connection.onHandoverComplete();
2238 }
2239 }
2240
2241 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07002242 * Notifies a {@link Connection} or {@link Conference} of a change to the extras from Telecom.
2243 * <p>
2244 * These extra changes can originate from Telecom itself, or from an {@link InCallService} via
2245 * the {@link android.telecom.Call#putExtra(String, boolean)},
2246 * {@link android.telecom.Call#putExtra(String, int)},
2247 * {@link android.telecom.Call#putExtra(String, String)},
2248 * {@link Call#removeExtras(List)}.
2249 *
2250 * @param callId The ID of the call receiving the event.
2251 * @param extras The new extras bundle.
2252 */
2253 private void handleExtrasChanged(String callId, Bundle extras) {
2254 Log.d(this, "handleExtrasChanged(%s, %s)", callId, extras);
2255 if (mConnectionById.containsKey(callId)) {
2256 findConnectionForAction(callId, "handleExtrasChanged").handleExtrasChanged(extras);
2257 } else if (mConferenceById.containsKey(callId)) {
2258 findConferenceForAction(callId, "handleExtrasChanged").handleExtrasChanged(extras);
2259 }
2260 }
2261
Hall Liub64ac4c2017-02-06 10:49:48 -08002262 private void startRtt(String callId, Connection.RttTextStream rttTextStream) {
2263 Log.d(this, "startRtt(%s)", callId);
2264 if (mConnectionById.containsKey(callId)) {
2265 findConnectionForAction(callId, "startRtt").onStartRtt(rttTextStream);
2266 } else if (mConferenceById.containsKey(callId)) {
2267 Log.w(this, "startRtt called on a conference.");
2268 }
2269 }
2270
2271 private void stopRtt(String callId) {
2272 Log.d(this, "stopRtt(%s)", callId);
2273 if (mConnectionById.containsKey(callId)) {
2274 findConnectionForAction(callId, "stopRtt").onStopRtt();
2275 } else if (mConferenceById.containsKey(callId)) {
2276 Log.w(this, "stopRtt called on a conference.");
2277 }
2278 }
2279
2280 private void handleRttUpgradeResponse(String callId, Connection.RttTextStream rttTextStream) {
2281 Log.d(this, "handleRttUpgradeResponse(%s, %s)", callId, rttTextStream == null);
2282 if (mConnectionById.containsKey(callId)) {
2283 findConnectionForAction(callId, "handleRttUpgradeResponse")
2284 .handleRttUpgradeResponse(rttTextStream);
2285 } else if (mConferenceById.containsKey(callId)) {
2286 Log.w(this, "handleRttUpgradeResponse called on a conference.");
2287 }
2288 }
2289
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002290 private void onPostDialContinue(String callId, boolean proceed) {
Evan Charlton6dea4ac2014-06-03 14:07:13 -07002291 Log.d(this, "onPostDialContinue(%s)", callId);
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002292 findConnectionForAction(callId, "stopDtmfTone").onPostDialContinue(proceed);
Evan Charlton6dea4ac2014-06-03 14:07:13 -07002293 }
2294
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002295 private void onAdapterAttached() {
Ihab Awad9c3f1882014-06-30 21:17:13 -07002296 if (mAreAccountsInitialized) {
Santos Cordon52d8a152014-06-17 19:08:45 -07002297 // No need to query again if we already did it.
2298 return;
2299 }
2300
Tyler Gunn4c69fb32019-05-17 10:49:16 -07002301 String callingPackage = getOpPackageName();
2302
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002303 mAdapter.queryRemoteConnectionServices(new RemoteServiceCallback.Stub() {
Santos Cordon52d8a152014-06-17 19:08:45 -07002304 @Override
2305 public void onResult(
2306 final List<ComponentName> componentNames,
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002307 final List<IBinder> services) {
Brad Ebinger0c3541b2016-11-01 14:11:38 -07002308 mHandler.post(new android.telecom.Logging.Runnable("oAA.qRCS.oR", null /*lock*/) {
Ihab Awad6107bab2014-08-18 09:23:25 -07002309 @Override
Brad Ebinger0c3541b2016-11-01 14:11:38 -07002310 public void loggedRun() {
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002311 for (int i = 0; i < componentNames.size() && i < services.size(); i++) {
Santos Cordon52d8a152014-06-17 19:08:45 -07002312 mRemoteConnectionManager.addConnectionService(
2313 componentNames.get(i),
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002314 IConnectionService.Stub.asInterface(services.get(i)));
Santos Cordon52d8a152014-06-17 19:08:45 -07002315 }
Ihab Awad5d0410f2014-07-30 10:07:40 -07002316 onAccountsInitialized();
Sailesh Nepalc5b01572014-07-14 16:29:44 -07002317 Log.d(this, "remote connection services found: " + services);
Santos Cordon52d8a152014-06-17 19:08:45 -07002318 }
Brad Ebinger0c3541b2016-11-01 14:11:38 -07002319 }.prepare());
Santos Cordon52d8a152014-06-17 19:08:45 -07002320 }
2321
2322 @Override
2323 public void onError() {
Brad Ebinger0c3541b2016-11-01 14:11:38 -07002324 mHandler.post(new android.telecom.Logging.Runnable("oAA.qRCS.oE", null /*lock*/) {
Ihab Awad6107bab2014-08-18 09:23:25 -07002325 @Override
Brad Ebinger0c3541b2016-11-01 14:11:38 -07002326 public void loggedRun() {
Ihab Awad9c3f1882014-06-30 21:17:13 -07002327 mAreAccountsInitialized = true;
Santos Cordon52d8a152014-06-17 19:08:45 -07002328 }
Brad Ebinger0c3541b2016-11-01 14:11:38 -07002329 }.prepare());
Santos Cordon52d8a152014-06-17 19:08:45 -07002330 }
Tyler Gunn4c69fb32019-05-17 10:49:16 -07002331 }, callingPackage);
Santos Cordon52d8a152014-06-17 19:08:45 -07002332 }
2333
Ihab Awadf8b69882014-07-25 15:14:01 -07002334 /**
2335 * Ask some other {@code ConnectionService} to create a {@code RemoteConnection} given an
Santos Cordona663f862014-10-29 13:49:58 -07002336 * incoming request. This is used by {@code ConnectionService}s that are registered with
2337 * {@link PhoneAccount#CAPABILITY_CONNECTION_MANAGER} and want to be able to manage
2338 * SIM-based incoming calls.
Ihab Awadf8b69882014-07-25 15:14:01 -07002339 *
2340 * @param connectionManagerPhoneAccount See description at
2341 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
2342 * @param request Details about the incoming call.
2343 * @return The {@code Connection} object to satisfy this call, or {@code null} to
2344 * not handle the call.
2345 */
2346 public final RemoteConnection createRemoteIncomingConnection(
2347 PhoneAccountHandle connectionManagerPhoneAccount,
2348 ConnectionRequest request) {
2349 return mRemoteConnectionManager.createRemoteConnection(
2350 connectionManagerPhoneAccount, request, true);
Santos Cordon52d8a152014-06-17 19:08:45 -07002351 }
2352
2353 /**
Ihab Awadf8b69882014-07-25 15:14:01 -07002354 * Ask some other {@code ConnectionService} to create a {@code RemoteConnection} given an
Santos Cordona663f862014-10-29 13:49:58 -07002355 * outgoing request. This is used by {@code ConnectionService}s that are registered with
2356 * {@link PhoneAccount#CAPABILITY_CONNECTION_MANAGER} and want to be able to use the
2357 * SIM-based {@code ConnectionService} to place its outgoing calls.
Ihab Awadf8b69882014-07-25 15:14:01 -07002358 *
2359 * @param connectionManagerPhoneAccount See description at
2360 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
Cuihtlauac ALVARADO0b3b2a52016-09-13 14:49:41 +02002361 * @param request Details about the outgoing call.
Ihab Awadf8b69882014-07-25 15:14:01 -07002362 * @return The {@code Connection} object to satisfy this call, or {@code null} to
2363 * not handle the call.
2364 */
2365 public final RemoteConnection createRemoteOutgoingConnection(
2366 PhoneAccountHandle connectionManagerPhoneAccount,
2367 ConnectionRequest request) {
2368 return mRemoteConnectionManager.createRemoteConnection(
2369 connectionManagerPhoneAccount, request, false);
2370 }
2371
2372 /**
Santos Cordona663f862014-10-29 13:49:58 -07002373 * Indicates to the relevant {@code RemoteConnectionService} that the specified
2374 * {@link RemoteConnection}s should be merged into a conference call.
2375 * <p>
2376 * If the conference request is successful, the method {@link #onRemoteConferenceAdded} will
2377 * be invoked.
2378 *
2379 * @param remoteConnection1 The first of the remote connections to conference.
2380 * @param remoteConnection2 The second of the remote connections to conference.
Ihab Awadb8e85c72014-08-23 20:34:57 -07002381 */
2382 public final void conferenceRemoteConnections(
Santos Cordona663f862014-10-29 13:49:58 -07002383 RemoteConnection remoteConnection1,
2384 RemoteConnection remoteConnection2) {
2385 mRemoteConnectionManager.conferenceRemoteConnections(remoteConnection1, remoteConnection2);
Ihab Awadb8e85c72014-08-23 20:34:57 -07002386 }
2387
2388 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07002389 * Adds a new conference call. When a conference call is created either as a result of an
2390 * explicit request via {@link #onConference} or otherwise, the connection service should supply
2391 * an instance of {@link Conference} by invoking this method. A conference call provided by this
2392 * method will persist until {@link Conference#destroy} is invoked on the conference instance.
2393 *
2394 * @param conference The new conference object.
2395 */
2396 public final void addConference(Conference conference) {
Rekha Kumar07366812015-03-24 16:42:31 -07002397 Log.d(this, "addConference: conference=%s", conference);
2398
Santos Cordon823fd3c2014-08-07 18:35:18 -07002399 String id = addConferenceInternal(conference);
2400 if (id != null) {
2401 List<String> connectionIds = new ArrayList<>(2);
2402 for (Connection connection : conference.getConnections()) {
2403 if (mIdByConnection.containsKey(connection)) {
2404 connectionIds.add(mIdByConnection.get(connection));
2405 }
2406 }
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002407 conference.setTelecomCallId(id);
Santos Cordon823fd3c2014-08-07 18:35:18 -07002408 ParcelableConference parcelableConference = new ParcelableConference(
Nancy Chenea38cca2014-09-05 16:38:49 -07002409 conference.getPhoneAccountHandle(),
Santos Cordon823fd3c2014-08-07 18:35:18 -07002410 conference.getState(),
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002411 conference.getConnectionCapabilities(),
Tyler Gunn720c6642016-03-22 09:02:47 -07002412 conference.getConnectionProperties(),
Tyler Gunncd5d33c2015-01-12 09:02:01 -08002413 connectionIds,
Rekha Kumar07366812015-03-24 16:42:31 -07002414 conference.getVideoProvider() == null ?
2415 null : conference.getVideoProvider().getInterface(),
2416 conference.getVideoState(),
Andrew Lee3e3e2f22015-04-16 13:48:43 -07002417 conference.getConnectTimeMillis(),
Tyler Gunn17541392018-02-01 08:58:38 -08002418 conference.getConnectionStartElapsedRealTime(),
Santos Cordon6b7f9552015-05-27 17:21:45 -07002419 conference.getStatusHints(),
Tyler Gunnac60f952019-05-31 07:23:16 -07002420 conference.getExtras(),
2421 conference.getAddress(),
2422 conference.getAddressPresentation(),
2423 conference.getCallerDisplayName(),
2424 conference.getCallerDisplayNamePresentation());
Andrew Lee0f51da32015-04-16 13:11:55 -07002425
Santos Cordon823fd3c2014-08-07 18:35:18 -07002426 mAdapter.addConferenceCall(id, parcelableConference);
Rekha Kumar07366812015-03-24 16:42:31 -07002427 mAdapter.setVideoProvider(id, conference.getVideoProvider());
2428 mAdapter.setVideoState(id, conference.getVideoState());
Santos Cordon823fd3c2014-08-07 18:35:18 -07002429
2430 // Go through any child calls and set the parent.
2431 for (Connection connection : conference.getConnections()) {
2432 String connectionId = mIdByConnection.get(connection);
2433 if (connectionId != null) {
2434 mAdapter.setIsConferenced(connectionId, id);
2435 }
2436 }
Pengquan Meng70c9885332017-10-02 18:09:03 -07002437 onConferenceAdded(conference);
Santos Cordon823fd3c2014-08-07 18:35:18 -07002438 }
2439 }
2440
2441 /**
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002442 * Adds a connection created by the {@link ConnectionService} and informs telecom of the new
2443 * connection.
2444 *
2445 * @param phoneAccountHandle The phone account handle for the connection.
2446 * @param connection The connection to add.
2447 */
2448 public final void addExistingConnection(PhoneAccountHandle phoneAccountHandle,
2449 Connection connection) {
Tyler Gunn78da7812017-05-09 14:34:57 -07002450 addExistingConnection(phoneAccountHandle, connection, null /* conference */);
2451 }
2452
2453 /**
Pengquan Meng731c1a32017-11-21 18:01:13 -08002454 * Call to inform Telecom that your {@link ConnectionService} has released call resources (e.g
2455 * microphone, camera).
2456 *
Pengquan Menge3bf7e22018-02-22 17:30:04 -08002457 * <p>
2458 * The {@link ConnectionService} will be disconnected when it failed to call this method within
2459 * 5 seconds after {@link #onConnectionServiceFocusLost()} is called.
2460 *
Pengquan Meng731c1a32017-11-21 18:01:13 -08002461 * @see ConnectionService#onConnectionServiceFocusLost()
2462 */
2463 public final void connectionServiceFocusReleased() {
2464 mAdapter.onConnectionServiceFocusReleased();
2465 }
2466
2467 /**
Tyler Gunn78da7812017-05-09 14:34:57 -07002468 * Adds a connection created by the {@link ConnectionService} and informs telecom of the new
Tyler Gunn5567d742019-10-31 13:04:37 -07002469 * connection, as well as adding that connection to the specified conference.
2470 * <p>
2471 * Note: This API is intended ONLY for use by the Telephony stack to provide an easy way to add
2472 * IMS conference participants to be added to a conference in a single step; this helps ensure
2473 * UI updates happen atomically, rather than adding the connection and then adding it to
2474 * the conference in another step.
Tyler Gunn78da7812017-05-09 14:34:57 -07002475 *
2476 * @param phoneAccountHandle The phone account handle for the connection.
2477 * @param connection The connection to add.
2478 * @param conference The parent conference of the new connection.
2479 * @hide
2480 */
Tyler Gunn5567d742019-10-31 13:04:37 -07002481 @SystemApi
2482 public final void addExistingConnection(@NonNull PhoneAccountHandle phoneAccountHandle,
2483 @NonNull Connection connection, @NonNull Conference conference) {
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002484
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002485 String id = addExistingConnectionInternal(phoneAccountHandle, connection);
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002486 if (id != null) {
2487 List<String> emptyList = new ArrayList<>(0);
Tyler Gunn78da7812017-05-09 14:34:57 -07002488 String conferenceId = null;
2489 if (conference != null) {
2490 conferenceId = mIdByConference.get(conference);
2491 }
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002492
2493 ParcelableConnection parcelableConnection = new ParcelableConnection(
2494 phoneAccountHandle,
2495 connection.getState(),
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002496 connection.getConnectionCapabilities(),
Tyler Gunn720c6642016-03-22 09:02:47 -07002497 connection.getConnectionProperties(),
Christine Hallstrom2830ce92016-11-30 16:06:42 -08002498 connection.getSupportedAudioRoutes(),
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002499 connection.getAddress(),
2500 connection.getAddressPresentation(),
2501 connection.getCallerDisplayName(),
2502 connection.getCallerDisplayNamePresentation(),
2503 connection.getVideoProvider() == null ?
2504 null : connection.getVideoProvider().getInterface(),
2505 connection.getVideoState(),
2506 connection.isRingbackRequested(),
2507 connection.getAudioModeIsVoip(),
Roshan Piuse927ec02015-07-15 15:47:21 -07002508 connection.getConnectTimeMillis(),
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002509 connection.getConnectElapsedTimeMillis(),
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002510 connection.getStatusHints(),
2511 connection.getDisconnectCause(),
Santos Cordon6b7f9552015-05-27 17:21:45 -07002512 emptyList,
Tyler Gunn78da7812017-05-09 14:34:57 -07002513 connection.getExtras(),
Tyler Gunn6986a632019-06-25 13:45:32 -07002514 conferenceId,
Tyler Gunnd57d76c2019-09-24 14:53:23 -07002515 connection.getCallDirection(),
2516 Connection.VERIFICATION_STATUS_NOT_VERIFIED);
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002517 mAdapter.addExistingConnection(id, parcelableConnection);
2518 }
2519 }
2520
2521 /**
Ihab Awadf8b69882014-07-25 15:14:01 -07002522 * Returns all the active {@code Connection}s for which this {@code ConnectionService}
2523 * has taken responsibility.
2524 *
2525 * @return A collection of {@code Connection}s created by this {@code ConnectionService}.
Santos Cordonb6939982014-06-04 20:20:58 -07002526 */
Sailesh Nepal091768c2014-06-30 15:15:23 -07002527 public final Collection<Connection> getAllConnections() {
Santos Cordonb6939982014-06-04 20:20:58 -07002528 return mConnectionById.values();
2529 }
2530
2531 /**
Santos Cordona6018b92016-02-16 14:23:12 -08002532 * Returns all the active {@code Conference}s for which this {@code ConnectionService}
2533 * has taken responsibility.
2534 *
2535 * @return A collection of {@code Conference}s created by this {@code ConnectionService}.
2536 */
2537 public final Collection<Conference> getAllConferences() {
2538 return mConferenceById.values();
2539 }
2540
2541 /**
Ihab Awadf8b69882014-07-25 15:14:01 -07002542 * Create a {@code Connection} given an incoming request. This is used to attach to existing
2543 * incoming calls.
Evan Charltonbf11f982014-07-20 22:06:28 -07002544 *
Ihab Awadf8b69882014-07-25 15:14:01 -07002545 * @param connectionManagerPhoneAccount See description at
2546 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
2547 * @param request Details about the incoming call.
2548 * @return The {@code Connection} object to satisfy this call, or {@code null} to
2549 * not handle the call.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002550 */
Ihab Awadf8b69882014-07-25 15:14:01 -07002551 public Connection onCreateIncomingConnection(
2552 PhoneAccountHandle connectionManagerPhoneAccount,
2553 ConnectionRequest request) {
2554 return null;
2555 }
Ravi Paluri80aa2142019-12-02 11:57:37 +05302556 /**
2557 * Create a {@code Connection} given an incoming request. This is used to attach to existing
2558 * incoming conference call.
2559 *
2560 * @param connectionManagerPhoneAccount See description at
2561 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
2562 * @param request Details about the incoming call.
2563 * @return The {@code Connection} object to satisfy this call, or {@code null} to
2564 * not handle the call.
2565 */
2566 public @Nullable Conference onCreateIncomingConference(
2567 @Nullable PhoneAccountHandle connectionManagerPhoneAccount,
2568 @Nullable ConnectionRequest request) {
2569 return null;
2570 }
Sailesh Nepalc5b01572014-07-14 16:29:44 -07002571
2572 /**
Tyler Gunn041a1fe2017-05-12 10:04:49 -07002573 * Called after the {@link Connection} returned by
2574 * {@link #onCreateIncomingConnection(PhoneAccountHandle, ConnectionRequest)}
2575 * or {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)} has been
2576 * added to the {@link ConnectionService} and sent to Telecom.
2577 *
2578 * @param connection the {@link Connection}.
2579 * @hide
2580 */
2581 public void onCreateConnectionComplete(Connection connection) {
2582 }
2583
2584 /**
Ravi Paluri80aa2142019-12-02 11:57:37 +05302585 * Called after the {@link Conference} returned by
2586 * {@link #onCreateIncomingConference(PhoneAccountHandle, ConnectionRequest)}
2587 * or {@link #onCreateOutgoingConference(PhoneAccountHandle, ConnectionRequest)} has been
2588 * added to the {@link ConnectionService} and sent to Telecom.
2589 *
2590 * @param conference the {@link Conference}.
2591 * @hide
2592 */
2593 public void onCreateConferenceComplete(Conference conference) {
2594 }
2595
2596
2597 /**
Tyler Gunnf5035432017-01-09 09:43:12 -08002598 * Called by Telecom to inform the {@link ConnectionService} that its request to create a new
2599 * incoming {@link Connection} was denied.
2600 * <p>
2601 * Used when a self-managed {@link ConnectionService} attempts to create a new incoming
2602 * {@link Connection}, but Telecom has determined that the call cannot be allowed at this time.
2603 * The {@link ConnectionService} is responsible for silently rejecting the new incoming
2604 * {@link Connection}.
2605 * <p>
2606 * See {@link TelecomManager#isIncomingCallPermitted(PhoneAccountHandle)} for more information.
2607 *
Tyler Gunn159f35c2017-03-02 09:28:37 -08002608 * @param connectionManagerPhoneAccount See description at
2609 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
Tyler Gunnf5035432017-01-09 09:43:12 -08002610 * @param request The incoming connection request.
2611 */
Tyler Gunn159f35c2017-03-02 09:28:37 -08002612 public void onCreateIncomingConnectionFailed(PhoneAccountHandle connectionManagerPhoneAccount,
2613 ConnectionRequest request) {
Tyler Gunnf5035432017-01-09 09:43:12 -08002614 }
2615
2616 /**
2617 * Called by Telecom to inform the {@link ConnectionService} that its request to create a new
2618 * outgoing {@link Connection} was denied.
2619 * <p>
2620 * Used when a self-managed {@link ConnectionService} attempts to create a new outgoing
2621 * {@link Connection}, but Telecom has determined that the call cannot be placed at this time.
2622 * The {@link ConnectionService} is responisible for informing the user that the
2623 * {@link Connection} cannot be made at this time.
2624 * <p>
2625 * See {@link TelecomManager#isOutgoingCallPermitted(PhoneAccountHandle)} for more information.
2626 *
Tyler Gunn159f35c2017-03-02 09:28:37 -08002627 * @param connectionManagerPhoneAccount See description at
2628 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
Tyler Gunnf5035432017-01-09 09:43:12 -08002629 * @param request The outgoing connection request.
2630 */
Tyler Gunn159f35c2017-03-02 09:28:37 -08002631 public void onCreateOutgoingConnectionFailed(PhoneAccountHandle connectionManagerPhoneAccount,
2632 ConnectionRequest request) {
Tyler Gunnf5035432017-01-09 09:43:12 -08002633 }
2634
2635 /**
Ravi Paluri80aa2142019-12-02 11:57:37 +05302636 * Called by Telecom to inform the {@link ConnectionService} that its request to create a new
2637 * incoming {@link Conference} was denied.
2638 * <p>
2639 * Used when a self-managed {@link ConnectionService} attempts to create a new incoming
2640 * {@link Conference}, but Telecom has determined that the call cannot be allowed at this time.
2641 * The {@link ConnectionService} is responsible for silently rejecting the new incoming
2642 * {@link Conference}.
2643 * <p>
2644 * See {@link TelecomManager#isIncomingCallPermitted(PhoneAccountHandle)} for more information.
2645 *
2646 * @param connectionManagerPhoneAccount See description at
2647 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
2648 * @param request The incoming connection request.
2649 */
2650 public void onCreateIncomingConferenceFailed(
2651 @Nullable PhoneAccountHandle connectionManagerPhoneAccount,
2652 @Nullable ConnectionRequest request) {
2653 }
2654
2655 /**
2656 * Called by Telecom to inform the {@link ConnectionService} that its request to create a new
2657 * outgoing {@link Conference} was denied.
2658 * <p>
2659 * Used when a self-managed {@link ConnectionService} attempts to create a new outgoing
2660 * {@link Conference}, but Telecom has determined that the call cannot be placed at this time.
2661 * The {@link ConnectionService} is responisible for informing the user that the
2662 * {@link Conference} cannot be made at this time.
2663 * <p>
2664 * See {@link TelecomManager#isOutgoingCallPermitted(PhoneAccountHandle)} for more information.
2665 *
2666 * @param connectionManagerPhoneAccount See description at
2667 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
2668 * @param request The outgoing connection request.
2669 */
2670 public void onCreateOutgoingConferenceFailed(
2671 @Nullable PhoneAccountHandle connectionManagerPhoneAccount,
2672 @Nullable ConnectionRequest request) {
2673 }
2674
2675
2676 /**
Shriram Ganesh6bf35ac2014-12-11 17:53:38 -08002677 * Trigger recalculate functinality for conference calls. This is used when a Telephony
2678 * Connection is part of a conference controller but is not yet added to Connection
2679 * Service and hence cannot be added to the conference call.
2680 *
2681 * @hide
2682 */
2683 public void triggerConferenceRecalculate() {
2684 }
2685
2686 /**
Ihab Awadf8b69882014-07-25 15:14:01 -07002687 * Create a {@code Connection} given an outgoing request. This is used to initiate new
2688 * outgoing calls.
Sailesh Nepalc5b01572014-07-14 16:29:44 -07002689 *
Ihab Awadf8b69882014-07-25 15:14:01 -07002690 * @param connectionManagerPhoneAccount The connection manager account to use for managing
2691 * this call.
2692 * <p>
2693 * If this parameter is not {@code null}, it means that this {@code ConnectionService}
2694 * has registered one or more {@code PhoneAccount}s having
2695 * {@link PhoneAccount#CAPABILITY_CONNECTION_MANAGER}. This parameter will contain
2696 * one of these {@code PhoneAccount}s, while the {@code request} will contain another
2697 * (usually but not always distinct) {@code PhoneAccount} to be used for actually
2698 * making the connection.
2699 * <p>
2700 * If this parameter is {@code null}, it means that this {@code ConnectionService} is
2701 * being asked to make a direct connection. The
2702 * {@link ConnectionRequest#getAccountHandle()} of parameter {@code request} will be
2703 * a {@code PhoneAccount} registered by this {@code ConnectionService} to use for
2704 * making the connection.
2705 * @param request Details about the outgoing call.
2706 * @return The {@code Connection} object to satisfy this call, or the result of an invocation
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002707 * of {@link Connection#createFailedConnection(DisconnectCause)} to not handle the call.
Sailesh Nepalc5b01572014-07-14 16:29:44 -07002708 */
Ihab Awadf8b69882014-07-25 15:14:01 -07002709 public Connection onCreateOutgoingConnection(
2710 PhoneAccountHandle connectionManagerPhoneAccount,
2711 ConnectionRequest request) {
2712 return null;
2713 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002714
2715 /**
Ravi Paluri80aa2142019-12-02 11:57:37 +05302716 * Create a {@code Conference} given an outgoing request. This is used to initiate new
2717 * outgoing conference call.
2718 *
2719 * @param connectionManagerPhoneAccount The connection manager account to use for managing
2720 * this call.
2721 * <p>
2722 * If this parameter is not {@code null}, it means that this {@code ConnectionService}
2723 * has registered one or more {@code PhoneAccount}s having
2724 * {@link PhoneAccount#CAPABILITY_CONNECTION_MANAGER}. This parameter will contain
2725 * one of these {@code PhoneAccount}s, while the {@code request} will contain another
2726 * (usually but not always distinct) {@code PhoneAccount} to be used for actually
2727 * making the connection.
2728 * <p>
2729 * If this parameter is {@code null}, it means that this {@code ConnectionService} is
2730 * being asked to make a direct connection. The
2731 * {@link ConnectionRequest#getAccountHandle()} of parameter {@code request} will be
2732 * a {@code PhoneAccount} registered by this {@code ConnectionService} to use for
2733 * making the connection.
2734 * @param request Details about the outgoing call.
2735 * @return The {@code Conference} object to satisfy this call, or the result of an invocation
2736 * of {@link Connection#createFailedConnection(DisconnectCause)} to not handle the call.
2737 */
2738 public @Nullable Conference onCreateOutgoingConference(
2739 @Nullable PhoneAccountHandle connectionManagerPhoneAccount,
2740 @Nullable ConnectionRequest request) {
2741 return null;
2742 }
2743
2744
2745 /**
Tyler Gunn9d127732018-03-02 15:45:51 -08002746 * Called by Telecom to request that a {@link ConnectionService} creates an instance of an
2747 * outgoing handover {@link Connection}.
2748 * <p>
2749 * A call handover is the process where an ongoing call is transferred from one app (i.e.
2750 * {@link ConnectionService} to another app. The user could, for example, choose to continue a
2751 * mobile network call in a video calling app. The mobile network call via the Telephony stack
2752 * is referred to as the source of the handover, and the video calling app is referred to as the
2753 * destination.
2754 * <p>
2755 * When considering a handover scenario the <em>initiating</em> device is where a user initiated
2756 * the handover process (e.g. by calling {@link android.telecom.Call#handoverTo(
2757 * PhoneAccountHandle, int, Bundle)}, and the other device is considered the <em>receiving</em>
2758 * device.
2759 * <p>
2760 * This method is called on the destination {@link ConnectionService} on <em>initiating</em>
2761 * device when the user initiates a handover request from one app to another. The user request
2762 * originates in the {@link InCallService} via
2763 * {@link android.telecom.Call#handoverTo(PhoneAccountHandle, int, Bundle)}.
2764 * <p>
2765 * For a full discussion of the handover process and the APIs involved, see
2766 * {@link android.telecom.Call#handoverTo(PhoneAccountHandle, int, Bundle)}.
2767 * <p>
2768 * Implementations of this method should return an instance of {@link Connection} which
2769 * represents the handover. If your app does not wish to accept a handover to it at this time,
2770 * you can return {@code null}. The code below shows an example of how this is done.
2771 * <pre>
2772 * {@code
2773 * public Connection onCreateIncomingHandoverConnection(PhoneAccountHandle
2774 * fromPhoneAccountHandle, ConnectionRequest request) {
2775 * if (!isHandoverAvailable()) {
2776 * return null;
2777 * }
2778 * MyConnection connection = new MyConnection();
2779 * connection.setAddress(request.getAddress(), TelecomManager.PRESENTATION_ALLOWED);
2780 * connection.setVideoState(request.getVideoState());
2781 * return connection;
2782 * }
2783 * }
2784 * </pre>
2785 *
Sanket Padawea8eddd42017-11-03 11:07:35 -07002786 * @param fromPhoneAccountHandle {@link PhoneAccountHandle} associated with the
2787 * ConnectionService which needs to handover the call.
Tyler Gunn9d127732018-03-02 15:45:51 -08002788 * @param request Details about the call to handover.
2789 * @return {@link Connection} instance corresponding to the handover call.
Sanket Padawea8eddd42017-11-03 11:07:35 -07002790 */
2791 public Connection onCreateOutgoingHandoverConnection(PhoneAccountHandle fromPhoneAccountHandle,
2792 ConnectionRequest request) {
2793 return null;
2794 }
2795
2796 /**
Tyler Gunn9d127732018-03-02 15:45:51 -08002797 * Called by Telecom to request that a {@link ConnectionService} creates an instance of an
2798 * incoming handover {@link Connection}.
2799 * <p>
2800 * A call handover is the process where an ongoing call is transferred from one app (i.e.
2801 * {@link ConnectionService} to another app. The user could, for example, choose to continue a
2802 * mobile network call in a video calling app. The mobile network call via the Telephony stack
2803 * is referred to as the source of the handover, and the video calling app is referred to as the
2804 * destination.
2805 * <p>
2806 * When considering a handover scenario the <em>initiating</em> device is where a user initiated
2807 * the handover process (e.g. by calling {@link android.telecom.Call#handoverTo(
2808 * PhoneAccountHandle, int, Bundle)}, and the other device is considered the <em>receiving</em>
2809 * device.
2810 * <p>
2811 * This method is called on the destination app on the <em>receiving</em> device when the
2812 * destination app calls {@link TelecomManager#acceptHandover(Uri, int, PhoneAccountHandle)} to
2813 * accept an incoming handover from the <em>initiating</em> device.
2814 * <p>
2815 * For a full discussion of the handover process and the APIs involved, see
2816 * {@link android.telecom.Call#handoverTo(PhoneAccountHandle, int, Bundle)}.
2817 * <p>
2818 * Implementations of this method should return an instance of {@link Connection} which
2819 * represents the handover. The code below shows an example of how this is done.
2820 * <pre>
2821 * {@code
2822 * public Connection onCreateIncomingHandoverConnection(PhoneAccountHandle
2823 * fromPhoneAccountHandle, ConnectionRequest request) {
2824 * // Given that your app requested to accept the handover, you should not return null here.
2825 * MyConnection connection = new MyConnection();
2826 * connection.setAddress(request.getAddress(), TelecomManager.PRESENTATION_ALLOWED);
2827 * connection.setVideoState(request.getVideoState());
2828 * return connection;
2829 * }
2830 * }
2831 * </pre>
2832 *
Sanket Padawea8eddd42017-11-03 11:07:35 -07002833 * @param fromPhoneAccountHandle {@link PhoneAccountHandle} associated with the
2834 * ConnectionService which needs to handover the call.
2835 * @param request Details about the call which needs to be handover.
Tyler Gunn9d127732018-03-02 15:45:51 -08002836 * @return {@link Connection} instance corresponding to the handover call.
Sanket Padawea8eddd42017-11-03 11:07:35 -07002837 */
2838 public Connection onCreateIncomingHandoverConnection(PhoneAccountHandle fromPhoneAccountHandle,
2839 ConnectionRequest request) {
2840 return null;
2841 }
2842
2843 /**
2844 * Called by Telecom in response to a {@code TelecomManager#acceptHandover()}
2845 * invocation which failed.
Tyler Gunn9d127732018-03-02 15:45:51 -08002846 * <p>
2847 * For a full discussion of the handover process and the APIs involved, see
2848 * {@link android.telecom.Call#handoverTo(PhoneAccountHandle, int, Bundle)}
2849 *
2850 * @param request Details about the call which failed to handover.
2851 * @param error Reason for handover failure. Will be one of the
Sanket Padawea8eddd42017-11-03 11:07:35 -07002852 */
Tyler Gunn9d127732018-03-02 15:45:51 -08002853 public void onHandoverFailed(ConnectionRequest request,
2854 @Call.Callback.HandoverFailureErrors int error) {
Sanket Padawea8eddd42017-11-03 11:07:35 -07002855 return;
2856 }
2857
2858 /**
Yorke Leec3cf9822014-10-02 09:38:39 -07002859 * Create a {@code Connection} for a new unknown call. An unknown call is a call originating
2860 * from the ConnectionService that was neither a user-initiated outgoing call, nor an incoming
2861 * call created using
2862 * {@code TelecomManager#addNewIncomingCall(PhoneAccountHandle, android.os.Bundle)}.
2863 *
Yorke Lee770ed6e2014-10-06 18:58:52 -07002864 * @hide
Yorke Leec3cf9822014-10-02 09:38:39 -07002865 */
2866 public Connection onCreateUnknownConnection(PhoneAccountHandle connectionManagerPhoneAccount,
2867 ConnectionRequest request) {
Brad Ebingerb32d4f82016-10-24 16:40:49 -07002868 return null;
Yorke Leec3cf9822014-10-02 09:38:39 -07002869 }
2870
2871 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07002872 * Conference two specified connections. Invoked when the user has made a request to merge the
2873 * specified connections into a conference call. In response, the connection service should
2874 * create an instance of {@link Conference} and pass it into {@link #addConference}.
Santos Cordonb6939982014-06-04 20:20:58 -07002875 *
Santos Cordon823fd3c2014-08-07 18:35:18 -07002876 * @param connection1 A connection to merge into a conference call.
2877 * @param connection2 A connection to merge into a conference call.
Santos Cordonb6939982014-06-04 20:20:58 -07002878 */
Santos Cordon823fd3c2014-08-07 18:35:18 -07002879 public void onConference(Connection connection1, Connection connection2) {}
Santos Cordonb6939982014-06-04 20:20:58 -07002880
Santos Cordona663f862014-10-29 13:49:58 -07002881 /**
Pengquan Meng70c9885332017-10-02 18:09:03 -07002882 * Called when a connection is added.
2883 * @hide
2884 */
2885 public void onConnectionAdded(Connection connection) {}
2886
2887 /**
2888 * Called when a connection is removed.
2889 * @hide
2890 */
2891 public void onConnectionRemoved(Connection connection) {}
2892
2893 /**
2894 * Called when a conference is added.
2895 * @hide
2896 */
2897 public void onConferenceAdded(Conference conference) {}
2898
2899 /**
2900 * Called when a conference is removed.
2901 * @hide
2902 */
2903 public void onConferenceRemoved(Conference conference) {}
2904
2905 /**
Santos Cordona663f862014-10-29 13:49:58 -07002906 * Indicates that a remote conference has been created for existing {@link RemoteConnection}s.
2907 * When this method is invoked, this {@link ConnectionService} should create its own
2908 * representation of the conference call and send it to telecom using {@link #addConference}.
2909 * <p>
2910 * This is only relevant to {@link ConnectionService}s which are registered with
2911 * {@link PhoneAccount#CAPABILITY_CONNECTION_MANAGER}.
2912 *
2913 * @param conference The remote conference call.
2914 */
Ihab Awadb8e85c72014-08-23 20:34:57 -07002915 public void onRemoteConferenceAdded(RemoteConference conference) {}
2916
Santos Cordon823fd3c2014-08-07 18:35:18 -07002917 /**
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002918 * Called when an existing connection is added remotely.
2919 * @param connection The existing connection which was added.
2920 */
2921 public void onRemoteExistingConnectionAdded(RemoteConnection connection) {}
2922
2923 /**
Pengquan Meng731c1a32017-11-21 18:01:13 -08002924 * Called when the {@link ConnectionService} has lost the call focus.
2925 * The {@link ConnectionService} should release the call resources and invokes
2926 * {@link ConnectionService#connectionServiceFocusReleased()} to inform telecom that it has
2927 * released the call resources.
2928 */
2929 public void onConnectionServiceFocusLost() {}
2930
2931 /**
2932 * Called when the {@link ConnectionService} has gained the call focus. The
2933 * {@link ConnectionService} can acquire the call resources at this time.
2934 */
2935 public void onConnectionServiceFocusGained() {}
2936
2937 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07002938 * @hide
2939 */
2940 public boolean containsConference(Conference conference) {
2941 return mIdByConference.containsKey(conference);
2942 }
2943
Ihab Awadb8e85c72014-08-23 20:34:57 -07002944 /** {@hide} */
2945 void addRemoteConference(RemoteConference remoteConference) {
2946 onRemoteConferenceAdded(remoteConference);
2947 }
2948
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002949 /** {@hide} */
2950 void addRemoteExistingConnection(RemoteConnection remoteConnection) {
2951 onRemoteExistingConnectionAdded(remoteConnection);
2952 }
2953
Ihab Awad5d0410f2014-07-30 10:07:40 -07002954 private void onAccountsInitialized() {
2955 mAreAccountsInitialized = true;
2956 for (Runnable r : mPreInitializationConnectionRequests) {
2957 r.run();
2958 }
2959 mPreInitializationConnectionRequests.clear();
2960 }
2961
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002962 /**
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002963 * Adds an existing connection to the list of connections, identified by a new call ID unique
2964 * to this connection service.
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002965 *
2966 * @param connection The connection.
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002967 * @return The ID of the connection (e.g. the call-id).
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002968 */
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002969 private String addExistingConnectionInternal(PhoneAccountHandle handle, Connection connection) {
2970 String id;
Tyler Gunncd6ccfd2016-10-17 15:48:19 -07002971
2972 if (connection.getExtras() != null && connection.getExtras()
2973 .containsKey(Connection.EXTRA_ORIGINAL_CONNECTION_ID)) {
2974 id = connection.getExtras().getString(Connection.EXTRA_ORIGINAL_CONNECTION_ID);
2975 Log.d(this, "addExistingConnectionInternal - conn %s reusing original id %s",
2976 connection.getTelecomCallId(), id);
2977 } else if (handle == null) {
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002978 // If no phone account handle was provided, we cannot be sure the call ID is unique,
2979 // so just use a random UUID.
2980 id = UUID.randomUUID().toString();
2981 } else {
2982 // Phone account handle was provided, so use the ConnectionService class name as a
2983 // prefix for a unique incremental call ID.
2984 id = handle.getComponentName().getClassName() + "@" + getNextCallId();
2985 }
Pengquan Meng70c9885332017-10-02 18:09:03 -07002986 addConnection(handle, id, connection);
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002987 return id;
2988 }
2989
Pengquan Meng70c9885332017-10-02 18:09:03 -07002990 private void addConnection(PhoneAccountHandle handle, String callId, Connection connection) {
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002991 connection.setTelecomCallId(callId);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002992 mConnectionById.put(callId, connection);
2993 mIdByConnection.put(connection, callId);
2994 connection.addConnectionListener(mConnectionListener);
Santos Cordon823fd3c2014-08-07 18:35:18 -07002995 connection.setConnectionService(this);
Pengquan Meng70c9885332017-10-02 18:09:03 -07002996 connection.setPhoneAccountHandle(handle);
2997 onConnectionAdded(connection);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002998 }
2999
Anthony Lee30e65842014-11-06 16:30:53 -08003000 /** {@hide} */
3001 protected void removeConnection(Connection connection) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07003002 connection.unsetConnectionService(this);
Ihab Awad542e0ea2014-05-16 10:22:16 -07003003 connection.removeConnectionListener(mConnectionListener);
Chenjie Luoe370b532016-05-12 16:59:43 -07003004 String id = mIdByConnection.get(connection);
3005 if (id != null) {
3006 mConnectionById.remove(id);
3007 mIdByConnection.remove(connection);
3008 mAdapter.removeCall(id);
Pengquan Meng70c9885332017-10-02 18:09:03 -07003009 onConnectionRemoved(connection);
Chenjie Luoe370b532016-05-12 16:59:43 -07003010 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07003011 }
3012
Santos Cordon823fd3c2014-08-07 18:35:18 -07003013 private String addConferenceInternal(Conference conference) {
Tyler Gunncd6ccfd2016-10-17 15:48:19 -07003014 String originalId = null;
3015 if (conference.getExtras() != null && conference.getExtras()
3016 .containsKey(Connection.EXTRA_ORIGINAL_CONNECTION_ID)) {
3017 originalId = conference.getExtras().getString(Connection.EXTRA_ORIGINAL_CONNECTION_ID);
3018 Log.d(this, "addConferenceInternal: conf %s reusing original id %s",
3019 conference.getTelecomCallId(),
3020 originalId);
3021 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07003022 if (mIdByConference.containsKey(conference)) {
3023 Log.w(this, "Re-adding an existing conference: %s.", conference);
3024 } else if (conference != null) {
Tyler Gunnf0500bd2015-09-01 10:59:48 -07003025 // Conferences do not (yet) have a PhoneAccountHandle associated with them, so we
3026 // cannot determine a ConnectionService class name to associate with the ID, so use
3027 // a unique UUID (for now).
Tyler Gunncd6ccfd2016-10-17 15:48:19 -07003028 String id = originalId == null ? UUID.randomUUID().toString() : originalId;
Santos Cordon823fd3c2014-08-07 18:35:18 -07003029 mConferenceById.put(id, conference);
3030 mIdByConference.put(conference, id);
3031 conference.addListener(mConferenceListener);
3032 return id;
3033 }
3034
3035 return null;
3036 }
3037
3038 private void removeConference(Conference conference) {
3039 if (mIdByConference.containsKey(conference)) {
3040 conference.removeListener(mConferenceListener);
3041
3042 String id = mIdByConference.get(conference);
3043 mConferenceById.remove(id);
3044 mIdByConference.remove(conference);
3045 mAdapter.removeCall(id);
Pengquan Meng70c9885332017-10-02 18:09:03 -07003046
3047 onConferenceRemoved(conference);
Santos Cordon823fd3c2014-08-07 18:35:18 -07003048 }
3049 }
3050
Ihab Awad542e0ea2014-05-16 10:22:16 -07003051 private Connection findConnectionForAction(String callId, String action) {
Tyler Gunn0a88f2e2017-06-16 20:20:34 -07003052 if (callId != null && mConnectionById.containsKey(callId)) {
Ihab Awad542e0ea2014-05-16 10:22:16 -07003053 return mConnectionById.get(callId);
3054 }
Ihab Awad60ac30b2014-05-20 22:32:12 -07003055 Log.w(this, "%s - Cannot find Connection %s", action, callId);
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07003056 return getNullConnection();
3057 }
3058
3059 static synchronized Connection getNullConnection() {
3060 if (sNullConnection == null) {
3061 sNullConnection = new Connection() {};
3062 }
3063 return sNullConnection;
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003064 }
Santos Cordon0159ac02014-08-21 14:28:11 -07003065
3066 private Conference findConferenceForAction(String conferenceId, String action) {
3067 if (mConferenceById.containsKey(conferenceId)) {
3068 return mConferenceById.get(conferenceId);
3069 }
3070 Log.w(this, "%s - Cannot find conference %s", action, conferenceId);
3071 return getNullConference();
3072 }
3073
Ihab Awadb8e85c72014-08-23 20:34:57 -07003074 private List<String> createConnectionIdList(List<Connection> connections) {
3075 List<String> ids = new ArrayList<>();
3076 for (Connection c : connections) {
3077 if (mIdByConnection.containsKey(c)) {
3078 ids.add(mIdByConnection.get(c));
3079 }
3080 }
3081 Collections.sort(ids);
3082 return ids;
3083 }
3084
Tyler Gunn6d76ca02014-11-17 15:49:51 -08003085 /**
3086 * Builds a list of {@link Connection} and {@link Conference} IDs based on the list of
Tyler Gunndf2cbc82015-04-20 09:13:01 -07003087 * {@link Conferenceable}s passed in.
Tyler Gunn6d76ca02014-11-17 15:49:51 -08003088 *
Tyler Gunndf2cbc82015-04-20 09:13:01 -07003089 * @param conferenceables The {@link Conferenceable} connections and conferences.
Tyler Gunn6d76ca02014-11-17 15:49:51 -08003090 * @return List of string conference and call Ids.
3091 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07003092 private List<String> createIdList(List<Conferenceable> conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08003093 List<String> ids = new ArrayList<>();
Tyler Gunndf2cbc82015-04-20 09:13:01 -07003094 for (Conferenceable c : conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08003095 // Only allow Connection and Conference conferenceables.
3096 if (c instanceof Connection) {
3097 Connection connection = (Connection) c;
3098 if (mIdByConnection.containsKey(connection)) {
3099 ids.add(mIdByConnection.get(connection));
3100 }
3101 } else if (c instanceof Conference) {
3102 Conference conference = (Conference) c;
3103 if (mIdByConference.containsKey(conference)) {
3104 ids.add(mIdByConference.get(conference));
3105 }
3106 }
3107 }
3108 Collections.sort(ids);
3109 return ids;
3110 }
3111
Santos Cordon0159ac02014-08-21 14:28:11 -07003112 private Conference getNullConference() {
3113 if (sNullConference == null) {
3114 sNullConference = new Conference(null) {};
3115 }
3116 return sNullConference;
3117 }
Santos Cordon29f2f2e2014-09-11 19:50:24 -07003118
3119 private void endAllConnections() {
3120 // Unbound from telecomm. We should end all connections and conferences.
3121 for (Connection connection : mIdByConnection.keySet()) {
3122 // only operate on top-level calls. Conference calls will be removed on their own.
3123 if (connection.getConference() == null) {
3124 connection.onDisconnect();
3125 }
3126 }
3127 for (Conference conference : mIdByConference.keySet()) {
3128 conference.onDisconnect();
3129 }
3130 }
Tyler Gunnf0500bd2015-09-01 10:59:48 -07003131
3132 /**
3133 * Retrieves the next call ID as maintainted by the connection service.
3134 *
3135 * @return The call ID.
3136 */
3137 private int getNextCallId() {
Brad Ebingerb32d4f82016-10-24 16:40:49 -07003138 synchronized (mIdSyncRoot) {
Tyler Gunnf0500bd2015-09-01 10:59:48 -07003139 return ++mId;
3140 }
3141 }
Brad Ebinger99f17ce2019-09-11 18:06:51 -07003142
3143 /**
3144 * Returns this handler, ONLY FOR TESTING.
3145 * @hide
3146 */
3147 @VisibleForTesting
3148 public Handler getHandler() {
3149 return mHandler;
3150 }
Santos Cordon980acb92014-05-31 10:31:19 -07003151}