blob: 3a0494e17db956e0cf75ae4050ae3908c2f5618c [file] [log] [blame]
Ihab Awad542e0ea2014-05-16 10:22:16 -07001/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Tyler Gunnef9f6f92014-09-12 22:16:17 -070017package android.telecom;
Ihab Awad542e0ea2014-05-16 10:22:16 -070018
Tyler Gunn5567d742019-10-31 13:04:37 -070019import android.annotation.NonNull;
20import android.annotation.Nullable;
21import android.annotation.RequiresPermission;
Santos Cordon5c6fa952014-07-20 17:47:12 -070022import android.annotation.SdkConstant;
Tyler Gunn5567d742019-10-31 13:04:37 -070023import android.annotation.SystemApi;
Sailesh Nepal2a46b902014-07-04 17:21:07 -070024import android.app.Service;
Santos Cordon52d8a152014-06-17 19:08:45 -070025import android.content.ComponentName;
Santos Cordon5c6fa952014-07-20 17:47:12 -070026import android.content.Intent;
Ihab Awad542e0ea2014-05-16 10:22:16 -070027import android.net.Uri;
Santos Cordon6b7f9552015-05-27 17:21:45 -070028import android.os.Bundle;
Santos Cordon52d8a152014-06-17 19:08:45 -070029import android.os.Handler;
30import android.os.IBinder;
31import android.os.Looper;
Sailesh Nepal2a46b902014-07-04 17:21:07 -070032import android.os.Message;
Hall Liub64ac4c2017-02-06 10:49:48 -080033import android.os.ParcelFileDescriptor;
34import android.os.RemoteException;
Brad Ebingerb32d4f82016-10-24 16:40:49 -070035import android.telecom.Logging.Session;
Andrew Lee14185762014-07-25 09:41:56 -070036
Brad Ebinger99f17ce2019-09-11 18:06:51 -070037import com.android.internal.annotations.VisibleForTesting;
Sailesh Nepal2a46b902014-07-04 17:21:07 -070038import com.android.internal.os.SomeArgs;
Tyler Gunnef9f6f92014-09-12 22:16:17 -070039import com.android.internal.telecom.IConnectionService;
40import com.android.internal.telecom.IConnectionServiceAdapter;
41import com.android.internal.telecom.RemoteServiceCallback;
Santos Cordon52d8a152014-06-17 19:08:45 -070042
Ihab Awad5d0410f2014-07-30 10:07:40 -070043import java.util.ArrayList;
Santos Cordonb6939982014-06-04 20:20:58 -070044import java.util.Collection;
Santos Cordon7c7bc7f2014-07-28 18:15:48 -070045import java.util.Collections;
Santos Cordon52d8a152014-06-17 19:08:45 -070046import java.util.List;
Ihab Awad542e0ea2014-05-16 10:22:16 -070047import java.util.Map;
Santos Cordon823fd3c2014-08-07 18:35:18 -070048import java.util.UUID;
mike dooley95e80702014-09-18 14:07:52 -070049import java.util.concurrent.ConcurrentHashMap;
Ihab Awad542e0ea2014-05-16 10:22:16 -070050
51/**
Tyler Gunnf5035432017-01-09 09:43:12 -080052 * An abstract service that should be implemented by any apps which either:
53 * <ol>
54 * <li>Can make phone calls (VoIP or otherwise) and want those calls to be integrated into the
55 * built-in phone app. Referred to as a <b>system managed</b> {@link ConnectionService}.</li>
56 * <li>Are a standalone calling app and don't want their calls to be integrated into the
57 * built-in phone app. Referred to as a <b>self managed</b> {@link ConnectionService}.</li>
58 * </ol>
59 * Once implemented, the {@link ConnectionService} needs to take the following steps so that Telecom
60 * will bind to it:
Santos Cordona663f862014-10-29 13:49:58 -070061 * <p>
62 * 1. <i>Registration in AndroidManifest.xml</i>
63 * <br/>
64 * <pre>
65 * &lt;service android:name="com.example.package.MyConnectionService"
66 * android:label="@string/some_label_for_my_connection_service"
Yorke Lee249c12e2015-05-13 15:59:29 -070067 * android:permission="android.permission.BIND_TELECOM_CONNECTION_SERVICE"&gt;
Santos Cordona663f862014-10-29 13:49:58 -070068 * &lt;intent-filter&gt;
69 * &lt;action android:name="android.telecom.ConnectionService" /&gt;
70 * &lt;/intent-filter&gt;
71 * &lt;/service&gt;
72 * </pre>
73 * <p>
74 * 2. <i> Registration of {@link PhoneAccount} with {@link TelecomManager}.</i>
75 * <br/>
76 * See {@link PhoneAccount} and {@link TelecomManager#registerPhoneAccount} for more information.
77 * <p>
Tyler Gunnf5035432017-01-09 09:43:12 -080078 * System managed {@link ConnectionService}s must be enabled by the user in the phone app settings
kopriva82c591b2018-10-08 15:57:00 -070079 * before Telecom will bind to them. Self-managed {@link ConnectionService}s must be granted the
Tyler Gunnf5035432017-01-09 09:43:12 -080080 * appropriate permission before Telecom will bind to them.
81 * <p>
82 * Once registered and enabled by the user in the phone app settings or granted permission, telecom
83 * will bind to a {@link ConnectionService} implementation when it wants that
84 * {@link ConnectionService} to place a call or the service has indicated that is has an incoming
85 * call through {@link TelecomManager#addNewIncomingCall}. The {@link ConnectionService} can then
86 * expect a call to {@link #onCreateIncomingConnection} or {@link #onCreateOutgoingConnection}
87 * wherein it should provide a new instance of a {@link Connection} object. It is through this
88 * {@link Connection} object that telecom receives state updates and the {@link ConnectionService}
Santos Cordona663f862014-10-29 13:49:58 -070089 * receives call-commands such as answer, reject, hold and disconnect.
90 * <p>
Tyler Gunnf5035432017-01-09 09:43:12 -080091 * When there are no more live calls, telecom will unbind from the {@link ConnectionService}.
Ihab Awad542e0ea2014-05-16 10:22:16 -070092 */
Sailesh Nepal2a46b902014-07-04 17:21:07 -070093public abstract class ConnectionService extends Service {
Santos Cordon5c6fa952014-07-20 17:47:12 -070094 /**
95 * The {@link Intent} that must be declared as handled by the service.
96 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -070097 @SdkConstant(SdkConstant.SdkConstantType.SERVICE_ACTION)
Tyler Gunnef9f6f92014-09-12 22:16:17 -070098 public static final String SERVICE_INTERFACE = "android.telecom.ConnectionService";
Santos Cordon5c6fa952014-07-20 17:47:12 -070099
Tyler Gunn8bf76572017-04-06 15:30:08 -0700100 /**
101 * Boolean extra used by Telecom to inform a {@link ConnectionService} that the purpose of it
102 * being asked to create a new outgoing {@link Connection} is to perform a handover of an
103 * ongoing call on the device from another {@link PhoneAccount}/{@link ConnectionService}. Will
104 * be specified in the {@link ConnectionRequest#getExtras()} passed by Telecom when
105 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)} is called.
106 * <p>
Tyler Gunn727c6bd2017-04-11 09:51:40 -0700107 * When your {@link ConnectionService} receives this extra, it should communicate the fact that
108 * this is a handover to the other device's matching {@link ConnectionService}. That
Tyler Gunn8bf76572017-04-06 15:30:08 -0700109 * {@link ConnectionService} will continue the handover using
110 * {@link TelecomManager#addNewIncomingCall(PhoneAccountHandle, Bundle)}, specifying
Tyler Gunn727c6bd2017-04-11 09:51:40 -0700111 * {@link TelecomManager#EXTRA_IS_HANDOVER}. Telecom will match the phone numbers of the
112 * handover call on the other device with ongoing calls for {@link ConnectionService}s which
113 * support {@link PhoneAccount#EXTRA_SUPPORTS_HANDOVER_FROM}.
Tyler Gunn8bf76572017-04-06 15:30:08 -0700114 * @hide
115 */
116 public static final String EXTRA_IS_HANDOVER = TelecomManager.EXTRA_IS_HANDOVER;
117
Ihab Awad542e0ea2014-05-16 10:22:16 -0700118 // Flag controlling whether PII is emitted into the logs
Ihab Awad60ac30b2014-05-20 22:32:12 -0700119 private static final boolean PII_DEBUG = Log.isLoggable(android.util.Log.DEBUG);
Ihab Awad542e0ea2014-05-16 10:22:16 -0700120
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700121 // Session Definitions
122 private static final String SESSION_HANDLER = "H.";
123 private static final String SESSION_ADD_CS_ADAPTER = "CS.aCSA";
124 private static final String SESSION_REMOVE_CS_ADAPTER = "CS.rCSA";
125 private static final String SESSION_CREATE_CONN = "CS.crCo";
Tyler Gunn041a1fe2017-05-12 10:04:49 -0700126 private static final String SESSION_CREATE_CONN_COMPLETE = "CS.crCoC";
Tyler Gunn44e01912017-01-31 10:49:05 -0800127 private static final String SESSION_CREATE_CONN_FAILED = "CS.crCoF";
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700128 private static final String SESSION_ABORT = "CS.ab";
129 private static final String SESSION_ANSWER = "CS.an";
130 private static final String SESSION_ANSWER_VIDEO = "CS.anV";
Pooja Jaind34698d2017-12-28 14:15:31 +0530131 private static final String SESSION_DEFLECT = "CS.def";
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700132 private static final String SESSION_REJECT = "CS.r";
133 private static final String SESSION_REJECT_MESSAGE = "CS.rWM";
134 private static final String SESSION_SILENCE = "CS.s";
135 private static final String SESSION_DISCONNECT = "CS.d";
136 private static final String SESSION_HOLD = "CS.h";
137 private static final String SESSION_UNHOLD = "CS.u";
138 private static final String SESSION_CALL_AUDIO_SC = "CS.cASC";
139 private static final String SESSION_PLAY_DTMF = "CS.pDT";
140 private static final String SESSION_STOP_DTMF = "CS.sDT";
141 private static final String SESSION_CONFERENCE = "CS.c";
142 private static final String SESSION_SPLIT_CONFERENCE = "CS.sFC";
143 private static final String SESSION_MERGE_CONFERENCE = "CS.mC";
144 private static final String SESSION_SWAP_CONFERENCE = "CS.sC";
145 private static final String SESSION_POST_DIAL_CONT = "CS.oPDC";
146 private static final String SESSION_PULL_EXTERNAL_CALL = "CS.pEC";
147 private static final String SESSION_SEND_CALL_EVENT = "CS.sCE";
Tyler Gunn79bc1ec2018-01-22 15:17:54 -0800148 private static final String SESSION_HANDOVER_COMPLETE = "CS.hC";
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700149 private static final String SESSION_EXTRAS_CHANGED = "CS.oEC";
Hall Liub64ac4c2017-02-06 10:49:48 -0800150 private static final String SESSION_START_RTT = "CS.+RTT";
Hall Liua549fed2018-02-09 16:40:03 -0800151 private static final String SESSION_UPDATE_RTT_PIPES = "CS.uRTT";
Hall Liub64ac4c2017-02-06 10:49:48 -0800152 private static final String SESSION_STOP_RTT = "CS.-RTT";
153 private static final String SESSION_RTT_UPGRADE_RESPONSE = "CS.rTRUR";
Pengquan Meng731c1a32017-11-21 18:01:13 -0800154 private static final String SESSION_CONNECTION_SERVICE_FOCUS_LOST = "CS.cSFL";
155 private static final String SESSION_CONNECTION_SERVICE_FOCUS_GAINED = "CS.cSFG";
Sanket Padawe4cc8ed52017-12-04 16:22:20 -0800156 private static final String SESSION_HANDOVER_FAILED = "CS.haF";
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700157
Ihab Awad8aecfed2014-08-08 17:06:11 -0700158 private static final int MSG_ADD_CONNECTION_SERVICE_ADAPTER = 1;
Sailesh Nepalc5b01572014-07-14 16:29:44 -0700159 private static final int MSG_CREATE_CONNECTION = 2;
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700160 private static final int MSG_ABORT = 3;
Sailesh Nepalc5b01572014-07-14 16:29:44 -0700161 private static final int MSG_ANSWER = 4;
162 private static final int MSG_REJECT = 5;
163 private static final int MSG_DISCONNECT = 6;
164 private static final int MSG_HOLD = 7;
165 private static final int MSG_UNHOLD = 8;
Yorke Lee4af59352015-05-13 14:14:54 -0700166 private static final int MSG_ON_CALL_AUDIO_STATE_CHANGED = 9;
Sailesh Nepalc5b01572014-07-14 16:29:44 -0700167 private static final int MSG_PLAY_DTMF_TONE = 10;
168 private static final int MSG_STOP_DTMF_TONE = 11;
169 private static final int MSG_CONFERENCE = 12;
170 private static final int MSG_SPLIT_FROM_CONFERENCE = 13;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700171 private static final int MSG_ON_POST_DIAL_CONTINUE = 14;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700172 private static final int MSG_REMOVE_CONNECTION_SERVICE_ADAPTER = 16;
Tyler Gunnbe74de02014-08-29 14:51:48 -0700173 private static final int MSG_ANSWER_VIDEO = 17;
Santos Cordona4868042014-09-04 17:39:22 -0700174 private static final int MSG_MERGE_CONFERENCE = 18;
175 private static final int MSG_SWAP_CONFERENCE = 19;
Bryce Lee81901682015-08-28 16:38:02 -0700176 private static final int MSG_REJECT_WITH_MESSAGE = 20;
Bryce Leecac50772015-11-17 15:13:29 -0800177 private static final int MSG_SILENCE = 21;
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700178 private static final int MSG_PULL_EXTERNAL_CALL = 22;
179 private static final int MSG_SEND_CALL_EVENT = 23;
Tyler Gunndee56a82016-03-23 16:06:34 -0700180 private static final int MSG_ON_EXTRAS_CHANGED = 24;
Tyler Gunn44e01912017-01-31 10:49:05 -0800181 private static final int MSG_CREATE_CONNECTION_FAILED = 25;
Hall Liub64ac4c2017-02-06 10:49:48 -0800182 private static final int MSG_ON_START_RTT = 26;
183 private static final int MSG_ON_STOP_RTT = 27;
184 private static final int MSG_RTT_UPGRADE_RESPONSE = 28;
Tyler Gunn041a1fe2017-05-12 10:04:49 -0700185 private static final int MSG_CREATE_CONNECTION_COMPLETE = 29;
Pengquan Meng731c1a32017-11-21 18:01:13 -0800186 private static final int MSG_CONNECTION_SERVICE_FOCUS_LOST = 30;
187 private static final int MSG_CONNECTION_SERVICE_FOCUS_GAINED = 31;
Sanket Padawe4cc8ed52017-12-04 16:22:20 -0800188 private static final int MSG_HANDOVER_FAILED = 32;
Tyler Gunn79bc1ec2018-01-22 15:17:54 -0800189 private static final int MSG_HANDOVER_COMPLETE = 33;
Pooja Jaind34698d2017-12-28 14:15:31 +0530190 private static final int MSG_DEFLECT = 34;
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700191
Sailesh Nepalcf7020b2014-08-20 10:07:19 -0700192 private static Connection sNullConnection;
193
mike dooley95e80702014-09-18 14:07:52 -0700194 private final Map<String, Connection> mConnectionById = new ConcurrentHashMap<>();
195 private final Map<Connection, String> mIdByConnection = new ConcurrentHashMap<>();
196 private final Map<String, Conference> mConferenceById = new ConcurrentHashMap<>();
197 private final Map<Conference, String> mIdByConference = new ConcurrentHashMap<>();
Ihab Awadb8e85c72014-08-23 20:34:57 -0700198 private final RemoteConnectionManager mRemoteConnectionManager =
199 new RemoteConnectionManager(this);
Ihab Awad5d0410f2014-07-30 10:07:40 -0700200 private final List<Runnable> mPreInitializationConnectionRequests = new ArrayList<>();
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700201 private final ConnectionServiceAdapter mAdapter = new ConnectionServiceAdapter();
Ihab Awad542e0ea2014-05-16 10:22:16 -0700202
Santos Cordon823fd3c2014-08-07 18:35:18 -0700203 private boolean mAreAccountsInitialized = false;
Santos Cordon0159ac02014-08-21 14:28:11 -0700204 private Conference sNullConference;
Tyler Gunnf0500bd2015-09-01 10:59:48 -0700205 private Object mIdSyncRoot = new Object();
206 private int mId = 0;
Santos Cordon823fd3c2014-08-07 18:35:18 -0700207
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700208 private final IBinder mBinder = new IConnectionService.Stub() {
209 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700210 public void addConnectionServiceAdapter(IConnectionServiceAdapter adapter,
211 Session.Info sessionInfo) {
212 Log.startSession(sessionInfo, SESSION_ADD_CS_ADAPTER);
213 try {
214 SomeArgs args = SomeArgs.obtain();
215 args.arg1 = adapter;
216 args.arg2 = Log.createSubsession();
217 mHandler.obtainMessage(MSG_ADD_CONNECTION_SERVICE_ADAPTER, args).sendToTarget();
218 } finally {
219 Log.endSession();
220 }
Ihab Awad8aecfed2014-08-08 17:06:11 -0700221 }
222
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700223 public void removeConnectionServiceAdapter(IConnectionServiceAdapter adapter,
224 Session.Info sessionInfo) {
225 Log.startSession(sessionInfo, SESSION_REMOVE_CS_ADAPTER);
226 try {
227 SomeArgs args = SomeArgs.obtain();
228 args.arg1 = adapter;
229 args.arg2 = Log.createSubsession();
230 mHandler.obtainMessage(MSG_REMOVE_CONNECTION_SERVICE_ADAPTER, args).sendToTarget();
231 } finally {
232 Log.endSession();
233 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700234 }
235
236 @Override
Ihab Awadf8b69882014-07-25 15:14:01 -0700237 public void createConnection(
238 PhoneAccountHandle connectionManagerPhoneAccount,
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700239 String id,
Ihab Awadf8b69882014-07-25 15:14:01 -0700240 ConnectionRequest request,
Yorke Leec3cf9822014-10-02 09:38:39 -0700241 boolean isIncoming,
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700242 boolean isUnknown,
243 Session.Info sessionInfo) {
244 Log.startSession(sessionInfo, SESSION_CREATE_CONN);
245 try {
246 SomeArgs args = SomeArgs.obtain();
247 args.arg1 = connectionManagerPhoneAccount;
248 args.arg2 = id;
249 args.arg3 = request;
250 args.arg4 = Log.createSubsession();
251 args.argi1 = isIncoming ? 1 : 0;
252 args.argi2 = isUnknown ? 1 : 0;
253 mHandler.obtainMessage(MSG_CREATE_CONNECTION, args).sendToTarget();
254 } finally {
255 Log.endSession();
256 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700257 }
258
259 @Override
Tyler Gunn041a1fe2017-05-12 10:04:49 -0700260 public void createConnectionComplete(String id, Session.Info sessionInfo) {
261 Log.startSession(sessionInfo, SESSION_CREATE_CONN_COMPLETE);
262 try {
263 SomeArgs args = SomeArgs.obtain();
264 args.arg1 = id;
265 args.arg2 = Log.createSubsession();
266 mHandler.obtainMessage(MSG_CREATE_CONNECTION_COMPLETE, args).sendToTarget();
267 } finally {
268 Log.endSession();
269 }
270 }
271
272 @Override
Tyler Gunn44e01912017-01-31 10:49:05 -0800273 public void createConnectionFailed(
Tyler Gunn159f35c2017-03-02 09:28:37 -0800274 PhoneAccountHandle connectionManagerPhoneAccount,
Tyler Gunn44e01912017-01-31 10:49:05 -0800275 String callId,
276 ConnectionRequest request,
277 boolean isIncoming,
278 Session.Info sessionInfo) {
279 Log.startSession(sessionInfo, SESSION_CREATE_CONN_FAILED);
280 try {
281 SomeArgs args = SomeArgs.obtain();
282 args.arg1 = callId;
283 args.arg2 = request;
284 args.arg3 = Log.createSubsession();
Tyler Gunn159f35c2017-03-02 09:28:37 -0800285 args.arg4 = connectionManagerPhoneAccount;
Tyler Gunn44e01912017-01-31 10:49:05 -0800286 args.argi1 = isIncoming ? 1 : 0;
287 mHandler.obtainMessage(MSG_CREATE_CONNECTION_FAILED, args).sendToTarget();
288 } finally {
289 Log.endSession();
290 }
291 }
292
293 @Override
Sanket Padawe4cc8ed52017-12-04 16:22:20 -0800294 public void handoverFailed(String callId, ConnectionRequest request, int reason,
295 Session.Info sessionInfo) {
296 Log.startSession(sessionInfo, SESSION_HANDOVER_FAILED);
297 try {
298 SomeArgs args = SomeArgs.obtain();
299 args.arg1 = callId;
300 args.arg2 = request;
301 args.arg3 = Log.createSubsession();
302 args.arg4 = reason;
303 mHandler.obtainMessage(MSG_HANDOVER_FAILED, args).sendToTarget();
304 } finally {
305 Log.endSession();
306 }
307 }
308
309 @Override
Tyler Gunn79bc1ec2018-01-22 15:17:54 -0800310 public void handoverComplete(String callId, Session.Info sessionInfo) {
311 Log.startSession(sessionInfo, SESSION_HANDOVER_COMPLETE);
312 try {
313 SomeArgs args = SomeArgs.obtain();
314 args.arg1 = callId;
315 args.arg2 = Log.createSubsession();
316 mHandler.obtainMessage(MSG_HANDOVER_COMPLETE, args).sendToTarget();
317 } finally {
318 Log.endSession();
319 }
320 }
321
322 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700323 public void abort(String callId, Session.Info sessionInfo) {
324 Log.startSession(sessionInfo, SESSION_ABORT);
325 try {
326 SomeArgs args = SomeArgs.obtain();
327 args.arg1 = callId;
328 args.arg2 = Log.createSubsession();
329 mHandler.obtainMessage(MSG_ABORT, args).sendToTarget();
330 } finally {
331 Log.endSession();
332 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700333 }
334
335 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700336 public void answerVideo(String callId, int videoState, Session.Info sessionInfo) {
337 Log.startSession(sessionInfo, SESSION_ANSWER_VIDEO);
338 try {
339 SomeArgs args = SomeArgs.obtain();
340 args.arg1 = callId;
341 args.arg2 = Log.createSubsession();
342 args.argi1 = videoState;
343 mHandler.obtainMessage(MSG_ANSWER_VIDEO, args).sendToTarget();
344 } finally {
345 Log.endSession();
346 }
Tyler Gunnbe74de02014-08-29 14:51:48 -0700347 }
348
349 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700350 public void answer(String callId, Session.Info sessionInfo) {
351 Log.startSession(sessionInfo, SESSION_ANSWER);
352 try {
353 SomeArgs args = SomeArgs.obtain();
354 args.arg1 = callId;
355 args.arg2 = Log.createSubsession();
356 mHandler.obtainMessage(MSG_ANSWER, args).sendToTarget();
357 } finally {
358 Log.endSession();
359 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700360 }
361
362 @Override
Pooja Jaind34698d2017-12-28 14:15:31 +0530363 public void deflect(String callId, Uri address, Session.Info sessionInfo) {
364 Log.startSession(sessionInfo, SESSION_DEFLECT);
365 try {
366 SomeArgs args = SomeArgs.obtain();
367 args.arg1 = callId;
368 args.arg2 = address;
369 args.arg3 = Log.createSubsession();
370 mHandler.obtainMessage(MSG_DEFLECT, args).sendToTarget();
371 } finally {
372 Log.endSession();
373 }
374 }
375
376 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700377 public void reject(String callId, Session.Info sessionInfo) {
378 Log.startSession(sessionInfo, SESSION_REJECT);
379 try {
380 SomeArgs args = SomeArgs.obtain();
381 args.arg1 = callId;
382 args.arg2 = Log.createSubsession();
383 mHandler.obtainMessage(MSG_REJECT, args).sendToTarget();
384 } finally {
385 Log.endSession();
386 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700387 }
388
389 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700390 public void rejectWithMessage(String callId, String message, Session.Info sessionInfo) {
391 Log.startSession(sessionInfo, SESSION_REJECT_MESSAGE);
392 try {
393 SomeArgs args = SomeArgs.obtain();
394 args.arg1 = callId;
395 args.arg2 = message;
396 args.arg3 = Log.createSubsession();
397 mHandler.obtainMessage(MSG_REJECT_WITH_MESSAGE, args).sendToTarget();
398 } finally {
399 Log.endSession();
400 }
Bryce Lee81901682015-08-28 16:38:02 -0700401 }
402
403 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700404 public void silence(String callId, Session.Info sessionInfo) {
405 Log.startSession(sessionInfo, SESSION_SILENCE);
406 try {
407 SomeArgs args = SomeArgs.obtain();
408 args.arg1 = callId;
409 args.arg2 = Log.createSubsession();
410 mHandler.obtainMessage(MSG_SILENCE, args).sendToTarget();
411 } finally {
412 Log.endSession();
413 }
Bryce Leecac50772015-11-17 15:13:29 -0800414 }
415
416 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700417 public void disconnect(String callId, Session.Info sessionInfo) {
418 Log.startSession(sessionInfo, SESSION_DISCONNECT);
419 try {
420 SomeArgs args = SomeArgs.obtain();
421 args.arg1 = callId;
422 args.arg2 = Log.createSubsession();
423 mHandler.obtainMessage(MSG_DISCONNECT, args).sendToTarget();
424 } finally {
425 Log.endSession();
426 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700427 }
428
429 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700430 public void hold(String callId, Session.Info sessionInfo) {
431 Log.startSession(sessionInfo, SESSION_HOLD);
432 try {
433 SomeArgs args = SomeArgs.obtain();
434 args.arg1 = callId;
435 args.arg2 = Log.createSubsession();
436 mHandler.obtainMessage(MSG_HOLD, args).sendToTarget();
437 } finally {
438 Log.endSession();
439 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700440 }
441
442 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700443 public void unhold(String callId, Session.Info sessionInfo) {
444 Log.startSession(sessionInfo, SESSION_UNHOLD);
445 try {
446 SomeArgs args = SomeArgs.obtain();
447 args.arg1 = callId;
448 args.arg2 = Log.createSubsession();
449 mHandler.obtainMessage(MSG_UNHOLD, args).sendToTarget();
450 } finally {
451 Log.endSession();
452 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700453 }
454
455 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700456 public void onCallAudioStateChanged(String callId, CallAudioState callAudioState,
457 Session.Info sessionInfo) {
458 Log.startSession(sessionInfo, SESSION_CALL_AUDIO_SC);
459 try {
460 SomeArgs args = SomeArgs.obtain();
461 args.arg1 = callId;
462 args.arg2 = callAudioState;
463 args.arg3 = Log.createSubsession();
464 mHandler.obtainMessage(MSG_ON_CALL_AUDIO_STATE_CHANGED, args).sendToTarget();
465 } finally {
466 Log.endSession();
467 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700468 }
469
470 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700471 public void playDtmfTone(String callId, char digit, Session.Info sessionInfo) {
472 Log.startSession(sessionInfo, SESSION_PLAY_DTMF);
473 try {
474 SomeArgs args = SomeArgs.obtain();
475 args.arg1 = digit;
476 args.arg2 = callId;
477 args.arg3 = Log.createSubsession();
478 mHandler.obtainMessage(MSG_PLAY_DTMF_TONE, args).sendToTarget();
479 } finally {
480 Log.endSession();
481 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700482 }
483
484 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700485 public void stopDtmfTone(String callId, Session.Info sessionInfo) {
486 Log.startSession(sessionInfo, SESSION_STOP_DTMF);
487 try {
488 SomeArgs args = SomeArgs.obtain();
489 args.arg1 = callId;
490 args.arg2 = Log.createSubsession();
491 mHandler.obtainMessage(MSG_STOP_DTMF_TONE, args).sendToTarget();
492 } finally {
493 Log.endSession();
494 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700495 }
496
497 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700498 public void conference(String callId1, String callId2, Session.Info sessionInfo) {
499 Log.startSession(sessionInfo, SESSION_CONFERENCE);
500 try {
501 SomeArgs args = SomeArgs.obtain();
502 args.arg1 = callId1;
503 args.arg2 = callId2;
504 args.arg3 = Log.createSubsession();
505 mHandler.obtainMessage(MSG_CONFERENCE, args).sendToTarget();
506 } finally {
507 Log.endSession();
508 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700509 }
510
511 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700512 public void splitFromConference(String callId, Session.Info sessionInfo) {
513 Log.startSession(sessionInfo, SESSION_SPLIT_CONFERENCE);
514 try {
515 SomeArgs args = SomeArgs.obtain();
516 args.arg1 = callId;
517 args.arg2 = Log.createSubsession();
518 mHandler.obtainMessage(MSG_SPLIT_FROM_CONFERENCE, args).sendToTarget();
519 } finally {
520 Log.endSession();
521 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700522 }
523
524 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700525 public void mergeConference(String callId, Session.Info sessionInfo) {
526 Log.startSession(sessionInfo, SESSION_MERGE_CONFERENCE);
527 try {
528 SomeArgs args = SomeArgs.obtain();
529 args.arg1 = callId;
530 args.arg2 = Log.createSubsession();
531 mHandler.obtainMessage(MSG_MERGE_CONFERENCE, args).sendToTarget();
532 } finally {
533 Log.endSession();
534 }
Santos Cordona4868042014-09-04 17:39:22 -0700535 }
536
537 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700538 public void swapConference(String callId, Session.Info sessionInfo) {
539 Log.startSession(sessionInfo, SESSION_SWAP_CONFERENCE);
540 try {
541 SomeArgs args = SomeArgs.obtain();
542 args.arg1 = callId;
543 args.arg2 = Log.createSubsession();
544 mHandler.obtainMessage(MSG_SWAP_CONFERENCE, args).sendToTarget();
545 } finally {
546 Log.endSession();
547 }
Santos Cordona4868042014-09-04 17:39:22 -0700548 }
549
550 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700551 public void onPostDialContinue(String callId, boolean proceed, Session.Info sessionInfo) {
552 Log.startSession(sessionInfo, SESSION_POST_DIAL_CONT);
553 try {
554 SomeArgs args = SomeArgs.obtain();
555 args.arg1 = callId;
556 args.arg2 = Log.createSubsession();
557 args.argi1 = proceed ? 1 : 0;
558 mHandler.obtainMessage(MSG_ON_POST_DIAL_CONTINUE, args).sendToTarget();
559 } finally {
560 Log.endSession();
561 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700562 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700563
564 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700565 public void pullExternalCall(String callId, Session.Info sessionInfo) {
566 Log.startSession(sessionInfo, SESSION_PULL_EXTERNAL_CALL);
567 try {
568 SomeArgs args = SomeArgs.obtain();
569 args.arg1 = callId;
570 args.arg2 = Log.createSubsession();
571 mHandler.obtainMessage(MSG_PULL_EXTERNAL_CALL, args).sendToTarget();
572 } finally {
573 Log.endSession();
574 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700575 }
576
577 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700578 public void sendCallEvent(String callId, String event, Bundle extras,
579 Session.Info sessionInfo) {
580 Log.startSession(sessionInfo, SESSION_SEND_CALL_EVENT);
581 try {
582 SomeArgs args = SomeArgs.obtain();
583 args.arg1 = callId;
584 args.arg2 = event;
585 args.arg3 = extras;
586 args.arg4 = Log.createSubsession();
587 mHandler.obtainMessage(MSG_SEND_CALL_EVENT, args).sendToTarget();
588 } finally {
589 Log.endSession();
590 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700591 }
Tyler Gunndee56a82016-03-23 16:06:34 -0700592
593 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700594 public void onExtrasChanged(String callId, Bundle extras, Session.Info sessionInfo) {
595 Log.startSession(sessionInfo, SESSION_EXTRAS_CHANGED);
596 try {
597 SomeArgs args = SomeArgs.obtain();
598 args.arg1 = callId;
599 args.arg2 = extras;
600 args.arg3 = Log.createSubsession();
601 mHandler.obtainMessage(MSG_ON_EXTRAS_CHANGED, args).sendToTarget();
602 } finally {
603 Log.endSession();
604 }
Tyler Gunndee56a82016-03-23 16:06:34 -0700605 }
Hall Liub64ac4c2017-02-06 10:49:48 -0800606
607 @Override
608 public void startRtt(String callId, ParcelFileDescriptor fromInCall,
609 ParcelFileDescriptor toInCall, Session.Info sessionInfo) throws RemoteException {
610 Log.startSession(sessionInfo, SESSION_START_RTT);
611 try {
612 SomeArgs args = SomeArgs.obtain();
613 args.arg1 = callId;
614 args.arg2 = new Connection.RttTextStream(toInCall, fromInCall);
615 args.arg3 = Log.createSubsession();
616 mHandler.obtainMessage(MSG_ON_START_RTT, args).sendToTarget();
617 } finally {
618 Log.endSession();
619 }
620 }
621
622 @Override
623 public void stopRtt(String callId, Session.Info sessionInfo) throws RemoteException {
624 Log.startSession(sessionInfo, SESSION_STOP_RTT);
625 try {
626 SomeArgs args = SomeArgs.obtain();
627 args.arg1 = callId;
628 args.arg2 = Log.createSubsession();
629 mHandler.obtainMessage(MSG_ON_STOP_RTT, args).sendToTarget();
630 } finally {
631 Log.endSession();
632 }
633 }
634
635 @Override
636 public void respondToRttUpgradeRequest(String callId, ParcelFileDescriptor fromInCall,
637 ParcelFileDescriptor toInCall, Session.Info sessionInfo) throws RemoteException {
638 Log.startSession(sessionInfo, SESSION_RTT_UPGRADE_RESPONSE);
639 try {
640 SomeArgs args = SomeArgs.obtain();
641 args.arg1 = callId;
642 if (toInCall == null || fromInCall == null) {
643 args.arg2 = null;
644 } else {
645 args.arg2 = new Connection.RttTextStream(toInCall, fromInCall);
646 }
647 args.arg3 = Log.createSubsession();
648 mHandler.obtainMessage(MSG_RTT_UPGRADE_RESPONSE, args).sendToTarget();
649 } finally {
650 Log.endSession();
651 }
652 }
Pengquan Meng731c1a32017-11-21 18:01:13 -0800653
654 @Override
655 public void connectionServiceFocusLost(Session.Info sessionInfo) throws RemoteException {
656 Log.startSession(sessionInfo, SESSION_CONNECTION_SERVICE_FOCUS_LOST);
657 try {
658 mHandler.obtainMessage(MSG_CONNECTION_SERVICE_FOCUS_LOST).sendToTarget();
659 } finally {
660 Log.endSession();
661 }
662 }
663
664 @Override
665 public void connectionServiceFocusGained(Session.Info sessionInfo) throws RemoteException {
666 Log.startSession(sessionInfo, SESSION_CONNECTION_SERVICE_FOCUS_GAINED);
667 try {
668 mHandler.obtainMessage(MSG_CONNECTION_SERVICE_FOCUS_GAINED).sendToTarget();
669 } finally {
670 Log.endSession();
671 }
672 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700673 };
674
675 private final Handler mHandler = new Handler(Looper.getMainLooper()) {
676 @Override
677 public void handleMessage(Message msg) {
678 switch (msg.what) {
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700679 case MSG_ADD_CONNECTION_SERVICE_ADAPTER: {
680 SomeArgs args = (SomeArgs) msg.obj;
681 try {
682 IConnectionServiceAdapter adapter = (IConnectionServiceAdapter) args.arg1;
683 Log.continueSession((Session) args.arg2,
684 SESSION_HANDLER + SESSION_ADD_CS_ADAPTER);
685 mAdapter.addAdapter(adapter);
686 onAdapterAttached();
687 } finally {
688 args.recycle();
689 Log.endSession();
690 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700691 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700692 }
693 case MSG_REMOVE_CONNECTION_SERVICE_ADAPTER: {
694 SomeArgs args = (SomeArgs) msg.obj;
695 try {
696 Log.continueSession((Session) args.arg2,
697 SESSION_HANDLER + SESSION_REMOVE_CS_ADAPTER);
698 mAdapter.removeAdapter((IConnectionServiceAdapter) args.arg1);
699 } finally {
700 args.recycle();
701 Log.endSession();
702 }
Ihab Awad8aecfed2014-08-08 17:06:11 -0700703 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700704 }
Ihab Awadf8b69882014-07-25 15:14:01 -0700705 case MSG_CREATE_CONNECTION: {
706 SomeArgs args = (SomeArgs) msg.obj;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700707 Log.continueSession((Session) args.arg4, SESSION_HANDLER + SESSION_CREATE_CONN);
Ihab Awadf8b69882014-07-25 15:14:01 -0700708 try {
Ihab Awad5d0410f2014-07-30 10:07:40 -0700709 final PhoneAccountHandle connectionManagerPhoneAccount =
Ihab Awadf8b69882014-07-25 15:14:01 -0700710 (PhoneAccountHandle) args.arg1;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700711 final String id = (String) args.arg2;
712 final ConnectionRequest request = (ConnectionRequest) args.arg3;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700713 final boolean isIncoming = args.argi1 == 1;
Yorke Leec3cf9822014-10-02 09:38:39 -0700714 final boolean isUnknown = args.argi2 == 1;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700715 if (!mAreAccountsInitialized) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700716 Log.d(this, "Enqueueing pre-init request %s", id);
Brad Ebinger0c3541b2016-11-01 14:11:38 -0700717 mPreInitializationConnectionRequests.add(
718 new android.telecom.Logging.Runnable(
719 SESSION_HANDLER + SESSION_CREATE_CONN + ".pICR",
720 null /*lock*/) {
Ihab Awad5d0410f2014-07-30 10:07:40 -0700721 @Override
Brad Ebinger0c3541b2016-11-01 14:11:38 -0700722 public void loggedRun() {
Ihab Awad5d0410f2014-07-30 10:07:40 -0700723 createConnection(
724 connectionManagerPhoneAccount,
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700725 id,
Ihab Awad5d0410f2014-07-30 10:07:40 -0700726 request,
Yorke Leec3cf9822014-10-02 09:38:39 -0700727 isIncoming,
728 isUnknown);
Ihab Awad5d0410f2014-07-30 10:07:40 -0700729 }
Brad Ebinger0c3541b2016-11-01 14:11:38 -0700730 }.prepare());
Ihab Awad5d0410f2014-07-30 10:07:40 -0700731 } else {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700732 createConnection(
733 connectionManagerPhoneAccount,
734 id,
735 request,
Yorke Leec3cf9822014-10-02 09:38:39 -0700736 isIncoming,
737 isUnknown);
Ihab Awad5d0410f2014-07-30 10:07:40 -0700738 }
Ihab Awadf8b69882014-07-25 15:14:01 -0700739 } finally {
740 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700741 Log.endSession();
Ihab Awadf8b69882014-07-25 15:14:01 -0700742 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700743 break;
Ihab Awadf8b69882014-07-25 15:14:01 -0700744 }
Tyler Gunn041a1fe2017-05-12 10:04:49 -0700745 case MSG_CREATE_CONNECTION_COMPLETE: {
746 SomeArgs args = (SomeArgs) msg.obj;
747 Log.continueSession((Session) args.arg2,
748 SESSION_HANDLER + SESSION_CREATE_CONN_COMPLETE);
749 try {
750 final String id = (String) args.arg1;
751 if (!mAreAccountsInitialized) {
752 Log.d(this, "Enqueueing pre-init request %s", id);
753 mPreInitializationConnectionRequests.add(
754 new android.telecom.Logging.Runnable(
755 SESSION_HANDLER + SESSION_CREATE_CONN_COMPLETE
756 + ".pICR",
757 null /*lock*/) {
758 @Override
759 public void loggedRun() {
760 notifyCreateConnectionComplete(id);
761 }
762 }.prepare());
763 } else {
764 notifyCreateConnectionComplete(id);
765 }
766 } finally {
767 args.recycle();
768 Log.endSession();
769 }
770 break;
771 }
Tyler Gunn44e01912017-01-31 10:49:05 -0800772 case MSG_CREATE_CONNECTION_FAILED: {
773 SomeArgs args = (SomeArgs) msg.obj;
774 Log.continueSession((Session) args.arg3, SESSION_HANDLER +
775 SESSION_CREATE_CONN_FAILED);
776 try {
777 final String id = (String) args.arg1;
778 final ConnectionRequest request = (ConnectionRequest) args.arg2;
779 final boolean isIncoming = args.argi1 == 1;
Tyler Gunn159f35c2017-03-02 09:28:37 -0800780 final PhoneAccountHandle connectionMgrPhoneAccount =
781 (PhoneAccountHandle) args.arg4;
Tyler Gunn44e01912017-01-31 10:49:05 -0800782 if (!mAreAccountsInitialized) {
783 Log.d(this, "Enqueueing pre-init request %s", id);
784 mPreInitializationConnectionRequests.add(
785 new android.telecom.Logging.Runnable(
786 SESSION_HANDLER + SESSION_CREATE_CONN_FAILED + ".pICR",
787 null /*lock*/) {
788 @Override
789 public void loggedRun() {
Tyler Gunn159f35c2017-03-02 09:28:37 -0800790 createConnectionFailed(connectionMgrPhoneAccount, id,
791 request, isIncoming);
Tyler Gunn44e01912017-01-31 10:49:05 -0800792 }
793 }.prepare());
794 } else {
795 Log.i(this, "createConnectionFailed %s", id);
Tyler Gunn159f35c2017-03-02 09:28:37 -0800796 createConnectionFailed(connectionMgrPhoneAccount, id, request,
797 isIncoming);
Tyler Gunn44e01912017-01-31 10:49:05 -0800798 }
799 } finally {
800 args.recycle();
801 Log.endSession();
802 }
803 break;
804 }
Sanket Padawe4cc8ed52017-12-04 16:22:20 -0800805 case MSG_HANDOVER_FAILED: {
806 SomeArgs args = (SomeArgs) msg.obj;
807 Log.continueSession((Session) args.arg3, SESSION_HANDLER +
808 SESSION_HANDOVER_FAILED);
809 try {
810 final String id = (String) args.arg1;
811 final ConnectionRequest request = (ConnectionRequest) args.arg2;
812 final int reason = (int) args.arg4;
813 if (!mAreAccountsInitialized) {
814 Log.d(this, "Enqueueing pre-init request %s", id);
815 mPreInitializationConnectionRequests.add(
816 new android.telecom.Logging.Runnable(
817 SESSION_HANDLER
818 + SESSION_HANDOVER_FAILED + ".pICR",
819 null /*lock*/) {
820 @Override
821 public void loggedRun() {
822 handoverFailed(id, request, reason);
823 }
824 }.prepare());
825 } else {
826 Log.i(this, "createConnectionFailed %s", id);
827 handoverFailed(id, request, reason);
828 }
829 } finally {
830 args.recycle();
831 Log.endSession();
832 }
833 break;
834 }
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700835 case MSG_ABORT: {
836 SomeArgs args = (SomeArgs) msg.obj;
837 Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_ABORT);
838 try {
839 abort((String) args.arg1);
840 } finally {
841 args.recycle();
842 Log.endSession();
843 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700844 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700845 }
846 case MSG_ANSWER: {
847 SomeArgs args = (SomeArgs) msg.obj;
848 Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_ANSWER);
849 try {
850 answer((String) args.arg1);
851 } finally {
852 args.recycle();
853 Log.endSession();
854 }
Tyler Gunnbe74de02014-08-29 14:51:48 -0700855 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700856 }
Tyler Gunnbe74de02014-08-29 14:51:48 -0700857 case MSG_ANSWER_VIDEO: {
Andrew Lee8da4c3c2014-07-16 10:11:42 -0700858 SomeArgs args = (SomeArgs) msg.obj;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700859 Log.continueSession((Session) args.arg2,
860 SESSION_HANDLER + SESSION_ANSWER_VIDEO);
Andrew Lee8da4c3c2014-07-16 10:11:42 -0700861 try {
862 String callId = (String) args.arg1;
Evan Charltonbf11f982014-07-20 22:06:28 -0700863 int videoState = args.argi1;
Tyler Gunnbe74de02014-08-29 14:51:48 -0700864 answerVideo(callId, videoState);
Andrew Lee8da4c3c2014-07-16 10:11:42 -0700865 } finally {
866 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700867 Log.endSession();
Andrew Lee8da4c3c2014-07-16 10:11:42 -0700868 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700869 break;
Andrew Lee8da4c3c2014-07-16 10:11:42 -0700870 }
Pooja Jaind34698d2017-12-28 14:15:31 +0530871 case MSG_DEFLECT: {
872 SomeArgs args = (SomeArgs) msg.obj;
873 Log.continueSession((Session) args.arg3, SESSION_HANDLER + SESSION_DEFLECT);
874 try {
875 deflect((String) args.arg1, (Uri) args.arg2);
876 } finally {
877 args.recycle();
878 Log.endSession();
879 }
880 break;
881 }
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700882 case MSG_REJECT: {
883 SomeArgs args = (SomeArgs) msg.obj;
884 Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_REJECT);
885 try {
886 reject((String) args.arg1);
887 } finally {
888 args.recycle();
889 Log.endSession();
890 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700891 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700892 }
Bryce Lee81901682015-08-28 16:38:02 -0700893 case MSG_REJECT_WITH_MESSAGE: {
894 SomeArgs args = (SomeArgs) msg.obj;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700895 Log.continueSession((Session) args.arg3,
896 SESSION_HANDLER + SESSION_REJECT_MESSAGE);
Bryce Lee81901682015-08-28 16:38:02 -0700897 try {
898 reject((String) args.arg1, (String) args.arg2);
899 } finally {
900 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700901 Log.endSession();
Bryce Lee81901682015-08-28 16:38:02 -0700902 }
903 break;
904 }
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700905 case MSG_DISCONNECT: {
906 SomeArgs args = (SomeArgs) msg.obj;
907 Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_DISCONNECT);
908 try {
909 disconnect((String) args.arg1);
910 } finally {
911 args.recycle();
912 Log.endSession();
913 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700914 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700915 }
916 case MSG_SILENCE: {
917 SomeArgs args = (SomeArgs) msg.obj;
918 Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_SILENCE);
919 try {
920 silence((String) args.arg1);
921 } finally {
922 args.recycle();
923 Log.endSession();
924 }
Bryce Leecac50772015-11-17 15:13:29 -0800925 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700926 }
927 case MSG_HOLD: {
928 SomeArgs args = (SomeArgs) msg.obj;
929 Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_REJECT);
930 try {
931 hold((String) args.arg1);
932 } finally {
933 args.recycle();
934 Log.endSession();
935 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700936 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700937 }
938 case MSG_UNHOLD: {
939 SomeArgs args = (SomeArgs) msg.obj;
940 Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_UNHOLD);
941 try {
942 unhold((String) args.arg1);
943 } finally {
944 args.recycle();
945 Log.endSession();
946 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700947 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700948 }
Yorke Lee4af59352015-05-13 14:14:54 -0700949 case MSG_ON_CALL_AUDIO_STATE_CHANGED: {
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700950 SomeArgs args = (SomeArgs) msg.obj;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700951 Log.continueSession((Session) args.arg3,
952 SESSION_HANDLER + SESSION_CALL_AUDIO_SC);
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700953 try {
954 String callId = (String) args.arg1;
Yorke Lee4af59352015-05-13 14:14:54 -0700955 CallAudioState audioState = (CallAudioState) args.arg2;
956 onCallAudioStateChanged(callId, new CallAudioState(audioState));
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700957 } finally {
958 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700959 Log.endSession();
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700960 }
961 break;
962 }
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700963 case MSG_PLAY_DTMF_TONE: {
964 SomeArgs args = (SomeArgs) msg.obj;
965 try {
966 Log.continueSession((Session) args.arg3,
967 SESSION_HANDLER + SESSION_PLAY_DTMF);
968 playDtmfTone((String) args.arg2, (char) args.arg1);
969 } finally {
970 args.recycle();
971 Log.endSession();
972 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700973 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700974 }
975 case MSG_STOP_DTMF_TONE: {
976 SomeArgs args = (SomeArgs) msg.obj;
977 try {
978 Log.continueSession((Session) args.arg2,
979 SESSION_HANDLER + SESSION_STOP_DTMF);
980 stopDtmfTone((String) args.arg1);
981 } finally {
982 args.recycle();
983 Log.endSession();
984 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700985 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700986 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700987 case MSG_CONFERENCE: {
988 SomeArgs args = (SomeArgs) msg.obj;
989 try {
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700990 Log.continueSession((Session) args.arg3,
991 SESSION_HANDLER + SESSION_CONFERENCE);
Santos Cordon823fd3c2014-08-07 18:35:18 -0700992 String callId1 = (String) args.arg1;
993 String callId2 = (String) args.arg2;
994 conference(callId1, callId2);
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700995 } finally {
996 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700997 Log.endSession();
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700998 }
999 break;
1000 }
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001001 case MSG_SPLIT_FROM_CONFERENCE: {
1002 SomeArgs args = (SomeArgs) msg.obj;
1003 try {
1004 Log.continueSession((Session) args.arg2,
1005 SESSION_HANDLER + SESSION_SPLIT_CONFERENCE);
1006 splitFromConference((String) args.arg1);
1007 } finally {
1008 args.recycle();
1009 Log.endSession();
1010 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001011 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001012 }
1013 case MSG_MERGE_CONFERENCE: {
1014 SomeArgs args = (SomeArgs) msg.obj;
1015 try {
1016 Log.continueSession((Session) args.arg2,
1017 SESSION_HANDLER + SESSION_MERGE_CONFERENCE);
1018 mergeConference((String) args.arg1);
1019 } finally {
1020 args.recycle();
1021 Log.endSession();
1022 }
Santos Cordona4868042014-09-04 17:39:22 -07001023 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001024 }
1025 case MSG_SWAP_CONFERENCE: {
1026 SomeArgs args = (SomeArgs) msg.obj;
1027 try {
1028 Log.continueSession((Session) args.arg2,
1029 SESSION_HANDLER + SESSION_SWAP_CONFERENCE);
1030 swapConference((String) args.arg1);
1031 } finally {
1032 args.recycle();
1033 Log.endSession();
1034 }
Santos Cordona4868042014-09-04 17:39:22 -07001035 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001036 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001037 case MSG_ON_POST_DIAL_CONTINUE: {
1038 SomeArgs args = (SomeArgs) msg.obj;
1039 try {
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001040 Log.continueSession((Session) args.arg2,
1041 SESSION_HANDLER + SESSION_POST_DIAL_CONT);
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001042 String callId = (String) args.arg1;
1043 boolean proceed = (args.argi1 == 1);
1044 onPostDialContinue(callId, proceed);
1045 } finally {
1046 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001047 Log.endSession();
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001048 }
1049 break;
1050 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001051 case MSG_PULL_EXTERNAL_CALL: {
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001052 SomeArgs args = (SomeArgs) msg.obj;
1053 try {
1054 Log.continueSession((Session) args.arg2,
1055 SESSION_HANDLER + SESSION_PULL_EXTERNAL_CALL);
1056 pullExternalCall((String) args.arg1);
1057 } finally {
1058 args.recycle();
1059 Log.endSession();
1060 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001061 break;
1062 }
1063 case MSG_SEND_CALL_EVENT: {
1064 SomeArgs args = (SomeArgs) msg.obj;
1065 try {
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001066 Log.continueSession((Session) args.arg4,
1067 SESSION_HANDLER + SESSION_SEND_CALL_EVENT);
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001068 String callId = (String) args.arg1;
1069 String event = (String) args.arg2;
1070 Bundle extras = (Bundle) args.arg3;
1071 sendCallEvent(callId, event, extras);
1072 } finally {
1073 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001074 Log.endSession();
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001075 }
1076 break;
1077 }
Tyler Gunn79bc1ec2018-01-22 15:17:54 -08001078 case MSG_HANDOVER_COMPLETE: {
1079 SomeArgs args = (SomeArgs) msg.obj;
1080 try {
1081 Log.continueSession((Session) args.arg2,
1082 SESSION_HANDLER + SESSION_HANDOVER_COMPLETE);
1083 String callId = (String) args.arg1;
1084 notifyHandoverComplete(callId);
1085 } finally {
1086 args.recycle();
1087 Log.endSession();
1088 }
1089 break;
1090 }
Tyler Gunndee56a82016-03-23 16:06:34 -07001091 case MSG_ON_EXTRAS_CHANGED: {
1092 SomeArgs args = (SomeArgs) msg.obj;
1093 try {
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001094 Log.continueSession((Session) args.arg3,
1095 SESSION_HANDLER + SESSION_EXTRAS_CHANGED);
Tyler Gunndee56a82016-03-23 16:06:34 -07001096 String callId = (String) args.arg1;
1097 Bundle extras = (Bundle) args.arg2;
1098 handleExtrasChanged(callId, extras);
1099 } finally {
1100 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001101 Log.endSession();
Tyler Gunndee56a82016-03-23 16:06:34 -07001102 }
1103 break;
1104 }
Hall Liub64ac4c2017-02-06 10:49:48 -08001105 case MSG_ON_START_RTT: {
1106 SomeArgs args = (SomeArgs) msg.obj;
1107 try {
1108 Log.continueSession((Session) args.arg3,
1109 SESSION_HANDLER + SESSION_START_RTT);
1110 String callId = (String) args.arg1;
1111 Connection.RttTextStream rttTextStream =
1112 (Connection.RttTextStream) args.arg2;
1113 startRtt(callId, rttTextStream);
1114 } finally {
1115 args.recycle();
1116 Log.endSession();
1117 }
1118 break;
1119 }
1120 case MSG_ON_STOP_RTT: {
1121 SomeArgs args = (SomeArgs) msg.obj;
1122 try {
1123 Log.continueSession((Session) args.arg2,
1124 SESSION_HANDLER + SESSION_STOP_RTT);
1125 String callId = (String) args.arg1;
1126 stopRtt(callId);
1127 } finally {
1128 args.recycle();
1129 Log.endSession();
1130 }
1131 break;
1132 }
1133 case MSG_RTT_UPGRADE_RESPONSE: {
1134 SomeArgs args = (SomeArgs) msg.obj;
1135 try {
1136 Log.continueSession((Session) args.arg3,
1137 SESSION_HANDLER + SESSION_RTT_UPGRADE_RESPONSE);
1138 String callId = (String) args.arg1;
1139 Connection.RttTextStream rttTextStream =
1140 (Connection.RttTextStream) args.arg2;
1141 handleRttUpgradeResponse(callId, rttTextStream);
1142 } finally {
1143 args.recycle();
1144 Log.endSession();
1145 }
1146 break;
1147 }
Pengquan Meng731c1a32017-11-21 18:01:13 -08001148 case MSG_CONNECTION_SERVICE_FOCUS_GAINED:
1149 onConnectionServiceFocusGained();
1150 break;
1151 case MSG_CONNECTION_SERVICE_FOCUS_LOST:
1152 onConnectionServiceFocusLost();
1153 break;
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001154 default:
1155 break;
1156 }
1157 }
1158 };
1159
Santos Cordon823fd3c2014-08-07 18:35:18 -07001160 private final Conference.Listener mConferenceListener = new Conference.Listener() {
1161 @Override
1162 public void onStateChanged(Conference conference, int oldState, int newState) {
1163 String id = mIdByConference.get(conference);
1164 switch (newState) {
1165 case Connection.STATE_ACTIVE:
1166 mAdapter.setActive(id);
1167 break;
1168 case Connection.STATE_HOLDING:
1169 mAdapter.setOnHold(id);
1170 break;
1171 case Connection.STATE_DISCONNECTED:
1172 // handled by onDisconnected
1173 break;
1174 }
1175 }
1176
1177 @Override
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001178 public void onDisconnected(Conference conference, DisconnectCause disconnectCause) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07001179 String id = mIdByConference.get(conference);
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001180 mAdapter.setDisconnected(id, disconnectCause);
Santos Cordon823fd3c2014-08-07 18:35:18 -07001181 }
1182
1183 @Override
1184 public void onConnectionAdded(Conference conference, Connection connection) {
1185 }
1186
1187 @Override
1188 public void onConnectionRemoved(Conference conference, Connection connection) {
1189 }
1190
1191 @Override
Ihab Awad50e35062014-09-30 09:17:03 -07001192 public void onConferenceableConnectionsChanged(
1193 Conference conference, List<Connection> conferenceableConnections) {
1194 mAdapter.setConferenceableConnections(
1195 mIdByConference.get(conference),
1196 createConnectionIdList(conferenceableConnections));
1197 }
1198
1199 @Override
Santos Cordon823fd3c2014-08-07 18:35:18 -07001200 public void onDestroyed(Conference conference) {
1201 removeConference(conference);
1202 }
1203
1204 @Override
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001205 public void onConnectionCapabilitiesChanged(
1206 Conference conference,
1207 int connectionCapabilities) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07001208 String id = mIdByConference.get(conference);
1209 Log.d(this, "call capabilities: conference: %s",
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001210 Connection.capabilitiesToString(connectionCapabilities));
1211 mAdapter.setConnectionCapabilities(id, connectionCapabilities);
Santos Cordon823fd3c2014-08-07 18:35:18 -07001212 }
Rekha Kumar07366812015-03-24 16:42:31 -07001213
1214 @Override
Tyler Gunn720c6642016-03-22 09:02:47 -07001215 public void onConnectionPropertiesChanged(
1216 Conference conference,
1217 int connectionProperties) {
1218 String id = mIdByConference.get(conference);
1219 Log.d(this, "call capabilities: conference: %s",
1220 Connection.propertiesToString(connectionProperties));
1221 mAdapter.setConnectionProperties(id, connectionProperties);
1222 }
1223
1224 @Override
Rekha Kumar07366812015-03-24 16:42:31 -07001225 public void onVideoStateChanged(Conference c, int videoState) {
1226 String id = mIdByConference.get(c);
1227 Log.d(this, "onVideoStateChanged set video state %d", videoState);
1228 mAdapter.setVideoState(id, videoState);
1229 }
1230
1231 @Override
1232 public void onVideoProviderChanged(Conference c, Connection.VideoProvider videoProvider) {
1233 String id = mIdByConference.get(c);
1234 Log.d(this, "onVideoProviderChanged: Connection: %s, VideoProvider: %s", c,
1235 videoProvider);
1236 mAdapter.setVideoProvider(id, videoProvider);
1237 }
Andrew Lee0f51da32015-04-16 13:11:55 -07001238
1239 @Override
Andrew Leeedc625f2015-04-14 13:38:12 -07001240 public void onStatusHintsChanged(Conference conference, StatusHints statusHints) {
1241 String id = mIdByConference.get(conference);
Tyler Gunndee56a82016-03-23 16:06:34 -07001242 if (id != null) {
1243 mAdapter.setStatusHints(id, statusHints);
1244 }
Andrew Leeedc625f2015-04-14 13:38:12 -07001245 }
Santos Cordon6b7f9552015-05-27 17:21:45 -07001246
1247 @Override
Tyler Gunndee56a82016-03-23 16:06:34 -07001248 public void onExtrasChanged(Conference c, Bundle extras) {
1249 String id = mIdByConference.get(c);
1250 if (id != null) {
1251 mAdapter.putExtras(id, extras);
1252 }
1253 }
1254
1255 @Override
1256 public void onExtrasRemoved(Conference c, List<String> keys) {
1257 String id = mIdByConference.get(c);
1258 if (id != null) {
1259 mAdapter.removeExtras(id, keys);
1260 }
Santos Cordon6b7f9552015-05-27 17:21:45 -07001261 }
Tyler Gunn68a73a42018-10-03 15:38:57 -07001262
1263 @Override
1264 public void onConferenceStateChanged(Conference c, boolean isConference) {
1265 String id = mIdByConference.get(c);
1266 if (id != null) {
1267 mAdapter.setConferenceState(id, isConference);
1268 }
1269 }
1270
1271 @Override
1272 public void onAddressChanged(Conference c, Uri newAddress, int presentation) {
1273 String id = mIdByConference.get(c);
1274 if (id != null) {
1275 mAdapter.setAddress(id, newAddress, presentation);
1276 }
1277 }
1278
1279 @Override
1280 public void onCallerDisplayNameChanged(Conference c, String callerDisplayName,
1281 int presentation) {
1282 String id = mIdByConference.get(c);
1283 if (id != null) {
1284 mAdapter.setCallerDisplayName(id, callerDisplayName, presentation);
1285 }
1286 }
Hall Liuc9bc1c62019-04-16 14:00:55 -07001287
1288 @Override
1289 public void onConnectionEvent(Conference c, String event, Bundle extras) {
1290 String id = mIdByConference.get(c);
1291 if (id != null) {
1292 mAdapter.onConnectionEvent(id, event, extras);
1293 }
1294 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07001295 };
1296
Ihab Awad542e0ea2014-05-16 10:22:16 -07001297 private final Connection.Listener mConnectionListener = new Connection.Listener() {
1298 @Override
1299 public void onStateChanged(Connection c, int state) {
1300 String id = mIdByConnection.get(c);
Ihab Awad42b30e12014-05-22 09:49:34 -07001301 Log.d(this, "Adapter set state %s %s", id, Connection.stateToString(state));
Ihab Awad542e0ea2014-05-16 10:22:16 -07001302 switch (state) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001303 case Connection.STATE_ACTIVE:
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001304 mAdapter.setActive(id);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001305 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001306 case Connection.STATE_DIALING:
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001307 mAdapter.setDialing(id);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001308 break;
Tyler Gunnc96b5e02016-07-07 22:53:57 -07001309 case Connection.STATE_PULLING_CALL:
1310 mAdapter.setPulling(id);
1311 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001312 case Connection.STATE_DISCONNECTED:
Ihab Awad542e0ea2014-05-16 10:22:16 -07001313 // Handled in onDisconnected()
1314 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001315 case Connection.STATE_HOLDING:
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001316 mAdapter.setOnHold(id);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001317 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001318 case Connection.STATE_NEW:
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001319 // Nothing to tell Telecom
Ihab Awad542e0ea2014-05-16 10:22:16 -07001320 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001321 case Connection.STATE_RINGING:
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001322 mAdapter.setRinging(id);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001323 break;
1324 }
1325 }
1326
1327 @Override
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001328 public void onDisconnected(Connection c, DisconnectCause disconnectCause) {
Ihab Awad542e0ea2014-05-16 10:22:16 -07001329 String id = mIdByConnection.get(c);
Andrew Lee26786392014-09-16 18:14:59 -07001330 Log.d(this, "Adapter set disconnected %s", disconnectCause);
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001331 mAdapter.setDisconnected(id, disconnectCause);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001332 }
1333
1334 @Override
Tyler Gunnaa07df82014-07-17 07:50:22 -07001335 public void onVideoStateChanged(Connection c, int videoState) {
1336 String id = mIdByConnection.get(c);
1337 Log.d(this, "Adapter set video state %d", videoState);
1338 mAdapter.setVideoState(id, videoState);
1339 }
1340
1341 @Override
Andrew Lee100e2932014-09-08 15:34:24 -07001342 public void onAddressChanged(Connection c, Uri address, int presentation) {
Sailesh Nepal61203862014-07-11 14:50:13 -07001343 String id = mIdByConnection.get(c);
Andrew Lee100e2932014-09-08 15:34:24 -07001344 mAdapter.setAddress(id, address, presentation);
Sailesh Nepal61203862014-07-11 14:50:13 -07001345 }
1346
1347 @Override
1348 public void onCallerDisplayNameChanged(
1349 Connection c, String callerDisplayName, int presentation) {
1350 String id = mIdByConnection.get(c);
1351 mAdapter.setCallerDisplayName(id, callerDisplayName, presentation);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001352 }
1353
1354 @Override
Ihab Awad542e0ea2014-05-16 10:22:16 -07001355 public void onDestroyed(Connection c) {
1356 removeConnection(c);
1357 }
Ihab Awadf8358972014-05-28 16:46:42 -07001358
1359 @Override
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001360 public void onPostDialWait(Connection c, String remaining) {
Sailesh Nepal091768c2014-06-30 15:15:23 -07001361 String id = mIdByConnection.get(c);
1362 Log.d(this, "Adapter onPostDialWait %s, %s", c, remaining);
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001363 mAdapter.onPostDialWait(id, remaining);
Sailesh Nepal091768c2014-06-30 15:15:23 -07001364 }
1365
1366 @Override
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001367 public void onPostDialChar(Connection c, char nextChar) {
1368 String id = mIdByConnection.get(c);
1369 Log.d(this, "Adapter onPostDialChar %s, %s", c, nextChar);
1370 mAdapter.onPostDialChar(id, nextChar);
1371 }
1372
1373 @Override
Andrew Lee100e2932014-09-08 15:34:24 -07001374 public void onRingbackRequested(Connection c, boolean ringback) {
Ihab Awadf8358972014-05-28 16:46:42 -07001375 String id = mIdByConnection.get(c);
1376 Log.d(this, "Adapter onRingback %b", ringback);
Andrew Lee100e2932014-09-08 15:34:24 -07001377 mAdapter.setRingbackRequested(id, ringback);
Ihab Awadf8358972014-05-28 16:46:42 -07001378 }
Santos Cordonb6939982014-06-04 20:20:58 -07001379
1380 @Override
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001381 public void onConnectionCapabilitiesChanged(Connection c, int capabilities) {
Santos Cordonb6939982014-06-04 20:20:58 -07001382 String id = mIdByConnection.get(c);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001383 Log.d(this, "capabilities: parcelableconnection: %s",
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001384 Connection.capabilitiesToString(capabilities));
1385 mAdapter.setConnectionCapabilities(id, capabilities);
Santos Cordonb6939982014-06-04 20:20:58 -07001386 }
1387
Santos Cordonb6939982014-06-04 20:20:58 -07001388 @Override
Tyler Gunn720c6642016-03-22 09:02:47 -07001389 public void onConnectionPropertiesChanged(Connection c, int properties) {
1390 String id = mIdByConnection.get(c);
1391 Log.d(this, "properties: parcelableconnection: %s",
1392 Connection.propertiesToString(properties));
1393 mAdapter.setConnectionProperties(id, properties);
1394 }
1395
1396 @Override
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001397 public void onVideoProviderChanged(Connection c, Connection.VideoProvider videoProvider) {
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07001398 String id = mIdByConnection.get(c);
Rekha Kumar07366812015-03-24 16:42:31 -07001399 Log.d(this, "onVideoProviderChanged: Connection: %s, VideoProvider: %s", c,
1400 videoProvider);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001401 mAdapter.setVideoProvider(id, videoProvider);
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07001402 }
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001403
1404 @Override
Sailesh Nepal001bbbb2014-07-15 14:40:39 -07001405 public void onAudioModeIsVoipChanged(Connection c, boolean isVoip) {
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001406 String id = mIdByConnection.get(c);
Andrew Lee100e2932014-09-08 15:34:24 -07001407 mAdapter.setIsVoipAudioMode(id, isVoip);
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001408 }
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001409
1410 @Override
Sailesh Nepal001bbbb2014-07-15 14:40:39 -07001411 public void onStatusHintsChanged(Connection c, StatusHints statusHints) {
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001412 String id = mIdByConnection.get(c);
1413 mAdapter.setStatusHints(id, statusHints);
1414 }
Sailesh Nepal2ab88cc2014-07-18 14:49:18 -07001415
1416 @Override
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001417 public void onConferenceablesChanged(
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001418 Connection connection, List<Conferenceable> conferenceables) {
Ihab Awadb8e85c72014-08-23 20:34:57 -07001419 mAdapter.setConferenceableConnections(
1420 mIdByConnection.get(connection),
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001421 createIdList(conferenceables));
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001422 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07001423
1424 @Override
1425 public void onConferenceChanged(Connection connection, Conference conference) {
1426 String id = mIdByConnection.get(connection);
1427 if (id != null) {
1428 String conferenceId = null;
1429 if (conference != null) {
1430 conferenceId = mIdByConference.get(conference);
1431 }
1432 mAdapter.setIsConferenced(id, conferenceId);
1433 }
1434 }
Anthony Lee17455a32015-04-24 15:25:29 -07001435
1436 @Override
1437 public void onConferenceMergeFailed(Connection connection) {
1438 String id = mIdByConnection.get(connection);
1439 if (id != null) {
1440 mAdapter.onConferenceMergeFailed(id);
1441 }
1442 }
Santos Cordon6b7f9552015-05-27 17:21:45 -07001443
1444 @Override
Tyler Gunndee56a82016-03-23 16:06:34 -07001445 public void onExtrasChanged(Connection c, Bundle extras) {
1446 String id = mIdByConnection.get(c);
Santos Cordon6b7f9552015-05-27 17:21:45 -07001447 if (id != null) {
Tyler Gunndee56a82016-03-23 16:06:34 -07001448 mAdapter.putExtras(id, extras);
Santos Cordon6b7f9552015-05-27 17:21:45 -07001449 }
1450 }
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001451
Tyler Gunnf5035432017-01-09 09:43:12 -08001452 @Override
Tyler Gunndee56a82016-03-23 16:06:34 -07001453 public void onExtrasRemoved(Connection c, List<String> keys) {
1454 String id = mIdByConnection.get(c);
1455 if (id != null) {
1456 mAdapter.removeExtras(id, keys);
1457 }
1458 }
1459
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08001460 @Override
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001461 public void onConnectionEvent(Connection connection, String event, Bundle extras) {
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08001462 String id = mIdByConnection.get(connection);
1463 if (id != null) {
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001464 mAdapter.onConnectionEvent(id, event, extras);
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08001465 }
1466 }
Tyler Gunnf5035432017-01-09 09:43:12 -08001467
1468 @Override
Hall Liua98f58b52017-11-07 17:59:28 -08001469 public void onAudioRouteChanged(Connection c, int audioRoute, String bluetoothAddress) {
Tyler Gunnf5035432017-01-09 09:43:12 -08001470 String id = mIdByConnection.get(c);
1471 if (id != null) {
Hall Liua98f58b52017-11-07 17:59:28 -08001472 mAdapter.setAudioRoute(id, audioRoute, bluetoothAddress);
Tyler Gunnf5035432017-01-09 09:43:12 -08001473 }
1474 }
Hall Liub64ac4c2017-02-06 10:49:48 -08001475
1476 @Override
1477 public void onRttInitiationSuccess(Connection c) {
1478 String id = mIdByConnection.get(c);
1479 if (id != null) {
1480 mAdapter.onRttInitiationSuccess(id);
1481 }
1482 }
1483
1484 @Override
1485 public void onRttInitiationFailure(Connection c, int reason) {
1486 String id = mIdByConnection.get(c);
1487 if (id != null) {
1488 mAdapter.onRttInitiationFailure(id, reason);
1489 }
1490 }
1491
1492 @Override
1493 public void onRttSessionRemotelyTerminated(Connection c) {
1494 String id = mIdByConnection.get(c);
1495 if (id != null) {
1496 mAdapter.onRttSessionRemotelyTerminated(id);
1497 }
1498 }
1499
1500 @Override
1501 public void onRemoteRttRequest(Connection c) {
1502 String id = mIdByConnection.get(c);
1503 if (id != null) {
1504 mAdapter.onRemoteRttRequest(id);
1505 }
1506 }
Srikanth Chintalafcb15012017-05-04 20:58:34 +05301507
1508 @Override
1509 public void onPhoneAccountChanged(Connection c, PhoneAccountHandle pHandle) {
1510 String id = mIdByConnection.get(c);
1511 if (id != null) {
1512 mAdapter.onPhoneAccountChanged(id, pHandle);
1513 }
1514 }
Mengjun Leng25707742017-07-04 11:10:37 +08001515
1516 public void onConnectionTimeReset(Connection c) {
1517 String id = mIdByConnection.get(c);
1518 if (id != null) {
1519 mAdapter.resetConnectionTime(id);
1520 }
1521 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001522 };
1523
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001524 /** {@inheritDoc} */
Ihab Awad542e0ea2014-05-16 10:22:16 -07001525 @Override
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001526 public final IBinder onBind(Intent intent) {
1527 return mBinder;
1528 }
1529
Santos Cordon29f2f2e2014-09-11 19:50:24 -07001530 /** {@inheritDoc} */
1531 @Override
1532 public boolean onUnbind(Intent intent) {
1533 endAllConnections();
1534 return super.onUnbind(intent);
1535 }
1536
Sailesh Nepalc5b01572014-07-14 16:29:44 -07001537 /**
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001538 * This can be used by telecom to either create a new outgoing call or attach to an existing
1539 * incoming call. In either case, telecom will cycle through a set of services and call
Sailesh Nepalc5b01572014-07-14 16:29:44 -07001540 * createConnection util a connection service cancels the process or completes it successfully.
1541 */
Ihab Awadf8b69882014-07-25 15:14:01 -07001542 private void createConnection(
1543 final PhoneAccountHandle callManagerAccount,
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001544 final String callId,
Ihab Awadf8b69882014-07-25 15:14:01 -07001545 final ConnectionRequest request,
Yorke Leec3cf9822014-10-02 09:38:39 -07001546 boolean isIncoming,
1547 boolean isUnknown) {
Tyler Gunn79bc1ec2018-01-22 15:17:54 -08001548 boolean isLegacyHandover = request.getExtras() != null &&
1549 request.getExtras().getBoolean(TelecomManager.EXTRA_IS_HANDOVER, false);
1550 boolean isHandover = request.getExtras() != null && request.getExtras().getBoolean(
1551 TelecomManager.EXTRA_IS_HANDOVER_CONNECTION, false);
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001552 Log.d(this, "createConnection, callManagerAccount: %s, callId: %s, request: %s, " +
Tyler Gunn79bc1ec2018-01-22 15:17:54 -08001553 "isIncoming: %b, isUnknown: %b, isLegacyHandover: %b, isHandover: %b",
1554 callManagerAccount, callId, request, isIncoming, isUnknown, isLegacyHandover,
1555 isHandover);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001556
Sanket Padawee29a2662017-12-01 13:59:27 -08001557 Connection connection = null;
Tyler Gunn79bc1ec2018-01-22 15:17:54 -08001558 if (isHandover) {
1559 PhoneAccountHandle fromPhoneAccountHandle = request.getExtras() != null
1560 ? (PhoneAccountHandle) request.getExtras().getParcelable(
1561 TelecomManager.EXTRA_HANDOVER_FROM_PHONE_ACCOUNT) : null;
Sanket Padawee29a2662017-12-01 13:59:27 -08001562 if (!isIncoming) {
Tyler Gunn79bc1ec2018-01-22 15:17:54 -08001563 connection = onCreateOutgoingHandoverConnection(fromPhoneAccountHandle, request);
Sanket Padawee29a2662017-12-01 13:59:27 -08001564 } else {
Tyler Gunn79bc1ec2018-01-22 15:17:54 -08001565 connection = onCreateIncomingHandoverConnection(fromPhoneAccountHandle, request);
Sanket Padawee29a2662017-12-01 13:59:27 -08001566 }
1567 } else {
1568 connection = isUnknown ? onCreateUnknownConnection(callManagerAccount, request)
1569 : isIncoming ? onCreateIncomingConnection(callManagerAccount, request)
1570 : onCreateOutgoingConnection(callManagerAccount, request);
1571 }
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001572 Log.d(this, "createConnection, connection: %s", connection);
1573 if (connection == null) {
Tyler Gunnfba1a8e2017-12-19 15:23:59 -08001574 Log.i(this, "createConnection, implementation returned null connection.");
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001575 connection = Connection.createFailedConnection(
Tyler Gunnfba1a8e2017-12-19 15:23:59 -08001576 new DisconnectCause(DisconnectCause.ERROR, "IMPL_RETURNED_NULL_CONNECTION"));
Sailesh Nepalc5b01572014-07-14 16:29:44 -07001577 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001578
Tyler Gunnf2e08b42018-05-24 10:44:44 -07001579 boolean isSelfManaged =
1580 (connection.getConnectionProperties() & Connection.PROPERTY_SELF_MANAGED)
1581 == Connection.PROPERTY_SELF_MANAGED;
1582 // Self-managed Connections should always use voip audio mode; we default here so that the
1583 // local state within the ConnectionService matches the default we assume in Telecom.
1584 if (isSelfManaged) {
1585 connection.setAudioModeIsVoip(true);
1586 }
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001587 connection.setTelecomCallId(callId);
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001588 if (connection.getState() != Connection.STATE_DISCONNECTED) {
Pengquan Meng70c9885332017-10-02 18:09:03 -07001589 addConnection(request.getAccountHandle(), callId, connection);
Ihab Awad6107bab2014-08-18 09:23:25 -07001590 }
1591
Andrew Lee100e2932014-09-08 15:34:24 -07001592 Uri address = connection.getAddress();
1593 String number = address == null ? "null" : address.getSchemeSpecificPart();
Tyler Gunn720c6642016-03-22 09:02:47 -07001594 Log.v(this, "createConnection, number: %s, state: %s, capabilities: %s, properties: %s",
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001595 Connection.toLogSafePhoneNumber(number),
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001596 Connection.stateToString(connection.getState()),
Tyler Gunn720c6642016-03-22 09:02:47 -07001597 Connection.capabilitiesToString(connection.getConnectionCapabilities()),
1598 Connection.propertiesToString(connection.getConnectionProperties()));
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001599
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001600 Log.d(this, "createConnection, calling handleCreateConnectionSuccessful %s", callId);
Ihab Awad6107bab2014-08-18 09:23:25 -07001601 mAdapter.handleCreateConnectionComplete(
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001602 callId,
Evan Charltonbf11f982014-07-20 22:06:28 -07001603 request,
1604 new ParcelableConnection(
1605 request.getAccountHandle(),
1606 connection.getState(),
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001607 connection.getConnectionCapabilities(),
Tyler Gunn720c6642016-03-22 09:02:47 -07001608 connection.getConnectionProperties(),
Christine Hallstrom2830ce92016-11-30 16:06:42 -08001609 connection.getSupportedAudioRoutes(),
Andrew Lee100e2932014-09-08 15:34:24 -07001610 connection.getAddress(),
1611 connection.getAddressPresentation(),
Evan Charltonbf11f982014-07-20 22:06:28 -07001612 connection.getCallerDisplayName(),
1613 connection.getCallerDisplayNamePresentation(),
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001614 connection.getVideoProvider() == null ?
1615 null : connection.getVideoProvider().getInterface(),
Sailesh Nepal8b9d3ca2014-08-14 17:39:34 -07001616 connection.getVideoState(),
Andrew Lee100e2932014-09-08 15:34:24 -07001617 connection.isRingbackRequested(),
Sailesh Nepal8b9d3ca2014-08-14 17:39:34 -07001618 connection.getAudioModeIsVoip(),
Roshan Piuse927ec02015-07-15 15:47:21 -07001619 connection.getConnectTimeMillis(),
Tyler Gunn3fa819c2017-08-04 09:27:26 -07001620 connection.getConnectElapsedTimeMillis(),
Ihab Awad6107bab2014-08-18 09:23:25 -07001621 connection.getStatusHints(),
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001622 connection.getDisconnectCause(),
Santos Cordon6b7f9552015-05-27 17:21:45 -07001623 createIdList(connection.getConferenceables()),
Tyler Gunnd57d76c2019-09-24 14:53:23 -07001624 connection.getExtras(),
1625 connection.getCallerNumberVerificationStatus()));
Tyler Gunnf5035432017-01-09 09:43:12 -08001626
Tyler Gunnf2e08b42018-05-24 10:44:44 -07001627 if (isIncoming && request.shouldShowIncomingCallUi() && isSelfManaged) {
Tyler Gunnf5035432017-01-09 09:43:12 -08001628 // Tell ConnectionService to show its incoming call UX.
1629 connection.onShowIncomingCallUi();
1630 }
Shriram Ganesh6bf35ac2014-12-11 17:53:38 -08001631 if (isUnknown) {
1632 triggerConferenceRecalculate();
1633 }
Evan Charltonbf11f982014-07-20 22:06:28 -07001634 }
1635
Tyler Gunn159f35c2017-03-02 09:28:37 -08001636 private void createConnectionFailed(final PhoneAccountHandle callManagerAccount,
1637 final String callId, final ConnectionRequest request,
1638 boolean isIncoming) {
Tyler Gunn44e01912017-01-31 10:49:05 -08001639
1640 Log.i(this, "createConnectionFailed %s", callId);
1641 if (isIncoming) {
Tyler Gunn159f35c2017-03-02 09:28:37 -08001642 onCreateIncomingConnectionFailed(callManagerAccount, request);
Tyler Gunn44e01912017-01-31 10:49:05 -08001643 } else {
Tyler Gunn159f35c2017-03-02 09:28:37 -08001644 onCreateOutgoingConnectionFailed(callManagerAccount, request);
Tyler Gunn44e01912017-01-31 10:49:05 -08001645 }
1646 }
1647
Sanket Padawe4cc8ed52017-12-04 16:22:20 -08001648 private void handoverFailed(final String callId, final ConnectionRequest request,
1649 int reason) {
1650
1651 Log.i(this, "handoverFailed %s", callId);
1652 onHandoverFailed(request, reason);
1653 }
1654
Tyler Gunn041a1fe2017-05-12 10:04:49 -07001655 /**
1656 * Called by Telecom when the creation of a new Connection has completed and it is now added
1657 * to Telecom.
1658 * @param callId The ID of the connection.
1659 */
1660 private void notifyCreateConnectionComplete(final String callId) {
1661 Log.i(this, "notifyCreateConnectionComplete %s", callId);
Tyler Gunn0a88f2e2017-06-16 20:20:34 -07001662 if (callId == null) {
1663 // This could happen if the connection fails quickly and is removed from the
1664 // ConnectionService before Telecom sends the create connection complete callback.
1665 Log.w(this, "notifyCreateConnectionComplete: callId is null.");
1666 return;
1667 }
Tyler Gunn041a1fe2017-05-12 10:04:49 -07001668 onCreateConnectionComplete(findConnectionForAction(callId,
1669 "notifyCreateConnectionComplete"));
1670 }
1671
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001672 private void abort(String callId) {
Ihab Awad60ac30b2014-05-20 22:32:12 -07001673 Log.d(this, "abort %s", callId);
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001674 findConnectionForAction(callId, "abort").onAbort();
Ihab Awad542e0ea2014-05-16 10:22:16 -07001675 }
1676
Tyler Gunnbe74de02014-08-29 14:51:48 -07001677 private void answerVideo(String callId, int videoState) {
1678 Log.d(this, "answerVideo %s", callId);
Andrew Lee8da4c3c2014-07-16 10:11:42 -07001679 findConnectionForAction(callId, "answer").onAnswer(videoState);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001680 }
1681
Tyler Gunnbe74de02014-08-29 14:51:48 -07001682 private void answer(String callId) {
1683 Log.d(this, "answer %s", callId);
1684 findConnectionForAction(callId, "answer").onAnswer();
1685 }
1686
Pooja Jaind34698d2017-12-28 14:15:31 +05301687 private void deflect(String callId, Uri address) {
1688 Log.d(this, "deflect %s", callId);
1689 findConnectionForAction(callId, "deflect").onDeflect(address);
1690 }
1691
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001692 private void reject(String callId) {
Ihab Awad60ac30b2014-05-20 22:32:12 -07001693 Log.d(this, "reject %s", callId);
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001694 findConnectionForAction(callId, "reject").onReject();
Ihab Awad542e0ea2014-05-16 10:22:16 -07001695 }
1696
Bryce Lee81901682015-08-28 16:38:02 -07001697 private void reject(String callId, String rejectWithMessage) {
1698 Log.d(this, "reject %s with message", callId);
1699 findConnectionForAction(callId, "reject").onReject(rejectWithMessage);
1700 }
1701
Bryce Leecac50772015-11-17 15:13:29 -08001702 private void silence(String callId) {
1703 Log.d(this, "silence %s", callId);
1704 findConnectionForAction(callId, "silence").onSilence();
1705 }
1706
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001707 private void disconnect(String callId) {
Ihab Awad60ac30b2014-05-20 22:32:12 -07001708 Log.d(this, "disconnect %s", callId);
Santos Cordon0159ac02014-08-21 14:28:11 -07001709 if (mConnectionById.containsKey(callId)) {
1710 findConnectionForAction(callId, "disconnect").onDisconnect();
1711 } else {
1712 findConferenceForAction(callId, "disconnect").onDisconnect();
1713 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001714 }
1715
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001716 private void hold(String callId) {
Ihab Awad60ac30b2014-05-20 22:32:12 -07001717 Log.d(this, "hold %s", callId);
Santos Cordon0159ac02014-08-21 14:28:11 -07001718 if (mConnectionById.containsKey(callId)) {
1719 findConnectionForAction(callId, "hold").onHold();
1720 } else {
1721 findConferenceForAction(callId, "hold").onHold();
1722 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001723 }
1724
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001725 private void unhold(String callId) {
Ihab Awad60ac30b2014-05-20 22:32:12 -07001726 Log.d(this, "unhold %s", callId);
Santos Cordon0159ac02014-08-21 14:28:11 -07001727 if (mConnectionById.containsKey(callId)) {
1728 findConnectionForAction(callId, "unhold").onUnhold();
1729 } else {
1730 findConferenceForAction(callId, "unhold").onUnhold();
1731 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001732 }
1733
Yorke Lee4af59352015-05-13 14:14:54 -07001734 private void onCallAudioStateChanged(String callId, CallAudioState callAudioState) {
1735 Log.d(this, "onAudioStateChanged %s %s", callId, callAudioState);
Yorke Leea0d3ca92014-09-15 19:18:13 -07001736 if (mConnectionById.containsKey(callId)) {
Yorke Lee4af59352015-05-13 14:14:54 -07001737 findConnectionForAction(callId, "onCallAudioStateChanged").setCallAudioState(
1738 callAudioState);
Yorke Leea0d3ca92014-09-15 19:18:13 -07001739 } else {
Yorke Lee4af59352015-05-13 14:14:54 -07001740 findConferenceForAction(callId, "onCallAudioStateChanged").setCallAudioState(
1741 callAudioState);
Yorke Leea0d3ca92014-09-15 19:18:13 -07001742 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001743 }
1744
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001745 private void playDtmfTone(String callId, char digit) {
1746 Log.d(this, "playDtmfTone %s %c", callId, digit);
Yorke Leea0d3ca92014-09-15 19:18:13 -07001747 if (mConnectionById.containsKey(callId)) {
1748 findConnectionForAction(callId, "playDtmfTone").onPlayDtmfTone(digit);
1749 } else {
1750 findConferenceForAction(callId, "playDtmfTone").onPlayDtmfTone(digit);
1751 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001752 }
1753
1754 private void stopDtmfTone(String callId) {
1755 Log.d(this, "stopDtmfTone %s", callId);
Yorke Leea0d3ca92014-09-15 19:18:13 -07001756 if (mConnectionById.containsKey(callId)) {
1757 findConnectionForAction(callId, "stopDtmfTone").onStopDtmfTone();
1758 } else {
1759 findConferenceForAction(callId, "stopDtmfTone").onStopDtmfTone();
1760 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001761 }
1762
Santos Cordon823fd3c2014-08-07 18:35:18 -07001763 private void conference(String callId1, String callId2) {
1764 Log.d(this, "conference %s, %s", callId1, callId2);
Santos Cordon980acb92014-05-31 10:31:19 -07001765
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001766 // Attempt to get second connection or conference.
Santos Cordon823fd3c2014-08-07 18:35:18 -07001767 Connection connection2 = findConnectionForAction(callId2, "conference");
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001768 Conference conference2 = getNullConference();
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001769 if (connection2 == getNullConnection()) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001770 conference2 = findConferenceForAction(callId2, "conference");
1771 if (conference2 == getNullConference()) {
1772 Log.w(this, "Connection2 or Conference2 missing in conference request %s.",
1773 callId2);
1774 return;
1775 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07001776 }
Santos Cordonb6939982014-06-04 20:20:58 -07001777
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001778 // Attempt to get first connection or conference and perform merge.
Ihab Awad50e35062014-09-30 09:17:03 -07001779 Connection connection1 = findConnectionForAction(callId1, "conference");
1780 if (connection1 == getNullConnection()) {
1781 Conference conference1 = findConferenceForAction(callId1, "addConnection");
1782 if (conference1 == getNullConference()) {
1783 Log.w(this,
1784 "Connection1 or Conference1 missing in conference request %s.",
1785 callId1);
1786 } else {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001787 // Call 1 is a conference.
1788 if (connection2 != getNullConnection()) {
1789 // Call 2 is a connection so merge via call 1 (conference).
1790 conference1.onMerge(connection2);
1791 } else {
1792 // Call 2 is ALSO a conference; this should never happen.
1793 Log.wtf(this, "There can only be one conference and an attempt was made to " +
1794 "merge two conferences.");
1795 return;
1796 }
Ihab Awad50e35062014-09-30 09:17:03 -07001797 }
1798 } else {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001799 // Call 1 is a connection.
1800 if (conference2 != getNullConference()) {
1801 // Call 2 is a conference, so merge via call 2.
1802 conference2.onMerge(connection1);
1803 } else {
1804 // Call 2 is a connection, so merge together.
1805 onConference(connection1, connection2);
1806 }
Ihab Awad50e35062014-09-30 09:17:03 -07001807 }
Santos Cordon980acb92014-05-31 10:31:19 -07001808 }
1809
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001810 private void splitFromConference(String callId) {
Santos Cordonb6939982014-06-04 20:20:58 -07001811 Log.d(this, "splitFromConference(%s)", callId);
Santos Cordon980acb92014-05-31 10:31:19 -07001812
1813 Connection connection = findConnectionForAction(callId, "splitFromConference");
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001814 if (connection == getNullConnection()) {
Santos Cordon980acb92014-05-31 10:31:19 -07001815 Log.w(this, "Connection missing in conference request %s.", callId);
1816 return;
1817 }
1818
Santos Cordon0159ac02014-08-21 14:28:11 -07001819 Conference conference = connection.getConference();
1820 if (conference != null) {
1821 conference.onSeparate(connection);
1822 }
Santos Cordon980acb92014-05-31 10:31:19 -07001823 }
1824
Santos Cordona4868042014-09-04 17:39:22 -07001825 private void mergeConference(String callId) {
1826 Log.d(this, "mergeConference(%s)", callId);
1827 Conference conference = findConferenceForAction(callId, "mergeConference");
1828 if (conference != null) {
1829 conference.onMerge();
1830 }
1831 }
1832
1833 private void swapConference(String callId) {
1834 Log.d(this, "swapConference(%s)", callId);
1835 Conference conference = findConferenceForAction(callId, "swapConference");
1836 if (conference != null) {
1837 conference.onSwap();
1838 }
1839 }
1840
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001841 /**
1842 * Notifies a {@link Connection} of a request to pull an external call.
1843 *
1844 * See {@link Call#pullExternalCall()}.
1845 *
1846 * @param callId The ID of the call to pull.
1847 */
1848 private void pullExternalCall(String callId) {
1849 Log.d(this, "pullExternalCall(%s)", callId);
1850 Connection connection = findConnectionForAction(callId, "pullExternalCall");
1851 if (connection != null) {
1852 connection.onPullExternalCall();
1853 }
1854 }
1855
1856 /**
1857 * Notifies a {@link Connection} of a call event.
1858 *
1859 * See {@link Call#sendCallEvent(String, Bundle)}.
1860 *
1861 * @param callId The ID of the call receiving the event.
1862 * @param event The event.
1863 * @param extras Extras associated with the event.
1864 */
1865 private void sendCallEvent(String callId, String event, Bundle extras) {
1866 Log.d(this, "sendCallEvent(%s, %s)", callId, event);
1867 Connection connection = findConnectionForAction(callId, "sendCallEvent");
1868 if (connection != null) {
1869 connection.onCallEvent(event, extras);
1870 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001871 }
1872
Tyler Gunndee56a82016-03-23 16:06:34 -07001873 /**
Tyler Gunn79bc1ec2018-01-22 15:17:54 -08001874 * Notifies a {@link Connection} that a handover has completed.
1875 *
1876 * @param callId The ID of the call which completed handover.
1877 */
1878 private void notifyHandoverComplete(String callId) {
1879 Log.d(this, "notifyHandoverComplete(%s)", callId);
1880 Connection connection = findConnectionForAction(callId, "notifyHandoverComplete");
1881 if (connection != null) {
1882 connection.onHandoverComplete();
1883 }
1884 }
1885
1886 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001887 * Notifies a {@link Connection} or {@link Conference} of a change to the extras from Telecom.
1888 * <p>
1889 * These extra changes can originate from Telecom itself, or from an {@link InCallService} via
1890 * the {@link android.telecom.Call#putExtra(String, boolean)},
1891 * {@link android.telecom.Call#putExtra(String, int)},
1892 * {@link android.telecom.Call#putExtra(String, String)},
1893 * {@link Call#removeExtras(List)}.
1894 *
1895 * @param callId The ID of the call receiving the event.
1896 * @param extras The new extras bundle.
1897 */
1898 private void handleExtrasChanged(String callId, Bundle extras) {
1899 Log.d(this, "handleExtrasChanged(%s, %s)", callId, extras);
1900 if (mConnectionById.containsKey(callId)) {
1901 findConnectionForAction(callId, "handleExtrasChanged").handleExtrasChanged(extras);
1902 } else if (mConferenceById.containsKey(callId)) {
1903 findConferenceForAction(callId, "handleExtrasChanged").handleExtrasChanged(extras);
1904 }
1905 }
1906
Hall Liub64ac4c2017-02-06 10:49:48 -08001907 private void startRtt(String callId, Connection.RttTextStream rttTextStream) {
1908 Log.d(this, "startRtt(%s)", callId);
1909 if (mConnectionById.containsKey(callId)) {
1910 findConnectionForAction(callId, "startRtt").onStartRtt(rttTextStream);
1911 } else if (mConferenceById.containsKey(callId)) {
1912 Log.w(this, "startRtt called on a conference.");
1913 }
1914 }
1915
1916 private void stopRtt(String callId) {
1917 Log.d(this, "stopRtt(%s)", callId);
1918 if (mConnectionById.containsKey(callId)) {
1919 findConnectionForAction(callId, "stopRtt").onStopRtt();
1920 } else if (mConferenceById.containsKey(callId)) {
1921 Log.w(this, "stopRtt called on a conference.");
1922 }
1923 }
1924
1925 private void handleRttUpgradeResponse(String callId, Connection.RttTextStream rttTextStream) {
1926 Log.d(this, "handleRttUpgradeResponse(%s, %s)", callId, rttTextStream == null);
1927 if (mConnectionById.containsKey(callId)) {
1928 findConnectionForAction(callId, "handleRttUpgradeResponse")
1929 .handleRttUpgradeResponse(rttTextStream);
1930 } else if (mConferenceById.containsKey(callId)) {
1931 Log.w(this, "handleRttUpgradeResponse called on a conference.");
1932 }
1933 }
1934
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001935 private void onPostDialContinue(String callId, boolean proceed) {
Evan Charlton6dea4ac2014-06-03 14:07:13 -07001936 Log.d(this, "onPostDialContinue(%s)", callId);
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001937 findConnectionForAction(callId, "stopDtmfTone").onPostDialContinue(proceed);
Evan Charlton6dea4ac2014-06-03 14:07:13 -07001938 }
1939
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001940 private void onAdapterAttached() {
Ihab Awad9c3f1882014-06-30 21:17:13 -07001941 if (mAreAccountsInitialized) {
Santos Cordon52d8a152014-06-17 19:08:45 -07001942 // No need to query again if we already did it.
1943 return;
1944 }
1945
Tyler Gunn4c69fb32019-05-17 10:49:16 -07001946 String callingPackage = getOpPackageName();
1947
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001948 mAdapter.queryRemoteConnectionServices(new RemoteServiceCallback.Stub() {
Santos Cordon52d8a152014-06-17 19:08:45 -07001949 @Override
1950 public void onResult(
1951 final List<ComponentName> componentNames,
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001952 final List<IBinder> services) {
Brad Ebinger0c3541b2016-11-01 14:11:38 -07001953 mHandler.post(new android.telecom.Logging.Runnable("oAA.qRCS.oR", null /*lock*/) {
Ihab Awad6107bab2014-08-18 09:23:25 -07001954 @Override
Brad Ebinger0c3541b2016-11-01 14:11:38 -07001955 public void loggedRun() {
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001956 for (int i = 0; i < componentNames.size() && i < services.size(); i++) {
Santos Cordon52d8a152014-06-17 19:08:45 -07001957 mRemoteConnectionManager.addConnectionService(
1958 componentNames.get(i),
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001959 IConnectionService.Stub.asInterface(services.get(i)));
Santos Cordon52d8a152014-06-17 19:08:45 -07001960 }
Ihab Awad5d0410f2014-07-30 10:07:40 -07001961 onAccountsInitialized();
Sailesh Nepalc5b01572014-07-14 16:29:44 -07001962 Log.d(this, "remote connection services found: " + services);
Santos Cordon52d8a152014-06-17 19:08:45 -07001963 }
Brad Ebinger0c3541b2016-11-01 14:11:38 -07001964 }.prepare());
Santos Cordon52d8a152014-06-17 19:08:45 -07001965 }
1966
1967 @Override
1968 public void onError() {
Brad Ebinger0c3541b2016-11-01 14:11:38 -07001969 mHandler.post(new android.telecom.Logging.Runnable("oAA.qRCS.oE", null /*lock*/) {
Ihab Awad6107bab2014-08-18 09:23:25 -07001970 @Override
Brad Ebinger0c3541b2016-11-01 14:11:38 -07001971 public void loggedRun() {
Ihab Awad9c3f1882014-06-30 21:17:13 -07001972 mAreAccountsInitialized = true;
Santos Cordon52d8a152014-06-17 19:08:45 -07001973 }
Brad Ebinger0c3541b2016-11-01 14:11:38 -07001974 }.prepare());
Santos Cordon52d8a152014-06-17 19:08:45 -07001975 }
Tyler Gunn4c69fb32019-05-17 10:49:16 -07001976 }, callingPackage);
Santos Cordon52d8a152014-06-17 19:08:45 -07001977 }
1978
Ihab Awadf8b69882014-07-25 15:14:01 -07001979 /**
1980 * Ask some other {@code ConnectionService} to create a {@code RemoteConnection} given an
Santos Cordona663f862014-10-29 13:49:58 -07001981 * incoming request. This is used by {@code ConnectionService}s that are registered with
1982 * {@link PhoneAccount#CAPABILITY_CONNECTION_MANAGER} and want to be able to manage
1983 * SIM-based incoming calls.
Ihab Awadf8b69882014-07-25 15:14:01 -07001984 *
1985 * @param connectionManagerPhoneAccount See description at
1986 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
1987 * @param request Details about the incoming call.
1988 * @return The {@code Connection} object to satisfy this call, or {@code null} to
1989 * not handle the call.
1990 */
1991 public final RemoteConnection createRemoteIncomingConnection(
1992 PhoneAccountHandle connectionManagerPhoneAccount,
1993 ConnectionRequest request) {
1994 return mRemoteConnectionManager.createRemoteConnection(
1995 connectionManagerPhoneAccount, request, true);
Santos Cordon52d8a152014-06-17 19:08:45 -07001996 }
1997
1998 /**
Ihab Awadf8b69882014-07-25 15:14:01 -07001999 * Ask some other {@code ConnectionService} to create a {@code RemoteConnection} given an
Santos Cordona663f862014-10-29 13:49:58 -07002000 * outgoing request. This is used by {@code ConnectionService}s that are registered with
2001 * {@link PhoneAccount#CAPABILITY_CONNECTION_MANAGER} and want to be able to use the
2002 * SIM-based {@code ConnectionService} to place its outgoing calls.
Ihab Awadf8b69882014-07-25 15:14:01 -07002003 *
2004 * @param connectionManagerPhoneAccount See description at
2005 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
Cuihtlauac ALVARADO0b3b2a52016-09-13 14:49:41 +02002006 * @param request Details about the outgoing call.
Ihab Awadf8b69882014-07-25 15:14:01 -07002007 * @return The {@code Connection} object to satisfy this call, or {@code null} to
2008 * not handle the call.
2009 */
2010 public final RemoteConnection createRemoteOutgoingConnection(
2011 PhoneAccountHandle connectionManagerPhoneAccount,
2012 ConnectionRequest request) {
2013 return mRemoteConnectionManager.createRemoteConnection(
2014 connectionManagerPhoneAccount, request, false);
2015 }
2016
2017 /**
Santos Cordona663f862014-10-29 13:49:58 -07002018 * Indicates to the relevant {@code RemoteConnectionService} that the specified
2019 * {@link RemoteConnection}s should be merged into a conference call.
2020 * <p>
2021 * If the conference request is successful, the method {@link #onRemoteConferenceAdded} will
2022 * be invoked.
2023 *
2024 * @param remoteConnection1 The first of the remote connections to conference.
2025 * @param remoteConnection2 The second of the remote connections to conference.
Ihab Awadb8e85c72014-08-23 20:34:57 -07002026 */
2027 public final void conferenceRemoteConnections(
Santos Cordona663f862014-10-29 13:49:58 -07002028 RemoteConnection remoteConnection1,
2029 RemoteConnection remoteConnection2) {
2030 mRemoteConnectionManager.conferenceRemoteConnections(remoteConnection1, remoteConnection2);
Ihab Awadb8e85c72014-08-23 20:34:57 -07002031 }
2032
2033 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07002034 * Adds a new conference call. When a conference call is created either as a result of an
2035 * explicit request via {@link #onConference} or otherwise, the connection service should supply
2036 * an instance of {@link Conference} by invoking this method. A conference call provided by this
2037 * method will persist until {@link Conference#destroy} is invoked on the conference instance.
2038 *
2039 * @param conference The new conference object.
2040 */
2041 public final void addConference(Conference conference) {
Rekha Kumar07366812015-03-24 16:42:31 -07002042 Log.d(this, "addConference: conference=%s", conference);
2043
Santos Cordon823fd3c2014-08-07 18:35:18 -07002044 String id = addConferenceInternal(conference);
2045 if (id != null) {
2046 List<String> connectionIds = new ArrayList<>(2);
2047 for (Connection connection : conference.getConnections()) {
2048 if (mIdByConnection.containsKey(connection)) {
2049 connectionIds.add(mIdByConnection.get(connection));
2050 }
2051 }
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002052 conference.setTelecomCallId(id);
Santos Cordon823fd3c2014-08-07 18:35:18 -07002053 ParcelableConference parcelableConference = new ParcelableConference(
Nancy Chenea38cca2014-09-05 16:38:49 -07002054 conference.getPhoneAccountHandle(),
Santos Cordon823fd3c2014-08-07 18:35:18 -07002055 conference.getState(),
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002056 conference.getConnectionCapabilities(),
Tyler Gunn720c6642016-03-22 09:02:47 -07002057 conference.getConnectionProperties(),
Tyler Gunncd5d33c2015-01-12 09:02:01 -08002058 connectionIds,
Rekha Kumar07366812015-03-24 16:42:31 -07002059 conference.getVideoProvider() == null ?
2060 null : conference.getVideoProvider().getInterface(),
2061 conference.getVideoState(),
Andrew Lee3e3e2f22015-04-16 13:48:43 -07002062 conference.getConnectTimeMillis(),
Tyler Gunn17541392018-02-01 08:58:38 -08002063 conference.getConnectionStartElapsedRealTime(),
Santos Cordon6b7f9552015-05-27 17:21:45 -07002064 conference.getStatusHints(),
Tyler Gunnac60f952019-05-31 07:23:16 -07002065 conference.getExtras(),
2066 conference.getAddress(),
2067 conference.getAddressPresentation(),
2068 conference.getCallerDisplayName(),
2069 conference.getCallerDisplayNamePresentation());
Andrew Lee0f51da32015-04-16 13:11:55 -07002070
Santos Cordon823fd3c2014-08-07 18:35:18 -07002071 mAdapter.addConferenceCall(id, parcelableConference);
Rekha Kumar07366812015-03-24 16:42:31 -07002072 mAdapter.setVideoProvider(id, conference.getVideoProvider());
2073 mAdapter.setVideoState(id, conference.getVideoState());
Santos Cordon823fd3c2014-08-07 18:35:18 -07002074
2075 // Go through any child calls and set the parent.
2076 for (Connection connection : conference.getConnections()) {
2077 String connectionId = mIdByConnection.get(connection);
2078 if (connectionId != null) {
2079 mAdapter.setIsConferenced(connectionId, id);
2080 }
2081 }
Pengquan Meng70c9885332017-10-02 18:09:03 -07002082 onConferenceAdded(conference);
Santos Cordon823fd3c2014-08-07 18:35:18 -07002083 }
2084 }
2085
2086 /**
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002087 * Adds a connection created by the {@link ConnectionService} and informs telecom of the new
2088 * connection.
2089 *
2090 * @param phoneAccountHandle The phone account handle for the connection.
2091 * @param connection The connection to add.
2092 */
2093 public final void addExistingConnection(PhoneAccountHandle phoneAccountHandle,
2094 Connection connection) {
Tyler Gunn78da7812017-05-09 14:34:57 -07002095 addExistingConnection(phoneAccountHandle, connection, null /* conference */);
2096 }
2097
2098 /**
Pengquan Meng731c1a32017-11-21 18:01:13 -08002099 * Call to inform Telecom that your {@link ConnectionService} has released call resources (e.g
2100 * microphone, camera).
2101 *
Pengquan Menge3bf7e22018-02-22 17:30:04 -08002102 * <p>
2103 * The {@link ConnectionService} will be disconnected when it failed to call this method within
2104 * 5 seconds after {@link #onConnectionServiceFocusLost()} is called.
2105 *
Pengquan Meng731c1a32017-11-21 18:01:13 -08002106 * @see ConnectionService#onConnectionServiceFocusLost()
2107 */
2108 public final void connectionServiceFocusReleased() {
2109 mAdapter.onConnectionServiceFocusReleased();
2110 }
2111
2112 /**
Tyler Gunn78da7812017-05-09 14:34:57 -07002113 * Adds a connection created by the {@link ConnectionService} and informs telecom of the new
Tyler Gunn5567d742019-10-31 13:04:37 -07002114 * connection, as well as adding that connection to the specified conference.
2115 * <p>
2116 * Note: This API is intended ONLY for use by the Telephony stack to provide an easy way to add
2117 * IMS conference participants to be added to a conference in a single step; this helps ensure
2118 * UI updates happen atomically, rather than adding the connection and then adding it to
2119 * the conference in another step.
Tyler Gunn78da7812017-05-09 14:34:57 -07002120 *
2121 * @param phoneAccountHandle The phone account handle for the connection.
2122 * @param connection The connection to add.
2123 * @param conference The parent conference of the new connection.
2124 * @hide
2125 */
Tyler Gunn5567d742019-10-31 13:04:37 -07002126 @SystemApi
2127 public final void addExistingConnection(@NonNull PhoneAccountHandle phoneAccountHandle,
2128 @NonNull Connection connection, @NonNull Conference conference) {
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002129
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002130 String id = addExistingConnectionInternal(phoneAccountHandle, connection);
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002131 if (id != null) {
2132 List<String> emptyList = new ArrayList<>(0);
Tyler Gunn78da7812017-05-09 14:34:57 -07002133 String conferenceId = null;
2134 if (conference != null) {
2135 conferenceId = mIdByConference.get(conference);
2136 }
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002137
2138 ParcelableConnection parcelableConnection = new ParcelableConnection(
2139 phoneAccountHandle,
2140 connection.getState(),
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002141 connection.getConnectionCapabilities(),
Tyler Gunn720c6642016-03-22 09:02:47 -07002142 connection.getConnectionProperties(),
Christine Hallstrom2830ce92016-11-30 16:06:42 -08002143 connection.getSupportedAudioRoutes(),
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002144 connection.getAddress(),
2145 connection.getAddressPresentation(),
2146 connection.getCallerDisplayName(),
2147 connection.getCallerDisplayNamePresentation(),
2148 connection.getVideoProvider() == null ?
2149 null : connection.getVideoProvider().getInterface(),
2150 connection.getVideoState(),
2151 connection.isRingbackRequested(),
2152 connection.getAudioModeIsVoip(),
Roshan Piuse927ec02015-07-15 15:47:21 -07002153 connection.getConnectTimeMillis(),
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002154 connection.getConnectElapsedTimeMillis(),
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002155 connection.getStatusHints(),
2156 connection.getDisconnectCause(),
Santos Cordon6b7f9552015-05-27 17:21:45 -07002157 emptyList,
Tyler Gunn78da7812017-05-09 14:34:57 -07002158 connection.getExtras(),
Tyler Gunn6986a632019-06-25 13:45:32 -07002159 conferenceId,
Tyler Gunnd57d76c2019-09-24 14:53:23 -07002160 connection.getCallDirection(),
2161 Connection.VERIFICATION_STATUS_NOT_VERIFIED);
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002162 mAdapter.addExistingConnection(id, parcelableConnection);
2163 }
2164 }
2165
2166 /**
Ihab Awadf8b69882014-07-25 15:14:01 -07002167 * Returns all the active {@code Connection}s for which this {@code ConnectionService}
2168 * has taken responsibility.
2169 *
2170 * @return A collection of {@code Connection}s created by this {@code ConnectionService}.
Santos Cordonb6939982014-06-04 20:20:58 -07002171 */
Sailesh Nepal091768c2014-06-30 15:15:23 -07002172 public final Collection<Connection> getAllConnections() {
Santos Cordonb6939982014-06-04 20:20:58 -07002173 return mConnectionById.values();
2174 }
2175
2176 /**
Santos Cordona6018b92016-02-16 14:23:12 -08002177 * Returns all the active {@code Conference}s for which this {@code ConnectionService}
2178 * has taken responsibility.
2179 *
2180 * @return A collection of {@code Conference}s created by this {@code ConnectionService}.
2181 */
2182 public final Collection<Conference> getAllConferences() {
2183 return mConferenceById.values();
2184 }
2185
2186 /**
Ihab Awadf8b69882014-07-25 15:14:01 -07002187 * Create a {@code Connection} given an incoming request. This is used to attach to existing
2188 * incoming calls.
Evan Charltonbf11f982014-07-20 22:06:28 -07002189 *
Ihab Awadf8b69882014-07-25 15:14:01 -07002190 * @param connectionManagerPhoneAccount See description at
2191 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
2192 * @param request Details about the incoming call.
2193 * @return The {@code Connection} object to satisfy this call, or {@code null} to
2194 * not handle the call.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002195 */
Ihab Awadf8b69882014-07-25 15:14:01 -07002196 public Connection onCreateIncomingConnection(
2197 PhoneAccountHandle connectionManagerPhoneAccount,
2198 ConnectionRequest request) {
2199 return null;
2200 }
Sailesh Nepalc5b01572014-07-14 16:29:44 -07002201
2202 /**
Tyler Gunn041a1fe2017-05-12 10:04:49 -07002203 * Called after the {@link Connection} returned by
2204 * {@link #onCreateIncomingConnection(PhoneAccountHandle, ConnectionRequest)}
2205 * or {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)} has been
2206 * added to the {@link ConnectionService} and sent to Telecom.
2207 *
2208 * @param connection the {@link Connection}.
2209 * @hide
2210 */
2211 public void onCreateConnectionComplete(Connection connection) {
2212 }
2213
2214 /**
Tyler Gunnf5035432017-01-09 09:43:12 -08002215 * Called by Telecom to inform the {@link ConnectionService} that its request to create a new
2216 * incoming {@link Connection} was denied.
2217 * <p>
2218 * Used when a self-managed {@link ConnectionService} attempts to create a new incoming
2219 * {@link Connection}, but Telecom has determined that the call cannot be allowed at this time.
2220 * The {@link ConnectionService} is responsible for silently rejecting the new incoming
2221 * {@link Connection}.
2222 * <p>
2223 * See {@link TelecomManager#isIncomingCallPermitted(PhoneAccountHandle)} for more information.
2224 *
Tyler Gunn159f35c2017-03-02 09:28:37 -08002225 * @param connectionManagerPhoneAccount See description at
2226 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
Tyler Gunnf5035432017-01-09 09:43:12 -08002227 * @param request The incoming connection request.
2228 */
Tyler Gunn159f35c2017-03-02 09:28:37 -08002229 public void onCreateIncomingConnectionFailed(PhoneAccountHandle connectionManagerPhoneAccount,
2230 ConnectionRequest request) {
Tyler Gunnf5035432017-01-09 09:43:12 -08002231 }
2232
2233 /**
2234 * Called by Telecom to inform the {@link ConnectionService} that its request to create a new
2235 * outgoing {@link Connection} was denied.
2236 * <p>
2237 * Used when a self-managed {@link ConnectionService} attempts to create a new outgoing
2238 * {@link Connection}, but Telecom has determined that the call cannot be placed at this time.
2239 * The {@link ConnectionService} is responisible for informing the user that the
2240 * {@link Connection} cannot be made at this time.
2241 * <p>
2242 * See {@link TelecomManager#isOutgoingCallPermitted(PhoneAccountHandle)} for more information.
2243 *
Tyler Gunn159f35c2017-03-02 09:28:37 -08002244 * @param connectionManagerPhoneAccount See description at
2245 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
Tyler Gunnf5035432017-01-09 09:43:12 -08002246 * @param request The outgoing connection request.
2247 */
Tyler Gunn159f35c2017-03-02 09:28:37 -08002248 public void onCreateOutgoingConnectionFailed(PhoneAccountHandle connectionManagerPhoneAccount,
2249 ConnectionRequest request) {
Tyler Gunnf5035432017-01-09 09:43:12 -08002250 }
2251
2252 /**
Shriram Ganesh6bf35ac2014-12-11 17:53:38 -08002253 * Trigger recalculate functinality for conference calls. This is used when a Telephony
2254 * Connection is part of a conference controller but is not yet added to Connection
2255 * Service and hence cannot be added to the conference call.
2256 *
2257 * @hide
2258 */
2259 public void triggerConferenceRecalculate() {
2260 }
2261
2262 /**
Ihab Awadf8b69882014-07-25 15:14:01 -07002263 * Create a {@code Connection} given an outgoing request. This is used to initiate new
2264 * outgoing calls.
Sailesh Nepalc5b01572014-07-14 16:29:44 -07002265 *
Ihab Awadf8b69882014-07-25 15:14:01 -07002266 * @param connectionManagerPhoneAccount The connection manager account to use for managing
2267 * this call.
2268 * <p>
2269 * If this parameter is not {@code null}, it means that this {@code ConnectionService}
2270 * has registered one or more {@code PhoneAccount}s having
2271 * {@link PhoneAccount#CAPABILITY_CONNECTION_MANAGER}. This parameter will contain
2272 * one of these {@code PhoneAccount}s, while the {@code request} will contain another
2273 * (usually but not always distinct) {@code PhoneAccount} to be used for actually
2274 * making the connection.
2275 * <p>
2276 * If this parameter is {@code null}, it means that this {@code ConnectionService} is
2277 * being asked to make a direct connection. The
2278 * {@link ConnectionRequest#getAccountHandle()} of parameter {@code request} will be
2279 * a {@code PhoneAccount} registered by this {@code ConnectionService} to use for
2280 * making the connection.
2281 * @param request Details about the outgoing call.
2282 * @return The {@code Connection} object to satisfy this call, or the result of an invocation
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002283 * of {@link Connection#createFailedConnection(DisconnectCause)} to not handle the call.
Sailesh Nepalc5b01572014-07-14 16:29:44 -07002284 */
Ihab Awadf8b69882014-07-25 15:14:01 -07002285 public Connection onCreateOutgoingConnection(
2286 PhoneAccountHandle connectionManagerPhoneAccount,
2287 ConnectionRequest request) {
2288 return null;
2289 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002290
2291 /**
Tyler Gunn9d127732018-03-02 15:45:51 -08002292 * Called by Telecom to request that a {@link ConnectionService} creates an instance of an
2293 * outgoing handover {@link Connection}.
2294 * <p>
2295 * A call handover is the process where an ongoing call is transferred from one app (i.e.
2296 * {@link ConnectionService} to another app. The user could, for example, choose to continue a
2297 * mobile network call in a video calling app. The mobile network call via the Telephony stack
2298 * is referred to as the source of the handover, and the video calling app is referred to as the
2299 * destination.
2300 * <p>
2301 * When considering a handover scenario the <em>initiating</em> device is where a user initiated
2302 * the handover process (e.g. by calling {@link android.telecom.Call#handoverTo(
2303 * PhoneAccountHandle, int, Bundle)}, and the other device is considered the <em>receiving</em>
2304 * device.
2305 * <p>
2306 * This method is called on the destination {@link ConnectionService} on <em>initiating</em>
2307 * device when the user initiates a handover request from one app to another. The user request
2308 * originates in the {@link InCallService} via
2309 * {@link android.telecom.Call#handoverTo(PhoneAccountHandle, int, Bundle)}.
2310 * <p>
2311 * For a full discussion of the handover process and the APIs involved, see
2312 * {@link android.telecom.Call#handoverTo(PhoneAccountHandle, int, Bundle)}.
2313 * <p>
2314 * Implementations of this method should return an instance of {@link Connection} which
2315 * represents the handover. If your app does not wish to accept a handover to it at this time,
2316 * you can return {@code null}. The code below shows an example of how this is done.
2317 * <pre>
2318 * {@code
2319 * public Connection onCreateIncomingHandoverConnection(PhoneAccountHandle
2320 * fromPhoneAccountHandle, ConnectionRequest request) {
2321 * if (!isHandoverAvailable()) {
2322 * return null;
2323 * }
2324 * MyConnection connection = new MyConnection();
2325 * connection.setAddress(request.getAddress(), TelecomManager.PRESENTATION_ALLOWED);
2326 * connection.setVideoState(request.getVideoState());
2327 * return connection;
2328 * }
2329 * }
2330 * </pre>
2331 *
Sanket Padawea8eddd42017-11-03 11:07:35 -07002332 * @param fromPhoneAccountHandle {@link PhoneAccountHandle} associated with the
2333 * ConnectionService which needs to handover the call.
Tyler Gunn9d127732018-03-02 15:45:51 -08002334 * @param request Details about the call to handover.
2335 * @return {@link Connection} instance corresponding to the handover call.
Sanket Padawea8eddd42017-11-03 11:07:35 -07002336 */
2337 public Connection onCreateOutgoingHandoverConnection(PhoneAccountHandle fromPhoneAccountHandle,
2338 ConnectionRequest request) {
2339 return null;
2340 }
2341
2342 /**
Tyler Gunn9d127732018-03-02 15:45:51 -08002343 * Called by Telecom to request that a {@link ConnectionService} creates an instance of an
2344 * incoming handover {@link Connection}.
2345 * <p>
2346 * A call handover is the process where an ongoing call is transferred from one app (i.e.
2347 * {@link ConnectionService} to another app. The user could, for example, choose to continue a
2348 * mobile network call in a video calling app. The mobile network call via the Telephony stack
2349 * is referred to as the source of the handover, and the video calling app is referred to as the
2350 * destination.
2351 * <p>
2352 * When considering a handover scenario the <em>initiating</em> device is where a user initiated
2353 * the handover process (e.g. by calling {@link android.telecom.Call#handoverTo(
2354 * PhoneAccountHandle, int, Bundle)}, and the other device is considered the <em>receiving</em>
2355 * device.
2356 * <p>
2357 * This method is called on the destination app on the <em>receiving</em> device when the
2358 * destination app calls {@link TelecomManager#acceptHandover(Uri, int, PhoneAccountHandle)} to
2359 * accept an incoming handover from the <em>initiating</em> device.
2360 * <p>
2361 * For a full discussion of the handover process and the APIs involved, see
2362 * {@link android.telecom.Call#handoverTo(PhoneAccountHandle, int, Bundle)}.
2363 * <p>
2364 * Implementations of this method should return an instance of {@link Connection} which
2365 * represents the handover. The code below shows an example of how this is done.
2366 * <pre>
2367 * {@code
2368 * public Connection onCreateIncomingHandoverConnection(PhoneAccountHandle
2369 * fromPhoneAccountHandle, ConnectionRequest request) {
2370 * // Given that your app requested to accept the handover, you should not return null here.
2371 * MyConnection connection = new MyConnection();
2372 * connection.setAddress(request.getAddress(), TelecomManager.PRESENTATION_ALLOWED);
2373 * connection.setVideoState(request.getVideoState());
2374 * return connection;
2375 * }
2376 * }
2377 * </pre>
2378 *
Sanket Padawea8eddd42017-11-03 11:07:35 -07002379 * @param fromPhoneAccountHandle {@link PhoneAccountHandle} associated with the
2380 * ConnectionService which needs to handover the call.
2381 * @param request Details about the call which needs to be handover.
Tyler Gunn9d127732018-03-02 15:45:51 -08002382 * @return {@link Connection} instance corresponding to the handover call.
Sanket Padawea8eddd42017-11-03 11:07:35 -07002383 */
2384 public Connection onCreateIncomingHandoverConnection(PhoneAccountHandle fromPhoneAccountHandle,
2385 ConnectionRequest request) {
2386 return null;
2387 }
2388
2389 /**
2390 * Called by Telecom in response to a {@code TelecomManager#acceptHandover()}
2391 * invocation which failed.
Tyler Gunn9d127732018-03-02 15:45:51 -08002392 * <p>
2393 * For a full discussion of the handover process and the APIs involved, see
2394 * {@link android.telecom.Call#handoverTo(PhoneAccountHandle, int, Bundle)}
2395 *
2396 * @param request Details about the call which failed to handover.
2397 * @param error Reason for handover failure. Will be one of the
Sanket Padawea8eddd42017-11-03 11:07:35 -07002398 */
Tyler Gunn9d127732018-03-02 15:45:51 -08002399 public void onHandoverFailed(ConnectionRequest request,
2400 @Call.Callback.HandoverFailureErrors int error) {
Sanket Padawea8eddd42017-11-03 11:07:35 -07002401 return;
2402 }
2403
2404 /**
Yorke Leec3cf9822014-10-02 09:38:39 -07002405 * Create a {@code Connection} for a new unknown call. An unknown call is a call originating
2406 * from the ConnectionService that was neither a user-initiated outgoing call, nor an incoming
2407 * call created using
2408 * {@code TelecomManager#addNewIncomingCall(PhoneAccountHandle, android.os.Bundle)}.
2409 *
Yorke Lee770ed6e2014-10-06 18:58:52 -07002410 * @hide
Yorke Leec3cf9822014-10-02 09:38:39 -07002411 */
2412 public Connection onCreateUnknownConnection(PhoneAccountHandle connectionManagerPhoneAccount,
2413 ConnectionRequest request) {
Brad Ebingerb32d4f82016-10-24 16:40:49 -07002414 return null;
Yorke Leec3cf9822014-10-02 09:38:39 -07002415 }
2416
2417 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07002418 * Conference two specified connections. Invoked when the user has made a request to merge the
2419 * specified connections into a conference call. In response, the connection service should
2420 * create an instance of {@link Conference} and pass it into {@link #addConference}.
Santos Cordonb6939982014-06-04 20:20:58 -07002421 *
Santos Cordon823fd3c2014-08-07 18:35:18 -07002422 * @param connection1 A connection to merge into a conference call.
2423 * @param connection2 A connection to merge into a conference call.
Santos Cordonb6939982014-06-04 20:20:58 -07002424 */
Santos Cordon823fd3c2014-08-07 18:35:18 -07002425 public void onConference(Connection connection1, Connection connection2) {}
Santos Cordonb6939982014-06-04 20:20:58 -07002426
Santos Cordona663f862014-10-29 13:49:58 -07002427 /**
Pengquan Meng70c9885332017-10-02 18:09:03 -07002428 * Called when a connection is added.
2429 * @hide
2430 */
2431 public void onConnectionAdded(Connection connection) {}
2432
2433 /**
2434 * Called when a connection is removed.
2435 * @hide
2436 */
2437 public void onConnectionRemoved(Connection connection) {}
2438
2439 /**
2440 * Called when a conference is added.
2441 * @hide
2442 */
2443 public void onConferenceAdded(Conference conference) {}
2444
2445 /**
2446 * Called when a conference is removed.
2447 * @hide
2448 */
2449 public void onConferenceRemoved(Conference conference) {}
2450
2451 /**
Santos Cordona663f862014-10-29 13:49:58 -07002452 * Indicates that a remote conference has been created for existing {@link RemoteConnection}s.
2453 * When this method is invoked, this {@link ConnectionService} should create its own
2454 * representation of the conference call and send it to telecom using {@link #addConference}.
2455 * <p>
2456 * This is only relevant to {@link ConnectionService}s which are registered with
2457 * {@link PhoneAccount#CAPABILITY_CONNECTION_MANAGER}.
2458 *
2459 * @param conference The remote conference call.
2460 */
Ihab Awadb8e85c72014-08-23 20:34:57 -07002461 public void onRemoteConferenceAdded(RemoteConference conference) {}
2462
Santos Cordon823fd3c2014-08-07 18:35:18 -07002463 /**
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002464 * Called when an existing connection is added remotely.
2465 * @param connection The existing connection which was added.
2466 */
2467 public void onRemoteExistingConnectionAdded(RemoteConnection connection) {}
2468
2469 /**
Pengquan Meng731c1a32017-11-21 18:01:13 -08002470 * Called when the {@link ConnectionService} has lost the call focus.
2471 * The {@link ConnectionService} should release the call resources and invokes
2472 * {@link ConnectionService#connectionServiceFocusReleased()} to inform telecom that it has
2473 * released the call resources.
2474 */
2475 public void onConnectionServiceFocusLost() {}
2476
2477 /**
2478 * Called when the {@link ConnectionService} has gained the call focus. The
2479 * {@link ConnectionService} can acquire the call resources at this time.
2480 */
2481 public void onConnectionServiceFocusGained() {}
2482
2483 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07002484 * @hide
2485 */
2486 public boolean containsConference(Conference conference) {
2487 return mIdByConference.containsKey(conference);
2488 }
2489
Ihab Awadb8e85c72014-08-23 20:34:57 -07002490 /** {@hide} */
2491 void addRemoteConference(RemoteConference remoteConference) {
2492 onRemoteConferenceAdded(remoteConference);
2493 }
2494
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002495 /** {@hide} */
2496 void addRemoteExistingConnection(RemoteConnection remoteConnection) {
2497 onRemoteExistingConnectionAdded(remoteConnection);
2498 }
2499
Ihab Awad5d0410f2014-07-30 10:07:40 -07002500 private void onAccountsInitialized() {
2501 mAreAccountsInitialized = true;
2502 for (Runnable r : mPreInitializationConnectionRequests) {
2503 r.run();
2504 }
2505 mPreInitializationConnectionRequests.clear();
2506 }
2507
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002508 /**
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002509 * Adds an existing connection to the list of connections, identified by a new call ID unique
2510 * to this connection service.
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002511 *
2512 * @param connection The connection.
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002513 * @return The ID of the connection (e.g. the call-id).
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002514 */
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002515 private String addExistingConnectionInternal(PhoneAccountHandle handle, Connection connection) {
2516 String id;
Tyler Gunncd6ccfd2016-10-17 15:48:19 -07002517
2518 if (connection.getExtras() != null && connection.getExtras()
2519 .containsKey(Connection.EXTRA_ORIGINAL_CONNECTION_ID)) {
2520 id = connection.getExtras().getString(Connection.EXTRA_ORIGINAL_CONNECTION_ID);
2521 Log.d(this, "addExistingConnectionInternal - conn %s reusing original id %s",
2522 connection.getTelecomCallId(), id);
2523 } else if (handle == null) {
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002524 // If no phone account handle was provided, we cannot be sure the call ID is unique,
2525 // so just use a random UUID.
2526 id = UUID.randomUUID().toString();
2527 } else {
2528 // Phone account handle was provided, so use the ConnectionService class name as a
2529 // prefix for a unique incremental call ID.
2530 id = handle.getComponentName().getClassName() + "@" + getNextCallId();
2531 }
Pengquan Meng70c9885332017-10-02 18:09:03 -07002532 addConnection(handle, id, connection);
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002533 return id;
2534 }
2535
Pengquan Meng70c9885332017-10-02 18:09:03 -07002536 private void addConnection(PhoneAccountHandle handle, String callId, Connection connection) {
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002537 connection.setTelecomCallId(callId);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002538 mConnectionById.put(callId, connection);
2539 mIdByConnection.put(connection, callId);
2540 connection.addConnectionListener(mConnectionListener);
Santos Cordon823fd3c2014-08-07 18:35:18 -07002541 connection.setConnectionService(this);
Pengquan Meng70c9885332017-10-02 18:09:03 -07002542 connection.setPhoneAccountHandle(handle);
2543 onConnectionAdded(connection);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002544 }
2545
Anthony Lee30e65842014-11-06 16:30:53 -08002546 /** {@hide} */
2547 protected void removeConnection(Connection connection) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07002548 connection.unsetConnectionService(this);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002549 connection.removeConnectionListener(mConnectionListener);
Chenjie Luoe370b532016-05-12 16:59:43 -07002550 String id = mIdByConnection.get(connection);
2551 if (id != null) {
2552 mConnectionById.remove(id);
2553 mIdByConnection.remove(connection);
2554 mAdapter.removeCall(id);
Pengquan Meng70c9885332017-10-02 18:09:03 -07002555 onConnectionRemoved(connection);
Chenjie Luoe370b532016-05-12 16:59:43 -07002556 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002557 }
2558
Santos Cordon823fd3c2014-08-07 18:35:18 -07002559 private String addConferenceInternal(Conference conference) {
Tyler Gunncd6ccfd2016-10-17 15:48:19 -07002560 String originalId = null;
2561 if (conference.getExtras() != null && conference.getExtras()
2562 .containsKey(Connection.EXTRA_ORIGINAL_CONNECTION_ID)) {
2563 originalId = conference.getExtras().getString(Connection.EXTRA_ORIGINAL_CONNECTION_ID);
2564 Log.d(this, "addConferenceInternal: conf %s reusing original id %s",
2565 conference.getTelecomCallId(),
2566 originalId);
2567 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07002568 if (mIdByConference.containsKey(conference)) {
2569 Log.w(this, "Re-adding an existing conference: %s.", conference);
2570 } else if (conference != null) {
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002571 // Conferences do not (yet) have a PhoneAccountHandle associated with them, so we
2572 // cannot determine a ConnectionService class name to associate with the ID, so use
2573 // a unique UUID (for now).
Tyler Gunncd6ccfd2016-10-17 15:48:19 -07002574 String id = originalId == null ? UUID.randomUUID().toString() : originalId;
Santos Cordon823fd3c2014-08-07 18:35:18 -07002575 mConferenceById.put(id, conference);
2576 mIdByConference.put(conference, id);
2577 conference.addListener(mConferenceListener);
2578 return id;
2579 }
2580
2581 return null;
2582 }
2583
2584 private void removeConference(Conference conference) {
2585 if (mIdByConference.containsKey(conference)) {
2586 conference.removeListener(mConferenceListener);
2587
2588 String id = mIdByConference.get(conference);
2589 mConferenceById.remove(id);
2590 mIdByConference.remove(conference);
2591 mAdapter.removeCall(id);
Pengquan Meng70c9885332017-10-02 18:09:03 -07002592
2593 onConferenceRemoved(conference);
Santos Cordon823fd3c2014-08-07 18:35:18 -07002594 }
2595 }
2596
Ihab Awad542e0ea2014-05-16 10:22:16 -07002597 private Connection findConnectionForAction(String callId, String action) {
Tyler Gunn0a88f2e2017-06-16 20:20:34 -07002598 if (callId != null && mConnectionById.containsKey(callId)) {
Ihab Awad542e0ea2014-05-16 10:22:16 -07002599 return mConnectionById.get(callId);
2600 }
Ihab Awad60ac30b2014-05-20 22:32:12 -07002601 Log.w(this, "%s - Cannot find Connection %s", action, callId);
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07002602 return getNullConnection();
2603 }
2604
2605 static synchronized Connection getNullConnection() {
2606 if (sNullConnection == null) {
2607 sNullConnection = new Connection() {};
2608 }
2609 return sNullConnection;
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002610 }
Santos Cordon0159ac02014-08-21 14:28:11 -07002611
2612 private Conference findConferenceForAction(String conferenceId, String action) {
2613 if (mConferenceById.containsKey(conferenceId)) {
2614 return mConferenceById.get(conferenceId);
2615 }
2616 Log.w(this, "%s - Cannot find conference %s", action, conferenceId);
2617 return getNullConference();
2618 }
2619
Ihab Awadb8e85c72014-08-23 20:34:57 -07002620 private List<String> createConnectionIdList(List<Connection> connections) {
2621 List<String> ids = new ArrayList<>();
2622 for (Connection c : connections) {
2623 if (mIdByConnection.containsKey(c)) {
2624 ids.add(mIdByConnection.get(c));
2625 }
2626 }
2627 Collections.sort(ids);
2628 return ids;
2629 }
2630
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002631 /**
2632 * Builds a list of {@link Connection} and {@link Conference} IDs based on the list of
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002633 * {@link Conferenceable}s passed in.
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002634 *
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002635 * @param conferenceables The {@link Conferenceable} connections and conferences.
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002636 * @return List of string conference and call Ids.
2637 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002638 private List<String> createIdList(List<Conferenceable> conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002639 List<String> ids = new ArrayList<>();
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002640 for (Conferenceable c : conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002641 // Only allow Connection and Conference conferenceables.
2642 if (c instanceof Connection) {
2643 Connection connection = (Connection) c;
2644 if (mIdByConnection.containsKey(connection)) {
2645 ids.add(mIdByConnection.get(connection));
2646 }
2647 } else if (c instanceof Conference) {
2648 Conference conference = (Conference) c;
2649 if (mIdByConference.containsKey(conference)) {
2650 ids.add(mIdByConference.get(conference));
2651 }
2652 }
2653 }
2654 Collections.sort(ids);
2655 return ids;
2656 }
2657
Santos Cordon0159ac02014-08-21 14:28:11 -07002658 private Conference getNullConference() {
2659 if (sNullConference == null) {
2660 sNullConference = new Conference(null) {};
2661 }
2662 return sNullConference;
2663 }
Santos Cordon29f2f2e2014-09-11 19:50:24 -07002664
2665 private void endAllConnections() {
2666 // Unbound from telecomm. We should end all connections and conferences.
2667 for (Connection connection : mIdByConnection.keySet()) {
2668 // only operate on top-level calls. Conference calls will be removed on their own.
2669 if (connection.getConference() == null) {
2670 connection.onDisconnect();
2671 }
2672 }
2673 for (Conference conference : mIdByConference.keySet()) {
2674 conference.onDisconnect();
2675 }
2676 }
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002677
2678 /**
2679 * Retrieves the next call ID as maintainted by the connection service.
2680 *
2681 * @return The call ID.
2682 */
2683 private int getNextCallId() {
Brad Ebingerb32d4f82016-10-24 16:40:49 -07002684 synchronized (mIdSyncRoot) {
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002685 return ++mId;
2686 }
2687 }
Brad Ebinger99f17ce2019-09-11 18:06:51 -07002688
2689 /**
2690 * Returns this handler, ONLY FOR TESTING.
2691 * @hide
2692 */
2693 @VisibleForTesting
2694 public Handler getHandler() {
2695 return mHandler;
2696 }
Santos Cordon980acb92014-05-31 10:31:19 -07002697}