blob: f86f9d5dad3de2d9259617dca86ea766814a6f23 [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;
Santos Cordon5c6fa952014-07-20 17:47:12 -070021import android.annotation.SdkConstant;
Tyler Gunn5567d742019-10-31 13:04:37 -070022import android.annotation.SystemApi;
Sailesh Nepal2a46b902014-07-04 17:21:07 -070023import android.app.Service;
Santos Cordon52d8a152014-06-17 19:08:45 -070024import android.content.ComponentName;
Santos Cordon5c6fa952014-07-20 17:47:12 -070025import android.content.Intent;
Ihab Awad542e0ea2014-05-16 10:22:16 -070026import android.net.Uri;
Santos Cordon6b7f9552015-05-27 17:21:45 -070027import android.os.Bundle;
Santos Cordon52d8a152014-06-17 19:08:45 -070028import android.os.Handler;
29import android.os.IBinder;
30import android.os.Looper;
Sailesh Nepal2a46b902014-07-04 17:21:07 -070031import android.os.Message;
Hall Liub64ac4c2017-02-06 10:49:48 -080032import android.os.ParcelFileDescriptor;
33import android.os.RemoteException;
Brad Ebingerb32d4f82016-10-24 16:40:49 -070034import android.telecom.Logging.Session;
Andrew Lee14185762014-07-25 09:41:56 -070035
Brad Ebinger99f17ce2019-09-11 18:06:51 -070036import com.android.internal.annotations.VisibleForTesting;
Sailesh Nepal2a46b902014-07-04 17:21:07 -070037import com.android.internal.os.SomeArgs;
Tyler Gunnef9f6f92014-09-12 22:16:17 -070038import com.android.internal.telecom.IConnectionService;
39import com.android.internal.telecom.IConnectionServiceAdapter;
40import com.android.internal.telecom.RemoteServiceCallback;
Santos Cordon52d8a152014-06-17 19:08:45 -070041
Ihab Awad5d0410f2014-07-30 10:07:40 -070042import java.util.ArrayList;
Santos Cordonb6939982014-06-04 20:20:58 -070043import java.util.Collection;
Santos Cordon7c7bc7f2014-07-28 18:15:48 -070044import java.util.Collections;
Santos Cordon52d8a152014-06-17 19:08:45 -070045import java.util.List;
Ihab Awad542e0ea2014-05-16 10:22:16 -070046import java.util.Map;
Santos Cordon823fd3c2014-08-07 18:35:18 -070047import java.util.UUID;
mike dooley95e80702014-09-18 14:07:52 -070048import java.util.concurrent.ConcurrentHashMap;
Ihab Awad542e0ea2014-05-16 10:22:16 -070049
50/**
Tyler Gunnf5035432017-01-09 09:43:12 -080051 * An abstract service that should be implemented by any apps which either:
52 * <ol>
53 * <li>Can make phone calls (VoIP or otherwise) and want those calls to be integrated into the
54 * built-in phone app. Referred to as a <b>system managed</b> {@link ConnectionService}.</li>
55 * <li>Are a standalone calling app and don't want their calls to be integrated into the
56 * built-in phone app. Referred to as a <b>self managed</b> {@link ConnectionService}.</li>
57 * </ol>
58 * Once implemented, the {@link ConnectionService} needs to take the following steps so that Telecom
59 * will bind to it:
Santos Cordona663f862014-10-29 13:49:58 -070060 * <p>
61 * 1. <i>Registration in AndroidManifest.xml</i>
62 * <br/>
63 * <pre>
64 * &lt;service android:name="com.example.package.MyConnectionService"
65 * android:label="@string/some_label_for_my_connection_service"
Yorke Lee249c12e2015-05-13 15:59:29 -070066 * android:permission="android.permission.BIND_TELECOM_CONNECTION_SERVICE"&gt;
Santos Cordona663f862014-10-29 13:49:58 -070067 * &lt;intent-filter&gt;
68 * &lt;action android:name="android.telecom.ConnectionService" /&gt;
69 * &lt;/intent-filter&gt;
70 * &lt;/service&gt;
71 * </pre>
72 * <p>
73 * 2. <i> Registration of {@link PhoneAccount} with {@link TelecomManager}.</i>
74 * <br/>
75 * See {@link PhoneAccount} and {@link TelecomManager#registerPhoneAccount} for more information.
76 * <p>
Tyler Gunnf5035432017-01-09 09:43:12 -080077 * System managed {@link ConnectionService}s must be enabled by the user in the phone app settings
kopriva82c591b2018-10-08 15:57:00 -070078 * before Telecom will bind to them. Self-managed {@link ConnectionService}s must be granted the
Tyler Gunnf5035432017-01-09 09:43:12 -080079 * appropriate permission before Telecom will bind to them.
80 * <p>
81 * Once registered and enabled by the user in the phone app settings or granted permission, telecom
82 * will bind to a {@link ConnectionService} implementation when it wants that
83 * {@link ConnectionService} to place a call or the service has indicated that is has an incoming
84 * call through {@link TelecomManager#addNewIncomingCall}. The {@link ConnectionService} can then
85 * expect a call to {@link #onCreateIncomingConnection} or {@link #onCreateOutgoingConnection}
86 * wherein it should provide a new instance of a {@link Connection} object. It is through this
87 * {@link Connection} object that telecom receives state updates and the {@link ConnectionService}
Santos Cordona663f862014-10-29 13:49:58 -070088 * receives call-commands such as answer, reject, hold and disconnect.
89 * <p>
Tyler Gunnf5035432017-01-09 09:43:12 -080090 * When there are no more live calls, telecom will unbind from the {@link ConnectionService}.
Ihab Awad542e0ea2014-05-16 10:22:16 -070091 */
Sailesh Nepal2a46b902014-07-04 17:21:07 -070092public abstract class ConnectionService extends Service {
Santos Cordon5c6fa952014-07-20 17:47:12 -070093 /**
94 * The {@link Intent} that must be declared as handled by the service.
95 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -070096 @SdkConstant(SdkConstant.SdkConstantType.SERVICE_ACTION)
Tyler Gunnef9f6f92014-09-12 22:16:17 -070097 public static final String SERVICE_INTERFACE = "android.telecom.ConnectionService";
Santos Cordon5c6fa952014-07-20 17:47:12 -070098
Tyler Gunn8bf76572017-04-06 15:30:08 -070099 /**
100 * Boolean extra used by Telecom to inform a {@link ConnectionService} that the purpose of it
101 * being asked to create a new outgoing {@link Connection} is to perform a handover of an
102 * ongoing call on the device from another {@link PhoneAccount}/{@link ConnectionService}. Will
103 * be specified in the {@link ConnectionRequest#getExtras()} passed by Telecom when
104 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)} is called.
105 * <p>
Tyler Gunn727c6bd2017-04-11 09:51:40 -0700106 * When your {@link ConnectionService} receives this extra, it should communicate the fact that
107 * this is a handover to the other device's matching {@link ConnectionService}. That
Tyler Gunn8bf76572017-04-06 15:30:08 -0700108 * {@link ConnectionService} will continue the handover using
109 * {@link TelecomManager#addNewIncomingCall(PhoneAccountHandle, Bundle)}, specifying
Tyler Gunn727c6bd2017-04-11 09:51:40 -0700110 * {@link TelecomManager#EXTRA_IS_HANDOVER}. Telecom will match the phone numbers of the
111 * handover call on the other device with ongoing calls for {@link ConnectionService}s which
112 * support {@link PhoneAccount#EXTRA_SUPPORTS_HANDOVER_FROM}.
Tyler Gunn8bf76572017-04-06 15:30:08 -0700113 * @hide
114 */
115 public static final String EXTRA_IS_HANDOVER = TelecomManager.EXTRA_IS_HANDOVER;
116
Ihab Awad542e0ea2014-05-16 10:22:16 -0700117 // Flag controlling whether PII is emitted into the logs
Ihab Awad60ac30b2014-05-20 22:32:12 -0700118 private static final boolean PII_DEBUG = Log.isLoggable(android.util.Log.DEBUG);
Ihab Awad542e0ea2014-05-16 10:22:16 -0700119
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700120 // Session Definitions
121 private static final String SESSION_HANDLER = "H.";
122 private static final String SESSION_ADD_CS_ADAPTER = "CS.aCSA";
123 private static final String SESSION_REMOVE_CS_ADAPTER = "CS.rCSA";
124 private static final String SESSION_CREATE_CONN = "CS.crCo";
Tyler Gunn041a1fe2017-05-12 10:04:49 -0700125 private static final String SESSION_CREATE_CONN_COMPLETE = "CS.crCoC";
Tyler Gunn44e01912017-01-31 10:49:05 -0800126 private static final String SESSION_CREATE_CONN_FAILED = "CS.crCoF";
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700127 private static final String SESSION_ABORT = "CS.ab";
128 private static final String SESSION_ANSWER = "CS.an";
129 private static final String SESSION_ANSWER_VIDEO = "CS.anV";
Pooja Jaind34698d2017-12-28 14:15:31 +0530130 private static final String SESSION_DEFLECT = "CS.def";
Ravi Palurif4b38e72020-02-05 12:35:41 +0530131 private static final String SESSION_TRANSFER = "CS.trans";
132 private static final String SESSION_CONSULTATIVE_TRANSFER = "CS.cTrans";
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700133 private static final String SESSION_REJECT = "CS.r";
134 private static final String SESSION_REJECT_MESSAGE = "CS.rWM";
135 private static final String SESSION_SILENCE = "CS.s";
136 private static final String SESSION_DISCONNECT = "CS.d";
137 private static final String SESSION_HOLD = "CS.h";
138 private static final String SESSION_UNHOLD = "CS.u";
139 private static final String SESSION_CALL_AUDIO_SC = "CS.cASC";
140 private static final String SESSION_PLAY_DTMF = "CS.pDT";
141 private static final String SESSION_STOP_DTMF = "CS.sDT";
142 private static final String SESSION_CONFERENCE = "CS.c";
143 private static final String SESSION_SPLIT_CONFERENCE = "CS.sFC";
144 private static final String SESSION_MERGE_CONFERENCE = "CS.mC";
145 private static final String SESSION_SWAP_CONFERENCE = "CS.sC";
Ravi Paluri404babb2020-01-23 19:02:44 +0530146 private static final String SESSION_ADD_PARTICIPANT = "CS.aP";
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700147 private static final String SESSION_POST_DIAL_CONT = "CS.oPDC";
148 private static final String SESSION_PULL_EXTERNAL_CALL = "CS.pEC";
149 private static final String SESSION_SEND_CALL_EVENT = "CS.sCE";
Hall Liu49cabcc2021-01-15 11:41:48 -0800150 private static final String SESSION_CALL_FILTERING_COMPLETED = "CS.oCFC";
Tyler Gunn79bc1ec2018-01-22 15:17:54 -0800151 private static final String SESSION_HANDOVER_COMPLETE = "CS.hC";
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700152 private static final String SESSION_EXTRAS_CHANGED = "CS.oEC";
Hall Liub64ac4c2017-02-06 10:49:48 -0800153 private static final String SESSION_START_RTT = "CS.+RTT";
Hall Liua549fed2018-02-09 16:40:03 -0800154 private static final String SESSION_UPDATE_RTT_PIPES = "CS.uRTT";
Hall Liub64ac4c2017-02-06 10:49:48 -0800155 private static final String SESSION_STOP_RTT = "CS.-RTT";
156 private static final String SESSION_RTT_UPGRADE_RESPONSE = "CS.rTRUR";
Pengquan Meng731c1a32017-11-21 18:01:13 -0800157 private static final String SESSION_CONNECTION_SERVICE_FOCUS_LOST = "CS.cSFL";
158 private static final String SESSION_CONNECTION_SERVICE_FOCUS_GAINED = "CS.cSFG";
Sanket Padawe4cc8ed52017-12-04 16:22:20 -0800159 private static final String SESSION_HANDOVER_FAILED = "CS.haF";
Ravi Paluri80aa2142019-12-02 11:57:37 +0530160 private static final String SESSION_CREATE_CONF = "CS.crConf";
161 private static final String SESSION_CREATE_CONF_COMPLETE = "CS.crConfC";
162 private static final String SESSION_CREATE_CONF_FAILED = "CS.crConfF";
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700163
Ihab Awad8aecfed2014-08-08 17:06:11 -0700164 private static final int MSG_ADD_CONNECTION_SERVICE_ADAPTER = 1;
Sailesh Nepalc5b01572014-07-14 16:29:44 -0700165 private static final int MSG_CREATE_CONNECTION = 2;
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700166 private static final int MSG_ABORT = 3;
Sailesh Nepalc5b01572014-07-14 16:29:44 -0700167 private static final int MSG_ANSWER = 4;
168 private static final int MSG_REJECT = 5;
169 private static final int MSG_DISCONNECT = 6;
170 private static final int MSG_HOLD = 7;
171 private static final int MSG_UNHOLD = 8;
Yorke Lee4af59352015-05-13 14:14:54 -0700172 private static final int MSG_ON_CALL_AUDIO_STATE_CHANGED = 9;
Sailesh Nepalc5b01572014-07-14 16:29:44 -0700173 private static final int MSG_PLAY_DTMF_TONE = 10;
174 private static final int MSG_STOP_DTMF_TONE = 11;
175 private static final int MSG_CONFERENCE = 12;
176 private static final int MSG_SPLIT_FROM_CONFERENCE = 13;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700177 private static final int MSG_ON_POST_DIAL_CONTINUE = 14;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700178 private static final int MSG_REMOVE_CONNECTION_SERVICE_ADAPTER = 16;
Tyler Gunnbe74de02014-08-29 14:51:48 -0700179 private static final int MSG_ANSWER_VIDEO = 17;
Santos Cordona4868042014-09-04 17:39:22 -0700180 private static final int MSG_MERGE_CONFERENCE = 18;
181 private static final int MSG_SWAP_CONFERENCE = 19;
Bryce Lee81901682015-08-28 16:38:02 -0700182 private static final int MSG_REJECT_WITH_MESSAGE = 20;
Bryce Leecac50772015-11-17 15:13:29 -0800183 private static final int MSG_SILENCE = 21;
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700184 private static final int MSG_PULL_EXTERNAL_CALL = 22;
185 private static final int MSG_SEND_CALL_EVENT = 23;
Tyler Gunndee56a82016-03-23 16:06:34 -0700186 private static final int MSG_ON_EXTRAS_CHANGED = 24;
Tyler Gunn44e01912017-01-31 10:49:05 -0800187 private static final int MSG_CREATE_CONNECTION_FAILED = 25;
Hall Liub64ac4c2017-02-06 10:49:48 -0800188 private static final int MSG_ON_START_RTT = 26;
189 private static final int MSG_ON_STOP_RTT = 27;
190 private static final int MSG_RTT_UPGRADE_RESPONSE = 28;
Tyler Gunn041a1fe2017-05-12 10:04:49 -0700191 private static final int MSG_CREATE_CONNECTION_COMPLETE = 29;
Pengquan Meng731c1a32017-11-21 18:01:13 -0800192 private static final int MSG_CONNECTION_SERVICE_FOCUS_LOST = 30;
193 private static final int MSG_CONNECTION_SERVICE_FOCUS_GAINED = 31;
Sanket Padawe4cc8ed52017-12-04 16:22:20 -0800194 private static final int MSG_HANDOVER_FAILED = 32;
Tyler Gunn79bc1ec2018-01-22 15:17:54 -0800195 private static final int MSG_HANDOVER_COMPLETE = 33;
Pooja Jaind34698d2017-12-28 14:15:31 +0530196 private static final int MSG_DEFLECT = 34;
Ravi Paluri80aa2142019-12-02 11:57:37 +0530197 private static final int MSG_CREATE_CONFERENCE = 35;
198 private static final int MSG_CREATE_CONFERENCE_COMPLETE = 36;
199 private static final int MSG_CREATE_CONFERENCE_FAILED = 37;
Tyler Gunnfacfdee2020-01-23 13:10:37 -0800200 private static final int MSG_REJECT_WITH_REASON = 38;
Ravi Paluri404babb2020-01-23 19:02:44 +0530201 private static final int MSG_ADD_PARTICIPANT = 39;
Ravi Palurif4b38e72020-02-05 12:35:41 +0530202 private static final int MSG_EXPLICIT_CALL_TRANSFER = 40;
203 private static final int MSG_EXPLICIT_CALL_TRANSFER_CONSULTATIVE = 41;
Hall Liu49cabcc2021-01-15 11:41:48 -0800204 private static final int MSG_ON_CALL_FILTERING_COMPLETED = 42;
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700205
Sailesh Nepalcf7020b2014-08-20 10:07:19 -0700206 private static Connection sNullConnection;
207
mike dooley95e80702014-09-18 14:07:52 -0700208 private final Map<String, Connection> mConnectionById = new ConcurrentHashMap<>();
209 private final Map<Connection, String> mIdByConnection = new ConcurrentHashMap<>();
210 private final Map<String, Conference> mConferenceById = new ConcurrentHashMap<>();
211 private final Map<Conference, String> mIdByConference = new ConcurrentHashMap<>();
Ihab Awadb8e85c72014-08-23 20:34:57 -0700212 private final RemoteConnectionManager mRemoteConnectionManager =
213 new RemoteConnectionManager(this);
Ihab Awad5d0410f2014-07-30 10:07:40 -0700214 private final List<Runnable> mPreInitializationConnectionRequests = new ArrayList<>();
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700215 private final ConnectionServiceAdapter mAdapter = new ConnectionServiceAdapter();
Ihab Awad542e0ea2014-05-16 10:22:16 -0700216
Santos Cordon823fd3c2014-08-07 18:35:18 -0700217 private boolean mAreAccountsInitialized = false;
Santos Cordon0159ac02014-08-21 14:28:11 -0700218 private Conference sNullConference;
Tyler Gunnf0500bd2015-09-01 10:59:48 -0700219 private Object mIdSyncRoot = new Object();
220 private int mId = 0;
Santos Cordon823fd3c2014-08-07 18:35:18 -0700221
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700222 private final IBinder mBinder = new IConnectionService.Stub() {
223 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700224 public void addConnectionServiceAdapter(IConnectionServiceAdapter adapter,
225 Session.Info sessionInfo) {
226 Log.startSession(sessionInfo, SESSION_ADD_CS_ADAPTER);
227 try {
228 SomeArgs args = SomeArgs.obtain();
229 args.arg1 = adapter;
230 args.arg2 = Log.createSubsession();
231 mHandler.obtainMessage(MSG_ADD_CONNECTION_SERVICE_ADAPTER, args).sendToTarget();
232 } finally {
233 Log.endSession();
234 }
Ihab Awad8aecfed2014-08-08 17:06:11 -0700235 }
236
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700237 public void removeConnectionServiceAdapter(IConnectionServiceAdapter adapter,
238 Session.Info sessionInfo) {
239 Log.startSession(sessionInfo, SESSION_REMOVE_CS_ADAPTER);
240 try {
241 SomeArgs args = SomeArgs.obtain();
242 args.arg1 = adapter;
243 args.arg2 = Log.createSubsession();
244 mHandler.obtainMessage(MSG_REMOVE_CONNECTION_SERVICE_ADAPTER, args).sendToTarget();
245 } finally {
246 Log.endSession();
247 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700248 }
249
250 @Override
Ihab Awadf8b69882014-07-25 15:14:01 -0700251 public void createConnection(
252 PhoneAccountHandle connectionManagerPhoneAccount,
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700253 String id,
Ihab Awadf8b69882014-07-25 15:14:01 -0700254 ConnectionRequest request,
Yorke Leec3cf9822014-10-02 09:38:39 -0700255 boolean isIncoming,
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700256 boolean isUnknown,
257 Session.Info sessionInfo) {
258 Log.startSession(sessionInfo, SESSION_CREATE_CONN);
259 try {
260 SomeArgs args = SomeArgs.obtain();
261 args.arg1 = connectionManagerPhoneAccount;
262 args.arg2 = id;
263 args.arg3 = request;
264 args.arg4 = Log.createSubsession();
265 args.argi1 = isIncoming ? 1 : 0;
266 args.argi2 = isUnknown ? 1 : 0;
267 mHandler.obtainMessage(MSG_CREATE_CONNECTION, args).sendToTarget();
268 } finally {
269 Log.endSession();
270 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700271 }
272
273 @Override
Tyler Gunn041a1fe2017-05-12 10:04:49 -0700274 public void createConnectionComplete(String id, Session.Info sessionInfo) {
275 Log.startSession(sessionInfo, SESSION_CREATE_CONN_COMPLETE);
276 try {
277 SomeArgs args = SomeArgs.obtain();
278 args.arg1 = id;
279 args.arg2 = Log.createSubsession();
280 mHandler.obtainMessage(MSG_CREATE_CONNECTION_COMPLETE, args).sendToTarget();
281 } finally {
282 Log.endSession();
283 }
284 }
285
286 @Override
Tyler Gunn44e01912017-01-31 10:49:05 -0800287 public void createConnectionFailed(
Tyler Gunn159f35c2017-03-02 09:28:37 -0800288 PhoneAccountHandle connectionManagerPhoneAccount,
Tyler Gunn44e01912017-01-31 10:49:05 -0800289 String callId,
290 ConnectionRequest request,
291 boolean isIncoming,
292 Session.Info sessionInfo) {
293 Log.startSession(sessionInfo, SESSION_CREATE_CONN_FAILED);
294 try {
295 SomeArgs args = SomeArgs.obtain();
296 args.arg1 = callId;
297 args.arg2 = request;
298 args.arg3 = Log.createSubsession();
Tyler Gunn159f35c2017-03-02 09:28:37 -0800299 args.arg4 = connectionManagerPhoneAccount;
Tyler Gunn44e01912017-01-31 10:49:05 -0800300 args.argi1 = isIncoming ? 1 : 0;
301 mHandler.obtainMessage(MSG_CREATE_CONNECTION_FAILED, args).sendToTarget();
302 } finally {
303 Log.endSession();
304 }
305 }
306
307 @Override
Ravi Paluri80aa2142019-12-02 11:57:37 +0530308 public void createConference(
309 PhoneAccountHandle connectionManagerPhoneAccount,
310 String id,
311 ConnectionRequest request,
312 boolean isIncoming,
313 boolean isUnknown,
314 Session.Info sessionInfo) {
315 Log.startSession(sessionInfo, SESSION_CREATE_CONF);
316 try {
317 SomeArgs args = SomeArgs.obtain();
318 args.arg1 = connectionManagerPhoneAccount;
319 args.arg2 = id;
320 args.arg3 = request;
321 args.arg4 = Log.createSubsession();
322 args.argi1 = isIncoming ? 1 : 0;
323 args.argi2 = isUnknown ? 1 : 0;
324 mHandler.obtainMessage(MSG_CREATE_CONFERENCE, args).sendToTarget();
325 } finally {
326 Log.endSession();
327 }
328 }
329
330 @Override
331 public void createConferenceComplete(String id, Session.Info sessionInfo) {
332 Log.startSession(sessionInfo, SESSION_CREATE_CONF_COMPLETE);
333 try {
334 SomeArgs args = SomeArgs.obtain();
335 args.arg1 = id;
336 args.arg2 = Log.createSubsession();
337 mHandler.obtainMessage(MSG_CREATE_CONFERENCE_COMPLETE, args).sendToTarget();
338 } finally {
339 Log.endSession();
340 }
341 }
342
343 @Override
344 public void createConferenceFailed(
345 PhoneAccountHandle connectionManagerPhoneAccount,
346 String callId,
347 ConnectionRequest request,
348 boolean isIncoming,
349 Session.Info sessionInfo) {
350 Log.startSession(sessionInfo, SESSION_CREATE_CONF_FAILED);
351 try {
352 SomeArgs args = SomeArgs.obtain();
353 args.arg1 = callId;
354 args.arg2 = request;
355 args.arg3 = Log.createSubsession();
356 args.arg4 = connectionManagerPhoneAccount;
357 args.argi1 = isIncoming ? 1 : 0;
358 mHandler.obtainMessage(MSG_CREATE_CONFERENCE_FAILED, args).sendToTarget();
359 } finally {
360 Log.endSession();
361 }
362 }
363
364 @Override
Sanket Padawe4cc8ed52017-12-04 16:22:20 -0800365 public void handoverFailed(String callId, ConnectionRequest request, int reason,
366 Session.Info sessionInfo) {
367 Log.startSession(sessionInfo, SESSION_HANDOVER_FAILED);
368 try {
369 SomeArgs args = SomeArgs.obtain();
370 args.arg1 = callId;
371 args.arg2 = request;
372 args.arg3 = Log.createSubsession();
373 args.arg4 = reason;
374 mHandler.obtainMessage(MSG_HANDOVER_FAILED, args).sendToTarget();
375 } finally {
376 Log.endSession();
377 }
378 }
379
380 @Override
Tyler Gunn79bc1ec2018-01-22 15:17:54 -0800381 public void handoverComplete(String callId, Session.Info sessionInfo) {
382 Log.startSession(sessionInfo, SESSION_HANDOVER_COMPLETE);
383 try {
384 SomeArgs args = SomeArgs.obtain();
385 args.arg1 = callId;
386 args.arg2 = Log.createSubsession();
387 mHandler.obtainMessage(MSG_HANDOVER_COMPLETE, args).sendToTarget();
388 } finally {
389 Log.endSession();
390 }
391 }
392
393 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700394 public void abort(String callId, Session.Info sessionInfo) {
395 Log.startSession(sessionInfo, SESSION_ABORT);
396 try {
397 SomeArgs args = SomeArgs.obtain();
398 args.arg1 = callId;
399 args.arg2 = Log.createSubsession();
400 mHandler.obtainMessage(MSG_ABORT, args).sendToTarget();
401 } finally {
402 Log.endSession();
403 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700404 }
405
406 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700407 public void answerVideo(String callId, int videoState, Session.Info sessionInfo) {
408 Log.startSession(sessionInfo, SESSION_ANSWER_VIDEO);
409 try {
410 SomeArgs args = SomeArgs.obtain();
411 args.arg1 = callId;
412 args.arg2 = Log.createSubsession();
413 args.argi1 = videoState;
414 mHandler.obtainMessage(MSG_ANSWER_VIDEO, args).sendToTarget();
415 } finally {
416 Log.endSession();
417 }
Tyler Gunnbe74de02014-08-29 14:51:48 -0700418 }
419
420 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700421 public void answer(String callId, Session.Info sessionInfo) {
422 Log.startSession(sessionInfo, SESSION_ANSWER);
423 try {
424 SomeArgs args = SomeArgs.obtain();
425 args.arg1 = callId;
426 args.arg2 = Log.createSubsession();
427 mHandler.obtainMessage(MSG_ANSWER, args).sendToTarget();
428 } finally {
429 Log.endSession();
430 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700431 }
432
433 @Override
Pooja Jaind34698d2017-12-28 14:15:31 +0530434 public void deflect(String callId, Uri address, Session.Info sessionInfo) {
435 Log.startSession(sessionInfo, SESSION_DEFLECT);
436 try {
437 SomeArgs args = SomeArgs.obtain();
438 args.arg1 = callId;
439 args.arg2 = address;
440 args.arg3 = Log.createSubsession();
441 mHandler.obtainMessage(MSG_DEFLECT, args).sendToTarget();
442 } finally {
443 Log.endSession();
444 }
445 }
446
447 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700448 public void reject(String callId, Session.Info sessionInfo) {
449 Log.startSession(sessionInfo, SESSION_REJECT);
450 try {
451 SomeArgs args = SomeArgs.obtain();
452 args.arg1 = callId;
453 args.arg2 = Log.createSubsession();
454 mHandler.obtainMessage(MSG_REJECT, args).sendToTarget();
455 } finally {
456 Log.endSession();
457 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700458 }
459
460 @Override
Tyler Gunnfacfdee2020-01-23 13:10:37 -0800461 public void rejectWithReason(String callId,
462 @android.telecom.Call.RejectReason int rejectReason, Session.Info sessionInfo) {
463 Log.startSession(sessionInfo, SESSION_REJECT);
464 try {
465 SomeArgs args = SomeArgs.obtain();
466 args.arg1 = callId;
467 args.argi1 = rejectReason;
468 args.arg2 = Log.createSubsession();
469 mHandler.obtainMessage(MSG_REJECT_WITH_REASON, args).sendToTarget();
470 } finally {
471 Log.endSession();
472 }
473 }
474
475 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700476 public void rejectWithMessage(String callId, String message, Session.Info sessionInfo) {
477 Log.startSession(sessionInfo, SESSION_REJECT_MESSAGE);
478 try {
479 SomeArgs args = SomeArgs.obtain();
480 args.arg1 = callId;
481 args.arg2 = message;
482 args.arg3 = Log.createSubsession();
483 mHandler.obtainMessage(MSG_REJECT_WITH_MESSAGE, args).sendToTarget();
484 } finally {
485 Log.endSession();
486 }
Bryce Lee81901682015-08-28 16:38:02 -0700487 }
488
489 @Override
Ravi Palurif4b38e72020-02-05 12:35:41 +0530490 public void transfer(@NonNull String callId, @NonNull Uri number,
491 boolean isConfirmationRequired, Session.Info sessionInfo) {
492 Log.startSession(sessionInfo, SESSION_TRANSFER);
493 try {
494 SomeArgs args = SomeArgs.obtain();
495 args.arg1 = callId;
496 args.arg2 = number;
497 args.argi1 = isConfirmationRequired ? 1 : 0;
498 args.arg3 = Log.createSubsession();
499 mHandler.obtainMessage(MSG_EXPLICIT_CALL_TRANSFER, args).sendToTarget();
500 } finally {
501 Log.endSession();
502 }
503 }
504
505 @Override
506 public void consultativeTransfer(@NonNull String callId, @NonNull String otherCallId,
507 Session.Info sessionInfo) {
508 Log.startSession(sessionInfo, SESSION_CONSULTATIVE_TRANSFER);
509 try {
510 SomeArgs args = SomeArgs.obtain();
511 args.arg1 = callId;
512 args.arg2 = otherCallId;
513 args.arg3 = Log.createSubsession();
514 mHandler.obtainMessage(
515 MSG_EXPLICIT_CALL_TRANSFER_CONSULTATIVE, args).sendToTarget();
516 } finally {
517 Log.endSession();
518 }
519 }
520
521 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700522 public void silence(String callId, Session.Info sessionInfo) {
523 Log.startSession(sessionInfo, SESSION_SILENCE);
524 try {
525 SomeArgs args = SomeArgs.obtain();
526 args.arg1 = callId;
527 args.arg2 = Log.createSubsession();
528 mHandler.obtainMessage(MSG_SILENCE, args).sendToTarget();
529 } finally {
530 Log.endSession();
531 }
Bryce Leecac50772015-11-17 15:13:29 -0800532 }
533
534 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700535 public void disconnect(String callId, Session.Info sessionInfo) {
536 Log.startSession(sessionInfo, SESSION_DISCONNECT);
537 try {
538 SomeArgs args = SomeArgs.obtain();
539 args.arg1 = callId;
540 args.arg2 = Log.createSubsession();
541 mHandler.obtainMessage(MSG_DISCONNECT, args).sendToTarget();
542 } finally {
543 Log.endSession();
544 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700545 }
546
547 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700548 public void hold(String callId, Session.Info sessionInfo) {
549 Log.startSession(sessionInfo, SESSION_HOLD);
550 try {
551 SomeArgs args = SomeArgs.obtain();
552 args.arg1 = callId;
553 args.arg2 = Log.createSubsession();
554 mHandler.obtainMessage(MSG_HOLD, args).sendToTarget();
555 } finally {
556 Log.endSession();
557 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700558 }
559
560 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700561 public void unhold(String callId, Session.Info sessionInfo) {
562 Log.startSession(sessionInfo, SESSION_UNHOLD);
563 try {
564 SomeArgs args = SomeArgs.obtain();
565 args.arg1 = callId;
566 args.arg2 = Log.createSubsession();
567 mHandler.obtainMessage(MSG_UNHOLD, args).sendToTarget();
568 } finally {
569 Log.endSession();
570 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700571 }
572
573 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700574 public void onCallAudioStateChanged(String callId, CallAudioState callAudioState,
575 Session.Info sessionInfo) {
576 Log.startSession(sessionInfo, SESSION_CALL_AUDIO_SC);
577 try {
578 SomeArgs args = SomeArgs.obtain();
579 args.arg1 = callId;
580 args.arg2 = callAudioState;
581 args.arg3 = Log.createSubsession();
582 mHandler.obtainMessage(MSG_ON_CALL_AUDIO_STATE_CHANGED, args).sendToTarget();
583 } finally {
584 Log.endSession();
585 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700586 }
587
588 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700589 public void playDtmfTone(String callId, char digit, Session.Info sessionInfo) {
590 Log.startSession(sessionInfo, SESSION_PLAY_DTMF);
591 try {
592 SomeArgs args = SomeArgs.obtain();
593 args.arg1 = digit;
594 args.arg2 = callId;
595 args.arg3 = Log.createSubsession();
596 mHandler.obtainMessage(MSG_PLAY_DTMF_TONE, args).sendToTarget();
597 } finally {
598 Log.endSession();
599 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700600 }
601
602 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700603 public void stopDtmfTone(String callId, Session.Info sessionInfo) {
604 Log.startSession(sessionInfo, SESSION_STOP_DTMF);
605 try {
606 SomeArgs args = SomeArgs.obtain();
607 args.arg1 = callId;
608 args.arg2 = Log.createSubsession();
609 mHandler.obtainMessage(MSG_STOP_DTMF_TONE, args).sendToTarget();
610 } finally {
611 Log.endSession();
612 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700613 }
614
615 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700616 public void conference(String callId1, String callId2, Session.Info sessionInfo) {
617 Log.startSession(sessionInfo, SESSION_CONFERENCE);
618 try {
619 SomeArgs args = SomeArgs.obtain();
620 args.arg1 = callId1;
621 args.arg2 = callId2;
622 args.arg3 = Log.createSubsession();
623 mHandler.obtainMessage(MSG_CONFERENCE, args).sendToTarget();
624 } finally {
625 Log.endSession();
626 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700627 }
628
629 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700630 public void splitFromConference(String callId, Session.Info sessionInfo) {
631 Log.startSession(sessionInfo, SESSION_SPLIT_CONFERENCE);
632 try {
633 SomeArgs args = SomeArgs.obtain();
634 args.arg1 = callId;
635 args.arg2 = Log.createSubsession();
636 mHandler.obtainMessage(MSG_SPLIT_FROM_CONFERENCE, args).sendToTarget();
637 } finally {
638 Log.endSession();
639 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700640 }
641
642 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700643 public void mergeConference(String callId, Session.Info sessionInfo) {
644 Log.startSession(sessionInfo, SESSION_MERGE_CONFERENCE);
645 try {
646 SomeArgs args = SomeArgs.obtain();
647 args.arg1 = callId;
648 args.arg2 = Log.createSubsession();
649 mHandler.obtainMessage(MSG_MERGE_CONFERENCE, args).sendToTarget();
650 } finally {
651 Log.endSession();
652 }
Santos Cordona4868042014-09-04 17:39:22 -0700653 }
654
655 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700656 public void swapConference(String callId, Session.Info sessionInfo) {
657 Log.startSession(sessionInfo, SESSION_SWAP_CONFERENCE);
658 try {
659 SomeArgs args = SomeArgs.obtain();
660 args.arg1 = callId;
661 args.arg2 = Log.createSubsession();
662 mHandler.obtainMessage(MSG_SWAP_CONFERENCE, args).sendToTarget();
663 } finally {
664 Log.endSession();
665 }
Santos Cordona4868042014-09-04 17:39:22 -0700666 }
667
668 @Override
Ravi Paluri404babb2020-01-23 19:02:44 +0530669 public void addConferenceParticipants(String callId, List<Uri> participants,
670 Session.Info sessionInfo) {
671 Log.startSession(sessionInfo, SESSION_ADD_PARTICIPANT);
672 try {
673 SomeArgs args = SomeArgs.obtain();
674 args.arg1 = callId;
675 args.arg2 = participants;
676 args.arg3 = Log.createSubsession();
677 mHandler.obtainMessage(MSG_ADD_PARTICIPANT, args).sendToTarget();
678 } finally {
679 Log.endSession();
680 }
681 }
682
683 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700684 public void onPostDialContinue(String callId, boolean proceed, Session.Info sessionInfo) {
685 Log.startSession(sessionInfo, SESSION_POST_DIAL_CONT);
686 try {
687 SomeArgs args = SomeArgs.obtain();
688 args.arg1 = callId;
689 args.arg2 = Log.createSubsession();
690 args.argi1 = proceed ? 1 : 0;
691 mHandler.obtainMessage(MSG_ON_POST_DIAL_CONTINUE, args).sendToTarget();
692 } finally {
693 Log.endSession();
694 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700695 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700696
697 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700698 public void pullExternalCall(String callId, Session.Info sessionInfo) {
699 Log.startSession(sessionInfo, SESSION_PULL_EXTERNAL_CALL);
700 try {
701 SomeArgs args = SomeArgs.obtain();
702 args.arg1 = callId;
703 args.arg2 = Log.createSubsession();
704 mHandler.obtainMessage(MSG_PULL_EXTERNAL_CALL, args).sendToTarget();
705 } finally {
706 Log.endSession();
707 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700708 }
709
710 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700711 public void sendCallEvent(String callId, String event, Bundle extras,
712 Session.Info sessionInfo) {
713 Log.startSession(sessionInfo, SESSION_SEND_CALL_EVENT);
714 try {
715 SomeArgs args = SomeArgs.obtain();
716 args.arg1 = callId;
717 args.arg2 = event;
718 args.arg3 = extras;
719 args.arg4 = Log.createSubsession();
720 mHandler.obtainMessage(MSG_SEND_CALL_EVENT, args).sendToTarget();
721 } finally {
722 Log.endSession();
723 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700724 }
Tyler Gunndee56a82016-03-23 16:06:34 -0700725
726 @Override
Hall Liu49cabcc2021-01-15 11:41:48 -0800727 public void onCallFilteringCompleted(String callId, boolean isBlocked, boolean isInContacts,
728 Session.Info sessionInfo) {
729 Log.startSession(sessionInfo, SESSION_CALL_FILTERING_COMPLETED);
730 try {
731 SomeArgs args = SomeArgs.obtain();
732 args.arg1 = callId;
733 args.arg2 = isBlocked;
734 args.arg3 = isInContacts;
735 args.arg4 = Log.createSubsession();
736 mHandler.obtainMessage(MSG_ON_CALL_FILTERING_COMPLETED, args).sendToTarget();
737 } finally {
738 Log.endSession();
739 }
740 }
741
742 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700743 public void onExtrasChanged(String callId, Bundle extras, Session.Info sessionInfo) {
744 Log.startSession(sessionInfo, SESSION_EXTRAS_CHANGED);
745 try {
746 SomeArgs args = SomeArgs.obtain();
747 args.arg1 = callId;
748 args.arg2 = extras;
749 args.arg3 = Log.createSubsession();
750 mHandler.obtainMessage(MSG_ON_EXTRAS_CHANGED, args).sendToTarget();
751 } finally {
752 Log.endSession();
753 }
Tyler Gunndee56a82016-03-23 16:06:34 -0700754 }
Hall Liub64ac4c2017-02-06 10:49:48 -0800755
756 @Override
757 public void startRtt(String callId, ParcelFileDescriptor fromInCall,
758 ParcelFileDescriptor toInCall, Session.Info sessionInfo) throws RemoteException {
759 Log.startSession(sessionInfo, SESSION_START_RTT);
760 try {
761 SomeArgs args = SomeArgs.obtain();
762 args.arg1 = callId;
763 args.arg2 = new Connection.RttTextStream(toInCall, fromInCall);
764 args.arg3 = Log.createSubsession();
765 mHandler.obtainMessage(MSG_ON_START_RTT, args).sendToTarget();
766 } finally {
767 Log.endSession();
768 }
769 }
770
771 @Override
772 public void stopRtt(String callId, Session.Info sessionInfo) throws RemoteException {
773 Log.startSession(sessionInfo, SESSION_STOP_RTT);
774 try {
775 SomeArgs args = SomeArgs.obtain();
776 args.arg1 = callId;
777 args.arg2 = Log.createSubsession();
778 mHandler.obtainMessage(MSG_ON_STOP_RTT, args).sendToTarget();
779 } finally {
780 Log.endSession();
781 }
782 }
783
784 @Override
785 public void respondToRttUpgradeRequest(String callId, ParcelFileDescriptor fromInCall,
786 ParcelFileDescriptor toInCall, Session.Info sessionInfo) throws RemoteException {
787 Log.startSession(sessionInfo, SESSION_RTT_UPGRADE_RESPONSE);
788 try {
789 SomeArgs args = SomeArgs.obtain();
790 args.arg1 = callId;
791 if (toInCall == null || fromInCall == null) {
792 args.arg2 = null;
793 } else {
794 args.arg2 = new Connection.RttTextStream(toInCall, fromInCall);
795 }
796 args.arg3 = Log.createSubsession();
797 mHandler.obtainMessage(MSG_RTT_UPGRADE_RESPONSE, args).sendToTarget();
798 } finally {
799 Log.endSession();
800 }
801 }
Pengquan Meng731c1a32017-11-21 18:01:13 -0800802
803 @Override
804 public void connectionServiceFocusLost(Session.Info sessionInfo) throws RemoteException {
805 Log.startSession(sessionInfo, SESSION_CONNECTION_SERVICE_FOCUS_LOST);
806 try {
807 mHandler.obtainMessage(MSG_CONNECTION_SERVICE_FOCUS_LOST).sendToTarget();
808 } finally {
809 Log.endSession();
810 }
811 }
812
813 @Override
814 public void connectionServiceFocusGained(Session.Info sessionInfo) throws RemoteException {
815 Log.startSession(sessionInfo, SESSION_CONNECTION_SERVICE_FOCUS_GAINED);
816 try {
817 mHandler.obtainMessage(MSG_CONNECTION_SERVICE_FOCUS_GAINED).sendToTarget();
818 } finally {
819 Log.endSession();
820 }
821 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700822 };
823
824 private final Handler mHandler = new Handler(Looper.getMainLooper()) {
825 @Override
826 public void handleMessage(Message msg) {
827 switch (msg.what) {
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700828 case MSG_ADD_CONNECTION_SERVICE_ADAPTER: {
829 SomeArgs args = (SomeArgs) msg.obj;
830 try {
831 IConnectionServiceAdapter adapter = (IConnectionServiceAdapter) args.arg1;
832 Log.continueSession((Session) args.arg2,
833 SESSION_HANDLER + SESSION_ADD_CS_ADAPTER);
834 mAdapter.addAdapter(adapter);
835 onAdapterAttached();
836 } finally {
837 args.recycle();
838 Log.endSession();
839 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700840 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700841 }
842 case MSG_REMOVE_CONNECTION_SERVICE_ADAPTER: {
843 SomeArgs args = (SomeArgs) msg.obj;
844 try {
845 Log.continueSession((Session) args.arg2,
846 SESSION_HANDLER + SESSION_REMOVE_CS_ADAPTER);
847 mAdapter.removeAdapter((IConnectionServiceAdapter) args.arg1);
848 } finally {
849 args.recycle();
850 Log.endSession();
851 }
Ihab Awad8aecfed2014-08-08 17:06:11 -0700852 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700853 }
Ihab Awadf8b69882014-07-25 15:14:01 -0700854 case MSG_CREATE_CONNECTION: {
855 SomeArgs args = (SomeArgs) msg.obj;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700856 Log.continueSession((Session) args.arg4, SESSION_HANDLER + SESSION_CREATE_CONN);
Ihab Awadf8b69882014-07-25 15:14:01 -0700857 try {
Ihab Awad5d0410f2014-07-30 10:07:40 -0700858 final PhoneAccountHandle connectionManagerPhoneAccount =
Ihab Awadf8b69882014-07-25 15:14:01 -0700859 (PhoneAccountHandle) args.arg1;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700860 final String id = (String) args.arg2;
861 final ConnectionRequest request = (ConnectionRequest) args.arg3;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700862 final boolean isIncoming = args.argi1 == 1;
Yorke Leec3cf9822014-10-02 09:38:39 -0700863 final boolean isUnknown = args.argi2 == 1;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700864 if (!mAreAccountsInitialized) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700865 Log.d(this, "Enqueueing pre-init request %s", id);
Brad Ebinger0c3541b2016-11-01 14:11:38 -0700866 mPreInitializationConnectionRequests.add(
867 new android.telecom.Logging.Runnable(
868 SESSION_HANDLER + SESSION_CREATE_CONN + ".pICR",
869 null /*lock*/) {
Ihab Awad5d0410f2014-07-30 10:07:40 -0700870 @Override
Brad Ebinger0c3541b2016-11-01 14:11:38 -0700871 public void loggedRun() {
Ihab Awad5d0410f2014-07-30 10:07:40 -0700872 createConnection(
873 connectionManagerPhoneAccount,
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700874 id,
Ihab Awad5d0410f2014-07-30 10:07:40 -0700875 request,
Yorke Leec3cf9822014-10-02 09:38:39 -0700876 isIncoming,
877 isUnknown);
Ihab Awad5d0410f2014-07-30 10:07:40 -0700878 }
Brad Ebinger0c3541b2016-11-01 14:11:38 -0700879 }.prepare());
Ihab Awad5d0410f2014-07-30 10:07:40 -0700880 } else {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700881 createConnection(
882 connectionManagerPhoneAccount,
883 id,
884 request,
Yorke Leec3cf9822014-10-02 09:38:39 -0700885 isIncoming,
886 isUnknown);
Ihab Awad5d0410f2014-07-30 10:07:40 -0700887 }
Ihab Awadf8b69882014-07-25 15:14:01 -0700888 } finally {
889 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700890 Log.endSession();
Ihab Awadf8b69882014-07-25 15:14:01 -0700891 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700892 break;
Ihab Awadf8b69882014-07-25 15:14:01 -0700893 }
Tyler Gunn041a1fe2017-05-12 10:04:49 -0700894 case MSG_CREATE_CONNECTION_COMPLETE: {
895 SomeArgs args = (SomeArgs) msg.obj;
896 Log.continueSession((Session) args.arg2,
897 SESSION_HANDLER + SESSION_CREATE_CONN_COMPLETE);
898 try {
899 final String id = (String) args.arg1;
900 if (!mAreAccountsInitialized) {
901 Log.d(this, "Enqueueing pre-init request %s", id);
902 mPreInitializationConnectionRequests.add(
903 new android.telecom.Logging.Runnable(
904 SESSION_HANDLER + SESSION_CREATE_CONN_COMPLETE
905 + ".pICR",
906 null /*lock*/) {
907 @Override
908 public void loggedRun() {
909 notifyCreateConnectionComplete(id);
910 }
911 }.prepare());
912 } else {
913 notifyCreateConnectionComplete(id);
914 }
915 } finally {
916 args.recycle();
917 Log.endSession();
918 }
919 break;
920 }
Tyler Gunn44e01912017-01-31 10:49:05 -0800921 case MSG_CREATE_CONNECTION_FAILED: {
922 SomeArgs args = (SomeArgs) msg.obj;
923 Log.continueSession((Session) args.arg3, SESSION_HANDLER +
924 SESSION_CREATE_CONN_FAILED);
925 try {
926 final String id = (String) args.arg1;
927 final ConnectionRequest request = (ConnectionRequest) args.arg2;
928 final boolean isIncoming = args.argi1 == 1;
Tyler Gunn159f35c2017-03-02 09:28:37 -0800929 final PhoneAccountHandle connectionMgrPhoneAccount =
930 (PhoneAccountHandle) args.arg4;
Tyler Gunn44e01912017-01-31 10:49:05 -0800931 if (!mAreAccountsInitialized) {
932 Log.d(this, "Enqueueing pre-init request %s", id);
933 mPreInitializationConnectionRequests.add(
934 new android.telecom.Logging.Runnable(
935 SESSION_HANDLER + SESSION_CREATE_CONN_FAILED + ".pICR",
936 null /*lock*/) {
937 @Override
938 public void loggedRun() {
Tyler Gunn159f35c2017-03-02 09:28:37 -0800939 createConnectionFailed(connectionMgrPhoneAccount, id,
940 request, isIncoming);
Tyler Gunn44e01912017-01-31 10:49:05 -0800941 }
942 }.prepare());
943 } else {
944 Log.i(this, "createConnectionFailed %s", id);
Tyler Gunn159f35c2017-03-02 09:28:37 -0800945 createConnectionFailed(connectionMgrPhoneAccount, id, request,
946 isIncoming);
Tyler Gunn44e01912017-01-31 10:49:05 -0800947 }
948 } finally {
949 args.recycle();
950 Log.endSession();
951 }
952 break;
953 }
Ravi Paluri80aa2142019-12-02 11:57:37 +0530954 case MSG_CREATE_CONFERENCE: {
955 SomeArgs args = (SomeArgs) msg.obj;
956 Log.continueSession((Session) args.arg4, SESSION_HANDLER + SESSION_CREATE_CONN);
957 try {
958 final PhoneAccountHandle connectionManagerPhoneAccount =
959 (PhoneAccountHandle) args.arg1;
960 final String id = (String) args.arg2;
961 final ConnectionRequest request = (ConnectionRequest) args.arg3;
962 final boolean isIncoming = args.argi1 == 1;
963 final boolean isUnknown = args.argi2 == 1;
964 if (!mAreAccountsInitialized) {
965 Log.d(this, "Enqueueing pre-initconference request %s", id);
966 mPreInitializationConnectionRequests.add(
967 new android.telecom.Logging.Runnable(
968 SESSION_HANDLER + SESSION_CREATE_CONF + ".pIConfR",
969 null /*lock*/) {
970 @Override
971 public void loggedRun() {
972 createConference(connectionManagerPhoneAccount,
973 id,
974 request,
975 isIncoming,
976 isUnknown);
977 }
978 }.prepare());
979 } else {
980 createConference(connectionManagerPhoneAccount,
981 id,
982 request,
983 isIncoming,
984 isUnknown);
985 }
986 } finally {
987 args.recycle();
988 Log.endSession();
989 }
990 break;
991 }
992 case MSG_CREATE_CONFERENCE_COMPLETE: {
993 SomeArgs args = (SomeArgs) msg.obj;
994 Log.continueSession((Session) args.arg2,
995 SESSION_HANDLER + SESSION_CREATE_CONN_COMPLETE);
996 try {
997 final String id = (String) args.arg1;
998 if (!mAreAccountsInitialized) {
999 Log.d(this, "Enqueueing pre-init conference request %s", id);
1000 mPreInitializationConnectionRequests.add(
1001 new android.telecom.Logging.Runnable(
1002 SESSION_HANDLER + SESSION_CREATE_CONF_COMPLETE
1003 + ".pIConfR",
1004 null /*lock*/) {
1005 @Override
1006 public void loggedRun() {
1007 notifyCreateConferenceComplete(id);
1008 }
1009 }.prepare());
1010 } else {
1011 notifyCreateConferenceComplete(id);
1012 }
1013 } finally {
1014 args.recycle();
1015 Log.endSession();
1016 }
1017 break;
1018 }
1019 case MSG_CREATE_CONFERENCE_FAILED: {
1020 SomeArgs args = (SomeArgs) msg.obj;
1021 Log.continueSession((Session) args.arg3, SESSION_HANDLER +
1022 SESSION_CREATE_CONN_FAILED);
1023 try {
1024 final String id = (String) args.arg1;
1025 final ConnectionRequest request = (ConnectionRequest) args.arg2;
1026 final boolean isIncoming = args.argi1 == 1;
1027 final PhoneAccountHandle connectionMgrPhoneAccount =
1028 (PhoneAccountHandle) args.arg4;
1029 if (!mAreAccountsInitialized) {
1030 Log.d(this, "Enqueueing pre-init conference request %s", id);
1031 mPreInitializationConnectionRequests.add(
1032 new android.telecom.Logging.Runnable(
1033 SESSION_HANDLER + SESSION_CREATE_CONF_FAILED
1034 + ".pIConfR",
1035 null /*lock*/) {
1036 @Override
1037 public void loggedRun() {
1038 createConferenceFailed(connectionMgrPhoneAccount, id,
1039 request, isIncoming);
1040 }
1041 }.prepare());
1042 } else {
1043 Log.i(this, "createConferenceFailed %s", id);
1044 createConferenceFailed(connectionMgrPhoneAccount, id, request,
1045 isIncoming);
1046 }
1047 } finally {
1048 args.recycle();
1049 Log.endSession();
1050 }
1051 break;
1052 }
1053
Sanket Padawe4cc8ed52017-12-04 16:22:20 -08001054 case MSG_HANDOVER_FAILED: {
1055 SomeArgs args = (SomeArgs) msg.obj;
1056 Log.continueSession((Session) args.arg3, SESSION_HANDLER +
1057 SESSION_HANDOVER_FAILED);
1058 try {
1059 final String id = (String) args.arg1;
1060 final ConnectionRequest request = (ConnectionRequest) args.arg2;
1061 final int reason = (int) args.arg4;
1062 if (!mAreAccountsInitialized) {
1063 Log.d(this, "Enqueueing pre-init request %s", id);
1064 mPreInitializationConnectionRequests.add(
1065 new android.telecom.Logging.Runnable(
1066 SESSION_HANDLER
1067 + SESSION_HANDOVER_FAILED + ".pICR",
1068 null /*lock*/) {
1069 @Override
1070 public void loggedRun() {
1071 handoverFailed(id, request, reason);
1072 }
1073 }.prepare());
1074 } else {
1075 Log.i(this, "createConnectionFailed %s", id);
1076 handoverFailed(id, request, reason);
1077 }
1078 } finally {
1079 args.recycle();
1080 Log.endSession();
1081 }
1082 break;
1083 }
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001084 case MSG_ABORT: {
1085 SomeArgs args = (SomeArgs) msg.obj;
1086 Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_ABORT);
1087 try {
1088 abort((String) args.arg1);
1089 } finally {
1090 args.recycle();
1091 Log.endSession();
1092 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001093 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001094 }
1095 case MSG_ANSWER: {
1096 SomeArgs args = (SomeArgs) msg.obj;
1097 Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_ANSWER);
1098 try {
1099 answer((String) args.arg1);
1100 } finally {
1101 args.recycle();
1102 Log.endSession();
1103 }
Tyler Gunnbe74de02014-08-29 14:51:48 -07001104 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001105 }
Tyler Gunnbe74de02014-08-29 14:51:48 -07001106 case MSG_ANSWER_VIDEO: {
Andrew Lee8da4c3c2014-07-16 10:11:42 -07001107 SomeArgs args = (SomeArgs) msg.obj;
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001108 Log.continueSession((Session) args.arg2,
1109 SESSION_HANDLER + SESSION_ANSWER_VIDEO);
Andrew Lee8da4c3c2014-07-16 10:11:42 -07001110 try {
1111 String callId = (String) args.arg1;
Evan Charltonbf11f982014-07-20 22:06:28 -07001112 int videoState = args.argi1;
Tyler Gunnbe74de02014-08-29 14:51:48 -07001113 answerVideo(callId, videoState);
Andrew Lee8da4c3c2014-07-16 10:11:42 -07001114 } finally {
1115 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001116 Log.endSession();
Andrew Lee8da4c3c2014-07-16 10:11:42 -07001117 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001118 break;
Andrew Lee8da4c3c2014-07-16 10:11:42 -07001119 }
Pooja Jaind34698d2017-12-28 14:15:31 +05301120 case MSG_DEFLECT: {
1121 SomeArgs args = (SomeArgs) msg.obj;
1122 Log.continueSession((Session) args.arg3, SESSION_HANDLER + SESSION_DEFLECT);
1123 try {
1124 deflect((String) args.arg1, (Uri) args.arg2);
1125 } finally {
1126 args.recycle();
1127 Log.endSession();
1128 }
1129 break;
1130 }
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001131 case MSG_REJECT: {
1132 SomeArgs args = (SomeArgs) msg.obj;
1133 Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_REJECT);
1134 try {
1135 reject((String) args.arg1);
1136 } finally {
1137 args.recycle();
1138 Log.endSession();
1139 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001140 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001141 }
Tyler Gunnfacfdee2020-01-23 13:10:37 -08001142 case MSG_REJECT_WITH_REASON: {
1143 SomeArgs args = (SomeArgs) msg.obj;
1144 Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_REJECT);
1145 try {
1146 reject((String) args.arg1, args.argi1);
1147 } finally {
1148 args.recycle();
1149 Log.endSession();
1150 }
1151 break;
1152 }
Bryce Lee81901682015-08-28 16:38:02 -07001153 case MSG_REJECT_WITH_MESSAGE: {
1154 SomeArgs args = (SomeArgs) msg.obj;
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001155 Log.continueSession((Session) args.arg3,
1156 SESSION_HANDLER + SESSION_REJECT_MESSAGE);
Bryce Lee81901682015-08-28 16:38:02 -07001157 try {
1158 reject((String) args.arg1, (String) args.arg2);
1159 } finally {
1160 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001161 Log.endSession();
Bryce Lee81901682015-08-28 16:38:02 -07001162 }
1163 break;
1164 }
Ravi Palurif4b38e72020-02-05 12:35:41 +05301165 case MSG_EXPLICIT_CALL_TRANSFER: {
1166 SomeArgs args = (SomeArgs) msg.obj;
1167 Log.continueSession((Session) args.arg3, SESSION_HANDLER + SESSION_TRANSFER);
1168 try {
1169 final boolean isConfirmationRequired = args.argi1 == 1;
1170 transfer((String) args.arg1, (Uri) args.arg2, isConfirmationRequired);
1171 } finally {
1172 args.recycle();
1173 Log.endSession();
1174 }
1175 break;
1176 }
1177 case MSG_EXPLICIT_CALL_TRANSFER_CONSULTATIVE: {
1178 SomeArgs args = (SomeArgs) msg.obj;
1179 Log.continueSession(
1180 (Session) args.arg3, SESSION_HANDLER + SESSION_CONSULTATIVE_TRANSFER);
1181 try {
1182 consultativeTransfer((String) args.arg1, (String) args.arg2);
1183 } finally {
1184 args.recycle();
1185 Log.endSession();
1186 }
1187 break;
1188 }
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001189 case MSG_DISCONNECT: {
1190 SomeArgs args = (SomeArgs) msg.obj;
1191 Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_DISCONNECT);
1192 try {
1193 disconnect((String) args.arg1);
1194 } finally {
1195 args.recycle();
1196 Log.endSession();
1197 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001198 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001199 }
1200 case MSG_SILENCE: {
1201 SomeArgs args = (SomeArgs) msg.obj;
1202 Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_SILENCE);
1203 try {
1204 silence((String) args.arg1);
1205 } finally {
1206 args.recycle();
1207 Log.endSession();
1208 }
Bryce Leecac50772015-11-17 15:13:29 -08001209 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001210 }
1211 case MSG_HOLD: {
1212 SomeArgs args = (SomeArgs) msg.obj;
1213 Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_REJECT);
1214 try {
1215 hold((String) args.arg1);
1216 } finally {
1217 args.recycle();
1218 Log.endSession();
1219 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001220 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001221 }
1222 case MSG_UNHOLD: {
1223 SomeArgs args = (SomeArgs) msg.obj;
1224 Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_UNHOLD);
1225 try {
1226 unhold((String) args.arg1);
1227 } finally {
1228 args.recycle();
1229 Log.endSession();
1230 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001231 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001232 }
Yorke Lee4af59352015-05-13 14:14:54 -07001233 case MSG_ON_CALL_AUDIO_STATE_CHANGED: {
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001234 SomeArgs args = (SomeArgs) msg.obj;
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001235 Log.continueSession((Session) args.arg3,
1236 SESSION_HANDLER + SESSION_CALL_AUDIO_SC);
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001237 try {
1238 String callId = (String) args.arg1;
Yorke Lee4af59352015-05-13 14:14:54 -07001239 CallAudioState audioState = (CallAudioState) args.arg2;
1240 onCallAudioStateChanged(callId, new CallAudioState(audioState));
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001241 } finally {
1242 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001243 Log.endSession();
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001244 }
1245 break;
1246 }
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001247 case MSG_PLAY_DTMF_TONE: {
1248 SomeArgs args = (SomeArgs) msg.obj;
1249 try {
1250 Log.continueSession((Session) args.arg3,
1251 SESSION_HANDLER + SESSION_PLAY_DTMF);
1252 playDtmfTone((String) args.arg2, (char) args.arg1);
1253 } finally {
1254 args.recycle();
1255 Log.endSession();
1256 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001257 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001258 }
1259 case MSG_STOP_DTMF_TONE: {
1260 SomeArgs args = (SomeArgs) msg.obj;
1261 try {
1262 Log.continueSession((Session) args.arg2,
1263 SESSION_HANDLER + SESSION_STOP_DTMF);
1264 stopDtmfTone((String) args.arg1);
1265 } finally {
1266 args.recycle();
1267 Log.endSession();
1268 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001269 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001270 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001271 case MSG_CONFERENCE: {
1272 SomeArgs args = (SomeArgs) msg.obj;
1273 try {
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001274 Log.continueSession((Session) args.arg3,
1275 SESSION_HANDLER + SESSION_CONFERENCE);
Santos Cordon823fd3c2014-08-07 18:35:18 -07001276 String callId1 = (String) args.arg1;
1277 String callId2 = (String) args.arg2;
1278 conference(callId1, callId2);
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001279 } finally {
1280 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001281 Log.endSession();
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001282 }
1283 break;
1284 }
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001285 case MSG_SPLIT_FROM_CONFERENCE: {
1286 SomeArgs args = (SomeArgs) msg.obj;
1287 try {
1288 Log.continueSession((Session) args.arg2,
1289 SESSION_HANDLER + SESSION_SPLIT_CONFERENCE);
1290 splitFromConference((String) args.arg1);
1291 } finally {
1292 args.recycle();
1293 Log.endSession();
1294 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001295 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001296 }
1297 case MSG_MERGE_CONFERENCE: {
1298 SomeArgs args = (SomeArgs) msg.obj;
1299 try {
1300 Log.continueSession((Session) args.arg2,
1301 SESSION_HANDLER + SESSION_MERGE_CONFERENCE);
1302 mergeConference((String) args.arg1);
1303 } finally {
1304 args.recycle();
1305 Log.endSession();
1306 }
Santos Cordona4868042014-09-04 17:39:22 -07001307 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001308 }
1309 case MSG_SWAP_CONFERENCE: {
1310 SomeArgs args = (SomeArgs) msg.obj;
1311 try {
1312 Log.continueSession((Session) args.arg2,
1313 SESSION_HANDLER + SESSION_SWAP_CONFERENCE);
1314 swapConference((String) args.arg1);
1315 } finally {
1316 args.recycle();
1317 Log.endSession();
1318 }
Santos Cordona4868042014-09-04 17:39:22 -07001319 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001320 }
Ravi Paluri404babb2020-01-23 19:02:44 +05301321 case MSG_ADD_PARTICIPANT: {
1322 SomeArgs args = (SomeArgs) msg.obj;
1323 try {
1324 Log.continueSession((Session) args.arg3,
1325 SESSION_HANDLER + SESSION_ADD_PARTICIPANT);
1326 addConferenceParticipants((String) args.arg1, (List<Uri>)args.arg2);
1327 } finally {
1328 args.recycle();
1329 Log.endSession();
1330 }
1331 break;
1332 }
1333
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001334 case MSG_ON_POST_DIAL_CONTINUE: {
1335 SomeArgs args = (SomeArgs) msg.obj;
1336 try {
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001337 Log.continueSession((Session) args.arg2,
1338 SESSION_HANDLER + SESSION_POST_DIAL_CONT);
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001339 String callId = (String) args.arg1;
1340 boolean proceed = (args.argi1 == 1);
1341 onPostDialContinue(callId, proceed);
1342 } finally {
1343 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001344 Log.endSession();
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001345 }
1346 break;
1347 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001348 case MSG_PULL_EXTERNAL_CALL: {
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001349 SomeArgs args = (SomeArgs) msg.obj;
1350 try {
1351 Log.continueSession((Session) args.arg2,
1352 SESSION_HANDLER + SESSION_PULL_EXTERNAL_CALL);
1353 pullExternalCall((String) args.arg1);
1354 } finally {
1355 args.recycle();
1356 Log.endSession();
1357 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001358 break;
1359 }
1360 case MSG_SEND_CALL_EVENT: {
1361 SomeArgs args = (SomeArgs) msg.obj;
1362 try {
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001363 Log.continueSession((Session) args.arg4,
1364 SESSION_HANDLER + SESSION_SEND_CALL_EVENT);
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001365 String callId = (String) args.arg1;
1366 String event = (String) args.arg2;
1367 Bundle extras = (Bundle) args.arg3;
1368 sendCallEvent(callId, event, extras);
1369 } finally {
1370 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001371 Log.endSession();
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001372 }
1373 break;
1374 }
Hall Liu49cabcc2021-01-15 11:41:48 -08001375 case MSG_ON_CALL_FILTERING_COMPLETED: {
1376 SomeArgs args = (SomeArgs) msg.obj;
1377 try {
1378 Log.continueSession((Session) args.arg4,
1379 SESSION_HANDLER + SESSION_CALL_FILTERING_COMPLETED);
1380 String callId = (String) args.arg1;
1381 boolean isBlocked = (boolean) args.arg2;
1382 boolean isInContacts = (boolean) args.arg3;
1383 onCallFilteringCompleted(callId, isBlocked, isInContacts);
1384 } finally {
1385 args.recycle();
1386 Log.endSession();
1387 }
1388 break;
1389 }
Tyler Gunn79bc1ec2018-01-22 15:17:54 -08001390 case MSG_HANDOVER_COMPLETE: {
1391 SomeArgs args = (SomeArgs) msg.obj;
1392 try {
1393 Log.continueSession((Session) args.arg2,
1394 SESSION_HANDLER + SESSION_HANDOVER_COMPLETE);
1395 String callId = (String) args.arg1;
1396 notifyHandoverComplete(callId);
1397 } finally {
1398 args.recycle();
1399 Log.endSession();
1400 }
1401 break;
1402 }
Tyler Gunndee56a82016-03-23 16:06:34 -07001403 case MSG_ON_EXTRAS_CHANGED: {
1404 SomeArgs args = (SomeArgs) msg.obj;
1405 try {
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001406 Log.continueSession((Session) args.arg3,
1407 SESSION_HANDLER + SESSION_EXTRAS_CHANGED);
Tyler Gunndee56a82016-03-23 16:06:34 -07001408 String callId = (String) args.arg1;
1409 Bundle extras = (Bundle) args.arg2;
1410 handleExtrasChanged(callId, extras);
1411 } finally {
1412 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001413 Log.endSession();
Tyler Gunndee56a82016-03-23 16:06:34 -07001414 }
1415 break;
1416 }
Hall Liub64ac4c2017-02-06 10:49:48 -08001417 case MSG_ON_START_RTT: {
1418 SomeArgs args = (SomeArgs) msg.obj;
1419 try {
1420 Log.continueSession((Session) args.arg3,
1421 SESSION_HANDLER + SESSION_START_RTT);
1422 String callId = (String) args.arg1;
1423 Connection.RttTextStream rttTextStream =
1424 (Connection.RttTextStream) args.arg2;
1425 startRtt(callId, rttTextStream);
1426 } finally {
1427 args.recycle();
1428 Log.endSession();
1429 }
1430 break;
1431 }
1432 case MSG_ON_STOP_RTT: {
1433 SomeArgs args = (SomeArgs) msg.obj;
1434 try {
1435 Log.continueSession((Session) args.arg2,
1436 SESSION_HANDLER + SESSION_STOP_RTT);
1437 String callId = (String) args.arg1;
1438 stopRtt(callId);
1439 } finally {
1440 args.recycle();
1441 Log.endSession();
1442 }
1443 break;
1444 }
1445 case MSG_RTT_UPGRADE_RESPONSE: {
1446 SomeArgs args = (SomeArgs) msg.obj;
1447 try {
1448 Log.continueSession((Session) args.arg3,
1449 SESSION_HANDLER + SESSION_RTT_UPGRADE_RESPONSE);
1450 String callId = (String) args.arg1;
1451 Connection.RttTextStream rttTextStream =
1452 (Connection.RttTextStream) args.arg2;
1453 handleRttUpgradeResponse(callId, rttTextStream);
1454 } finally {
1455 args.recycle();
1456 Log.endSession();
1457 }
1458 break;
1459 }
Pengquan Meng731c1a32017-11-21 18:01:13 -08001460 case MSG_CONNECTION_SERVICE_FOCUS_GAINED:
1461 onConnectionServiceFocusGained();
1462 break;
1463 case MSG_CONNECTION_SERVICE_FOCUS_LOST:
1464 onConnectionServiceFocusLost();
1465 break;
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001466 default:
1467 break;
1468 }
1469 }
1470 };
1471
Santos Cordon823fd3c2014-08-07 18:35:18 -07001472 private final Conference.Listener mConferenceListener = new Conference.Listener() {
1473 @Override
1474 public void onStateChanged(Conference conference, int oldState, int newState) {
1475 String id = mIdByConference.get(conference);
1476 switch (newState) {
Ravi Paluri80aa2142019-12-02 11:57:37 +05301477 case Connection.STATE_RINGING:
1478 mAdapter.setRinging(id);
1479 break;
1480 case Connection.STATE_DIALING:
1481 mAdapter.setDialing(id);
1482 break;
Santos Cordon823fd3c2014-08-07 18:35:18 -07001483 case Connection.STATE_ACTIVE:
1484 mAdapter.setActive(id);
1485 break;
1486 case Connection.STATE_HOLDING:
1487 mAdapter.setOnHold(id);
1488 break;
1489 case Connection.STATE_DISCONNECTED:
1490 // handled by onDisconnected
1491 break;
1492 }
1493 }
1494
1495 @Override
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001496 public void onDisconnected(Conference conference, DisconnectCause disconnectCause) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07001497 String id = mIdByConference.get(conference);
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001498 mAdapter.setDisconnected(id, disconnectCause);
Santos Cordon823fd3c2014-08-07 18:35:18 -07001499 }
1500
1501 @Override
1502 public void onConnectionAdded(Conference conference, Connection connection) {
1503 }
1504
1505 @Override
1506 public void onConnectionRemoved(Conference conference, Connection connection) {
1507 }
1508
1509 @Override
Ihab Awad50e35062014-09-30 09:17:03 -07001510 public void onConferenceableConnectionsChanged(
1511 Conference conference, List<Connection> conferenceableConnections) {
1512 mAdapter.setConferenceableConnections(
1513 mIdByConference.get(conference),
1514 createConnectionIdList(conferenceableConnections));
1515 }
1516
1517 @Override
Santos Cordon823fd3c2014-08-07 18:35:18 -07001518 public void onDestroyed(Conference conference) {
1519 removeConference(conference);
1520 }
1521
1522 @Override
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001523 public void onConnectionCapabilitiesChanged(
1524 Conference conference,
1525 int connectionCapabilities) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07001526 String id = mIdByConference.get(conference);
1527 Log.d(this, "call capabilities: conference: %s",
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001528 Connection.capabilitiesToString(connectionCapabilities));
1529 mAdapter.setConnectionCapabilities(id, connectionCapabilities);
Santos Cordon823fd3c2014-08-07 18:35:18 -07001530 }
Rekha Kumar07366812015-03-24 16:42:31 -07001531
1532 @Override
Tyler Gunn720c6642016-03-22 09:02:47 -07001533 public void onConnectionPropertiesChanged(
1534 Conference conference,
1535 int connectionProperties) {
1536 String id = mIdByConference.get(conference);
1537 Log.d(this, "call capabilities: conference: %s",
1538 Connection.propertiesToString(connectionProperties));
1539 mAdapter.setConnectionProperties(id, connectionProperties);
1540 }
1541
1542 @Override
Rekha Kumar07366812015-03-24 16:42:31 -07001543 public void onVideoStateChanged(Conference c, int videoState) {
1544 String id = mIdByConference.get(c);
1545 Log.d(this, "onVideoStateChanged set video state %d", videoState);
1546 mAdapter.setVideoState(id, videoState);
1547 }
1548
1549 @Override
1550 public void onVideoProviderChanged(Conference c, Connection.VideoProvider videoProvider) {
1551 String id = mIdByConference.get(c);
1552 Log.d(this, "onVideoProviderChanged: Connection: %s, VideoProvider: %s", c,
1553 videoProvider);
1554 mAdapter.setVideoProvider(id, videoProvider);
1555 }
Andrew Lee0f51da32015-04-16 13:11:55 -07001556
1557 @Override
Andrew Leeedc625f2015-04-14 13:38:12 -07001558 public void onStatusHintsChanged(Conference conference, StatusHints statusHints) {
1559 String id = mIdByConference.get(conference);
Tyler Gunndee56a82016-03-23 16:06:34 -07001560 if (id != null) {
1561 mAdapter.setStatusHints(id, statusHints);
1562 }
Andrew Leeedc625f2015-04-14 13:38:12 -07001563 }
Santos Cordon6b7f9552015-05-27 17:21:45 -07001564
1565 @Override
Tyler Gunndee56a82016-03-23 16:06:34 -07001566 public void onExtrasChanged(Conference c, Bundle extras) {
1567 String id = mIdByConference.get(c);
1568 if (id != null) {
1569 mAdapter.putExtras(id, extras);
1570 }
1571 }
1572
1573 @Override
1574 public void onExtrasRemoved(Conference c, List<String> keys) {
1575 String id = mIdByConference.get(c);
1576 if (id != null) {
1577 mAdapter.removeExtras(id, keys);
1578 }
Santos Cordon6b7f9552015-05-27 17:21:45 -07001579 }
Tyler Gunn68a73a42018-10-03 15:38:57 -07001580
1581 @Override
1582 public void onConferenceStateChanged(Conference c, boolean isConference) {
1583 String id = mIdByConference.get(c);
1584 if (id != null) {
1585 mAdapter.setConferenceState(id, isConference);
1586 }
1587 }
1588
1589 @Override
Brad Ebingere0c12f42020-04-08 16:25:12 -07001590 public void onCallDirectionChanged(Conference c, int direction) {
1591 String id = mIdByConference.get(c);
1592 if (id != null) {
1593 mAdapter.setCallDirection(id, direction);
1594 }
1595 }
1596
1597 @Override
Tyler Gunn68a73a42018-10-03 15:38:57 -07001598 public void onAddressChanged(Conference c, Uri newAddress, int presentation) {
1599 String id = mIdByConference.get(c);
1600 if (id != null) {
1601 mAdapter.setAddress(id, newAddress, presentation);
1602 }
1603 }
1604
1605 @Override
1606 public void onCallerDisplayNameChanged(Conference c, String callerDisplayName,
1607 int presentation) {
1608 String id = mIdByConference.get(c);
1609 if (id != null) {
1610 mAdapter.setCallerDisplayName(id, callerDisplayName, presentation);
1611 }
1612 }
Hall Liuc9bc1c62019-04-16 14:00:55 -07001613
1614 @Override
1615 public void onConnectionEvent(Conference c, String event, Bundle extras) {
1616 String id = mIdByConference.get(c);
1617 if (id != null) {
1618 mAdapter.onConnectionEvent(id, event, extras);
1619 }
1620 }
Ravi Paluri80aa2142019-12-02 11:57:37 +05301621
1622 @Override
1623 public void onRingbackRequested(Conference c, boolean ringback) {
1624 String id = mIdByConference.get(c);
1625 Log.d(this, "Adapter conference onRingback %b", ringback);
1626 mAdapter.setRingbackRequested(id, ringback);
1627 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07001628 };
1629
Ihab Awad542e0ea2014-05-16 10:22:16 -07001630 private final Connection.Listener mConnectionListener = new Connection.Listener() {
1631 @Override
1632 public void onStateChanged(Connection c, int state) {
1633 String id = mIdByConnection.get(c);
Ihab Awad42b30e12014-05-22 09:49:34 -07001634 Log.d(this, "Adapter set state %s %s", id, Connection.stateToString(state));
Ihab Awad542e0ea2014-05-16 10:22:16 -07001635 switch (state) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001636 case Connection.STATE_ACTIVE:
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001637 mAdapter.setActive(id);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001638 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001639 case Connection.STATE_DIALING:
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001640 mAdapter.setDialing(id);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001641 break;
Tyler Gunnc96b5e02016-07-07 22:53:57 -07001642 case Connection.STATE_PULLING_CALL:
1643 mAdapter.setPulling(id);
1644 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001645 case Connection.STATE_DISCONNECTED:
Ihab Awad542e0ea2014-05-16 10:22:16 -07001646 // Handled in onDisconnected()
1647 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001648 case Connection.STATE_HOLDING:
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001649 mAdapter.setOnHold(id);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001650 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001651 case Connection.STATE_NEW:
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001652 // Nothing to tell Telecom
Ihab Awad542e0ea2014-05-16 10:22:16 -07001653 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001654 case Connection.STATE_RINGING:
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001655 mAdapter.setRinging(id);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001656 break;
1657 }
1658 }
1659
1660 @Override
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001661 public void onDisconnected(Connection c, DisconnectCause disconnectCause) {
Ihab Awad542e0ea2014-05-16 10:22:16 -07001662 String id = mIdByConnection.get(c);
Andrew Lee26786392014-09-16 18:14:59 -07001663 Log.d(this, "Adapter set disconnected %s", disconnectCause);
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001664 mAdapter.setDisconnected(id, disconnectCause);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001665 }
1666
1667 @Override
Tyler Gunnaa07df82014-07-17 07:50:22 -07001668 public void onVideoStateChanged(Connection c, int videoState) {
1669 String id = mIdByConnection.get(c);
1670 Log.d(this, "Adapter set video state %d", videoState);
1671 mAdapter.setVideoState(id, videoState);
1672 }
1673
1674 @Override
Andrew Lee100e2932014-09-08 15:34:24 -07001675 public void onAddressChanged(Connection c, Uri address, int presentation) {
Sailesh Nepal61203862014-07-11 14:50:13 -07001676 String id = mIdByConnection.get(c);
Andrew Lee100e2932014-09-08 15:34:24 -07001677 mAdapter.setAddress(id, address, presentation);
Sailesh Nepal61203862014-07-11 14:50:13 -07001678 }
1679
1680 @Override
1681 public void onCallerDisplayNameChanged(
1682 Connection c, String callerDisplayName, int presentation) {
1683 String id = mIdByConnection.get(c);
1684 mAdapter.setCallerDisplayName(id, callerDisplayName, presentation);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001685 }
1686
1687 @Override
Ihab Awad542e0ea2014-05-16 10:22:16 -07001688 public void onDestroyed(Connection c) {
1689 removeConnection(c);
1690 }
Ihab Awadf8358972014-05-28 16:46:42 -07001691
1692 @Override
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001693 public void onPostDialWait(Connection c, String remaining) {
Sailesh Nepal091768c2014-06-30 15:15:23 -07001694 String id = mIdByConnection.get(c);
1695 Log.d(this, "Adapter onPostDialWait %s, %s", c, remaining);
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001696 mAdapter.onPostDialWait(id, remaining);
Sailesh Nepal091768c2014-06-30 15:15:23 -07001697 }
1698
1699 @Override
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001700 public void onPostDialChar(Connection c, char nextChar) {
1701 String id = mIdByConnection.get(c);
1702 Log.d(this, "Adapter onPostDialChar %s, %s", c, nextChar);
1703 mAdapter.onPostDialChar(id, nextChar);
1704 }
1705
1706 @Override
Andrew Lee100e2932014-09-08 15:34:24 -07001707 public void onRingbackRequested(Connection c, boolean ringback) {
Ihab Awadf8358972014-05-28 16:46:42 -07001708 String id = mIdByConnection.get(c);
1709 Log.d(this, "Adapter onRingback %b", ringback);
Andrew Lee100e2932014-09-08 15:34:24 -07001710 mAdapter.setRingbackRequested(id, ringback);
Ihab Awadf8358972014-05-28 16:46:42 -07001711 }
Santos Cordonb6939982014-06-04 20:20:58 -07001712
1713 @Override
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001714 public void onConnectionCapabilitiesChanged(Connection c, int capabilities) {
Santos Cordonb6939982014-06-04 20:20:58 -07001715 String id = mIdByConnection.get(c);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001716 Log.d(this, "capabilities: parcelableconnection: %s",
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001717 Connection.capabilitiesToString(capabilities));
1718 mAdapter.setConnectionCapabilities(id, capabilities);
Santos Cordonb6939982014-06-04 20:20:58 -07001719 }
1720
Santos Cordonb6939982014-06-04 20:20:58 -07001721 @Override
Tyler Gunn720c6642016-03-22 09:02:47 -07001722 public void onConnectionPropertiesChanged(Connection c, int properties) {
1723 String id = mIdByConnection.get(c);
1724 Log.d(this, "properties: parcelableconnection: %s",
1725 Connection.propertiesToString(properties));
1726 mAdapter.setConnectionProperties(id, properties);
1727 }
1728
1729 @Override
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001730 public void onVideoProviderChanged(Connection c, Connection.VideoProvider videoProvider) {
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07001731 String id = mIdByConnection.get(c);
Rekha Kumar07366812015-03-24 16:42:31 -07001732 Log.d(this, "onVideoProviderChanged: Connection: %s, VideoProvider: %s", c,
1733 videoProvider);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001734 mAdapter.setVideoProvider(id, videoProvider);
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07001735 }
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001736
1737 @Override
Sailesh Nepal001bbbb2014-07-15 14:40:39 -07001738 public void onAudioModeIsVoipChanged(Connection c, boolean isVoip) {
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001739 String id = mIdByConnection.get(c);
Andrew Lee100e2932014-09-08 15:34:24 -07001740 mAdapter.setIsVoipAudioMode(id, isVoip);
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001741 }
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001742
1743 @Override
Sailesh Nepal001bbbb2014-07-15 14:40:39 -07001744 public void onStatusHintsChanged(Connection c, StatusHints statusHints) {
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001745 String id = mIdByConnection.get(c);
1746 mAdapter.setStatusHints(id, statusHints);
1747 }
Sailesh Nepal2ab88cc2014-07-18 14:49:18 -07001748
1749 @Override
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001750 public void onConferenceablesChanged(
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001751 Connection connection, List<Conferenceable> conferenceables) {
Ihab Awadb8e85c72014-08-23 20:34:57 -07001752 mAdapter.setConferenceableConnections(
1753 mIdByConnection.get(connection),
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001754 createIdList(conferenceables));
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001755 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07001756
1757 @Override
1758 public void onConferenceChanged(Connection connection, Conference conference) {
1759 String id = mIdByConnection.get(connection);
1760 if (id != null) {
1761 String conferenceId = null;
1762 if (conference != null) {
1763 conferenceId = mIdByConference.get(conference);
1764 }
1765 mAdapter.setIsConferenced(id, conferenceId);
1766 }
1767 }
Anthony Lee17455a32015-04-24 15:25:29 -07001768
1769 @Override
1770 public void onConferenceMergeFailed(Connection connection) {
1771 String id = mIdByConnection.get(connection);
1772 if (id != null) {
1773 mAdapter.onConferenceMergeFailed(id);
1774 }
1775 }
Santos Cordon6b7f9552015-05-27 17:21:45 -07001776
1777 @Override
Tyler Gunndee56a82016-03-23 16:06:34 -07001778 public void onExtrasChanged(Connection c, Bundle extras) {
1779 String id = mIdByConnection.get(c);
Santos Cordon6b7f9552015-05-27 17:21:45 -07001780 if (id != null) {
Tyler Gunndee56a82016-03-23 16:06:34 -07001781 mAdapter.putExtras(id, extras);
Santos Cordon6b7f9552015-05-27 17:21:45 -07001782 }
1783 }
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001784
Tyler Gunnf5035432017-01-09 09:43:12 -08001785 @Override
Tyler Gunndee56a82016-03-23 16:06:34 -07001786 public void onExtrasRemoved(Connection c, List<String> keys) {
1787 String id = mIdByConnection.get(c);
1788 if (id != null) {
1789 mAdapter.removeExtras(id, keys);
1790 }
1791 }
1792
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08001793 @Override
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001794 public void onConnectionEvent(Connection connection, String event, Bundle extras) {
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08001795 String id = mIdByConnection.get(connection);
1796 if (id != null) {
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001797 mAdapter.onConnectionEvent(id, event, extras);
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08001798 }
1799 }
Tyler Gunnf5035432017-01-09 09:43:12 -08001800
1801 @Override
Hall Liua98f58b52017-11-07 17:59:28 -08001802 public void onAudioRouteChanged(Connection c, int audioRoute, String bluetoothAddress) {
Tyler Gunnf5035432017-01-09 09:43:12 -08001803 String id = mIdByConnection.get(c);
1804 if (id != null) {
Hall Liua98f58b52017-11-07 17:59:28 -08001805 mAdapter.setAudioRoute(id, audioRoute, bluetoothAddress);
Tyler Gunnf5035432017-01-09 09:43:12 -08001806 }
1807 }
Hall Liub64ac4c2017-02-06 10:49:48 -08001808
1809 @Override
1810 public void onRttInitiationSuccess(Connection c) {
1811 String id = mIdByConnection.get(c);
1812 if (id != null) {
1813 mAdapter.onRttInitiationSuccess(id);
1814 }
1815 }
1816
1817 @Override
1818 public void onRttInitiationFailure(Connection c, int reason) {
1819 String id = mIdByConnection.get(c);
1820 if (id != null) {
1821 mAdapter.onRttInitiationFailure(id, reason);
1822 }
1823 }
1824
1825 @Override
1826 public void onRttSessionRemotelyTerminated(Connection c) {
1827 String id = mIdByConnection.get(c);
1828 if (id != null) {
1829 mAdapter.onRttSessionRemotelyTerminated(id);
1830 }
1831 }
1832
1833 @Override
1834 public void onRemoteRttRequest(Connection c) {
1835 String id = mIdByConnection.get(c);
1836 if (id != null) {
1837 mAdapter.onRemoteRttRequest(id);
1838 }
1839 }
Srikanth Chintalafcb15012017-05-04 20:58:34 +05301840
1841 @Override
1842 public void onPhoneAccountChanged(Connection c, PhoneAccountHandle pHandle) {
1843 String id = mIdByConnection.get(c);
1844 if (id != null) {
1845 mAdapter.onPhoneAccountChanged(id, pHandle);
1846 }
1847 }
Mengjun Leng25707742017-07-04 11:10:37 +08001848
1849 public void onConnectionTimeReset(Connection c) {
1850 String id = mIdByConnection.get(c);
1851 if (id != null) {
1852 mAdapter.resetConnectionTime(id);
1853 }
1854 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001855 };
1856
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001857 /** {@inheritDoc} */
Ihab Awad542e0ea2014-05-16 10:22:16 -07001858 @Override
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001859 public final IBinder onBind(Intent intent) {
1860 return mBinder;
1861 }
1862
Santos Cordon29f2f2e2014-09-11 19:50:24 -07001863 /** {@inheritDoc} */
1864 @Override
1865 public boolean onUnbind(Intent intent) {
1866 endAllConnections();
1867 return super.onUnbind(intent);
1868 }
1869
Ravi Paluri80aa2142019-12-02 11:57:37 +05301870
1871 /**
1872 * This can be used by telecom to either create a new outgoing conference call or attach
1873 * to an existing incoming conference call. In either case, telecom will cycle through a
1874 * set of services and call createConference until a connection service cancels the process
1875 * or completes it successfully.
1876 */
1877 private void createConference(
1878 final PhoneAccountHandle callManagerAccount,
1879 final String callId,
1880 final ConnectionRequest request,
1881 boolean isIncoming,
1882 boolean isUnknown) {
1883
1884 Conference conference = null;
1885 conference = isIncoming ? onCreateIncomingConference(callManagerAccount, request)
1886 : onCreateOutgoingConference(callManagerAccount, request);
1887
1888 Log.d(this, "createConference, conference: %s", conference);
1889 if (conference == null) {
1890 Log.i(this, "createConference, implementation returned null conference.");
1891 conference = Conference.createFailedConference(
1892 new DisconnectCause(DisconnectCause.ERROR, "IMPL_RETURNED_NULL_CONFERENCE"),
1893 request.getAccountHandle());
1894 }
Tyler Gunnc59fd0c2020-04-17 14:03:35 -07001895
1896 Bundle extras = request.getExtras();
1897 Bundle newExtras = new Bundle();
1898 newExtras.putString(Connection.EXTRA_ORIGINAL_CONNECTION_ID, callId);
1899 if (extras != null) {
1900 // If the request originated from a remote connection service, we will add some
1901 // tracking information that Telecom can use to keep informed of which package
1902 // made the remote request, and which remote connection service was used.
1903 if (extras.containsKey(Connection.EXTRA_REMOTE_CONNECTION_ORIGINATING_PACKAGE_NAME)) {
1904 newExtras.putString(
1905 Connection.EXTRA_REMOTE_CONNECTION_ORIGINATING_PACKAGE_NAME,
1906 extras.getString(
1907 Connection.EXTRA_REMOTE_CONNECTION_ORIGINATING_PACKAGE_NAME));
1908 newExtras.putParcelable(Connection.EXTRA_REMOTE_PHONE_ACCOUNT_HANDLE,
1909 request.getAccountHandle());
1910 }
Ravi Paluri80aa2142019-12-02 11:57:37 +05301911 }
Tyler Gunnc59fd0c2020-04-17 14:03:35 -07001912 conference.putExtras(newExtras);
1913
Ravi Paluri80aa2142019-12-02 11:57:37 +05301914 mConferenceById.put(callId, conference);
1915 mIdByConference.put(conference, callId);
Tyler Gunn460360d2020-07-29 10:21:45 -07001916
Ravi Paluri80aa2142019-12-02 11:57:37 +05301917 conference.addListener(mConferenceListener);
Brad Ebinger0ae44ed2020-04-09 15:30:57 -07001918 ParcelableConference parcelableConference = new ParcelableConference.Builder(
1919 request.getAccountHandle(), conference.getState())
1920 .setConnectionCapabilities(conference.getConnectionCapabilities())
1921 .setConnectionProperties(conference.getConnectionProperties())
1922 .setVideoAttributes(conference.getVideoProvider() == null
1923 ? null : conference.getVideoProvider().getInterface(),
1924 conference.getVideoState())
1925 .setConnectTimeMillis(conference.getConnectTimeMillis(),
1926 conference.getConnectionStartElapsedRealtimeMillis())
1927 .setStatusHints(conference.getStatusHints())
1928 .setExtras(conference.getExtras())
1929 .setAddress(conference.getAddress(), conference.getAddressPresentation())
1930 .setCallerDisplayName(conference.getCallerDisplayName(),
1931 conference.getCallerDisplayNamePresentation())
1932 .setDisconnectCause(conference.getDisconnectCause())
1933 .setRingbackRequested(conference.isRingbackRequested())
1934 .build();
Ravi Paluri80aa2142019-12-02 11:57:37 +05301935 if (conference.getState() != Connection.STATE_DISCONNECTED) {
1936 conference.setTelecomCallId(callId);
1937 mAdapter.setVideoProvider(callId, conference.getVideoProvider());
1938 mAdapter.setVideoState(callId, conference.getVideoState());
1939 onConferenceAdded(conference);
1940 }
1941
1942 Log.d(this, "createConference, calling handleCreateConferenceSuccessful %s", callId);
1943 mAdapter.handleCreateConferenceComplete(
1944 callId,
1945 request,
1946 parcelableConference);
1947 }
1948
Sailesh Nepalc5b01572014-07-14 16:29:44 -07001949 /**
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001950 * This can be used by telecom to either create a new outgoing call or attach to an existing
1951 * incoming call. In either case, telecom will cycle through a set of services and call
Sailesh Nepalc5b01572014-07-14 16:29:44 -07001952 * createConnection util a connection service cancels the process or completes it successfully.
1953 */
Ihab Awadf8b69882014-07-25 15:14:01 -07001954 private void createConnection(
1955 final PhoneAccountHandle callManagerAccount,
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001956 final String callId,
Ihab Awadf8b69882014-07-25 15:14:01 -07001957 final ConnectionRequest request,
Yorke Leec3cf9822014-10-02 09:38:39 -07001958 boolean isIncoming,
1959 boolean isUnknown) {
Tyler Gunn79bc1ec2018-01-22 15:17:54 -08001960 boolean isLegacyHandover = request.getExtras() != null &&
1961 request.getExtras().getBoolean(TelecomManager.EXTRA_IS_HANDOVER, false);
1962 boolean isHandover = request.getExtras() != null && request.getExtras().getBoolean(
1963 TelecomManager.EXTRA_IS_HANDOVER_CONNECTION, false);
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001964 Log.d(this, "createConnection, callManagerAccount: %s, callId: %s, request: %s, " +
Tyler Gunn79bc1ec2018-01-22 15:17:54 -08001965 "isIncoming: %b, isUnknown: %b, isLegacyHandover: %b, isHandover: %b",
1966 callManagerAccount, callId, request, isIncoming, isUnknown, isLegacyHandover,
1967 isHandover);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001968
Sanket Padawee29a2662017-12-01 13:59:27 -08001969 Connection connection = null;
Tyler Gunn79bc1ec2018-01-22 15:17:54 -08001970 if (isHandover) {
1971 PhoneAccountHandle fromPhoneAccountHandle = request.getExtras() != null
1972 ? (PhoneAccountHandle) request.getExtras().getParcelable(
1973 TelecomManager.EXTRA_HANDOVER_FROM_PHONE_ACCOUNT) : null;
Sanket Padawee29a2662017-12-01 13:59:27 -08001974 if (!isIncoming) {
Tyler Gunn79bc1ec2018-01-22 15:17:54 -08001975 connection = onCreateOutgoingHandoverConnection(fromPhoneAccountHandle, request);
Sanket Padawee29a2662017-12-01 13:59:27 -08001976 } else {
Tyler Gunn79bc1ec2018-01-22 15:17:54 -08001977 connection = onCreateIncomingHandoverConnection(fromPhoneAccountHandle, request);
Sanket Padawee29a2662017-12-01 13:59:27 -08001978 }
1979 } else {
1980 connection = isUnknown ? onCreateUnknownConnection(callManagerAccount, request)
1981 : isIncoming ? onCreateIncomingConnection(callManagerAccount, request)
1982 : onCreateOutgoingConnection(callManagerAccount, request);
1983 }
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001984 Log.d(this, "createConnection, connection: %s", connection);
1985 if (connection == null) {
Tyler Gunnfba1a8e2017-12-19 15:23:59 -08001986 Log.i(this, "createConnection, implementation returned null connection.");
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001987 connection = Connection.createFailedConnection(
Tyler Gunnfba1a8e2017-12-19 15:23:59 -08001988 new DisconnectCause(DisconnectCause.ERROR, "IMPL_RETURNED_NULL_CONNECTION"));
Tyler Gunnc59fd0c2020-04-17 14:03:35 -07001989 } else {
1990 try {
1991 Bundle extras = request.getExtras();
1992 if (extras != null) {
1993 // If the request originated from a remote connection service, we will add some
1994 // tracking information that Telecom can use to keep informed of which package
1995 // made the remote request, and which remote connection service was used.
1996 if (extras.containsKey(
1997 Connection.EXTRA_REMOTE_CONNECTION_ORIGINATING_PACKAGE_NAME)) {
1998 Bundle newExtras = new Bundle();
1999 newExtras.putString(
2000 Connection.EXTRA_REMOTE_CONNECTION_ORIGINATING_PACKAGE_NAME,
2001 extras.getString(
2002 Connection.EXTRA_REMOTE_CONNECTION_ORIGINATING_PACKAGE_NAME
2003 ));
2004 newExtras.putParcelable(Connection.EXTRA_REMOTE_PHONE_ACCOUNT_HANDLE,
2005 request.getAccountHandle());
2006 connection.putExtras(newExtras);
2007 }
2008 }
2009 } catch (UnsupportedOperationException ose) {
2010 // Do nothing; if the ConnectionService reported a failure it will be an instance
2011 // of an immutable Connection which we cannot edit, so we're out of luck.
2012 }
Sailesh Nepalc5b01572014-07-14 16:29:44 -07002013 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002014
Tyler Gunnf2e08b42018-05-24 10:44:44 -07002015 boolean isSelfManaged =
2016 (connection.getConnectionProperties() & Connection.PROPERTY_SELF_MANAGED)
2017 == Connection.PROPERTY_SELF_MANAGED;
2018 // Self-managed Connections should always use voip audio mode; we default here so that the
2019 // local state within the ConnectionService matches the default we assume in Telecom.
2020 if (isSelfManaged) {
2021 connection.setAudioModeIsVoip(true);
2022 }
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002023 connection.setTelecomCallId(callId);
Sungjae7f4137452020-09-16 17:01:54 +09002024 PhoneAccountHandle phoneAccountHandle = connection.getPhoneAccountHandle() == null
2025 ? request.getAccountHandle() : connection.getPhoneAccountHandle();
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07002026 if (connection.getState() != Connection.STATE_DISCONNECTED) {
Sungjae7f4137452020-09-16 17:01:54 +09002027 addConnection(phoneAccountHandle, callId, connection);
Ihab Awad6107bab2014-08-18 09:23:25 -07002028 }
2029
Andrew Lee100e2932014-09-08 15:34:24 -07002030 Uri address = connection.getAddress();
2031 String number = address == null ? "null" : address.getSchemeSpecificPart();
Tyler Gunn720c6642016-03-22 09:02:47 -07002032 Log.v(this, "createConnection, number: %s, state: %s, capabilities: %s, properties: %s",
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002033 Connection.toLogSafePhoneNumber(number),
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07002034 Connection.stateToString(connection.getState()),
Tyler Gunn720c6642016-03-22 09:02:47 -07002035 Connection.capabilitiesToString(connection.getConnectionCapabilities()),
2036 Connection.propertiesToString(connection.getConnectionProperties()));
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002037
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07002038 Log.d(this, "createConnection, calling handleCreateConnectionSuccessful %s", callId);
Ihab Awad6107bab2014-08-18 09:23:25 -07002039 mAdapter.handleCreateConnectionComplete(
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002040 callId,
Evan Charltonbf11f982014-07-20 22:06:28 -07002041 request,
2042 new ParcelableConnection(
Sungjae7f4137452020-09-16 17:01:54 +09002043 phoneAccountHandle,
Evan Charltonbf11f982014-07-20 22:06:28 -07002044 connection.getState(),
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002045 connection.getConnectionCapabilities(),
Tyler Gunn720c6642016-03-22 09:02:47 -07002046 connection.getConnectionProperties(),
Christine Hallstrom2830ce92016-11-30 16:06:42 -08002047 connection.getSupportedAudioRoutes(),
Andrew Lee100e2932014-09-08 15:34:24 -07002048 connection.getAddress(),
2049 connection.getAddressPresentation(),
Evan Charltonbf11f982014-07-20 22:06:28 -07002050 connection.getCallerDisplayName(),
2051 connection.getCallerDisplayNamePresentation(),
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002052 connection.getVideoProvider() == null ?
2053 null : connection.getVideoProvider().getInterface(),
Sailesh Nepal8b9d3ca2014-08-14 17:39:34 -07002054 connection.getVideoState(),
Andrew Lee100e2932014-09-08 15:34:24 -07002055 connection.isRingbackRequested(),
Sailesh Nepal8b9d3ca2014-08-14 17:39:34 -07002056 connection.getAudioModeIsVoip(),
Roshan Piuse927ec02015-07-15 15:47:21 -07002057 connection.getConnectTimeMillis(),
Tyler Gunnc9503d62020-01-27 10:30:51 -08002058 connection.getConnectionStartElapsedRealtimeMillis(),
Ihab Awad6107bab2014-08-18 09:23:25 -07002059 connection.getStatusHints(),
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07002060 connection.getDisconnectCause(),
Santos Cordon6b7f9552015-05-27 17:21:45 -07002061 createIdList(connection.getConferenceables()),
Tyler Gunnd57d76c2019-09-24 14:53:23 -07002062 connection.getExtras(),
2063 connection.getCallerNumberVerificationStatus()));
Tyler Gunnf5035432017-01-09 09:43:12 -08002064
Tyler Gunnf2e08b42018-05-24 10:44:44 -07002065 if (isIncoming && request.shouldShowIncomingCallUi() && isSelfManaged) {
Tyler Gunnf5035432017-01-09 09:43:12 -08002066 // Tell ConnectionService to show its incoming call UX.
2067 connection.onShowIncomingCallUi();
2068 }
Shriram Ganesh6bf35ac2014-12-11 17:53:38 -08002069 if (isUnknown) {
2070 triggerConferenceRecalculate();
2071 }
Evan Charltonbf11f982014-07-20 22:06:28 -07002072 }
2073
Tyler Gunn159f35c2017-03-02 09:28:37 -08002074 private void createConnectionFailed(final PhoneAccountHandle callManagerAccount,
2075 final String callId, final ConnectionRequest request,
2076 boolean isIncoming) {
Tyler Gunn44e01912017-01-31 10:49:05 -08002077
2078 Log.i(this, "createConnectionFailed %s", callId);
2079 if (isIncoming) {
Tyler Gunn159f35c2017-03-02 09:28:37 -08002080 onCreateIncomingConnectionFailed(callManagerAccount, request);
Tyler Gunn44e01912017-01-31 10:49:05 -08002081 } else {
Tyler Gunn159f35c2017-03-02 09:28:37 -08002082 onCreateOutgoingConnectionFailed(callManagerAccount, request);
Tyler Gunn44e01912017-01-31 10:49:05 -08002083 }
2084 }
2085
Ravi Paluri80aa2142019-12-02 11:57:37 +05302086 private void createConferenceFailed(final PhoneAccountHandle callManagerAccount,
2087 final String callId, final ConnectionRequest request,
2088 boolean isIncoming) {
2089
2090 Log.i(this, "createConferenceFailed %s", callId);
2091 if (isIncoming) {
2092 onCreateIncomingConferenceFailed(callManagerAccount, request);
2093 } else {
2094 onCreateOutgoingConferenceFailed(callManagerAccount, request);
2095 }
2096 }
2097
Sanket Padawe4cc8ed52017-12-04 16:22:20 -08002098 private void handoverFailed(final String callId, final ConnectionRequest request,
2099 int reason) {
2100
2101 Log.i(this, "handoverFailed %s", callId);
2102 onHandoverFailed(request, reason);
2103 }
2104
Tyler Gunn041a1fe2017-05-12 10:04:49 -07002105 /**
2106 * Called by Telecom when the creation of a new Connection has completed and it is now added
2107 * to Telecom.
2108 * @param callId The ID of the connection.
2109 */
2110 private void notifyCreateConnectionComplete(final String callId) {
2111 Log.i(this, "notifyCreateConnectionComplete %s", callId);
Tyler Gunn0a88f2e2017-06-16 20:20:34 -07002112 if (callId == null) {
2113 // This could happen if the connection fails quickly and is removed from the
2114 // ConnectionService before Telecom sends the create connection complete callback.
2115 Log.w(this, "notifyCreateConnectionComplete: callId is null.");
2116 return;
2117 }
Tyler Gunn041a1fe2017-05-12 10:04:49 -07002118 onCreateConnectionComplete(findConnectionForAction(callId,
2119 "notifyCreateConnectionComplete"));
2120 }
2121
Ravi Paluri80aa2142019-12-02 11:57:37 +05302122 /**
2123 * Called by Telecom when the creation of a new Conference has completed and it is now added
2124 * to Telecom.
2125 * @param callId The ID of the connection.
2126 */
2127 private void notifyCreateConferenceComplete(final String callId) {
2128 Log.i(this, "notifyCreateConferenceComplete %s", callId);
2129 if (callId == null) {
2130 // This could happen if the conference fails quickly and is removed from the
2131 // ConnectionService before Telecom sends the create conference complete callback.
2132 Log.w(this, "notifyCreateConferenceComplete: callId is null.");
2133 return;
2134 }
2135 onCreateConferenceComplete(findConferenceForAction(callId,
2136 "notifyCreateConferenceComplete"));
2137 }
2138
2139
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002140 private void abort(String callId) {
Tyler Gunnffbcd892020-05-04 15:01:59 -07002141 Log.i(this, "abort %s", callId);
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002142 findConnectionForAction(callId, "abort").onAbort();
Ihab Awad542e0ea2014-05-16 10:22:16 -07002143 }
2144
Tyler Gunnbe74de02014-08-29 14:51:48 -07002145 private void answerVideo(String callId, int videoState) {
Tyler Gunnffbcd892020-05-04 15:01:59 -07002146 Log.i(this, "answerVideo %s", callId);
Ravi Paluri80aa2142019-12-02 11:57:37 +05302147 if (mConnectionById.containsKey(callId)) {
2148 findConnectionForAction(callId, "answer").onAnswer(videoState);
2149 } else {
2150 findConferenceForAction(callId, "answer").onAnswer(videoState);
2151 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002152 }
2153
Tyler Gunnbe74de02014-08-29 14:51:48 -07002154 private void answer(String callId) {
Tyler Gunnffbcd892020-05-04 15:01:59 -07002155 Log.i(this, "answer %s", callId);
Ravi Paluri80aa2142019-12-02 11:57:37 +05302156 if (mConnectionById.containsKey(callId)) {
2157 findConnectionForAction(callId, "answer").onAnswer();
2158 } else {
2159 findConferenceForAction(callId, "answer").onAnswer();
2160 }
Tyler Gunnbe74de02014-08-29 14:51:48 -07002161 }
2162
Pooja Jaind34698d2017-12-28 14:15:31 +05302163 private void deflect(String callId, Uri address) {
Tyler Gunnffbcd892020-05-04 15:01:59 -07002164 Log.i(this, "deflect %s", callId);
Pooja Jaind34698d2017-12-28 14:15:31 +05302165 findConnectionForAction(callId, "deflect").onDeflect(address);
2166 }
2167
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002168 private void reject(String callId) {
Tyler Gunnffbcd892020-05-04 15:01:59 -07002169 Log.i(this, "reject %s", callId);
Ravi Paluri80aa2142019-12-02 11:57:37 +05302170 if (mConnectionById.containsKey(callId)) {
2171 findConnectionForAction(callId, "reject").onReject();
2172 } else {
2173 findConferenceForAction(callId, "reject").onReject();
2174 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002175 }
2176
Bryce Lee81901682015-08-28 16:38:02 -07002177 private void reject(String callId, String rejectWithMessage) {
Tyler Gunnffbcd892020-05-04 15:01:59 -07002178 Log.i(this, "reject %s with message", callId);
Bryce Lee81901682015-08-28 16:38:02 -07002179 findConnectionForAction(callId, "reject").onReject(rejectWithMessage);
2180 }
2181
Tyler Gunnfacfdee2020-01-23 13:10:37 -08002182 private void reject(String callId, @android.telecom.Call.RejectReason int rejectReason) {
Tyler Gunnffbcd892020-05-04 15:01:59 -07002183 Log.i(this, "reject %s with reason %d", callId, rejectReason);
Tyler Gunnfacfdee2020-01-23 13:10:37 -08002184 findConnectionForAction(callId, "reject").onReject(rejectReason);
2185 }
2186
Ravi Palurif4b38e72020-02-05 12:35:41 +05302187 private void transfer(String callId, Uri number, boolean isConfirmationRequired) {
Tyler Gunnffbcd892020-05-04 15:01:59 -07002188 Log.i(this, "transfer %s", callId);
Ravi Palurif4b38e72020-02-05 12:35:41 +05302189 findConnectionForAction(callId, "transfer").onTransfer(number, isConfirmationRequired);
2190 }
2191
2192 private void consultativeTransfer(String callId, String otherCallId) {
Tyler Gunnffbcd892020-05-04 15:01:59 -07002193 Log.i(this, "consultativeTransfer %s", callId);
Ravi Palurif4b38e72020-02-05 12:35:41 +05302194 Connection connection1 = findConnectionForAction(callId, "consultativeTransfer");
2195 Connection connection2 = findConnectionForAction(otherCallId, " consultativeTransfer");
2196 connection1.onTransfer(connection2);
2197 }
2198
Bryce Leecac50772015-11-17 15:13:29 -08002199 private void silence(String callId) {
Tyler Gunnffbcd892020-05-04 15:01:59 -07002200 Log.i(this, "silence %s", callId);
Bryce Leecac50772015-11-17 15:13:29 -08002201 findConnectionForAction(callId, "silence").onSilence();
2202 }
2203
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002204 private void disconnect(String callId) {
Tyler Gunnffbcd892020-05-04 15:01:59 -07002205 Log.i(this, "disconnect %s", callId);
Santos Cordon0159ac02014-08-21 14:28:11 -07002206 if (mConnectionById.containsKey(callId)) {
2207 findConnectionForAction(callId, "disconnect").onDisconnect();
2208 } else {
2209 findConferenceForAction(callId, "disconnect").onDisconnect();
2210 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002211 }
2212
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002213 private void hold(String callId) {
Tyler Gunnffbcd892020-05-04 15:01:59 -07002214 Log.i(this, "hold %s", callId);
Santos Cordon0159ac02014-08-21 14:28:11 -07002215 if (mConnectionById.containsKey(callId)) {
2216 findConnectionForAction(callId, "hold").onHold();
2217 } else {
2218 findConferenceForAction(callId, "hold").onHold();
2219 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002220 }
2221
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002222 private void unhold(String callId) {
Tyler Gunnffbcd892020-05-04 15:01:59 -07002223 Log.i(this, "unhold %s", callId);
Santos Cordon0159ac02014-08-21 14:28:11 -07002224 if (mConnectionById.containsKey(callId)) {
2225 findConnectionForAction(callId, "unhold").onUnhold();
2226 } else {
2227 findConferenceForAction(callId, "unhold").onUnhold();
2228 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002229 }
2230
Yorke Lee4af59352015-05-13 14:14:54 -07002231 private void onCallAudioStateChanged(String callId, CallAudioState callAudioState) {
Tyler Gunnffbcd892020-05-04 15:01:59 -07002232 Log.i(this, "onAudioStateChanged %s %s", callId, callAudioState);
Yorke Leea0d3ca92014-09-15 19:18:13 -07002233 if (mConnectionById.containsKey(callId)) {
Yorke Lee4af59352015-05-13 14:14:54 -07002234 findConnectionForAction(callId, "onCallAudioStateChanged").setCallAudioState(
2235 callAudioState);
Yorke Leea0d3ca92014-09-15 19:18:13 -07002236 } else {
Yorke Lee4af59352015-05-13 14:14:54 -07002237 findConferenceForAction(callId, "onCallAudioStateChanged").setCallAudioState(
2238 callAudioState);
Yorke Leea0d3ca92014-09-15 19:18:13 -07002239 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002240 }
2241
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002242 private void playDtmfTone(String callId, char digit) {
Tyler Gunnffbcd892020-05-04 15:01:59 -07002243 Log.i(this, "playDtmfTone %s %c", callId, digit);
Yorke Leea0d3ca92014-09-15 19:18:13 -07002244 if (mConnectionById.containsKey(callId)) {
2245 findConnectionForAction(callId, "playDtmfTone").onPlayDtmfTone(digit);
2246 } else {
2247 findConferenceForAction(callId, "playDtmfTone").onPlayDtmfTone(digit);
2248 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002249 }
2250
2251 private void stopDtmfTone(String callId) {
Tyler Gunnffbcd892020-05-04 15:01:59 -07002252 Log.i(this, "stopDtmfTone %s", callId);
Yorke Leea0d3ca92014-09-15 19:18:13 -07002253 if (mConnectionById.containsKey(callId)) {
2254 findConnectionForAction(callId, "stopDtmfTone").onStopDtmfTone();
2255 } else {
2256 findConferenceForAction(callId, "stopDtmfTone").onStopDtmfTone();
2257 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002258 }
2259
Santos Cordon823fd3c2014-08-07 18:35:18 -07002260 private void conference(String callId1, String callId2) {
Tyler Gunnffbcd892020-05-04 15:01:59 -07002261 Log.i(this, "conference %s, %s", callId1, callId2);
Santos Cordon980acb92014-05-31 10:31:19 -07002262
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002263 // Attempt to get second connection or conference.
Santos Cordon823fd3c2014-08-07 18:35:18 -07002264 Connection connection2 = findConnectionForAction(callId2, "conference");
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002265 Conference conference2 = getNullConference();
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07002266 if (connection2 == getNullConnection()) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002267 conference2 = findConferenceForAction(callId2, "conference");
2268 if (conference2 == getNullConference()) {
2269 Log.w(this, "Connection2 or Conference2 missing in conference request %s.",
2270 callId2);
2271 return;
2272 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07002273 }
Santos Cordonb6939982014-06-04 20:20:58 -07002274
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002275 // Attempt to get first connection or conference and perform merge.
Ihab Awad50e35062014-09-30 09:17:03 -07002276 Connection connection1 = findConnectionForAction(callId1, "conference");
2277 if (connection1 == getNullConnection()) {
2278 Conference conference1 = findConferenceForAction(callId1, "addConnection");
2279 if (conference1 == getNullConference()) {
2280 Log.w(this,
2281 "Connection1 or Conference1 missing in conference request %s.",
2282 callId1);
2283 } else {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002284 // Call 1 is a conference.
2285 if (connection2 != getNullConnection()) {
2286 // Call 2 is a connection so merge via call 1 (conference).
2287 conference1.onMerge(connection2);
2288 } else {
2289 // Call 2 is ALSO a conference; this should never happen.
2290 Log.wtf(this, "There can only be one conference and an attempt was made to " +
2291 "merge two conferences.");
2292 return;
2293 }
Ihab Awad50e35062014-09-30 09:17:03 -07002294 }
2295 } else {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002296 // Call 1 is a connection.
2297 if (conference2 != getNullConference()) {
2298 // Call 2 is a conference, so merge via call 2.
2299 conference2.onMerge(connection1);
2300 } else {
2301 // Call 2 is a connection, so merge together.
2302 onConference(connection1, connection2);
2303 }
Ihab Awad50e35062014-09-30 09:17:03 -07002304 }
Santos Cordon980acb92014-05-31 10:31:19 -07002305 }
2306
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002307 private void splitFromConference(String callId) {
Tyler Gunnffbcd892020-05-04 15:01:59 -07002308 Log.i(this, "splitFromConference(%s)", callId);
Santos Cordon980acb92014-05-31 10:31:19 -07002309
2310 Connection connection = findConnectionForAction(callId, "splitFromConference");
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07002311 if (connection == getNullConnection()) {
Santos Cordon980acb92014-05-31 10:31:19 -07002312 Log.w(this, "Connection missing in conference request %s.", callId);
2313 return;
2314 }
2315
Santos Cordon0159ac02014-08-21 14:28:11 -07002316 Conference conference = connection.getConference();
2317 if (conference != null) {
2318 conference.onSeparate(connection);
2319 }
Santos Cordon980acb92014-05-31 10:31:19 -07002320 }
2321
Santos Cordona4868042014-09-04 17:39:22 -07002322 private void mergeConference(String callId) {
Tyler Gunnffbcd892020-05-04 15:01:59 -07002323 Log.i(this, "mergeConference(%s)", callId);
Santos Cordona4868042014-09-04 17:39:22 -07002324 Conference conference = findConferenceForAction(callId, "mergeConference");
2325 if (conference != null) {
2326 conference.onMerge();
2327 }
2328 }
2329
2330 private void swapConference(String callId) {
Tyler Gunnffbcd892020-05-04 15:01:59 -07002331 Log.i(this, "swapConference(%s)", callId);
Santos Cordona4868042014-09-04 17:39:22 -07002332 Conference conference = findConferenceForAction(callId, "swapConference");
2333 if (conference != null) {
2334 conference.onSwap();
2335 }
2336 }
2337
Ravi Paluri404babb2020-01-23 19:02:44 +05302338 private void addConferenceParticipants(String callId, List<Uri> participants) {
Tyler Gunnffbcd892020-05-04 15:01:59 -07002339 Log.i(this, "addConferenceParticipants(%s)", callId);
Ravi Paluri404babb2020-01-23 19:02:44 +05302340 if (mConnectionById.containsKey(callId)) {
2341 findConnectionForAction(callId, "addConferenceParticipants")
2342 .onAddConferenceParticipants(participants);
2343 } else {
2344 findConferenceForAction(callId, "addConferenceParticipants")
2345 .onAddConferenceParticipants(participants);
2346 }
2347 }
2348
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002349 /**
2350 * Notifies a {@link Connection} of a request to pull an external call.
2351 *
2352 * See {@link Call#pullExternalCall()}.
2353 *
2354 * @param callId The ID of the call to pull.
2355 */
2356 private void pullExternalCall(String callId) {
Tyler Gunnffbcd892020-05-04 15:01:59 -07002357 Log.i(this, "pullExternalCall(%s)", callId);
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002358 Connection connection = findConnectionForAction(callId, "pullExternalCall");
2359 if (connection != null) {
2360 connection.onPullExternalCall();
2361 }
2362 }
2363
2364 /**
2365 * Notifies a {@link Connection} of a call event.
2366 *
2367 * See {@link Call#sendCallEvent(String, Bundle)}.
2368 *
2369 * @param callId The ID of the call receiving the event.
2370 * @param event The event.
2371 * @param extras Extras associated with the event.
2372 */
2373 private void sendCallEvent(String callId, String event, Bundle extras) {
Tyler Gunnffbcd892020-05-04 15:01:59 -07002374 Log.i(this, "sendCallEvent(%s, %s)", callId, event);
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002375 Connection connection = findConnectionForAction(callId, "sendCallEvent");
2376 if (connection != null) {
2377 connection.onCallEvent(event, extras);
2378 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002379 }
2380
Hall Liu49cabcc2021-01-15 11:41:48 -08002381 private void onCallFilteringCompleted(String callId, boolean isBlocked, boolean isInContacts) {
2382 Log.i(this, "onCallFilteringCompleted(%s, %b, %b)", isBlocked, isInContacts);
2383 Connection connection = findConnectionForAction(callId, "onCallFilteringCompleted");
2384 if (connection != null) {
2385 connection.onCallFilteringCompleted(isBlocked, isInContacts);
2386 }
2387 }
2388
Tyler Gunndee56a82016-03-23 16:06:34 -07002389 /**
Tyler Gunn79bc1ec2018-01-22 15:17:54 -08002390 * Notifies a {@link Connection} that a handover has completed.
2391 *
2392 * @param callId The ID of the call which completed handover.
2393 */
2394 private void notifyHandoverComplete(String callId) {
Tyler Gunnffbcd892020-05-04 15:01:59 -07002395 Log.i(this, "notifyHandoverComplete(%s)", callId);
Tyler Gunn79bc1ec2018-01-22 15:17:54 -08002396 Connection connection = findConnectionForAction(callId, "notifyHandoverComplete");
2397 if (connection != null) {
2398 connection.onHandoverComplete();
2399 }
2400 }
2401
2402 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07002403 * Notifies a {@link Connection} or {@link Conference} of a change to the extras from Telecom.
2404 * <p>
2405 * These extra changes can originate from Telecom itself, or from an {@link InCallService} via
2406 * the {@link android.telecom.Call#putExtra(String, boolean)},
2407 * {@link android.telecom.Call#putExtra(String, int)},
2408 * {@link android.telecom.Call#putExtra(String, String)},
2409 * {@link Call#removeExtras(List)}.
2410 *
2411 * @param callId The ID of the call receiving the event.
2412 * @param extras The new extras bundle.
2413 */
2414 private void handleExtrasChanged(String callId, Bundle extras) {
Tyler Gunnffbcd892020-05-04 15:01:59 -07002415 Log.i(this, "handleExtrasChanged(%s, %s)", callId, extras);
Tyler Gunndee56a82016-03-23 16:06:34 -07002416 if (mConnectionById.containsKey(callId)) {
2417 findConnectionForAction(callId, "handleExtrasChanged").handleExtrasChanged(extras);
2418 } else if (mConferenceById.containsKey(callId)) {
2419 findConferenceForAction(callId, "handleExtrasChanged").handleExtrasChanged(extras);
2420 }
2421 }
2422
Hall Liub64ac4c2017-02-06 10:49:48 -08002423 private void startRtt(String callId, Connection.RttTextStream rttTextStream) {
Tyler Gunnffbcd892020-05-04 15:01:59 -07002424 Log.i(this, "startRtt(%s)", callId);
Hall Liub64ac4c2017-02-06 10:49:48 -08002425 if (mConnectionById.containsKey(callId)) {
2426 findConnectionForAction(callId, "startRtt").onStartRtt(rttTextStream);
2427 } else if (mConferenceById.containsKey(callId)) {
2428 Log.w(this, "startRtt called on a conference.");
2429 }
2430 }
2431
2432 private void stopRtt(String callId) {
Tyler Gunnffbcd892020-05-04 15:01:59 -07002433 Log.i(this, "stopRtt(%s)", callId);
Hall Liub64ac4c2017-02-06 10:49:48 -08002434 if (mConnectionById.containsKey(callId)) {
2435 findConnectionForAction(callId, "stopRtt").onStopRtt();
2436 } else if (mConferenceById.containsKey(callId)) {
2437 Log.w(this, "stopRtt called on a conference.");
2438 }
2439 }
2440
2441 private void handleRttUpgradeResponse(String callId, Connection.RttTextStream rttTextStream) {
Tyler Gunnffbcd892020-05-04 15:01:59 -07002442 Log.i(this, "handleRttUpgradeResponse(%s, %s)", callId, rttTextStream == null);
Hall Liub64ac4c2017-02-06 10:49:48 -08002443 if (mConnectionById.containsKey(callId)) {
2444 findConnectionForAction(callId, "handleRttUpgradeResponse")
2445 .handleRttUpgradeResponse(rttTextStream);
2446 } else if (mConferenceById.containsKey(callId)) {
2447 Log.w(this, "handleRttUpgradeResponse called on a conference.");
2448 }
2449 }
2450
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002451 private void onPostDialContinue(String callId, boolean proceed) {
Tyler Gunnffbcd892020-05-04 15:01:59 -07002452 Log.i(this, "onPostDialContinue(%s)", callId);
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002453 findConnectionForAction(callId, "stopDtmfTone").onPostDialContinue(proceed);
Evan Charlton6dea4ac2014-06-03 14:07:13 -07002454 }
2455
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002456 private void onAdapterAttached() {
Ihab Awad9c3f1882014-06-30 21:17:13 -07002457 if (mAreAccountsInitialized) {
Santos Cordon52d8a152014-06-17 19:08:45 -07002458 // No need to query again if we already did it.
2459 return;
2460 }
2461
Tyler Gunn4c69fb32019-05-17 10:49:16 -07002462 String callingPackage = getOpPackageName();
2463
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002464 mAdapter.queryRemoteConnectionServices(new RemoteServiceCallback.Stub() {
Santos Cordon52d8a152014-06-17 19:08:45 -07002465 @Override
2466 public void onResult(
2467 final List<ComponentName> componentNames,
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002468 final List<IBinder> services) {
Brad Ebinger0c3541b2016-11-01 14:11:38 -07002469 mHandler.post(new android.telecom.Logging.Runnable("oAA.qRCS.oR", null /*lock*/) {
Ihab Awad6107bab2014-08-18 09:23:25 -07002470 @Override
Brad Ebinger0c3541b2016-11-01 14:11:38 -07002471 public void loggedRun() {
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002472 for (int i = 0; i < componentNames.size() && i < services.size(); i++) {
Santos Cordon52d8a152014-06-17 19:08:45 -07002473 mRemoteConnectionManager.addConnectionService(
2474 componentNames.get(i),
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002475 IConnectionService.Stub.asInterface(services.get(i)));
Santos Cordon52d8a152014-06-17 19:08:45 -07002476 }
Ihab Awad5d0410f2014-07-30 10:07:40 -07002477 onAccountsInitialized();
Sailesh Nepalc5b01572014-07-14 16:29:44 -07002478 Log.d(this, "remote connection services found: " + services);
Santos Cordon52d8a152014-06-17 19:08:45 -07002479 }
Brad Ebinger0c3541b2016-11-01 14:11:38 -07002480 }.prepare());
Santos Cordon52d8a152014-06-17 19:08:45 -07002481 }
2482
2483 @Override
2484 public void onError() {
Brad Ebinger0c3541b2016-11-01 14:11:38 -07002485 mHandler.post(new android.telecom.Logging.Runnable("oAA.qRCS.oE", null /*lock*/) {
Ihab Awad6107bab2014-08-18 09:23:25 -07002486 @Override
Brad Ebinger0c3541b2016-11-01 14:11:38 -07002487 public void loggedRun() {
Ihab Awad9c3f1882014-06-30 21:17:13 -07002488 mAreAccountsInitialized = true;
Santos Cordon52d8a152014-06-17 19:08:45 -07002489 }
Brad Ebinger0c3541b2016-11-01 14:11:38 -07002490 }.prepare());
Santos Cordon52d8a152014-06-17 19:08:45 -07002491 }
Tyler Gunn4c69fb32019-05-17 10:49:16 -07002492 }, callingPackage);
Santos Cordon52d8a152014-06-17 19:08:45 -07002493 }
2494
Ihab Awadf8b69882014-07-25 15:14:01 -07002495 /**
2496 * Ask some other {@code ConnectionService} to create a {@code RemoteConnection} given an
Santos Cordona663f862014-10-29 13:49:58 -07002497 * incoming request. This is used by {@code ConnectionService}s that are registered with
2498 * {@link PhoneAccount#CAPABILITY_CONNECTION_MANAGER} and want to be able to manage
2499 * SIM-based incoming calls.
Ihab Awadf8b69882014-07-25 15:14:01 -07002500 *
2501 * @param connectionManagerPhoneAccount See description at
2502 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
2503 * @param request Details about the incoming call.
2504 * @return The {@code Connection} object to satisfy this call, or {@code null} to
2505 * not handle the call.
2506 */
2507 public final RemoteConnection createRemoteIncomingConnection(
2508 PhoneAccountHandle connectionManagerPhoneAccount,
2509 ConnectionRequest request) {
2510 return mRemoteConnectionManager.createRemoteConnection(
2511 connectionManagerPhoneAccount, request, true);
Santos Cordon52d8a152014-06-17 19:08:45 -07002512 }
2513
2514 /**
Ihab Awadf8b69882014-07-25 15:14:01 -07002515 * Ask some other {@code ConnectionService} to create a {@code RemoteConnection} given an
Santos Cordona663f862014-10-29 13:49:58 -07002516 * outgoing request. This is used by {@code ConnectionService}s that are registered with
2517 * {@link PhoneAccount#CAPABILITY_CONNECTION_MANAGER} and want to be able to use the
2518 * SIM-based {@code ConnectionService} to place its outgoing calls.
Ihab Awadf8b69882014-07-25 15:14:01 -07002519 *
2520 * @param connectionManagerPhoneAccount See description at
2521 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
Cuihtlauac ALVARADO0b3b2a52016-09-13 14:49:41 +02002522 * @param request Details about the outgoing call.
Ihab Awadf8b69882014-07-25 15:14:01 -07002523 * @return The {@code Connection} object to satisfy this call, or {@code null} to
2524 * not handle the call.
2525 */
2526 public final RemoteConnection createRemoteOutgoingConnection(
2527 PhoneAccountHandle connectionManagerPhoneAccount,
2528 ConnectionRequest request) {
2529 return mRemoteConnectionManager.createRemoteConnection(
2530 connectionManagerPhoneAccount, request, false);
2531 }
2532
2533 /**
Grace Jia9a09c672020-08-04 12:52:09 -07002534 * Ask some other {@code ConnectionService} to create a {@code RemoteConference} given an
2535 * incoming request. This is used by {@code ConnectionService}s that are registered with
2536 * {@link PhoneAccount#CAPABILITY_ADHOC_CONFERENCE_CALLING}.
2537 *
2538 * @param connectionManagerPhoneAccount See description at
2539 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
2540 * @param request Details about the incoming conference call.
2541 * @return The {@code RemoteConference} object to satisfy this call, or {@code null} to not
2542 * handle the call.
2543 */
2544 public final @Nullable RemoteConference createRemoteIncomingConference(
2545 @Nullable PhoneAccountHandle connectionManagerPhoneAccount,
2546 @Nullable ConnectionRequest request) {
2547 return mRemoteConnectionManager.createRemoteConference(connectionManagerPhoneAccount,
2548 request, true);
2549 }
2550
2551 /**
2552 * Ask some other {@code ConnectionService} to create a {@code RemoteConference} given an
2553 * outgoing request. This is used by {@code ConnectionService}s that are registered with
2554 * {@link PhoneAccount#CAPABILITY_ADHOC_CONFERENCE_CALLING}.
2555 *
2556 * @param connectionManagerPhoneAccount See description at
2557 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
2558 * @param request Details about the outgoing conference call.
2559 * @return The {@code RemoteConference} object to satisfy this call, or {@code null} to not
2560 * handle the call.
2561 */
2562 public final @Nullable RemoteConference createRemoteOutgoingConference(
2563 @Nullable PhoneAccountHandle connectionManagerPhoneAccount,
2564 @Nullable ConnectionRequest request) {
2565 return mRemoteConnectionManager.createRemoteConference(connectionManagerPhoneAccount,
2566 request, false);
2567 }
2568
2569 /**
Santos Cordona663f862014-10-29 13:49:58 -07002570 * Indicates to the relevant {@code RemoteConnectionService} that the specified
2571 * {@link RemoteConnection}s should be merged into a conference call.
2572 * <p>
2573 * If the conference request is successful, the method {@link #onRemoteConferenceAdded} will
2574 * be invoked.
2575 *
2576 * @param remoteConnection1 The first of the remote connections to conference.
2577 * @param remoteConnection2 The second of the remote connections to conference.
Ihab Awadb8e85c72014-08-23 20:34:57 -07002578 */
2579 public final void conferenceRemoteConnections(
Santos Cordona663f862014-10-29 13:49:58 -07002580 RemoteConnection remoteConnection1,
2581 RemoteConnection remoteConnection2) {
2582 mRemoteConnectionManager.conferenceRemoteConnections(remoteConnection1, remoteConnection2);
Ihab Awadb8e85c72014-08-23 20:34:57 -07002583 }
2584
2585 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07002586 * Adds a new conference call. When a conference call is created either as a result of an
2587 * explicit request via {@link #onConference} or otherwise, the connection service should supply
2588 * an instance of {@link Conference} by invoking this method. A conference call provided by this
2589 * method will persist until {@link Conference#destroy} is invoked on the conference instance.
2590 *
2591 * @param conference The new conference object.
2592 */
2593 public final void addConference(Conference conference) {
Rekha Kumar07366812015-03-24 16:42:31 -07002594 Log.d(this, "addConference: conference=%s", conference);
2595
Santos Cordon823fd3c2014-08-07 18:35:18 -07002596 String id = addConferenceInternal(conference);
2597 if (id != null) {
2598 List<String> connectionIds = new ArrayList<>(2);
2599 for (Connection connection : conference.getConnections()) {
2600 if (mIdByConnection.containsKey(connection)) {
2601 connectionIds.add(mIdByConnection.get(connection));
2602 }
2603 }
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002604 conference.setTelecomCallId(id);
Brad Ebinger0ae44ed2020-04-09 15:30:57 -07002605 ParcelableConference parcelableConference = new ParcelableConference.Builder(
2606 conference.getPhoneAccountHandle(), conference.getState())
2607 .setConnectionCapabilities(conference.getConnectionCapabilities())
2608 .setConnectionProperties(conference.getConnectionProperties())
2609 .setConnectionIds(connectionIds)
2610 .setVideoAttributes(conference.getVideoProvider() == null
2611 ? null : conference.getVideoProvider().getInterface(),
2612 conference.getVideoState())
2613 .setConnectTimeMillis(conference.getConnectTimeMillis(),
2614 conference.getConnectionStartElapsedRealtimeMillis())
2615 .setStatusHints(conference.getStatusHints())
2616 .setExtras(conference.getExtras())
2617 .setAddress(conference.getAddress(), conference.getAddressPresentation())
2618 .setCallerDisplayName(conference.getCallerDisplayName(),
2619 conference.getCallerDisplayNamePresentation())
2620 .setDisconnectCause(conference.getDisconnectCause())
2621 .setRingbackRequested(conference.isRingbackRequested())
2622 .setCallDirection(conference.getCallDirection())
2623 .build();
Andrew Lee0f51da32015-04-16 13:11:55 -07002624
Santos Cordon823fd3c2014-08-07 18:35:18 -07002625 mAdapter.addConferenceCall(id, parcelableConference);
Rekha Kumar07366812015-03-24 16:42:31 -07002626 mAdapter.setVideoProvider(id, conference.getVideoProvider());
2627 mAdapter.setVideoState(id, conference.getVideoState());
Tyler Gunn10362372020-04-08 13:12:30 -07002628 // In some instances a conference can start its life as a standalone call with just a
2629 // single participant; ensure we signal to Telecom in this case.
2630 if (!conference.isMultiparty()) {
2631 mAdapter.setConferenceState(id, conference.isMultiparty());
2632 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07002633
2634 // Go through any child calls and set the parent.
2635 for (Connection connection : conference.getConnections()) {
2636 String connectionId = mIdByConnection.get(connection);
2637 if (connectionId != null) {
2638 mAdapter.setIsConferenced(connectionId, id);
2639 }
2640 }
Pengquan Meng70c9885332017-10-02 18:09:03 -07002641 onConferenceAdded(conference);
Santos Cordon823fd3c2014-08-07 18:35:18 -07002642 }
2643 }
2644
2645 /**
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002646 * Adds a connection created by the {@link ConnectionService} and informs telecom of the new
2647 * connection.
2648 *
2649 * @param phoneAccountHandle The phone account handle for the connection.
2650 * @param connection The connection to add.
2651 */
2652 public final void addExistingConnection(PhoneAccountHandle phoneAccountHandle,
2653 Connection connection) {
Tyler Gunn78da7812017-05-09 14:34:57 -07002654 addExistingConnection(phoneAccountHandle, connection, null /* conference */);
2655 }
2656
2657 /**
Pengquan Meng731c1a32017-11-21 18:01:13 -08002658 * Call to inform Telecom that your {@link ConnectionService} has released call resources (e.g
2659 * microphone, camera).
2660 *
Pengquan Menge3bf7e22018-02-22 17:30:04 -08002661 * <p>
2662 * The {@link ConnectionService} will be disconnected when it failed to call this method within
2663 * 5 seconds after {@link #onConnectionServiceFocusLost()} is called.
2664 *
Pengquan Meng731c1a32017-11-21 18:01:13 -08002665 * @see ConnectionService#onConnectionServiceFocusLost()
2666 */
2667 public final void connectionServiceFocusReleased() {
2668 mAdapter.onConnectionServiceFocusReleased();
2669 }
2670
2671 /**
Tyler Gunn78da7812017-05-09 14:34:57 -07002672 * Adds a connection created by the {@link ConnectionService} and informs telecom of the new
Tyler Gunn5567d742019-10-31 13:04:37 -07002673 * connection, as well as adding that connection to the specified conference.
2674 * <p>
2675 * Note: This API is intended ONLY for use by the Telephony stack to provide an easy way to add
2676 * IMS conference participants to be added to a conference in a single step; this helps ensure
2677 * UI updates happen atomically, rather than adding the connection and then adding it to
2678 * the conference in another step.
Tyler Gunn78da7812017-05-09 14:34:57 -07002679 *
2680 * @param phoneAccountHandle The phone account handle for the connection.
2681 * @param connection The connection to add.
2682 * @param conference The parent conference of the new connection.
2683 * @hide
2684 */
Tyler Gunn5567d742019-10-31 13:04:37 -07002685 @SystemApi
2686 public final void addExistingConnection(@NonNull PhoneAccountHandle phoneAccountHandle,
2687 @NonNull Connection connection, @NonNull Conference conference) {
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002688
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002689 String id = addExistingConnectionInternal(phoneAccountHandle, connection);
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002690 if (id != null) {
2691 List<String> emptyList = new ArrayList<>(0);
Tyler Gunn78da7812017-05-09 14:34:57 -07002692 String conferenceId = null;
2693 if (conference != null) {
2694 conferenceId = mIdByConference.get(conference);
2695 }
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002696
2697 ParcelableConnection parcelableConnection = new ParcelableConnection(
2698 phoneAccountHandle,
2699 connection.getState(),
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002700 connection.getConnectionCapabilities(),
Tyler Gunn720c6642016-03-22 09:02:47 -07002701 connection.getConnectionProperties(),
Christine Hallstrom2830ce92016-11-30 16:06:42 -08002702 connection.getSupportedAudioRoutes(),
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002703 connection.getAddress(),
2704 connection.getAddressPresentation(),
2705 connection.getCallerDisplayName(),
2706 connection.getCallerDisplayNamePresentation(),
2707 connection.getVideoProvider() == null ?
2708 null : connection.getVideoProvider().getInterface(),
2709 connection.getVideoState(),
2710 connection.isRingbackRequested(),
2711 connection.getAudioModeIsVoip(),
Roshan Piuse927ec02015-07-15 15:47:21 -07002712 connection.getConnectTimeMillis(),
Tyler Gunnc9503d62020-01-27 10:30:51 -08002713 connection.getConnectionStartElapsedRealtimeMillis(),
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002714 connection.getStatusHints(),
2715 connection.getDisconnectCause(),
Santos Cordon6b7f9552015-05-27 17:21:45 -07002716 emptyList,
Tyler Gunn78da7812017-05-09 14:34:57 -07002717 connection.getExtras(),
Tyler Gunn6986a632019-06-25 13:45:32 -07002718 conferenceId,
Tyler Gunnd57d76c2019-09-24 14:53:23 -07002719 connection.getCallDirection(),
2720 Connection.VERIFICATION_STATUS_NOT_VERIFIED);
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002721 mAdapter.addExistingConnection(id, parcelableConnection);
2722 }
2723 }
2724
2725 /**
Ihab Awadf8b69882014-07-25 15:14:01 -07002726 * Returns all the active {@code Connection}s for which this {@code ConnectionService}
2727 * has taken responsibility.
2728 *
2729 * @return A collection of {@code Connection}s created by this {@code ConnectionService}.
Santos Cordonb6939982014-06-04 20:20:58 -07002730 */
Sailesh Nepal091768c2014-06-30 15:15:23 -07002731 public final Collection<Connection> getAllConnections() {
Santos Cordonb6939982014-06-04 20:20:58 -07002732 return mConnectionById.values();
2733 }
2734
2735 /**
Santos Cordona6018b92016-02-16 14:23:12 -08002736 * Returns all the active {@code Conference}s for which this {@code ConnectionService}
2737 * has taken responsibility.
2738 *
2739 * @return A collection of {@code Conference}s created by this {@code ConnectionService}.
2740 */
2741 public final Collection<Conference> getAllConferences() {
2742 return mConferenceById.values();
2743 }
2744
2745 /**
Ihab Awadf8b69882014-07-25 15:14:01 -07002746 * Create a {@code Connection} given an incoming request. This is used to attach to existing
2747 * incoming calls.
Evan Charltonbf11f982014-07-20 22:06:28 -07002748 *
Ihab Awadf8b69882014-07-25 15:14:01 -07002749 * @param connectionManagerPhoneAccount See description at
2750 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
2751 * @param request Details about the incoming call.
2752 * @return The {@code Connection} object to satisfy this call, or {@code null} to
2753 * not handle the call.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002754 */
Ihab Awadf8b69882014-07-25 15:14:01 -07002755 public Connection onCreateIncomingConnection(
2756 PhoneAccountHandle connectionManagerPhoneAccount,
2757 ConnectionRequest request) {
2758 return null;
2759 }
Ravi Paluri80aa2142019-12-02 11:57:37 +05302760 /**
Grace Jia8587ee52020-07-10 15:42:32 -07002761 * Create a {@code Conference} given an incoming request. This is used to attach to an incoming
2762 * conference call initiated via
2763 * {@link TelecomManager#addNewIncomingConference(PhoneAccountHandle, Bundle)}.
Ravi Paluri80aa2142019-12-02 11:57:37 +05302764 *
2765 * @param connectionManagerPhoneAccount See description at
2766 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
Grace Jia8587ee52020-07-10 15:42:32 -07002767 * @param request Details about the incoming conference call.
2768 * @return The {@code Conference} object to satisfy this call, or {@code null} to
Ravi Paluri80aa2142019-12-02 11:57:37 +05302769 * not handle the call.
2770 */
2771 public @Nullable Conference onCreateIncomingConference(
2772 @Nullable PhoneAccountHandle connectionManagerPhoneAccount,
2773 @Nullable ConnectionRequest request) {
2774 return null;
2775 }
Sailesh Nepalc5b01572014-07-14 16:29:44 -07002776
2777 /**
Tyler Gunn041a1fe2017-05-12 10:04:49 -07002778 * Called after the {@link Connection} returned by
2779 * {@link #onCreateIncomingConnection(PhoneAccountHandle, ConnectionRequest)}
2780 * or {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)} has been
2781 * added to the {@link ConnectionService} and sent to Telecom.
2782 *
2783 * @param connection the {@link Connection}.
2784 * @hide
2785 */
2786 public void onCreateConnectionComplete(Connection connection) {
2787 }
2788
2789 /**
Ravi Paluri80aa2142019-12-02 11:57:37 +05302790 * Called after the {@link Conference} returned by
2791 * {@link #onCreateIncomingConference(PhoneAccountHandle, ConnectionRequest)}
2792 * or {@link #onCreateOutgoingConference(PhoneAccountHandle, ConnectionRequest)} has been
2793 * added to the {@link ConnectionService} and sent to Telecom.
2794 *
2795 * @param conference the {@link Conference}.
2796 * @hide
2797 */
2798 public void onCreateConferenceComplete(Conference conference) {
2799 }
2800
2801
2802 /**
Tyler Gunnf5035432017-01-09 09:43:12 -08002803 * Called by Telecom to inform the {@link ConnectionService} that its request to create a new
2804 * incoming {@link Connection} was denied.
2805 * <p>
2806 * Used when a self-managed {@link ConnectionService} attempts to create a new incoming
2807 * {@link Connection}, but Telecom has determined that the call cannot be allowed at this time.
2808 * The {@link ConnectionService} is responsible for silently rejecting the new incoming
2809 * {@link Connection}.
2810 * <p>
2811 * See {@link TelecomManager#isIncomingCallPermitted(PhoneAccountHandle)} for more information.
2812 *
Tyler Gunn159f35c2017-03-02 09:28:37 -08002813 * @param connectionManagerPhoneAccount See description at
2814 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
Tyler Gunnf5035432017-01-09 09:43:12 -08002815 * @param request The incoming connection request.
2816 */
Tyler Gunn159f35c2017-03-02 09:28:37 -08002817 public void onCreateIncomingConnectionFailed(PhoneAccountHandle connectionManagerPhoneAccount,
2818 ConnectionRequest request) {
Tyler Gunnf5035432017-01-09 09:43:12 -08002819 }
2820
2821 /**
2822 * Called by Telecom to inform the {@link ConnectionService} that its request to create a new
2823 * outgoing {@link Connection} was denied.
2824 * <p>
2825 * Used when a self-managed {@link ConnectionService} attempts to create a new outgoing
2826 * {@link Connection}, but Telecom has determined that the call cannot be placed at this time.
2827 * The {@link ConnectionService} is responisible for informing the user that the
2828 * {@link Connection} cannot be made at this time.
2829 * <p>
2830 * See {@link TelecomManager#isOutgoingCallPermitted(PhoneAccountHandle)} for more information.
2831 *
Tyler Gunn159f35c2017-03-02 09:28:37 -08002832 * @param connectionManagerPhoneAccount See description at
2833 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
Tyler Gunnf5035432017-01-09 09:43:12 -08002834 * @param request The outgoing connection request.
2835 */
Tyler Gunn159f35c2017-03-02 09:28:37 -08002836 public void onCreateOutgoingConnectionFailed(PhoneAccountHandle connectionManagerPhoneAccount,
2837 ConnectionRequest request) {
Tyler Gunnf5035432017-01-09 09:43:12 -08002838 }
2839
2840 /**
Ravi Paluri80aa2142019-12-02 11:57:37 +05302841 * Called by Telecom to inform the {@link ConnectionService} that its request to create a new
2842 * incoming {@link Conference} was denied.
2843 * <p>
2844 * Used when a self-managed {@link ConnectionService} attempts to create a new incoming
2845 * {@link Conference}, but Telecom has determined that the call cannot be allowed at this time.
2846 * The {@link ConnectionService} is responsible for silently rejecting the new incoming
2847 * {@link Conference}.
2848 * <p>
2849 * See {@link TelecomManager#isIncomingCallPermitted(PhoneAccountHandle)} for more information.
2850 *
2851 * @param connectionManagerPhoneAccount See description at
2852 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
2853 * @param request The incoming connection request.
2854 */
2855 public void onCreateIncomingConferenceFailed(
2856 @Nullable PhoneAccountHandle connectionManagerPhoneAccount,
2857 @Nullable ConnectionRequest request) {
2858 }
2859
2860 /**
2861 * Called by Telecom to inform the {@link ConnectionService} that its request to create a new
2862 * outgoing {@link Conference} was denied.
2863 * <p>
2864 * Used when a self-managed {@link ConnectionService} attempts to create a new outgoing
2865 * {@link Conference}, but Telecom has determined that the call cannot be placed at this time.
2866 * The {@link ConnectionService} is responisible for informing the user that the
2867 * {@link Conference} cannot be made at this time.
2868 * <p>
2869 * See {@link TelecomManager#isOutgoingCallPermitted(PhoneAccountHandle)} for more information.
2870 *
2871 * @param connectionManagerPhoneAccount See description at
2872 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
2873 * @param request The outgoing connection request.
2874 */
2875 public void onCreateOutgoingConferenceFailed(
2876 @Nullable PhoneAccountHandle connectionManagerPhoneAccount,
2877 @Nullable ConnectionRequest request) {
2878 }
2879
2880
2881 /**
Shriram Ganesh6bf35ac2014-12-11 17:53:38 -08002882 * Trigger recalculate functinality for conference calls. This is used when a Telephony
2883 * Connection is part of a conference controller but is not yet added to Connection
2884 * Service and hence cannot be added to the conference call.
2885 *
2886 * @hide
2887 */
2888 public void triggerConferenceRecalculate() {
2889 }
2890
2891 /**
Ihab Awadf8b69882014-07-25 15:14:01 -07002892 * Create a {@code Connection} given an outgoing request. This is used to initiate new
2893 * outgoing calls.
Sailesh Nepalc5b01572014-07-14 16:29:44 -07002894 *
Ihab Awadf8b69882014-07-25 15:14:01 -07002895 * @param connectionManagerPhoneAccount The connection manager account to use for managing
2896 * this call.
2897 * <p>
2898 * If this parameter is not {@code null}, it means that this {@code ConnectionService}
2899 * has registered one or more {@code PhoneAccount}s having
2900 * {@link PhoneAccount#CAPABILITY_CONNECTION_MANAGER}. This parameter will contain
2901 * one of these {@code PhoneAccount}s, while the {@code request} will contain another
2902 * (usually but not always distinct) {@code PhoneAccount} to be used for actually
2903 * making the connection.
2904 * <p>
2905 * If this parameter is {@code null}, it means that this {@code ConnectionService} is
2906 * being asked to make a direct connection. The
2907 * {@link ConnectionRequest#getAccountHandle()} of parameter {@code request} will be
2908 * a {@code PhoneAccount} registered by this {@code ConnectionService} to use for
2909 * making the connection.
2910 * @param request Details about the outgoing call.
2911 * @return The {@code Connection} object to satisfy this call, or the result of an invocation
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002912 * of {@link Connection#createFailedConnection(DisconnectCause)} to not handle the call.
Sailesh Nepalc5b01572014-07-14 16:29:44 -07002913 */
Ihab Awadf8b69882014-07-25 15:14:01 -07002914 public Connection onCreateOutgoingConnection(
2915 PhoneAccountHandle connectionManagerPhoneAccount,
2916 ConnectionRequest request) {
2917 return null;
2918 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002919
2920 /**
Ravi Paluri80aa2142019-12-02 11:57:37 +05302921 * Create a {@code Conference} given an outgoing request. This is used to initiate new
Grace Jia8587ee52020-07-10 15:42:32 -07002922 * outgoing conference call requested via
2923 * {@link TelecomManager#startConference(List, Bundle)}.
Ravi Paluri80aa2142019-12-02 11:57:37 +05302924 *
2925 * @param connectionManagerPhoneAccount The connection manager account to use for managing
2926 * this call.
2927 * <p>
2928 * If this parameter is not {@code null}, it means that this {@code ConnectionService}
2929 * has registered one or more {@code PhoneAccount}s having
2930 * {@link PhoneAccount#CAPABILITY_CONNECTION_MANAGER}. This parameter will contain
2931 * one of these {@code PhoneAccount}s, while the {@code request} will contain another
2932 * (usually but not always distinct) {@code PhoneAccount} to be used for actually
2933 * making the connection.
2934 * <p>
2935 * If this parameter is {@code null}, it means that this {@code ConnectionService} is
2936 * being asked to make a direct connection. The
2937 * {@link ConnectionRequest#getAccountHandle()} of parameter {@code request} will be
2938 * a {@code PhoneAccount} registered by this {@code ConnectionService} to use for
2939 * making the connection.
2940 * @param request Details about the outgoing call.
2941 * @return The {@code Conference} object to satisfy this call, or the result of an invocation
2942 * of {@link Connection#createFailedConnection(DisconnectCause)} to not handle the call.
2943 */
2944 public @Nullable Conference onCreateOutgoingConference(
2945 @Nullable PhoneAccountHandle connectionManagerPhoneAccount,
2946 @Nullable ConnectionRequest request) {
2947 return null;
2948 }
2949
2950
2951 /**
Tyler Gunn9d127732018-03-02 15:45:51 -08002952 * Called by Telecom to request that a {@link ConnectionService} creates an instance of an
2953 * outgoing handover {@link Connection}.
2954 * <p>
2955 * A call handover is the process where an ongoing call is transferred from one app (i.e.
2956 * {@link ConnectionService} to another app. The user could, for example, choose to continue a
2957 * mobile network call in a video calling app. The mobile network call via the Telephony stack
2958 * is referred to as the source of the handover, and the video calling app is referred to as the
2959 * destination.
2960 * <p>
2961 * When considering a handover scenario the <em>initiating</em> device is where a user initiated
2962 * the handover process (e.g. by calling {@link android.telecom.Call#handoverTo(
2963 * PhoneAccountHandle, int, Bundle)}, and the other device is considered the <em>receiving</em>
2964 * device.
2965 * <p>
2966 * This method is called on the destination {@link ConnectionService} on <em>initiating</em>
2967 * device when the user initiates a handover request from one app to another. The user request
2968 * originates in the {@link InCallService} via
2969 * {@link android.telecom.Call#handoverTo(PhoneAccountHandle, int, Bundle)}.
2970 * <p>
2971 * For a full discussion of the handover process and the APIs involved, see
2972 * {@link android.telecom.Call#handoverTo(PhoneAccountHandle, int, Bundle)}.
2973 * <p>
2974 * Implementations of this method should return an instance of {@link Connection} which
2975 * represents the handover. If your app does not wish to accept a handover to it at this time,
2976 * you can return {@code null}. The code below shows an example of how this is done.
2977 * <pre>
2978 * {@code
2979 * public Connection onCreateIncomingHandoverConnection(PhoneAccountHandle
2980 * fromPhoneAccountHandle, ConnectionRequest request) {
2981 * if (!isHandoverAvailable()) {
2982 * return null;
2983 * }
2984 * MyConnection connection = new MyConnection();
2985 * connection.setAddress(request.getAddress(), TelecomManager.PRESENTATION_ALLOWED);
2986 * connection.setVideoState(request.getVideoState());
2987 * return connection;
2988 * }
2989 * }
2990 * </pre>
2991 *
Sanket Padawea8eddd42017-11-03 11:07:35 -07002992 * @param fromPhoneAccountHandle {@link PhoneAccountHandle} associated with the
2993 * ConnectionService which needs to handover the call.
Tyler Gunn9d127732018-03-02 15:45:51 -08002994 * @param request Details about the call to handover.
2995 * @return {@link Connection} instance corresponding to the handover call.
Sanket Padawea8eddd42017-11-03 11:07:35 -07002996 */
2997 public Connection onCreateOutgoingHandoverConnection(PhoneAccountHandle fromPhoneAccountHandle,
2998 ConnectionRequest request) {
2999 return null;
3000 }
3001
3002 /**
Tyler Gunn9d127732018-03-02 15:45:51 -08003003 * Called by Telecom to request that a {@link ConnectionService} creates an instance of an
3004 * incoming handover {@link Connection}.
3005 * <p>
3006 * A call handover is the process where an ongoing call is transferred from one app (i.e.
3007 * {@link ConnectionService} to another app. The user could, for example, choose to continue a
3008 * mobile network call in a video calling app. The mobile network call via the Telephony stack
3009 * is referred to as the source of the handover, and the video calling app is referred to as the
3010 * destination.
3011 * <p>
3012 * When considering a handover scenario the <em>initiating</em> device is where a user initiated
3013 * the handover process (e.g. by calling {@link android.telecom.Call#handoverTo(
3014 * PhoneAccountHandle, int, Bundle)}, and the other device is considered the <em>receiving</em>
3015 * device.
3016 * <p>
3017 * This method is called on the destination app on the <em>receiving</em> device when the
3018 * destination app calls {@link TelecomManager#acceptHandover(Uri, int, PhoneAccountHandle)} to
3019 * accept an incoming handover from the <em>initiating</em> device.
3020 * <p>
3021 * For a full discussion of the handover process and the APIs involved, see
3022 * {@link android.telecom.Call#handoverTo(PhoneAccountHandle, int, Bundle)}.
3023 * <p>
3024 * Implementations of this method should return an instance of {@link Connection} which
3025 * represents the handover. The code below shows an example of how this is done.
3026 * <pre>
3027 * {@code
3028 * public Connection onCreateIncomingHandoverConnection(PhoneAccountHandle
3029 * fromPhoneAccountHandle, ConnectionRequest request) {
3030 * // Given that your app requested to accept the handover, you should not return null here.
3031 * MyConnection connection = new MyConnection();
3032 * connection.setAddress(request.getAddress(), TelecomManager.PRESENTATION_ALLOWED);
3033 * connection.setVideoState(request.getVideoState());
3034 * return connection;
3035 * }
3036 * }
3037 * </pre>
3038 *
Sanket Padawea8eddd42017-11-03 11:07:35 -07003039 * @param fromPhoneAccountHandle {@link PhoneAccountHandle} associated with the
3040 * ConnectionService which needs to handover the call.
3041 * @param request Details about the call which needs to be handover.
Tyler Gunn9d127732018-03-02 15:45:51 -08003042 * @return {@link Connection} instance corresponding to the handover call.
Sanket Padawea8eddd42017-11-03 11:07:35 -07003043 */
3044 public Connection onCreateIncomingHandoverConnection(PhoneAccountHandle fromPhoneAccountHandle,
3045 ConnectionRequest request) {
3046 return null;
3047 }
3048
3049 /**
3050 * Called by Telecom in response to a {@code TelecomManager#acceptHandover()}
3051 * invocation which failed.
Tyler Gunn9d127732018-03-02 15:45:51 -08003052 * <p>
3053 * For a full discussion of the handover process and the APIs involved, see
3054 * {@link android.telecom.Call#handoverTo(PhoneAccountHandle, int, Bundle)}
3055 *
3056 * @param request Details about the call which failed to handover.
3057 * @param error Reason for handover failure. Will be one of the
Sanket Padawea8eddd42017-11-03 11:07:35 -07003058 */
Tyler Gunn9d127732018-03-02 15:45:51 -08003059 public void onHandoverFailed(ConnectionRequest request,
3060 @Call.Callback.HandoverFailureErrors int error) {
Sanket Padawea8eddd42017-11-03 11:07:35 -07003061 return;
3062 }
3063
3064 /**
Yorke Leec3cf9822014-10-02 09:38:39 -07003065 * Create a {@code Connection} for a new unknown call. An unknown call is a call originating
3066 * from the ConnectionService that was neither a user-initiated outgoing call, nor an incoming
3067 * call created using
3068 * {@code TelecomManager#addNewIncomingCall(PhoneAccountHandle, android.os.Bundle)}.
3069 *
Yorke Lee770ed6e2014-10-06 18:58:52 -07003070 * @hide
Yorke Leec3cf9822014-10-02 09:38:39 -07003071 */
3072 public Connection onCreateUnknownConnection(PhoneAccountHandle connectionManagerPhoneAccount,
3073 ConnectionRequest request) {
Brad Ebingerb32d4f82016-10-24 16:40:49 -07003074 return null;
Yorke Leec3cf9822014-10-02 09:38:39 -07003075 }
3076
3077 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07003078 * Conference two specified connections. Invoked when the user has made a request to merge the
3079 * specified connections into a conference call. In response, the connection service should
3080 * create an instance of {@link Conference} and pass it into {@link #addConference}.
Santos Cordonb6939982014-06-04 20:20:58 -07003081 *
Santos Cordon823fd3c2014-08-07 18:35:18 -07003082 * @param connection1 A connection to merge into a conference call.
3083 * @param connection2 A connection to merge into a conference call.
Santos Cordonb6939982014-06-04 20:20:58 -07003084 */
Santos Cordon823fd3c2014-08-07 18:35:18 -07003085 public void onConference(Connection connection1, Connection connection2) {}
Santos Cordonb6939982014-06-04 20:20:58 -07003086
Santos Cordona663f862014-10-29 13:49:58 -07003087 /**
Pengquan Meng70c9885332017-10-02 18:09:03 -07003088 * Called when a connection is added.
3089 * @hide
3090 */
3091 public void onConnectionAdded(Connection connection) {}
3092
3093 /**
3094 * Called when a connection is removed.
3095 * @hide
3096 */
3097 public void onConnectionRemoved(Connection connection) {}
3098
3099 /**
3100 * Called when a conference is added.
3101 * @hide
3102 */
3103 public void onConferenceAdded(Conference conference) {}
3104
3105 /**
3106 * Called when a conference is removed.
3107 * @hide
3108 */
3109 public void onConferenceRemoved(Conference conference) {}
3110
3111 /**
Santos Cordona663f862014-10-29 13:49:58 -07003112 * Indicates that a remote conference has been created for existing {@link RemoteConnection}s.
3113 * When this method is invoked, this {@link ConnectionService} should create its own
3114 * representation of the conference call and send it to telecom using {@link #addConference}.
3115 * <p>
3116 * This is only relevant to {@link ConnectionService}s which are registered with
3117 * {@link PhoneAccount#CAPABILITY_CONNECTION_MANAGER}.
3118 *
3119 * @param conference The remote conference call.
3120 */
Ihab Awadb8e85c72014-08-23 20:34:57 -07003121 public void onRemoteConferenceAdded(RemoteConference conference) {}
3122
Santos Cordon823fd3c2014-08-07 18:35:18 -07003123 /**
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07003124 * Called when an existing connection is added remotely.
3125 * @param connection The existing connection which was added.
3126 */
3127 public void onRemoteExistingConnectionAdded(RemoteConnection connection) {}
3128
3129 /**
Pengquan Meng731c1a32017-11-21 18:01:13 -08003130 * Called when the {@link ConnectionService} has lost the call focus.
3131 * The {@link ConnectionService} should release the call resources and invokes
3132 * {@link ConnectionService#connectionServiceFocusReleased()} to inform telecom that it has
3133 * released the call resources.
3134 */
3135 public void onConnectionServiceFocusLost() {}
3136
3137 /**
3138 * Called when the {@link ConnectionService} has gained the call focus. The
3139 * {@link ConnectionService} can acquire the call resources at this time.
3140 */
3141 public void onConnectionServiceFocusGained() {}
3142
3143 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07003144 * @hide
3145 */
3146 public boolean containsConference(Conference conference) {
3147 return mIdByConference.containsKey(conference);
3148 }
3149
Ihab Awadb8e85c72014-08-23 20:34:57 -07003150 /** {@hide} */
3151 void addRemoteConference(RemoteConference remoteConference) {
3152 onRemoteConferenceAdded(remoteConference);
3153 }
3154
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07003155 /** {@hide} */
3156 void addRemoteExistingConnection(RemoteConnection remoteConnection) {
3157 onRemoteExistingConnectionAdded(remoteConnection);
3158 }
3159
Ihab Awad5d0410f2014-07-30 10:07:40 -07003160 private void onAccountsInitialized() {
3161 mAreAccountsInitialized = true;
3162 for (Runnable r : mPreInitializationConnectionRequests) {
3163 r.run();
3164 }
3165 mPreInitializationConnectionRequests.clear();
3166 }
3167
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07003168 /**
Tyler Gunnf0500bd2015-09-01 10:59:48 -07003169 * Adds an existing connection to the list of connections, identified by a new call ID unique
3170 * to this connection service.
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07003171 *
3172 * @param connection The connection.
Tyler Gunnf0500bd2015-09-01 10:59:48 -07003173 * @return The ID of the connection (e.g. the call-id).
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07003174 */
Tyler Gunnf0500bd2015-09-01 10:59:48 -07003175 private String addExistingConnectionInternal(PhoneAccountHandle handle, Connection connection) {
3176 String id;
Tyler Gunncd6ccfd2016-10-17 15:48:19 -07003177
3178 if (connection.getExtras() != null && connection.getExtras()
3179 .containsKey(Connection.EXTRA_ORIGINAL_CONNECTION_ID)) {
3180 id = connection.getExtras().getString(Connection.EXTRA_ORIGINAL_CONNECTION_ID);
3181 Log.d(this, "addExistingConnectionInternal - conn %s reusing original id %s",
3182 connection.getTelecomCallId(), id);
3183 } else if (handle == null) {
Tyler Gunnf0500bd2015-09-01 10:59:48 -07003184 // If no phone account handle was provided, we cannot be sure the call ID is unique,
3185 // so just use a random UUID.
3186 id = UUID.randomUUID().toString();
3187 } else {
3188 // Phone account handle was provided, so use the ConnectionService class name as a
3189 // prefix for a unique incremental call ID.
3190 id = handle.getComponentName().getClassName() + "@" + getNextCallId();
3191 }
Pengquan Meng70c9885332017-10-02 18:09:03 -07003192 addConnection(handle, id, connection);
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07003193 return id;
3194 }
3195
Pengquan Meng70c9885332017-10-02 18:09:03 -07003196 private void addConnection(PhoneAccountHandle handle, String callId, Connection connection) {
Tyler Gunnf0500bd2015-09-01 10:59:48 -07003197 connection.setTelecomCallId(callId);
Ihab Awad542e0ea2014-05-16 10:22:16 -07003198 mConnectionById.put(callId, connection);
3199 mIdByConnection.put(connection, callId);
3200 connection.addConnectionListener(mConnectionListener);
Santos Cordon823fd3c2014-08-07 18:35:18 -07003201 connection.setConnectionService(this);
Pengquan Meng70c9885332017-10-02 18:09:03 -07003202 connection.setPhoneAccountHandle(handle);
3203 onConnectionAdded(connection);
Ihab Awad542e0ea2014-05-16 10:22:16 -07003204 }
3205
Anthony Lee30e65842014-11-06 16:30:53 -08003206 /** {@hide} */
3207 protected void removeConnection(Connection connection) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07003208 connection.unsetConnectionService(this);
Ihab Awad542e0ea2014-05-16 10:22:16 -07003209 connection.removeConnectionListener(mConnectionListener);
Chenjie Luoe370b532016-05-12 16:59:43 -07003210 String id = mIdByConnection.get(connection);
3211 if (id != null) {
3212 mConnectionById.remove(id);
3213 mIdByConnection.remove(connection);
3214 mAdapter.removeCall(id);
Pengquan Meng70c9885332017-10-02 18:09:03 -07003215 onConnectionRemoved(connection);
Chenjie Luoe370b532016-05-12 16:59:43 -07003216 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07003217 }
3218
Santos Cordon823fd3c2014-08-07 18:35:18 -07003219 private String addConferenceInternal(Conference conference) {
Tyler Gunncd6ccfd2016-10-17 15:48:19 -07003220 String originalId = null;
3221 if (conference.getExtras() != null && conference.getExtras()
3222 .containsKey(Connection.EXTRA_ORIGINAL_CONNECTION_ID)) {
3223 originalId = conference.getExtras().getString(Connection.EXTRA_ORIGINAL_CONNECTION_ID);
3224 Log.d(this, "addConferenceInternal: conf %s reusing original id %s",
3225 conference.getTelecomCallId(),
3226 originalId);
3227 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07003228 if (mIdByConference.containsKey(conference)) {
3229 Log.w(this, "Re-adding an existing conference: %s.", conference);
3230 } else if (conference != null) {
Tyler Gunnf0500bd2015-09-01 10:59:48 -07003231 // Conferences do not (yet) have a PhoneAccountHandle associated with them, so we
3232 // cannot determine a ConnectionService class name to associate with the ID, so use
3233 // a unique UUID (for now).
Tyler Gunncd6ccfd2016-10-17 15:48:19 -07003234 String id = originalId == null ? UUID.randomUUID().toString() : originalId;
Santos Cordon823fd3c2014-08-07 18:35:18 -07003235 mConferenceById.put(id, conference);
3236 mIdByConference.put(conference, id);
3237 conference.addListener(mConferenceListener);
3238 return id;
3239 }
3240
3241 return null;
3242 }
3243
3244 private void removeConference(Conference conference) {
3245 if (mIdByConference.containsKey(conference)) {
3246 conference.removeListener(mConferenceListener);
3247
3248 String id = mIdByConference.get(conference);
3249 mConferenceById.remove(id);
3250 mIdByConference.remove(conference);
3251 mAdapter.removeCall(id);
Pengquan Meng70c9885332017-10-02 18:09:03 -07003252
3253 onConferenceRemoved(conference);
Santos Cordon823fd3c2014-08-07 18:35:18 -07003254 }
3255 }
3256
Ihab Awad542e0ea2014-05-16 10:22:16 -07003257 private Connection findConnectionForAction(String callId, String action) {
Tyler Gunn0a88f2e2017-06-16 20:20:34 -07003258 if (callId != null && mConnectionById.containsKey(callId)) {
Ihab Awad542e0ea2014-05-16 10:22:16 -07003259 return mConnectionById.get(callId);
3260 }
Ihab Awad60ac30b2014-05-20 22:32:12 -07003261 Log.w(this, "%s - Cannot find Connection %s", action, callId);
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07003262 return getNullConnection();
3263 }
3264
3265 static synchronized Connection getNullConnection() {
3266 if (sNullConnection == null) {
3267 sNullConnection = new Connection() {};
3268 }
3269 return sNullConnection;
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003270 }
Santos Cordon0159ac02014-08-21 14:28:11 -07003271
3272 private Conference findConferenceForAction(String conferenceId, String action) {
3273 if (mConferenceById.containsKey(conferenceId)) {
3274 return mConferenceById.get(conferenceId);
3275 }
3276 Log.w(this, "%s - Cannot find conference %s", action, conferenceId);
3277 return getNullConference();
3278 }
3279
Ihab Awadb8e85c72014-08-23 20:34:57 -07003280 private List<String> createConnectionIdList(List<Connection> connections) {
3281 List<String> ids = new ArrayList<>();
3282 for (Connection c : connections) {
3283 if (mIdByConnection.containsKey(c)) {
3284 ids.add(mIdByConnection.get(c));
3285 }
3286 }
3287 Collections.sort(ids);
3288 return ids;
3289 }
3290
Tyler Gunn6d76ca02014-11-17 15:49:51 -08003291 /**
3292 * Builds a list of {@link Connection} and {@link Conference} IDs based on the list of
Tyler Gunndf2cbc82015-04-20 09:13:01 -07003293 * {@link Conferenceable}s passed in.
Tyler Gunn6d76ca02014-11-17 15:49:51 -08003294 *
Tyler Gunndf2cbc82015-04-20 09:13:01 -07003295 * @param conferenceables The {@link Conferenceable} connections and conferences.
Tyler Gunn6d76ca02014-11-17 15:49:51 -08003296 * @return List of string conference and call Ids.
3297 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07003298 private List<String> createIdList(List<Conferenceable> conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08003299 List<String> ids = new ArrayList<>();
Tyler Gunndf2cbc82015-04-20 09:13:01 -07003300 for (Conferenceable c : conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08003301 // Only allow Connection and Conference conferenceables.
3302 if (c instanceof Connection) {
3303 Connection connection = (Connection) c;
3304 if (mIdByConnection.containsKey(connection)) {
3305 ids.add(mIdByConnection.get(connection));
3306 }
3307 } else if (c instanceof Conference) {
3308 Conference conference = (Conference) c;
3309 if (mIdByConference.containsKey(conference)) {
3310 ids.add(mIdByConference.get(conference));
3311 }
3312 }
3313 }
3314 Collections.sort(ids);
3315 return ids;
3316 }
3317
Santos Cordon0159ac02014-08-21 14:28:11 -07003318 private Conference getNullConference() {
3319 if (sNullConference == null) {
3320 sNullConference = new Conference(null) {};
3321 }
3322 return sNullConference;
3323 }
Santos Cordon29f2f2e2014-09-11 19:50:24 -07003324
3325 private void endAllConnections() {
3326 // Unbound from telecomm. We should end all connections and conferences.
3327 for (Connection connection : mIdByConnection.keySet()) {
3328 // only operate on top-level calls. Conference calls will be removed on their own.
3329 if (connection.getConference() == null) {
3330 connection.onDisconnect();
3331 }
3332 }
3333 for (Conference conference : mIdByConference.keySet()) {
3334 conference.onDisconnect();
3335 }
3336 }
Tyler Gunnf0500bd2015-09-01 10:59:48 -07003337
3338 /**
3339 * Retrieves the next call ID as maintainted by the connection service.
3340 *
3341 * @return The call ID.
3342 */
3343 private int getNextCallId() {
Brad Ebingerb32d4f82016-10-24 16:40:49 -07003344 synchronized (mIdSyncRoot) {
Tyler Gunnf0500bd2015-09-01 10:59:48 -07003345 return ++mId;
3346 }
3347 }
Brad Ebinger99f17ce2019-09-11 18:06:51 -07003348
3349 /**
3350 * Returns this handler, ONLY FOR TESTING.
3351 * @hide
3352 */
3353 @VisibleForTesting
3354 public Handler getHandler() {
3355 return mHandler;
3356 }
Santos Cordon980acb92014-05-31 10:31:19 -07003357}