blob: 6288bc1698e90928f980e454136e36d39ffef426 [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";
Tyler Gunn79bc1ec2018-01-22 15:17:54 -0800150 private static final String SESSION_HANDOVER_COMPLETE = "CS.hC";
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700151 private static final String SESSION_EXTRAS_CHANGED = "CS.oEC";
Hall Liub64ac4c2017-02-06 10:49:48 -0800152 private static final String SESSION_START_RTT = "CS.+RTT";
Hall Liua549fed2018-02-09 16:40:03 -0800153 private static final String SESSION_UPDATE_RTT_PIPES = "CS.uRTT";
Hall Liub64ac4c2017-02-06 10:49:48 -0800154 private static final String SESSION_STOP_RTT = "CS.-RTT";
155 private static final String SESSION_RTT_UPGRADE_RESPONSE = "CS.rTRUR";
Pengquan Meng731c1a32017-11-21 18:01:13 -0800156 private static final String SESSION_CONNECTION_SERVICE_FOCUS_LOST = "CS.cSFL";
157 private static final String SESSION_CONNECTION_SERVICE_FOCUS_GAINED = "CS.cSFG";
Sanket Padawe4cc8ed52017-12-04 16:22:20 -0800158 private static final String SESSION_HANDOVER_FAILED = "CS.haF";
Ravi Paluri80aa2142019-12-02 11:57:37 +0530159 private static final String SESSION_CREATE_CONF = "CS.crConf";
160 private static final String SESSION_CREATE_CONF_COMPLETE = "CS.crConfC";
161 private static final String SESSION_CREATE_CONF_FAILED = "CS.crConfF";
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700162
Ihab Awad8aecfed2014-08-08 17:06:11 -0700163 private static final int MSG_ADD_CONNECTION_SERVICE_ADAPTER = 1;
Sailesh Nepalc5b01572014-07-14 16:29:44 -0700164 private static final int MSG_CREATE_CONNECTION = 2;
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700165 private static final int MSG_ABORT = 3;
Sailesh Nepalc5b01572014-07-14 16:29:44 -0700166 private static final int MSG_ANSWER = 4;
167 private static final int MSG_REJECT = 5;
168 private static final int MSG_DISCONNECT = 6;
169 private static final int MSG_HOLD = 7;
170 private static final int MSG_UNHOLD = 8;
Yorke Lee4af59352015-05-13 14:14:54 -0700171 private static final int MSG_ON_CALL_AUDIO_STATE_CHANGED = 9;
Sailesh Nepalc5b01572014-07-14 16:29:44 -0700172 private static final int MSG_PLAY_DTMF_TONE = 10;
173 private static final int MSG_STOP_DTMF_TONE = 11;
174 private static final int MSG_CONFERENCE = 12;
175 private static final int MSG_SPLIT_FROM_CONFERENCE = 13;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700176 private static final int MSG_ON_POST_DIAL_CONTINUE = 14;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700177 private static final int MSG_REMOVE_CONNECTION_SERVICE_ADAPTER = 16;
Tyler Gunnbe74de02014-08-29 14:51:48 -0700178 private static final int MSG_ANSWER_VIDEO = 17;
Santos Cordona4868042014-09-04 17:39:22 -0700179 private static final int MSG_MERGE_CONFERENCE = 18;
180 private static final int MSG_SWAP_CONFERENCE = 19;
Bryce Lee81901682015-08-28 16:38:02 -0700181 private static final int MSG_REJECT_WITH_MESSAGE = 20;
Bryce Leecac50772015-11-17 15:13:29 -0800182 private static final int MSG_SILENCE = 21;
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700183 private static final int MSG_PULL_EXTERNAL_CALL = 22;
184 private static final int MSG_SEND_CALL_EVENT = 23;
Tyler Gunndee56a82016-03-23 16:06:34 -0700185 private static final int MSG_ON_EXTRAS_CHANGED = 24;
Tyler Gunn44e01912017-01-31 10:49:05 -0800186 private static final int MSG_CREATE_CONNECTION_FAILED = 25;
Hall Liub64ac4c2017-02-06 10:49:48 -0800187 private static final int MSG_ON_START_RTT = 26;
188 private static final int MSG_ON_STOP_RTT = 27;
189 private static final int MSG_RTT_UPGRADE_RESPONSE = 28;
Tyler Gunn041a1fe2017-05-12 10:04:49 -0700190 private static final int MSG_CREATE_CONNECTION_COMPLETE = 29;
Pengquan Meng731c1a32017-11-21 18:01:13 -0800191 private static final int MSG_CONNECTION_SERVICE_FOCUS_LOST = 30;
192 private static final int MSG_CONNECTION_SERVICE_FOCUS_GAINED = 31;
Sanket Padawe4cc8ed52017-12-04 16:22:20 -0800193 private static final int MSG_HANDOVER_FAILED = 32;
Tyler Gunn79bc1ec2018-01-22 15:17:54 -0800194 private static final int MSG_HANDOVER_COMPLETE = 33;
Pooja Jaind34698d2017-12-28 14:15:31 +0530195 private static final int MSG_DEFLECT = 34;
Ravi Paluri80aa2142019-12-02 11:57:37 +0530196 private static final int MSG_CREATE_CONFERENCE = 35;
197 private static final int MSG_CREATE_CONFERENCE_COMPLETE = 36;
198 private static final int MSG_CREATE_CONFERENCE_FAILED = 37;
Tyler Gunnfacfdee2020-01-23 13:10:37 -0800199 private static final int MSG_REJECT_WITH_REASON = 38;
Ravi Paluri404babb2020-01-23 19:02:44 +0530200 private static final int MSG_ADD_PARTICIPANT = 39;
Ravi Palurif4b38e72020-02-05 12:35:41 +0530201 private static final int MSG_EXPLICIT_CALL_TRANSFER = 40;
202 private static final int MSG_EXPLICIT_CALL_TRANSFER_CONSULTATIVE = 41;
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700203
Sailesh Nepalcf7020b2014-08-20 10:07:19 -0700204 private static Connection sNullConnection;
205
mike dooley95e80702014-09-18 14:07:52 -0700206 private final Map<String, Connection> mConnectionById = new ConcurrentHashMap<>();
207 private final Map<Connection, String> mIdByConnection = new ConcurrentHashMap<>();
208 private final Map<String, Conference> mConferenceById = new ConcurrentHashMap<>();
209 private final Map<Conference, String> mIdByConference = new ConcurrentHashMap<>();
Ihab Awadb8e85c72014-08-23 20:34:57 -0700210 private final RemoteConnectionManager mRemoteConnectionManager =
211 new RemoteConnectionManager(this);
Ihab Awad5d0410f2014-07-30 10:07:40 -0700212 private final List<Runnable> mPreInitializationConnectionRequests = new ArrayList<>();
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700213 private final ConnectionServiceAdapter mAdapter = new ConnectionServiceAdapter();
Ihab Awad542e0ea2014-05-16 10:22:16 -0700214
Santos Cordon823fd3c2014-08-07 18:35:18 -0700215 private boolean mAreAccountsInitialized = false;
Santos Cordon0159ac02014-08-21 14:28:11 -0700216 private Conference sNullConference;
Tyler Gunnf0500bd2015-09-01 10:59:48 -0700217 private Object mIdSyncRoot = new Object();
218 private int mId = 0;
Santos Cordon823fd3c2014-08-07 18:35:18 -0700219
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700220 private final IBinder mBinder = new IConnectionService.Stub() {
221 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700222 public void addConnectionServiceAdapter(IConnectionServiceAdapter adapter,
223 Session.Info sessionInfo) {
224 Log.startSession(sessionInfo, SESSION_ADD_CS_ADAPTER);
225 try {
226 SomeArgs args = SomeArgs.obtain();
227 args.arg1 = adapter;
228 args.arg2 = Log.createSubsession();
229 mHandler.obtainMessage(MSG_ADD_CONNECTION_SERVICE_ADAPTER, args).sendToTarget();
230 } finally {
231 Log.endSession();
232 }
Ihab Awad8aecfed2014-08-08 17:06:11 -0700233 }
234
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700235 public void removeConnectionServiceAdapter(IConnectionServiceAdapter adapter,
236 Session.Info sessionInfo) {
237 Log.startSession(sessionInfo, SESSION_REMOVE_CS_ADAPTER);
238 try {
239 SomeArgs args = SomeArgs.obtain();
240 args.arg1 = adapter;
241 args.arg2 = Log.createSubsession();
242 mHandler.obtainMessage(MSG_REMOVE_CONNECTION_SERVICE_ADAPTER, args).sendToTarget();
243 } finally {
244 Log.endSession();
245 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700246 }
247
248 @Override
Ihab Awadf8b69882014-07-25 15:14:01 -0700249 public void createConnection(
250 PhoneAccountHandle connectionManagerPhoneAccount,
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700251 String id,
Ihab Awadf8b69882014-07-25 15:14:01 -0700252 ConnectionRequest request,
Yorke Leec3cf9822014-10-02 09:38:39 -0700253 boolean isIncoming,
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700254 boolean isUnknown,
255 Session.Info sessionInfo) {
256 Log.startSession(sessionInfo, SESSION_CREATE_CONN);
257 try {
258 SomeArgs args = SomeArgs.obtain();
259 args.arg1 = connectionManagerPhoneAccount;
260 args.arg2 = id;
261 args.arg3 = request;
262 args.arg4 = Log.createSubsession();
263 args.argi1 = isIncoming ? 1 : 0;
264 args.argi2 = isUnknown ? 1 : 0;
265 mHandler.obtainMessage(MSG_CREATE_CONNECTION, args).sendToTarget();
266 } finally {
267 Log.endSession();
268 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700269 }
270
271 @Override
Tyler Gunn041a1fe2017-05-12 10:04:49 -0700272 public void createConnectionComplete(String id, Session.Info sessionInfo) {
273 Log.startSession(sessionInfo, SESSION_CREATE_CONN_COMPLETE);
274 try {
275 SomeArgs args = SomeArgs.obtain();
276 args.arg1 = id;
277 args.arg2 = Log.createSubsession();
278 mHandler.obtainMessage(MSG_CREATE_CONNECTION_COMPLETE, args).sendToTarget();
279 } finally {
280 Log.endSession();
281 }
282 }
283
284 @Override
Tyler Gunn44e01912017-01-31 10:49:05 -0800285 public void createConnectionFailed(
Tyler Gunn159f35c2017-03-02 09:28:37 -0800286 PhoneAccountHandle connectionManagerPhoneAccount,
Tyler Gunn44e01912017-01-31 10:49:05 -0800287 String callId,
288 ConnectionRequest request,
289 boolean isIncoming,
290 Session.Info sessionInfo) {
291 Log.startSession(sessionInfo, SESSION_CREATE_CONN_FAILED);
292 try {
293 SomeArgs args = SomeArgs.obtain();
294 args.arg1 = callId;
295 args.arg2 = request;
296 args.arg3 = Log.createSubsession();
Tyler Gunn159f35c2017-03-02 09:28:37 -0800297 args.arg4 = connectionManagerPhoneAccount;
Tyler Gunn44e01912017-01-31 10:49:05 -0800298 args.argi1 = isIncoming ? 1 : 0;
299 mHandler.obtainMessage(MSG_CREATE_CONNECTION_FAILED, args).sendToTarget();
300 } finally {
301 Log.endSession();
302 }
303 }
304
305 @Override
Ravi Paluri80aa2142019-12-02 11:57:37 +0530306 public void createConference(
307 PhoneAccountHandle connectionManagerPhoneAccount,
308 String id,
309 ConnectionRequest request,
310 boolean isIncoming,
311 boolean isUnknown,
312 Session.Info sessionInfo) {
313 Log.startSession(sessionInfo, SESSION_CREATE_CONF);
314 try {
315 SomeArgs args = SomeArgs.obtain();
316 args.arg1 = connectionManagerPhoneAccount;
317 args.arg2 = id;
318 args.arg3 = request;
319 args.arg4 = Log.createSubsession();
320 args.argi1 = isIncoming ? 1 : 0;
321 args.argi2 = isUnknown ? 1 : 0;
322 mHandler.obtainMessage(MSG_CREATE_CONFERENCE, args).sendToTarget();
323 } finally {
324 Log.endSession();
325 }
326 }
327
328 @Override
329 public void createConferenceComplete(String id, Session.Info sessionInfo) {
330 Log.startSession(sessionInfo, SESSION_CREATE_CONF_COMPLETE);
331 try {
332 SomeArgs args = SomeArgs.obtain();
333 args.arg1 = id;
334 args.arg2 = Log.createSubsession();
335 mHandler.obtainMessage(MSG_CREATE_CONFERENCE_COMPLETE, args).sendToTarget();
336 } finally {
337 Log.endSession();
338 }
339 }
340
341 @Override
342 public void createConferenceFailed(
343 PhoneAccountHandle connectionManagerPhoneAccount,
344 String callId,
345 ConnectionRequest request,
346 boolean isIncoming,
347 Session.Info sessionInfo) {
348 Log.startSession(sessionInfo, SESSION_CREATE_CONF_FAILED);
349 try {
350 SomeArgs args = SomeArgs.obtain();
351 args.arg1 = callId;
352 args.arg2 = request;
353 args.arg3 = Log.createSubsession();
354 args.arg4 = connectionManagerPhoneAccount;
355 args.argi1 = isIncoming ? 1 : 0;
356 mHandler.obtainMessage(MSG_CREATE_CONFERENCE_FAILED, args).sendToTarget();
357 } finally {
358 Log.endSession();
359 }
360 }
361
362 @Override
Sanket Padawe4cc8ed52017-12-04 16:22:20 -0800363 public void handoverFailed(String callId, ConnectionRequest request, int reason,
364 Session.Info sessionInfo) {
365 Log.startSession(sessionInfo, SESSION_HANDOVER_FAILED);
366 try {
367 SomeArgs args = SomeArgs.obtain();
368 args.arg1 = callId;
369 args.arg2 = request;
370 args.arg3 = Log.createSubsession();
371 args.arg4 = reason;
372 mHandler.obtainMessage(MSG_HANDOVER_FAILED, args).sendToTarget();
373 } finally {
374 Log.endSession();
375 }
376 }
377
378 @Override
Tyler Gunn79bc1ec2018-01-22 15:17:54 -0800379 public void handoverComplete(String callId, Session.Info sessionInfo) {
380 Log.startSession(sessionInfo, SESSION_HANDOVER_COMPLETE);
381 try {
382 SomeArgs args = SomeArgs.obtain();
383 args.arg1 = callId;
384 args.arg2 = Log.createSubsession();
385 mHandler.obtainMessage(MSG_HANDOVER_COMPLETE, args).sendToTarget();
386 } finally {
387 Log.endSession();
388 }
389 }
390
391 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700392 public void abort(String callId, Session.Info sessionInfo) {
393 Log.startSession(sessionInfo, SESSION_ABORT);
394 try {
395 SomeArgs args = SomeArgs.obtain();
396 args.arg1 = callId;
397 args.arg2 = Log.createSubsession();
398 mHandler.obtainMessage(MSG_ABORT, args).sendToTarget();
399 } finally {
400 Log.endSession();
401 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700402 }
403
404 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700405 public void answerVideo(String callId, int videoState, Session.Info sessionInfo) {
406 Log.startSession(sessionInfo, SESSION_ANSWER_VIDEO);
407 try {
408 SomeArgs args = SomeArgs.obtain();
409 args.arg1 = callId;
410 args.arg2 = Log.createSubsession();
411 args.argi1 = videoState;
412 mHandler.obtainMessage(MSG_ANSWER_VIDEO, args).sendToTarget();
413 } finally {
414 Log.endSession();
415 }
Tyler Gunnbe74de02014-08-29 14:51:48 -0700416 }
417
418 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700419 public void answer(String callId, Session.Info sessionInfo) {
420 Log.startSession(sessionInfo, SESSION_ANSWER);
421 try {
422 SomeArgs args = SomeArgs.obtain();
423 args.arg1 = callId;
424 args.arg2 = Log.createSubsession();
425 mHandler.obtainMessage(MSG_ANSWER, args).sendToTarget();
426 } finally {
427 Log.endSession();
428 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700429 }
430
431 @Override
Pooja Jaind34698d2017-12-28 14:15:31 +0530432 public void deflect(String callId, Uri address, Session.Info sessionInfo) {
433 Log.startSession(sessionInfo, SESSION_DEFLECT);
434 try {
435 SomeArgs args = SomeArgs.obtain();
436 args.arg1 = callId;
437 args.arg2 = address;
438 args.arg3 = Log.createSubsession();
439 mHandler.obtainMessage(MSG_DEFLECT, args).sendToTarget();
440 } finally {
441 Log.endSession();
442 }
443 }
444
445 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700446 public void reject(String callId, Session.Info sessionInfo) {
447 Log.startSession(sessionInfo, SESSION_REJECT);
448 try {
449 SomeArgs args = SomeArgs.obtain();
450 args.arg1 = callId;
451 args.arg2 = Log.createSubsession();
452 mHandler.obtainMessage(MSG_REJECT, args).sendToTarget();
453 } finally {
454 Log.endSession();
455 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700456 }
457
458 @Override
Tyler Gunnfacfdee2020-01-23 13:10:37 -0800459 public void rejectWithReason(String callId,
460 @android.telecom.Call.RejectReason int rejectReason, Session.Info sessionInfo) {
461 Log.startSession(sessionInfo, SESSION_REJECT);
462 try {
463 SomeArgs args = SomeArgs.obtain();
464 args.arg1 = callId;
465 args.argi1 = rejectReason;
466 args.arg2 = Log.createSubsession();
467 mHandler.obtainMessage(MSG_REJECT_WITH_REASON, args).sendToTarget();
468 } finally {
469 Log.endSession();
470 }
471 }
472
473 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700474 public void rejectWithMessage(String callId, String message, Session.Info sessionInfo) {
475 Log.startSession(sessionInfo, SESSION_REJECT_MESSAGE);
476 try {
477 SomeArgs args = SomeArgs.obtain();
478 args.arg1 = callId;
479 args.arg2 = message;
480 args.arg3 = Log.createSubsession();
481 mHandler.obtainMessage(MSG_REJECT_WITH_MESSAGE, args).sendToTarget();
482 } finally {
483 Log.endSession();
484 }
Bryce Lee81901682015-08-28 16:38:02 -0700485 }
486
487 @Override
Ravi Palurif4b38e72020-02-05 12:35:41 +0530488 public void transfer(@NonNull String callId, @NonNull Uri number,
489 boolean isConfirmationRequired, Session.Info sessionInfo) {
490 Log.startSession(sessionInfo, SESSION_TRANSFER);
491 try {
492 SomeArgs args = SomeArgs.obtain();
493 args.arg1 = callId;
494 args.arg2 = number;
495 args.argi1 = isConfirmationRequired ? 1 : 0;
496 args.arg3 = Log.createSubsession();
497 mHandler.obtainMessage(MSG_EXPLICIT_CALL_TRANSFER, args).sendToTarget();
498 } finally {
499 Log.endSession();
500 }
501 }
502
503 @Override
504 public void consultativeTransfer(@NonNull String callId, @NonNull String otherCallId,
505 Session.Info sessionInfo) {
506 Log.startSession(sessionInfo, SESSION_CONSULTATIVE_TRANSFER);
507 try {
508 SomeArgs args = SomeArgs.obtain();
509 args.arg1 = callId;
510 args.arg2 = otherCallId;
511 args.arg3 = Log.createSubsession();
512 mHandler.obtainMessage(
513 MSG_EXPLICIT_CALL_TRANSFER_CONSULTATIVE, args).sendToTarget();
514 } finally {
515 Log.endSession();
516 }
517 }
518
519 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700520 public void silence(String callId, Session.Info sessionInfo) {
521 Log.startSession(sessionInfo, SESSION_SILENCE);
522 try {
523 SomeArgs args = SomeArgs.obtain();
524 args.arg1 = callId;
525 args.arg2 = Log.createSubsession();
526 mHandler.obtainMessage(MSG_SILENCE, args).sendToTarget();
527 } finally {
528 Log.endSession();
529 }
Bryce Leecac50772015-11-17 15:13:29 -0800530 }
531
532 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700533 public void disconnect(String callId, Session.Info sessionInfo) {
534 Log.startSession(sessionInfo, SESSION_DISCONNECT);
535 try {
536 SomeArgs args = SomeArgs.obtain();
537 args.arg1 = callId;
538 args.arg2 = Log.createSubsession();
539 mHandler.obtainMessage(MSG_DISCONNECT, args).sendToTarget();
540 } finally {
541 Log.endSession();
542 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700543 }
544
545 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700546 public void hold(String callId, Session.Info sessionInfo) {
547 Log.startSession(sessionInfo, SESSION_HOLD);
548 try {
549 SomeArgs args = SomeArgs.obtain();
550 args.arg1 = callId;
551 args.arg2 = Log.createSubsession();
552 mHandler.obtainMessage(MSG_HOLD, args).sendToTarget();
553 } finally {
554 Log.endSession();
555 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700556 }
557
558 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700559 public void unhold(String callId, Session.Info sessionInfo) {
560 Log.startSession(sessionInfo, SESSION_UNHOLD);
561 try {
562 SomeArgs args = SomeArgs.obtain();
563 args.arg1 = callId;
564 args.arg2 = Log.createSubsession();
565 mHandler.obtainMessage(MSG_UNHOLD, args).sendToTarget();
566 } finally {
567 Log.endSession();
568 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700569 }
570
571 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700572 public void onCallAudioStateChanged(String callId, CallAudioState callAudioState,
573 Session.Info sessionInfo) {
574 Log.startSession(sessionInfo, SESSION_CALL_AUDIO_SC);
575 try {
576 SomeArgs args = SomeArgs.obtain();
577 args.arg1 = callId;
578 args.arg2 = callAudioState;
579 args.arg3 = Log.createSubsession();
580 mHandler.obtainMessage(MSG_ON_CALL_AUDIO_STATE_CHANGED, args).sendToTarget();
581 } finally {
582 Log.endSession();
583 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700584 }
585
586 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700587 public void playDtmfTone(String callId, char digit, Session.Info sessionInfo) {
588 Log.startSession(sessionInfo, SESSION_PLAY_DTMF);
589 try {
590 SomeArgs args = SomeArgs.obtain();
591 args.arg1 = digit;
592 args.arg2 = callId;
593 args.arg3 = Log.createSubsession();
594 mHandler.obtainMessage(MSG_PLAY_DTMF_TONE, args).sendToTarget();
595 } finally {
596 Log.endSession();
597 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700598 }
599
600 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700601 public void stopDtmfTone(String callId, Session.Info sessionInfo) {
602 Log.startSession(sessionInfo, SESSION_STOP_DTMF);
603 try {
604 SomeArgs args = SomeArgs.obtain();
605 args.arg1 = callId;
606 args.arg2 = Log.createSubsession();
607 mHandler.obtainMessage(MSG_STOP_DTMF_TONE, args).sendToTarget();
608 } finally {
609 Log.endSession();
610 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700611 }
612
613 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700614 public void conference(String callId1, String callId2, Session.Info sessionInfo) {
615 Log.startSession(sessionInfo, SESSION_CONFERENCE);
616 try {
617 SomeArgs args = SomeArgs.obtain();
618 args.arg1 = callId1;
619 args.arg2 = callId2;
620 args.arg3 = Log.createSubsession();
621 mHandler.obtainMessage(MSG_CONFERENCE, args).sendToTarget();
622 } finally {
623 Log.endSession();
624 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700625 }
626
627 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700628 public void splitFromConference(String callId, Session.Info sessionInfo) {
629 Log.startSession(sessionInfo, SESSION_SPLIT_CONFERENCE);
630 try {
631 SomeArgs args = SomeArgs.obtain();
632 args.arg1 = callId;
633 args.arg2 = Log.createSubsession();
634 mHandler.obtainMessage(MSG_SPLIT_FROM_CONFERENCE, args).sendToTarget();
635 } finally {
636 Log.endSession();
637 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700638 }
639
640 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700641 public void mergeConference(String callId, Session.Info sessionInfo) {
642 Log.startSession(sessionInfo, SESSION_MERGE_CONFERENCE);
643 try {
644 SomeArgs args = SomeArgs.obtain();
645 args.arg1 = callId;
646 args.arg2 = Log.createSubsession();
647 mHandler.obtainMessage(MSG_MERGE_CONFERENCE, args).sendToTarget();
648 } finally {
649 Log.endSession();
650 }
Santos Cordona4868042014-09-04 17:39:22 -0700651 }
652
653 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700654 public void swapConference(String callId, Session.Info sessionInfo) {
655 Log.startSession(sessionInfo, SESSION_SWAP_CONFERENCE);
656 try {
657 SomeArgs args = SomeArgs.obtain();
658 args.arg1 = callId;
659 args.arg2 = Log.createSubsession();
660 mHandler.obtainMessage(MSG_SWAP_CONFERENCE, args).sendToTarget();
661 } finally {
662 Log.endSession();
663 }
Santos Cordona4868042014-09-04 17:39:22 -0700664 }
665
666 @Override
Ravi Paluri404babb2020-01-23 19:02:44 +0530667 public void addConferenceParticipants(String callId, List<Uri> participants,
668 Session.Info sessionInfo) {
669 Log.startSession(sessionInfo, SESSION_ADD_PARTICIPANT);
670 try {
671 SomeArgs args = SomeArgs.obtain();
672 args.arg1 = callId;
673 args.arg2 = participants;
674 args.arg3 = Log.createSubsession();
675 mHandler.obtainMessage(MSG_ADD_PARTICIPANT, args).sendToTarget();
676 } finally {
677 Log.endSession();
678 }
679 }
680
681 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700682 public void onPostDialContinue(String callId, boolean proceed, Session.Info sessionInfo) {
683 Log.startSession(sessionInfo, SESSION_POST_DIAL_CONT);
684 try {
685 SomeArgs args = SomeArgs.obtain();
686 args.arg1 = callId;
687 args.arg2 = Log.createSubsession();
688 args.argi1 = proceed ? 1 : 0;
689 mHandler.obtainMessage(MSG_ON_POST_DIAL_CONTINUE, args).sendToTarget();
690 } finally {
691 Log.endSession();
692 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700693 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700694
695 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700696 public void pullExternalCall(String callId, Session.Info sessionInfo) {
697 Log.startSession(sessionInfo, SESSION_PULL_EXTERNAL_CALL);
698 try {
699 SomeArgs args = SomeArgs.obtain();
700 args.arg1 = callId;
701 args.arg2 = Log.createSubsession();
702 mHandler.obtainMessage(MSG_PULL_EXTERNAL_CALL, args).sendToTarget();
703 } finally {
704 Log.endSession();
705 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700706 }
707
708 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700709 public void sendCallEvent(String callId, String event, Bundle extras,
710 Session.Info sessionInfo) {
711 Log.startSession(sessionInfo, SESSION_SEND_CALL_EVENT);
712 try {
713 SomeArgs args = SomeArgs.obtain();
714 args.arg1 = callId;
715 args.arg2 = event;
716 args.arg3 = extras;
717 args.arg4 = Log.createSubsession();
718 mHandler.obtainMessage(MSG_SEND_CALL_EVENT, args).sendToTarget();
719 } finally {
720 Log.endSession();
721 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700722 }
Tyler Gunndee56a82016-03-23 16:06:34 -0700723
724 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700725 public void onExtrasChanged(String callId, Bundle extras, Session.Info sessionInfo) {
726 Log.startSession(sessionInfo, SESSION_EXTRAS_CHANGED);
727 try {
728 SomeArgs args = SomeArgs.obtain();
729 args.arg1 = callId;
730 args.arg2 = extras;
731 args.arg3 = Log.createSubsession();
732 mHandler.obtainMessage(MSG_ON_EXTRAS_CHANGED, args).sendToTarget();
733 } finally {
734 Log.endSession();
735 }
Tyler Gunndee56a82016-03-23 16:06:34 -0700736 }
Hall Liub64ac4c2017-02-06 10:49:48 -0800737
738 @Override
739 public void startRtt(String callId, ParcelFileDescriptor fromInCall,
740 ParcelFileDescriptor toInCall, Session.Info sessionInfo) throws RemoteException {
741 Log.startSession(sessionInfo, SESSION_START_RTT);
742 try {
743 SomeArgs args = SomeArgs.obtain();
744 args.arg1 = callId;
745 args.arg2 = new Connection.RttTextStream(toInCall, fromInCall);
746 args.arg3 = Log.createSubsession();
747 mHandler.obtainMessage(MSG_ON_START_RTT, args).sendToTarget();
748 } finally {
749 Log.endSession();
750 }
751 }
752
753 @Override
754 public void stopRtt(String callId, Session.Info sessionInfo) throws RemoteException {
755 Log.startSession(sessionInfo, SESSION_STOP_RTT);
756 try {
757 SomeArgs args = SomeArgs.obtain();
758 args.arg1 = callId;
759 args.arg2 = Log.createSubsession();
760 mHandler.obtainMessage(MSG_ON_STOP_RTT, args).sendToTarget();
761 } finally {
762 Log.endSession();
763 }
764 }
765
766 @Override
767 public void respondToRttUpgradeRequest(String callId, ParcelFileDescriptor fromInCall,
768 ParcelFileDescriptor toInCall, Session.Info sessionInfo) throws RemoteException {
769 Log.startSession(sessionInfo, SESSION_RTT_UPGRADE_RESPONSE);
770 try {
771 SomeArgs args = SomeArgs.obtain();
772 args.arg1 = callId;
773 if (toInCall == null || fromInCall == null) {
774 args.arg2 = null;
775 } else {
776 args.arg2 = new Connection.RttTextStream(toInCall, fromInCall);
777 }
778 args.arg3 = Log.createSubsession();
779 mHandler.obtainMessage(MSG_RTT_UPGRADE_RESPONSE, args).sendToTarget();
780 } finally {
781 Log.endSession();
782 }
783 }
Pengquan Meng731c1a32017-11-21 18:01:13 -0800784
785 @Override
786 public void connectionServiceFocusLost(Session.Info sessionInfo) throws RemoteException {
787 Log.startSession(sessionInfo, SESSION_CONNECTION_SERVICE_FOCUS_LOST);
788 try {
789 mHandler.obtainMessage(MSG_CONNECTION_SERVICE_FOCUS_LOST).sendToTarget();
790 } finally {
791 Log.endSession();
792 }
793 }
794
795 @Override
796 public void connectionServiceFocusGained(Session.Info sessionInfo) throws RemoteException {
797 Log.startSession(sessionInfo, SESSION_CONNECTION_SERVICE_FOCUS_GAINED);
798 try {
799 mHandler.obtainMessage(MSG_CONNECTION_SERVICE_FOCUS_GAINED).sendToTarget();
800 } finally {
801 Log.endSession();
802 }
803 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700804 };
805
806 private final Handler mHandler = new Handler(Looper.getMainLooper()) {
807 @Override
808 public void handleMessage(Message msg) {
809 switch (msg.what) {
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700810 case MSG_ADD_CONNECTION_SERVICE_ADAPTER: {
811 SomeArgs args = (SomeArgs) msg.obj;
812 try {
813 IConnectionServiceAdapter adapter = (IConnectionServiceAdapter) args.arg1;
814 Log.continueSession((Session) args.arg2,
815 SESSION_HANDLER + SESSION_ADD_CS_ADAPTER);
816 mAdapter.addAdapter(adapter);
817 onAdapterAttached();
818 } finally {
819 args.recycle();
820 Log.endSession();
821 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700822 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700823 }
824 case MSG_REMOVE_CONNECTION_SERVICE_ADAPTER: {
825 SomeArgs args = (SomeArgs) msg.obj;
826 try {
827 Log.continueSession((Session) args.arg2,
828 SESSION_HANDLER + SESSION_REMOVE_CS_ADAPTER);
829 mAdapter.removeAdapter((IConnectionServiceAdapter) args.arg1);
830 } finally {
831 args.recycle();
832 Log.endSession();
833 }
Ihab Awad8aecfed2014-08-08 17:06:11 -0700834 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700835 }
Ihab Awadf8b69882014-07-25 15:14:01 -0700836 case MSG_CREATE_CONNECTION: {
837 SomeArgs args = (SomeArgs) msg.obj;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700838 Log.continueSession((Session) args.arg4, SESSION_HANDLER + SESSION_CREATE_CONN);
Ihab Awadf8b69882014-07-25 15:14:01 -0700839 try {
Ihab Awad5d0410f2014-07-30 10:07:40 -0700840 final PhoneAccountHandle connectionManagerPhoneAccount =
Ihab Awadf8b69882014-07-25 15:14:01 -0700841 (PhoneAccountHandle) args.arg1;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700842 final String id = (String) args.arg2;
843 final ConnectionRequest request = (ConnectionRequest) args.arg3;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700844 final boolean isIncoming = args.argi1 == 1;
Yorke Leec3cf9822014-10-02 09:38:39 -0700845 final boolean isUnknown = args.argi2 == 1;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700846 if (!mAreAccountsInitialized) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700847 Log.d(this, "Enqueueing pre-init request %s", id);
Brad Ebinger0c3541b2016-11-01 14:11:38 -0700848 mPreInitializationConnectionRequests.add(
849 new android.telecom.Logging.Runnable(
850 SESSION_HANDLER + SESSION_CREATE_CONN + ".pICR",
851 null /*lock*/) {
Ihab Awad5d0410f2014-07-30 10:07:40 -0700852 @Override
Brad Ebinger0c3541b2016-11-01 14:11:38 -0700853 public void loggedRun() {
Ihab Awad5d0410f2014-07-30 10:07:40 -0700854 createConnection(
855 connectionManagerPhoneAccount,
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700856 id,
Ihab Awad5d0410f2014-07-30 10:07:40 -0700857 request,
Yorke Leec3cf9822014-10-02 09:38:39 -0700858 isIncoming,
859 isUnknown);
Ihab Awad5d0410f2014-07-30 10:07:40 -0700860 }
Brad Ebinger0c3541b2016-11-01 14:11:38 -0700861 }.prepare());
Ihab Awad5d0410f2014-07-30 10:07:40 -0700862 } else {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700863 createConnection(
864 connectionManagerPhoneAccount,
865 id,
866 request,
Yorke Leec3cf9822014-10-02 09:38:39 -0700867 isIncoming,
868 isUnknown);
Ihab Awad5d0410f2014-07-30 10:07:40 -0700869 }
Ihab Awadf8b69882014-07-25 15:14:01 -0700870 } finally {
871 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700872 Log.endSession();
Ihab Awadf8b69882014-07-25 15:14:01 -0700873 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700874 break;
Ihab Awadf8b69882014-07-25 15:14:01 -0700875 }
Tyler Gunn041a1fe2017-05-12 10:04:49 -0700876 case MSG_CREATE_CONNECTION_COMPLETE: {
877 SomeArgs args = (SomeArgs) msg.obj;
878 Log.continueSession((Session) args.arg2,
879 SESSION_HANDLER + SESSION_CREATE_CONN_COMPLETE);
880 try {
881 final String id = (String) args.arg1;
882 if (!mAreAccountsInitialized) {
883 Log.d(this, "Enqueueing pre-init request %s", id);
884 mPreInitializationConnectionRequests.add(
885 new android.telecom.Logging.Runnable(
886 SESSION_HANDLER + SESSION_CREATE_CONN_COMPLETE
887 + ".pICR",
888 null /*lock*/) {
889 @Override
890 public void loggedRun() {
891 notifyCreateConnectionComplete(id);
892 }
893 }.prepare());
894 } else {
895 notifyCreateConnectionComplete(id);
896 }
897 } finally {
898 args.recycle();
899 Log.endSession();
900 }
901 break;
902 }
Tyler Gunn44e01912017-01-31 10:49:05 -0800903 case MSG_CREATE_CONNECTION_FAILED: {
904 SomeArgs args = (SomeArgs) msg.obj;
905 Log.continueSession((Session) args.arg3, SESSION_HANDLER +
906 SESSION_CREATE_CONN_FAILED);
907 try {
908 final String id = (String) args.arg1;
909 final ConnectionRequest request = (ConnectionRequest) args.arg2;
910 final boolean isIncoming = args.argi1 == 1;
Tyler Gunn159f35c2017-03-02 09:28:37 -0800911 final PhoneAccountHandle connectionMgrPhoneAccount =
912 (PhoneAccountHandle) args.arg4;
Tyler Gunn44e01912017-01-31 10:49:05 -0800913 if (!mAreAccountsInitialized) {
914 Log.d(this, "Enqueueing pre-init request %s", id);
915 mPreInitializationConnectionRequests.add(
916 new android.telecom.Logging.Runnable(
917 SESSION_HANDLER + SESSION_CREATE_CONN_FAILED + ".pICR",
918 null /*lock*/) {
919 @Override
920 public void loggedRun() {
Tyler Gunn159f35c2017-03-02 09:28:37 -0800921 createConnectionFailed(connectionMgrPhoneAccount, id,
922 request, isIncoming);
Tyler Gunn44e01912017-01-31 10:49:05 -0800923 }
924 }.prepare());
925 } else {
926 Log.i(this, "createConnectionFailed %s", id);
Tyler Gunn159f35c2017-03-02 09:28:37 -0800927 createConnectionFailed(connectionMgrPhoneAccount, id, request,
928 isIncoming);
Tyler Gunn44e01912017-01-31 10:49:05 -0800929 }
930 } finally {
931 args.recycle();
932 Log.endSession();
933 }
934 break;
935 }
Ravi Paluri80aa2142019-12-02 11:57:37 +0530936 case MSG_CREATE_CONFERENCE: {
937 SomeArgs args = (SomeArgs) msg.obj;
938 Log.continueSession((Session) args.arg4, SESSION_HANDLER + SESSION_CREATE_CONN);
939 try {
940 final PhoneAccountHandle connectionManagerPhoneAccount =
941 (PhoneAccountHandle) args.arg1;
942 final String id = (String) args.arg2;
943 final ConnectionRequest request = (ConnectionRequest) args.arg3;
944 final boolean isIncoming = args.argi1 == 1;
945 final boolean isUnknown = args.argi2 == 1;
946 if (!mAreAccountsInitialized) {
947 Log.d(this, "Enqueueing pre-initconference request %s", id);
948 mPreInitializationConnectionRequests.add(
949 new android.telecom.Logging.Runnable(
950 SESSION_HANDLER + SESSION_CREATE_CONF + ".pIConfR",
951 null /*lock*/) {
952 @Override
953 public void loggedRun() {
954 createConference(connectionManagerPhoneAccount,
955 id,
956 request,
957 isIncoming,
958 isUnknown);
959 }
960 }.prepare());
961 } else {
962 createConference(connectionManagerPhoneAccount,
963 id,
964 request,
965 isIncoming,
966 isUnknown);
967 }
968 } finally {
969 args.recycle();
970 Log.endSession();
971 }
972 break;
973 }
974 case MSG_CREATE_CONFERENCE_COMPLETE: {
975 SomeArgs args = (SomeArgs) msg.obj;
976 Log.continueSession((Session) args.arg2,
977 SESSION_HANDLER + SESSION_CREATE_CONN_COMPLETE);
978 try {
979 final String id = (String) args.arg1;
980 if (!mAreAccountsInitialized) {
981 Log.d(this, "Enqueueing pre-init conference request %s", id);
982 mPreInitializationConnectionRequests.add(
983 new android.telecom.Logging.Runnable(
984 SESSION_HANDLER + SESSION_CREATE_CONF_COMPLETE
985 + ".pIConfR",
986 null /*lock*/) {
987 @Override
988 public void loggedRun() {
989 notifyCreateConferenceComplete(id);
990 }
991 }.prepare());
992 } else {
993 notifyCreateConferenceComplete(id);
994 }
995 } finally {
996 args.recycle();
997 Log.endSession();
998 }
999 break;
1000 }
1001 case MSG_CREATE_CONFERENCE_FAILED: {
1002 SomeArgs args = (SomeArgs) msg.obj;
1003 Log.continueSession((Session) args.arg3, SESSION_HANDLER +
1004 SESSION_CREATE_CONN_FAILED);
1005 try {
1006 final String id = (String) args.arg1;
1007 final ConnectionRequest request = (ConnectionRequest) args.arg2;
1008 final boolean isIncoming = args.argi1 == 1;
1009 final PhoneAccountHandle connectionMgrPhoneAccount =
1010 (PhoneAccountHandle) args.arg4;
1011 if (!mAreAccountsInitialized) {
1012 Log.d(this, "Enqueueing pre-init conference request %s", id);
1013 mPreInitializationConnectionRequests.add(
1014 new android.telecom.Logging.Runnable(
1015 SESSION_HANDLER + SESSION_CREATE_CONF_FAILED
1016 + ".pIConfR",
1017 null /*lock*/) {
1018 @Override
1019 public void loggedRun() {
1020 createConferenceFailed(connectionMgrPhoneAccount, id,
1021 request, isIncoming);
1022 }
1023 }.prepare());
1024 } else {
1025 Log.i(this, "createConferenceFailed %s", id);
1026 createConferenceFailed(connectionMgrPhoneAccount, id, request,
1027 isIncoming);
1028 }
1029 } finally {
1030 args.recycle();
1031 Log.endSession();
1032 }
1033 break;
1034 }
1035
Sanket Padawe4cc8ed52017-12-04 16:22:20 -08001036 case MSG_HANDOVER_FAILED: {
1037 SomeArgs args = (SomeArgs) msg.obj;
1038 Log.continueSession((Session) args.arg3, SESSION_HANDLER +
1039 SESSION_HANDOVER_FAILED);
1040 try {
1041 final String id = (String) args.arg1;
1042 final ConnectionRequest request = (ConnectionRequest) args.arg2;
1043 final int reason = (int) args.arg4;
1044 if (!mAreAccountsInitialized) {
1045 Log.d(this, "Enqueueing pre-init request %s", id);
1046 mPreInitializationConnectionRequests.add(
1047 new android.telecom.Logging.Runnable(
1048 SESSION_HANDLER
1049 + SESSION_HANDOVER_FAILED + ".pICR",
1050 null /*lock*/) {
1051 @Override
1052 public void loggedRun() {
1053 handoverFailed(id, request, reason);
1054 }
1055 }.prepare());
1056 } else {
1057 Log.i(this, "createConnectionFailed %s", id);
1058 handoverFailed(id, request, reason);
1059 }
1060 } finally {
1061 args.recycle();
1062 Log.endSession();
1063 }
1064 break;
1065 }
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001066 case MSG_ABORT: {
1067 SomeArgs args = (SomeArgs) msg.obj;
1068 Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_ABORT);
1069 try {
1070 abort((String) args.arg1);
1071 } finally {
1072 args.recycle();
1073 Log.endSession();
1074 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001075 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001076 }
1077 case MSG_ANSWER: {
1078 SomeArgs args = (SomeArgs) msg.obj;
1079 Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_ANSWER);
1080 try {
1081 answer((String) args.arg1);
1082 } finally {
1083 args.recycle();
1084 Log.endSession();
1085 }
Tyler Gunnbe74de02014-08-29 14:51:48 -07001086 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001087 }
Tyler Gunnbe74de02014-08-29 14:51:48 -07001088 case MSG_ANSWER_VIDEO: {
Andrew Lee8da4c3c2014-07-16 10:11:42 -07001089 SomeArgs args = (SomeArgs) msg.obj;
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001090 Log.continueSession((Session) args.arg2,
1091 SESSION_HANDLER + SESSION_ANSWER_VIDEO);
Andrew Lee8da4c3c2014-07-16 10:11:42 -07001092 try {
1093 String callId = (String) args.arg1;
Evan Charltonbf11f982014-07-20 22:06:28 -07001094 int videoState = args.argi1;
Tyler Gunnbe74de02014-08-29 14:51:48 -07001095 answerVideo(callId, videoState);
Andrew Lee8da4c3c2014-07-16 10:11:42 -07001096 } finally {
1097 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001098 Log.endSession();
Andrew Lee8da4c3c2014-07-16 10:11:42 -07001099 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001100 break;
Andrew Lee8da4c3c2014-07-16 10:11:42 -07001101 }
Pooja Jaind34698d2017-12-28 14:15:31 +05301102 case MSG_DEFLECT: {
1103 SomeArgs args = (SomeArgs) msg.obj;
1104 Log.continueSession((Session) args.arg3, SESSION_HANDLER + SESSION_DEFLECT);
1105 try {
1106 deflect((String) args.arg1, (Uri) args.arg2);
1107 } finally {
1108 args.recycle();
1109 Log.endSession();
1110 }
1111 break;
1112 }
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001113 case MSG_REJECT: {
1114 SomeArgs args = (SomeArgs) msg.obj;
1115 Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_REJECT);
1116 try {
1117 reject((String) args.arg1);
1118 } finally {
1119 args.recycle();
1120 Log.endSession();
1121 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001122 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001123 }
Tyler Gunnfacfdee2020-01-23 13:10:37 -08001124 case MSG_REJECT_WITH_REASON: {
1125 SomeArgs args = (SomeArgs) msg.obj;
1126 Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_REJECT);
1127 try {
1128 reject((String) args.arg1, args.argi1);
1129 } finally {
1130 args.recycle();
1131 Log.endSession();
1132 }
1133 break;
1134 }
Bryce Lee81901682015-08-28 16:38:02 -07001135 case MSG_REJECT_WITH_MESSAGE: {
1136 SomeArgs args = (SomeArgs) msg.obj;
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001137 Log.continueSession((Session) args.arg3,
1138 SESSION_HANDLER + SESSION_REJECT_MESSAGE);
Bryce Lee81901682015-08-28 16:38:02 -07001139 try {
1140 reject((String) args.arg1, (String) args.arg2);
1141 } finally {
1142 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001143 Log.endSession();
Bryce Lee81901682015-08-28 16:38:02 -07001144 }
1145 break;
1146 }
Ravi Palurif4b38e72020-02-05 12:35:41 +05301147 case MSG_EXPLICIT_CALL_TRANSFER: {
1148 SomeArgs args = (SomeArgs) msg.obj;
1149 Log.continueSession((Session) args.arg3, SESSION_HANDLER + SESSION_TRANSFER);
1150 try {
1151 final boolean isConfirmationRequired = args.argi1 == 1;
1152 transfer((String) args.arg1, (Uri) args.arg2, isConfirmationRequired);
1153 } finally {
1154 args.recycle();
1155 Log.endSession();
1156 }
1157 break;
1158 }
1159 case MSG_EXPLICIT_CALL_TRANSFER_CONSULTATIVE: {
1160 SomeArgs args = (SomeArgs) msg.obj;
1161 Log.continueSession(
1162 (Session) args.arg3, SESSION_HANDLER + SESSION_CONSULTATIVE_TRANSFER);
1163 try {
1164 consultativeTransfer((String) args.arg1, (String) args.arg2);
1165 } finally {
1166 args.recycle();
1167 Log.endSession();
1168 }
1169 break;
1170 }
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001171 case MSG_DISCONNECT: {
1172 SomeArgs args = (SomeArgs) msg.obj;
1173 Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_DISCONNECT);
1174 try {
1175 disconnect((String) args.arg1);
1176 } finally {
1177 args.recycle();
1178 Log.endSession();
1179 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001180 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001181 }
1182 case MSG_SILENCE: {
1183 SomeArgs args = (SomeArgs) msg.obj;
1184 Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_SILENCE);
1185 try {
1186 silence((String) args.arg1);
1187 } finally {
1188 args.recycle();
1189 Log.endSession();
1190 }
Bryce Leecac50772015-11-17 15:13:29 -08001191 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001192 }
1193 case MSG_HOLD: {
1194 SomeArgs args = (SomeArgs) msg.obj;
1195 Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_REJECT);
1196 try {
1197 hold((String) args.arg1);
1198 } finally {
1199 args.recycle();
1200 Log.endSession();
1201 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001202 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001203 }
1204 case MSG_UNHOLD: {
1205 SomeArgs args = (SomeArgs) msg.obj;
1206 Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_UNHOLD);
1207 try {
1208 unhold((String) args.arg1);
1209 } finally {
1210 args.recycle();
1211 Log.endSession();
1212 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001213 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001214 }
Yorke Lee4af59352015-05-13 14:14:54 -07001215 case MSG_ON_CALL_AUDIO_STATE_CHANGED: {
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001216 SomeArgs args = (SomeArgs) msg.obj;
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001217 Log.continueSession((Session) args.arg3,
1218 SESSION_HANDLER + SESSION_CALL_AUDIO_SC);
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001219 try {
1220 String callId = (String) args.arg1;
Yorke Lee4af59352015-05-13 14:14:54 -07001221 CallAudioState audioState = (CallAudioState) args.arg2;
1222 onCallAudioStateChanged(callId, new CallAudioState(audioState));
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001223 } finally {
1224 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001225 Log.endSession();
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001226 }
1227 break;
1228 }
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001229 case MSG_PLAY_DTMF_TONE: {
1230 SomeArgs args = (SomeArgs) msg.obj;
1231 try {
1232 Log.continueSession((Session) args.arg3,
1233 SESSION_HANDLER + SESSION_PLAY_DTMF);
1234 playDtmfTone((String) args.arg2, (char) args.arg1);
1235 } finally {
1236 args.recycle();
1237 Log.endSession();
1238 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001239 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001240 }
1241 case MSG_STOP_DTMF_TONE: {
1242 SomeArgs args = (SomeArgs) msg.obj;
1243 try {
1244 Log.continueSession((Session) args.arg2,
1245 SESSION_HANDLER + SESSION_STOP_DTMF);
1246 stopDtmfTone((String) args.arg1);
1247 } finally {
1248 args.recycle();
1249 Log.endSession();
1250 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001251 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001252 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001253 case MSG_CONFERENCE: {
1254 SomeArgs args = (SomeArgs) msg.obj;
1255 try {
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001256 Log.continueSession((Session) args.arg3,
1257 SESSION_HANDLER + SESSION_CONFERENCE);
Santos Cordon823fd3c2014-08-07 18:35:18 -07001258 String callId1 = (String) args.arg1;
1259 String callId2 = (String) args.arg2;
1260 conference(callId1, callId2);
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001261 } finally {
1262 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001263 Log.endSession();
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001264 }
1265 break;
1266 }
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001267 case MSG_SPLIT_FROM_CONFERENCE: {
1268 SomeArgs args = (SomeArgs) msg.obj;
1269 try {
1270 Log.continueSession((Session) args.arg2,
1271 SESSION_HANDLER + SESSION_SPLIT_CONFERENCE);
1272 splitFromConference((String) args.arg1);
1273 } finally {
1274 args.recycle();
1275 Log.endSession();
1276 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001277 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001278 }
1279 case MSG_MERGE_CONFERENCE: {
1280 SomeArgs args = (SomeArgs) msg.obj;
1281 try {
1282 Log.continueSession((Session) args.arg2,
1283 SESSION_HANDLER + SESSION_MERGE_CONFERENCE);
1284 mergeConference((String) args.arg1);
1285 } finally {
1286 args.recycle();
1287 Log.endSession();
1288 }
Santos Cordona4868042014-09-04 17:39:22 -07001289 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001290 }
1291 case MSG_SWAP_CONFERENCE: {
1292 SomeArgs args = (SomeArgs) msg.obj;
1293 try {
1294 Log.continueSession((Session) args.arg2,
1295 SESSION_HANDLER + SESSION_SWAP_CONFERENCE);
1296 swapConference((String) args.arg1);
1297 } finally {
1298 args.recycle();
1299 Log.endSession();
1300 }
Santos Cordona4868042014-09-04 17:39:22 -07001301 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001302 }
Ravi Paluri404babb2020-01-23 19:02:44 +05301303 case MSG_ADD_PARTICIPANT: {
1304 SomeArgs args = (SomeArgs) msg.obj;
1305 try {
1306 Log.continueSession((Session) args.arg3,
1307 SESSION_HANDLER + SESSION_ADD_PARTICIPANT);
1308 addConferenceParticipants((String) args.arg1, (List<Uri>)args.arg2);
1309 } finally {
1310 args.recycle();
1311 Log.endSession();
1312 }
1313 break;
1314 }
1315
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001316 case MSG_ON_POST_DIAL_CONTINUE: {
1317 SomeArgs args = (SomeArgs) msg.obj;
1318 try {
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001319 Log.continueSession((Session) args.arg2,
1320 SESSION_HANDLER + SESSION_POST_DIAL_CONT);
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001321 String callId = (String) args.arg1;
1322 boolean proceed = (args.argi1 == 1);
1323 onPostDialContinue(callId, proceed);
1324 } finally {
1325 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001326 Log.endSession();
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001327 }
1328 break;
1329 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001330 case MSG_PULL_EXTERNAL_CALL: {
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001331 SomeArgs args = (SomeArgs) msg.obj;
1332 try {
1333 Log.continueSession((Session) args.arg2,
1334 SESSION_HANDLER + SESSION_PULL_EXTERNAL_CALL);
1335 pullExternalCall((String) args.arg1);
1336 } finally {
1337 args.recycle();
1338 Log.endSession();
1339 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001340 break;
1341 }
1342 case MSG_SEND_CALL_EVENT: {
1343 SomeArgs args = (SomeArgs) msg.obj;
1344 try {
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001345 Log.continueSession((Session) args.arg4,
1346 SESSION_HANDLER + SESSION_SEND_CALL_EVENT);
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001347 String callId = (String) args.arg1;
1348 String event = (String) args.arg2;
1349 Bundle extras = (Bundle) args.arg3;
1350 sendCallEvent(callId, event, extras);
1351 } finally {
1352 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001353 Log.endSession();
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001354 }
1355 break;
1356 }
Tyler Gunn79bc1ec2018-01-22 15:17:54 -08001357 case MSG_HANDOVER_COMPLETE: {
1358 SomeArgs args = (SomeArgs) msg.obj;
1359 try {
1360 Log.continueSession((Session) args.arg2,
1361 SESSION_HANDLER + SESSION_HANDOVER_COMPLETE);
1362 String callId = (String) args.arg1;
1363 notifyHandoverComplete(callId);
1364 } finally {
1365 args.recycle();
1366 Log.endSession();
1367 }
1368 break;
1369 }
Tyler Gunndee56a82016-03-23 16:06:34 -07001370 case MSG_ON_EXTRAS_CHANGED: {
1371 SomeArgs args = (SomeArgs) msg.obj;
1372 try {
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001373 Log.continueSession((Session) args.arg3,
1374 SESSION_HANDLER + SESSION_EXTRAS_CHANGED);
Tyler Gunndee56a82016-03-23 16:06:34 -07001375 String callId = (String) args.arg1;
1376 Bundle extras = (Bundle) args.arg2;
1377 handleExtrasChanged(callId, extras);
1378 } finally {
1379 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001380 Log.endSession();
Tyler Gunndee56a82016-03-23 16:06:34 -07001381 }
1382 break;
1383 }
Hall Liub64ac4c2017-02-06 10:49:48 -08001384 case MSG_ON_START_RTT: {
1385 SomeArgs args = (SomeArgs) msg.obj;
1386 try {
1387 Log.continueSession((Session) args.arg3,
1388 SESSION_HANDLER + SESSION_START_RTT);
1389 String callId = (String) args.arg1;
1390 Connection.RttTextStream rttTextStream =
1391 (Connection.RttTextStream) args.arg2;
1392 startRtt(callId, rttTextStream);
1393 } finally {
1394 args.recycle();
1395 Log.endSession();
1396 }
1397 break;
1398 }
1399 case MSG_ON_STOP_RTT: {
1400 SomeArgs args = (SomeArgs) msg.obj;
1401 try {
1402 Log.continueSession((Session) args.arg2,
1403 SESSION_HANDLER + SESSION_STOP_RTT);
1404 String callId = (String) args.arg1;
1405 stopRtt(callId);
1406 } finally {
1407 args.recycle();
1408 Log.endSession();
1409 }
1410 break;
1411 }
1412 case MSG_RTT_UPGRADE_RESPONSE: {
1413 SomeArgs args = (SomeArgs) msg.obj;
1414 try {
1415 Log.continueSession((Session) args.arg3,
1416 SESSION_HANDLER + SESSION_RTT_UPGRADE_RESPONSE);
1417 String callId = (String) args.arg1;
1418 Connection.RttTextStream rttTextStream =
1419 (Connection.RttTextStream) args.arg2;
1420 handleRttUpgradeResponse(callId, rttTextStream);
1421 } finally {
1422 args.recycle();
1423 Log.endSession();
1424 }
1425 break;
1426 }
Pengquan Meng731c1a32017-11-21 18:01:13 -08001427 case MSG_CONNECTION_SERVICE_FOCUS_GAINED:
1428 onConnectionServiceFocusGained();
1429 break;
1430 case MSG_CONNECTION_SERVICE_FOCUS_LOST:
1431 onConnectionServiceFocusLost();
1432 break;
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001433 default:
1434 break;
1435 }
1436 }
1437 };
1438
Santos Cordon823fd3c2014-08-07 18:35:18 -07001439 private final Conference.Listener mConferenceListener = new Conference.Listener() {
1440 @Override
1441 public void onStateChanged(Conference conference, int oldState, int newState) {
1442 String id = mIdByConference.get(conference);
1443 switch (newState) {
Ravi Paluri80aa2142019-12-02 11:57:37 +05301444 case Connection.STATE_RINGING:
1445 mAdapter.setRinging(id);
1446 break;
1447 case Connection.STATE_DIALING:
1448 mAdapter.setDialing(id);
1449 break;
Santos Cordon823fd3c2014-08-07 18:35:18 -07001450 case Connection.STATE_ACTIVE:
1451 mAdapter.setActive(id);
1452 break;
1453 case Connection.STATE_HOLDING:
1454 mAdapter.setOnHold(id);
1455 break;
1456 case Connection.STATE_DISCONNECTED:
1457 // handled by onDisconnected
1458 break;
1459 }
1460 }
1461
1462 @Override
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001463 public void onDisconnected(Conference conference, DisconnectCause disconnectCause) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07001464 String id = mIdByConference.get(conference);
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001465 mAdapter.setDisconnected(id, disconnectCause);
Santos Cordon823fd3c2014-08-07 18:35:18 -07001466 }
1467
1468 @Override
1469 public void onConnectionAdded(Conference conference, Connection connection) {
1470 }
1471
1472 @Override
1473 public void onConnectionRemoved(Conference conference, Connection connection) {
1474 }
1475
1476 @Override
Ihab Awad50e35062014-09-30 09:17:03 -07001477 public void onConferenceableConnectionsChanged(
1478 Conference conference, List<Connection> conferenceableConnections) {
1479 mAdapter.setConferenceableConnections(
1480 mIdByConference.get(conference),
1481 createConnectionIdList(conferenceableConnections));
1482 }
1483
1484 @Override
Santos Cordon823fd3c2014-08-07 18:35:18 -07001485 public void onDestroyed(Conference conference) {
1486 removeConference(conference);
1487 }
1488
1489 @Override
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001490 public void onConnectionCapabilitiesChanged(
1491 Conference conference,
1492 int connectionCapabilities) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07001493 String id = mIdByConference.get(conference);
1494 Log.d(this, "call capabilities: conference: %s",
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001495 Connection.capabilitiesToString(connectionCapabilities));
1496 mAdapter.setConnectionCapabilities(id, connectionCapabilities);
Santos Cordon823fd3c2014-08-07 18:35:18 -07001497 }
Rekha Kumar07366812015-03-24 16:42:31 -07001498
1499 @Override
Tyler Gunn720c6642016-03-22 09:02:47 -07001500 public void onConnectionPropertiesChanged(
1501 Conference conference,
1502 int connectionProperties) {
1503 String id = mIdByConference.get(conference);
1504 Log.d(this, "call capabilities: conference: %s",
1505 Connection.propertiesToString(connectionProperties));
1506 mAdapter.setConnectionProperties(id, connectionProperties);
1507 }
1508
1509 @Override
Rekha Kumar07366812015-03-24 16:42:31 -07001510 public void onVideoStateChanged(Conference c, int videoState) {
1511 String id = mIdByConference.get(c);
1512 Log.d(this, "onVideoStateChanged set video state %d", videoState);
1513 mAdapter.setVideoState(id, videoState);
1514 }
1515
1516 @Override
1517 public void onVideoProviderChanged(Conference c, Connection.VideoProvider videoProvider) {
1518 String id = mIdByConference.get(c);
1519 Log.d(this, "onVideoProviderChanged: Connection: %s, VideoProvider: %s", c,
1520 videoProvider);
1521 mAdapter.setVideoProvider(id, videoProvider);
1522 }
Andrew Lee0f51da32015-04-16 13:11:55 -07001523
1524 @Override
Andrew Leeedc625f2015-04-14 13:38:12 -07001525 public void onStatusHintsChanged(Conference conference, StatusHints statusHints) {
1526 String id = mIdByConference.get(conference);
Tyler Gunndee56a82016-03-23 16:06:34 -07001527 if (id != null) {
1528 mAdapter.setStatusHints(id, statusHints);
1529 }
Andrew Leeedc625f2015-04-14 13:38:12 -07001530 }
Santos Cordon6b7f9552015-05-27 17:21:45 -07001531
1532 @Override
Tyler Gunndee56a82016-03-23 16:06:34 -07001533 public void onExtrasChanged(Conference c, Bundle extras) {
1534 String id = mIdByConference.get(c);
1535 if (id != null) {
1536 mAdapter.putExtras(id, extras);
1537 }
1538 }
1539
1540 @Override
1541 public void onExtrasRemoved(Conference c, List<String> keys) {
1542 String id = mIdByConference.get(c);
1543 if (id != null) {
1544 mAdapter.removeExtras(id, keys);
1545 }
Santos Cordon6b7f9552015-05-27 17:21:45 -07001546 }
Tyler Gunn68a73a42018-10-03 15:38:57 -07001547
1548 @Override
1549 public void onConferenceStateChanged(Conference c, boolean isConference) {
1550 String id = mIdByConference.get(c);
1551 if (id != null) {
1552 mAdapter.setConferenceState(id, isConference);
1553 }
1554 }
1555
1556 @Override
Brad Ebingere0c12f42020-04-08 16:25:12 -07001557 public void onCallDirectionChanged(Conference c, int direction) {
1558 String id = mIdByConference.get(c);
1559 if (id != null) {
1560 mAdapter.setCallDirection(id, direction);
1561 }
1562 }
1563
1564 @Override
Tyler Gunn68a73a42018-10-03 15:38:57 -07001565 public void onAddressChanged(Conference c, Uri newAddress, int presentation) {
1566 String id = mIdByConference.get(c);
1567 if (id != null) {
1568 mAdapter.setAddress(id, newAddress, presentation);
1569 }
1570 }
1571
1572 @Override
1573 public void onCallerDisplayNameChanged(Conference c, String callerDisplayName,
1574 int presentation) {
1575 String id = mIdByConference.get(c);
1576 if (id != null) {
1577 mAdapter.setCallerDisplayName(id, callerDisplayName, presentation);
1578 }
1579 }
Hall Liuc9bc1c62019-04-16 14:00:55 -07001580
1581 @Override
1582 public void onConnectionEvent(Conference c, String event, Bundle extras) {
1583 String id = mIdByConference.get(c);
1584 if (id != null) {
1585 mAdapter.onConnectionEvent(id, event, extras);
1586 }
1587 }
Ravi Paluri80aa2142019-12-02 11:57:37 +05301588
1589 @Override
1590 public void onRingbackRequested(Conference c, boolean ringback) {
1591 String id = mIdByConference.get(c);
1592 Log.d(this, "Adapter conference onRingback %b", ringback);
1593 mAdapter.setRingbackRequested(id, ringback);
1594 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07001595 };
1596
Ihab Awad542e0ea2014-05-16 10:22:16 -07001597 private final Connection.Listener mConnectionListener = new Connection.Listener() {
1598 @Override
1599 public void onStateChanged(Connection c, int state) {
1600 String id = mIdByConnection.get(c);
Ihab Awad42b30e12014-05-22 09:49:34 -07001601 Log.d(this, "Adapter set state %s %s", id, Connection.stateToString(state));
Ihab Awad542e0ea2014-05-16 10:22:16 -07001602 switch (state) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001603 case Connection.STATE_ACTIVE:
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001604 mAdapter.setActive(id);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001605 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001606 case Connection.STATE_DIALING:
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001607 mAdapter.setDialing(id);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001608 break;
Tyler Gunnc96b5e02016-07-07 22:53:57 -07001609 case Connection.STATE_PULLING_CALL:
1610 mAdapter.setPulling(id);
1611 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001612 case Connection.STATE_DISCONNECTED:
Ihab Awad542e0ea2014-05-16 10:22:16 -07001613 // Handled in onDisconnected()
1614 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001615 case Connection.STATE_HOLDING:
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001616 mAdapter.setOnHold(id);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001617 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001618 case Connection.STATE_NEW:
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001619 // Nothing to tell Telecom
Ihab Awad542e0ea2014-05-16 10:22:16 -07001620 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001621 case Connection.STATE_RINGING:
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001622 mAdapter.setRinging(id);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001623 break;
1624 }
1625 }
1626
1627 @Override
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001628 public void onDisconnected(Connection c, DisconnectCause disconnectCause) {
Ihab Awad542e0ea2014-05-16 10:22:16 -07001629 String id = mIdByConnection.get(c);
Andrew Lee26786392014-09-16 18:14:59 -07001630 Log.d(this, "Adapter set disconnected %s", disconnectCause);
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001631 mAdapter.setDisconnected(id, disconnectCause);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001632 }
1633
1634 @Override
Tyler Gunnaa07df82014-07-17 07:50:22 -07001635 public void onVideoStateChanged(Connection c, int videoState) {
1636 String id = mIdByConnection.get(c);
1637 Log.d(this, "Adapter set video state %d", videoState);
1638 mAdapter.setVideoState(id, videoState);
1639 }
1640
1641 @Override
Andrew Lee100e2932014-09-08 15:34:24 -07001642 public void onAddressChanged(Connection c, Uri address, int presentation) {
Sailesh Nepal61203862014-07-11 14:50:13 -07001643 String id = mIdByConnection.get(c);
Andrew Lee100e2932014-09-08 15:34:24 -07001644 mAdapter.setAddress(id, address, presentation);
Sailesh Nepal61203862014-07-11 14:50:13 -07001645 }
1646
1647 @Override
1648 public void onCallerDisplayNameChanged(
1649 Connection c, String callerDisplayName, int presentation) {
1650 String id = mIdByConnection.get(c);
1651 mAdapter.setCallerDisplayName(id, callerDisplayName, presentation);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001652 }
1653
1654 @Override
Ihab Awad542e0ea2014-05-16 10:22:16 -07001655 public void onDestroyed(Connection c) {
1656 removeConnection(c);
1657 }
Ihab Awadf8358972014-05-28 16:46:42 -07001658
1659 @Override
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001660 public void onPostDialWait(Connection c, String remaining) {
Sailesh Nepal091768c2014-06-30 15:15:23 -07001661 String id = mIdByConnection.get(c);
1662 Log.d(this, "Adapter onPostDialWait %s, %s", c, remaining);
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001663 mAdapter.onPostDialWait(id, remaining);
Sailesh Nepal091768c2014-06-30 15:15:23 -07001664 }
1665
1666 @Override
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001667 public void onPostDialChar(Connection c, char nextChar) {
1668 String id = mIdByConnection.get(c);
1669 Log.d(this, "Adapter onPostDialChar %s, %s", c, nextChar);
1670 mAdapter.onPostDialChar(id, nextChar);
1671 }
1672
1673 @Override
Andrew Lee100e2932014-09-08 15:34:24 -07001674 public void onRingbackRequested(Connection c, boolean ringback) {
Ihab Awadf8358972014-05-28 16:46:42 -07001675 String id = mIdByConnection.get(c);
1676 Log.d(this, "Adapter onRingback %b", ringback);
Andrew Lee100e2932014-09-08 15:34:24 -07001677 mAdapter.setRingbackRequested(id, ringback);
Ihab Awadf8358972014-05-28 16:46:42 -07001678 }
Santos Cordonb6939982014-06-04 20:20:58 -07001679
1680 @Override
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001681 public void onConnectionCapabilitiesChanged(Connection c, int capabilities) {
Santos Cordonb6939982014-06-04 20:20:58 -07001682 String id = mIdByConnection.get(c);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001683 Log.d(this, "capabilities: parcelableconnection: %s",
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001684 Connection.capabilitiesToString(capabilities));
1685 mAdapter.setConnectionCapabilities(id, capabilities);
Santos Cordonb6939982014-06-04 20:20:58 -07001686 }
1687
Santos Cordonb6939982014-06-04 20:20:58 -07001688 @Override
Tyler Gunn720c6642016-03-22 09:02:47 -07001689 public void onConnectionPropertiesChanged(Connection c, int properties) {
1690 String id = mIdByConnection.get(c);
1691 Log.d(this, "properties: parcelableconnection: %s",
1692 Connection.propertiesToString(properties));
1693 mAdapter.setConnectionProperties(id, properties);
1694 }
1695
1696 @Override
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001697 public void onVideoProviderChanged(Connection c, Connection.VideoProvider videoProvider) {
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07001698 String id = mIdByConnection.get(c);
Rekha Kumar07366812015-03-24 16:42:31 -07001699 Log.d(this, "onVideoProviderChanged: Connection: %s, VideoProvider: %s", c,
1700 videoProvider);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001701 mAdapter.setVideoProvider(id, videoProvider);
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07001702 }
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001703
1704 @Override
Sailesh Nepal001bbbb2014-07-15 14:40:39 -07001705 public void onAudioModeIsVoipChanged(Connection c, boolean isVoip) {
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001706 String id = mIdByConnection.get(c);
Andrew Lee100e2932014-09-08 15:34:24 -07001707 mAdapter.setIsVoipAudioMode(id, isVoip);
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001708 }
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001709
1710 @Override
Sailesh Nepal001bbbb2014-07-15 14:40:39 -07001711 public void onStatusHintsChanged(Connection c, StatusHints statusHints) {
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001712 String id = mIdByConnection.get(c);
1713 mAdapter.setStatusHints(id, statusHints);
1714 }
Sailesh Nepal2ab88cc2014-07-18 14:49:18 -07001715
1716 @Override
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001717 public void onConferenceablesChanged(
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001718 Connection connection, List<Conferenceable> conferenceables) {
Ihab Awadb8e85c72014-08-23 20:34:57 -07001719 mAdapter.setConferenceableConnections(
1720 mIdByConnection.get(connection),
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001721 createIdList(conferenceables));
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001722 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07001723
1724 @Override
1725 public void onConferenceChanged(Connection connection, Conference conference) {
1726 String id = mIdByConnection.get(connection);
1727 if (id != null) {
1728 String conferenceId = null;
1729 if (conference != null) {
1730 conferenceId = mIdByConference.get(conference);
1731 }
1732 mAdapter.setIsConferenced(id, conferenceId);
1733 }
1734 }
Anthony Lee17455a32015-04-24 15:25:29 -07001735
1736 @Override
1737 public void onConferenceMergeFailed(Connection connection) {
1738 String id = mIdByConnection.get(connection);
1739 if (id != null) {
1740 mAdapter.onConferenceMergeFailed(id);
1741 }
1742 }
Santos Cordon6b7f9552015-05-27 17:21:45 -07001743
1744 @Override
Tyler Gunndee56a82016-03-23 16:06:34 -07001745 public void onExtrasChanged(Connection c, Bundle extras) {
1746 String id = mIdByConnection.get(c);
Santos Cordon6b7f9552015-05-27 17:21:45 -07001747 if (id != null) {
Tyler Gunndee56a82016-03-23 16:06:34 -07001748 mAdapter.putExtras(id, extras);
Santos Cordon6b7f9552015-05-27 17:21:45 -07001749 }
1750 }
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001751
Tyler Gunnf5035432017-01-09 09:43:12 -08001752 @Override
Tyler Gunndee56a82016-03-23 16:06:34 -07001753 public void onExtrasRemoved(Connection c, List<String> keys) {
1754 String id = mIdByConnection.get(c);
1755 if (id != null) {
1756 mAdapter.removeExtras(id, keys);
1757 }
1758 }
1759
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08001760 @Override
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001761 public void onConnectionEvent(Connection connection, String event, Bundle extras) {
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08001762 String id = mIdByConnection.get(connection);
1763 if (id != null) {
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001764 mAdapter.onConnectionEvent(id, event, extras);
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08001765 }
1766 }
Tyler Gunnf5035432017-01-09 09:43:12 -08001767
1768 @Override
Hall Liua98f58b52017-11-07 17:59:28 -08001769 public void onAudioRouteChanged(Connection c, int audioRoute, String bluetoothAddress) {
Tyler Gunnf5035432017-01-09 09:43:12 -08001770 String id = mIdByConnection.get(c);
1771 if (id != null) {
Hall Liua98f58b52017-11-07 17:59:28 -08001772 mAdapter.setAudioRoute(id, audioRoute, bluetoothAddress);
Tyler Gunnf5035432017-01-09 09:43:12 -08001773 }
1774 }
Hall Liub64ac4c2017-02-06 10:49:48 -08001775
1776 @Override
1777 public void onRttInitiationSuccess(Connection c) {
1778 String id = mIdByConnection.get(c);
1779 if (id != null) {
1780 mAdapter.onRttInitiationSuccess(id);
1781 }
1782 }
1783
1784 @Override
1785 public void onRttInitiationFailure(Connection c, int reason) {
1786 String id = mIdByConnection.get(c);
1787 if (id != null) {
1788 mAdapter.onRttInitiationFailure(id, reason);
1789 }
1790 }
1791
1792 @Override
1793 public void onRttSessionRemotelyTerminated(Connection c) {
1794 String id = mIdByConnection.get(c);
1795 if (id != null) {
1796 mAdapter.onRttSessionRemotelyTerminated(id);
1797 }
1798 }
1799
1800 @Override
1801 public void onRemoteRttRequest(Connection c) {
1802 String id = mIdByConnection.get(c);
1803 if (id != null) {
1804 mAdapter.onRemoteRttRequest(id);
1805 }
1806 }
Srikanth Chintalafcb15012017-05-04 20:58:34 +05301807
1808 @Override
1809 public void onPhoneAccountChanged(Connection c, PhoneAccountHandle pHandle) {
1810 String id = mIdByConnection.get(c);
1811 if (id != null) {
1812 mAdapter.onPhoneAccountChanged(id, pHandle);
1813 }
1814 }
Mengjun Leng25707742017-07-04 11:10:37 +08001815
1816 public void onConnectionTimeReset(Connection c) {
1817 String id = mIdByConnection.get(c);
1818 if (id != null) {
1819 mAdapter.resetConnectionTime(id);
1820 }
1821 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001822 };
1823
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001824 /** {@inheritDoc} */
Ihab Awad542e0ea2014-05-16 10:22:16 -07001825 @Override
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001826 public final IBinder onBind(Intent intent) {
1827 return mBinder;
1828 }
1829
Santos Cordon29f2f2e2014-09-11 19:50:24 -07001830 /** {@inheritDoc} */
1831 @Override
1832 public boolean onUnbind(Intent intent) {
1833 endAllConnections();
1834 return super.onUnbind(intent);
1835 }
1836
Ravi Paluri80aa2142019-12-02 11:57:37 +05301837
1838 /**
1839 * This can be used by telecom to either create a new outgoing conference call or attach
1840 * to an existing incoming conference call. In either case, telecom will cycle through a
1841 * set of services and call createConference until a connection service cancels the process
1842 * or completes it successfully.
1843 */
1844 private void createConference(
1845 final PhoneAccountHandle callManagerAccount,
1846 final String callId,
1847 final ConnectionRequest request,
1848 boolean isIncoming,
1849 boolean isUnknown) {
1850
1851 Conference conference = null;
1852 conference = isIncoming ? onCreateIncomingConference(callManagerAccount, request)
1853 : onCreateOutgoingConference(callManagerAccount, request);
1854
1855 Log.d(this, "createConference, conference: %s", conference);
1856 if (conference == null) {
1857 Log.i(this, "createConference, implementation returned null conference.");
1858 conference = Conference.createFailedConference(
1859 new DisconnectCause(DisconnectCause.ERROR, "IMPL_RETURNED_NULL_CONFERENCE"),
1860 request.getAccountHandle());
1861 }
Tyler Gunnc59fd0c2020-04-17 14:03:35 -07001862
1863 Bundle extras = request.getExtras();
1864 Bundle newExtras = new Bundle();
1865 newExtras.putString(Connection.EXTRA_ORIGINAL_CONNECTION_ID, callId);
1866 if (extras != null) {
1867 // If the request originated from a remote connection service, we will add some
1868 // tracking information that Telecom can use to keep informed of which package
1869 // made the remote request, and which remote connection service was used.
1870 if (extras.containsKey(Connection.EXTRA_REMOTE_CONNECTION_ORIGINATING_PACKAGE_NAME)) {
1871 newExtras.putString(
1872 Connection.EXTRA_REMOTE_CONNECTION_ORIGINATING_PACKAGE_NAME,
1873 extras.getString(
1874 Connection.EXTRA_REMOTE_CONNECTION_ORIGINATING_PACKAGE_NAME));
1875 newExtras.putParcelable(Connection.EXTRA_REMOTE_PHONE_ACCOUNT_HANDLE,
1876 request.getAccountHandle());
1877 }
Ravi Paluri80aa2142019-12-02 11:57:37 +05301878 }
Tyler Gunnc59fd0c2020-04-17 14:03:35 -07001879 conference.putExtras(newExtras);
1880
Ravi Paluri80aa2142019-12-02 11:57:37 +05301881 mConferenceById.put(callId, conference);
1882 mIdByConference.put(conference, callId);
Tyler Gunn460360d2020-07-29 10:21:45 -07001883
Ravi Paluri80aa2142019-12-02 11:57:37 +05301884 conference.addListener(mConferenceListener);
Brad Ebinger0ae44ed2020-04-09 15:30:57 -07001885 ParcelableConference parcelableConference = new ParcelableConference.Builder(
1886 request.getAccountHandle(), conference.getState())
1887 .setConnectionCapabilities(conference.getConnectionCapabilities())
1888 .setConnectionProperties(conference.getConnectionProperties())
1889 .setVideoAttributes(conference.getVideoProvider() == null
1890 ? null : conference.getVideoProvider().getInterface(),
1891 conference.getVideoState())
1892 .setConnectTimeMillis(conference.getConnectTimeMillis(),
1893 conference.getConnectionStartElapsedRealtimeMillis())
1894 .setStatusHints(conference.getStatusHints())
1895 .setExtras(conference.getExtras())
1896 .setAddress(conference.getAddress(), conference.getAddressPresentation())
1897 .setCallerDisplayName(conference.getCallerDisplayName(),
1898 conference.getCallerDisplayNamePresentation())
1899 .setDisconnectCause(conference.getDisconnectCause())
1900 .setRingbackRequested(conference.isRingbackRequested())
1901 .build();
Ravi Paluri80aa2142019-12-02 11:57:37 +05301902 if (conference.getState() != Connection.STATE_DISCONNECTED) {
1903 conference.setTelecomCallId(callId);
1904 mAdapter.setVideoProvider(callId, conference.getVideoProvider());
1905 mAdapter.setVideoState(callId, conference.getVideoState());
1906 onConferenceAdded(conference);
1907 }
1908
1909 Log.d(this, "createConference, calling handleCreateConferenceSuccessful %s", callId);
1910 mAdapter.handleCreateConferenceComplete(
1911 callId,
1912 request,
1913 parcelableConference);
1914 }
1915
Sailesh Nepalc5b01572014-07-14 16:29:44 -07001916 /**
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001917 * This can be used by telecom to either create a new outgoing call or attach to an existing
1918 * incoming call. In either case, telecom will cycle through a set of services and call
Sailesh Nepalc5b01572014-07-14 16:29:44 -07001919 * createConnection util a connection service cancels the process or completes it successfully.
1920 */
Ihab Awadf8b69882014-07-25 15:14:01 -07001921 private void createConnection(
1922 final PhoneAccountHandle callManagerAccount,
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001923 final String callId,
Ihab Awadf8b69882014-07-25 15:14:01 -07001924 final ConnectionRequest request,
Yorke Leec3cf9822014-10-02 09:38:39 -07001925 boolean isIncoming,
1926 boolean isUnknown) {
Tyler Gunn79bc1ec2018-01-22 15:17:54 -08001927 boolean isLegacyHandover = request.getExtras() != null &&
1928 request.getExtras().getBoolean(TelecomManager.EXTRA_IS_HANDOVER, false);
1929 boolean isHandover = request.getExtras() != null && request.getExtras().getBoolean(
1930 TelecomManager.EXTRA_IS_HANDOVER_CONNECTION, false);
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001931 Log.d(this, "createConnection, callManagerAccount: %s, callId: %s, request: %s, " +
Tyler Gunn79bc1ec2018-01-22 15:17:54 -08001932 "isIncoming: %b, isUnknown: %b, isLegacyHandover: %b, isHandover: %b",
1933 callManagerAccount, callId, request, isIncoming, isUnknown, isLegacyHandover,
1934 isHandover);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001935
Sanket Padawee29a2662017-12-01 13:59:27 -08001936 Connection connection = null;
Tyler Gunn79bc1ec2018-01-22 15:17:54 -08001937 if (isHandover) {
1938 PhoneAccountHandle fromPhoneAccountHandle = request.getExtras() != null
1939 ? (PhoneAccountHandle) request.getExtras().getParcelable(
1940 TelecomManager.EXTRA_HANDOVER_FROM_PHONE_ACCOUNT) : null;
Sanket Padawee29a2662017-12-01 13:59:27 -08001941 if (!isIncoming) {
Tyler Gunn79bc1ec2018-01-22 15:17:54 -08001942 connection = onCreateOutgoingHandoverConnection(fromPhoneAccountHandle, request);
Sanket Padawee29a2662017-12-01 13:59:27 -08001943 } else {
Tyler Gunn79bc1ec2018-01-22 15:17:54 -08001944 connection = onCreateIncomingHandoverConnection(fromPhoneAccountHandle, request);
Sanket Padawee29a2662017-12-01 13:59:27 -08001945 }
1946 } else {
1947 connection = isUnknown ? onCreateUnknownConnection(callManagerAccount, request)
1948 : isIncoming ? onCreateIncomingConnection(callManagerAccount, request)
1949 : onCreateOutgoingConnection(callManagerAccount, request);
1950 }
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001951 Log.d(this, "createConnection, connection: %s", connection);
1952 if (connection == null) {
Tyler Gunnfba1a8e2017-12-19 15:23:59 -08001953 Log.i(this, "createConnection, implementation returned null connection.");
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001954 connection = Connection.createFailedConnection(
Tyler Gunnfba1a8e2017-12-19 15:23:59 -08001955 new DisconnectCause(DisconnectCause.ERROR, "IMPL_RETURNED_NULL_CONNECTION"));
Tyler Gunnc59fd0c2020-04-17 14:03:35 -07001956 } else {
1957 try {
1958 Bundle extras = request.getExtras();
1959 if (extras != null) {
1960 // If the request originated from a remote connection service, we will add some
1961 // tracking information that Telecom can use to keep informed of which package
1962 // made the remote request, and which remote connection service was used.
1963 if (extras.containsKey(
1964 Connection.EXTRA_REMOTE_CONNECTION_ORIGINATING_PACKAGE_NAME)) {
1965 Bundle newExtras = new Bundle();
1966 newExtras.putString(
1967 Connection.EXTRA_REMOTE_CONNECTION_ORIGINATING_PACKAGE_NAME,
1968 extras.getString(
1969 Connection.EXTRA_REMOTE_CONNECTION_ORIGINATING_PACKAGE_NAME
1970 ));
1971 newExtras.putParcelable(Connection.EXTRA_REMOTE_PHONE_ACCOUNT_HANDLE,
1972 request.getAccountHandle());
1973 connection.putExtras(newExtras);
1974 }
1975 }
1976 } catch (UnsupportedOperationException ose) {
1977 // Do nothing; if the ConnectionService reported a failure it will be an instance
1978 // of an immutable Connection which we cannot edit, so we're out of luck.
1979 }
Sailesh Nepalc5b01572014-07-14 16:29:44 -07001980 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001981
Tyler Gunnf2e08b42018-05-24 10:44:44 -07001982 boolean isSelfManaged =
1983 (connection.getConnectionProperties() & Connection.PROPERTY_SELF_MANAGED)
1984 == Connection.PROPERTY_SELF_MANAGED;
1985 // Self-managed Connections should always use voip audio mode; we default here so that the
1986 // local state within the ConnectionService matches the default we assume in Telecom.
1987 if (isSelfManaged) {
1988 connection.setAudioModeIsVoip(true);
1989 }
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001990 connection.setTelecomCallId(callId);
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001991 if (connection.getState() != Connection.STATE_DISCONNECTED) {
Pengquan Meng70c9885332017-10-02 18:09:03 -07001992 addConnection(request.getAccountHandle(), callId, connection);
Ihab Awad6107bab2014-08-18 09:23:25 -07001993 }
1994
Andrew Lee100e2932014-09-08 15:34:24 -07001995 Uri address = connection.getAddress();
1996 String number = address == null ? "null" : address.getSchemeSpecificPart();
Tyler Gunn720c6642016-03-22 09:02:47 -07001997 Log.v(this, "createConnection, number: %s, state: %s, capabilities: %s, properties: %s",
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001998 Connection.toLogSafePhoneNumber(number),
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001999 Connection.stateToString(connection.getState()),
Tyler Gunn720c6642016-03-22 09:02:47 -07002000 Connection.capabilitiesToString(connection.getConnectionCapabilities()),
2001 Connection.propertiesToString(connection.getConnectionProperties()));
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002002
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07002003 Log.d(this, "createConnection, calling handleCreateConnectionSuccessful %s", callId);
Ihab Awad6107bab2014-08-18 09:23:25 -07002004 mAdapter.handleCreateConnectionComplete(
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002005 callId,
Evan Charltonbf11f982014-07-20 22:06:28 -07002006 request,
2007 new ParcelableConnection(
2008 request.getAccountHandle(),
2009 connection.getState(),
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002010 connection.getConnectionCapabilities(),
Tyler Gunn720c6642016-03-22 09:02:47 -07002011 connection.getConnectionProperties(),
Christine Hallstrom2830ce92016-11-30 16:06:42 -08002012 connection.getSupportedAudioRoutes(),
Andrew Lee100e2932014-09-08 15:34:24 -07002013 connection.getAddress(),
2014 connection.getAddressPresentation(),
Evan Charltonbf11f982014-07-20 22:06:28 -07002015 connection.getCallerDisplayName(),
2016 connection.getCallerDisplayNamePresentation(),
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002017 connection.getVideoProvider() == null ?
2018 null : connection.getVideoProvider().getInterface(),
Sailesh Nepal8b9d3ca2014-08-14 17:39:34 -07002019 connection.getVideoState(),
Andrew Lee100e2932014-09-08 15:34:24 -07002020 connection.isRingbackRequested(),
Sailesh Nepal8b9d3ca2014-08-14 17:39:34 -07002021 connection.getAudioModeIsVoip(),
Roshan Piuse927ec02015-07-15 15:47:21 -07002022 connection.getConnectTimeMillis(),
Tyler Gunnc9503d62020-01-27 10:30:51 -08002023 connection.getConnectionStartElapsedRealtimeMillis(),
Ihab Awad6107bab2014-08-18 09:23:25 -07002024 connection.getStatusHints(),
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07002025 connection.getDisconnectCause(),
Santos Cordon6b7f9552015-05-27 17:21:45 -07002026 createIdList(connection.getConferenceables()),
Tyler Gunnd57d76c2019-09-24 14:53:23 -07002027 connection.getExtras(),
2028 connection.getCallerNumberVerificationStatus()));
Tyler Gunnf5035432017-01-09 09:43:12 -08002029
Tyler Gunnf2e08b42018-05-24 10:44:44 -07002030 if (isIncoming && request.shouldShowIncomingCallUi() && isSelfManaged) {
Tyler Gunnf5035432017-01-09 09:43:12 -08002031 // Tell ConnectionService to show its incoming call UX.
2032 connection.onShowIncomingCallUi();
2033 }
Shriram Ganesh6bf35ac2014-12-11 17:53:38 -08002034 if (isUnknown) {
2035 triggerConferenceRecalculate();
2036 }
Evan Charltonbf11f982014-07-20 22:06:28 -07002037 }
2038
Tyler Gunn159f35c2017-03-02 09:28:37 -08002039 private void createConnectionFailed(final PhoneAccountHandle callManagerAccount,
2040 final String callId, final ConnectionRequest request,
2041 boolean isIncoming) {
Tyler Gunn44e01912017-01-31 10:49:05 -08002042
2043 Log.i(this, "createConnectionFailed %s", callId);
2044 if (isIncoming) {
Tyler Gunn159f35c2017-03-02 09:28:37 -08002045 onCreateIncomingConnectionFailed(callManagerAccount, request);
Tyler Gunn44e01912017-01-31 10:49:05 -08002046 } else {
Tyler Gunn159f35c2017-03-02 09:28:37 -08002047 onCreateOutgoingConnectionFailed(callManagerAccount, request);
Tyler Gunn44e01912017-01-31 10:49:05 -08002048 }
2049 }
2050
Ravi Paluri80aa2142019-12-02 11:57:37 +05302051 private void createConferenceFailed(final PhoneAccountHandle callManagerAccount,
2052 final String callId, final ConnectionRequest request,
2053 boolean isIncoming) {
2054
2055 Log.i(this, "createConferenceFailed %s", callId);
2056 if (isIncoming) {
2057 onCreateIncomingConferenceFailed(callManagerAccount, request);
2058 } else {
2059 onCreateOutgoingConferenceFailed(callManagerAccount, request);
2060 }
2061 }
2062
Sanket Padawe4cc8ed52017-12-04 16:22:20 -08002063 private void handoverFailed(final String callId, final ConnectionRequest request,
2064 int reason) {
2065
2066 Log.i(this, "handoverFailed %s", callId);
2067 onHandoverFailed(request, reason);
2068 }
2069
Tyler Gunn041a1fe2017-05-12 10:04:49 -07002070 /**
2071 * Called by Telecom when the creation of a new Connection has completed and it is now added
2072 * to Telecom.
2073 * @param callId The ID of the connection.
2074 */
2075 private void notifyCreateConnectionComplete(final String callId) {
2076 Log.i(this, "notifyCreateConnectionComplete %s", callId);
Tyler Gunn0a88f2e2017-06-16 20:20:34 -07002077 if (callId == null) {
2078 // This could happen if the connection fails quickly and is removed from the
2079 // ConnectionService before Telecom sends the create connection complete callback.
2080 Log.w(this, "notifyCreateConnectionComplete: callId is null.");
2081 return;
2082 }
Tyler Gunn041a1fe2017-05-12 10:04:49 -07002083 onCreateConnectionComplete(findConnectionForAction(callId,
2084 "notifyCreateConnectionComplete"));
2085 }
2086
Ravi Paluri80aa2142019-12-02 11:57:37 +05302087 /**
2088 * Called by Telecom when the creation of a new Conference has completed and it is now added
2089 * to Telecom.
2090 * @param callId The ID of the connection.
2091 */
2092 private void notifyCreateConferenceComplete(final String callId) {
2093 Log.i(this, "notifyCreateConferenceComplete %s", callId);
2094 if (callId == null) {
2095 // This could happen if the conference fails quickly and is removed from the
2096 // ConnectionService before Telecom sends the create conference complete callback.
2097 Log.w(this, "notifyCreateConferenceComplete: callId is null.");
2098 return;
2099 }
2100 onCreateConferenceComplete(findConferenceForAction(callId,
2101 "notifyCreateConferenceComplete"));
2102 }
2103
2104
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002105 private void abort(String callId) {
Tyler Gunnffbcd892020-05-04 15:01:59 -07002106 Log.i(this, "abort %s", callId);
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002107 findConnectionForAction(callId, "abort").onAbort();
Ihab Awad542e0ea2014-05-16 10:22:16 -07002108 }
2109
Tyler Gunnbe74de02014-08-29 14:51:48 -07002110 private void answerVideo(String callId, int videoState) {
Tyler Gunnffbcd892020-05-04 15:01:59 -07002111 Log.i(this, "answerVideo %s", callId);
Ravi Paluri80aa2142019-12-02 11:57:37 +05302112 if (mConnectionById.containsKey(callId)) {
2113 findConnectionForAction(callId, "answer").onAnswer(videoState);
2114 } else {
2115 findConferenceForAction(callId, "answer").onAnswer(videoState);
2116 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002117 }
2118
Tyler Gunnbe74de02014-08-29 14:51:48 -07002119 private void answer(String callId) {
Tyler Gunnffbcd892020-05-04 15:01:59 -07002120 Log.i(this, "answer %s", callId);
Ravi Paluri80aa2142019-12-02 11:57:37 +05302121 if (mConnectionById.containsKey(callId)) {
2122 findConnectionForAction(callId, "answer").onAnswer();
2123 } else {
2124 findConferenceForAction(callId, "answer").onAnswer();
2125 }
Tyler Gunnbe74de02014-08-29 14:51:48 -07002126 }
2127
Pooja Jaind34698d2017-12-28 14:15:31 +05302128 private void deflect(String callId, Uri address) {
Tyler Gunnffbcd892020-05-04 15:01:59 -07002129 Log.i(this, "deflect %s", callId);
Pooja Jaind34698d2017-12-28 14:15:31 +05302130 findConnectionForAction(callId, "deflect").onDeflect(address);
2131 }
2132
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002133 private void reject(String callId) {
Tyler Gunnffbcd892020-05-04 15:01:59 -07002134 Log.i(this, "reject %s", callId);
Ravi Paluri80aa2142019-12-02 11:57:37 +05302135 if (mConnectionById.containsKey(callId)) {
2136 findConnectionForAction(callId, "reject").onReject();
2137 } else {
2138 findConferenceForAction(callId, "reject").onReject();
2139 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002140 }
2141
Bryce Lee81901682015-08-28 16:38:02 -07002142 private void reject(String callId, String rejectWithMessage) {
Tyler Gunnffbcd892020-05-04 15:01:59 -07002143 Log.i(this, "reject %s with message", callId);
Bryce Lee81901682015-08-28 16:38:02 -07002144 findConnectionForAction(callId, "reject").onReject(rejectWithMessage);
2145 }
2146
Tyler Gunnfacfdee2020-01-23 13:10:37 -08002147 private void reject(String callId, @android.telecom.Call.RejectReason int rejectReason) {
Tyler Gunnffbcd892020-05-04 15:01:59 -07002148 Log.i(this, "reject %s with reason %d", callId, rejectReason);
Tyler Gunnfacfdee2020-01-23 13:10:37 -08002149 findConnectionForAction(callId, "reject").onReject(rejectReason);
2150 }
2151
Ravi Palurif4b38e72020-02-05 12:35:41 +05302152 private void transfer(String callId, Uri number, boolean isConfirmationRequired) {
Tyler Gunnffbcd892020-05-04 15:01:59 -07002153 Log.i(this, "transfer %s", callId);
Ravi Palurif4b38e72020-02-05 12:35:41 +05302154 findConnectionForAction(callId, "transfer").onTransfer(number, isConfirmationRequired);
2155 }
2156
2157 private void consultativeTransfer(String callId, String otherCallId) {
Tyler Gunnffbcd892020-05-04 15:01:59 -07002158 Log.i(this, "consultativeTransfer %s", callId);
Ravi Palurif4b38e72020-02-05 12:35:41 +05302159 Connection connection1 = findConnectionForAction(callId, "consultativeTransfer");
2160 Connection connection2 = findConnectionForAction(otherCallId, " consultativeTransfer");
2161 connection1.onTransfer(connection2);
2162 }
2163
Bryce Leecac50772015-11-17 15:13:29 -08002164 private void silence(String callId) {
Tyler Gunnffbcd892020-05-04 15:01:59 -07002165 Log.i(this, "silence %s", callId);
Bryce Leecac50772015-11-17 15:13:29 -08002166 findConnectionForAction(callId, "silence").onSilence();
2167 }
2168
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002169 private void disconnect(String callId) {
Tyler Gunnffbcd892020-05-04 15:01:59 -07002170 Log.i(this, "disconnect %s", callId);
Santos Cordon0159ac02014-08-21 14:28:11 -07002171 if (mConnectionById.containsKey(callId)) {
2172 findConnectionForAction(callId, "disconnect").onDisconnect();
2173 } else {
2174 findConferenceForAction(callId, "disconnect").onDisconnect();
2175 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002176 }
2177
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002178 private void hold(String callId) {
Tyler Gunnffbcd892020-05-04 15:01:59 -07002179 Log.i(this, "hold %s", callId);
Santos Cordon0159ac02014-08-21 14:28:11 -07002180 if (mConnectionById.containsKey(callId)) {
2181 findConnectionForAction(callId, "hold").onHold();
2182 } else {
2183 findConferenceForAction(callId, "hold").onHold();
2184 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002185 }
2186
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002187 private void unhold(String callId) {
Tyler Gunnffbcd892020-05-04 15:01:59 -07002188 Log.i(this, "unhold %s", callId);
Santos Cordon0159ac02014-08-21 14:28:11 -07002189 if (mConnectionById.containsKey(callId)) {
2190 findConnectionForAction(callId, "unhold").onUnhold();
2191 } else {
2192 findConferenceForAction(callId, "unhold").onUnhold();
2193 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002194 }
2195
Yorke Lee4af59352015-05-13 14:14:54 -07002196 private void onCallAudioStateChanged(String callId, CallAudioState callAudioState) {
Tyler Gunnffbcd892020-05-04 15:01:59 -07002197 Log.i(this, "onAudioStateChanged %s %s", callId, callAudioState);
Yorke Leea0d3ca92014-09-15 19:18:13 -07002198 if (mConnectionById.containsKey(callId)) {
Yorke Lee4af59352015-05-13 14:14:54 -07002199 findConnectionForAction(callId, "onCallAudioStateChanged").setCallAudioState(
2200 callAudioState);
Yorke Leea0d3ca92014-09-15 19:18:13 -07002201 } else {
Yorke Lee4af59352015-05-13 14:14:54 -07002202 findConferenceForAction(callId, "onCallAudioStateChanged").setCallAudioState(
2203 callAudioState);
Yorke Leea0d3ca92014-09-15 19:18:13 -07002204 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002205 }
2206
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002207 private void playDtmfTone(String callId, char digit) {
Tyler Gunnffbcd892020-05-04 15:01:59 -07002208 Log.i(this, "playDtmfTone %s %c", callId, digit);
Yorke Leea0d3ca92014-09-15 19:18:13 -07002209 if (mConnectionById.containsKey(callId)) {
2210 findConnectionForAction(callId, "playDtmfTone").onPlayDtmfTone(digit);
2211 } else {
2212 findConferenceForAction(callId, "playDtmfTone").onPlayDtmfTone(digit);
2213 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002214 }
2215
2216 private void stopDtmfTone(String callId) {
Tyler Gunnffbcd892020-05-04 15:01:59 -07002217 Log.i(this, "stopDtmfTone %s", callId);
Yorke Leea0d3ca92014-09-15 19:18:13 -07002218 if (mConnectionById.containsKey(callId)) {
2219 findConnectionForAction(callId, "stopDtmfTone").onStopDtmfTone();
2220 } else {
2221 findConferenceForAction(callId, "stopDtmfTone").onStopDtmfTone();
2222 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002223 }
2224
Santos Cordon823fd3c2014-08-07 18:35:18 -07002225 private void conference(String callId1, String callId2) {
Tyler Gunnffbcd892020-05-04 15:01:59 -07002226 Log.i(this, "conference %s, %s", callId1, callId2);
Santos Cordon980acb92014-05-31 10:31:19 -07002227
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002228 // Attempt to get second connection or conference.
Santos Cordon823fd3c2014-08-07 18:35:18 -07002229 Connection connection2 = findConnectionForAction(callId2, "conference");
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002230 Conference conference2 = getNullConference();
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07002231 if (connection2 == getNullConnection()) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002232 conference2 = findConferenceForAction(callId2, "conference");
2233 if (conference2 == getNullConference()) {
2234 Log.w(this, "Connection2 or Conference2 missing in conference request %s.",
2235 callId2);
2236 return;
2237 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07002238 }
Santos Cordonb6939982014-06-04 20:20:58 -07002239
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002240 // Attempt to get first connection or conference and perform merge.
Ihab Awad50e35062014-09-30 09:17:03 -07002241 Connection connection1 = findConnectionForAction(callId1, "conference");
2242 if (connection1 == getNullConnection()) {
2243 Conference conference1 = findConferenceForAction(callId1, "addConnection");
2244 if (conference1 == getNullConference()) {
2245 Log.w(this,
2246 "Connection1 or Conference1 missing in conference request %s.",
2247 callId1);
2248 } else {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002249 // Call 1 is a conference.
2250 if (connection2 != getNullConnection()) {
2251 // Call 2 is a connection so merge via call 1 (conference).
2252 conference1.onMerge(connection2);
2253 } else {
2254 // Call 2 is ALSO a conference; this should never happen.
2255 Log.wtf(this, "There can only be one conference and an attempt was made to " +
2256 "merge two conferences.");
2257 return;
2258 }
Ihab Awad50e35062014-09-30 09:17:03 -07002259 }
2260 } else {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002261 // Call 1 is a connection.
2262 if (conference2 != getNullConference()) {
2263 // Call 2 is a conference, so merge via call 2.
2264 conference2.onMerge(connection1);
2265 } else {
2266 // Call 2 is a connection, so merge together.
2267 onConference(connection1, connection2);
2268 }
Ihab Awad50e35062014-09-30 09:17:03 -07002269 }
Santos Cordon980acb92014-05-31 10:31:19 -07002270 }
2271
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002272 private void splitFromConference(String callId) {
Tyler Gunnffbcd892020-05-04 15:01:59 -07002273 Log.i(this, "splitFromConference(%s)", callId);
Santos Cordon980acb92014-05-31 10:31:19 -07002274
2275 Connection connection = findConnectionForAction(callId, "splitFromConference");
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07002276 if (connection == getNullConnection()) {
Santos Cordon980acb92014-05-31 10:31:19 -07002277 Log.w(this, "Connection missing in conference request %s.", callId);
2278 return;
2279 }
2280
Santos Cordon0159ac02014-08-21 14:28:11 -07002281 Conference conference = connection.getConference();
2282 if (conference != null) {
2283 conference.onSeparate(connection);
2284 }
Santos Cordon980acb92014-05-31 10:31:19 -07002285 }
2286
Santos Cordona4868042014-09-04 17:39:22 -07002287 private void mergeConference(String callId) {
Tyler Gunnffbcd892020-05-04 15:01:59 -07002288 Log.i(this, "mergeConference(%s)", callId);
Santos Cordona4868042014-09-04 17:39:22 -07002289 Conference conference = findConferenceForAction(callId, "mergeConference");
2290 if (conference != null) {
2291 conference.onMerge();
2292 }
2293 }
2294
2295 private void swapConference(String callId) {
Tyler Gunnffbcd892020-05-04 15:01:59 -07002296 Log.i(this, "swapConference(%s)", callId);
Santos Cordona4868042014-09-04 17:39:22 -07002297 Conference conference = findConferenceForAction(callId, "swapConference");
2298 if (conference != null) {
2299 conference.onSwap();
2300 }
2301 }
2302
Ravi Paluri404babb2020-01-23 19:02:44 +05302303 private void addConferenceParticipants(String callId, List<Uri> participants) {
Tyler Gunnffbcd892020-05-04 15:01:59 -07002304 Log.i(this, "addConferenceParticipants(%s)", callId);
Ravi Paluri404babb2020-01-23 19:02:44 +05302305 if (mConnectionById.containsKey(callId)) {
2306 findConnectionForAction(callId, "addConferenceParticipants")
2307 .onAddConferenceParticipants(participants);
2308 } else {
2309 findConferenceForAction(callId, "addConferenceParticipants")
2310 .onAddConferenceParticipants(participants);
2311 }
2312 }
2313
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002314 /**
2315 * Notifies a {@link Connection} of a request to pull an external call.
2316 *
2317 * See {@link Call#pullExternalCall()}.
2318 *
2319 * @param callId The ID of the call to pull.
2320 */
2321 private void pullExternalCall(String callId) {
Tyler Gunnffbcd892020-05-04 15:01:59 -07002322 Log.i(this, "pullExternalCall(%s)", callId);
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002323 Connection connection = findConnectionForAction(callId, "pullExternalCall");
2324 if (connection != null) {
2325 connection.onPullExternalCall();
2326 }
2327 }
2328
2329 /**
2330 * Notifies a {@link Connection} of a call event.
2331 *
2332 * See {@link Call#sendCallEvent(String, Bundle)}.
2333 *
2334 * @param callId The ID of the call receiving the event.
2335 * @param event The event.
2336 * @param extras Extras associated with the event.
2337 */
2338 private void sendCallEvent(String callId, String event, Bundle extras) {
Tyler Gunnffbcd892020-05-04 15:01:59 -07002339 Log.i(this, "sendCallEvent(%s, %s)", callId, event);
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002340 Connection connection = findConnectionForAction(callId, "sendCallEvent");
2341 if (connection != null) {
2342 connection.onCallEvent(event, extras);
2343 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002344 }
2345
Tyler Gunndee56a82016-03-23 16:06:34 -07002346 /**
Tyler Gunn79bc1ec2018-01-22 15:17:54 -08002347 * Notifies a {@link Connection} that a handover has completed.
2348 *
2349 * @param callId The ID of the call which completed handover.
2350 */
2351 private void notifyHandoverComplete(String callId) {
Tyler Gunnffbcd892020-05-04 15:01:59 -07002352 Log.i(this, "notifyHandoverComplete(%s)", callId);
Tyler Gunn79bc1ec2018-01-22 15:17:54 -08002353 Connection connection = findConnectionForAction(callId, "notifyHandoverComplete");
2354 if (connection != null) {
2355 connection.onHandoverComplete();
2356 }
2357 }
2358
2359 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07002360 * Notifies a {@link Connection} or {@link Conference} of a change to the extras from Telecom.
2361 * <p>
2362 * These extra changes can originate from Telecom itself, or from an {@link InCallService} via
2363 * the {@link android.telecom.Call#putExtra(String, boolean)},
2364 * {@link android.telecom.Call#putExtra(String, int)},
2365 * {@link android.telecom.Call#putExtra(String, String)},
2366 * {@link Call#removeExtras(List)}.
2367 *
2368 * @param callId The ID of the call receiving the event.
2369 * @param extras The new extras bundle.
2370 */
2371 private void handleExtrasChanged(String callId, Bundle extras) {
Tyler Gunnffbcd892020-05-04 15:01:59 -07002372 Log.i(this, "handleExtrasChanged(%s, %s)", callId, extras);
Tyler Gunndee56a82016-03-23 16:06:34 -07002373 if (mConnectionById.containsKey(callId)) {
2374 findConnectionForAction(callId, "handleExtrasChanged").handleExtrasChanged(extras);
2375 } else if (mConferenceById.containsKey(callId)) {
2376 findConferenceForAction(callId, "handleExtrasChanged").handleExtrasChanged(extras);
2377 }
2378 }
2379
Hall Liub64ac4c2017-02-06 10:49:48 -08002380 private void startRtt(String callId, Connection.RttTextStream rttTextStream) {
Tyler Gunnffbcd892020-05-04 15:01:59 -07002381 Log.i(this, "startRtt(%s)", callId);
Hall Liub64ac4c2017-02-06 10:49:48 -08002382 if (mConnectionById.containsKey(callId)) {
2383 findConnectionForAction(callId, "startRtt").onStartRtt(rttTextStream);
2384 } else if (mConferenceById.containsKey(callId)) {
2385 Log.w(this, "startRtt called on a conference.");
2386 }
2387 }
2388
2389 private void stopRtt(String callId) {
Tyler Gunnffbcd892020-05-04 15:01:59 -07002390 Log.i(this, "stopRtt(%s)", callId);
Hall Liub64ac4c2017-02-06 10:49:48 -08002391 if (mConnectionById.containsKey(callId)) {
2392 findConnectionForAction(callId, "stopRtt").onStopRtt();
2393 } else if (mConferenceById.containsKey(callId)) {
2394 Log.w(this, "stopRtt called on a conference.");
2395 }
2396 }
2397
2398 private void handleRttUpgradeResponse(String callId, Connection.RttTextStream rttTextStream) {
Tyler Gunnffbcd892020-05-04 15:01:59 -07002399 Log.i(this, "handleRttUpgradeResponse(%s, %s)", callId, rttTextStream == null);
Hall Liub64ac4c2017-02-06 10:49:48 -08002400 if (mConnectionById.containsKey(callId)) {
2401 findConnectionForAction(callId, "handleRttUpgradeResponse")
2402 .handleRttUpgradeResponse(rttTextStream);
2403 } else if (mConferenceById.containsKey(callId)) {
2404 Log.w(this, "handleRttUpgradeResponse called on a conference.");
2405 }
2406 }
2407
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002408 private void onPostDialContinue(String callId, boolean proceed) {
Tyler Gunnffbcd892020-05-04 15:01:59 -07002409 Log.i(this, "onPostDialContinue(%s)", callId);
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002410 findConnectionForAction(callId, "stopDtmfTone").onPostDialContinue(proceed);
Evan Charlton6dea4ac2014-06-03 14:07:13 -07002411 }
2412
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002413 private void onAdapterAttached() {
Ihab Awad9c3f1882014-06-30 21:17:13 -07002414 if (mAreAccountsInitialized) {
Santos Cordon52d8a152014-06-17 19:08:45 -07002415 // No need to query again if we already did it.
2416 return;
2417 }
2418
Tyler Gunn4c69fb32019-05-17 10:49:16 -07002419 String callingPackage = getOpPackageName();
2420
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002421 mAdapter.queryRemoteConnectionServices(new RemoteServiceCallback.Stub() {
Santos Cordon52d8a152014-06-17 19:08:45 -07002422 @Override
2423 public void onResult(
2424 final List<ComponentName> componentNames,
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002425 final List<IBinder> services) {
Brad Ebinger0c3541b2016-11-01 14:11:38 -07002426 mHandler.post(new android.telecom.Logging.Runnable("oAA.qRCS.oR", null /*lock*/) {
Ihab Awad6107bab2014-08-18 09:23:25 -07002427 @Override
Brad Ebinger0c3541b2016-11-01 14:11:38 -07002428 public void loggedRun() {
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002429 for (int i = 0; i < componentNames.size() && i < services.size(); i++) {
Santos Cordon52d8a152014-06-17 19:08:45 -07002430 mRemoteConnectionManager.addConnectionService(
2431 componentNames.get(i),
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002432 IConnectionService.Stub.asInterface(services.get(i)));
Santos Cordon52d8a152014-06-17 19:08:45 -07002433 }
Ihab Awad5d0410f2014-07-30 10:07:40 -07002434 onAccountsInitialized();
Sailesh Nepalc5b01572014-07-14 16:29:44 -07002435 Log.d(this, "remote connection services found: " + services);
Santos Cordon52d8a152014-06-17 19:08:45 -07002436 }
Brad Ebinger0c3541b2016-11-01 14:11:38 -07002437 }.prepare());
Santos Cordon52d8a152014-06-17 19:08:45 -07002438 }
2439
2440 @Override
2441 public void onError() {
Brad Ebinger0c3541b2016-11-01 14:11:38 -07002442 mHandler.post(new android.telecom.Logging.Runnable("oAA.qRCS.oE", null /*lock*/) {
Ihab Awad6107bab2014-08-18 09:23:25 -07002443 @Override
Brad Ebinger0c3541b2016-11-01 14:11:38 -07002444 public void loggedRun() {
Ihab Awad9c3f1882014-06-30 21:17:13 -07002445 mAreAccountsInitialized = true;
Santos Cordon52d8a152014-06-17 19:08:45 -07002446 }
Brad Ebinger0c3541b2016-11-01 14:11:38 -07002447 }.prepare());
Santos Cordon52d8a152014-06-17 19:08:45 -07002448 }
Tyler Gunn4c69fb32019-05-17 10:49:16 -07002449 }, callingPackage);
Santos Cordon52d8a152014-06-17 19:08:45 -07002450 }
2451
Ihab Awadf8b69882014-07-25 15:14:01 -07002452 /**
2453 * Ask some other {@code ConnectionService} to create a {@code RemoteConnection} given an
Santos Cordona663f862014-10-29 13:49:58 -07002454 * incoming request. This is used by {@code ConnectionService}s that are registered with
2455 * {@link PhoneAccount#CAPABILITY_CONNECTION_MANAGER} and want to be able to manage
2456 * SIM-based incoming calls.
Ihab Awadf8b69882014-07-25 15:14:01 -07002457 *
2458 * @param connectionManagerPhoneAccount See description at
2459 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
2460 * @param request Details about the incoming call.
2461 * @return The {@code Connection} object to satisfy this call, or {@code null} to
2462 * not handle the call.
2463 */
2464 public final RemoteConnection createRemoteIncomingConnection(
2465 PhoneAccountHandle connectionManagerPhoneAccount,
2466 ConnectionRequest request) {
2467 return mRemoteConnectionManager.createRemoteConnection(
2468 connectionManagerPhoneAccount, request, true);
Santos Cordon52d8a152014-06-17 19:08:45 -07002469 }
2470
2471 /**
Ihab Awadf8b69882014-07-25 15:14:01 -07002472 * Ask some other {@code ConnectionService} to create a {@code RemoteConnection} given an
Santos Cordona663f862014-10-29 13:49:58 -07002473 * outgoing request. This is used by {@code ConnectionService}s that are registered with
2474 * {@link PhoneAccount#CAPABILITY_CONNECTION_MANAGER} and want to be able to use the
2475 * SIM-based {@code ConnectionService} to place its outgoing calls.
Ihab Awadf8b69882014-07-25 15:14:01 -07002476 *
2477 * @param connectionManagerPhoneAccount See description at
2478 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
Cuihtlauac ALVARADO0b3b2a52016-09-13 14:49:41 +02002479 * @param request Details about the outgoing call.
Ihab Awadf8b69882014-07-25 15:14:01 -07002480 * @return The {@code Connection} object to satisfy this call, or {@code null} to
2481 * not handle the call.
2482 */
2483 public final RemoteConnection createRemoteOutgoingConnection(
2484 PhoneAccountHandle connectionManagerPhoneAccount,
2485 ConnectionRequest request) {
2486 return mRemoteConnectionManager.createRemoteConnection(
2487 connectionManagerPhoneAccount, request, false);
2488 }
2489
2490 /**
Grace Jia9a09c672020-08-04 12:52:09 -07002491 * Ask some other {@code ConnectionService} to create a {@code RemoteConference} given an
2492 * incoming request. This is used by {@code ConnectionService}s that are registered with
2493 * {@link PhoneAccount#CAPABILITY_ADHOC_CONFERENCE_CALLING}.
2494 *
2495 * @param connectionManagerPhoneAccount See description at
2496 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
2497 * @param request Details about the incoming conference call.
2498 * @return The {@code RemoteConference} object to satisfy this call, or {@code null} to not
2499 * handle the call.
2500 */
2501 public final @Nullable RemoteConference createRemoteIncomingConference(
2502 @Nullable PhoneAccountHandle connectionManagerPhoneAccount,
2503 @Nullable ConnectionRequest request) {
2504 return mRemoteConnectionManager.createRemoteConference(connectionManagerPhoneAccount,
2505 request, true);
2506 }
2507
2508 /**
2509 * Ask some other {@code ConnectionService} to create a {@code RemoteConference} given an
2510 * outgoing request. This is used by {@code ConnectionService}s that are registered with
2511 * {@link PhoneAccount#CAPABILITY_ADHOC_CONFERENCE_CALLING}.
2512 *
2513 * @param connectionManagerPhoneAccount See description at
2514 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
2515 * @param request Details about the outgoing conference call.
2516 * @return The {@code RemoteConference} object to satisfy this call, or {@code null} to not
2517 * handle the call.
2518 */
2519 public final @Nullable RemoteConference createRemoteOutgoingConference(
2520 @Nullable PhoneAccountHandle connectionManagerPhoneAccount,
2521 @Nullable ConnectionRequest request) {
2522 return mRemoteConnectionManager.createRemoteConference(connectionManagerPhoneAccount,
2523 request, false);
2524 }
2525
2526 /**
Santos Cordona663f862014-10-29 13:49:58 -07002527 * Indicates to the relevant {@code RemoteConnectionService} that the specified
2528 * {@link RemoteConnection}s should be merged into a conference call.
2529 * <p>
2530 * If the conference request is successful, the method {@link #onRemoteConferenceAdded} will
2531 * be invoked.
2532 *
2533 * @param remoteConnection1 The first of the remote connections to conference.
2534 * @param remoteConnection2 The second of the remote connections to conference.
Ihab Awadb8e85c72014-08-23 20:34:57 -07002535 */
2536 public final void conferenceRemoteConnections(
Santos Cordona663f862014-10-29 13:49:58 -07002537 RemoteConnection remoteConnection1,
2538 RemoteConnection remoteConnection2) {
2539 mRemoteConnectionManager.conferenceRemoteConnections(remoteConnection1, remoteConnection2);
Ihab Awadb8e85c72014-08-23 20:34:57 -07002540 }
2541
2542 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07002543 * Adds a new conference call. When a conference call is created either as a result of an
2544 * explicit request via {@link #onConference} or otherwise, the connection service should supply
2545 * an instance of {@link Conference} by invoking this method. A conference call provided by this
2546 * method will persist until {@link Conference#destroy} is invoked on the conference instance.
2547 *
2548 * @param conference The new conference object.
2549 */
2550 public final void addConference(Conference conference) {
Rekha Kumar07366812015-03-24 16:42:31 -07002551 Log.d(this, "addConference: conference=%s", conference);
2552
Santos Cordon823fd3c2014-08-07 18:35:18 -07002553 String id = addConferenceInternal(conference);
2554 if (id != null) {
2555 List<String> connectionIds = new ArrayList<>(2);
2556 for (Connection connection : conference.getConnections()) {
2557 if (mIdByConnection.containsKey(connection)) {
2558 connectionIds.add(mIdByConnection.get(connection));
2559 }
2560 }
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002561 conference.setTelecomCallId(id);
Brad Ebinger0ae44ed2020-04-09 15:30:57 -07002562 ParcelableConference parcelableConference = new ParcelableConference.Builder(
2563 conference.getPhoneAccountHandle(), conference.getState())
2564 .setConnectionCapabilities(conference.getConnectionCapabilities())
2565 .setConnectionProperties(conference.getConnectionProperties())
2566 .setConnectionIds(connectionIds)
2567 .setVideoAttributes(conference.getVideoProvider() == null
2568 ? null : conference.getVideoProvider().getInterface(),
2569 conference.getVideoState())
2570 .setConnectTimeMillis(conference.getConnectTimeMillis(),
2571 conference.getConnectionStartElapsedRealtimeMillis())
2572 .setStatusHints(conference.getStatusHints())
2573 .setExtras(conference.getExtras())
2574 .setAddress(conference.getAddress(), conference.getAddressPresentation())
2575 .setCallerDisplayName(conference.getCallerDisplayName(),
2576 conference.getCallerDisplayNamePresentation())
2577 .setDisconnectCause(conference.getDisconnectCause())
2578 .setRingbackRequested(conference.isRingbackRequested())
2579 .setCallDirection(conference.getCallDirection())
2580 .build();
Andrew Lee0f51da32015-04-16 13:11:55 -07002581
Santos Cordon823fd3c2014-08-07 18:35:18 -07002582 mAdapter.addConferenceCall(id, parcelableConference);
Rekha Kumar07366812015-03-24 16:42:31 -07002583 mAdapter.setVideoProvider(id, conference.getVideoProvider());
2584 mAdapter.setVideoState(id, conference.getVideoState());
Tyler Gunn10362372020-04-08 13:12:30 -07002585 // In some instances a conference can start its life as a standalone call with just a
2586 // single participant; ensure we signal to Telecom in this case.
2587 if (!conference.isMultiparty()) {
2588 mAdapter.setConferenceState(id, conference.isMultiparty());
2589 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07002590
2591 // Go through any child calls and set the parent.
2592 for (Connection connection : conference.getConnections()) {
2593 String connectionId = mIdByConnection.get(connection);
2594 if (connectionId != null) {
2595 mAdapter.setIsConferenced(connectionId, id);
2596 }
2597 }
Pengquan Meng70c9885332017-10-02 18:09:03 -07002598 onConferenceAdded(conference);
Santos Cordon823fd3c2014-08-07 18:35:18 -07002599 }
2600 }
2601
2602 /**
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002603 * Adds a connection created by the {@link ConnectionService} and informs telecom of the new
2604 * connection.
2605 *
2606 * @param phoneAccountHandle The phone account handle for the connection.
2607 * @param connection The connection to add.
2608 */
2609 public final void addExistingConnection(PhoneAccountHandle phoneAccountHandle,
2610 Connection connection) {
Tyler Gunn78da7812017-05-09 14:34:57 -07002611 addExistingConnection(phoneAccountHandle, connection, null /* conference */);
2612 }
2613
2614 /**
Pengquan Meng731c1a32017-11-21 18:01:13 -08002615 * Call to inform Telecom that your {@link ConnectionService} has released call resources (e.g
2616 * microphone, camera).
2617 *
Pengquan Menge3bf7e22018-02-22 17:30:04 -08002618 * <p>
2619 * The {@link ConnectionService} will be disconnected when it failed to call this method within
2620 * 5 seconds after {@link #onConnectionServiceFocusLost()} is called.
2621 *
Pengquan Meng731c1a32017-11-21 18:01:13 -08002622 * @see ConnectionService#onConnectionServiceFocusLost()
2623 */
2624 public final void connectionServiceFocusReleased() {
2625 mAdapter.onConnectionServiceFocusReleased();
2626 }
2627
2628 /**
Tyler Gunn78da7812017-05-09 14:34:57 -07002629 * Adds a connection created by the {@link ConnectionService} and informs telecom of the new
Tyler Gunn5567d742019-10-31 13:04:37 -07002630 * connection, as well as adding that connection to the specified conference.
2631 * <p>
2632 * Note: This API is intended ONLY for use by the Telephony stack to provide an easy way to add
2633 * IMS conference participants to be added to a conference in a single step; this helps ensure
2634 * UI updates happen atomically, rather than adding the connection and then adding it to
2635 * the conference in another step.
Tyler Gunn78da7812017-05-09 14:34:57 -07002636 *
2637 * @param phoneAccountHandle The phone account handle for the connection.
2638 * @param connection The connection to add.
2639 * @param conference The parent conference of the new connection.
2640 * @hide
2641 */
Tyler Gunn5567d742019-10-31 13:04:37 -07002642 @SystemApi
2643 public final void addExistingConnection(@NonNull PhoneAccountHandle phoneAccountHandle,
2644 @NonNull Connection connection, @NonNull Conference conference) {
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002645
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002646 String id = addExistingConnectionInternal(phoneAccountHandle, connection);
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002647 if (id != null) {
2648 List<String> emptyList = new ArrayList<>(0);
Tyler Gunn78da7812017-05-09 14:34:57 -07002649 String conferenceId = null;
2650 if (conference != null) {
2651 conferenceId = mIdByConference.get(conference);
2652 }
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002653
2654 ParcelableConnection parcelableConnection = new ParcelableConnection(
2655 phoneAccountHandle,
2656 connection.getState(),
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002657 connection.getConnectionCapabilities(),
Tyler Gunn720c6642016-03-22 09:02:47 -07002658 connection.getConnectionProperties(),
Christine Hallstrom2830ce92016-11-30 16:06:42 -08002659 connection.getSupportedAudioRoutes(),
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002660 connection.getAddress(),
2661 connection.getAddressPresentation(),
2662 connection.getCallerDisplayName(),
2663 connection.getCallerDisplayNamePresentation(),
2664 connection.getVideoProvider() == null ?
2665 null : connection.getVideoProvider().getInterface(),
2666 connection.getVideoState(),
2667 connection.isRingbackRequested(),
2668 connection.getAudioModeIsVoip(),
Roshan Piuse927ec02015-07-15 15:47:21 -07002669 connection.getConnectTimeMillis(),
Tyler Gunnc9503d62020-01-27 10:30:51 -08002670 connection.getConnectionStartElapsedRealtimeMillis(),
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002671 connection.getStatusHints(),
2672 connection.getDisconnectCause(),
Santos Cordon6b7f9552015-05-27 17:21:45 -07002673 emptyList,
Tyler Gunn78da7812017-05-09 14:34:57 -07002674 connection.getExtras(),
Tyler Gunn6986a632019-06-25 13:45:32 -07002675 conferenceId,
Tyler Gunnd57d76c2019-09-24 14:53:23 -07002676 connection.getCallDirection(),
2677 Connection.VERIFICATION_STATUS_NOT_VERIFIED);
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002678 mAdapter.addExistingConnection(id, parcelableConnection);
2679 }
2680 }
2681
2682 /**
Ihab Awadf8b69882014-07-25 15:14:01 -07002683 * Returns all the active {@code Connection}s for which this {@code ConnectionService}
2684 * has taken responsibility.
2685 *
2686 * @return A collection of {@code Connection}s created by this {@code ConnectionService}.
Santos Cordonb6939982014-06-04 20:20:58 -07002687 */
Sailesh Nepal091768c2014-06-30 15:15:23 -07002688 public final Collection<Connection> getAllConnections() {
Santos Cordonb6939982014-06-04 20:20:58 -07002689 return mConnectionById.values();
2690 }
2691
2692 /**
Santos Cordona6018b92016-02-16 14:23:12 -08002693 * Returns all the active {@code Conference}s for which this {@code ConnectionService}
2694 * has taken responsibility.
2695 *
2696 * @return A collection of {@code Conference}s created by this {@code ConnectionService}.
2697 */
2698 public final Collection<Conference> getAllConferences() {
2699 return mConferenceById.values();
2700 }
2701
2702 /**
Ihab Awadf8b69882014-07-25 15:14:01 -07002703 * Create a {@code Connection} given an incoming request. This is used to attach to existing
2704 * incoming calls.
Evan Charltonbf11f982014-07-20 22:06:28 -07002705 *
Ihab Awadf8b69882014-07-25 15:14:01 -07002706 * @param connectionManagerPhoneAccount See description at
2707 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
2708 * @param request Details about the incoming call.
2709 * @return The {@code Connection} object to satisfy this call, or {@code null} to
2710 * not handle the call.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002711 */
Ihab Awadf8b69882014-07-25 15:14:01 -07002712 public Connection onCreateIncomingConnection(
2713 PhoneAccountHandle connectionManagerPhoneAccount,
2714 ConnectionRequest request) {
2715 return null;
2716 }
Ravi Paluri80aa2142019-12-02 11:57:37 +05302717 /**
Grace Jia8587ee52020-07-10 15:42:32 -07002718 * Create a {@code Conference} given an incoming request. This is used to attach to an incoming
2719 * conference call initiated via
2720 * {@link TelecomManager#addNewIncomingConference(PhoneAccountHandle, Bundle)}.
Ravi Paluri80aa2142019-12-02 11:57:37 +05302721 *
2722 * @param connectionManagerPhoneAccount See description at
2723 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
Grace Jia8587ee52020-07-10 15:42:32 -07002724 * @param request Details about the incoming conference call.
2725 * @return The {@code Conference} object to satisfy this call, or {@code null} to
Ravi Paluri80aa2142019-12-02 11:57:37 +05302726 * not handle the call.
2727 */
2728 public @Nullable Conference onCreateIncomingConference(
2729 @Nullable PhoneAccountHandle connectionManagerPhoneAccount,
2730 @Nullable ConnectionRequest request) {
2731 return null;
2732 }
Sailesh Nepalc5b01572014-07-14 16:29:44 -07002733
2734 /**
Tyler Gunn041a1fe2017-05-12 10:04:49 -07002735 * Called after the {@link Connection} returned by
2736 * {@link #onCreateIncomingConnection(PhoneAccountHandle, ConnectionRequest)}
2737 * or {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)} has been
2738 * added to the {@link ConnectionService} and sent to Telecom.
2739 *
2740 * @param connection the {@link Connection}.
2741 * @hide
2742 */
2743 public void onCreateConnectionComplete(Connection connection) {
2744 }
2745
2746 /**
Ravi Paluri80aa2142019-12-02 11:57:37 +05302747 * Called after the {@link Conference} returned by
2748 * {@link #onCreateIncomingConference(PhoneAccountHandle, ConnectionRequest)}
2749 * or {@link #onCreateOutgoingConference(PhoneAccountHandle, ConnectionRequest)} has been
2750 * added to the {@link ConnectionService} and sent to Telecom.
2751 *
2752 * @param conference the {@link Conference}.
2753 * @hide
2754 */
2755 public void onCreateConferenceComplete(Conference conference) {
2756 }
2757
2758
2759 /**
Tyler Gunnf5035432017-01-09 09:43:12 -08002760 * Called by Telecom to inform the {@link ConnectionService} that its request to create a new
2761 * incoming {@link Connection} was denied.
2762 * <p>
2763 * Used when a self-managed {@link ConnectionService} attempts to create a new incoming
2764 * {@link Connection}, but Telecom has determined that the call cannot be allowed at this time.
2765 * The {@link ConnectionService} is responsible for silently rejecting the new incoming
2766 * {@link Connection}.
2767 * <p>
2768 * See {@link TelecomManager#isIncomingCallPermitted(PhoneAccountHandle)} for more information.
2769 *
Tyler Gunn159f35c2017-03-02 09:28:37 -08002770 * @param connectionManagerPhoneAccount See description at
2771 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
Tyler Gunnf5035432017-01-09 09:43:12 -08002772 * @param request The incoming connection request.
2773 */
Tyler Gunn159f35c2017-03-02 09:28:37 -08002774 public void onCreateIncomingConnectionFailed(PhoneAccountHandle connectionManagerPhoneAccount,
2775 ConnectionRequest request) {
Tyler Gunnf5035432017-01-09 09:43:12 -08002776 }
2777
2778 /**
2779 * Called by Telecom to inform the {@link ConnectionService} that its request to create a new
2780 * outgoing {@link Connection} was denied.
2781 * <p>
2782 * Used when a self-managed {@link ConnectionService} attempts to create a new outgoing
2783 * {@link Connection}, but Telecom has determined that the call cannot be placed at this time.
2784 * The {@link ConnectionService} is responisible for informing the user that the
2785 * {@link Connection} cannot be made at this time.
2786 * <p>
2787 * See {@link TelecomManager#isOutgoingCallPermitted(PhoneAccountHandle)} for more information.
2788 *
Tyler Gunn159f35c2017-03-02 09:28:37 -08002789 * @param connectionManagerPhoneAccount See description at
2790 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
Tyler Gunnf5035432017-01-09 09:43:12 -08002791 * @param request The outgoing connection request.
2792 */
Tyler Gunn159f35c2017-03-02 09:28:37 -08002793 public void onCreateOutgoingConnectionFailed(PhoneAccountHandle connectionManagerPhoneAccount,
2794 ConnectionRequest request) {
Tyler Gunnf5035432017-01-09 09:43:12 -08002795 }
2796
2797 /**
Ravi Paluri80aa2142019-12-02 11:57:37 +05302798 * Called by Telecom to inform the {@link ConnectionService} that its request to create a new
2799 * incoming {@link Conference} was denied.
2800 * <p>
2801 * Used when a self-managed {@link ConnectionService} attempts to create a new incoming
2802 * {@link Conference}, but Telecom has determined that the call cannot be allowed at this time.
2803 * The {@link ConnectionService} is responsible for silently rejecting the new incoming
2804 * {@link Conference}.
2805 * <p>
2806 * See {@link TelecomManager#isIncomingCallPermitted(PhoneAccountHandle)} for more information.
2807 *
2808 * @param connectionManagerPhoneAccount See description at
2809 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
2810 * @param request The incoming connection request.
2811 */
2812 public void onCreateIncomingConferenceFailed(
2813 @Nullable PhoneAccountHandle connectionManagerPhoneAccount,
2814 @Nullable ConnectionRequest request) {
2815 }
2816
2817 /**
2818 * Called by Telecom to inform the {@link ConnectionService} that its request to create a new
2819 * outgoing {@link Conference} was denied.
2820 * <p>
2821 * Used when a self-managed {@link ConnectionService} attempts to create a new outgoing
2822 * {@link Conference}, but Telecom has determined that the call cannot be placed at this time.
2823 * The {@link ConnectionService} is responisible for informing the user that the
2824 * {@link Conference} cannot be made at this time.
2825 * <p>
2826 * See {@link TelecomManager#isOutgoingCallPermitted(PhoneAccountHandle)} for more information.
2827 *
2828 * @param connectionManagerPhoneAccount See description at
2829 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
2830 * @param request The outgoing connection request.
2831 */
2832 public void onCreateOutgoingConferenceFailed(
2833 @Nullable PhoneAccountHandle connectionManagerPhoneAccount,
2834 @Nullable ConnectionRequest request) {
2835 }
2836
2837
2838 /**
Shriram Ganesh6bf35ac2014-12-11 17:53:38 -08002839 * Trigger recalculate functinality for conference calls. This is used when a Telephony
2840 * Connection is part of a conference controller but is not yet added to Connection
2841 * Service and hence cannot be added to the conference call.
2842 *
2843 * @hide
2844 */
2845 public void triggerConferenceRecalculate() {
2846 }
2847
2848 /**
Ihab Awadf8b69882014-07-25 15:14:01 -07002849 * Create a {@code Connection} given an outgoing request. This is used to initiate new
2850 * outgoing calls.
Sailesh Nepalc5b01572014-07-14 16:29:44 -07002851 *
Ihab Awadf8b69882014-07-25 15:14:01 -07002852 * @param connectionManagerPhoneAccount The connection manager account to use for managing
2853 * this call.
2854 * <p>
2855 * If this parameter is not {@code null}, it means that this {@code ConnectionService}
2856 * has registered one or more {@code PhoneAccount}s having
2857 * {@link PhoneAccount#CAPABILITY_CONNECTION_MANAGER}. This parameter will contain
2858 * one of these {@code PhoneAccount}s, while the {@code request} will contain another
2859 * (usually but not always distinct) {@code PhoneAccount} to be used for actually
2860 * making the connection.
2861 * <p>
2862 * If this parameter is {@code null}, it means that this {@code ConnectionService} is
2863 * being asked to make a direct connection. The
2864 * {@link ConnectionRequest#getAccountHandle()} of parameter {@code request} will be
2865 * a {@code PhoneAccount} registered by this {@code ConnectionService} to use for
2866 * making the connection.
2867 * @param request Details about the outgoing call.
2868 * @return The {@code Connection} object to satisfy this call, or the result of an invocation
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002869 * of {@link Connection#createFailedConnection(DisconnectCause)} to not handle the call.
Sailesh Nepalc5b01572014-07-14 16:29:44 -07002870 */
Ihab Awadf8b69882014-07-25 15:14:01 -07002871 public Connection onCreateOutgoingConnection(
2872 PhoneAccountHandle connectionManagerPhoneAccount,
2873 ConnectionRequest request) {
2874 return null;
2875 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002876
2877 /**
Ravi Paluri80aa2142019-12-02 11:57:37 +05302878 * Create a {@code Conference} given an outgoing request. This is used to initiate new
Grace Jia8587ee52020-07-10 15:42:32 -07002879 * outgoing conference call requested via
2880 * {@link TelecomManager#startConference(List, Bundle)}.
Ravi Paluri80aa2142019-12-02 11:57:37 +05302881 *
2882 * @param connectionManagerPhoneAccount The connection manager account to use for managing
2883 * this call.
2884 * <p>
2885 * If this parameter is not {@code null}, it means that this {@code ConnectionService}
2886 * has registered one or more {@code PhoneAccount}s having
2887 * {@link PhoneAccount#CAPABILITY_CONNECTION_MANAGER}. This parameter will contain
2888 * one of these {@code PhoneAccount}s, while the {@code request} will contain another
2889 * (usually but not always distinct) {@code PhoneAccount} to be used for actually
2890 * making the connection.
2891 * <p>
2892 * If this parameter is {@code null}, it means that this {@code ConnectionService} is
2893 * being asked to make a direct connection. The
2894 * {@link ConnectionRequest#getAccountHandle()} of parameter {@code request} will be
2895 * a {@code PhoneAccount} registered by this {@code ConnectionService} to use for
2896 * making the connection.
2897 * @param request Details about the outgoing call.
2898 * @return The {@code Conference} object to satisfy this call, or the result of an invocation
2899 * of {@link Connection#createFailedConnection(DisconnectCause)} to not handle the call.
2900 */
2901 public @Nullable Conference onCreateOutgoingConference(
2902 @Nullable PhoneAccountHandle connectionManagerPhoneAccount,
2903 @Nullable ConnectionRequest request) {
2904 return null;
2905 }
2906
2907
2908 /**
Tyler Gunn9d127732018-03-02 15:45:51 -08002909 * Called by Telecom to request that a {@link ConnectionService} creates an instance of an
2910 * outgoing handover {@link Connection}.
2911 * <p>
2912 * A call handover is the process where an ongoing call is transferred from one app (i.e.
2913 * {@link ConnectionService} to another app. The user could, for example, choose to continue a
2914 * mobile network call in a video calling app. The mobile network call via the Telephony stack
2915 * is referred to as the source of the handover, and the video calling app is referred to as the
2916 * destination.
2917 * <p>
2918 * When considering a handover scenario the <em>initiating</em> device is where a user initiated
2919 * the handover process (e.g. by calling {@link android.telecom.Call#handoverTo(
2920 * PhoneAccountHandle, int, Bundle)}, and the other device is considered the <em>receiving</em>
2921 * device.
2922 * <p>
2923 * This method is called on the destination {@link ConnectionService} on <em>initiating</em>
2924 * device when the user initiates a handover request from one app to another. The user request
2925 * originates in the {@link InCallService} via
2926 * {@link android.telecom.Call#handoverTo(PhoneAccountHandle, int, Bundle)}.
2927 * <p>
2928 * For a full discussion of the handover process and the APIs involved, see
2929 * {@link android.telecom.Call#handoverTo(PhoneAccountHandle, int, Bundle)}.
2930 * <p>
2931 * Implementations of this method should return an instance of {@link Connection} which
2932 * represents the handover. If your app does not wish to accept a handover to it at this time,
2933 * you can return {@code null}. The code below shows an example of how this is done.
2934 * <pre>
2935 * {@code
2936 * public Connection onCreateIncomingHandoverConnection(PhoneAccountHandle
2937 * fromPhoneAccountHandle, ConnectionRequest request) {
2938 * if (!isHandoverAvailable()) {
2939 * return null;
2940 * }
2941 * MyConnection connection = new MyConnection();
2942 * connection.setAddress(request.getAddress(), TelecomManager.PRESENTATION_ALLOWED);
2943 * connection.setVideoState(request.getVideoState());
2944 * return connection;
2945 * }
2946 * }
2947 * </pre>
2948 *
Sanket Padawea8eddd42017-11-03 11:07:35 -07002949 * @param fromPhoneAccountHandle {@link PhoneAccountHandle} associated with the
2950 * ConnectionService which needs to handover the call.
Tyler Gunn9d127732018-03-02 15:45:51 -08002951 * @param request Details about the call to handover.
2952 * @return {@link Connection} instance corresponding to the handover call.
Sanket Padawea8eddd42017-11-03 11:07:35 -07002953 */
2954 public Connection onCreateOutgoingHandoverConnection(PhoneAccountHandle fromPhoneAccountHandle,
2955 ConnectionRequest request) {
2956 return null;
2957 }
2958
2959 /**
Tyler Gunn9d127732018-03-02 15:45:51 -08002960 * Called by Telecom to request that a {@link ConnectionService} creates an instance of an
2961 * incoming handover {@link Connection}.
2962 * <p>
2963 * A call handover is the process where an ongoing call is transferred from one app (i.e.
2964 * {@link ConnectionService} to another app. The user could, for example, choose to continue a
2965 * mobile network call in a video calling app. The mobile network call via the Telephony stack
2966 * is referred to as the source of the handover, and the video calling app is referred to as the
2967 * destination.
2968 * <p>
2969 * When considering a handover scenario the <em>initiating</em> device is where a user initiated
2970 * the handover process (e.g. by calling {@link android.telecom.Call#handoverTo(
2971 * PhoneAccountHandle, int, Bundle)}, and the other device is considered the <em>receiving</em>
2972 * device.
2973 * <p>
2974 * This method is called on the destination app on the <em>receiving</em> device when the
2975 * destination app calls {@link TelecomManager#acceptHandover(Uri, int, PhoneAccountHandle)} to
2976 * accept an incoming handover from the <em>initiating</em> device.
2977 * <p>
2978 * For a full discussion of the handover process and the APIs involved, see
2979 * {@link android.telecom.Call#handoverTo(PhoneAccountHandle, int, Bundle)}.
2980 * <p>
2981 * Implementations of this method should return an instance of {@link Connection} which
2982 * represents the handover. The code below shows an example of how this is done.
2983 * <pre>
2984 * {@code
2985 * public Connection onCreateIncomingHandoverConnection(PhoneAccountHandle
2986 * fromPhoneAccountHandle, ConnectionRequest request) {
2987 * // Given that your app requested to accept the handover, you should not return null here.
2988 * MyConnection connection = new MyConnection();
2989 * connection.setAddress(request.getAddress(), TelecomManager.PRESENTATION_ALLOWED);
2990 * connection.setVideoState(request.getVideoState());
2991 * return connection;
2992 * }
2993 * }
2994 * </pre>
2995 *
Sanket Padawea8eddd42017-11-03 11:07:35 -07002996 * @param fromPhoneAccountHandle {@link PhoneAccountHandle} associated with the
2997 * ConnectionService which needs to handover the call.
2998 * @param request Details about the call which needs to be handover.
Tyler Gunn9d127732018-03-02 15:45:51 -08002999 * @return {@link Connection} instance corresponding to the handover call.
Sanket Padawea8eddd42017-11-03 11:07:35 -07003000 */
3001 public Connection onCreateIncomingHandoverConnection(PhoneAccountHandle fromPhoneAccountHandle,
3002 ConnectionRequest request) {
3003 return null;
3004 }
3005
3006 /**
3007 * Called by Telecom in response to a {@code TelecomManager#acceptHandover()}
3008 * invocation which failed.
Tyler Gunn9d127732018-03-02 15:45:51 -08003009 * <p>
3010 * For a full discussion of the handover process and the APIs involved, see
3011 * {@link android.telecom.Call#handoverTo(PhoneAccountHandle, int, Bundle)}
3012 *
3013 * @param request Details about the call which failed to handover.
3014 * @param error Reason for handover failure. Will be one of the
Sanket Padawea8eddd42017-11-03 11:07:35 -07003015 */
Tyler Gunn9d127732018-03-02 15:45:51 -08003016 public void onHandoverFailed(ConnectionRequest request,
3017 @Call.Callback.HandoverFailureErrors int error) {
Sanket Padawea8eddd42017-11-03 11:07:35 -07003018 return;
3019 }
3020
3021 /**
Yorke Leec3cf9822014-10-02 09:38:39 -07003022 * Create a {@code Connection} for a new unknown call. An unknown call is a call originating
3023 * from the ConnectionService that was neither a user-initiated outgoing call, nor an incoming
3024 * call created using
3025 * {@code TelecomManager#addNewIncomingCall(PhoneAccountHandle, android.os.Bundle)}.
3026 *
Yorke Lee770ed6e2014-10-06 18:58:52 -07003027 * @hide
Yorke Leec3cf9822014-10-02 09:38:39 -07003028 */
3029 public Connection onCreateUnknownConnection(PhoneAccountHandle connectionManagerPhoneAccount,
3030 ConnectionRequest request) {
Brad Ebingerb32d4f82016-10-24 16:40:49 -07003031 return null;
Yorke Leec3cf9822014-10-02 09:38:39 -07003032 }
3033
3034 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07003035 * Conference two specified connections. Invoked when the user has made a request to merge the
3036 * specified connections into a conference call. In response, the connection service should
3037 * create an instance of {@link Conference} and pass it into {@link #addConference}.
Santos Cordonb6939982014-06-04 20:20:58 -07003038 *
Santos Cordon823fd3c2014-08-07 18:35:18 -07003039 * @param connection1 A connection to merge into a conference call.
3040 * @param connection2 A connection to merge into a conference call.
Santos Cordonb6939982014-06-04 20:20:58 -07003041 */
Santos Cordon823fd3c2014-08-07 18:35:18 -07003042 public void onConference(Connection connection1, Connection connection2) {}
Santos Cordonb6939982014-06-04 20:20:58 -07003043
Santos Cordona663f862014-10-29 13:49:58 -07003044 /**
Pengquan Meng70c9885332017-10-02 18:09:03 -07003045 * Called when a connection is added.
3046 * @hide
3047 */
3048 public void onConnectionAdded(Connection connection) {}
3049
3050 /**
3051 * Called when a connection is removed.
3052 * @hide
3053 */
3054 public void onConnectionRemoved(Connection connection) {}
3055
3056 /**
3057 * Called when a conference is added.
3058 * @hide
3059 */
3060 public void onConferenceAdded(Conference conference) {}
3061
3062 /**
3063 * Called when a conference is removed.
3064 * @hide
3065 */
3066 public void onConferenceRemoved(Conference conference) {}
3067
3068 /**
Santos Cordona663f862014-10-29 13:49:58 -07003069 * Indicates that a remote conference has been created for existing {@link RemoteConnection}s.
3070 * When this method is invoked, this {@link ConnectionService} should create its own
3071 * representation of the conference call and send it to telecom using {@link #addConference}.
3072 * <p>
3073 * This is only relevant to {@link ConnectionService}s which are registered with
3074 * {@link PhoneAccount#CAPABILITY_CONNECTION_MANAGER}.
3075 *
3076 * @param conference The remote conference call.
3077 */
Ihab Awadb8e85c72014-08-23 20:34:57 -07003078 public void onRemoteConferenceAdded(RemoteConference conference) {}
3079
Santos Cordon823fd3c2014-08-07 18:35:18 -07003080 /**
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07003081 * Called when an existing connection is added remotely.
3082 * @param connection The existing connection which was added.
3083 */
3084 public void onRemoteExistingConnectionAdded(RemoteConnection connection) {}
3085
3086 /**
Pengquan Meng731c1a32017-11-21 18:01:13 -08003087 * Called when the {@link ConnectionService} has lost the call focus.
3088 * The {@link ConnectionService} should release the call resources and invokes
3089 * {@link ConnectionService#connectionServiceFocusReleased()} to inform telecom that it has
3090 * released the call resources.
3091 */
3092 public void onConnectionServiceFocusLost() {}
3093
3094 /**
3095 * Called when the {@link ConnectionService} has gained the call focus. The
3096 * {@link ConnectionService} can acquire the call resources at this time.
3097 */
3098 public void onConnectionServiceFocusGained() {}
3099
3100 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07003101 * @hide
3102 */
3103 public boolean containsConference(Conference conference) {
3104 return mIdByConference.containsKey(conference);
3105 }
3106
Ihab Awadb8e85c72014-08-23 20:34:57 -07003107 /** {@hide} */
3108 void addRemoteConference(RemoteConference remoteConference) {
3109 onRemoteConferenceAdded(remoteConference);
3110 }
3111
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07003112 /** {@hide} */
3113 void addRemoteExistingConnection(RemoteConnection remoteConnection) {
3114 onRemoteExistingConnectionAdded(remoteConnection);
3115 }
3116
Ihab Awad5d0410f2014-07-30 10:07:40 -07003117 private void onAccountsInitialized() {
3118 mAreAccountsInitialized = true;
3119 for (Runnable r : mPreInitializationConnectionRequests) {
3120 r.run();
3121 }
3122 mPreInitializationConnectionRequests.clear();
3123 }
3124
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07003125 /**
Tyler Gunnf0500bd2015-09-01 10:59:48 -07003126 * Adds an existing connection to the list of connections, identified by a new call ID unique
3127 * to this connection service.
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07003128 *
3129 * @param connection The connection.
Tyler Gunnf0500bd2015-09-01 10:59:48 -07003130 * @return The ID of the connection (e.g. the call-id).
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07003131 */
Tyler Gunnf0500bd2015-09-01 10:59:48 -07003132 private String addExistingConnectionInternal(PhoneAccountHandle handle, Connection connection) {
3133 String id;
Tyler Gunncd6ccfd2016-10-17 15:48:19 -07003134
3135 if (connection.getExtras() != null && connection.getExtras()
3136 .containsKey(Connection.EXTRA_ORIGINAL_CONNECTION_ID)) {
3137 id = connection.getExtras().getString(Connection.EXTRA_ORIGINAL_CONNECTION_ID);
3138 Log.d(this, "addExistingConnectionInternal - conn %s reusing original id %s",
3139 connection.getTelecomCallId(), id);
3140 } else if (handle == null) {
Tyler Gunnf0500bd2015-09-01 10:59:48 -07003141 // If no phone account handle was provided, we cannot be sure the call ID is unique,
3142 // so just use a random UUID.
3143 id = UUID.randomUUID().toString();
3144 } else {
3145 // Phone account handle was provided, so use the ConnectionService class name as a
3146 // prefix for a unique incremental call ID.
3147 id = handle.getComponentName().getClassName() + "@" + getNextCallId();
3148 }
Pengquan Meng70c9885332017-10-02 18:09:03 -07003149 addConnection(handle, id, connection);
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07003150 return id;
3151 }
3152
Pengquan Meng70c9885332017-10-02 18:09:03 -07003153 private void addConnection(PhoneAccountHandle handle, String callId, Connection connection) {
Tyler Gunnf0500bd2015-09-01 10:59:48 -07003154 connection.setTelecomCallId(callId);
Ihab Awad542e0ea2014-05-16 10:22:16 -07003155 mConnectionById.put(callId, connection);
3156 mIdByConnection.put(connection, callId);
3157 connection.addConnectionListener(mConnectionListener);
Santos Cordon823fd3c2014-08-07 18:35:18 -07003158 connection.setConnectionService(this);
Pengquan Meng70c9885332017-10-02 18:09:03 -07003159 connection.setPhoneAccountHandle(handle);
3160 onConnectionAdded(connection);
Ihab Awad542e0ea2014-05-16 10:22:16 -07003161 }
3162
Anthony Lee30e65842014-11-06 16:30:53 -08003163 /** {@hide} */
3164 protected void removeConnection(Connection connection) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07003165 connection.unsetConnectionService(this);
Ihab Awad542e0ea2014-05-16 10:22:16 -07003166 connection.removeConnectionListener(mConnectionListener);
Chenjie Luoe370b532016-05-12 16:59:43 -07003167 String id = mIdByConnection.get(connection);
3168 if (id != null) {
3169 mConnectionById.remove(id);
3170 mIdByConnection.remove(connection);
3171 mAdapter.removeCall(id);
Pengquan Meng70c9885332017-10-02 18:09:03 -07003172 onConnectionRemoved(connection);
Chenjie Luoe370b532016-05-12 16:59:43 -07003173 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07003174 }
3175
Santos Cordon823fd3c2014-08-07 18:35:18 -07003176 private String addConferenceInternal(Conference conference) {
Tyler Gunncd6ccfd2016-10-17 15:48:19 -07003177 String originalId = null;
3178 if (conference.getExtras() != null && conference.getExtras()
3179 .containsKey(Connection.EXTRA_ORIGINAL_CONNECTION_ID)) {
3180 originalId = conference.getExtras().getString(Connection.EXTRA_ORIGINAL_CONNECTION_ID);
3181 Log.d(this, "addConferenceInternal: conf %s reusing original id %s",
3182 conference.getTelecomCallId(),
3183 originalId);
3184 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07003185 if (mIdByConference.containsKey(conference)) {
3186 Log.w(this, "Re-adding an existing conference: %s.", conference);
3187 } else if (conference != null) {
Tyler Gunnf0500bd2015-09-01 10:59:48 -07003188 // Conferences do not (yet) have a PhoneAccountHandle associated with them, so we
3189 // cannot determine a ConnectionService class name to associate with the ID, so use
3190 // a unique UUID (for now).
Tyler Gunncd6ccfd2016-10-17 15:48:19 -07003191 String id = originalId == null ? UUID.randomUUID().toString() : originalId;
Santos Cordon823fd3c2014-08-07 18:35:18 -07003192 mConferenceById.put(id, conference);
3193 mIdByConference.put(conference, id);
3194 conference.addListener(mConferenceListener);
3195 return id;
3196 }
3197
3198 return null;
3199 }
3200
3201 private void removeConference(Conference conference) {
3202 if (mIdByConference.containsKey(conference)) {
3203 conference.removeListener(mConferenceListener);
3204
3205 String id = mIdByConference.get(conference);
3206 mConferenceById.remove(id);
3207 mIdByConference.remove(conference);
3208 mAdapter.removeCall(id);
Pengquan Meng70c9885332017-10-02 18:09:03 -07003209
3210 onConferenceRemoved(conference);
Santos Cordon823fd3c2014-08-07 18:35:18 -07003211 }
3212 }
3213
Ihab Awad542e0ea2014-05-16 10:22:16 -07003214 private Connection findConnectionForAction(String callId, String action) {
Tyler Gunn0a88f2e2017-06-16 20:20:34 -07003215 if (callId != null && mConnectionById.containsKey(callId)) {
Ihab Awad542e0ea2014-05-16 10:22:16 -07003216 return mConnectionById.get(callId);
3217 }
Ihab Awad60ac30b2014-05-20 22:32:12 -07003218 Log.w(this, "%s - Cannot find Connection %s", action, callId);
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07003219 return getNullConnection();
3220 }
3221
3222 static synchronized Connection getNullConnection() {
3223 if (sNullConnection == null) {
3224 sNullConnection = new Connection() {};
3225 }
3226 return sNullConnection;
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003227 }
Santos Cordon0159ac02014-08-21 14:28:11 -07003228
3229 private Conference findConferenceForAction(String conferenceId, String action) {
3230 if (mConferenceById.containsKey(conferenceId)) {
3231 return mConferenceById.get(conferenceId);
3232 }
3233 Log.w(this, "%s - Cannot find conference %s", action, conferenceId);
3234 return getNullConference();
3235 }
3236
Ihab Awadb8e85c72014-08-23 20:34:57 -07003237 private List<String> createConnectionIdList(List<Connection> connections) {
3238 List<String> ids = new ArrayList<>();
3239 for (Connection c : connections) {
3240 if (mIdByConnection.containsKey(c)) {
3241 ids.add(mIdByConnection.get(c));
3242 }
3243 }
3244 Collections.sort(ids);
3245 return ids;
3246 }
3247
Tyler Gunn6d76ca02014-11-17 15:49:51 -08003248 /**
3249 * Builds a list of {@link Connection} and {@link Conference} IDs based on the list of
Tyler Gunndf2cbc82015-04-20 09:13:01 -07003250 * {@link Conferenceable}s passed in.
Tyler Gunn6d76ca02014-11-17 15:49:51 -08003251 *
Tyler Gunndf2cbc82015-04-20 09:13:01 -07003252 * @param conferenceables The {@link Conferenceable} connections and conferences.
Tyler Gunn6d76ca02014-11-17 15:49:51 -08003253 * @return List of string conference and call Ids.
3254 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07003255 private List<String> createIdList(List<Conferenceable> conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08003256 List<String> ids = new ArrayList<>();
Tyler Gunndf2cbc82015-04-20 09:13:01 -07003257 for (Conferenceable c : conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08003258 // Only allow Connection and Conference conferenceables.
3259 if (c instanceof Connection) {
3260 Connection connection = (Connection) c;
3261 if (mIdByConnection.containsKey(connection)) {
3262 ids.add(mIdByConnection.get(connection));
3263 }
3264 } else if (c instanceof Conference) {
3265 Conference conference = (Conference) c;
3266 if (mIdByConference.containsKey(conference)) {
3267 ids.add(mIdByConference.get(conference));
3268 }
3269 }
3270 }
3271 Collections.sort(ids);
3272 return ids;
3273 }
3274
Santos Cordon0159ac02014-08-21 14:28:11 -07003275 private Conference getNullConference() {
3276 if (sNullConference == null) {
3277 sNullConference = new Conference(null) {};
3278 }
3279 return sNullConference;
3280 }
Santos Cordon29f2f2e2014-09-11 19:50:24 -07003281
3282 private void endAllConnections() {
3283 // Unbound from telecomm. We should end all connections and conferences.
3284 for (Connection connection : mIdByConnection.keySet()) {
3285 // only operate on top-level calls. Conference calls will be removed on their own.
3286 if (connection.getConference() == null) {
3287 connection.onDisconnect();
3288 }
3289 }
3290 for (Conference conference : mIdByConference.keySet()) {
3291 conference.onDisconnect();
3292 }
3293 }
Tyler Gunnf0500bd2015-09-01 10:59:48 -07003294
3295 /**
3296 * Retrieves the next call ID as maintainted by the connection service.
3297 *
3298 * @return The call ID.
3299 */
3300 private int getNextCallId() {
Brad Ebingerb32d4f82016-10-24 16:40:49 -07003301 synchronized (mIdSyncRoot) {
Tyler Gunnf0500bd2015-09-01 10:59:48 -07003302 return ++mId;
3303 }
3304 }
Brad Ebinger99f17ce2019-09-11 18:06:51 -07003305
3306 /**
3307 * Returns this handler, ONLY FOR TESTING.
3308 * @hide
3309 */
3310 @VisibleForTesting
3311 public Handler getHandler() {
3312 return mHandler;
3313 }
Santos Cordon980acb92014-05-31 10:31:19 -07003314}