blob: 6fcb1156a45daf148e41567595210cb229bb5cb2 [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
Santos Cordon5c6fa952014-07-20 17:47:12 -070019import android.annotation.SdkConstant;
Sailesh Nepal2a46b902014-07-04 17:21:07 -070020import android.app.Service;
Santos Cordon52d8a152014-06-17 19:08:45 -070021import android.content.ComponentName;
Santos Cordon5c6fa952014-07-20 17:47:12 -070022import android.content.Intent;
Ihab Awad542e0ea2014-05-16 10:22:16 -070023import android.net.Uri;
Sanket Padawe02d8c272017-12-20 10:13:05 -080024import android.os.Build;
Santos Cordon6b7f9552015-05-27 17:21:45 -070025import android.os.Bundle;
Santos Cordon52d8a152014-06-17 19:08:45 -070026import android.os.Handler;
27import android.os.IBinder;
28import android.os.Looper;
Sailesh Nepal2a46b902014-07-04 17:21:07 -070029import android.os.Message;
Hall Liub64ac4c2017-02-06 10:49:48 -080030import android.os.ParcelFileDescriptor;
31import android.os.RemoteException;
Brad Ebingerb32d4f82016-10-24 16:40:49 -070032import android.telecom.Logging.Session;
Andrew Lee14185762014-07-25 09:41:56 -070033
Sailesh Nepal2a46b902014-07-04 17:21:07 -070034import com.android.internal.os.SomeArgs;
Tyler Gunnef9f6f92014-09-12 22:16:17 -070035import com.android.internal.telecom.IConnectionService;
36import com.android.internal.telecom.IConnectionServiceAdapter;
37import com.android.internal.telecom.RemoteServiceCallback;
Santos Cordon52d8a152014-06-17 19:08:45 -070038
Ihab Awad5d0410f2014-07-30 10:07:40 -070039import java.util.ArrayList;
Santos Cordonb6939982014-06-04 20:20:58 -070040import java.util.Collection;
Santos Cordon7c7bc7f2014-07-28 18:15:48 -070041import java.util.Collections;
Santos Cordon52d8a152014-06-17 19:08:45 -070042import java.util.List;
Ihab Awad542e0ea2014-05-16 10:22:16 -070043import java.util.Map;
Santos Cordon823fd3c2014-08-07 18:35:18 -070044import java.util.UUID;
mike dooley95e80702014-09-18 14:07:52 -070045import java.util.concurrent.ConcurrentHashMap;
Ihab Awad542e0ea2014-05-16 10:22:16 -070046
47/**
Tyler Gunnf5035432017-01-09 09:43:12 -080048 * An abstract service that should be implemented by any apps which either:
49 * <ol>
50 * <li>Can make phone calls (VoIP or otherwise) and want those calls to be integrated into the
51 * built-in phone app. Referred to as a <b>system managed</b> {@link ConnectionService}.</li>
52 * <li>Are a standalone calling app and don't want their calls to be integrated into the
53 * built-in phone app. Referred to as a <b>self managed</b> {@link ConnectionService}.</li>
54 * </ol>
55 * Once implemented, the {@link ConnectionService} needs to take the following steps so that Telecom
56 * will bind to it:
Santos Cordona663f862014-10-29 13:49:58 -070057 * <p>
58 * 1. <i>Registration in AndroidManifest.xml</i>
59 * <br/>
60 * <pre>
61 * &lt;service android:name="com.example.package.MyConnectionService"
62 * android:label="@string/some_label_for_my_connection_service"
Yorke Lee249c12e2015-05-13 15:59:29 -070063 * android:permission="android.permission.BIND_TELECOM_CONNECTION_SERVICE"&gt;
Santos Cordona663f862014-10-29 13:49:58 -070064 * &lt;intent-filter&gt;
65 * &lt;action android:name="android.telecom.ConnectionService" /&gt;
66 * &lt;/intent-filter&gt;
67 * &lt;/service&gt;
68 * </pre>
69 * <p>
70 * 2. <i> Registration of {@link PhoneAccount} with {@link TelecomManager}.</i>
71 * <br/>
72 * See {@link PhoneAccount} and {@link TelecomManager#registerPhoneAccount} for more information.
73 * <p>
Tyler Gunnf5035432017-01-09 09:43:12 -080074 * System managed {@link ConnectionService}s must be enabled by the user in the phone app settings
75 * before Telecom will bind to them. Self-manged {@link ConnectionService}s must be granted the
76 * appropriate permission before Telecom will bind to them.
77 * <p>
78 * Once registered and enabled by the user in the phone app settings or granted permission, telecom
79 * will bind to a {@link ConnectionService} implementation when it wants that
80 * {@link ConnectionService} to place a call or the service has indicated that is has an incoming
81 * call through {@link TelecomManager#addNewIncomingCall}. The {@link ConnectionService} can then
82 * expect a call to {@link #onCreateIncomingConnection} or {@link #onCreateOutgoingConnection}
83 * wherein it should provide a new instance of a {@link Connection} object. It is through this
84 * {@link Connection} object that telecom receives state updates and the {@link ConnectionService}
Santos Cordona663f862014-10-29 13:49:58 -070085 * receives call-commands such as answer, reject, hold and disconnect.
86 * <p>
Tyler Gunnf5035432017-01-09 09:43:12 -080087 * When there are no more live calls, telecom will unbind from the {@link ConnectionService}.
Ihab Awad542e0ea2014-05-16 10:22:16 -070088 */
Sailesh Nepal2a46b902014-07-04 17:21:07 -070089public abstract class ConnectionService extends Service {
Santos Cordon5c6fa952014-07-20 17:47:12 -070090 /**
91 * The {@link Intent} that must be declared as handled by the service.
92 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -070093 @SdkConstant(SdkConstant.SdkConstantType.SERVICE_ACTION)
Tyler Gunnef9f6f92014-09-12 22:16:17 -070094 public static final String SERVICE_INTERFACE = "android.telecom.ConnectionService";
Santos Cordon5c6fa952014-07-20 17:47:12 -070095
Tyler Gunn8bf76572017-04-06 15:30:08 -070096 /**
97 * Boolean extra used by Telecom to inform a {@link ConnectionService} that the purpose of it
98 * being asked to create a new outgoing {@link Connection} is to perform a handover of an
99 * ongoing call on the device from another {@link PhoneAccount}/{@link ConnectionService}. Will
100 * be specified in the {@link ConnectionRequest#getExtras()} passed by Telecom when
101 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)} is called.
102 * <p>
Tyler Gunn727c6bd2017-04-11 09:51:40 -0700103 * When your {@link ConnectionService} receives this extra, it should communicate the fact that
104 * this is a handover to the other device's matching {@link ConnectionService}. That
Tyler Gunn8bf76572017-04-06 15:30:08 -0700105 * {@link ConnectionService} will continue the handover using
106 * {@link TelecomManager#addNewIncomingCall(PhoneAccountHandle, Bundle)}, specifying
Tyler Gunn727c6bd2017-04-11 09:51:40 -0700107 * {@link TelecomManager#EXTRA_IS_HANDOVER}. Telecom will match the phone numbers of the
108 * handover call on the other device with ongoing calls for {@link ConnectionService}s which
109 * support {@link PhoneAccount#EXTRA_SUPPORTS_HANDOVER_FROM}.
Tyler Gunn8bf76572017-04-06 15:30:08 -0700110 * @hide
111 */
112 public static final String EXTRA_IS_HANDOVER = TelecomManager.EXTRA_IS_HANDOVER;
113
Ihab Awad542e0ea2014-05-16 10:22:16 -0700114 // Flag controlling whether PII is emitted into the logs
Ihab Awad60ac30b2014-05-20 22:32:12 -0700115 private static final boolean PII_DEBUG = Log.isLoggable(android.util.Log.DEBUG);
Ihab Awad542e0ea2014-05-16 10:22:16 -0700116
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700117 // Session Definitions
118 private static final String SESSION_HANDLER = "H.";
119 private static final String SESSION_ADD_CS_ADAPTER = "CS.aCSA";
120 private static final String SESSION_REMOVE_CS_ADAPTER = "CS.rCSA";
121 private static final String SESSION_CREATE_CONN = "CS.crCo";
Tyler Gunn041a1fe2017-05-12 10:04:49 -0700122 private static final String SESSION_CREATE_CONN_COMPLETE = "CS.crCoC";
Tyler Gunn44e01912017-01-31 10:49:05 -0800123 private static final String SESSION_CREATE_CONN_FAILED = "CS.crCoF";
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700124 private static final String SESSION_ABORT = "CS.ab";
125 private static final String SESSION_ANSWER = "CS.an";
126 private static final String SESSION_ANSWER_VIDEO = "CS.anV";
127 private static final String SESSION_REJECT = "CS.r";
128 private static final String SESSION_REJECT_MESSAGE = "CS.rWM";
129 private static final String SESSION_SILENCE = "CS.s";
130 private static final String SESSION_DISCONNECT = "CS.d";
131 private static final String SESSION_HOLD = "CS.h";
132 private static final String SESSION_UNHOLD = "CS.u";
133 private static final String SESSION_CALL_AUDIO_SC = "CS.cASC";
134 private static final String SESSION_PLAY_DTMF = "CS.pDT";
135 private static final String SESSION_STOP_DTMF = "CS.sDT";
136 private static final String SESSION_CONFERENCE = "CS.c";
137 private static final String SESSION_SPLIT_CONFERENCE = "CS.sFC";
138 private static final String SESSION_MERGE_CONFERENCE = "CS.mC";
139 private static final String SESSION_SWAP_CONFERENCE = "CS.sC";
140 private static final String SESSION_POST_DIAL_CONT = "CS.oPDC";
141 private static final String SESSION_PULL_EXTERNAL_CALL = "CS.pEC";
142 private static final String SESSION_SEND_CALL_EVENT = "CS.sCE";
143 private static final String SESSION_EXTRAS_CHANGED = "CS.oEC";
Hall Liub64ac4c2017-02-06 10:49:48 -0800144 private static final String SESSION_START_RTT = "CS.+RTT";
145 private static final String SESSION_STOP_RTT = "CS.-RTT";
146 private static final String SESSION_RTT_UPGRADE_RESPONSE = "CS.rTRUR";
Sanket Padawe02d8c272017-12-20 10:13:05 -0800147 private static final String SESSION_HANDOVER_FAILED = "CS.haF";
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700148
Ihab Awad8aecfed2014-08-08 17:06:11 -0700149 private static final int MSG_ADD_CONNECTION_SERVICE_ADAPTER = 1;
Sailesh Nepalc5b01572014-07-14 16:29:44 -0700150 private static final int MSG_CREATE_CONNECTION = 2;
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700151 private static final int MSG_ABORT = 3;
Sailesh Nepalc5b01572014-07-14 16:29:44 -0700152 private static final int MSG_ANSWER = 4;
153 private static final int MSG_REJECT = 5;
154 private static final int MSG_DISCONNECT = 6;
155 private static final int MSG_HOLD = 7;
156 private static final int MSG_UNHOLD = 8;
Yorke Lee4af59352015-05-13 14:14:54 -0700157 private static final int MSG_ON_CALL_AUDIO_STATE_CHANGED = 9;
Sailesh Nepalc5b01572014-07-14 16:29:44 -0700158 private static final int MSG_PLAY_DTMF_TONE = 10;
159 private static final int MSG_STOP_DTMF_TONE = 11;
160 private static final int MSG_CONFERENCE = 12;
161 private static final int MSG_SPLIT_FROM_CONFERENCE = 13;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700162 private static final int MSG_ON_POST_DIAL_CONTINUE = 14;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700163 private static final int MSG_REMOVE_CONNECTION_SERVICE_ADAPTER = 16;
Tyler Gunnbe74de02014-08-29 14:51:48 -0700164 private static final int MSG_ANSWER_VIDEO = 17;
Santos Cordona4868042014-09-04 17:39:22 -0700165 private static final int MSG_MERGE_CONFERENCE = 18;
166 private static final int MSG_SWAP_CONFERENCE = 19;
Bryce Lee81901682015-08-28 16:38:02 -0700167 private static final int MSG_REJECT_WITH_MESSAGE = 20;
Bryce Leecac50772015-11-17 15:13:29 -0800168 private static final int MSG_SILENCE = 21;
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700169 private static final int MSG_PULL_EXTERNAL_CALL = 22;
170 private static final int MSG_SEND_CALL_EVENT = 23;
Tyler Gunndee56a82016-03-23 16:06:34 -0700171 private static final int MSG_ON_EXTRAS_CHANGED = 24;
Tyler Gunn44e01912017-01-31 10:49:05 -0800172 private static final int MSG_CREATE_CONNECTION_FAILED = 25;
Hall Liub64ac4c2017-02-06 10:49:48 -0800173 private static final int MSG_ON_START_RTT = 26;
174 private static final int MSG_ON_STOP_RTT = 27;
175 private static final int MSG_RTT_UPGRADE_RESPONSE = 28;
Tyler Gunn041a1fe2017-05-12 10:04:49 -0700176 private static final int MSG_CREATE_CONNECTION_COMPLETE = 29;
Sanket Padawe02d8c272017-12-20 10:13:05 -0800177 private static final int MSG_HANDOVER_FAILED = 32;
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700178
Sailesh Nepalcf7020b2014-08-20 10:07:19 -0700179 private static Connection sNullConnection;
180
mike dooley95e80702014-09-18 14:07:52 -0700181 private final Map<String, Connection> mConnectionById = new ConcurrentHashMap<>();
182 private final Map<Connection, String> mIdByConnection = new ConcurrentHashMap<>();
183 private final Map<String, Conference> mConferenceById = new ConcurrentHashMap<>();
184 private final Map<Conference, String> mIdByConference = new ConcurrentHashMap<>();
Ihab Awadb8e85c72014-08-23 20:34:57 -0700185 private final RemoteConnectionManager mRemoteConnectionManager =
186 new RemoteConnectionManager(this);
Ihab Awad5d0410f2014-07-30 10:07:40 -0700187 private final List<Runnable> mPreInitializationConnectionRequests = new ArrayList<>();
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700188 private final ConnectionServiceAdapter mAdapter = new ConnectionServiceAdapter();
Ihab Awad542e0ea2014-05-16 10:22:16 -0700189
Santos Cordon823fd3c2014-08-07 18:35:18 -0700190 private boolean mAreAccountsInitialized = false;
Santos Cordon0159ac02014-08-21 14:28:11 -0700191 private Conference sNullConference;
Tyler Gunnf0500bd2015-09-01 10:59:48 -0700192 private Object mIdSyncRoot = new Object();
193 private int mId = 0;
Santos Cordon823fd3c2014-08-07 18:35:18 -0700194
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700195 private final IBinder mBinder = new IConnectionService.Stub() {
196 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700197 public void addConnectionServiceAdapter(IConnectionServiceAdapter adapter,
198 Session.Info sessionInfo) {
199 Log.startSession(sessionInfo, SESSION_ADD_CS_ADAPTER);
200 try {
201 SomeArgs args = SomeArgs.obtain();
202 args.arg1 = adapter;
203 args.arg2 = Log.createSubsession();
204 mHandler.obtainMessage(MSG_ADD_CONNECTION_SERVICE_ADAPTER, args).sendToTarget();
205 } finally {
206 Log.endSession();
207 }
Ihab Awad8aecfed2014-08-08 17:06:11 -0700208 }
209
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700210 public void removeConnectionServiceAdapter(IConnectionServiceAdapter adapter,
211 Session.Info sessionInfo) {
212 Log.startSession(sessionInfo, SESSION_REMOVE_CS_ADAPTER);
213 try {
214 SomeArgs args = SomeArgs.obtain();
215 args.arg1 = adapter;
216 args.arg2 = Log.createSubsession();
217 mHandler.obtainMessage(MSG_REMOVE_CONNECTION_SERVICE_ADAPTER, args).sendToTarget();
218 } finally {
219 Log.endSession();
220 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700221 }
222
223 @Override
Ihab Awadf8b69882014-07-25 15:14:01 -0700224 public void createConnection(
225 PhoneAccountHandle connectionManagerPhoneAccount,
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700226 String id,
Ihab Awadf8b69882014-07-25 15:14:01 -0700227 ConnectionRequest request,
Yorke Leec3cf9822014-10-02 09:38:39 -0700228 boolean isIncoming,
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700229 boolean isUnknown,
230 Session.Info sessionInfo) {
231 Log.startSession(sessionInfo, SESSION_CREATE_CONN);
232 try {
233 SomeArgs args = SomeArgs.obtain();
234 args.arg1 = connectionManagerPhoneAccount;
235 args.arg2 = id;
236 args.arg3 = request;
237 args.arg4 = Log.createSubsession();
238 args.argi1 = isIncoming ? 1 : 0;
239 args.argi2 = isUnknown ? 1 : 0;
240 mHandler.obtainMessage(MSG_CREATE_CONNECTION, args).sendToTarget();
241 } finally {
242 Log.endSession();
243 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700244 }
245
246 @Override
Tyler Gunn041a1fe2017-05-12 10:04:49 -0700247 public void createConnectionComplete(String id, Session.Info sessionInfo) {
248 Log.startSession(sessionInfo, SESSION_CREATE_CONN_COMPLETE);
249 try {
250 SomeArgs args = SomeArgs.obtain();
251 args.arg1 = id;
252 args.arg2 = Log.createSubsession();
253 mHandler.obtainMessage(MSG_CREATE_CONNECTION_COMPLETE, args).sendToTarget();
254 } finally {
255 Log.endSession();
256 }
257 }
258
259 @Override
Tyler Gunn44e01912017-01-31 10:49:05 -0800260 public void createConnectionFailed(
Tyler Gunn159f35c2017-03-02 09:28:37 -0800261 PhoneAccountHandle connectionManagerPhoneAccount,
Tyler Gunn44e01912017-01-31 10:49:05 -0800262 String callId,
263 ConnectionRequest request,
264 boolean isIncoming,
265 Session.Info sessionInfo) {
266 Log.startSession(sessionInfo, SESSION_CREATE_CONN_FAILED);
267 try {
268 SomeArgs args = SomeArgs.obtain();
269 args.arg1 = callId;
270 args.arg2 = request;
271 args.arg3 = Log.createSubsession();
Tyler Gunn159f35c2017-03-02 09:28:37 -0800272 args.arg4 = connectionManagerPhoneAccount;
Tyler Gunn44e01912017-01-31 10:49:05 -0800273 args.argi1 = isIncoming ? 1 : 0;
274 mHandler.obtainMessage(MSG_CREATE_CONNECTION_FAILED, args).sendToTarget();
275 } finally {
276 Log.endSession();
277 }
278 }
279
280 @Override
Sanket Padawe02d8c272017-12-20 10:13:05 -0800281 public void handoverFailed(String callId, ConnectionRequest request, int reason,
282 Session.Info sessionInfo) {
283 Log.startSession(sessionInfo, SESSION_HANDOVER_FAILED);
284 try {
285 SomeArgs args = SomeArgs.obtain();
286 args.arg1 = callId;
287 args.arg2 = request;
288 args.arg3 = Log.createSubsession();
289 args.arg4 = reason;
290 mHandler.obtainMessage(MSG_HANDOVER_FAILED, args).sendToTarget();
291 } finally {
292 Log.endSession();
293 }
294 }
295
296 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700297 public void abort(String callId, Session.Info sessionInfo) {
298 Log.startSession(sessionInfo, SESSION_ABORT);
299 try {
300 SomeArgs args = SomeArgs.obtain();
301 args.arg1 = callId;
302 args.arg2 = Log.createSubsession();
303 mHandler.obtainMessage(MSG_ABORT, args).sendToTarget();
304 } finally {
305 Log.endSession();
306 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700307 }
308
309 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700310 public void answerVideo(String callId, int videoState, Session.Info sessionInfo) {
311 Log.startSession(sessionInfo, SESSION_ANSWER_VIDEO);
312 try {
313 SomeArgs args = SomeArgs.obtain();
314 args.arg1 = callId;
315 args.arg2 = Log.createSubsession();
316 args.argi1 = videoState;
317 mHandler.obtainMessage(MSG_ANSWER_VIDEO, args).sendToTarget();
318 } finally {
319 Log.endSession();
320 }
Tyler Gunnbe74de02014-08-29 14:51:48 -0700321 }
322
323 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700324 public void answer(String callId, Session.Info sessionInfo) {
325 Log.startSession(sessionInfo, SESSION_ANSWER);
326 try {
327 SomeArgs args = SomeArgs.obtain();
328 args.arg1 = callId;
329 args.arg2 = Log.createSubsession();
330 mHandler.obtainMessage(MSG_ANSWER, args).sendToTarget();
331 } finally {
332 Log.endSession();
333 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700334 }
335
336 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700337 public void reject(String callId, Session.Info sessionInfo) {
338 Log.startSession(sessionInfo, SESSION_REJECT);
339 try {
340 SomeArgs args = SomeArgs.obtain();
341 args.arg1 = callId;
342 args.arg2 = Log.createSubsession();
343 mHandler.obtainMessage(MSG_REJECT, args).sendToTarget();
344 } finally {
345 Log.endSession();
346 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700347 }
348
349 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700350 public void rejectWithMessage(String callId, String message, Session.Info sessionInfo) {
351 Log.startSession(sessionInfo, SESSION_REJECT_MESSAGE);
352 try {
353 SomeArgs args = SomeArgs.obtain();
354 args.arg1 = callId;
355 args.arg2 = message;
356 args.arg3 = Log.createSubsession();
357 mHandler.obtainMessage(MSG_REJECT_WITH_MESSAGE, args).sendToTarget();
358 } finally {
359 Log.endSession();
360 }
Bryce Lee81901682015-08-28 16:38:02 -0700361 }
362
363 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700364 public void silence(String callId, Session.Info sessionInfo) {
365 Log.startSession(sessionInfo, SESSION_SILENCE);
366 try {
367 SomeArgs args = SomeArgs.obtain();
368 args.arg1 = callId;
369 args.arg2 = Log.createSubsession();
370 mHandler.obtainMessage(MSG_SILENCE, args).sendToTarget();
371 } finally {
372 Log.endSession();
373 }
Bryce Leecac50772015-11-17 15:13:29 -0800374 }
375
376 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700377 public void disconnect(String callId, Session.Info sessionInfo) {
378 Log.startSession(sessionInfo, SESSION_DISCONNECT);
379 try {
380 SomeArgs args = SomeArgs.obtain();
381 args.arg1 = callId;
382 args.arg2 = Log.createSubsession();
383 mHandler.obtainMessage(MSG_DISCONNECT, 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 hold(String callId, Session.Info sessionInfo) {
391 Log.startSession(sessionInfo, SESSION_HOLD);
392 try {
393 SomeArgs args = SomeArgs.obtain();
394 args.arg1 = callId;
395 args.arg2 = Log.createSubsession();
396 mHandler.obtainMessage(MSG_HOLD, args).sendToTarget();
397 } finally {
398 Log.endSession();
399 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700400 }
401
402 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700403 public void unhold(String callId, Session.Info sessionInfo) {
404 Log.startSession(sessionInfo, SESSION_UNHOLD);
405 try {
406 SomeArgs args = SomeArgs.obtain();
407 args.arg1 = callId;
408 args.arg2 = Log.createSubsession();
409 mHandler.obtainMessage(MSG_UNHOLD, args).sendToTarget();
410 } finally {
411 Log.endSession();
412 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700413 }
414
415 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700416 public void onCallAudioStateChanged(String callId, CallAudioState callAudioState,
417 Session.Info sessionInfo) {
418 Log.startSession(sessionInfo, SESSION_CALL_AUDIO_SC);
419 try {
420 SomeArgs args = SomeArgs.obtain();
421 args.arg1 = callId;
422 args.arg2 = callAudioState;
423 args.arg3 = Log.createSubsession();
424 mHandler.obtainMessage(MSG_ON_CALL_AUDIO_STATE_CHANGED, args).sendToTarget();
425 } finally {
426 Log.endSession();
427 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700428 }
429
430 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700431 public void playDtmfTone(String callId, char digit, Session.Info sessionInfo) {
432 Log.startSession(sessionInfo, SESSION_PLAY_DTMF);
433 try {
434 SomeArgs args = SomeArgs.obtain();
435 args.arg1 = digit;
436 args.arg2 = callId;
437 args.arg3 = Log.createSubsession();
438 mHandler.obtainMessage(MSG_PLAY_DTMF_TONE, args).sendToTarget();
439 } finally {
440 Log.endSession();
441 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700442 }
443
444 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700445 public void stopDtmfTone(String callId, Session.Info sessionInfo) {
446 Log.startSession(sessionInfo, SESSION_STOP_DTMF);
447 try {
448 SomeArgs args = SomeArgs.obtain();
449 args.arg1 = callId;
450 args.arg2 = Log.createSubsession();
451 mHandler.obtainMessage(MSG_STOP_DTMF_TONE, args).sendToTarget();
452 } finally {
453 Log.endSession();
454 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700455 }
456
457 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700458 public void conference(String callId1, String callId2, Session.Info sessionInfo) {
459 Log.startSession(sessionInfo, SESSION_CONFERENCE);
460 try {
461 SomeArgs args = SomeArgs.obtain();
462 args.arg1 = callId1;
463 args.arg2 = callId2;
464 args.arg3 = Log.createSubsession();
465 mHandler.obtainMessage(MSG_CONFERENCE, args).sendToTarget();
466 } finally {
467 Log.endSession();
468 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700469 }
470
471 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700472 public void splitFromConference(String callId, Session.Info sessionInfo) {
473 Log.startSession(sessionInfo, SESSION_SPLIT_CONFERENCE);
474 try {
475 SomeArgs args = SomeArgs.obtain();
476 args.arg1 = callId;
477 args.arg2 = Log.createSubsession();
478 mHandler.obtainMessage(MSG_SPLIT_FROM_CONFERENCE, 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 mergeConference(String callId, Session.Info sessionInfo) {
486 Log.startSession(sessionInfo, SESSION_MERGE_CONFERENCE);
487 try {
488 SomeArgs args = SomeArgs.obtain();
489 args.arg1 = callId;
490 args.arg2 = Log.createSubsession();
491 mHandler.obtainMessage(MSG_MERGE_CONFERENCE, args).sendToTarget();
492 } finally {
493 Log.endSession();
494 }
Santos Cordona4868042014-09-04 17:39:22 -0700495 }
496
497 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700498 public void swapConference(String callId, Session.Info sessionInfo) {
499 Log.startSession(sessionInfo, SESSION_SWAP_CONFERENCE);
500 try {
501 SomeArgs args = SomeArgs.obtain();
502 args.arg1 = callId;
503 args.arg2 = Log.createSubsession();
504 mHandler.obtainMessage(MSG_SWAP_CONFERENCE, args).sendToTarget();
505 } finally {
506 Log.endSession();
507 }
Santos Cordona4868042014-09-04 17:39:22 -0700508 }
509
510 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700511 public void onPostDialContinue(String callId, boolean proceed, Session.Info sessionInfo) {
512 Log.startSession(sessionInfo, SESSION_POST_DIAL_CONT);
513 try {
514 SomeArgs args = SomeArgs.obtain();
515 args.arg1 = callId;
516 args.arg2 = Log.createSubsession();
517 args.argi1 = proceed ? 1 : 0;
518 mHandler.obtainMessage(MSG_ON_POST_DIAL_CONTINUE, args).sendToTarget();
519 } finally {
520 Log.endSession();
521 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700522 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700523
524 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700525 public void pullExternalCall(String callId, Session.Info sessionInfo) {
526 Log.startSession(sessionInfo, SESSION_PULL_EXTERNAL_CALL);
527 try {
528 SomeArgs args = SomeArgs.obtain();
529 args.arg1 = callId;
530 args.arg2 = Log.createSubsession();
531 mHandler.obtainMessage(MSG_PULL_EXTERNAL_CALL, args).sendToTarget();
532 } finally {
533 Log.endSession();
534 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700535 }
536
537 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700538 public void sendCallEvent(String callId, String event, Bundle extras,
539 Session.Info sessionInfo) {
540 Log.startSession(sessionInfo, SESSION_SEND_CALL_EVENT);
541 try {
542 SomeArgs args = SomeArgs.obtain();
543 args.arg1 = callId;
544 args.arg2 = event;
545 args.arg3 = extras;
546 args.arg4 = Log.createSubsession();
547 mHandler.obtainMessage(MSG_SEND_CALL_EVENT, args).sendToTarget();
548 } finally {
549 Log.endSession();
550 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700551 }
Tyler Gunndee56a82016-03-23 16:06:34 -0700552
553 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700554 public void onExtrasChanged(String callId, Bundle extras, Session.Info sessionInfo) {
555 Log.startSession(sessionInfo, SESSION_EXTRAS_CHANGED);
556 try {
557 SomeArgs args = SomeArgs.obtain();
558 args.arg1 = callId;
559 args.arg2 = extras;
560 args.arg3 = Log.createSubsession();
561 mHandler.obtainMessage(MSG_ON_EXTRAS_CHANGED, args).sendToTarget();
562 } finally {
563 Log.endSession();
564 }
Tyler Gunndee56a82016-03-23 16:06:34 -0700565 }
Hall Liub64ac4c2017-02-06 10:49:48 -0800566
567 @Override
568 public void startRtt(String callId, ParcelFileDescriptor fromInCall,
569 ParcelFileDescriptor toInCall, Session.Info sessionInfo) throws RemoteException {
570 Log.startSession(sessionInfo, SESSION_START_RTT);
571 try {
572 SomeArgs args = SomeArgs.obtain();
573 args.arg1 = callId;
574 args.arg2 = new Connection.RttTextStream(toInCall, fromInCall);
575 args.arg3 = Log.createSubsession();
576 mHandler.obtainMessage(MSG_ON_START_RTT, args).sendToTarget();
577 } finally {
578 Log.endSession();
579 }
580 }
581
582 @Override
583 public void stopRtt(String callId, Session.Info sessionInfo) throws RemoteException {
584 Log.startSession(sessionInfo, SESSION_STOP_RTT);
585 try {
586 SomeArgs args = SomeArgs.obtain();
587 args.arg1 = callId;
588 args.arg2 = Log.createSubsession();
589 mHandler.obtainMessage(MSG_ON_STOP_RTT, args).sendToTarget();
590 } finally {
591 Log.endSession();
592 }
593 }
594
595 @Override
596 public void respondToRttUpgradeRequest(String callId, ParcelFileDescriptor fromInCall,
597 ParcelFileDescriptor toInCall, Session.Info sessionInfo) throws RemoteException {
598 Log.startSession(sessionInfo, SESSION_RTT_UPGRADE_RESPONSE);
599 try {
600 SomeArgs args = SomeArgs.obtain();
601 args.arg1 = callId;
602 if (toInCall == null || fromInCall == null) {
603 args.arg2 = null;
604 } else {
605 args.arg2 = new Connection.RttTextStream(toInCall, fromInCall);
606 }
607 args.arg3 = Log.createSubsession();
608 mHandler.obtainMessage(MSG_RTT_UPGRADE_RESPONSE, args).sendToTarget();
609 } finally {
610 Log.endSession();
611 }
612 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700613 };
614
615 private final Handler mHandler = new Handler(Looper.getMainLooper()) {
616 @Override
617 public void handleMessage(Message msg) {
618 switch (msg.what) {
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700619 case MSG_ADD_CONNECTION_SERVICE_ADAPTER: {
620 SomeArgs args = (SomeArgs) msg.obj;
621 try {
622 IConnectionServiceAdapter adapter = (IConnectionServiceAdapter) args.arg1;
623 Log.continueSession((Session) args.arg2,
624 SESSION_HANDLER + SESSION_ADD_CS_ADAPTER);
625 mAdapter.addAdapter(adapter);
626 onAdapterAttached();
627 } finally {
628 args.recycle();
629 Log.endSession();
630 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700631 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700632 }
633 case MSG_REMOVE_CONNECTION_SERVICE_ADAPTER: {
634 SomeArgs args = (SomeArgs) msg.obj;
635 try {
636 Log.continueSession((Session) args.arg2,
637 SESSION_HANDLER + SESSION_REMOVE_CS_ADAPTER);
638 mAdapter.removeAdapter((IConnectionServiceAdapter) args.arg1);
639 } finally {
640 args.recycle();
641 Log.endSession();
642 }
Ihab Awad8aecfed2014-08-08 17:06:11 -0700643 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700644 }
Ihab Awadf8b69882014-07-25 15:14:01 -0700645 case MSG_CREATE_CONNECTION: {
646 SomeArgs args = (SomeArgs) msg.obj;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700647 Log.continueSession((Session) args.arg4, SESSION_HANDLER + SESSION_CREATE_CONN);
Ihab Awadf8b69882014-07-25 15:14:01 -0700648 try {
Ihab Awad5d0410f2014-07-30 10:07:40 -0700649 final PhoneAccountHandle connectionManagerPhoneAccount =
Ihab Awadf8b69882014-07-25 15:14:01 -0700650 (PhoneAccountHandle) args.arg1;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700651 final String id = (String) args.arg2;
652 final ConnectionRequest request = (ConnectionRequest) args.arg3;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700653 final boolean isIncoming = args.argi1 == 1;
Yorke Leec3cf9822014-10-02 09:38:39 -0700654 final boolean isUnknown = args.argi2 == 1;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700655 if (!mAreAccountsInitialized) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700656 Log.d(this, "Enqueueing pre-init request %s", id);
Brad Ebinger0c3541b2016-11-01 14:11:38 -0700657 mPreInitializationConnectionRequests.add(
658 new android.telecom.Logging.Runnable(
659 SESSION_HANDLER + SESSION_CREATE_CONN + ".pICR",
660 null /*lock*/) {
Ihab Awad5d0410f2014-07-30 10:07:40 -0700661 @Override
Brad Ebinger0c3541b2016-11-01 14:11:38 -0700662 public void loggedRun() {
Ihab Awad5d0410f2014-07-30 10:07:40 -0700663 createConnection(
664 connectionManagerPhoneAccount,
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700665 id,
Ihab Awad5d0410f2014-07-30 10:07:40 -0700666 request,
Yorke Leec3cf9822014-10-02 09:38:39 -0700667 isIncoming,
668 isUnknown);
Ihab Awad5d0410f2014-07-30 10:07:40 -0700669 }
Brad Ebinger0c3541b2016-11-01 14:11:38 -0700670 }.prepare());
Ihab Awad5d0410f2014-07-30 10:07:40 -0700671 } else {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700672 createConnection(
673 connectionManagerPhoneAccount,
674 id,
675 request,
Yorke Leec3cf9822014-10-02 09:38:39 -0700676 isIncoming,
677 isUnknown);
Ihab Awad5d0410f2014-07-30 10:07:40 -0700678 }
Ihab Awadf8b69882014-07-25 15:14:01 -0700679 } finally {
680 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700681 Log.endSession();
Ihab Awadf8b69882014-07-25 15:14:01 -0700682 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700683 break;
Ihab Awadf8b69882014-07-25 15:14:01 -0700684 }
Tyler Gunn041a1fe2017-05-12 10:04:49 -0700685 case MSG_CREATE_CONNECTION_COMPLETE: {
686 SomeArgs args = (SomeArgs) msg.obj;
687 Log.continueSession((Session) args.arg2,
688 SESSION_HANDLER + SESSION_CREATE_CONN_COMPLETE);
689 try {
690 final String id = (String) args.arg1;
691 if (!mAreAccountsInitialized) {
692 Log.d(this, "Enqueueing pre-init request %s", id);
693 mPreInitializationConnectionRequests.add(
694 new android.telecom.Logging.Runnable(
695 SESSION_HANDLER + SESSION_CREATE_CONN_COMPLETE
696 + ".pICR",
697 null /*lock*/) {
698 @Override
699 public void loggedRun() {
700 notifyCreateConnectionComplete(id);
701 }
702 }.prepare());
703 } else {
704 notifyCreateConnectionComplete(id);
705 }
706 } finally {
707 args.recycle();
708 Log.endSession();
709 }
710 break;
711 }
Tyler Gunn44e01912017-01-31 10:49:05 -0800712 case MSG_CREATE_CONNECTION_FAILED: {
713 SomeArgs args = (SomeArgs) msg.obj;
714 Log.continueSession((Session) args.arg3, SESSION_HANDLER +
715 SESSION_CREATE_CONN_FAILED);
716 try {
717 final String id = (String) args.arg1;
718 final ConnectionRequest request = (ConnectionRequest) args.arg2;
719 final boolean isIncoming = args.argi1 == 1;
Tyler Gunn159f35c2017-03-02 09:28:37 -0800720 final PhoneAccountHandle connectionMgrPhoneAccount =
721 (PhoneAccountHandle) args.arg4;
Tyler Gunn44e01912017-01-31 10:49:05 -0800722 if (!mAreAccountsInitialized) {
723 Log.d(this, "Enqueueing pre-init request %s", id);
724 mPreInitializationConnectionRequests.add(
725 new android.telecom.Logging.Runnable(
726 SESSION_HANDLER + SESSION_CREATE_CONN_FAILED + ".pICR",
727 null /*lock*/) {
728 @Override
729 public void loggedRun() {
Tyler Gunn159f35c2017-03-02 09:28:37 -0800730 createConnectionFailed(connectionMgrPhoneAccount, id,
731 request, isIncoming);
Tyler Gunn44e01912017-01-31 10:49:05 -0800732 }
733 }.prepare());
734 } else {
735 Log.i(this, "createConnectionFailed %s", id);
Tyler Gunn159f35c2017-03-02 09:28:37 -0800736 createConnectionFailed(connectionMgrPhoneAccount, id, request,
737 isIncoming);
Tyler Gunn44e01912017-01-31 10:49:05 -0800738 }
739 } finally {
740 args.recycle();
741 Log.endSession();
742 }
743 break;
744 }
Sanket Padawe02d8c272017-12-20 10:13:05 -0800745 case MSG_HANDOVER_FAILED: {
746 SomeArgs args = (SomeArgs) msg.obj;
747 Log.continueSession((Session) args.arg3, SESSION_HANDLER +
748 SESSION_HANDOVER_FAILED);
749 try {
750 final String id = (String) args.arg1;
751 final ConnectionRequest request = (ConnectionRequest) args.arg2;
752 final int reason = (int) args.arg4;
753 if (!mAreAccountsInitialized) {
754 Log.d(this, "Enqueueing pre-init request %s", id);
755 mPreInitializationConnectionRequests.add(
756 new android.telecom.Logging.Runnable(
757 SESSION_HANDLER
758 + SESSION_HANDOVER_FAILED + ".pICR",
759 null /*lock*/) {
760 @Override
761 public void loggedRun() {
762 handoverFailed(id, request, reason);
763 }
764 }.prepare());
765 } else {
766 Log.i(this, "createConnectionFailed %s", id);
767 handoverFailed(id, request, reason);
768 }
769 } finally {
770 args.recycle();
771 Log.endSession();
772 }
773 break;
774 }
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700775 case MSG_ABORT: {
776 SomeArgs args = (SomeArgs) msg.obj;
777 Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_ABORT);
778 try {
779 abort((String) args.arg1);
780 } finally {
781 args.recycle();
782 Log.endSession();
783 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700784 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700785 }
786 case MSG_ANSWER: {
787 SomeArgs args = (SomeArgs) msg.obj;
788 Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_ANSWER);
789 try {
790 answer((String) args.arg1);
791 } finally {
792 args.recycle();
793 Log.endSession();
794 }
Tyler Gunnbe74de02014-08-29 14:51:48 -0700795 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700796 }
Tyler Gunnbe74de02014-08-29 14:51:48 -0700797 case MSG_ANSWER_VIDEO: {
Andrew Lee8da4c3c2014-07-16 10:11:42 -0700798 SomeArgs args = (SomeArgs) msg.obj;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700799 Log.continueSession((Session) args.arg2,
800 SESSION_HANDLER + SESSION_ANSWER_VIDEO);
Andrew Lee8da4c3c2014-07-16 10:11:42 -0700801 try {
802 String callId = (String) args.arg1;
Evan Charltonbf11f982014-07-20 22:06:28 -0700803 int videoState = args.argi1;
Tyler Gunnbe74de02014-08-29 14:51:48 -0700804 answerVideo(callId, videoState);
Andrew Lee8da4c3c2014-07-16 10:11:42 -0700805 } finally {
806 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700807 Log.endSession();
Andrew Lee8da4c3c2014-07-16 10:11:42 -0700808 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700809 break;
Andrew Lee8da4c3c2014-07-16 10:11:42 -0700810 }
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700811 case MSG_REJECT: {
812 SomeArgs args = (SomeArgs) msg.obj;
813 Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_REJECT);
814 try {
815 reject((String) args.arg1);
816 } finally {
817 args.recycle();
818 Log.endSession();
819 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700820 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700821 }
Bryce Lee81901682015-08-28 16:38:02 -0700822 case MSG_REJECT_WITH_MESSAGE: {
823 SomeArgs args = (SomeArgs) msg.obj;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700824 Log.continueSession((Session) args.arg3,
825 SESSION_HANDLER + SESSION_REJECT_MESSAGE);
Bryce Lee81901682015-08-28 16:38:02 -0700826 try {
827 reject((String) args.arg1, (String) args.arg2);
828 } finally {
829 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700830 Log.endSession();
Bryce Lee81901682015-08-28 16:38:02 -0700831 }
832 break;
833 }
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700834 case MSG_DISCONNECT: {
835 SomeArgs args = (SomeArgs) msg.obj;
836 Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_DISCONNECT);
837 try {
838 disconnect((String) args.arg1);
839 } finally {
840 args.recycle();
841 Log.endSession();
842 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700843 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700844 }
845 case MSG_SILENCE: {
846 SomeArgs args = (SomeArgs) msg.obj;
847 Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_SILENCE);
848 try {
849 silence((String) args.arg1);
850 } finally {
851 args.recycle();
852 Log.endSession();
853 }
Bryce Leecac50772015-11-17 15:13:29 -0800854 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700855 }
856 case MSG_HOLD: {
857 SomeArgs args = (SomeArgs) msg.obj;
858 Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_REJECT);
859 try {
860 hold((String) args.arg1);
861 } finally {
862 args.recycle();
863 Log.endSession();
864 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700865 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700866 }
867 case MSG_UNHOLD: {
868 SomeArgs args = (SomeArgs) msg.obj;
869 Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_UNHOLD);
870 try {
871 unhold((String) args.arg1);
872 } finally {
873 args.recycle();
874 Log.endSession();
875 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700876 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700877 }
Yorke Lee4af59352015-05-13 14:14:54 -0700878 case MSG_ON_CALL_AUDIO_STATE_CHANGED: {
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700879 SomeArgs args = (SomeArgs) msg.obj;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700880 Log.continueSession((Session) args.arg3,
881 SESSION_HANDLER + SESSION_CALL_AUDIO_SC);
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700882 try {
883 String callId = (String) args.arg1;
Yorke Lee4af59352015-05-13 14:14:54 -0700884 CallAudioState audioState = (CallAudioState) args.arg2;
885 onCallAudioStateChanged(callId, new CallAudioState(audioState));
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700886 } finally {
887 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700888 Log.endSession();
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700889 }
890 break;
891 }
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700892 case MSG_PLAY_DTMF_TONE: {
893 SomeArgs args = (SomeArgs) msg.obj;
894 try {
895 Log.continueSession((Session) args.arg3,
896 SESSION_HANDLER + SESSION_PLAY_DTMF);
897 playDtmfTone((String) args.arg2, (char) args.arg1);
898 } finally {
899 args.recycle();
900 Log.endSession();
901 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700902 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700903 }
904 case MSG_STOP_DTMF_TONE: {
905 SomeArgs args = (SomeArgs) msg.obj;
906 try {
907 Log.continueSession((Session) args.arg2,
908 SESSION_HANDLER + SESSION_STOP_DTMF);
909 stopDtmfTone((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 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700916 case MSG_CONFERENCE: {
917 SomeArgs args = (SomeArgs) msg.obj;
918 try {
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700919 Log.continueSession((Session) args.arg3,
920 SESSION_HANDLER + SESSION_CONFERENCE);
Santos Cordon823fd3c2014-08-07 18:35:18 -0700921 String callId1 = (String) args.arg1;
922 String callId2 = (String) args.arg2;
923 conference(callId1, callId2);
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700924 } finally {
925 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700926 Log.endSession();
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700927 }
928 break;
929 }
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700930 case MSG_SPLIT_FROM_CONFERENCE: {
931 SomeArgs args = (SomeArgs) msg.obj;
932 try {
933 Log.continueSession((Session) args.arg2,
934 SESSION_HANDLER + SESSION_SPLIT_CONFERENCE);
935 splitFromConference((String) args.arg1);
936 } finally {
937 args.recycle();
938 Log.endSession();
939 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700940 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700941 }
942 case MSG_MERGE_CONFERENCE: {
943 SomeArgs args = (SomeArgs) msg.obj;
944 try {
945 Log.continueSession((Session) args.arg2,
946 SESSION_HANDLER + SESSION_MERGE_CONFERENCE);
947 mergeConference((String) args.arg1);
948 } finally {
949 args.recycle();
950 Log.endSession();
951 }
Santos Cordona4868042014-09-04 17:39:22 -0700952 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700953 }
954 case MSG_SWAP_CONFERENCE: {
955 SomeArgs args = (SomeArgs) msg.obj;
956 try {
957 Log.continueSession((Session) args.arg2,
958 SESSION_HANDLER + SESSION_SWAP_CONFERENCE);
959 swapConference((String) args.arg1);
960 } finally {
961 args.recycle();
962 Log.endSession();
963 }
Santos Cordona4868042014-09-04 17:39:22 -0700964 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700965 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700966 case MSG_ON_POST_DIAL_CONTINUE: {
967 SomeArgs args = (SomeArgs) msg.obj;
968 try {
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700969 Log.continueSession((Session) args.arg2,
970 SESSION_HANDLER + SESSION_POST_DIAL_CONT);
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700971 String callId = (String) args.arg1;
972 boolean proceed = (args.argi1 == 1);
973 onPostDialContinue(callId, proceed);
974 } finally {
975 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700976 Log.endSession();
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700977 }
978 break;
979 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700980 case MSG_PULL_EXTERNAL_CALL: {
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700981 SomeArgs args = (SomeArgs) msg.obj;
982 try {
983 Log.continueSession((Session) args.arg2,
984 SESSION_HANDLER + SESSION_PULL_EXTERNAL_CALL);
985 pullExternalCall((String) args.arg1);
986 } finally {
987 args.recycle();
988 Log.endSession();
989 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700990 break;
991 }
992 case MSG_SEND_CALL_EVENT: {
993 SomeArgs args = (SomeArgs) msg.obj;
994 try {
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700995 Log.continueSession((Session) args.arg4,
996 SESSION_HANDLER + SESSION_SEND_CALL_EVENT);
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700997 String callId = (String) args.arg1;
998 String event = (String) args.arg2;
999 Bundle extras = (Bundle) args.arg3;
1000 sendCallEvent(callId, event, extras);
1001 } finally {
1002 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001003 Log.endSession();
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001004 }
1005 break;
1006 }
Tyler Gunndee56a82016-03-23 16:06:34 -07001007 case MSG_ON_EXTRAS_CHANGED: {
1008 SomeArgs args = (SomeArgs) msg.obj;
1009 try {
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001010 Log.continueSession((Session) args.arg3,
1011 SESSION_HANDLER + SESSION_EXTRAS_CHANGED);
Tyler Gunndee56a82016-03-23 16:06:34 -07001012 String callId = (String) args.arg1;
1013 Bundle extras = (Bundle) args.arg2;
1014 handleExtrasChanged(callId, extras);
1015 } finally {
1016 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001017 Log.endSession();
Tyler Gunndee56a82016-03-23 16:06:34 -07001018 }
1019 break;
1020 }
Hall Liub64ac4c2017-02-06 10:49:48 -08001021 case MSG_ON_START_RTT: {
1022 SomeArgs args = (SomeArgs) msg.obj;
1023 try {
1024 Log.continueSession((Session) args.arg3,
1025 SESSION_HANDLER + SESSION_START_RTT);
1026 String callId = (String) args.arg1;
1027 Connection.RttTextStream rttTextStream =
1028 (Connection.RttTextStream) args.arg2;
1029 startRtt(callId, rttTextStream);
1030 } finally {
1031 args.recycle();
1032 Log.endSession();
1033 }
1034 break;
1035 }
1036 case MSG_ON_STOP_RTT: {
1037 SomeArgs args = (SomeArgs) msg.obj;
1038 try {
1039 Log.continueSession((Session) args.arg2,
1040 SESSION_HANDLER + SESSION_STOP_RTT);
1041 String callId = (String) args.arg1;
1042 stopRtt(callId);
1043 } finally {
1044 args.recycle();
1045 Log.endSession();
1046 }
1047 break;
1048 }
1049 case MSG_RTT_UPGRADE_RESPONSE: {
1050 SomeArgs args = (SomeArgs) msg.obj;
1051 try {
1052 Log.continueSession((Session) args.arg3,
1053 SESSION_HANDLER + SESSION_RTT_UPGRADE_RESPONSE);
1054 String callId = (String) args.arg1;
1055 Connection.RttTextStream rttTextStream =
1056 (Connection.RttTextStream) args.arg2;
1057 handleRttUpgradeResponse(callId, rttTextStream);
1058 } finally {
1059 args.recycle();
1060 Log.endSession();
1061 }
1062 break;
1063 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001064 default:
1065 break;
1066 }
1067 }
1068 };
1069
Santos Cordon823fd3c2014-08-07 18:35:18 -07001070 private final Conference.Listener mConferenceListener = new Conference.Listener() {
1071 @Override
1072 public void onStateChanged(Conference conference, int oldState, int newState) {
1073 String id = mIdByConference.get(conference);
1074 switch (newState) {
1075 case Connection.STATE_ACTIVE:
1076 mAdapter.setActive(id);
1077 break;
1078 case Connection.STATE_HOLDING:
1079 mAdapter.setOnHold(id);
1080 break;
1081 case Connection.STATE_DISCONNECTED:
1082 // handled by onDisconnected
1083 break;
1084 }
1085 }
1086
1087 @Override
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001088 public void onDisconnected(Conference conference, DisconnectCause disconnectCause) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07001089 String id = mIdByConference.get(conference);
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001090 mAdapter.setDisconnected(id, disconnectCause);
Santos Cordon823fd3c2014-08-07 18:35:18 -07001091 }
1092
1093 @Override
1094 public void onConnectionAdded(Conference conference, Connection connection) {
1095 }
1096
1097 @Override
1098 public void onConnectionRemoved(Conference conference, Connection connection) {
1099 }
1100
1101 @Override
Ihab Awad50e35062014-09-30 09:17:03 -07001102 public void onConferenceableConnectionsChanged(
1103 Conference conference, List<Connection> conferenceableConnections) {
1104 mAdapter.setConferenceableConnections(
1105 mIdByConference.get(conference),
1106 createConnectionIdList(conferenceableConnections));
1107 }
1108
1109 @Override
Santos Cordon823fd3c2014-08-07 18:35:18 -07001110 public void onDestroyed(Conference conference) {
1111 removeConference(conference);
1112 }
1113
1114 @Override
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001115 public void onConnectionCapabilitiesChanged(
1116 Conference conference,
1117 int connectionCapabilities) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07001118 String id = mIdByConference.get(conference);
1119 Log.d(this, "call capabilities: conference: %s",
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001120 Connection.capabilitiesToString(connectionCapabilities));
1121 mAdapter.setConnectionCapabilities(id, connectionCapabilities);
Santos Cordon823fd3c2014-08-07 18:35:18 -07001122 }
Rekha Kumar07366812015-03-24 16:42:31 -07001123
1124 @Override
Tyler Gunn720c6642016-03-22 09:02:47 -07001125 public void onConnectionPropertiesChanged(
1126 Conference conference,
1127 int connectionProperties) {
1128 String id = mIdByConference.get(conference);
1129 Log.d(this, "call capabilities: conference: %s",
1130 Connection.propertiesToString(connectionProperties));
1131 mAdapter.setConnectionProperties(id, connectionProperties);
1132 }
1133
1134 @Override
Rekha Kumar07366812015-03-24 16:42:31 -07001135 public void onVideoStateChanged(Conference c, int videoState) {
1136 String id = mIdByConference.get(c);
1137 Log.d(this, "onVideoStateChanged set video state %d", videoState);
1138 mAdapter.setVideoState(id, videoState);
1139 }
1140
1141 @Override
1142 public void onVideoProviderChanged(Conference c, Connection.VideoProvider videoProvider) {
1143 String id = mIdByConference.get(c);
1144 Log.d(this, "onVideoProviderChanged: Connection: %s, VideoProvider: %s", c,
1145 videoProvider);
1146 mAdapter.setVideoProvider(id, videoProvider);
1147 }
Andrew Lee0f51da32015-04-16 13:11:55 -07001148
1149 @Override
Andrew Leeedc625f2015-04-14 13:38:12 -07001150 public void onStatusHintsChanged(Conference conference, StatusHints statusHints) {
1151 String id = mIdByConference.get(conference);
Tyler Gunndee56a82016-03-23 16:06:34 -07001152 if (id != null) {
1153 mAdapter.setStatusHints(id, statusHints);
1154 }
Andrew Leeedc625f2015-04-14 13:38:12 -07001155 }
Santos Cordon6b7f9552015-05-27 17:21:45 -07001156
1157 @Override
Tyler Gunndee56a82016-03-23 16:06:34 -07001158 public void onExtrasChanged(Conference c, Bundle extras) {
1159 String id = mIdByConference.get(c);
1160 if (id != null) {
1161 mAdapter.putExtras(id, extras);
1162 }
1163 }
1164
1165 @Override
1166 public void onExtrasRemoved(Conference c, List<String> keys) {
1167 String id = mIdByConference.get(c);
1168 if (id != null) {
1169 mAdapter.removeExtras(id, keys);
1170 }
Santos Cordon6b7f9552015-05-27 17:21:45 -07001171 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07001172 };
1173
Ihab Awad542e0ea2014-05-16 10:22:16 -07001174 private final Connection.Listener mConnectionListener = new Connection.Listener() {
1175 @Override
1176 public void onStateChanged(Connection c, int state) {
1177 String id = mIdByConnection.get(c);
Ihab Awad42b30e12014-05-22 09:49:34 -07001178 Log.d(this, "Adapter set state %s %s", id, Connection.stateToString(state));
Ihab Awad542e0ea2014-05-16 10:22:16 -07001179 switch (state) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001180 case Connection.STATE_ACTIVE:
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001181 mAdapter.setActive(id);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001182 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001183 case Connection.STATE_DIALING:
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001184 mAdapter.setDialing(id);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001185 break;
Tyler Gunnc96b5e02016-07-07 22:53:57 -07001186 case Connection.STATE_PULLING_CALL:
1187 mAdapter.setPulling(id);
1188 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001189 case Connection.STATE_DISCONNECTED:
Ihab Awad542e0ea2014-05-16 10:22:16 -07001190 // Handled in onDisconnected()
1191 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001192 case Connection.STATE_HOLDING:
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001193 mAdapter.setOnHold(id);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001194 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001195 case Connection.STATE_NEW:
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001196 // Nothing to tell Telecom
Ihab Awad542e0ea2014-05-16 10:22:16 -07001197 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001198 case Connection.STATE_RINGING:
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001199 mAdapter.setRinging(id);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001200 break;
1201 }
1202 }
1203
1204 @Override
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001205 public void onDisconnected(Connection c, DisconnectCause disconnectCause) {
Ihab Awad542e0ea2014-05-16 10:22:16 -07001206 String id = mIdByConnection.get(c);
Andrew Lee26786392014-09-16 18:14:59 -07001207 Log.d(this, "Adapter set disconnected %s", disconnectCause);
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001208 mAdapter.setDisconnected(id, disconnectCause);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001209 }
1210
1211 @Override
Tyler Gunnaa07df82014-07-17 07:50:22 -07001212 public void onVideoStateChanged(Connection c, int videoState) {
1213 String id = mIdByConnection.get(c);
1214 Log.d(this, "Adapter set video state %d", videoState);
1215 mAdapter.setVideoState(id, videoState);
1216 }
1217
1218 @Override
Andrew Lee100e2932014-09-08 15:34:24 -07001219 public void onAddressChanged(Connection c, Uri address, int presentation) {
Sailesh Nepal61203862014-07-11 14:50:13 -07001220 String id = mIdByConnection.get(c);
Andrew Lee100e2932014-09-08 15:34:24 -07001221 mAdapter.setAddress(id, address, presentation);
Sailesh Nepal61203862014-07-11 14:50:13 -07001222 }
1223
1224 @Override
1225 public void onCallerDisplayNameChanged(
1226 Connection c, String callerDisplayName, int presentation) {
1227 String id = mIdByConnection.get(c);
1228 mAdapter.setCallerDisplayName(id, callerDisplayName, presentation);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001229 }
1230
1231 @Override
Ihab Awad542e0ea2014-05-16 10:22:16 -07001232 public void onDestroyed(Connection c) {
1233 removeConnection(c);
1234 }
Ihab Awadf8358972014-05-28 16:46:42 -07001235
1236 @Override
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001237 public void onPostDialWait(Connection c, String remaining) {
Sailesh Nepal091768c2014-06-30 15:15:23 -07001238 String id = mIdByConnection.get(c);
1239 Log.d(this, "Adapter onPostDialWait %s, %s", c, remaining);
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001240 mAdapter.onPostDialWait(id, remaining);
Sailesh Nepal091768c2014-06-30 15:15:23 -07001241 }
1242
1243 @Override
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001244 public void onPostDialChar(Connection c, char nextChar) {
1245 String id = mIdByConnection.get(c);
1246 Log.d(this, "Adapter onPostDialChar %s, %s", c, nextChar);
1247 mAdapter.onPostDialChar(id, nextChar);
1248 }
1249
1250 @Override
Andrew Lee100e2932014-09-08 15:34:24 -07001251 public void onRingbackRequested(Connection c, boolean ringback) {
Ihab Awadf8358972014-05-28 16:46:42 -07001252 String id = mIdByConnection.get(c);
1253 Log.d(this, "Adapter onRingback %b", ringback);
Andrew Lee100e2932014-09-08 15:34:24 -07001254 mAdapter.setRingbackRequested(id, ringback);
Ihab Awadf8358972014-05-28 16:46:42 -07001255 }
Santos Cordonb6939982014-06-04 20:20:58 -07001256
1257 @Override
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001258 public void onConnectionCapabilitiesChanged(Connection c, int capabilities) {
Santos Cordonb6939982014-06-04 20:20:58 -07001259 String id = mIdByConnection.get(c);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001260 Log.d(this, "capabilities: parcelableconnection: %s",
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001261 Connection.capabilitiesToString(capabilities));
1262 mAdapter.setConnectionCapabilities(id, capabilities);
Santos Cordonb6939982014-06-04 20:20:58 -07001263 }
1264
Santos Cordonb6939982014-06-04 20:20:58 -07001265 @Override
Tyler Gunn720c6642016-03-22 09:02:47 -07001266 public void onConnectionPropertiesChanged(Connection c, int properties) {
1267 String id = mIdByConnection.get(c);
1268 Log.d(this, "properties: parcelableconnection: %s",
1269 Connection.propertiesToString(properties));
1270 mAdapter.setConnectionProperties(id, properties);
1271 }
1272
1273 @Override
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001274 public void onVideoProviderChanged(Connection c, Connection.VideoProvider videoProvider) {
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07001275 String id = mIdByConnection.get(c);
Rekha Kumar07366812015-03-24 16:42:31 -07001276 Log.d(this, "onVideoProviderChanged: Connection: %s, VideoProvider: %s", c,
1277 videoProvider);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001278 mAdapter.setVideoProvider(id, videoProvider);
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07001279 }
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001280
1281 @Override
Sailesh Nepal001bbbb2014-07-15 14:40:39 -07001282 public void onAudioModeIsVoipChanged(Connection c, boolean isVoip) {
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001283 String id = mIdByConnection.get(c);
Andrew Lee100e2932014-09-08 15:34:24 -07001284 mAdapter.setIsVoipAudioMode(id, isVoip);
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001285 }
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001286
1287 @Override
Sailesh Nepal001bbbb2014-07-15 14:40:39 -07001288 public void onStatusHintsChanged(Connection c, StatusHints statusHints) {
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001289 String id = mIdByConnection.get(c);
1290 mAdapter.setStatusHints(id, statusHints);
1291 }
Sailesh Nepal2ab88cc2014-07-18 14:49:18 -07001292
1293 @Override
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001294 public void onConferenceablesChanged(
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001295 Connection connection, List<Conferenceable> conferenceables) {
Ihab Awadb8e85c72014-08-23 20:34:57 -07001296 mAdapter.setConferenceableConnections(
1297 mIdByConnection.get(connection),
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001298 createIdList(conferenceables));
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001299 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07001300
1301 @Override
1302 public void onConferenceChanged(Connection connection, Conference conference) {
1303 String id = mIdByConnection.get(connection);
1304 if (id != null) {
1305 String conferenceId = null;
1306 if (conference != null) {
1307 conferenceId = mIdByConference.get(conference);
1308 }
1309 mAdapter.setIsConferenced(id, conferenceId);
1310 }
1311 }
Anthony Lee17455a32015-04-24 15:25:29 -07001312
1313 @Override
1314 public void onConferenceMergeFailed(Connection connection) {
1315 String id = mIdByConnection.get(connection);
1316 if (id != null) {
1317 mAdapter.onConferenceMergeFailed(id);
1318 }
1319 }
Santos Cordon6b7f9552015-05-27 17:21:45 -07001320
1321 @Override
Tyler Gunndee56a82016-03-23 16:06:34 -07001322 public void onExtrasChanged(Connection c, Bundle extras) {
1323 String id = mIdByConnection.get(c);
Santos Cordon6b7f9552015-05-27 17:21:45 -07001324 if (id != null) {
Tyler Gunndee56a82016-03-23 16:06:34 -07001325 mAdapter.putExtras(id, extras);
Santos Cordon6b7f9552015-05-27 17:21:45 -07001326 }
1327 }
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001328
Tyler Gunnf5035432017-01-09 09:43:12 -08001329 @Override
Tyler Gunndee56a82016-03-23 16:06:34 -07001330 public void onExtrasRemoved(Connection c, List<String> keys) {
1331 String id = mIdByConnection.get(c);
1332 if (id != null) {
1333 mAdapter.removeExtras(id, keys);
1334 }
1335 }
1336
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08001337 @Override
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001338 public void onConnectionEvent(Connection connection, String event, Bundle extras) {
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08001339 String id = mIdByConnection.get(connection);
1340 if (id != null) {
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001341 mAdapter.onConnectionEvent(id, event, extras);
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08001342 }
1343 }
Tyler Gunnf5035432017-01-09 09:43:12 -08001344
1345 @Override
Hall Liua98f58b52017-11-07 17:59:28 -08001346 public void onAudioRouteChanged(Connection c, int audioRoute, String bluetoothAddress) {
Tyler Gunnf5035432017-01-09 09:43:12 -08001347 String id = mIdByConnection.get(c);
1348 if (id != null) {
Hall Liua98f58b52017-11-07 17:59:28 -08001349 mAdapter.setAudioRoute(id, audioRoute, bluetoothAddress);
Tyler Gunnf5035432017-01-09 09:43:12 -08001350 }
1351 }
Hall Liub64ac4c2017-02-06 10:49:48 -08001352
1353 @Override
1354 public void onRttInitiationSuccess(Connection c) {
1355 String id = mIdByConnection.get(c);
1356 if (id != null) {
1357 mAdapter.onRttInitiationSuccess(id);
1358 }
1359 }
1360
1361 @Override
1362 public void onRttInitiationFailure(Connection c, int reason) {
1363 String id = mIdByConnection.get(c);
1364 if (id != null) {
1365 mAdapter.onRttInitiationFailure(id, reason);
1366 }
1367 }
1368
1369 @Override
1370 public void onRttSessionRemotelyTerminated(Connection c) {
1371 String id = mIdByConnection.get(c);
1372 if (id != null) {
1373 mAdapter.onRttSessionRemotelyTerminated(id);
1374 }
1375 }
1376
1377 @Override
1378 public void onRemoteRttRequest(Connection c) {
1379 String id = mIdByConnection.get(c);
1380 if (id != null) {
1381 mAdapter.onRemoteRttRequest(id);
1382 }
1383 }
Srikanth Chintalafcb15012017-05-04 20:58:34 +05301384
1385 @Override
1386 public void onPhoneAccountChanged(Connection c, PhoneAccountHandle pHandle) {
1387 String id = mIdByConnection.get(c);
1388 if (id != null) {
1389 mAdapter.onPhoneAccountChanged(id, pHandle);
1390 }
1391 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001392 };
1393
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001394 /** {@inheritDoc} */
Ihab Awad542e0ea2014-05-16 10:22:16 -07001395 @Override
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001396 public final IBinder onBind(Intent intent) {
1397 return mBinder;
1398 }
1399
Santos Cordon29f2f2e2014-09-11 19:50:24 -07001400 /** {@inheritDoc} */
1401 @Override
1402 public boolean onUnbind(Intent intent) {
1403 endAllConnections();
1404 return super.onUnbind(intent);
1405 }
1406
Sailesh Nepalc5b01572014-07-14 16:29:44 -07001407 /**
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001408 * This can be used by telecom to either create a new outgoing call or attach to an existing
1409 * incoming call. In either case, telecom will cycle through a set of services and call
Sailesh Nepalc5b01572014-07-14 16:29:44 -07001410 * createConnection util a connection service cancels the process or completes it successfully.
1411 */
Ihab Awadf8b69882014-07-25 15:14:01 -07001412 private void createConnection(
1413 final PhoneAccountHandle callManagerAccount,
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001414 final String callId,
Ihab Awadf8b69882014-07-25 15:14:01 -07001415 final ConnectionRequest request,
Yorke Leec3cf9822014-10-02 09:38:39 -07001416 boolean isIncoming,
1417 boolean isUnknown) {
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001418 Log.d(this, "createConnection, callManagerAccount: %s, callId: %s, request: %s, " +
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001419 "isIncoming: %b, isUnknown: %b", callManagerAccount, callId, request,
1420 isIncoming,
Yorke Leec3cf9822014-10-02 09:38:39 -07001421 isUnknown);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001422
Sanket Padawe85291f62017-12-01 13:59:27 -08001423 Connection connection = null;
Sanket Padawe02d8c272017-12-20 10:13:05 -08001424 if (getApplicationContext().getApplicationInfo().targetSdkVersion >
1425 Build.VERSION_CODES.O_MR1 && request.getExtras() != null &&
1426 request.getExtras().getBoolean(TelecomManager.EXTRA_IS_HANDOVER,false)) {
Sanket Padawe85291f62017-12-01 13:59:27 -08001427 if (!isIncoming) {
1428 connection = onCreateOutgoingHandoverConnection(callManagerAccount, request);
1429 } else {
Sanket Padawe02d8c272017-12-20 10:13:05 -08001430 connection = onCreateIncomingHandoverConnection(callManagerAccount, request);
Sanket Padawe85291f62017-12-01 13:59:27 -08001431 }
1432 } else {
1433 connection = isUnknown ? onCreateUnknownConnection(callManagerAccount, request)
1434 : isIncoming ? onCreateIncomingConnection(callManagerAccount, request)
1435 : onCreateOutgoingConnection(callManagerAccount, request);
1436 }
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001437 Log.d(this, "createConnection, connection: %s", connection);
1438 if (connection == null) {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001439 connection = Connection.createFailedConnection(
1440 new DisconnectCause(DisconnectCause.ERROR));
Sailesh Nepalc5b01572014-07-14 16:29:44 -07001441 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001442
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001443 connection.setTelecomCallId(callId);
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001444 if (connection.getState() != Connection.STATE_DISCONNECTED) {
Ihab Awad6107bab2014-08-18 09:23:25 -07001445 addConnection(callId, connection);
1446 }
1447
Andrew Lee100e2932014-09-08 15:34:24 -07001448 Uri address = connection.getAddress();
1449 String number = address == null ? "null" : address.getSchemeSpecificPart();
Tyler Gunn720c6642016-03-22 09:02:47 -07001450 Log.v(this, "createConnection, number: %s, state: %s, capabilities: %s, properties: %s",
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001451 Connection.toLogSafePhoneNumber(number),
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001452 Connection.stateToString(connection.getState()),
Tyler Gunn720c6642016-03-22 09:02:47 -07001453 Connection.capabilitiesToString(connection.getConnectionCapabilities()),
1454 Connection.propertiesToString(connection.getConnectionProperties()));
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001455
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001456 Log.d(this, "createConnection, calling handleCreateConnectionSuccessful %s", callId);
Ihab Awad6107bab2014-08-18 09:23:25 -07001457 mAdapter.handleCreateConnectionComplete(
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001458 callId,
Evan Charltonbf11f982014-07-20 22:06:28 -07001459 request,
1460 new ParcelableConnection(
1461 request.getAccountHandle(),
1462 connection.getState(),
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001463 connection.getConnectionCapabilities(),
Tyler Gunn720c6642016-03-22 09:02:47 -07001464 connection.getConnectionProperties(),
Christine Hallstrom2830ce92016-11-30 16:06:42 -08001465 connection.getSupportedAudioRoutes(),
Andrew Lee100e2932014-09-08 15:34:24 -07001466 connection.getAddress(),
1467 connection.getAddressPresentation(),
Evan Charltonbf11f982014-07-20 22:06:28 -07001468 connection.getCallerDisplayName(),
1469 connection.getCallerDisplayNamePresentation(),
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001470 connection.getVideoProvider() == null ?
1471 null : connection.getVideoProvider().getInterface(),
Sailesh Nepal8b9d3ca2014-08-14 17:39:34 -07001472 connection.getVideoState(),
Andrew Lee100e2932014-09-08 15:34:24 -07001473 connection.isRingbackRequested(),
Sailesh Nepal8b9d3ca2014-08-14 17:39:34 -07001474 connection.getAudioModeIsVoip(),
Roshan Piuse927ec02015-07-15 15:47:21 -07001475 connection.getConnectTimeMillis(),
Tyler Gunn3fa819c2017-08-04 09:27:26 -07001476 connection.getConnectElapsedTimeMillis(),
Ihab Awad6107bab2014-08-18 09:23:25 -07001477 connection.getStatusHints(),
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001478 connection.getDisconnectCause(),
Santos Cordon6b7f9552015-05-27 17:21:45 -07001479 createIdList(connection.getConferenceables()),
1480 connection.getExtras()));
Tyler Gunnf5035432017-01-09 09:43:12 -08001481
1482 if (isIncoming && request.shouldShowIncomingCallUi() &&
1483 (connection.getConnectionProperties() & Connection.PROPERTY_SELF_MANAGED) ==
1484 Connection.PROPERTY_SELF_MANAGED) {
1485 // Tell ConnectionService to show its incoming call UX.
1486 connection.onShowIncomingCallUi();
1487 }
Shriram Ganesh6bf35ac2014-12-11 17:53:38 -08001488 if (isUnknown) {
1489 triggerConferenceRecalculate();
1490 }
Evan Charltonbf11f982014-07-20 22:06:28 -07001491 }
1492
Tyler Gunn159f35c2017-03-02 09:28:37 -08001493 private void createConnectionFailed(final PhoneAccountHandle callManagerAccount,
1494 final String callId, final ConnectionRequest request,
1495 boolean isIncoming) {
Tyler Gunn44e01912017-01-31 10:49:05 -08001496
1497 Log.i(this, "createConnectionFailed %s", callId);
1498 if (isIncoming) {
Tyler Gunn159f35c2017-03-02 09:28:37 -08001499 onCreateIncomingConnectionFailed(callManagerAccount, request);
Tyler Gunn44e01912017-01-31 10:49:05 -08001500 } else {
Tyler Gunn159f35c2017-03-02 09:28:37 -08001501 onCreateOutgoingConnectionFailed(callManagerAccount, request);
Tyler Gunn44e01912017-01-31 10:49:05 -08001502 }
1503 }
1504
Sanket Padawe02d8c272017-12-20 10:13:05 -08001505 private void handoverFailed(final String callId, final ConnectionRequest request,
1506 int reason) {
1507
1508 Log.i(this, "handoverFailed %s", callId);
1509 onHandoverFailed(request, reason);
1510 }
1511
Tyler Gunn041a1fe2017-05-12 10:04:49 -07001512 /**
1513 * Called by Telecom when the creation of a new Connection has completed and it is now added
1514 * to Telecom.
1515 * @param callId The ID of the connection.
1516 */
1517 private void notifyCreateConnectionComplete(final String callId) {
1518 Log.i(this, "notifyCreateConnectionComplete %s", callId);
Tyler Gunn0a88f2e2017-06-16 20:20:34 -07001519 if (callId == null) {
1520 // This could happen if the connection fails quickly and is removed from the
1521 // ConnectionService before Telecom sends the create connection complete callback.
1522 Log.w(this, "notifyCreateConnectionComplete: callId is null.");
1523 return;
1524 }
Tyler Gunn041a1fe2017-05-12 10:04:49 -07001525 onCreateConnectionComplete(findConnectionForAction(callId,
1526 "notifyCreateConnectionComplete"));
1527 }
1528
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001529 private void abort(String callId) {
Ihab Awad60ac30b2014-05-20 22:32:12 -07001530 Log.d(this, "abort %s", callId);
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001531 findConnectionForAction(callId, "abort").onAbort();
Ihab Awad542e0ea2014-05-16 10:22:16 -07001532 }
1533
Tyler Gunnbe74de02014-08-29 14:51:48 -07001534 private void answerVideo(String callId, int videoState) {
1535 Log.d(this, "answerVideo %s", callId);
Andrew Lee8da4c3c2014-07-16 10:11:42 -07001536 findConnectionForAction(callId, "answer").onAnswer(videoState);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001537 }
1538
Tyler Gunnbe74de02014-08-29 14:51:48 -07001539 private void answer(String callId) {
1540 Log.d(this, "answer %s", callId);
1541 findConnectionForAction(callId, "answer").onAnswer();
1542 }
1543
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001544 private void reject(String callId) {
Ihab Awad60ac30b2014-05-20 22:32:12 -07001545 Log.d(this, "reject %s", callId);
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001546 findConnectionForAction(callId, "reject").onReject();
Ihab Awad542e0ea2014-05-16 10:22:16 -07001547 }
1548
Bryce Lee81901682015-08-28 16:38:02 -07001549 private void reject(String callId, String rejectWithMessage) {
1550 Log.d(this, "reject %s with message", callId);
1551 findConnectionForAction(callId, "reject").onReject(rejectWithMessage);
1552 }
1553
Bryce Leecac50772015-11-17 15:13:29 -08001554 private void silence(String callId) {
1555 Log.d(this, "silence %s", callId);
1556 findConnectionForAction(callId, "silence").onSilence();
1557 }
1558
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001559 private void disconnect(String callId) {
Ihab Awad60ac30b2014-05-20 22:32:12 -07001560 Log.d(this, "disconnect %s", callId);
Santos Cordon0159ac02014-08-21 14:28:11 -07001561 if (mConnectionById.containsKey(callId)) {
1562 findConnectionForAction(callId, "disconnect").onDisconnect();
1563 } else {
1564 findConferenceForAction(callId, "disconnect").onDisconnect();
1565 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001566 }
1567
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001568 private void hold(String callId) {
Ihab Awad60ac30b2014-05-20 22:32:12 -07001569 Log.d(this, "hold %s", callId);
Santos Cordon0159ac02014-08-21 14:28:11 -07001570 if (mConnectionById.containsKey(callId)) {
1571 findConnectionForAction(callId, "hold").onHold();
1572 } else {
1573 findConferenceForAction(callId, "hold").onHold();
1574 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001575 }
1576
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001577 private void unhold(String callId) {
Ihab Awad60ac30b2014-05-20 22:32:12 -07001578 Log.d(this, "unhold %s", callId);
Santos Cordon0159ac02014-08-21 14:28:11 -07001579 if (mConnectionById.containsKey(callId)) {
1580 findConnectionForAction(callId, "unhold").onUnhold();
1581 } else {
1582 findConferenceForAction(callId, "unhold").onUnhold();
1583 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001584 }
1585
Yorke Lee4af59352015-05-13 14:14:54 -07001586 private void onCallAudioStateChanged(String callId, CallAudioState callAudioState) {
1587 Log.d(this, "onAudioStateChanged %s %s", callId, callAudioState);
Yorke Leea0d3ca92014-09-15 19:18:13 -07001588 if (mConnectionById.containsKey(callId)) {
Yorke Lee4af59352015-05-13 14:14:54 -07001589 findConnectionForAction(callId, "onCallAudioStateChanged").setCallAudioState(
1590 callAudioState);
Yorke Leea0d3ca92014-09-15 19:18:13 -07001591 } else {
Yorke Lee4af59352015-05-13 14:14:54 -07001592 findConferenceForAction(callId, "onCallAudioStateChanged").setCallAudioState(
1593 callAudioState);
Yorke Leea0d3ca92014-09-15 19:18:13 -07001594 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001595 }
1596
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001597 private void playDtmfTone(String callId, char digit) {
1598 Log.d(this, "playDtmfTone %s %c", callId, digit);
Yorke Leea0d3ca92014-09-15 19:18:13 -07001599 if (mConnectionById.containsKey(callId)) {
1600 findConnectionForAction(callId, "playDtmfTone").onPlayDtmfTone(digit);
1601 } else {
1602 findConferenceForAction(callId, "playDtmfTone").onPlayDtmfTone(digit);
1603 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001604 }
1605
1606 private void stopDtmfTone(String callId) {
1607 Log.d(this, "stopDtmfTone %s", callId);
Yorke Leea0d3ca92014-09-15 19:18:13 -07001608 if (mConnectionById.containsKey(callId)) {
1609 findConnectionForAction(callId, "stopDtmfTone").onStopDtmfTone();
1610 } else {
1611 findConferenceForAction(callId, "stopDtmfTone").onStopDtmfTone();
1612 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001613 }
1614
Santos Cordon823fd3c2014-08-07 18:35:18 -07001615 private void conference(String callId1, String callId2) {
1616 Log.d(this, "conference %s, %s", callId1, callId2);
Santos Cordon980acb92014-05-31 10:31:19 -07001617
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001618 // Attempt to get second connection or conference.
Santos Cordon823fd3c2014-08-07 18:35:18 -07001619 Connection connection2 = findConnectionForAction(callId2, "conference");
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001620 Conference conference2 = getNullConference();
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001621 if (connection2 == getNullConnection()) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001622 conference2 = findConferenceForAction(callId2, "conference");
1623 if (conference2 == getNullConference()) {
1624 Log.w(this, "Connection2 or Conference2 missing in conference request %s.",
1625 callId2);
1626 return;
1627 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07001628 }
Santos Cordonb6939982014-06-04 20:20:58 -07001629
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001630 // Attempt to get first connection or conference and perform merge.
Ihab Awad50e35062014-09-30 09:17:03 -07001631 Connection connection1 = findConnectionForAction(callId1, "conference");
1632 if (connection1 == getNullConnection()) {
1633 Conference conference1 = findConferenceForAction(callId1, "addConnection");
1634 if (conference1 == getNullConference()) {
1635 Log.w(this,
1636 "Connection1 or Conference1 missing in conference request %s.",
1637 callId1);
1638 } else {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001639 // Call 1 is a conference.
1640 if (connection2 != getNullConnection()) {
1641 // Call 2 is a connection so merge via call 1 (conference).
1642 conference1.onMerge(connection2);
1643 } else {
1644 // Call 2 is ALSO a conference; this should never happen.
1645 Log.wtf(this, "There can only be one conference and an attempt was made to " +
1646 "merge two conferences.");
1647 return;
1648 }
Ihab Awad50e35062014-09-30 09:17:03 -07001649 }
1650 } else {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001651 // Call 1 is a connection.
1652 if (conference2 != getNullConference()) {
1653 // Call 2 is a conference, so merge via call 2.
1654 conference2.onMerge(connection1);
1655 } else {
1656 // Call 2 is a connection, so merge together.
1657 onConference(connection1, connection2);
1658 }
Ihab Awad50e35062014-09-30 09:17:03 -07001659 }
Santos Cordon980acb92014-05-31 10:31:19 -07001660 }
1661
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001662 private void splitFromConference(String callId) {
Santos Cordonb6939982014-06-04 20:20:58 -07001663 Log.d(this, "splitFromConference(%s)", callId);
Santos Cordon980acb92014-05-31 10:31:19 -07001664
1665 Connection connection = findConnectionForAction(callId, "splitFromConference");
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001666 if (connection == getNullConnection()) {
Santos Cordon980acb92014-05-31 10:31:19 -07001667 Log.w(this, "Connection missing in conference request %s.", callId);
1668 return;
1669 }
1670
Santos Cordon0159ac02014-08-21 14:28:11 -07001671 Conference conference = connection.getConference();
1672 if (conference != null) {
1673 conference.onSeparate(connection);
1674 }
Santos Cordon980acb92014-05-31 10:31:19 -07001675 }
1676
Santos Cordona4868042014-09-04 17:39:22 -07001677 private void mergeConference(String callId) {
1678 Log.d(this, "mergeConference(%s)", callId);
1679 Conference conference = findConferenceForAction(callId, "mergeConference");
1680 if (conference != null) {
1681 conference.onMerge();
1682 }
1683 }
1684
1685 private void swapConference(String callId) {
1686 Log.d(this, "swapConference(%s)", callId);
1687 Conference conference = findConferenceForAction(callId, "swapConference");
1688 if (conference != null) {
1689 conference.onSwap();
1690 }
1691 }
1692
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001693 /**
1694 * Notifies a {@link Connection} of a request to pull an external call.
1695 *
1696 * See {@link Call#pullExternalCall()}.
1697 *
1698 * @param callId The ID of the call to pull.
1699 */
1700 private void pullExternalCall(String callId) {
1701 Log.d(this, "pullExternalCall(%s)", callId);
1702 Connection connection = findConnectionForAction(callId, "pullExternalCall");
1703 if (connection != null) {
1704 connection.onPullExternalCall();
1705 }
1706 }
1707
1708 /**
1709 * Notifies a {@link Connection} of a call event.
1710 *
1711 * See {@link Call#sendCallEvent(String, Bundle)}.
1712 *
1713 * @param callId The ID of the call receiving the event.
1714 * @param event The event.
1715 * @param extras Extras associated with the event.
1716 */
1717 private void sendCallEvent(String callId, String event, Bundle extras) {
1718 Log.d(this, "sendCallEvent(%s, %s)", callId, event);
1719 Connection connection = findConnectionForAction(callId, "sendCallEvent");
1720 if (connection != null) {
1721 connection.onCallEvent(event, extras);
1722 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001723 }
1724
Tyler Gunndee56a82016-03-23 16:06:34 -07001725 /**
1726 * Notifies a {@link Connection} or {@link Conference} of a change to the extras from Telecom.
1727 * <p>
1728 * These extra changes can originate from Telecom itself, or from an {@link InCallService} via
1729 * the {@link android.telecom.Call#putExtra(String, boolean)},
1730 * {@link android.telecom.Call#putExtra(String, int)},
1731 * {@link android.telecom.Call#putExtra(String, String)},
1732 * {@link Call#removeExtras(List)}.
1733 *
1734 * @param callId The ID of the call receiving the event.
1735 * @param extras The new extras bundle.
1736 */
1737 private void handleExtrasChanged(String callId, Bundle extras) {
1738 Log.d(this, "handleExtrasChanged(%s, %s)", callId, extras);
1739 if (mConnectionById.containsKey(callId)) {
1740 findConnectionForAction(callId, "handleExtrasChanged").handleExtrasChanged(extras);
1741 } else if (mConferenceById.containsKey(callId)) {
1742 findConferenceForAction(callId, "handleExtrasChanged").handleExtrasChanged(extras);
1743 }
1744 }
1745
Hall Liub64ac4c2017-02-06 10:49:48 -08001746 private void startRtt(String callId, Connection.RttTextStream rttTextStream) {
1747 Log.d(this, "startRtt(%s)", callId);
1748 if (mConnectionById.containsKey(callId)) {
1749 findConnectionForAction(callId, "startRtt").onStartRtt(rttTextStream);
1750 } else if (mConferenceById.containsKey(callId)) {
1751 Log.w(this, "startRtt called on a conference.");
1752 }
1753 }
1754
1755 private void stopRtt(String callId) {
1756 Log.d(this, "stopRtt(%s)", callId);
1757 if (mConnectionById.containsKey(callId)) {
1758 findConnectionForAction(callId, "stopRtt").onStopRtt();
Hall Liuffa4a812017-03-02 16:11:00 -08001759 findConnectionForAction(callId, "stopRtt").unsetRttProperty();
Hall Liub64ac4c2017-02-06 10:49:48 -08001760 } else if (mConferenceById.containsKey(callId)) {
1761 Log.w(this, "stopRtt called on a conference.");
1762 }
1763 }
1764
1765 private void handleRttUpgradeResponse(String callId, Connection.RttTextStream rttTextStream) {
1766 Log.d(this, "handleRttUpgradeResponse(%s, %s)", callId, rttTextStream == null);
1767 if (mConnectionById.containsKey(callId)) {
1768 findConnectionForAction(callId, "handleRttUpgradeResponse")
1769 .handleRttUpgradeResponse(rttTextStream);
1770 } else if (mConferenceById.containsKey(callId)) {
1771 Log.w(this, "handleRttUpgradeResponse called on a conference.");
1772 }
1773 }
1774
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001775 private void onPostDialContinue(String callId, boolean proceed) {
Evan Charlton6dea4ac2014-06-03 14:07:13 -07001776 Log.d(this, "onPostDialContinue(%s)", callId);
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001777 findConnectionForAction(callId, "stopDtmfTone").onPostDialContinue(proceed);
Evan Charlton6dea4ac2014-06-03 14:07:13 -07001778 }
1779
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001780 private void onAdapterAttached() {
Ihab Awad9c3f1882014-06-30 21:17:13 -07001781 if (mAreAccountsInitialized) {
Santos Cordon52d8a152014-06-17 19:08:45 -07001782 // No need to query again if we already did it.
1783 return;
1784 }
1785
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001786 mAdapter.queryRemoteConnectionServices(new RemoteServiceCallback.Stub() {
Santos Cordon52d8a152014-06-17 19:08:45 -07001787 @Override
1788 public void onResult(
1789 final List<ComponentName> componentNames,
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001790 final List<IBinder> services) {
Brad Ebinger0c3541b2016-11-01 14:11:38 -07001791 mHandler.post(new android.telecom.Logging.Runnable("oAA.qRCS.oR", null /*lock*/) {
Ihab Awad6107bab2014-08-18 09:23:25 -07001792 @Override
Brad Ebinger0c3541b2016-11-01 14:11:38 -07001793 public void loggedRun() {
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001794 for (int i = 0; i < componentNames.size() && i < services.size(); i++) {
Santos Cordon52d8a152014-06-17 19:08:45 -07001795 mRemoteConnectionManager.addConnectionService(
1796 componentNames.get(i),
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001797 IConnectionService.Stub.asInterface(services.get(i)));
Santos Cordon52d8a152014-06-17 19:08:45 -07001798 }
Ihab Awad5d0410f2014-07-30 10:07:40 -07001799 onAccountsInitialized();
Sailesh Nepalc5b01572014-07-14 16:29:44 -07001800 Log.d(this, "remote connection services found: " + services);
Santos Cordon52d8a152014-06-17 19:08:45 -07001801 }
Brad Ebinger0c3541b2016-11-01 14:11:38 -07001802 }.prepare());
Santos Cordon52d8a152014-06-17 19:08:45 -07001803 }
1804
1805 @Override
1806 public void onError() {
Brad Ebinger0c3541b2016-11-01 14:11:38 -07001807 mHandler.post(new android.telecom.Logging.Runnable("oAA.qRCS.oE", null /*lock*/) {
Ihab Awad6107bab2014-08-18 09:23:25 -07001808 @Override
Brad Ebinger0c3541b2016-11-01 14:11:38 -07001809 public void loggedRun() {
Ihab Awad9c3f1882014-06-30 21:17:13 -07001810 mAreAccountsInitialized = true;
Santos Cordon52d8a152014-06-17 19:08:45 -07001811 }
Brad Ebinger0c3541b2016-11-01 14:11:38 -07001812 }.prepare());
Santos Cordon52d8a152014-06-17 19:08:45 -07001813 }
1814 });
1815 }
1816
Ihab Awadf8b69882014-07-25 15:14:01 -07001817 /**
1818 * Ask some other {@code ConnectionService} to create a {@code RemoteConnection} given an
Santos Cordona663f862014-10-29 13:49:58 -07001819 * incoming request. This is used by {@code ConnectionService}s that are registered with
1820 * {@link PhoneAccount#CAPABILITY_CONNECTION_MANAGER} and want to be able to manage
1821 * SIM-based incoming calls.
Ihab Awadf8b69882014-07-25 15:14:01 -07001822 *
1823 * @param connectionManagerPhoneAccount See description at
1824 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
1825 * @param request Details about the incoming call.
1826 * @return The {@code Connection} object to satisfy this call, or {@code null} to
1827 * not handle the call.
1828 */
1829 public final RemoteConnection createRemoteIncomingConnection(
1830 PhoneAccountHandle connectionManagerPhoneAccount,
1831 ConnectionRequest request) {
1832 return mRemoteConnectionManager.createRemoteConnection(
1833 connectionManagerPhoneAccount, request, true);
Santos Cordon52d8a152014-06-17 19:08:45 -07001834 }
1835
1836 /**
Ihab Awadf8b69882014-07-25 15:14:01 -07001837 * Ask some other {@code ConnectionService} to create a {@code RemoteConnection} given an
Santos Cordona663f862014-10-29 13:49:58 -07001838 * outgoing request. This is used by {@code ConnectionService}s that are registered with
1839 * {@link PhoneAccount#CAPABILITY_CONNECTION_MANAGER} and want to be able to use the
1840 * SIM-based {@code ConnectionService} to place its outgoing calls.
Ihab Awadf8b69882014-07-25 15:14:01 -07001841 *
1842 * @param connectionManagerPhoneAccount See description at
1843 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
Cuihtlauac ALVARADO0b3b2a52016-09-13 14:49:41 +02001844 * @param request Details about the outgoing call.
Ihab Awadf8b69882014-07-25 15:14:01 -07001845 * @return The {@code Connection} object to satisfy this call, or {@code null} to
1846 * not handle the call.
1847 */
1848 public final RemoteConnection createRemoteOutgoingConnection(
1849 PhoneAccountHandle connectionManagerPhoneAccount,
1850 ConnectionRequest request) {
1851 return mRemoteConnectionManager.createRemoteConnection(
1852 connectionManagerPhoneAccount, request, false);
1853 }
1854
1855 /**
Santos Cordona663f862014-10-29 13:49:58 -07001856 * Indicates to the relevant {@code RemoteConnectionService} that the specified
1857 * {@link RemoteConnection}s should be merged into a conference call.
1858 * <p>
1859 * If the conference request is successful, the method {@link #onRemoteConferenceAdded} will
1860 * be invoked.
1861 *
1862 * @param remoteConnection1 The first of the remote connections to conference.
1863 * @param remoteConnection2 The second of the remote connections to conference.
Ihab Awadb8e85c72014-08-23 20:34:57 -07001864 */
1865 public final void conferenceRemoteConnections(
Santos Cordona663f862014-10-29 13:49:58 -07001866 RemoteConnection remoteConnection1,
1867 RemoteConnection remoteConnection2) {
1868 mRemoteConnectionManager.conferenceRemoteConnections(remoteConnection1, remoteConnection2);
Ihab Awadb8e85c72014-08-23 20:34:57 -07001869 }
1870
1871 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07001872 * Adds a new conference call. When a conference call is created either as a result of an
1873 * explicit request via {@link #onConference} or otherwise, the connection service should supply
1874 * an instance of {@link Conference} by invoking this method. A conference call provided by this
1875 * method will persist until {@link Conference#destroy} is invoked on the conference instance.
1876 *
1877 * @param conference The new conference object.
1878 */
1879 public final void addConference(Conference conference) {
Rekha Kumar07366812015-03-24 16:42:31 -07001880 Log.d(this, "addConference: conference=%s", conference);
1881
Santos Cordon823fd3c2014-08-07 18:35:18 -07001882 String id = addConferenceInternal(conference);
1883 if (id != null) {
1884 List<String> connectionIds = new ArrayList<>(2);
1885 for (Connection connection : conference.getConnections()) {
1886 if (mIdByConnection.containsKey(connection)) {
1887 connectionIds.add(mIdByConnection.get(connection));
1888 }
1889 }
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001890 conference.setTelecomCallId(id);
Santos Cordon823fd3c2014-08-07 18:35:18 -07001891 ParcelableConference parcelableConference = new ParcelableConference(
Nancy Chenea38cca2014-09-05 16:38:49 -07001892 conference.getPhoneAccountHandle(),
Santos Cordon823fd3c2014-08-07 18:35:18 -07001893 conference.getState(),
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001894 conference.getConnectionCapabilities(),
Tyler Gunn720c6642016-03-22 09:02:47 -07001895 conference.getConnectionProperties(),
Tyler Gunncd5d33c2015-01-12 09:02:01 -08001896 connectionIds,
Rekha Kumar07366812015-03-24 16:42:31 -07001897 conference.getVideoProvider() == null ?
1898 null : conference.getVideoProvider().getInterface(),
1899 conference.getVideoState(),
Andrew Lee3e3e2f22015-04-16 13:48:43 -07001900 conference.getConnectTimeMillis(),
Tyler Gunn3fa819c2017-08-04 09:27:26 -07001901 conference.getConnectElapsedTime(),
Santos Cordon6b7f9552015-05-27 17:21:45 -07001902 conference.getStatusHints(),
1903 conference.getExtras());
Andrew Lee0f51da32015-04-16 13:11:55 -07001904
Santos Cordon823fd3c2014-08-07 18:35:18 -07001905 mAdapter.addConferenceCall(id, parcelableConference);
Rekha Kumar07366812015-03-24 16:42:31 -07001906 mAdapter.setVideoProvider(id, conference.getVideoProvider());
1907 mAdapter.setVideoState(id, conference.getVideoState());
Santos Cordon823fd3c2014-08-07 18:35:18 -07001908
1909 // Go through any child calls and set the parent.
1910 for (Connection connection : conference.getConnections()) {
1911 String connectionId = mIdByConnection.get(connection);
1912 if (connectionId != null) {
1913 mAdapter.setIsConferenced(connectionId, id);
1914 }
1915 }
1916 }
1917 }
1918
1919 /**
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07001920 * Adds a connection created by the {@link ConnectionService} and informs telecom of the new
1921 * connection.
1922 *
1923 * @param phoneAccountHandle The phone account handle for the connection.
1924 * @param connection The connection to add.
1925 */
1926 public final void addExistingConnection(PhoneAccountHandle phoneAccountHandle,
1927 Connection connection) {
Tyler Gunn78da7812017-05-09 14:34:57 -07001928 addExistingConnection(phoneAccountHandle, connection, null /* conference */);
1929 }
1930
1931 /**
1932 * Adds a connection created by the {@link ConnectionService} and informs telecom of the new
1933 * connection.
1934 *
1935 * @param phoneAccountHandle The phone account handle for the connection.
1936 * @param connection The connection to add.
1937 * @param conference The parent conference of the new connection.
1938 * @hide
1939 */
1940 public final void addExistingConnection(PhoneAccountHandle phoneAccountHandle,
1941 Connection connection, Conference conference) {
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07001942
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001943 String id = addExistingConnectionInternal(phoneAccountHandle, connection);
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07001944 if (id != null) {
1945 List<String> emptyList = new ArrayList<>(0);
Tyler Gunn78da7812017-05-09 14:34:57 -07001946 String conferenceId = null;
1947 if (conference != null) {
1948 conferenceId = mIdByConference.get(conference);
1949 }
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07001950
1951 ParcelableConnection parcelableConnection = new ParcelableConnection(
1952 phoneAccountHandle,
1953 connection.getState(),
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001954 connection.getConnectionCapabilities(),
Tyler Gunn720c6642016-03-22 09:02:47 -07001955 connection.getConnectionProperties(),
Christine Hallstrom2830ce92016-11-30 16:06:42 -08001956 connection.getSupportedAudioRoutes(),
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07001957 connection.getAddress(),
1958 connection.getAddressPresentation(),
1959 connection.getCallerDisplayName(),
1960 connection.getCallerDisplayNamePresentation(),
1961 connection.getVideoProvider() == null ?
1962 null : connection.getVideoProvider().getInterface(),
1963 connection.getVideoState(),
1964 connection.isRingbackRequested(),
1965 connection.getAudioModeIsVoip(),
Roshan Piuse927ec02015-07-15 15:47:21 -07001966 connection.getConnectTimeMillis(),
Tyler Gunn3fa819c2017-08-04 09:27:26 -07001967 connection.getConnectElapsedTimeMillis(),
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07001968 connection.getStatusHints(),
1969 connection.getDisconnectCause(),
Santos Cordon6b7f9552015-05-27 17:21:45 -07001970 emptyList,
Tyler Gunn78da7812017-05-09 14:34:57 -07001971 connection.getExtras(),
1972 conferenceId);
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07001973 mAdapter.addExistingConnection(id, parcelableConnection);
1974 }
1975 }
1976
1977 /**
Ihab Awadf8b69882014-07-25 15:14:01 -07001978 * Returns all the active {@code Connection}s for which this {@code ConnectionService}
1979 * has taken responsibility.
1980 *
1981 * @return A collection of {@code Connection}s created by this {@code ConnectionService}.
Santos Cordonb6939982014-06-04 20:20:58 -07001982 */
Sailesh Nepal091768c2014-06-30 15:15:23 -07001983 public final Collection<Connection> getAllConnections() {
Santos Cordonb6939982014-06-04 20:20:58 -07001984 return mConnectionById.values();
1985 }
1986
1987 /**
Santos Cordona6018b92016-02-16 14:23:12 -08001988 * Returns all the active {@code Conference}s for which this {@code ConnectionService}
1989 * has taken responsibility.
1990 *
1991 * @return A collection of {@code Conference}s created by this {@code ConnectionService}.
1992 */
1993 public final Collection<Conference> getAllConferences() {
1994 return mConferenceById.values();
1995 }
1996
1997 /**
Ihab Awadf8b69882014-07-25 15:14:01 -07001998 * Create a {@code Connection} given an incoming request. This is used to attach to existing
1999 * incoming calls.
Evan Charltonbf11f982014-07-20 22:06:28 -07002000 *
Ihab Awadf8b69882014-07-25 15:14:01 -07002001 * @param connectionManagerPhoneAccount See description at
2002 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
2003 * @param request Details about the incoming call.
2004 * @return The {@code Connection} object to satisfy this call, or {@code null} to
2005 * not handle the call.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002006 */
Ihab Awadf8b69882014-07-25 15:14:01 -07002007 public Connection onCreateIncomingConnection(
2008 PhoneAccountHandle connectionManagerPhoneAccount,
2009 ConnectionRequest request) {
2010 return null;
2011 }
Sailesh Nepalc5b01572014-07-14 16:29:44 -07002012
2013 /**
Tyler Gunn041a1fe2017-05-12 10:04:49 -07002014 * Called after the {@link Connection} returned by
2015 * {@link #onCreateIncomingConnection(PhoneAccountHandle, ConnectionRequest)}
2016 * or {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)} has been
2017 * added to the {@link ConnectionService} and sent to Telecom.
2018 *
2019 * @param connection the {@link Connection}.
2020 * @hide
2021 */
2022 public void onCreateConnectionComplete(Connection connection) {
2023 }
2024
2025 /**
Tyler Gunnf5035432017-01-09 09:43:12 -08002026 * Called by Telecom to inform the {@link ConnectionService} that its request to create a new
2027 * incoming {@link Connection} was denied.
2028 * <p>
2029 * Used when a self-managed {@link ConnectionService} attempts to create a new incoming
2030 * {@link Connection}, but Telecom has determined that the call cannot be allowed at this time.
2031 * The {@link ConnectionService} is responsible for silently rejecting the new incoming
2032 * {@link Connection}.
2033 * <p>
2034 * See {@link TelecomManager#isIncomingCallPermitted(PhoneAccountHandle)} for more information.
2035 *
Tyler Gunn159f35c2017-03-02 09:28:37 -08002036 * @param connectionManagerPhoneAccount See description at
2037 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
Tyler Gunnf5035432017-01-09 09:43:12 -08002038 * @param request The incoming connection request.
2039 */
Tyler Gunn159f35c2017-03-02 09:28:37 -08002040 public void onCreateIncomingConnectionFailed(PhoneAccountHandle connectionManagerPhoneAccount,
2041 ConnectionRequest request) {
Tyler Gunnf5035432017-01-09 09:43:12 -08002042 }
2043
2044 /**
2045 * Called by Telecom to inform the {@link ConnectionService} that its request to create a new
2046 * outgoing {@link Connection} was denied.
2047 * <p>
2048 * Used when a self-managed {@link ConnectionService} attempts to create a new outgoing
2049 * {@link Connection}, but Telecom has determined that the call cannot be placed at this time.
2050 * The {@link ConnectionService} is responisible for informing the user that the
2051 * {@link Connection} cannot be made at this time.
2052 * <p>
2053 * See {@link TelecomManager#isOutgoingCallPermitted(PhoneAccountHandle)} for more information.
2054 *
Tyler Gunn159f35c2017-03-02 09:28:37 -08002055 * @param connectionManagerPhoneAccount See description at
2056 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
Tyler Gunnf5035432017-01-09 09:43:12 -08002057 * @param request The outgoing connection request.
2058 */
Tyler Gunn159f35c2017-03-02 09:28:37 -08002059 public void onCreateOutgoingConnectionFailed(PhoneAccountHandle connectionManagerPhoneAccount,
2060 ConnectionRequest request) {
Tyler Gunnf5035432017-01-09 09:43:12 -08002061 }
2062
2063 /**
Shriram Ganesh6bf35ac2014-12-11 17:53:38 -08002064 * Trigger recalculate functinality for conference calls. This is used when a Telephony
2065 * Connection is part of a conference controller but is not yet added to Connection
2066 * Service and hence cannot be added to the conference call.
2067 *
2068 * @hide
2069 */
2070 public void triggerConferenceRecalculate() {
2071 }
2072
2073 /**
Ihab Awadf8b69882014-07-25 15:14:01 -07002074 * Create a {@code Connection} given an outgoing request. This is used to initiate new
2075 * outgoing calls.
Sailesh Nepalc5b01572014-07-14 16:29:44 -07002076 *
Ihab Awadf8b69882014-07-25 15:14:01 -07002077 * @param connectionManagerPhoneAccount The connection manager account to use for managing
2078 * this call.
2079 * <p>
2080 * If this parameter is not {@code null}, it means that this {@code ConnectionService}
2081 * has registered one or more {@code PhoneAccount}s having
2082 * {@link PhoneAccount#CAPABILITY_CONNECTION_MANAGER}. This parameter will contain
2083 * one of these {@code PhoneAccount}s, while the {@code request} will contain another
2084 * (usually but not always distinct) {@code PhoneAccount} to be used for actually
2085 * making the connection.
2086 * <p>
2087 * If this parameter is {@code null}, it means that this {@code ConnectionService} is
2088 * being asked to make a direct connection. The
2089 * {@link ConnectionRequest#getAccountHandle()} of parameter {@code request} will be
2090 * a {@code PhoneAccount} registered by this {@code ConnectionService} to use for
2091 * making the connection.
2092 * @param request Details about the outgoing call.
2093 * @return The {@code Connection} object to satisfy this call, or the result of an invocation
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002094 * of {@link Connection#createFailedConnection(DisconnectCause)} to not handle the call.
Sailesh Nepalc5b01572014-07-14 16:29:44 -07002095 */
Ihab Awadf8b69882014-07-25 15:14:01 -07002096 public Connection onCreateOutgoingConnection(
2097 PhoneAccountHandle connectionManagerPhoneAccount,
2098 ConnectionRequest request) {
2099 return null;
2100 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002101
2102 /**
Sanket Padawea8eddd42017-11-03 11:07:35 -07002103 * Called by Telecom on the initiating side of the handover to create an instance of a
2104 * handover connection.
2105 * @param fromPhoneAccountHandle {@link PhoneAccountHandle} associated with the
2106 * ConnectionService which needs to handover the call.
2107 * @param request Details about the call which needs to be handover.
2108 * @return Connection object corresponding to the handover call.
2109 */
2110 public Connection onCreateOutgoingHandoverConnection(PhoneAccountHandle fromPhoneAccountHandle,
2111 ConnectionRequest request) {
2112 return null;
2113 }
2114
2115 /**
2116 * Called by Telecom on the receiving side of the handover to request the
2117 * {@link ConnectionService} to create an instance of a handover connection.
2118 * @param fromPhoneAccountHandle {@link PhoneAccountHandle} associated with the
2119 * ConnectionService which needs to handover the call.
2120 * @param request Details about the call which needs to be handover.
2121 * @return {@link Connection} object corresponding to the handover call.
2122 */
2123 public Connection onCreateIncomingHandoverConnection(PhoneAccountHandle fromPhoneAccountHandle,
2124 ConnectionRequest request) {
2125 return null;
2126 }
2127
2128 /**
2129 * Called by Telecom in response to a {@code TelecomManager#acceptHandover()}
2130 * invocation which failed.
2131 * @param request Details about the call which needs to be handover.
2132 * @param error Reason for handover failure as defined in
2133 * {@link android.telecom.Call.Callback#HANDOVER_FAILURE_DEST_INVALID_PERM}
2134 */
2135 public void onHandoverFailed(ConnectionRequest request, int error) {
2136 return;
2137 }
2138
2139 /**
Yorke Leec3cf9822014-10-02 09:38:39 -07002140 * Create a {@code Connection} for a new unknown call. An unknown call is a call originating
2141 * from the ConnectionService that was neither a user-initiated outgoing call, nor an incoming
2142 * call created using
2143 * {@code TelecomManager#addNewIncomingCall(PhoneAccountHandle, android.os.Bundle)}.
2144 *
Yorke Lee770ed6e2014-10-06 18:58:52 -07002145 * @hide
Yorke Leec3cf9822014-10-02 09:38:39 -07002146 */
2147 public Connection onCreateUnknownConnection(PhoneAccountHandle connectionManagerPhoneAccount,
2148 ConnectionRequest request) {
Brad Ebingerb32d4f82016-10-24 16:40:49 -07002149 return null;
Yorke Leec3cf9822014-10-02 09:38:39 -07002150 }
2151
2152 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07002153 * Conference two specified connections. Invoked when the user has made a request to merge the
2154 * specified connections into a conference call. In response, the connection service should
2155 * create an instance of {@link Conference} and pass it into {@link #addConference}.
Santos Cordonb6939982014-06-04 20:20:58 -07002156 *
Santos Cordon823fd3c2014-08-07 18:35:18 -07002157 * @param connection1 A connection to merge into a conference call.
2158 * @param connection2 A connection to merge into a conference call.
Santos Cordonb6939982014-06-04 20:20:58 -07002159 */
Santos Cordon823fd3c2014-08-07 18:35:18 -07002160 public void onConference(Connection connection1, Connection connection2) {}
Santos Cordonb6939982014-06-04 20:20:58 -07002161
Santos Cordona663f862014-10-29 13:49:58 -07002162 /**
2163 * Indicates that a remote conference has been created for existing {@link RemoteConnection}s.
2164 * When this method is invoked, this {@link ConnectionService} should create its own
2165 * representation of the conference call and send it to telecom using {@link #addConference}.
2166 * <p>
2167 * This is only relevant to {@link ConnectionService}s which are registered with
2168 * {@link PhoneAccount#CAPABILITY_CONNECTION_MANAGER}.
2169 *
2170 * @param conference The remote conference call.
2171 */
Ihab Awadb8e85c72014-08-23 20:34:57 -07002172 public void onRemoteConferenceAdded(RemoteConference conference) {}
2173
Santos Cordon823fd3c2014-08-07 18:35:18 -07002174 /**
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002175 * Called when an existing connection is added remotely.
2176 * @param connection The existing connection which was added.
2177 */
2178 public void onRemoteExistingConnectionAdded(RemoteConnection connection) {}
2179
2180 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07002181 * @hide
2182 */
2183 public boolean containsConference(Conference conference) {
2184 return mIdByConference.containsKey(conference);
2185 }
2186
Ihab Awadb8e85c72014-08-23 20:34:57 -07002187 /** {@hide} */
2188 void addRemoteConference(RemoteConference remoteConference) {
2189 onRemoteConferenceAdded(remoteConference);
2190 }
2191
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002192 /** {@hide} */
2193 void addRemoteExistingConnection(RemoteConnection remoteConnection) {
2194 onRemoteExistingConnectionAdded(remoteConnection);
2195 }
2196
Ihab Awad5d0410f2014-07-30 10:07:40 -07002197 private void onAccountsInitialized() {
2198 mAreAccountsInitialized = true;
2199 for (Runnable r : mPreInitializationConnectionRequests) {
2200 r.run();
2201 }
2202 mPreInitializationConnectionRequests.clear();
2203 }
2204
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002205 /**
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002206 * Adds an existing connection to the list of connections, identified by a new call ID unique
2207 * to this connection service.
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002208 *
2209 * @param connection The connection.
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002210 * @return The ID of the connection (e.g. the call-id).
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002211 */
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002212 private String addExistingConnectionInternal(PhoneAccountHandle handle, Connection connection) {
2213 String id;
Tyler Gunncd6ccfd2016-10-17 15:48:19 -07002214
2215 if (connection.getExtras() != null && connection.getExtras()
2216 .containsKey(Connection.EXTRA_ORIGINAL_CONNECTION_ID)) {
2217 id = connection.getExtras().getString(Connection.EXTRA_ORIGINAL_CONNECTION_ID);
2218 Log.d(this, "addExistingConnectionInternal - conn %s reusing original id %s",
2219 connection.getTelecomCallId(), id);
2220 } else if (handle == null) {
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002221 // If no phone account handle was provided, we cannot be sure the call ID is unique,
2222 // so just use a random UUID.
2223 id = UUID.randomUUID().toString();
2224 } else {
2225 // Phone account handle was provided, so use the ConnectionService class name as a
2226 // prefix for a unique incremental call ID.
2227 id = handle.getComponentName().getClassName() + "@" + getNextCallId();
2228 }
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002229 addConnection(id, connection);
2230 return id;
2231 }
2232
Ihab Awad542e0ea2014-05-16 10:22:16 -07002233 private void addConnection(String callId, Connection connection) {
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002234 connection.setTelecomCallId(callId);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002235 mConnectionById.put(callId, connection);
2236 mIdByConnection.put(connection, callId);
2237 connection.addConnectionListener(mConnectionListener);
Santos Cordon823fd3c2014-08-07 18:35:18 -07002238 connection.setConnectionService(this);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002239 }
2240
Anthony Lee30e65842014-11-06 16:30:53 -08002241 /** {@hide} */
2242 protected void removeConnection(Connection connection) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07002243 connection.unsetConnectionService(this);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002244 connection.removeConnectionListener(mConnectionListener);
Chenjie Luoe370b532016-05-12 16:59:43 -07002245 String id = mIdByConnection.get(connection);
2246 if (id != null) {
2247 mConnectionById.remove(id);
2248 mIdByConnection.remove(connection);
2249 mAdapter.removeCall(id);
2250 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002251 }
2252
Santos Cordon823fd3c2014-08-07 18:35:18 -07002253 private String addConferenceInternal(Conference conference) {
Tyler Gunncd6ccfd2016-10-17 15:48:19 -07002254 String originalId = null;
2255 if (conference.getExtras() != null && conference.getExtras()
2256 .containsKey(Connection.EXTRA_ORIGINAL_CONNECTION_ID)) {
2257 originalId = conference.getExtras().getString(Connection.EXTRA_ORIGINAL_CONNECTION_ID);
2258 Log.d(this, "addConferenceInternal: conf %s reusing original id %s",
2259 conference.getTelecomCallId(),
2260 originalId);
2261 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07002262 if (mIdByConference.containsKey(conference)) {
2263 Log.w(this, "Re-adding an existing conference: %s.", conference);
2264 } else if (conference != null) {
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002265 // Conferences do not (yet) have a PhoneAccountHandle associated with them, so we
2266 // cannot determine a ConnectionService class name to associate with the ID, so use
2267 // a unique UUID (for now).
Tyler Gunncd6ccfd2016-10-17 15:48:19 -07002268 String id = originalId == null ? UUID.randomUUID().toString() : originalId;
Santos Cordon823fd3c2014-08-07 18:35:18 -07002269 mConferenceById.put(id, conference);
2270 mIdByConference.put(conference, id);
2271 conference.addListener(mConferenceListener);
2272 return id;
2273 }
2274
2275 return null;
2276 }
2277
2278 private void removeConference(Conference conference) {
2279 if (mIdByConference.containsKey(conference)) {
2280 conference.removeListener(mConferenceListener);
2281
2282 String id = mIdByConference.get(conference);
2283 mConferenceById.remove(id);
2284 mIdByConference.remove(conference);
2285 mAdapter.removeCall(id);
2286 }
2287 }
2288
Ihab Awad542e0ea2014-05-16 10:22:16 -07002289 private Connection findConnectionForAction(String callId, String action) {
Tyler Gunn0a88f2e2017-06-16 20:20:34 -07002290 if (callId != null && mConnectionById.containsKey(callId)) {
Ihab Awad542e0ea2014-05-16 10:22:16 -07002291 return mConnectionById.get(callId);
2292 }
Ihab Awad60ac30b2014-05-20 22:32:12 -07002293 Log.w(this, "%s - Cannot find Connection %s", action, callId);
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07002294 return getNullConnection();
2295 }
2296
2297 static synchronized Connection getNullConnection() {
2298 if (sNullConnection == null) {
2299 sNullConnection = new Connection() {};
2300 }
2301 return sNullConnection;
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002302 }
Santos Cordon0159ac02014-08-21 14:28:11 -07002303
2304 private Conference findConferenceForAction(String conferenceId, String action) {
2305 if (mConferenceById.containsKey(conferenceId)) {
2306 return mConferenceById.get(conferenceId);
2307 }
2308 Log.w(this, "%s - Cannot find conference %s", action, conferenceId);
2309 return getNullConference();
2310 }
2311
Ihab Awadb8e85c72014-08-23 20:34:57 -07002312 private List<String> createConnectionIdList(List<Connection> connections) {
2313 List<String> ids = new ArrayList<>();
2314 for (Connection c : connections) {
2315 if (mIdByConnection.containsKey(c)) {
2316 ids.add(mIdByConnection.get(c));
2317 }
2318 }
2319 Collections.sort(ids);
2320 return ids;
2321 }
2322
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002323 /**
2324 * Builds a list of {@link Connection} and {@link Conference} IDs based on the list of
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002325 * {@link Conferenceable}s passed in.
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002326 *
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002327 * @param conferenceables The {@link Conferenceable} connections and conferences.
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002328 * @return List of string conference and call Ids.
2329 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002330 private List<String> createIdList(List<Conferenceable> conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002331 List<String> ids = new ArrayList<>();
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002332 for (Conferenceable c : conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002333 // Only allow Connection and Conference conferenceables.
2334 if (c instanceof Connection) {
2335 Connection connection = (Connection) c;
2336 if (mIdByConnection.containsKey(connection)) {
2337 ids.add(mIdByConnection.get(connection));
2338 }
2339 } else if (c instanceof Conference) {
2340 Conference conference = (Conference) c;
2341 if (mIdByConference.containsKey(conference)) {
2342 ids.add(mIdByConference.get(conference));
2343 }
2344 }
2345 }
2346 Collections.sort(ids);
2347 return ids;
2348 }
2349
Santos Cordon0159ac02014-08-21 14:28:11 -07002350 private Conference getNullConference() {
2351 if (sNullConference == null) {
2352 sNullConference = new Conference(null) {};
2353 }
2354 return sNullConference;
2355 }
Santos Cordon29f2f2e2014-09-11 19:50:24 -07002356
2357 private void endAllConnections() {
2358 // Unbound from telecomm. We should end all connections and conferences.
2359 for (Connection connection : mIdByConnection.keySet()) {
2360 // only operate on top-level calls. Conference calls will be removed on their own.
2361 if (connection.getConference() == null) {
2362 connection.onDisconnect();
2363 }
2364 }
2365 for (Conference conference : mIdByConference.keySet()) {
2366 conference.onDisconnect();
2367 }
2368 }
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002369
2370 /**
2371 * Retrieves the next call ID as maintainted by the connection service.
2372 *
2373 * @return The call ID.
2374 */
2375 private int getNextCallId() {
Brad Ebingerb32d4f82016-10-24 16:40:49 -07002376 synchronized (mIdSyncRoot) {
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002377 return ++mId;
2378 }
2379 }
Santos Cordon980acb92014-05-31 10:31:19 -07002380}