blob: 812b805675e5f5deeca3fb75be8da3fd810cb019 [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()),
1624 connection.getExtras()));
Tyler Gunnf5035432017-01-09 09:43:12 -08001625
Tyler Gunnf2e08b42018-05-24 10:44:44 -07001626 if (isIncoming && request.shouldShowIncomingCallUi() && isSelfManaged) {
Tyler Gunnf5035432017-01-09 09:43:12 -08001627 // Tell ConnectionService to show its incoming call UX.
1628 connection.onShowIncomingCallUi();
1629 }
Shriram Ganesh6bf35ac2014-12-11 17:53:38 -08001630 if (isUnknown) {
1631 triggerConferenceRecalculate();
1632 }
Evan Charltonbf11f982014-07-20 22:06:28 -07001633 }
1634
Tyler Gunn159f35c2017-03-02 09:28:37 -08001635 private void createConnectionFailed(final PhoneAccountHandle callManagerAccount,
1636 final String callId, final ConnectionRequest request,
1637 boolean isIncoming) {
Tyler Gunn44e01912017-01-31 10:49:05 -08001638
1639 Log.i(this, "createConnectionFailed %s", callId);
1640 if (isIncoming) {
Tyler Gunn159f35c2017-03-02 09:28:37 -08001641 onCreateIncomingConnectionFailed(callManagerAccount, request);
Tyler Gunn44e01912017-01-31 10:49:05 -08001642 } else {
Tyler Gunn159f35c2017-03-02 09:28:37 -08001643 onCreateOutgoingConnectionFailed(callManagerAccount, request);
Tyler Gunn44e01912017-01-31 10:49:05 -08001644 }
1645 }
1646
Sanket Padawe4cc8ed52017-12-04 16:22:20 -08001647 private void handoverFailed(final String callId, final ConnectionRequest request,
1648 int reason) {
1649
1650 Log.i(this, "handoverFailed %s", callId);
1651 onHandoverFailed(request, reason);
1652 }
1653
Tyler Gunn041a1fe2017-05-12 10:04:49 -07001654 /**
1655 * Called by Telecom when the creation of a new Connection has completed and it is now added
1656 * to Telecom.
1657 * @param callId The ID of the connection.
1658 */
1659 private void notifyCreateConnectionComplete(final String callId) {
1660 Log.i(this, "notifyCreateConnectionComplete %s", callId);
Tyler Gunn0a88f2e2017-06-16 20:20:34 -07001661 if (callId == null) {
1662 // This could happen if the connection fails quickly and is removed from the
1663 // ConnectionService before Telecom sends the create connection complete callback.
1664 Log.w(this, "notifyCreateConnectionComplete: callId is null.");
1665 return;
1666 }
Tyler Gunn041a1fe2017-05-12 10:04:49 -07001667 onCreateConnectionComplete(findConnectionForAction(callId,
1668 "notifyCreateConnectionComplete"));
1669 }
1670
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001671 private void abort(String callId) {
Ihab Awad60ac30b2014-05-20 22:32:12 -07001672 Log.d(this, "abort %s", callId);
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001673 findConnectionForAction(callId, "abort").onAbort();
Ihab Awad542e0ea2014-05-16 10:22:16 -07001674 }
1675
Tyler Gunnbe74de02014-08-29 14:51:48 -07001676 private void answerVideo(String callId, int videoState) {
1677 Log.d(this, "answerVideo %s", callId);
Andrew Lee8da4c3c2014-07-16 10:11:42 -07001678 findConnectionForAction(callId, "answer").onAnswer(videoState);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001679 }
1680
Tyler Gunnbe74de02014-08-29 14:51:48 -07001681 private void answer(String callId) {
1682 Log.d(this, "answer %s", callId);
1683 findConnectionForAction(callId, "answer").onAnswer();
1684 }
1685
Pooja Jaind34698d2017-12-28 14:15:31 +05301686 private void deflect(String callId, Uri address) {
1687 Log.d(this, "deflect %s", callId);
1688 findConnectionForAction(callId, "deflect").onDeflect(address);
1689 }
1690
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001691 private void reject(String callId) {
Ihab Awad60ac30b2014-05-20 22:32:12 -07001692 Log.d(this, "reject %s", callId);
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001693 findConnectionForAction(callId, "reject").onReject();
Ihab Awad542e0ea2014-05-16 10:22:16 -07001694 }
1695
Bryce Lee81901682015-08-28 16:38:02 -07001696 private void reject(String callId, String rejectWithMessage) {
1697 Log.d(this, "reject %s with message", callId);
1698 findConnectionForAction(callId, "reject").onReject(rejectWithMessage);
1699 }
1700
Bryce Leecac50772015-11-17 15:13:29 -08001701 private void silence(String callId) {
1702 Log.d(this, "silence %s", callId);
1703 findConnectionForAction(callId, "silence").onSilence();
1704 }
1705
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001706 private void disconnect(String callId) {
Ihab Awad60ac30b2014-05-20 22:32:12 -07001707 Log.d(this, "disconnect %s", callId);
Santos Cordon0159ac02014-08-21 14:28:11 -07001708 if (mConnectionById.containsKey(callId)) {
1709 findConnectionForAction(callId, "disconnect").onDisconnect();
1710 } else {
1711 findConferenceForAction(callId, "disconnect").onDisconnect();
1712 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001713 }
1714
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001715 private void hold(String callId) {
Ihab Awad60ac30b2014-05-20 22:32:12 -07001716 Log.d(this, "hold %s", callId);
Santos Cordon0159ac02014-08-21 14:28:11 -07001717 if (mConnectionById.containsKey(callId)) {
1718 findConnectionForAction(callId, "hold").onHold();
1719 } else {
1720 findConferenceForAction(callId, "hold").onHold();
1721 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001722 }
1723
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001724 private void unhold(String callId) {
Ihab Awad60ac30b2014-05-20 22:32:12 -07001725 Log.d(this, "unhold %s", callId);
Santos Cordon0159ac02014-08-21 14:28:11 -07001726 if (mConnectionById.containsKey(callId)) {
1727 findConnectionForAction(callId, "unhold").onUnhold();
1728 } else {
1729 findConferenceForAction(callId, "unhold").onUnhold();
1730 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001731 }
1732
Yorke Lee4af59352015-05-13 14:14:54 -07001733 private void onCallAudioStateChanged(String callId, CallAudioState callAudioState) {
1734 Log.d(this, "onAudioStateChanged %s %s", callId, callAudioState);
Yorke Leea0d3ca92014-09-15 19:18:13 -07001735 if (mConnectionById.containsKey(callId)) {
Yorke Lee4af59352015-05-13 14:14:54 -07001736 findConnectionForAction(callId, "onCallAudioStateChanged").setCallAudioState(
1737 callAudioState);
Yorke Leea0d3ca92014-09-15 19:18:13 -07001738 } else {
Yorke Lee4af59352015-05-13 14:14:54 -07001739 findConferenceForAction(callId, "onCallAudioStateChanged").setCallAudioState(
1740 callAudioState);
Yorke Leea0d3ca92014-09-15 19:18:13 -07001741 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001742 }
1743
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001744 private void playDtmfTone(String callId, char digit) {
1745 Log.d(this, "playDtmfTone %s %c", callId, digit);
Yorke Leea0d3ca92014-09-15 19:18:13 -07001746 if (mConnectionById.containsKey(callId)) {
1747 findConnectionForAction(callId, "playDtmfTone").onPlayDtmfTone(digit);
1748 } else {
1749 findConferenceForAction(callId, "playDtmfTone").onPlayDtmfTone(digit);
1750 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001751 }
1752
1753 private void stopDtmfTone(String callId) {
1754 Log.d(this, "stopDtmfTone %s", callId);
Yorke Leea0d3ca92014-09-15 19:18:13 -07001755 if (mConnectionById.containsKey(callId)) {
1756 findConnectionForAction(callId, "stopDtmfTone").onStopDtmfTone();
1757 } else {
1758 findConferenceForAction(callId, "stopDtmfTone").onStopDtmfTone();
1759 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001760 }
1761
Santos Cordon823fd3c2014-08-07 18:35:18 -07001762 private void conference(String callId1, String callId2) {
1763 Log.d(this, "conference %s, %s", callId1, callId2);
Santos Cordon980acb92014-05-31 10:31:19 -07001764
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001765 // Attempt to get second connection or conference.
Santos Cordon823fd3c2014-08-07 18:35:18 -07001766 Connection connection2 = findConnectionForAction(callId2, "conference");
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001767 Conference conference2 = getNullConference();
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001768 if (connection2 == getNullConnection()) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001769 conference2 = findConferenceForAction(callId2, "conference");
1770 if (conference2 == getNullConference()) {
1771 Log.w(this, "Connection2 or Conference2 missing in conference request %s.",
1772 callId2);
1773 return;
1774 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07001775 }
Santos Cordonb6939982014-06-04 20:20:58 -07001776
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001777 // Attempt to get first connection or conference and perform merge.
Ihab Awad50e35062014-09-30 09:17:03 -07001778 Connection connection1 = findConnectionForAction(callId1, "conference");
1779 if (connection1 == getNullConnection()) {
1780 Conference conference1 = findConferenceForAction(callId1, "addConnection");
1781 if (conference1 == getNullConference()) {
1782 Log.w(this,
1783 "Connection1 or Conference1 missing in conference request %s.",
1784 callId1);
1785 } else {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001786 // Call 1 is a conference.
1787 if (connection2 != getNullConnection()) {
1788 // Call 2 is a connection so merge via call 1 (conference).
1789 conference1.onMerge(connection2);
1790 } else {
1791 // Call 2 is ALSO a conference; this should never happen.
1792 Log.wtf(this, "There can only be one conference and an attempt was made to " +
1793 "merge two conferences.");
1794 return;
1795 }
Ihab Awad50e35062014-09-30 09:17:03 -07001796 }
1797 } else {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001798 // Call 1 is a connection.
1799 if (conference2 != getNullConference()) {
1800 // Call 2 is a conference, so merge via call 2.
1801 conference2.onMerge(connection1);
1802 } else {
1803 // Call 2 is a connection, so merge together.
1804 onConference(connection1, connection2);
1805 }
Ihab Awad50e35062014-09-30 09:17:03 -07001806 }
Santos Cordon980acb92014-05-31 10:31:19 -07001807 }
1808
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001809 private void splitFromConference(String callId) {
Santos Cordonb6939982014-06-04 20:20:58 -07001810 Log.d(this, "splitFromConference(%s)", callId);
Santos Cordon980acb92014-05-31 10:31:19 -07001811
1812 Connection connection = findConnectionForAction(callId, "splitFromConference");
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001813 if (connection == getNullConnection()) {
Santos Cordon980acb92014-05-31 10:31:19 -07001814 Log.w(this, "Connection missing in conference request %s.", callId);
1815 return;
1816 }
1817
Santos Cordon0159ac02014-08-21 14:28:11 -07001818 Conference conference = connection.getConference();
1819 if (conference != null) {
1820 conference.onSeparate(connection);
1821 }
Santos Cordon980acb92014-05-31 10:31:19 -07001822 }
1823
Santos Cordona4868042014-09-04 17:39:22 -07001824 private void mergeConference(String callId) {
1825 Log.d(this, "mergeConference(%s)", callId);
1826 Conference conference = findConferenceForAction(callId, "mergeConference");
1827 if (conference != null) {
1828 conference.onMerge();
1829 }
1830 }
1831
1832 private void swapConference(String callId) {
1833 Log.d(this, "swapConference(%s)", callId);
1834 Conference conference = findConferenceForAction(callId, "swapConference");
1835 if (conference != null) {
1836 conference.onSwap();
1837 }
1838 }
1839
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001840 /**
1841 * Notifies a {@link Connection} of a request to pull an external call.
1842 *
1843 * See {@link Call#pullExternalCall()}.
1844 *
1845 * @param callId The ID of the call to pull.
1846 */
1847 private void pullExternalCall(String callId) {
1848 Log.d(this, "pullExternalCall(%s)", callId);
1849 Connection connection = findConnectionForAction(callId, "pullExternalCall");
1850 if (connection != null) {
1851 connection.onPullExternalCall();
1852 }
1853 }
1854
1855 /**
1856 * Notifies a {@link Connection} of a call event.
1857 *
1858 * See {@link Call#sendCallEvent(String, Bundle)}.
1859 *
1860 * @param callId The ID of the call receiving the event.
1861 * @param event The event.
1862 * @param extras Extras associated with the event.
1863 */
1864 private void sendCallEvent(String callId, String event, Bundle extras) {
1865 Log.d(this, "sendCallEvent(%s, %s)", callId, event);
1866 Connection connection = findConnectionForAction(callId, "sendCallEvent");
1867 if (connection != null) {
1868 connection.onCallEvent(event, extras);
1869 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001870 }
1871
Tyler Gunndee56a82016-03-23 16:06:34 -07001872 /**
Tyler Gunn79bc1ec2018-01-22 15:17:54 -08001873 * Notifies a {@link Connection} that a handover has completed.
1874 *
1875 * @param callId The ID of the call which completed handover.
1876 */
1877 private void notifyHandoverComplete(String callId) {
1878 Log.d(this, "notifyHandoverComplete(%s)", callId);
1879 Connection connection = findConnectionForAction(callId, "notifyHandoverComplete");
1880 if (connection != null) {
1881 connection.onHandoverComplete();
1882 }
1883 }
1884
1885 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001886 * Notifies a {@link Connection} or {@link Conference} of a change to the extras from Telecom.
1887 * <p>
1888 * These extra changes can originate from Telecom itself, or from an {@link InCallService} via
1889 * the {@link android.telecom.Call#putExtra(String, boolean)},
1890 * {@link android.telecom.Call#putExtra(String, int)},
1891 * {@link android.telecom.Call#putExtra(String, String)},
1892 * {@link Call#removeExtras(List)}.
1893 *
1894 * @param callId The ID of the call receiving the event.
1895 * @param extras The new extras bundle.
1896 */
1897 private void handleExtrasChanged(String callId, Bundle extras) {
1898 Log.d(this, "handleExtrasChanged(%s, %s)", callId, extras);
1899 if (mConnectionById.containsKey(callId)) {
1900 findConnectionForAction(callId, "handleExtrasChanged").handleExtrasChanged(extras);
1901 } else if (mConferenceById.containsKey(callId)) {
1902 findConferenceForAction(callId, "handleExtrasChanged").handleExtrasChanged(extras);
1903 }
1904 }
1905
Hall Liub64ac4c2017-02-06 10:49:48 -08001906 private void startRtt(String callId, Connection.RttTextStream rttTextStream) {
1907 Log.d(this, "startRtt(%s)", callId);
1908 if (mConnectionById.containsKey(callId)) {
1909 findConnectionForAction(callId, "startRtt").onStartRtt(rttTextStream);
1910 } else if (mConferenceById.containsKey(callId)) {
1911 Log.w(this, "startRtt called on a conference.");
1912 }
1913 }
1914
1915 private void stopRtt(String callId) {
1916 Log.d(this, "stopRtt(%s)", callId);
1917 if (mConnectionById.containsKey(callId)) {
1918 findConnectionForAction(callId, "stopRtt").onStopRtt();
1919 } else if (mConferenceById.containsKey(callId)) {
1920 Log.w(this, "stopRtt called on a conference.");
1921 }
1922 }
1923
1924 private void handleRttUpgradeResponse(String callId, Connection.RttTextStream rttTextStream) {
1925 Log.d(this, "handleRttUpgradeResponse(%s, %s)", callId, rttTextStream == null);
1926 if (mConnectionById.containsKey(callId)) {
1927 findConnectionForAction(callId, "handleRttUpgradeResponse")
1928 .handleRttUpgradeResponse(rttTextStream);
1929 } else if (mConferenceById.containsKey(callId)) {
1930 Log.w(this, "handleRttUpgradeResponse called on a conference.");
1931 }
1932 }
1933
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001934 private void onPostDialContinue(String callId, boolean proceed) {
Evan Charlton6dea4ac2014-06-03 14:07:13 -07001935 Log.d(this, "onPostDialContinue(%s)", callId);
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001936 findConnectionForAction(callId, "stopDtmfTone").onPostDialContinue(proceed);
Evan Charlton6dea4ac2014-06-03 14:07:13 -07001937 }
1938
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001939 private void onAdapterAttached() {
Ihab Awad9c3f1882014-06-30 21:17:13 -07001940 if (mAreAccountsInitialized) {
Santos Cordon52d8a152014-06-17 19:08:45 -07001941 // No need to query again if we already did it.
1942 return;
1943 }
1944
Tyler Gunn4c69fb32019-05-17 10:49:16 -07001945 String callingPackage = getOpPackageName();
1946
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001947 mAdapter.queryRemoteConnectionServices(new RemoteServiceCallback.Stub() {
Santos Cordon52d8a152014-06-17 19:08:45 -07001948 @Override
1949 public void onResult(
1950 final List<ComponentName> componentNames,
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001951 final List<IBinder> services) {
Brad Ebinger0c3541b2016-11-01 14:11:38 -07001952 mHandler.post(new android.telecom.Logging.Runnable("oAA.qRCS.oR", null /*lock*/) {
Ihab Awad6107bab2014-08-18 09:23:25 -07001953 @Override
Brad Ebinger0c3541b2016-11-01 14:11:38 -07001954 public void loggedRun() {
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001955 for (int i = 0; i < componentNames.size() && i < services.size(); i++) {
Santos Cordon52d8a152014-06-17 19:08:45 -07001956 mRemoteConnectionManager.addConnectionService(
1957 componentNames.get(i),
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001958 IConnectionService.Stub.asInterface(services.get(i)));
Santos Cordon52d8a152014-06-17 19:08:45 -07001959 }
Ihab Awad5d0410f2014-07-30 10:07:40 -07001960 onAccountsInitialized();
Sailesh Nepalc5b01572014-07-14 16:29:44 -07001961 Log.d(this, "remote connection services found: " + services);
Santos Cordon52d8a152014-06-17 19:08:45 -07001962 }
Brad Ebinger0c3541b2016-11-01 14:11:38 -07001963 }.prepare());
Santos Cordon52d8a152014-06-17 19:08:45 -07001964 }
1965
1966 @Override
1967 public void onError() {
Brad Ebinger0c3541b2016-11-01 14:11:38 -07001968 mHandler.post(new android.telecom.Logging.Runnable("oAA.qRCS.oE", null /*lock*/) {
Ihab Awad6107bab2014-08-18 09:23:25 -07001969 @Override
Brad Ebinger0c3541b2016-11-01 14:11:38 -07001970 public void loggedRun() {
Ihab Awad9c3f1882014-06-30 21:17:13 -07001971 mAreAccountsInitialized = true;
Santos Cordon52d8a152014-06-17 19:08:45 -07001972 }
Brad Ebinger0c3541b2016-11-01 14:11:38 -07001973 }.prepare());
Santos Cordon52d8a152014-06-17 19:08:45 -07001974 }
Tyler Gunn4c69fb32019-05-17 10:49:16 -07001975 }, callingPackage);
Santos Cordon52d8a152014-06-17 19:08:45 -07001976 }
1977
Ihab Awadf8b69882014-07-25 15:14:01 -07001978 /**
1979 * Ask some other {@code ConnectionService} to create a {@code RemoteConnection} given an
Santos Cordona663f862014-10-29 13:49:58 -07001980 * incoming request. This is used by {@code ConnectionService}s that are registered with
1981 * {@link PhoneAccount#CAPABILITY_CONNECTION_MANAGER} and want to be able to manage
1982 * SIM-based incoming calls.
Ihab Awadf8b69882014-07-25 15:14:01 -07001983 *
1984 * @param connectionManagerPhoneAccount See description at
1985 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
1986 * @param request Details about the incoming call.
1987 * @return The {@code Connection} object to satisfy this call, or {@code null} to
1988 * not handle the call.
1989 */
1990 public final RemoteConnection createRemoteIncomingConnection(
1991 PhoneAccountHandle connectionManagerPhoneAccount,
1992 ConnectionRequest request) {
1993 return mRemoteConnectionManager.createRemoteConnection(
1994 connectionManagerPhoneAccount, request, true);
Santos Cordon52d8a152014-06-17 19:08:45 -07001995 }
1996
1997 /**
Ihab Awadf8b69882014-07-25 15:14:01 -07001998 * Ask some other {@code ConnectionService} to create a {@code RemoteConnection} given an
Santos Cordona663f862014-10-29 13:49:58 -07001999 * outgoing request. This is used by {@code ConnectionService}s that are registered with
2000 * {@link PhoneAccount#CAPABILITY_CONNECTION_MANAGER} and want to be able to use the
2001 * SIM-based {@code ConnectionService} to place its outgoing calls.
Ihab Awadf8b69882014-07-25 15:14:01 -07002002 *
2003 * @param connectionManagerPhoneAccount See description at
2004 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
Cuihtlauac ALVARADO0b3b2a52016-09-13 14:49:41 +02002005 * @param request Details about the outgoing call.
Ihab Awadf8b69882014-07-25 15:14:01 -07002006 * @return The {@code Connection} object to satisfy this call, or {@code null} to
2007 * not handle the call.
2008 */
2009 public final RemoteConnection createRemoteOutgoingConnection(
2010 PhoneAccountHandle connectionManagerPhoneAccount,
2011 ConnectionRequest request) {
2012 return mRemoteConnectionManager.createRemoteConnection(
2013 connectionManagerPhoneAccount, request, false);
2014 }
2015
2016 /**
Santos Cordona663f862014-10-29 13:49:58 -07002017 * Indicates to the relevant {@code RemoteConnectionService} that the specified
2018 * {@link RemoteConnection}s should be merged into a conference call.
2019 * <p>
2020 * If the conference request is successful, the method {@link #onRemoteConferenceAdded} will
2021 * be invoked.
2022 *
2023 * @param remoteConnection1 The first of the remote connections to conference.
2024 * @param remoteConnection2 The second of the remote connections to conference.
Ihab Awadb8e85c72014-08-23 20:34:57 -07002025 */
2026 public final void conferenceRemoteConnections(
Santos Cordona663f862014-10-29 13:49:58 -07002027 RemoteConnection remoteConnection1,
2028 RemoteConnection remoteConnection2) {
2029 mRemoteConnectionManager.conferenceRemoteConnections(remoteConnection1, remoteConnection2);
Ihab Awadb8e85c72014-08-23 20:34:57 -07002030 }
2031
2032 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07002033 * Adds a new conference call. When a conference call is created either as a result of an
2034 * explicit request via {@link #onConference} or otherwise, the connection service should supply
2035 * an instance of {@link Conference} by invoking this method. A conference call provided by this
2036 * method will persist until {@link Conference#destroy} is invoked on the conference instance.
2037 *
2038 * @param conference The new conference object.
2039 */
2040 public final void addConference(Conference conference) {
Rekha Kumar07366812015-03-24 16:42:31 -07002041 Log.d(this, "addConference: conference=%s", conference);
2042
Santos Cordon823fd3c2014-08-07 18:35:18 -07002043 String id = addConferenceInternal(conference);
2044 if (id != null) {
2045 List<String> connectionIds = new ArrayList<>(2);
2046 for (Connection connection : conference.getConnections()) {
2047 if (mIdByConnection.containsKey(connection)) {
2048 connectionIds.add(mIdByConnection.get(connection));
2049 }
2050 }
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002051 conference.setTelecomCallId(id);
Santos Cordon823fd3c2014-08-07 18:35:18 -07002052 ParcelableConference parcelableConference = new ParcelableConference(
Nancy Chenea38cca2014-09-05 16:38:49 -07002053 conference.getPhoneAccountHandle(),
Santos Cordon823fd3c2014-08-07 18:35:18 -07002054 conference.getState(),
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002055 conference.getConnectionCapabilities(),
Tyler Gunn720c6642016-03-22 09:02:47 -07002056 conference.getConnectionProperties(),
Tyler Gunncd5d33c2015-01-12 09:02:01 -08002057 connectionIds,
Rekha Kumar07366812015-03-24 16:42:31 -07002058 conference.getVideoProvider() == null ?
2059 null : conference.getVideoProvider().getInterface(),
2060 conference.getVideoState(),
Andrew Lee3e3e2f22015-04-16 13:48:43 -07002061 conference.getConnectTimeMillis(),
Tyler Gunn17541392018-02-01 08:58:38 -08002062 conference.getConnectionStartElapsedRealTime(),
Santos Cordon6b7f9552015-05-27 17:21:45 -07002063 conference.getStatusHints(),
Tyler Gunnac60f952019-05-31 07:23:16 -07002064 conference.getExtras(),
2065 conference.getAddress(),
2066 conference.getAddressPresentation(),
2067 conference.getCallerDisplayName(),
2068 conference.getCallerDisplayNamePresentation());
Andrew Lee0f51da32015-04-16 13:11:55 -07002069
Santos Cordon823fd3c2014-08-07 18:35:18 -07002070 mAdapter.addConferenceCall(id, parcelableConference);
Rekha Kumar07366812015-03-24 16:42:31 -07002071 mAdapter.setVideoProvider(id, conference.getVideoProvider());
2072 mAdapter.setVideoState(id, conference.getVideoState());
Santos Cordon823fd3c2014-08-07 18:35:18 -07002073
2074 // Go through any child calls and set the parent.
2075 for (Connection connection : conference.getConnections()) {
2076 String connectionId = mIdByConnection.get(connection);
2077 if (connectionId != null) {
2078 mAdapter.setIsConferenced(connectionId, id);
2079 }
2080 }
Pengquan Meng70c9885332017-10-02 18:09:03 -07002081 onConferenceAdded(conference);
Santos Cordon823fd3c2014-08-07 18:35:18 -07002082 }
2083 }
2084
2085 /**
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002086 * Adds a connection created by the {@link ConnectionService} and informs telecom of the new
2087 * connection.
2088 *
2089 * @param phoneAccountHandle The phone account handle for the connection.
2090 * @param connection The connection to add.
2091 */
2092 public final void addExistingConnection(PhoneAccountHandle phoneAccountHandle,
2093 Connection connection) {
Tyler Gunn78da7812017-05-09 14:34:57 -07002094 addExistingConnection(phoneAccountHandle, connection, null /* conference */);
2095 }
2096
2097 /**
Pengquan Meng731c1a32017-11-21 18:01:13 -08002098 * Call to inform Telecom that your {@link ConnectionService} has released call resources (e.g
2099 * microphone, camera).
2100 *
Pengquan Menge3bf7e22018-02-22 17:30:04 -08002101 * <p>
2102 * The {@link ConnectionService} will be disconnected when it failed to call this method within
2103 * 5 seconds after {@link #onConnectionServiceFocusLost()} is called.
2104 *
Pengquan Meng731c1a32017-11-21 18:01:13 -08002105 * @see ConnectionService#onConnectionServiceFocusLost()
2106 */
2107 public final void connectionServiceFocusReleased() {
2108 mAdapter.onConnectionServiceFocusReleased();
2109 }
2110
2111 /**
Tyler Gunn78da7812017-05-09 14:34:57 -07002112 * Adds a connection created by the {@link ConnectionService} and informs telecom of the new
Tyler Gunn5567d742019-10-31 13:04:37 -07002113 * connection, as well as adding that connection to the specified conference.
2114 * <p>
2115 * Note: This API is intended ONLY for use by the Telephony stack to provide an easy way to add
2116 * IMS conference participants to be added to a conference in a single step; this helps ensure
2117 * UI updates happen atomically, rather than adding the connection and then adding it to
2118 * the conference in another step.
Tyler Gunn78da7812017-05-09 14:34:57 -07002119 *
2120 * @param phoneAccountHandle The phone account handle for the connection.
2121 * @param connection The connection to add.
2122 * @param conference The parent conference of the new connection.
2123 * @hide
2124 */
Tyler Gunn5567d742019-10-31 13:04:37 -07002125 @SystemApi
2126 public final void addExistingConnection(@NonNull PhoneAccountHandle phoneAccountHandle,
2127 @NonNull Connection connection, @NonNull Conference conference) {
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002128
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002129 String id = addExistingConnectionInternal(phoneAccountHandle, connection);
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002130 if (id != null) {
2131 List<String> emptyList = new ArrayList<>(0);
Tyler Gunn78da7812017-05-09 14:34:57 -07002132 String conferenceId = null;
2133 if (conference != null) {
2134 conferenceId = mIdByConference.get(conference);
2135 }
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002136
2137 ParcelableConnection parcelableConnection = new ParcelableConnection(
2138 phoneAccountHandle,
2139 connection.getState(),
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002140 connection.getConnectionCapabilities(),
Tyler Gunn720c6642016-03-22 09:02:47 -07002141 connection.getConnectionProperties(),
Christine Hallstrom2830ce92016-11-30 16:06:42 -08002142 connection.getSupportedAudioRoutes(),
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002143 connection.getAddress(),
2144 connection.getAddressPresentation(),
2145 connection.getCallerDisplayName(),
2146 connection.getCallerDisplayNamePresentation(),
2147 connection.getVideoProvider() == null ?
2148 null : connection.getVideoProvider().getInterface(),
2149 connection.getVideoState(),
2150 connection.isRingbackRequested(),
2151 connection.getAudioModeIsVoip(),
Roshan Piuse927ec02015-07-15 15:47:21 -07002152 connection.getConnectTimeMillis(),
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002153 connection.getConnectElapsedTimeMillis(),
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002154 connection.getStatusHints(),
2155 connection.getDisconnectCause(),
Santos Cordon6b7f9552015-05-27 17:21:45 -07002156 emptyList,
Tyler Gunn78da7812017-05-09 14:34:57 -07002157 connection.getExtras(),
Tyler Gunn6986a632019-06-25 13:45:32 -07002158 conferenceId,
2159 connection.getCallDirection());
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002160 mAdapter.addExistingConnection(id, parcelableConnection);
2161 }
2162 }
2163
2164 /**
Ihab Awadf8b69882014-07-25 15:14:01 -07002165 * Returns all the active {@code Connection}s for which this {@code ConnectionService}
2166 * has taken responsibility.
2167 *
2168 * @return A collection of {@code Connection}s created by this {@code ConnectionService}.
Santos Cordonb6939982014-06-04 20:20:58 -07002169 */
Sailesh Nepal091768c2014-06-30 15:15:23 -07002170 public final Collection<Connection> getAllConnections() {
Santos Cordonb6939982014-06-04 20:20:58 -07002171 return mConnectionById.values();
2172 }
2173
2174 /**
Santos Cordona6018b92016-02-16 14:23:12 -08002175 * Returns all the active {@code Conference}s for which this {@code ConnectionService}
2176 * has taken responsibility.
2177 *
2178 * @return A collection of {@code Conference}s created by this {@code ConnectionService}.
2179 */
2180 public final Collection<Conference> getAllConferences() {
2181 return mConferenceById.values();
2182 }
2183
2184 /**
Ihab Awadf8b69882014-07-25 15:14:01 -07002185 * Create a {@code Connection} given an incoming request. This is used to attach to existing
2186 * incoming calls.
Evan Charltonbf11f982014-07-20 22:06:28 -07002187 *
Ihab Awadf8b69882014-07-25 15:14:01 -07002188 * @param connectionManagerPhoneAccount See description at
2189 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
2190 * @param request Details about the incoming call.
2191 * @return The {@code Connection} object to satisfy this call, or {@code null} to
2192 * not handle the call.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002193 */
Ihab Awadf8b69882014-07-25 15:14:01 -07002194 public Connection onCreateIncomingConnection(
2195 PhoneAccountHandle connectionManagerPhoneAccount,
2196 ConnectionRequest request) {
2197 return null;
2198 }
Sailesh Nepalc5b01572014-07-14 16:29:44 -07002199
2200 /**
Tyler Gunn041a1fe2017-05-12 10:04:49 -07002201 * Called after the {@link Connection} returned by
2202 * {@link #onCreateIncomingConnection(PhoneAccountHandle, ConnectionRequest)}
2203 * or {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)} has been
2204 * added to the {@link ConnectionService} and sent to Telecom.
2205 *
2206 * @param connection the {@link Connection}.
2207 * @hide
2208 */
2209 public void onCreateConnectionComplete(Connection connection) {
2210 }
2211
2212 /**
Tyler Gunnf5035432017-01-09 09:43:12 -08002213 * Called by Telecom to inform the {@link ConnectionService} that its request to create a new
2214 * incoming {@link Connection} was denied.
2215 * <p>
2216 * Used when a self-managed {@link ConnectionService} attempts to create a new incoming
2217 * {@link Connection}, but Telecom has determined that the call cannot be allowed at this time.
2218 * The {@link ConnectionService} is responsible for silently rejecting the new incoming
2219 * {@link Connection}.
2220 * <p>
2221 * See {@link TelecomManager#isIncomingCallPermitted(PhoneAccountHandle)} for more information.
2222 *
Tyler Gunn159f35c2017-03-02 09:28:37 -08002223 * @param connectionManagerPhoneAccount See description at
2224 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
Tyler Gunnf5035432017-01-09 09:43:12 -08002225 * @param request The incoming connection request.
2226 */
Tyler Gunn159f35c2017-03-02 09:28:37 -08002227 public void onCreateIncomingConnectionFailed(PhoneAccountHandle connectionManagerPhoneAccount,
2228 ConnectionRequest request) {
Tyler Gunnf5035432017-01-09 09:43:12 -08002229 }
2230
2231 /**
2232 * Called by Telecom to inform the {@link ConnectionService} that its request to create a new
2233 * outgoing {@link Connection} was denied.
2234 * <p>
2235 * Used when a self-managed {@link ConnectionService} attempts to create a new outgoing
2236 * {@link Connection}, but Telecom has determined that the call cannot be placed at this time.
2237 * The {@link ConnectionService} is responisible for informing the user that the
2238 * {@link Connection} cannot be made at this time.
2239 * <p>
2240 * See {@link TelecomManager#isOutgoingCallPermitted(PhoneAccountHandle)} for more information.
2241 *
Tyler Gunn159f35c2017-03-02 09:28:37 -08002242 * @param connectionManagerPhoneAccount See description at
2243 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
Tyler Gunnf5035432017-01-09 09:43:12 -08002244 * @param request The outgoing connection request.
2245 */
Tyler Gunn159f35c2017-03-02 09:28:37 -08002246 public void onCreateOutgoingConnectionFailed(PhoneAccountHandle connectionManagerPhoneAccount,
2247 ConnectionRequest request) {
Tyler Gunnf5035432017-01-09 09:43:12 -08002248 }
2249
2250 /**
Shriram Ganesh6bf35ac2014-12-11 17:53:38 -08002251 * Trigger recalculate functinality for conference calls. This is used when a Telephony
2252 * Connection is part of a conference controller but is not yet added to Connection
2253 * Service and hence cannot be added to the conference call.
2254 *
2255 * @hide
2256 */
2257 public void triggerConferenceRecalculate() {
2258 }
2259
2260 /**
Ihab Awadf8b69882014-07-25 15:14:01 -07002261 * Create a {@code Connection} given an outgoing request. This is used to initiate new
2262 * outgoing calls.
Sailesh Nepalc5b01572014-07-14 16:29:44 -07002263 *
Ihab Awadf8b69882014-07-25 15:14:01 -07002264 * @param connectionManagerPhoneAccount The connection manager account to use for managing
2265 * this call.
2266 * <p>
2267 * If this parameter is not {@code null}, it means that this {@code ConnectionService}
2268 * has registered one or more {@code PhoneAccount}s having
2269 * {@link PhoneAccount#CAPABILITY_CONNECTION_MANAGER}. This parameter will contain
2270 * one of these {@code PhoneAccount}s, while the {@code request} will contain another
2271 * (usually but not always distinct) {@code PhoneAccount} to be used for actually
2272 * making the connection.
2273 * <p>
2274 * If this parameter is {@code null}, it means that this {@code ConnectionService} is
2275 * being asked to make a direct connection. The
2276 * {@link ConnectionRequest#getAccountHandle()} of parameter {@code request} will be
2277 * a {@code PhoneAccount} registered by this {@code ConnectionService} to use for
2278 * making the connection.
2279 * @param request Details about the outgoing call.
2280 * @return The {@code Connection} object to satisfy this call, or the result of an invocation
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002281 * of {@link Connection#createFailedConnection(DisconnectCause)} to not handle the call.
Sailesh Nepalc5b01572014-07-14 16:29:44 -07002282 */
Ihab Awadf8b69882014-07-25 15:14:01 -07002283 public Connection onCreateOutgoingConnection(
2284 PhoneAccountHandle connectionManagerPhoneAccount,
2285 ConnectionRequest request) {
2286 return null;
2287 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002288
2289 /**
Tyler Gunn9d127732018-03-02 15:45:51 -08002290 * Called by Telecom to request that a {@link ConnectionService} creates an instance of an
2291 * outgoing handover {@link Connection}.
2292 * <p>
2293 * A call handover is the process where an ongoing call is transferred from one app (i.e.
2294 * {@link ConnectionService} to another app. The user could, for example, choose to continue a
2295 * mobile network call in a video calling app. The mobile network call via the Telephony stack
2296 * is referred to as the source of the handover, and the video calling app is referred to as the
2297 * destination.
2298 * <p>
2299 * When considering a handover scenario the <em>initiating</em> device is where a user initiated
2300 * the handover process (e.g. by calling {@link android.telecom.Call#handoverTo(
2301 * PhoneAccountHandle, int, Bundle)}, and the other device is considered the <em>receiving</em>
2302 * device.
2303 * <p>
2304 * This method is called on the destination {@link ConnectionService} on <em>initiating</em>
2305 * device when the user initiates a handover request from one app to another. The user request
2306 * originates in the {@link InCallService} via
2307 * {@link android.telecom.Call#handoverTo(PhoneAccountHandle, int, Bundle)}.
2308 * <p>
2309 * For a full discussion of the handover process and the APIs involved, see
2310 * {@link android.telecom.Call#handoverTo(PhoneAccountHandle, int, Bundle)}.
2311 * <p>
2312 * Implementations of this method should return an instance of {@link Connection} which
2313 * represents the handover. If your app does not wish to accept a handover to it at this time,
2314 * you can return {@code null}. The code below shows an example of how this is done.
2315 * <pre>
2316 * {@code
2317 * public Connection onCreateIncomingHandoverConnection(PhoneAccountHandle
2318 * fromPhoneAccountHandle, ConnectionRequest request) {
2319 * if (!isHandoverAvailable()) {
2320 * return null;
2321 * }
2322 * MyConnection connection = new MyConnection();
2323 * connection.setAddress(request.getAddress(), TelecomManager.PRESENTATION_ALLOWED);
2324 * connection.setVideoState(request.getVideoState());
2325 * return connection;
2326 * }
2327 * }
2328 * </pre>
2329 *
Sanket Padawea8eddd42017-11-03 11:07:35 -07002330 * @param fromPhoneAccountHandle {@link PhoneAccountHandle} associated with the
2331 * ConnectionService which needs to handover the call.
Tyler Gunn9d127732018-03-02 15:45:51 -08002332 * @param request Details about the call to handover.
2333 * @return {@link Connection} instance corresponding to the handover call.
Sanket Padawea8eddd42017-11-03 11:07:35 -07002334 */
2335 public Connection onCreateOutgoingHandoverConnection(PhoneAccountHandle fromPhoneAccountHandle,
2336 ConnectionRequest request) {
2337 return null;
2338 }
2339
2340 /**
Tyler Gunn9d127732018-03-02 15:45:51 -08002341 * Called by Telecom to request that a {@link ConnectionService} creates an instance of an
2342 * incoming handover {@link Connection}.
2343 * <p>
2344 * A call handover is the process where an ongoing call is transferred from one app (i.e.
2345 * {@link ConnectionService} to another app. The user could, for example, choose to continue a
2346 * mobile network call in a video calling app. The mobile network call via the Telephony stack
2347 * is referred to as the source of the handover, and the video calling app is referred to as the
2348 * destination.
2349 * <p>
2350 * When considering a handover scenario the <em>initiating</em> device is where a user initiated
2351 * the handover process (e.g. by calling {@link android.telecom.Call#handoverTo(
2352 * PhoneAccountHandle, int, Bundle)}, and the other device is considered the <em>receiving</em>
2353 * device.
2354 * <p>
2355 * This method is called on the destination app on the <em>receiving</em> device when the
2356 * destination app calls {@link TelecomManager#acceptHandover(Uri, int, PhoneAccountHandle)} to
2357 * accept an incoming handover from the <em>initiating</em> device.
2358 * <p>
2359 * For a full discussion of the handover process and the APIs involved, see
2360 * {@link android.telecom.Call#handoverTo(PhoneAccountHandle, int, Bundle)}.
2361 * <p>
2362 * Implementations of this method should return an instance of {@link Connection} which
2363 * represents the handover. The code below shows an example of how this is done.
2364 * <pre>
2365 * {@code
2366 * public Connection onCreateIncomingHandoverConnection(PhoneAccountHandle
2367 * fromPhoneAccountHandle, ConnectionRequest request) {
2368 * // Given that your app requested to accept the handover, you should not return null here.
2369 * MyConnection connection = new MyConnection();
2370 * connection.setAddress(request.getAddress(), TelecomManager.PRESENTATION_ALLOWED);
2371 * connection.setVideoState(request.getVideoState());
2372 * return connection;
2373 * }
2374 * }
2375 * </pre>
2376 *
Sanket Padawea8eddd42017-11-03 11:07:35 -07002377 * @param fromPhoneAccountHandle {@link PhoneAccountHandle} associated with the
2378 * ConnectionService which needs to handover the call.
2379 * @param request Details about the call which needs to be handover.
Tyler Gunn9d127732018-03-02 15:45:51 -08002380 * @return {@link Connection} instance corresponding to the handover call.
Sanket Padawea8eddd42017-11-03 11:07:35 -07002381 */
2382 public Connection onCreateIncomingHandoverConnection(PhoneAccountHandle fromPhoneAccountHandle,
2383 ConnectionRequest request) {
2384 return null;
2385 }
2386
2387 /**
2388 * Called by Telecom in response to a {@code TelecomManager#acceptHandover()}
2389 * invocation which failed.
Tyler Gunn9d127732018-03-02 15:45:51 -08002390 * <p>
2391 * For a full discussion of the handover process and the APIs involved, see
2392 * {@link android.telecom.Call#handoverTo(PhoneAccountHandle, int, Bundle)}
2393 *
2394 * @param request Details about the call which failed to handover.
2395 * @param error Reason for handover failure. Will be one of the
Sanket Padawea8eddd42017-11-03 11:07:35 -07002396 */
Tyler Gunn9d127732018-03-02 15:45:51 -08002397 public void onHandoverFailed(ConnectionRequest request,
2398 @Call.Callback.HandoverFailureErrors int error) {
Sanket Padawea8eddd42017-11-03 11:07:35 -07002399 return;
2400 }
2401
2402 /**
Yorke Leec3cf9822014-10-02 09:38:39 -07002403 * Create a {@code Connection} for a new unknown call. An unknown call is a call originating
2404 * from the ConnectionService that was neither a user-initiated outgoing call, nor an incoming
2405 * call created using
2406 * {@code TelecomManager#addNewIncomingCall(PhoneAccountHandle, android.os.Bundle)}.
2407 *
Yorke Lee770ed6e2014-10-06 18:58:52 -07002408 * @hide
Yorke Leec3cf9822014-10-02 09:38:39 -07002409 */
2410 public Connection onCreateUnknownConnection(PhoneAccountHandle connectionManagerPhoneAccount,
2411 ConnectionRequest request) {
Brad Ebingerb32d4f82016-10-24 16:40:49 -07002412 return null;
Yorke Leec3cf9822014-10-02 09:38:39 -07002413 }
2414
2415 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07002416 * Conference two specified connections. Invoked when the user has made a request to merge the
2417 * specified connections into a conference call. In response, the connection service should
2418 * create an instance of {@link Conference} and pass it into {@link #addConference}.
Santos Cordonb6939982014-06-04 20:20:58 -07002419 *
Santos Cordon823fd3c2014-08-07 18:35:18 -07002420 * @param connection1 A connection to merge into a conference call.
2421 * @param connection2 A connection to merge into a conference call.
Santos Cordonb6939982014-06-04 20:20:58 -07002422 */
Santos Cordon823fd3c2014-08-07 18:35:18 -07002423 public void onConference(Connection connection1, Connection connection2) {}
Santos Cordonb6939982014-06-04 20:20:58 -07002424
Santos Cordona663f862014-10-29 13:49:58 -07002425 /**
Pengquan Meng70c9885332017-10-02 18:09:03 -07002426 * Called when a connection is added.
2427 * @hide
2428 */
2429 public void onConnectionAdded(Connection connection) {}
2430
2431 /**
2432 * Called when a connection is removed.
2433 * @hide
2434 */
2435 public void onConnectionRemoved(Connection connection) {}
2436
2437 /**
2438 * Called when a conference is added.
2439 * @hide
2440 */
2441 public void onConferenceAdded(Conference conference) {}
2442
2443 /**
2444 * Called when a conference is removed.
2445 * @hide
2446 */
2447 public void onConferenceRemoved(Conference conference) {}
2448
2449 /**
Santos Cordona663f862014-10-29 13:49:58 -07002450 * Indicates that a remote conference has been created for existing {@link RemoteConnection}s.
2451 * When this method is invoked, this {@link ConnectionService} should create its own
2452 * representation of the conference call and send it to telecom using {@link #addConference}.
2453 * <p>
2454 * This is only relevant to {@link ConnectionService}s which are registered with
2455 * {@link PhoneAccount#CAPABILITY_CONNECTION_MANAGER}.
2456 *
2457 * @param conference The remote conference call.
2458 */
Ihab Awadb8e85c72014-08-23 20:34:57 -07002459 public void onRemoteConferenceAdded(RemoteConference conference) {}
2460
Santos Cordon823fd3c2014-08-07 18:35:18 -07002461 /**
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002462 * Called when an existing connection is added remotely.
2463 * @param connection The existing connection which was added.
2464 */
2465 public void onRemoteExistingConnectionAdded(RemoteConnection connection) {}
2466
2467 /**
Pengquan Meng731c1a32017-11-21 18:01:13 -08002468 * Called when the {@link ConnectionService} has lost the call focus.
2469 * The {@link ConnectionService} should release the call resources and invokes
2470 * {@link ConnectionService#connectionServiceFocusReleased()} to inform telecom that it has
2471 * released the call resources.
2472 */
2473 public void onConnectionServiceFocusLost() {}
2474
2475 /**
2476 * Called when the {@link ConnectionService} has gained the call focus. The
2477 * {@link ConnectionService} can acquire the call resources at this time.
2478 */
2479 public void onConnectionServiceFocusGained() {}
2480
2481 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07002482 * @hide
2483 */
2484 public boolean containsConference(Conference conference) {
2485 return mIdByConference.containsKey(conference);
2486 }
2487
Ihab Awadb8e85c72014-08-23 20:34:57 -07002488 /** {@hide} */
2489 void addRemoteConference(RemoteConference remoteConference) {
2490 onRemoteConferenceAdded(remoteConference);
2491 }
2492
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002493 /** {@hide} */
2494 void addRemoteExistingConnection(RemoteConnection remoteConnection) {
2495 onRemoteExistingConnectionAdded(remoteConnection);
2496 }
2497
Ihab Awad5d0410f2014-07-30 10:07:40 -07002498 private void onAccountsInitialized() {
2499 mAreAccountsInitialized = true;
2500 for (Runnable r : mPreInitializationConnectionRequests) {
2501 r.run();
2502 }
2503 mPreInitializationConnectionRequests.clear();
2504 }
2505
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002506 /**
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002507 * Adds an existing connection to the list of connections, identified by a new call ID unique
2508 * to this connection service.
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002509 *
2510 * @param connection The connection.
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002511 * @return The ID of the connection (e.g. the call-id).
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002512 */
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002513 private String addExistingConnectionInternal(PhoneAccountHandle handle, Connection connection) {
2514 String id;
Tyler Gunncd6ccfd2016-10-17 15:48:19 -07002515
2516 if (connection.getExtras() != null && connection.getExtras()
2517 .containsKey(Connection.EXTRA_ORIGINAL_CONNECTION_ID)) {
2518 id = connection.getExtras().getString(Connection.EXTRA_ORIGINAL_CONNECTION_ID);
2519 Log.d(this, "addExistingConnectionInternal - conn %s reusing original id %s",
2520 connection.getTelecomCallId(), id);
2521 } else if (handle == null) {
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002522 // If no phone account handle was provided, we cannot be sure the call ID is unique,
2523 // so just use a random UUID.
2524 id = UUID.randomUUID().toString();
2525 } else {
2526 // Phone account handle was provided, so use the ConnectionService class name as a
2527 // prefix for a unique incremental call ID.
2528 id = handle.getComponentName().getClassName() + "@" + getNextCallId();
2529 }
Pengquan Meng70c9885332017-10-02 18:09:03 -07002530 addConnection(handle, id, connection);
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002531 return id;
2532 }
2533
Pengquan Meng70c9885332017-10-02 18:09:03 -07002534 private void addConnection(PhoneAccountHandle handle, String callId, Connection connection) {
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002535 connection.setTelecomCallId(callId);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002536 mConnectionById.put(callId, connection);
2537 mIdByConnection.put(connection, callId);
2538 connection.addConnectionListener(mConnectionListener);
Santos Cordon823fd3c2014-08-07 18:35:18 -07002539 connection.setConnectionService(this);
Pengquan Meng70c9885332017-10-02 18:09:03 -07002540 connection.setPhoneAccountHandle(handle);
2541 onConnectionAdded(connection);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002542 }
2543
Anthony Lee30e65842014-11-06 16:30:53 -08002544 /** {@hide} */
2545 protected void removeConnection(Connection connection) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07002546 connection.unsetConnectionService(this);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002547 connection.removeConnectionListener(mConnectionListener);
Chenjie Luoe370b532016-05-12 16:59:43 -07002548 String id = mIdByConnection.get(connection);
2549 if (id != null) {
2550 mConnectionById.remove(id);
2551 mIdByConnection.remove(connection);
2552 mAdapter.removeCall(id);
Pengquan Meng70c9885332017-10-02 18:09:03 -07002553 onConnectionRemoved(connection);
Chenjie Luoe370b532016-05-12 16:59:43 -07002554 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002555 }
2556
Santos Cordon823fd3c2014-08-07 18:35:18 -07002557 private String addConferenceInternal(Conference conference) {
Tyler Gunncd6ccfd2016-10-17 15:48:19 -07002558 String originalId = null;
2559 if (conference.getExtras() != null && conference.getExtras()
2560 .containsKey(Connection.EXTRA_ORIGINAL_CONNECTION_ID)) {
2561 originalId = conference.getExtras().getString(Connection.EXTRA_ORIGINAL_CONNECTION_ID);
2562 Log.d(this, "addConferenceInternal: conf %s reusing original id %s",
2563 conference.getTelecomCallId(),
2564 originalId);
2565 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07002566 if (mIdByConference.containsKey(conference)) {
2567 Log.w(this, "Re-adding an existing conference: %s.", conference);
2568 } else if (conference != null) {
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002569 // Conferences do not (yet) have a PhoneAccountHandle associated with them, so we
2570 // cannot determine a ConnectionService class name to associate with the ID, so use
2571 // a unique UUID (for now).
Tyler Gunncd6ccfd2016-10-17 15:48:19 -07002572 String id = originalId == null ? UUID.randomUUID().toString() : originalId;
Santos Cordon823fd3c2014-08-07 18:35:18 -07002573 mConferenceById.put(id, conference);
2574 mIdByConference.put(conference, id);
2575 conference.addListener(mConferenceListener);
2576 return id;
2577 }
2578
2579 return null;
2580 }
2581
2582 private void removeConference(Conference conference) {
2583 if (mIdByConference.containsKey(conference)) {
2584 conference.removeListener(mConferenceListener);
2585
2586 String id = mIdByConference.get(conference);
2587 mConferenceById.remove(id);
2588 mIdByConference.remove(conference);
2589 mAdapter.removeCall(id);
Pengquan Meng70c9885332017-10-02 18:09:03 -07002590
2591 onConferenceRemoved(conference);
Santos Cordon823fd3c2014-08-07 18:35:18 -07002592 }
2593 }
2594
Ihab Awad542e0ea2014-05-16 10:22:16 -07002595 private Connection findConnectionForAction(String callId, String action) {
Tyler Gunn0a88f2e2017-06-16 20:20:34 -07002596 if (callId != null && mConnectionById.containsKey(callId)) {
Ihab Awad542e0ea2014-05-16 10:22:16 -07002597 return mConnectionById.get(callId);
2598 }
Ihab Awad60ac30b2014-05-20 22:32:12 -07002599 Log.w(this, "%s - Cannot find Connection %s", action, callId);
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07002600 return getNullConnection();
2601 }
2602
2603 static synchronized Connection getNullConnection() {
2604 if (sNullConnection == null) {
2605 sNullConnection = new Connection() {};
2606 }
2607 return sNullConnection;
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002608 }
Santos Cordon0159ac02014-08-21 14:28:11 -07002609
2610 private Conference findConferenceForAction(String conferenceId, String action) {
2611 if (mConferenceById.containsKey(conferenceId)) {
2612 return mConferenceById.get(conferenceId);
2613 }
2614 Log.w(this, "%s - Cannot find conference %s", action, conferenceId);
2615 return getNullConference();
2616 }
2617
Ihab Awadb8e85c72014-08-23 20:34:57 -07002618 private List<String> createConnectionIdList(List<Connection> connections) {
2619 List<String> ids = new ArrayList<>();
2620 for (Connection c : connections) {
2621 if (mIdByConnection.containsKey(c)) {
2622 ids.add(mIdByConnection.get(c));
2623 }
2624 }
2625 Collections.sort(ids);
2626 return ids;
2627 }
2628
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002629 /**
2630 * Builds a list of {@link Connection} and {@link Conference} IDs based on the list of
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002631 * {@link Conferenceable}s passed in.
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002632 *
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002633 * @param conferenceables The {@link Conferenceable} connections and conferences.
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002634 * @return List of string conference and call Ids.
2635 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002636 private List<String> createIdList(List<Conferenceable> conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002637 List<String> ids = new ArrayList<>();
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002638 for (Conferenceable c : conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002639 // Only allow Connection and Conference conferenceables.
2640 if (c instanceof Connection) {
2641 Connection connection = (Connection) c;
2642 if (mIdByConnection.containsKey(connection)) {
2643 ids.add(mIdByConnection.get(connection));
2644 }
2645 } else if (c instanceof Conference) {
2646 Conference conference = (Conference) c;
2647 if (mIdByConference.containsKey(conference)) {
2648 ids.add(mIdByConference.get(conference));
2649 }
2650 }
2651 }
2652 Collections.sort(ids);
2653 return ids;
2654 }
2655
Santos Cordon0159ac02014-08-21 14:28:11 -07002656 private Conference getNullConference() {
2657 if (sNullConference == null) {
2658 sNullConference = new Conference(null) {};
2659 }
2660 return sNullConference;
2661 }
Santos Cordon29f2f2e2014-09-11 19:50:24 -07002662
2663 private void endAllConnections() {
2664 // Unbound from telecomm. We should end all connections and conferences.
2665 for (Connection connection : mIdByConnection.keySet()) {
2666 // only operate on top-level calls. Conference calls will be removed on their own.
2667 if (connection.getConference() == null) {
2668 connection.onDisconnect();
2669 }
2670 }
2671 for (Conference conference : mIdByConference.keySet()) {
2672 conference.onDisconnect();
2673 }
2674 }
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002675
2676 /**
2677 * Retrieves the next call ID as maintainted by the connection service.
2678 *
2679 * @return The call ID.
2680 */
2681 private int getNextCallId() {
Brad Ebingerb32d4f82016-10-24 16:40:49 -07002682 synchronized (mIdSyncRoot) {
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002683 return ++mId;
2684 }
2685 }
Brad Ebinger99f17ce2019-09-11 18:06:51 -07002686
2687 /**
2688 * Returns this handler, ONLY FOR TESTING.
2689 * @hide
2690 */
2691 @VisibleForTesting
2692 public Handler getHandler() {
2693 return mHandler;
2694 }
Santos Cordon980acb92014-05-31 10:31:19 -07002695}