blob: 70016157960aa0ce26ca1d2467eb8d6b4644e912 [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;
Santos Cordon6b7f9552015-05-27 17:21:45 -070024import android.os.Bundle;
Santos Cordon52d8a152014-06-17 19:08:45 -070025import android.os.Handler;
26import android.os.IBinder;
27import android.os.Looper;
Sailesh Nepal2a46b902014-07-04 17:21:07 -070028import android.os.Message;
Hall Liub64ac4c2017-02-06 10:49:48 -080029import android.os.ParcelFileDescriptor;
30import android.os.RemoteException;
Brad Ebingerb32d4f82016-10-24 16:40:49 -070031import android.telecom.Logging.Session;
Andrew Lee14185762014-07-25 09:41:56 -070032
Sailesh Nepal2a46b902014-07-04 17:21:07 -070033import com.android.internal.os.SomeArgs;
Tyler Gunnef9f6f92014-09-12 22:16:17 -070034import com.android.internal.telecom.IConnectionService;
35import com.android.internal.telecom.IConnectionServiceAdapter;
36import com.android.internal.telecom.RemoteServiceCallback;
Santos Cordon52d8a152014-06-17 19:08:45 -070037
Ihab Awad5d0410f2014-07-30 10:07:40 -070038import java.util.ArrayList;
Santos Cordonb6939982014-06-04 20:20:58 -070039import java.util.Collection;
Santos Cordon7c7bc7f2014-07-28 18:15:48 -070040import java.util.Collections;
Santos Cordon52d8a152014-06-17 19:08:45 -070041import java.util.List;
Ihab Awad542e0ea2014-05-16 10:22:16 -070042import java.util.Map;
Santos Cordon823fd3c2014-08-07 18:35:18 -070043import java.util.UUID;
mike dooley95e80702014-09-18 14:07:52 -070044import java.util.concurrent.ConcurrentHashMap;
Ihab Awad542e0ea2014-05-16 10:22:16 -070045
46/**
Tyler Gunnf5035432017-01-09 09:43:12 -080047 * An abstract service that should be implemented by any apps which either:
48 * <ol>
49 * <li>Can make phone calls (VoIP or otherwise) and want those calls to be integrated into the
50 * built-in phone app. Referred to as a <b>system managed</b> {@link ConnectionService}.</li>
51 * <li>Are a standalone calling app and don't want their calls to be integrated into the
52 * built-in phone app. Referred to as a <b>self managed</b> {@link ConnectionService}.</li>
53 * </ol>
54 * Once implemented, the {@link ConnectionService} needs to take the following steps so that Telecom
55 * will bind to it:
Santos Cordona663f862014-10-29 13:49:58 -070056 * <p>
57 * 1. <i>Registration in AndroidManifest.xml</i>
58 * <br/>
59 * <pre>
60 * &lt;service android:name="com.example.package.MyConnectionService"
61 * android:label="@string/some_label_for_my_connection_service"
Yorke Lee249c12e2015-05-13 15:59:29 -070062 * android:permission="android.permission.BIND_TELECOM_CONNECTION_SERVICE"&gt;
Santos Cordona663f862014-10-29 13:49:58 -070063 * &lt;intent-filter&gt;
64 * &lt;action android:name="android.telecom.ConnectionService" /&gt;
65 * &lt;/intent-filter&gt;
66 * &lt;/service&gt;
67 * </pre>
68 * <p>
69 * 2. <i> Registration of {@link PhoneAccount} with {@link TelecomManager}.</i>
70 * <br/>
71 * See {@link PhoneAccount} and {@link TelecomManager#registerPhoneAccount} for more information.
72 * <p>
Tyler Gunnf5035432017-01-09 09:43:12 -080073 * System managed {@link ConnectionService}s must be enabled by the user in the phone app settings
74 * before Telecom will bind to them. Self-manged {@link ConnectionService}s must be granted the
75 * appropriate permission before Telecom will bind to them.
76 * <p>
77 * Once registered and enabled by the user in the phone app settings or granted permission, telecom
78 * will bind to a {@link ConnectionService} implementation when it wants that
79 * {@link ConnectionService} to place a call or the service has indicated that is has an incoming
80 * call through {@link TelecomManager#addNewIncomingCall}. The {@link ConnectionService} can then
81 * expect a call to {@link #onCreateIncomingConnection} or {@link #onCreateOutgoingConnection}
82 * wherein it should provide a new instance of a {@link Connection} object. It is through this
83 * {@link Connection} object that telecom receives state updates and the {@link ConnectionService}
Santos Cordona663f862014-10-29 13:49:58 -070084 * receives call-commands such as answer, reject, hold and disconnect.
85 * <p>
Tyler Gunnf5035432017-01-09 09:43:12 -080086 * When there are no more live calls, telecom will unbind from the {@link ConnectionService}.
Ihab Awad542e0ea2014-05-16 10:22:16 -070087 */
Sailesh Nepal2a46b902014-07-04 17:21:07 -070088public abstract class ConnectionService extends Service {
Santos Cordon5c6fa952014-07-20 17:47:12 -070089 /**
90 * The {@link Intent} that must be declared as handled by the service.
91 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -070092 @SdkConstant(SdkConstant.SdkConstantType.SERVICE_ACTION)
Tyler Gunnef9f6f92014-09-12 22:16:17 -070093 public static final String SERVICE_INTERFACE = "android.telecom.ConnectionService";
Santos Cordon5c6fa952014-07-20 17:47:12 -070094
Tyler Gunn8bf76572017-04-06 15:30:08 -070095 /**
96 * Boolean extra used by Telecom to inform a {@link ConnectionService} that the purpose of it
97 * being asked to create a new outgoing {@link Connection} is to perform a handover of an
98 * ongoing call on the device from another {@link PhoneAccount}/{@link ConnectionService}. Will
99 * be specified in the {@link ConnectionRequest#getExtras()} passed by Telecom when
100 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)} is called.
101 * <p>
Tyler Gunn727c6bd2017-04-11 09:51:40 -0700102 * When your {@link ConnectionService} receives this extra, it should communicate the fact that
103 * this is a handover to the other device's matching {@link ConnectionService}. That
Tyler Gunn8bf76572017-04-06 15:30:08 -0700104 * {@link ConnectionService} will continue the handover using
105 * {@link TelecomManager#addNewIncomingCall(PhoneAccountHandle, Bundle)}, specifying
Tyler Gunn727c6bd2017-04-11 09:51:40 -0700106 * {@link TelecomManager#EXTRA_IS_HANDOVER}. Telecom will match the phone numbers of the
107 * handover call on the other device with ongoing calls for {@link ConnectionService}s which
108 * support {@link PhoneAccount#EXTRA_SUPPORTS_HANDOVER_FROM}.
Tyler Gunn8bf76572017-04-06 15:30:08 -0700109 * @hide
110 */
111 public static final String EXTRA_IS_HANDOVER = TelecomManager.EXTRA_IS_HANDOVER;
112
Ihab Awad542e0ea2014-05-16 10:22:16 -0700113 // Flag controlling whether PII is emitted into the logs
Ihab Awad60ac30b2014-05-20 22:32:12 -0700114 private static final boolean PII_DEBUG = Log.isLoggable(android.util.Log.DEBUG);
Ihab Awad542e0ea2014-05-16 10:22:16 -0700115
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700116 // Session Definitions
117 private static final String SESSION_HANDLER = "H.";
118 private static final String SESSION_ADD_CS_ADAPTER = "CS.aCSA";
119 private static final String SESSION_REMOVE_CS_ADAPTER = "CS.rCSA";
120 private static final String SESSION_CREATE_CONN = "CS.crCo";
Tyler Gunn041a1fe2017-05-12 10:04:49 -0700121 private static final String SESSION_CREATE_CONN_COMPLETE = "CS.crCoC";
Tyler Gunn44e01912017-01-31 10:49:05 -0800122 private static final String SESSION_CREATE_CONN_FAILED = "CS.crCoF";
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700123 private static final String SESSION_ABORT = "CS.ab";
124 private static final String SESSION_ANSWER = "CS.an";
125 private static final String SESSION_ANSWER_VIDEO = "CS.anV";
126 private static final String SESSION_REJECT = "CS.r";
127 private static final String SESSION_REJECT_MESSAGE = "CS.rWM";
128 private static final String SESSION_SILENCE = "CS.s";
129 private static final String SESSION_DISCONNECT = "CS.d";
130 private static final String SESSION_HOLD = "CS.h";
131 private static final String SESSION_UNHOLD = "CS.u";
132 private static final String SESSION_CALL_AUDIO_SC = "CS.cASC";
133 private static final String SESSION_PLAY_DTMF = "CS.pDT";
134 private static final String SESSION_STOP_DTMF = "CS.sDT";
135 private static final String SESSION_CONFERENCE = "CS.c";
136 private static final String SESSION_SPLIT_CONFERENCE = "CS.sFC";
137 private static final String SESSION_MERGE_CONFERENCE = "CS.mC";
138 private static final String SESSION_SWAP_CONFERENCE = "CS.sC";
139 private static final String SESSION_POST_DIAL_CONT = "CS.oPDC";
140 private static final String SESSION_PULL_EXTERNAL_CALL = "CS.pEC";
141 private static final String SESSION_SEND_CALL_EVENT = "CS.sCE";
142 private static final String SESSION_EXTRAS_CHANGED = "CS.oEC";
Hall Liub64ac4c2017-02-06 10:49:48 -0800143 private static final String SESSION_START_RTT = "CS.+RTT";
144 private static final String SESSION_STOP_RTT = "CS.-RTT";
145 private static final String SESSION_RTT_UPGRADE_RESPONSE = "CS.rTRUR";
Pengquan Meng731c1a32017-11-21 18:01:13 -0800146 private static final String SESSION_CONNECTION_SERVICE_FOCUS_LOST = "CS.cSFL";
147 private static final String SESSION_CONNECTION_SERVICE_FOCUS_GAINED = "CS.cSFG";
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;
Pengquan Meng731c1a32017-11-21 18:01:13 -0800177 private static final int MSG_CONNECTION_SERVICE_FOCUS_LOST = 30;
178 private static final int MSG_CONNECTION_SERVICE_FOCUS_GAINED = 31;
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700179
Sailesh Nepalcf7020b2014-08-20 10:07:19 -0700180 private static Connection sNullConnection;
181
mike dooley95e80702014-09-18 14:07:52 -0700182 private final Map<String, Connection> mConnectionById = new ConcurrentHashMap<>();
183 private final Map<Connection, String> mIdByConnection = new ConcurrentHashMap<>();
184 private final Map<String, Conference> mConferenceById = new ConcurrentHashMap<>();
185 private final Map<Conference, String> mIdByConference = new ConcurrentHashMap<>();
Ihab Awadb8e85c72014-08-23 20:34:57 -0700186 private final RemoteConnectionManager mRemoteConnectionManager =
187 new RemoteConnectionManager(this);
Ihab Awad5d0410f2014-07-30 10:07:40 -0700188 private final List<Runnable> mPreInitializationConnectionRequests = new ArrayList<>();
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700189 private final ConnectionServiceAdapter mAdapter = new ConnectionServiceAdapter();
Ihab Awad542e0ea2014-05-16 10:22:16 -0700190
Santos Cordon823fd3c2014-08-07 18:35:18 -0700191 private boolean mAreAccountsInitialized = false;
Santos Cordon0159ac02014-08-21 14:28:11 -0700192 private Conference sNullConference;
Tyler Gunnf0500bd2015-09-01 10:59:48 -0700193 private Object mIdSyncRoot = new Object();
194 private int mId = 0;
Santos Cordon823fd3c2014-08-07 18:35:18 -0700195
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700196 private final IBinder mBinder = new IConnectionService.Stub() {
197 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700198 public void addConnectionServiceAdapter(IConnectionServiceAdapter adapter,
199 Session.Info sessionInfo) {
200 Log.startSession(sessionInfo, SESSION_ADD_CS_ADAPTER);
201 try {
202 SomeArgs args = SomeArgs.obtain();
203 args.arg1 = adapter;
204 args.arg2 = Log.createSubsession();
205 mHandler.obtainMessage(MSG_ADD_CONNECTION_SERVICE_ADAPTER, args).sendToTarget();
206 } finally {
207 Log.endSession();
208 }
Ihab Awad8aecfed2014-08-08 17:06:11 -0700209 }
210
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700211 public void removeConnectionServiceAdapter(IConnectionServiceAdapter adapter,
212 Session.Info sessionInfo) {
213 Log.startSession(sessionInfo, SESSION_REMOVE_CS_ADAPTER);
214 try {
215 SomeArgs args = SomeArgs.obtain();
216 args.arg1 = adapter;
217 args.arg2 = Log.createSubsession();
218 mHandler.obtainMessage(MSG_REMOVE_CONNECTION_SERVICE_ADAPTER, args).sendToTarget();
219 } finally {
220 Log.endSession();
221 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700222 }
223
224 @Override
Ihab Awadf8b69882014-07-25 15:14:01 -0700225 public void createConnection(
226 PhoneAccountHandle connectionManagerPhoneAccount,
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700227 String id,
Ihab Awadf8b69882014-07-25 15:14:01 -0700228 ConnectionRequest request,
Yorke Leec3cf9822014-10-02 09:38:39 -0700229 boolean isIncoming,
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700230 boolean isUnknown,
231 Session.Info sessionInfo) {
232 Log.startSession(sessionInfo, SESSION_CREATE_CONN);
233 try {
234 SomeArgs args = SomeArgs.obtain();
235 args.arg1 = connectionManagerPhoneAccount;
236 args.arg2 = id;
237 args.arg3 = request;
238 args.arg4 = Log.createSubsession();
239 args.argi1 = isIncoming ? 1 : 0;
240 args.argi2 = isUnknown ? 1 : 0;
241 mHandler.obtainMessage(MSG_CREATE_CONNECTION, args).sendToTarget();
242 } finally {
243 Log.endSession();
244 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700245 }
246
247 @Override
Tyler Gunn041a1fe2017-05-12 10:04:49 -0700248 public void createConnectionComplete(String id, Session.Info sessionInfo) {
249 Log.startSession(sessionInfo, SESSION_CREATE_CONN_COMPLETE);
250 try {
251 SomeArgs args = SomeArgs.obtain();
252 args.arg1 = id;
253 args.arg2 = Log.createSubsession();
254 mHandler.obtainMessage(MSG_CREATE_CONNECTION_COMPLETE, args).sendToTarget();
255 } finally {
256 Log.endSession();
257 }
258 }
259
260 @Override
Tyler Gunn44e01912017-01-31 10:49:05 -0800261 public void createConnectionFailed(
Tyler Gunn159f35c2017-03-02 09:28:37 -0800262 PhoneAccountHandle connectionManagerPhoneAccount,
Tyler Gunn44e01912017-01-31 10:49:05 -0800263 String callId,
264 ConnectionRequest request,
265 boolean isIncoming,
266 Session.Info sessionInfo) {
267 Log.startSession(sessionInfo, SESSION_CREATE_CONN_FAILED);
268 try {
269 SomeArgs args = SomeArgs.obtain();
270 args.arg1 = callId;
271 args.arg2 = request;
272 args.arg3 = Log.createSubsession();
Tyler Gunn159f35c2017-03-02 09:28:37 -0800273 args.arg4 = connectionManagerPhoneAccount;
Tyler Gunn44e01912017-01-31 10:49:05 -0800274 args.argi1 = isIncoming ? 1 : 0;
275 mHandler.obtainMessage(MSG_CREATE_CONNECTION_FAILED, args).sendToTarget();
276 } finally {
277 Log.endSession();
278 }
279 }
280
281 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700282 public void abort(String callId, Session.Info sessionInfo) {
283 Log.startSession(sessionInfo, SESSION_ABORT);
284 try {
285 SomeArgs args = SomeArgs.obtain();
286 args.arg1 = callId;
287 args.arg2 = Log.createSubsession();
288 mHandler.obtainMessage(MSG_ABORT, args).sendToTarget();
289 } finally {
290 Log.endSession();
291 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700292 }
293
294 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700295 public void answerVideo(String callId, int videoState, Session.Info sessionInfo) {
296 Log.startSession(sessionInfo, SESSION_ANSWER_VIDEO);
297 try {
298 SomeArgs args = SomeArgs.obtain();
299 args.arg1 = callId;
300 args.arg2 = Log.createSubsession();
301 args.argi1 = videoState;
302 mHandler.obtainMessage(MSG_ANSWER_VIDEO, args).sendToTarget();
303 } finally {
304 Log.endSession();
305 }
Tyler Gunnbe74de02014-08-29 14:51:48 -0700306 }
307
308 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700309 public void answer(String callId, Session.Info sessionInfo) {
310 Log.startSession(sessionInfo, SESSION_ANSWER);
311 try {
312 SomeArgs args = SomeArgs.obtain();
313 args.arg1 = callId;
314 args.arg2 = Log.createSubsession();
315 mHandler.obtainMessage(MSG_ANSWER, args).sendToTarget();
316 } finally {
317 Log.endSession();
318 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700319 }
320
321 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700322 public void reject(String callId, Session.Info sessionInfo) {
323 Log.startSession(sessionInfo, SESSION_REJECT);
324 try {
325 SomeArgs args = SomeArgs.obtain();
326 args.arg1 = callId;
327 args.arg2 = Log.createSubsession();
328 mHandler.obtainMessage(MSG_REJECT, args).sendToTarget();
329 } finally {
330 Log.endSession();
331 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700332 }
333
334 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700335 public void rejectWithMessage(String callId, String message, Session.Info sessionInfo) {
336 Log.startSession(sessionInfo, SESSION_REJECT_MESSAGE);
337 try {
338 SomeArgs args = SomeArgs.obtain();
339 args.arg1 = callId;
340 args.arg2 = message;
341 args.arg3 = Log.createSubsession();
342 mHandler.obtainMessage(MSG_REJECT_WITH_MESSAGE, args).sendToTarget();
343 } finally {
344 Log.endSession();
345 }
Bryce Lee81901682015-08-28 16:38:02 -0700346 }
347
348 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700349 public void silence(String callId, Session.Info sessionInfo) {
350 Log.startSession(sessionInfo, SESSION_SILENCE);
351 try {
352 SomeArgs args = SomeArgs.obtain();
353 args.arg1 = callId;
354 args.arg2 = Log.createSubsession();
355 mHandler.obtainMessage(MSG_SILENCE, args).sendToTarget();
356 } finally {
357 Log.endSession();
358 }
Bryce Leecac50772015-11-17 15:13:29 -0800359 }
360
361 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700362 public void disconnect(String callId, Session.Info sessionInfo) {
363 Log.startSession(sessionInfo, SESSION_DISCONNECT);
364 try {
365 SomeArgs args = SomeArgs.obtain();
366 args.arg1 = callId;
367 args.arg2 = Log.createSubsession();
368 mHandler.obtainMessage(MSG_DISCONNECT, args).sendToTarget();
369 } finally {
370 Log.endSession();
371 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700372 }
373
374 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700375 public void hold(String callId, Session.Info sessionInfo) {
376 Log.startSession(sessionInfo, SESSION_HOLD);
377 try {
378 SomeArgs args = SomeArgs.obtain();
379 args.arg1 = callId;
380 args.arg2 = Log.createSubsession();
381 mHandler.obtainMessage(MSG_HOLD, args).sendToTarget();
382 } finally {
383 Log.endSession();
384 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700385 }
386
387 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700388 public void unhold(String callId, Session.Info sessionInfo) {
389 Log.startSession(sessionInfo, SESSION_UNHOLD);
390 try {
391 SomeArgs args = SomeArgs.obtain();
392 args.arg1 = callId;
393 args.arg2 = Log.createSubsession();
394 mHandler.obtainMessage(MSG_UNHOLD, args).sendToTarget();
395 } finally {
396 Log.endSession();
397 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700398 }
399
400 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700401 public void onCallAudioStateChanged(String callId, CallAudioState callAudioState,
402 Session.Info sessionInfo) {
403 Log.startSession(sessionInfo, SESSION_CALL_AUDIO_SC);
404 try {
405 SomeArgs args = SomeArgs.obtain();
406 args.arg1 = callId;
407 args.arg2 = callAudioState;
408 args.arg3 = Log.createSubsession();
409 mHandler.obtainMessage(MSG_ON_CALL_AUDIO_STATE_CHANGED, 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 playDtmfTone(String callId, char digit, Session.Info sessionInfo) {
417 Log.startSession(sessionInfo, SESSION_PLAY_DTMF);
418 try {
419 SomeArgs args = SomeArgs.obtain();
420 args.arg1 = digit;
421 args.arg2 = callId;
422 args.arg3 = Log.createSubsession();
423 mHandler.obtainMessage(MSG_PLAY_DTMF_TONE, args).sendToTarget();
424 } finally {
425 Log.endSession();
426 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700427 }
428
429 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700430 public void stopDtmfTone(String callId, Session.Info sessionInfo) {
431 Log.startSession(sessionInfo, SESSION_STOP_DTMF);
432 try {
433 SomeArgs args = SomeArgs.obtain();
434 args.arg1 = callId;
435 args.arg2 = Log.createSubsession();
436 mHandler.obtainMessage(MSG_STOP_DTMF_TONE, args).sendToTarget();
437 } finally {
438 Log.endSession();
439 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700440 }
441
442 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700443 public void conference(String callId1, String callId2, Session.Info sessionInfo) {
444 Log.startSession(sessionInfo, SESSION_CONFERENCE);
445 try {
446 SomeArgs args = SomeArgs.obtain();
447 args.arg1 = callId1;
448 args.arg2 = callId2;
449 args.arg3 = Log.createSubsession();
450 mHandler.obtainMessage(MSG_CONFERENCE, args).sendToTarget();
451 } finally {
452 Log.endSession();
453 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700454 }
455
456 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700457 public void splitFromConference(String callId, Session.Info sessionInfo) {
458 Log.startSession(sessionInfo, SESSION_SPLIT_CONFERENCE);
459 try {
460 SomeArgs args = SomeArgs.obtain();
461 args.arg1 = callId;
462 args.arg2 = Log.createSubsession();
463 mHandler.obtainMessage(MSG_SPLIT_FROM_CONFERENCE, args).sendToTarget();
464 } finally {
465 Log.endSession();
466 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700467 }
468
469 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700470 public void mergeConference(String callId, Session.Info sessionInfo) {
471 Log.startSession(sessionInfo, SESSION_MERGE_CONFERENCE);
472 try {
473 SomeArgs args = SomeArgs.obtain();
474 args.arg1 = callId;
475 args.arg2 = Log.createSubsession();
476 mHandler.obtainMessage(MSG_MERGE_CONFERENCE, args).sendToTarget();
477 } finally {
478 Log.endSession();
479 }
Santos Cordona4868042014-09-04 17:39:22 -0700480 }
481
482 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700483 public void swapConference(String callId, Session.Info sessionInfo) {
484 Log.startSession(sessionInfo, SESSION_SWAP_CONFERENCE);
485 try {
486 SomeArgs args = SomeArgs.obtain();
487 args.arg1 = callId;
488 args.arg2 = Log.createSubsession();
489 mHandler.obtainMessage(MSG_SWAP_CONFERENCE, args).sendToTarget();
490 } finally {
491 Log.endSession();
492 }
Santos Cordona4868042014-09-04 17:39:22 -0700493 }
494
495 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700496 public void onPostDialContinue(String callId, boolean proceed, Session.Info sessionInfo) {
497 Log.startSession(sessionInfo, SESSION_POST_DIAL_CONT);
498 try {
499 SomeArgs args = SomeArgs.obtain();
500 args.arg1 = callId;
501 args.arg2 = Log.createSubsession();
502 args.argi1 = proceed ? 1 : 0;
503 mHandler.obtainMessage(MSG_ON_POST_DIAL_CONTINUE, args).sendToTarget();
504 } finally {
505 Log.endSession();
506 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700507 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700508
509 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700510 public void pullExternalCall(String callId, Session.Info sessionInfo) {
511 Log.startSession(sessionInfo, SESSION_PULL_EXTERNAL_CALL);
512 try {
513 SomeArgs args = SomeArgs.obtain();
514 args.arg1 = callId;
515 args.arg2 = Log.createSubsession();
516 mHandler.obtainMessage(MSG_PULL_EXTERNAL_CALL, args).sendToTarget();
517 } finally {
518 Log.endSession();
519 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700520 }
521
522 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700523 public void sendCallEvent(String callId, String event, Bundle extras,
524 Session.Info sessionInfo) {
525 Log.startSession(sessionInfo, SESSION_SEND_CALL_EVENT);
526 try {
527 SomeArgs args = SomeArgs.obtain();
528 args.arg1 = callId;
529 args.arg2 = event;
530 args.arg3 = extras;
531 args.arg4 = Log.createSubsession();
532 mHandler.obtainMessage(MSG_SEND_CALL_EVENT, args).sendToTarget();
533 } finally {
534 Log.endSession();
535 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700536 }
Tyler Gunndee56a82016-03-23 16:06:34 -0700537
538 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700539 public void onExtrasChanged(String callId, Bundle extras, Session.Info sessionInfo) {
540 Log.startSession(sessionInfo, SESSION_EXTRAS_CHANGED);
541 try {
542 SomeArgs args = SomeArgs.obtain();
543 args.arg1 = callId;
544 args.arg2 = extras;
545 args.arg3 = Log.createSubsession();
546 mHandler.obtainMessage(MSG_ON_EXTRAS_CHANGED, args).sendToTarget();
547 } finally {
548 Log.endSession();
549 }
Tyler Gunndee56a82016-03-23 16:06:34 -0700550 }
Hall Liub64ac4c2017-02-06 10:49:48 -0800551
552 @Override
553 public void startRtt(String callId, ParcelFileDescriptor fromInCall,
554 ParcelFileDescriptor toInCall, Session.Info sessionInfo) throws RemoteException {
555 Log.startSession(sessionInfo, SESSION_START_RTT);
556 try {
557 SomeArgs args = SomeArgs.obtain();
558 args.arg1 = callId;
559 args.arg2 = new Connection.RttTextStream(toInCall, fromInCall);
560 args.arg3 = Log.createSubsession();
561 mHandler.obtainMessage(MSG_ON_START_RTT, args).sendToTarget();
562 } finally {
563 Log.endSession();
564 }
565 }
566
567 @Override
568 public void stopRtt(String callId, Session.Info sessionInfo) throws RemoteException {
569 Log.startSession(sessionInfo, SESSION_STOP_RTT);
570 try {
571 SomeArgs args = SomeArgs.obtain();
572 args.arg1 = callId;
573 args.arg2 = Log.createSubsession();
574 mHandler.obtainMessage(MSG_ON_STOP_RTT, args).sendToTarget();
575 } finally {
576 Log.endSession();
577 }
578 }
579
580 @Override
581 public void respondToRttUpgradeRequest(String callId, ParcelFileDescriptor fromInCall,
582 ParcelFileDescriptor toInCall, Session.Info sessionInfo) throws RemoteException {
583 Log.startSession(sessionInfo, SESSION_RTT_UPGRADE_RESPONSE);
584 try {
585 SomeArgs args = SomeArgs.obtain();
586 args.arg1 = callId;
587 if (toInCall == null || fromInCall == null) {
588 args.arg2 = null;
589 } else {
590 args.arg2 = new Connection.RttTextStream(toInCall, fromInCall);
591 }
592 args.arg3 = Log.createSubsession();
593 mHandler.obtainMessage(MSG_RTT_UPGRADE_RESPONSE, args).sendToTarget();
594 } finally {
595 Log.endSession();
596 }
597 }
Pengquan Meng731c1a32017-11-21 18:01:13 -0800598
599 @Override
600 public void connectionServiceFocusLost(Session.Info sessionInfo) throws RemoteException {
601 Log.startSession(sessionInfo, SESSION_CONNECTION_SERVICE_FOCUS_LOST);
602 try {
603 mHandler.obtainMessage(MSG_CONNECTION_SERVICE_FOCUS_LOST).sendToTarget();
604 } finally {
605 Log.endSession();
606 }
607 }
608
609 @Override
610 public void connectionServiceFocusGained(Session.Info sessionInfo) throws RemoteException {
611 Log.startSession(sessionInfo, SESSION_CONNECTION_SERVICE_FOCUS_GAINED);
612 try {
613 mHandler.obtainMessage(MSG_CONNECTION_SERVICE_FOCUS_GAINED).sendToTarget();
614 } finally {
615 Log.endSession();
616 }
617 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700618 };
619
620 private final Handler mHandler = new Handler(Looper.getMainLooper()) {
621 @Override
622 public void handleMessage(Message msg) {
623 switch (msg.what) {
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700624 case MSG_ADD_CONNECTION_SERVICE_ADAPTER: {
625 SomeArgs args = (SomeArgs) msg.obj;
626 try {
627 IConnectionServiceAdapter adapter = (IConnectionServiceAdapter) args.arg1;
628 Log.continueSession((Session) args.arg2,
629 SESSION_HANDLER + SESSION_ADD_CS_ADAPTER);
630 mAdapter.addAdapter(adapter);
631 onAdapterAttached();
632 } finally {
633 args.recycle();
634 Log.endSession();
635 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700636 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700637 }
638 case MSG_REMOVE_CONNECTION_SERVICE_ADAPTER: {
639 SomeArgs args = (SomeArgs) msg.obj;
640 try {
641 Log.continueSession((Session) args.arg2,
642 SESSION_HANDLER + SESSION_REMOVE_CS_ADAPTER);
643 mAdapter.removeAdapter((IConnectionServiceAdapter) args.arg1);
644 } finally {
645 args.recycle();
646 Log.endSession();
647 }
Ihab Awad8aecfed2014-08-08 17:06:11 -0700648 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700649 }
Ihab Awadf8b69882014-07-25 15:14:01 -0700650 case MSG_CREATE_CONNECTION: {
651 SomeArgs args = (SomeArgs) msg.obj;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700652 Log.continueSession((Session) args.arg4, SESSION_HANDLER + SESSION_CREATE_CONN);
Ihab Awadf8b69882014-07-25 15:14:01 -0700653 try {
Ihab Awad5d0410f2014-07-30 10:07:40 -0700654 final PhoneAccountHandle connectionManagerPhoneAccount =
Ihab Awadf8b69882014-07-25 15:14:01 -0700655 (PhoneAccountHandle) args.arg1;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700656 final String id = (String) args.arg2;
657 final ConnectionRequest request = (ConnectionRequest) args.arg3;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700658 final boolean isIncoming = args.argi1 == 1;
Yorke Leec3cf9822014-10-02 09:38:39 -0700659 final boolean isUnknown = args.argi2 == 1;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700660 if (!mAreAccountsInitialized) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700661 Log.d(this, "Enqueueing pre-init request %s", id);
Brad Ebinger0c3541b2016-11-01 14:11:38 -0700662 mPreInitializationConnectionRequests.add(
663 new android.telecom.Logging.Runnable(
664 SESSION_HANDLER + SESSION_CREATE_CONN + ".pICR",
665 null /*lock*/) {
Ihab Awad5d0410f2014-07-30 10:07:40 -0700666 @Override
Brad Ebinger0c3541b2016-11-01 14:11:38 -0700667 public void loggedRun() {
Ihab Awad5d0410f2014-07-30 10:07:40 -0700668 createConnection(
669 connectionManagerPhoneAccount,
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700670 id,
Ihab Awad5d0410f2014-07-30 10:07:40 -0700671 request,
Yorke Leec3cf9822014-10-02 09:38:39 -0700672 isIncoming,
673 isUnknown);
Ihab Awad5d0410f2014-07-30 10:07:40 -0700674 }
Brad Ebinger0c3541b2016-11-01 14:11:38 -0700675 }.prepare());
Ihab Awad5d0410f2014-07-30 10:07:40 -0700676 } else {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700677 createConnection(
678 connectionManagerPhoneAccount,
679 id,
680 request,
Yorke Leec3cf9822014-10-02 09:38:39 -0700681 isIncoming,
682 isUnknown);
Ihab Awad5d0410f2014-07-30 10:07:40 -0700683 }
Ihab Awadf8b69882014-07-25 15:14:01 -0700684 } finally {
685 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700686 Log.endSession();
Ihab Awadf8b69882014-07-25 15:14:01 -0700687 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700688 break;
Ihab Awadf8b69882014-07-25 15:14:01 -0700689 }
Tyler Gunn041a1fe2017-05-12 10:04:49 -0700690 case MSG_CREATE_CONNECTION_COMPLETE: {
691 SomeArgs args = (SomeArgs) msg.obj;
692 Log.continueSession((Session) args.arg2,
693 SESSION_HANDLER + SESSION_CREATE_CONN_COMPLETE);
694 try {
695 final String id = (String) args.arg1;
696 if (!mAreAccountsInitialized) {
697 Log.d(this, "Enqueueing pre-init request %s", id);
698 mPreInitializationConnectionRequests.add(
699 new android.telecom.Logging.Runnable(
700 SESSION_HANDLER + SESSION_CREATE_CONN_COMPLETE
701 + ".pICR",
702 null /*lock*/) {
703 @Override
704 public void loggedRun() {
705 notifyCreateConnectionComplete(id);
706 }
707 }.prepare());
708 } else {
709 notifyCreateConnectionComplete(id);
710 }
711 } finally {
712 args.recycle();
713 Log.endSession();
714 }
715 break;
716 }
Tyler Gunn44e01912017-01-31 10:49:05 -0800717 case MSG_CREATE_CONNECTION_FAILED: {
718 SomeArgs args = (SomeArgs) msg.obj;
719 Log.continueSession((Session) args.arg3, SESSION_HANDLER +
720 SESSION_CREATE_CONN_FAILED);
721 try {
722 final String id = (String) args.arg1;
723 final ConnectionRequest request = (ConnectionRequest) args.arg2;
724 final boolean isIncoming = args.argi1 == 1;
Tyler Gunn159f35c2017-03-02 09:28:37 -0800725 final PhoneAccountHandle connectionMgrPhoneAccount =
726 (PhoneAccountHandle) args.arg4;
Tyler Gunn44e01912017-01-31 10:49:05 -0800727 if (!mAreAccountsInitialized) {
728 Log.d(this, "Enqueueing pre-init request %s", id);
729 mPreInitializationConnectionRequests.add(
730 new android.telecom.Logging.Runnable(
731 SESSION_HANDLER + SESSION_CREATE_CONN_FAILED + ".pICR",
732 null /*lock*/) {
733 @Override
734 public void loggedRun() {
Tyler Gunn159f35c2017-03-02 09:28:37 -0800735 createConnectionFailed(connectionMgrPhoneAccount, id,
736 request, isIncoming);
Tyler Gunn44e01912017-01-31 10:49:05 -0800737 }
738 }.prepare());
739 } else {
740 Log.i(this, "createConnectionFailed %s", id);
Tyler Gunn159f35c2017-03-02 09:28:37 -0800741 createConnectionFailed(connectionMgrPhoneAccount, id, request,
742 isIncoming);
Tyler Gunn44e01912017-01-31 10:49:05 -0800743 }
744 } finally {
745 args.recycle();
746 Log.endSession();
747 }
748 break;
749 }
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700750 case MSG_ABORT: {
751 SomeArgs args = (SomeArgs) msg.obj;
752 Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_ABORT);
753 try {
754 abort((String) args.arg1);
755 } finally {
756 args.recycle();
757 Log.endSession();
758 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700759 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700760 }
761 case MSG_ANSWER: {
762 SomeArgs args = (SomeArgs) msg.obj;
763 Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_ANSWER);
764 try {
765 answer((String) args.arg1);
766 } finally {
767 args.recycle();
768 Log.endSession();
769 }
Tyler Gunnbe74de02014-08-29 14:51:48 -0700770 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700771 }
Tyler Gunnbe74de02014-08-29 14:51:48 -0700772 case MSG_ANSWER_VIDEO: {
Andrew Lee8da4c3c2014-07-16 10:11:42 -0700773 SomeArgs args = (SomeArgs) msg.obj;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700774 Log.continueSession((Session) args.arg2,
775 SESSION_HANDLER + SESSION_ANSWER_VIDEO);
Andrew Lee8da4c3c2014-07-16 10:11:42 -0700776 try {
777 String callId = (String) args.arg1;
Evan Charltonbf11f982014-07-20 22:06:28 -0700778 int videoState = args.argi1;
Tyler Gunnbe74de02014-08-29 14:51:48 -0700779 answerVideo(callId, videoState);
Andrew Lee8da4c3c2014-07-16 10:11:42 -0700780 } finally {
781 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700782 Log.endSession();
Andrew Lee8da4c3c2014-07-16 10:11:42 -0700783 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700784 break;
Andrew Lee8da4c3c2014-07-16 10:11:42 -0700785 }
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700786 case MSG_REJECT: {
787 SomeArgs args = (SomeArgs) msg.obj;
788 Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_REJECT);
789 try {
790 reject((String) args.arg1);
791 } finally {
792 args.recycle();
793 Log.endSession();
794 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700795 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700796 }
Bryce Lee81901682015-08-28 16:38:02 -0700797 case MSG_REJECT_WITH_MESSAGE: {
798 SomeArgs args = (SomeArgs) msg.obj;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700799 Log.continueSession((Session) args.arg3,
800 SESSION_HANDLER + SESSION_REJECT_MESSAGE);
Bryce Lee81901682015-08-28 16:38:02 -0700801 try {
802 reject((String) args.arg1, (String) args.arg2);
803 } finally {
804 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700805 Log.endSession();
Bryce Lee81901682015-08-28 16:38:02 -0700806 }
807 break;
808 }
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700809 case MSG_DISCONNECT: {
810 SomeArgs args = (SomeArgs) msg.obj;
811 Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_DISCONNECT);
812 try {
813 disconnect((String) args.arg1);
814 } finally {
815 args.recycle();
816 Log.endSession();
817 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700818 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700819 }
820 case MSG_SILENCE: {
821 SomeArgs args = (SomeArgs) msg.obj;
822 Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_SILENCE);
823 try {
824 silence((String) args.arg1);
825 } finally {
826 args.recycle();
827 Log.endSession();
828 }
Bryce Leecac50772015-11-17 15:13:29 -0800829 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700830 }
831 case MSG_HOLD: {
832 SomeArgs args = (SomeArgs) msg.obj;
833 Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_REJECT);
834 try {
835 hold((String) args.arg1);
836 } finally {
837 args.recycle();
838 Log.endSession();
839 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700840 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700841 }
842 case MSG_UNHOLD: {
843 SomeArgs args = (SomeArgs) msg.obj;
844 Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_UNHOLD);
845 try {
846 unhold((String) args.arg1);
847 } finally {
848 args.recycle();
849 Log.endSession();
850 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700851 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700852 }
Yorke Lee4af59352015-05-13 14:14:54 -0700853 case MSG_ON_CALL_AUDIO_STATE_CHANGED: {
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700854 SomeArgs args = (SomeArgs) msg.obj;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700855 Log.continueSession((Session) args.arg3,
856 SESSION_HANDLER + SESSION_CALL_AUDIO_SC);
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700857 try {
858 String callId = (String) args.arg1;
Yorke Lee4af59352015-05-13 14:14:54 -0700859 CallAudioState audioState = (CallAudioState) args.arg2;
860 onCallAudioStateChanged(callId, new CallAudioState(audioState));
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700861 } finally {
862 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700863 Log.endSession();
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700864 }
865 break;
866 }
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700867 case MSG_PLAY_DTMF_TONE: {
868 SomeArgs args = (SomeArgs) msg.obj;
869 try {
870 Log.continueSession((Session) args.arg3,
871 SESSION_HANDLER + SESSION_PLAY_DTMF);
872 playDtmfTone((String) args.arg2, (char) args.arg1);
873 } finally {
874 args.recycle();
875 Log.endSession();
876 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700877 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700878 }
879 case MSG_STOP_DTMF_TONE: {
880 SomeArgs args = (SomeArgs) msg.obj;
881 try {
882 Log.continueSession((Session) args.arg2,
883 SESSION_HANDLER + SESSION_STOP_DTMF);
884 stopDtmfTone((String) args.arg1);
885 } finally {
886 args.recycle();
887 Log.endSession();
888 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700889 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700890 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700891 case MSG_CONFERENCE: {
892 SomeArgs args = (SomeArgs) msg.obj;
893 try {
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700894 Log.continueSession((Session) args.arg3,
895 SESSION_HANDLER + SESSION_CONFERENCE);
Santos Cordon823fd3c2014-08-07 18:35:18 -0700896 String callId1 = (String) args.arg1;
897 String callId2 = (String) args.arg2;
898 conference(callId1, callId2);
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700899 } finally {
900 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700901 Log.endSession();
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700902 }
903 break;
904 }
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700905 case MSG_SPLIT_FROM_CONFERENCE: {
906 SomeArgs args = (SomeArgs) msg.obj;
907 try {
908 Log.continueSession((Session) args.arg2,
909 SESSION_HANDLER + SESSION_SPLIT_CONFERENCE);
910 splitFromConference((String) args.arg1);
911 } finally {
912 args.recycle();
913 Log.endSession();
914 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700915 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700916 }
917 case MSG_MERGE_CONFERENCE: {
918 SomeArgs args = (SomeArgs) msg.obj;
919 try {
920 Log.continueSession((Session) args.arg2,
921 SESSION_HANDLER + SESSION_MERGE_CONFERENCE);
922 mergeConference((String) args.arg1);
923 } finally {
924 args.recycle();
925 Log.endSession();
926 }
Santos Cordona4868042014-09-04 17:39:22 -0700927 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700928 }
929 case MSG_SWAP_CONFERENCE: {
930 SomeArgs args = (SomeArgs) msg.obj;
931 try {
932 Log.continueSession((Session) args.arg2,
933 SESSION_HANDLER + SESSION_SWAP_CONFERENCE);
934 swapConference((String) args.arg1);
935 } finally {
936 args.recycle();
937 Log.endSession();
938 }
Santos Cordona4868042014-09-04 17:39:22 -0700939 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700940 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700941 case MSG_ON_POST_DIAL_CONTINUE: {
942 SomeArgs args = (SomeArgs) msg.obj;
943 try {
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700944 Log.continueSession((Session) args.arg2,
945 SESSION_HANDLER + SESSION_POST_DIAL_CONT);
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700946 String callId = (String) args.arg1;
947 boolean proceed = (args.argi1 == 1);
948 onPostDialContinue(callId, proceed);
949 } finally {
950 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700951 Log.endSession();
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700952 }
953 break;
954 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700955 case MSG_PULL_EXTERNAL_CALL: {
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700956 SomeArgs args = (SomeArgs) msg.obj;
957 try {
958 Log.continueSession((Session) args.arg2,
959 SESSION_HANDLER + SESSION_PULL_EXTERNAL_CALL);
960 pullExternalCall((String) args.arg1);
961 } finally {
962 args.recycle();
963 Log.endSession();
964 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700965 break;
966 }
967 case MSG_SEND_CALL_EVENT: {
968 SomeArgs args = (SomeArgs) msg.obj;
969 try {
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700970 Log.continueSession((Session) args.arg4,
971 SESSION_HANDLER + SESSION_SEND_CALL_EVENT);
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700972 String callId = (String) args.arg1;
973 String event = (String) args.arg2;
974 Bundle extras = (Bundle) args.arg3;
975 sendCallEvent(callId, event, extras);
976 } finally {
977 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700978 Log.endSession();
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700979 }
980 break;
981 }
Tyler Gunndee56a82016-03-23 16:06:34 -0700982 case MSG_ON_EXTRAS_CHANGED: {
983 SomeArgs args = (SomeArgs) msg.obj;
984 try {
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700985 Log.continueSession((Session) args.arg3,
986 SESSION_HANDLER + SESSION_EXTRAS_CHANGED);
Tyler Gunndee56a82016-03-23 16:06:34 -0700987 String callId = (String) args.arg1;
988 Bundle extras = (Bundle) args.arg2;
989 handleExtrasChanged(callId, extras);
990 } finally {
991 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700992 Log.endSession();
Tyler Gunndee56a82016-03-23 16:06:34 -0700993 }
994 break;
995 }
Hall Liub64ac4c2017-02-06 10:49:48 -0800996 case MSG_ON_START_RTT: {
997 SomeArgs args = (SomeArgs) msg.obj;
998 try {
999 Log.continueSession((Session) args.arg3,
1000 SESSION_HANDLER + SESSION_START_RTT);
1001 String callId = (String) args.arg1;
1002 Connection.RttTextStream rttTextStream =
1003 (Connection.RttTextStream) args.arg2;
1004 startRtt(callId, rttTextStream);
1005 } finally {
1006 args.recycle();
1007 Log.endSession();
1008 }
1009 break;
1010 }
1011 case MSG_ON_STOP_RTT: {
1012 SomeArgs args = (SomeArgs) msg.obj;
1013 try {
1014 Log.continueSession((Session) args.arg2,
1015 SESSION_HANDLER + SESSION_STOP_RTT);
1016 String callId = (String) args.arg1;
1017 stopRtt(callId);
1018 } finally {
1019 args.recycle();
1020 Log.endSession();
1021 }
1022 break;
1023 }
1024 case MSG_RTT_UPGRADE_RESPONSE: {
1025 SomeArgs args = (SomeArgs) msg.obj;
1026 try {
1027 Log.continueSession((Session) args.arg3,
1028 SESSION_HANDLER + SESSION_RTT_UPGRADE_RESPONSE);
1029 String callId = (String) args.arg1;
1030 Connection.RttTextStream rttTextStream =
1031 (Connection.RttTextStream) args.arg2;
1032 handleRttUpgradeResponse(callId, rttTextStream);
1033 } finally {
1034 args.recycle();
1035 Log.endSession();
1036 }
1037 break;
1038 }
Pengquan Meng731c1a32017-11-21 18:01:13 -08001039 case MSG_CONNECTION_SERVICE_FOCUS_GAINED:
1040 onConnectionServiceFocusGained();
1041 break;
1042 case MSG_CONNECTION_SERVICE_FOCUS_LOST:
1043 onConnectionServiceFocusLost();
1044 break;
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001045 default:
1046 break;
1047 }
1048 }
1049 };
1050
Santos Cordon823fd3c2014-08-07 18:35:18 -07001051 private final Conference.Listener mConferenceListener = new Conference.Listener() {
1052 @Override
1053 public void onStateChanged(Conference conference, int oldState, int newState) {
1054 String id = mIdByConference.get(conference);
1055 switch (newState) {
1056 case Connection.STATE_ACTIVE:
1057 mAdapter.setActive(id);
1058 break;
1059 case Connection.STATE_HOLDING:
1060 mAdapter.setOnHold(id);
1061 break;
1062 case Connection.STATE_DISCONNECTED:
1063 // handled by onDisconnected
1064 break;
1065 }
1066 }
1067
1068 @Override
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001069 public void onDisconnected(Conference conference, DisconnectCause disconnectCause) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07001070 String id = mIdByConference.get(conference);
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001071 mAdapter.setDisconnected(id, disconnectCause);
Santos Cordon823fd3c2014-08-07 18:35:18 -07001072 }
1073
1074 @Override
1075 public void onConnectionAdded(Conference conference, Connection connection) {
1076 }
1077
1078 @Override
1079 public void onConnectionRemoved(Conference conference, Connection connection) {
1080 }
1081
1082 @Override
Ihab Awad50e35062014-09-30 09:17:03 -07001083 public void onConferenceableConnectionsChanged(
1084 Conference conference, List<Connection> conferenceableConnections) {
1085 mAdapter.setConferenceableConnections(
1086 mIdByConference.get(conference),
1087 createConnectionIdList(conferenceableConnections));
1088 }
1089
1090 @Override
Santos Cordon823fd3c2014-08-07 18:35:18 -07001091 public void onDestroyed(Conference conference) {
1092 removeConference(conference);
1093 }
1094
1095 @Override
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001096 public void onConnectionCapabilitiesChanged(
1097 Conference conference,
1098 int connectionCapabilities) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07001099 String id = mIdByConference.get(conference);
1100 Log.d(this, "call capabilities: conference: %s",
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001101 Connection.capabilitiesToString(connectionCapabilities));
1102 mAdapter.setConnectionCapabilities(id, connectionCapabilities);
Santos Cordon823fd3c2014-08-07 18:35:18 -07001103 }
Rekha Kumar07366812015-03-24 16:42:31 -07001104
1105 @Override
Tyler Gunn720c6642016-03-22 09:02:47 -07001106 public void onConnectionPropertiesChanged(
1107 Conference conference,
1108 int connectionProperties) {
1109 String id = mIdByConference.get(conference);
1110 Log.d(this, "call capabilities: conference: %s",
1111 Connection.propertiesToString(connectionProperties));
1112 mAdapter.setConnectionProperties(id, connectionProperties);
1113 }
1114
1115 @Override
Rekha Kumar07366812015-03-24 16:42:31 -07001116 public void onVideoStateChanged(Conference c, int videoState) {
1117 String id = mIdByConference.get(c);
1118 Log.d(this, "onVideoStateChanged set video state %d", videoState);
1119 mAdapter.setVideoState(id, videoState);
1120 }
1121
1122 @Override
1123 public void onVideoProviderChanged(Conference c, Connection.VideoProvider videoProvider) {
1124 String id = mIdByConference.get(c);
1125 Log.d(this, "onVideoProviderChanged: Connection: %s, VideoProvider: %s", c,
1126 videoProvider);
1127 mAdapter.setVideoProvider(id, videoProvider);
1128 }
Andrew Lee0f51da32015-04-16 13:11:55 -07001129
1130 @Override
Andrew Leeedc625f2015-04-14 13:38:12 -07001131 public void onStatusHintsChanged(Conference conference, StatusHints statusHints) {
1132 String id = mIdByConference.get(conference);
Tyler Gunndee56a82016-03-23 16:06:34 -07001133 if (id != null) {
1134 mAdapter.setStatusHints(id, statusHints);
1135 }
Andrew Leeedc625f2015-04-14 13:38:12 -07001136 }
Santos Cordon6b7f9552015-05-27 17:21:45 -07001137
1138 @Override
Tyler Gunndee56a82016-03-23 16:06:34 -07001139 public void onExtrasChanged(Conference c, Bundle extras) {
1140 String id = mIdByConference.get(c);
1141 if (id != null) {
1142 mAdapter.putExtras(id, extras);
1143 }
1144 }
1145
1146 @Override
1147 public void onExtrasRemoved(Conference c, List<String> keys) {
1148 String id = mIdByConference.get(c);
1149 if (id != null) {
1150 mAdapter.removeExtras(id, keys);
1151 }
Santos Cordon6b7f9552015-05-27 17:21:45 -07001152 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07001153 };
1154
Ihab Awad542e0ea2014-05-16 10:22:16 -07001155 private final Connection.Listener mConnectionListener = new Connection.Listener() {
1156 @Override
1157 public void onStateChanged(Connection c, int state) {
1158 String id = mIdByConnection.get(c);
Ihab Awad42b30e12014-05-22 09:49:34 -07001159 Log.d(this, "Adapter set state %s %s", id, Connection.stateToString(state));
Ihab Awad542e0ea2014-05-16 10:22:16 -07001160 switch (state) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001161 case Connection.STATE_ACTIVE:
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001162 mAdapter.setActive(id);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001163 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001164 case Connection.STATE_DIALING:
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001165 mAdapter.setDialing(id);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001166 break;
Tyler Gunnc96b5e02016-07-07 22:53:57 -07001167 case Connection.STATE_PULLING_CALL:
1168 mAdapter.setPulling(id);
1169 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001170 case Connection.STATE_DISCONNECTED:
Ihab Awad542e0ea2014-05-16 10:22:16 -07001171 // Handled in onDisconnected()
1172 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001173 case Connection.STATE_HOLDING:
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001174 mAdapter.setOnHold(id);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001175 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001176 case Connection.STATE_NEW:
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001177 // Nothing to tell Telecom
Ihab Awad542e0ea2014-05-16 10:22:16 -07001178 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001179 case Connection.STATE_RINGING:
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001180 mAdapter.setRinging(id);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001181 break;
1182 }
1183 }
1184
1185 @Override
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001186 public void onDisconnected(Connection c, DisconnectCause disconnectCause) {
Ihab Awad542e0ea2014-05-16 10:22:16 -07001187 String id = mIdByConnection.get(c);
Andrew Lee26786392014-09-16 18:14:59 -07001188 Log.d(this, "Adapter set disconnected %s", disconnectCause);
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001189 mAdapter.setDisconnected(id, disconnectCause);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001190 }
1191
1192 @Override
Tyler Gunnaa07df82014-07-17 07:50:22 -07001193 public void onVideoStateChanged(Connection c, int videoState) {
1194 String id = mIdByConnection.get(c);
1195 Log.d(this, "Adapter set video state %d", videoState);
1196 mAdapter.setVideoState(id, videoState);
1197 }
1198
1199 @Override
Andrew Lee100e2932014-09-08 15:34:24 -07001200 public void onAddressChanged(Connection c, Uri address, int presentation) {
Sailesh Nepal61203862014-07-11 14:50:13 -07001201 String id = mIdByConnection.get(c);
Andrew Lee100e2932014-09-08 15:34:24 -07001202 mAdapter.setAddress(id, address, presentation);
Sailesh Nepal61203862014-07-11 14:50:13 -07001203 }
1204
1205 @Override
1206 public void onCallerDisplayNameChanged(
1207 Connection c, String callerDisplayName, int presentation) {
1208 String id = mIdByConnection.get(c);
1209 mAdapter.setCallerDisplayName(id, callerDisplayName, presentation);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001210 }
1211
1212 @Override
Ihab Awad542e0ea2014-05-16 10:22:16 -07001213 public void onDestroyed(Connection c) {
1214 removeConnection(c);
1215 }
Ihab Awadf8358972014-05-28 16:46:42 -07001216
1217 @Override
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001218 public void onPostDialWait(Connection c, String remaining) {
Sailesh Nepal091768c2014-06-30 15:15:23 -07001219 String id = mIdByConnection.get(c);
1220 Log.d(this, "Adapter onPostDialWait %s, %s", c, remaining);
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001221 mAdapter.onPostDialWait(id, remaining);
Sailesh Nepal091768c2014-06-30 15:15:23 -07001222 }
1223
1224 @Override
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001225 public void onPostDialChar(Connection c, char nextChar) {
1226 String id = mIdByConnection.get(c);
1227 Log.d(this, "Adapter onPostDialChar %s, %s", c, nextChar);
1228 mAdapter.onPostDialChar(id, nextChar);
1229 }
1230
1231 @Override
Andrew Lee100e2932014-09-08 15:34:24 -07001232 public void onRingbackRequested(Connection c, boolean ringback) {
Ihab Awadf8358972014-05-28 16:46:42 -07001233 String id = mIdByConnection.get(c);
1234 Log.d(this, "Adapter onRingback %b", ringback);
Andrew Lee100e2932014-09-08 15:34:24 -07001235 mAdapter.setRingbackRequested(id, ringback);
Ihab Awadf8358972014-05-28 16:46:42 -07001236 }
Santos Cordonb6939982014-06-04 20:20:58 -07001237
1238 @Override
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001239 public void onConnectionCapabilitiesChanged(Connection c, int capabilities) {
Santos Cordonb6939982014-06-04 20:20:58 -07001240 String id = mIdByConnection.get(c);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001241 Log.d(this, "capabilities: parcelableconnection: %s",
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001242 Connection.capabilitiesToString(capabilities));
1243 mAdapter.setConnectionCapabilities(id, capabilities);
Santos Cordonb6939982014-06-04 20:20:58 -07001244 }
1245
Santos Cordonb6939982014-06-04 20:20:58 -07001246 @Override
Tyler Gunn720c6642016-03-22 09:02:47 -07001247 public void onConnectionPropertiesChanged(Connection c, int properties) {
1248 String id = mIdByConnection.get(c);
1249 Log.d(this, "properties: parcelableconnection: %s",
1250 Connection.propertiesToString(properties));
1251 mAdapter.setConnectionProperties(id, properties);
1252 }
1253
1254 @Override
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001255 public void onVideoProviderChanged(Connection c, Connection.VideoProvider videoProvider) {
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07001256 String id = mIdByConnection.get(c);
Rekha Kumar07366812015-03-24 16:42:31 -07001257 Log.d(this, "onVideoProviderChanged: Connection: %s, VideoProvider: %s", c,
1258 videoProvider);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001259 mAdapter.setVideoProvider(id, videoProvider);
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07001260 }
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001261
1262 @Override
Sailesh Nepal001bbbb2014-07-15 14:40:39 -07001263 public void onAudioModeIsVoipChanged(Connection c, boolean isVoip) {
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001264 String id = mIdByConnection.get(c);
Andrew Lee100e2932014-09-08 15:34:24 -07001265 mAdapter.setIsVoipAudioMode(id, isVoip);
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001266 }
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001267
1268 @Override
Sailesh Nepal001bbbb2014-07-15 14:40:39 -07001269 public void onStatusHintsChanged(Connection c, StatusHints statusHints) {
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001270 String id = mIdByConnection.get(c);
1271 mAdapter.setStatusHints(id, statusHints);
1272 }
Sailesh Nepal2ab88cc2014-07-18 14:49:18 -07001273
1274 @Override
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001275 public void onConferenceablesChanged(
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001276 Connection connection, List<Conferenceable> conferenceables) {
Ihab Awadb8e85c72014-08-23 20:34:57 -07001277 mAdapter.setConferenceableConnections(
1278 mIdByConnection.get(connection),
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001279 createIdList(conferenceables));
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001280 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07001281
1282 @Override
1283 public void onConferenceChanged(Connection connection, Conference conference) {
1284 String id = mIdByConnection.get(connection);
1285 if (id != null) {
1286 String conferenceId = null;
1287 if (conference != null) {
1288 conferenceId = mIdByConference.get(conference);
1289 }
1290 mAdapter.setIsConferenced(id, conferenceId);
1291 }
1292 }
Anthony Lee17455a32015-04-24 15:25:29 -07001293
1294 @Override
1295 public void onConferenceMergeFailed(Connection connection) {
1296 String id = mIdByConnection.get(connection);
1297 if (id != null) {
1298 mAdapter.onConferenceMergeFailed(id);
1299 }
1300 }
Santos Cordon6b7f9552015-05-27 17:21:45 -07001301
1302 @Override
Tyler Gunndee56a82016-03-23 16:06:34 -07001303 public void onExtrasChanged(Connection c, Bundle extras) {
1304 String id = mIdByConnection.get(c);
Santos Cordon6b7f9552015-05-27 17:21:45 -07001305 if (id != null) {
Tyler Gunndee56a82016-03-23 16:06:34 -07001306 mAdapter.putExtras(id, extras);
Santos Cordon6b7f9552015-05-27 17:21:45 -07001307 }
1308 }
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001309
Tyler Gunnf5035432017-01-09 09:43:12 -08001310 @Override
Tyler Gunndee56a82016-03-23 16:06:34 -07001311 public void onExtrasRemoved(Connection c, List<String> keys) {
1312 String id = mIdByConnection.get(c);
1313 if (id != null) {
1314 mAdapter.removeExtras(id, keys);
1315 }
1316 }
1317
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08001318 @Override
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001319 public void onConnectionEvent(Connection connection, String event, Bundle extras) {
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08001320 String id = mIdByConnection.get(connection);
1321 if (id != null) {
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001322 mAdapter.onConnectionEvent(id, event, extras);
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08001323 }
1324 }
Tyler Gunnf5035432017-01-09 09:43:12 -08001325
1326 @Override
Hall Liua98f58b52017-11-07 17:59:28 -08001327 public void onAudioRouteChanged(Connection c, int audioRoute, String bluetoothAddress) {
Tyler Gunnf5035432017-01-09 09:43:12 -08001328 String id = mIdByConnection.get(c);
1329 if (id != null) {
Hall Liua98f58b52017-11-07 17:59:28 -08001330 mAdapter.setAudioRoute(id, audioRoute, bluetoothAddress);
Tyler Gunnf5035432017-01-09 09:43:12 -08001331 }
1332 }
Hall Liub64ac4c2017-02-06 10:49:48 -08001333
1334 @Override
1335 public void onRttInitiationSuccess(Connection c) {
1336 String id = mIdByConnection.get(c);
1337 if (id != null) {
1338 mAdapter.onRttInitiationSuccess(id);
1339 }
1340 }
1341
1342 @Override
1343 public void onRttInitiationFailure(Connection c, int reason) {
1344 String id = mIdByConnection.get(c);
1345 if (id != null) {
1346 mAdapter.onRttInitiationFailure(id, reason);
1347 }
1348 }
1349
1350 @Override
1351 public void onRttSessionRemotelyTerminated(Connection c) {
1352 String id = mIdByConnection.get(c);
1353 if (id != null) {
1354 mAdapter.onRttSessionRemotelyTerminated(id);
1355 }
1356 }
1357
1358 @Override
1359 public void onRemoteRttRequest(Connection c) {
1360 String id = mIdByConnection.get(c);
1361 if (id != null) {
1362 mAdapter.onRemoteRttRequest(id);
1363 }
1364 }
Srikanth Chintalafcb15012017-05-04 20:58:34 +05301365
1366 @Override
1367 public void onPhoneAccountChanged(Connection c, PhoneAccountHandle pHandle) {
1368 String id = mIdByConnection.get(c);
1369 if (id != null) {
1370 mAdapter.onPhoneAccountChanged(id, pHandle);
1371 }
1372 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001373 };
1374
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001375 /** {@inheritDoc} */
Ihab Awad542e0ea2014-05-16 10:22:16 -07001376 @Override
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001377 public final IBinder onBind(Intent intent) {
1378 return mBinder;
1379 }
1380
Santos Cordon29f2f2e2014-09-11 19:50:24 -07001381 /** {@inheritDoc} */
1382 @Override
1383 public boolean onUnbind(Intent intent) {
1384 endAllConnections();
1385 return super.onUnbind(intent);
1386 }
1387
Sailesh Nepalc5b01572014-07-14 16:29:44 -07001388 /**
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001389 * This can be used by telecom to either create a new outgoing call or attach to an existing
1390 * incoming call. In either case, telecom will cycle through a set of services and call
Sailesh Nepalc5b01572014-07-14 16:29:44 -07001391 * createConnection util a connection service cancels the process or completes it successfully.
1392 */
Ihab Awadf8b69882014-07-25 15:14:01 -07001393 private void createConnection(
1394 final PhoneAccountHandle callManagerAccount,
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001395 final String callId,
Ihab Awadf8b69882014-07-25 15:14:01 -07001396 final ConnectionRequest request,
Yorke Leec3cf9822014-10-02 09:38:39 -07001397 boolean isIncoming,
1398 boolean isUnknown) {
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001399 Log.d(this, "createConnection, callManagerAccount: %s, callId: %s, request: %s, " +
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001400 "isIncoming: %b, isUnknown: %b", callManagerAccount, callId, request,
1401 isIncoming,
Yorke Leec3cf9822014-10-02 09:38:39 -07001402 isUnknown);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001403
Sanket Padawee29a2662017-12-01 13:59:27 -08001404 Connection connection = null;
1405 if (request.getExtras() != null && request.getExtras().getBoolean(
1406 TelecomManager.EXTRA_IS_HANDOVER,false)) {
1407 if (!isIncoming) {
1408 connection = onCreateOutgoingHandoverConnection(callManagerAccount, request);
1409 } else {
1410 // Todo: Call onCreateIncommingHandoverConnection()
1411 }
1412 } else {
1413 connection = isUnknown ? onCreateUnknownConnection(callManagerAccount, request)
1414 : isIncoming ? onCreateIncomingConnection(callManagerAccount, request)
1415 : onCreateOutgoingConnection(callManagerAccount, request);
1416 }
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001417 Log.d(this, "createConnection, connection: %s", connection);
1418 if (connection == null) {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001419 connection = Connection.createFailedConnection(
1420 new DisconnectCause(DisconnectCause.ERROR));
Sailesh Nepalc5b01572014-07-14 16:29:44 -07001421 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001422
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001423 connection.setTelecomCallId(callId);
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001424 if (connection.getState() != Connection.STATE_DISCONNECTED) {
Pengquan Meng70c9885332017-10-02 18:09:03 -07001425 addConnection(request.getAccountHandle(), callId, connection);
Ihab Awad6107bab2014-08-18 09:23:25 -07001426 }
1427
Andrew Lee100e2932014-09-08 15:34:24 -07001428 Uri address = connection.getAddress();
1429 String number = address == null ? "null" : address.getSchemeSpecificPart();
Tyler Gunn720c6642016-03-22 09:02:47 -07001430 Log.v(this, "createConnection, number: %s, state: %s, capabilities: %s, properties: %s",
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001431 Connection.toLogSafePhoneNumber(number),
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001432 Connection.stateToString(connection.getState()),
Tyler Gunn720c6642016-03-22 09:02:47 -07001433 Connection.capabilitiesToString(connection.getConnectionCapabilities()),
1434 Connection.propertiesToString(connection.getConnectionProperties()));
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001435
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001436 Log.d(this, "createConnection, calling handleCreateConnectionSuccessful %s", callId);
Ihab Awad6107bab2014-08-18 09:23:25 -07001437 mAdapter.handleCreateConnectionComplete(
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001438 callId,
Evan Charltonbf11f982014-07-20 22:06:28 -07001439 request,
1440 new ParcelableConnection(
1441 request.getAccountHandle(),
1442 connection.getState(),
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001443 connection.getConnectionCapabilities(),
Tyler Gunn720c6642016-03-22 09:02:47 -07001444 connection.getConnectionProperties(),
Christine Hallstrom2830ce92016-11-30 16:06:42 -08001445 connection.getSupportedAudioRoutes(),
Andrew Lee100e2932014-09-08 15:34:24 -07001446 connection.getAddress(),
1447 connection.getAddressPresentation(),
Evan Charltonbf11f982014-07-20 22:06:28 -07001448 connection.getCallerDisplayName(),
1449 connection.getCallerDisplayNamePresentation(),
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001450 connection.getVideoProvider() == null ?
1451 null : connection.getVideoProvider().getInterface(),
Sailesh Nepal8b9d3ca2014-08-14 17:39:34 -07001452 connection.getVideoState(),
Andrew Lee100e2932014-09-08 15:34:24 -07001453 connection.isRingbackRequested(),
Sailesh Nepal8b9d3ca2014-08-14 17:39:34 -07001454 connection.getAudioModeIsVoip(),
Roshan Piuse927ec02015-07-15 15:47:21 -07001455 connection.getConnectTimeMillis(),
Tyler Gunn3fa819c2017-08-04 09:27:26 -07001456 connection.getConnectElapsedTimeMillis(),
Ihab Awad6107bab2014-08-18 09:23:25 -07001457 connection.getStatusHints(),
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001458 connection.getDisconnectCause(),
Santos Cordon6b7f9552015-05-27 17:21:45 -07001459 createIdList(connection.getConferenceables()),
1460 connection.getExtras()));
Tyler Gunnf5035432017-01-09 09:43:12 -08001461
1462 if (isIncoming && request.shouldShowIncomingCallUi() &&
1463 (connection.getConnectionProperties() & Connection.PROPERTY_SELF_MANAGED) ==
1464 Connection.PROPERTY_SELF_MANAGED) {
1465 // Tell ConnectionService to show its incoming call UX.
1466 connection.onShowIncomingCallUi();
1467 }
Shriram Ganesh6bf35ac2014-12-11 17:53:38 -08001468 if (isUnknown) {
1469 triggerConferenceRecalculate();
1470 }
Evan Charltonbf11f982014-07-20 22:06:28 -07001471 }
1472
Tyler Gunn159f35c2017-03-02 09:28:37 -08001473 private void createConnectionFailed(final PhoneAccountHandle callManagerAccount,
1474 final String callId, final ConnectionRequest request,
1475 boolean isIncoming) {
Tyler Gunn44e01912017-01-31 10:49:05 -08001476
1477 Log.i(this, "createConnectionFailed %s", callId);
1478 if (isIncoming) {
Tyler Gunn159f35c2017-03-02 09:28:37 -08001479 onCreateIncomingConnectionFailed(callManagerAccount, request);
Tyler Gunn44e01912017-01-31 10:49:05 -08001480 } else {
Tyler Gunn159f35c2017-03-02 09:28:37 -08001481 onCreateOutgoingConnectionFailed(callManagerAccount, request);
Tyler Gunn44e01912017-01-31 10:49:05 -08001482 }
1483 }
1484
Tyler Gunn041a1fe2017-05-12 10:04:49 -07001485 /**
1486 * Called by Telecom when the creation of a new Connection has completed and it is now added
1487 * to Telecom.
1488 * @param callId The ID of the connection.
1489 */
1490 private void notifyCreateConnectionComplete(final String callId) {
1491 Log.i(this, "notifyCreateConnectionComplete %s", callId);
Tyler Gunn0a88f2e2017-06-16 20:20:34 -07001492 if (callId == null) {
1493 // This could happen if the connection fails quickly and is removed from the
1494 // ConnectionService before Telecom sends the create connection complete callback.
1495 Log.w(this, "notifyCreateConnectionComplete: callId is null.");
1496 return;
1497 }
Tyler Gunn041a1fe2017-05-12 10:04:49 -07001498 onCreateConnectionComplete(findConnectionForAction(callId,
1499 "notifyCreateConnectionComplete"));
1500 }
1501
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001502 private void abort(String callId) {
Ihab Awad60ac30b2014-05-20 22:32:12 -07001503 Log.d(this, "abort %s", callId);
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001504 findConnectionForAction(callId, "abort").onAbort();
Ihab Awad542e0ea2014-05-16 10:22:16 -07001505 }
1506
Tyler Gunnbe74de02014-08-29 14:51:48 -07001507 private void answerVideo(String callId, int videoState) {
1508 Log.d(this, "answerVideo %s", callId);
Andrew Lee8da4c3c2014-07-16 10:11:42 -07001509 findConnectionForAction(callId, "answer").onAnswer(videoState);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001510 }
1511
Tyler Gunnbe74de02014-08-29 14:51:48 -07001512 private void answer(String callId) {
1513 Log.d(this, "answer %s", callId);
1514 findConnectionForAction(callId, "answer").onAnswer();
1515 }
1516
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001517 private void reject(String callId) {
Ihab Awad60ac30b2014-05-20 22:32:12 -07001518 Log.d(this, "reject %s", callId);
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001519 findConnectionForAction(callId, "reject").onReject();
Ihab Awad542e0ea2014-05-16 10:22:16 -07001520 }
1521
Bryce Lee81901682015-08-28 16:38:02 -07001522 private void reject(String callId, String rejectWithMessage) {
1523 Log.d(this, "reject %s with message", callId);
1524 findConnectionForAction(callId, "reject").onReject(rejectWithMessage);
1525 }
1526
Bryce Leecac50772015-11-17 15:13:29 -08001527 private void silence(String callId) {
1528 Log.d(this, "silence %s", callId);
1529 findConnectionForAction(callId, "silence").onSilence();
1530 }
1531
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001532 private void disconnect(String callId) {
Ihab Awad60ac30b2014-05-20 22:32:12 -07001533 Log.d(this, "disconnect %s", callId);
Santos Cordon0159ac02014-08-21 14:28:11 -07001534 if (mConnectionById.containsKey(callId)) {
1535 findConnectionForAction(callId, "disconnect").onDisconnect();
1536 } else {
1537 findConferenceForAction(callId, "disconnect").onDisconnect();
1538 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001539 }
1540
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001541 private void hold(String callId) {
Ihab Awad60ac30b2014-05-20 22:32:12 -07001542 Log.d(this, "hold %s", callId);
Santos Cordon0159ac02014-08-21 14:28:11 -07001543 if (mConnectionById.containsKey(callId)) {
1544 findConnectionForAction(callId, "hold").onHold();
1545 } else {
1546 findConferenceForAction(callId, "hold").onHold();
1547 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001548 }
1549
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001550 private void unhold(String callId) {
Ihab Awad60ac30b2014-05-20 22:32:12 -07001551 Log.d(this, "unhold %s", callId);
Santos Cordon0159ac02014-08-21 14:28:11 -07001552 if (mConnectionById.containsKey(callId)) {
1553 findConnectionForAction(callId, "unhold").onUnhold();
1554 } else {
1555 findConferenceForAction(callId, "unhold").onUnhold();
1556 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001557 }
1558
Yorke Lee4af59352015-05-13 14:14:54 -07001559 private void onCallAudioStateChanged(String callId, CallAudioState callAudioState) {
1560 Log.d(this, "onAudioStateChanged %s %s", callId, callAudioState);
Yorke Leea0d3ca92014-09-15 19:18:13 -07001561 if (mConnectionById.containsKey(callId)) {
Yorke Lee4af59352015-05-13 14:14:54 -07001562 findConnectionForAction(callId, "onCallAudioStateChanged").setCallAudioState(
1563 callAudioState);
Yorke Leea0d3ca92014-09-15 19:18:13 -07001564 } else {
Yorke Lee4af59352015-05-13 14:14:54 -07001565 findConferenceForAction(callId, "onCallAudioStateChanged").setCallAudioState(
1566 callAudioState);
Yorke Leea0d3ca92014-09-15 19:18:13 -07001567 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001568 }
1569
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001570 private void playDtmfTone(String callId, char digit) {
1571 Log.d(this, "playDtmfTone %s %c", callId, digit);
Yorke Leea0d3ca92014-09-15 19:18:13 -07001572 if (mConnectionById.containsKey(callId)) {
1573 findConnectionForAction(callId, "playDtmfTone").onPlayDtmfTone(digit);
1574 } else {
1575 findConferenceForAction(callId, "playDtmfTone").onPlayDtmfTone(digit);
1576 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001577 }
1578
1579 private void stopDtmfTone(String callId) {
1580 Log.d(this, "stopDtmfTone %s", callId);
Yorke Leea0d3ca92014-09-15 19:18:13 -07001581 if (mConnectionById.containsKey(callId)) {
1582 findConnectionForAction(callId, "stopDtmfTone").onStopDtmfTone();
1583 } else {
1584 findConferenceForAction(callId, "stopDtmfTone").onStopDtmfTone();
1585 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001586 }
1587
Santos Cordon823fd3c2014-08-07 18:35:18 -07001588 private void conference(String callId1, String callId2) {
1589 Log.d(this, "conference %s, %s", callId1, callId2);
Santos Cordon980acb92014-05-31 10:31:19 -07001590
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001591 // Attempt to get second connection or conference.
Santos Cordon823fd3c2014-08-07 18:35:18 -07001592 Connection connection2 = findConnectionForAction(callId2, "conference");
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001593 Conference conference2 = getNullConference();
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001594 if (connection2 == getNullConnection()) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001595 conference2 = findConferenceForAction(callId2, "conference");
1596 if (conference2 == getNullConference()) {
1597 Log.w(this, "Connection2 or Conference2 missing in conference request %s.",
1598 callId2);
1599 return;
1600 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07001601 }
Santos Cordonb6939982014-06-04 20:20:58 -07001602
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001603 // Attempt to get first connection or conference and perform merge.
Ihab Awad50e35062014-09-30 09:17:03 -07001604 Connection connection1 = findConnectionForAction(callId1, "conference");
1605 if (connection1 == getNullConnection()) {
1606 Conference conference1 = findConferenceForAction(callId1, "addConnection");
1607 if (conference1 == getNullConference()) {
1608 Log.w(this,
1609 "Connection1 or Conference1 missing in conference request %s.",
1610 callId1);
1611 } else {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001612 // Call 1 is a conference.
1613 if (connection2 != getNullConnection()) {
1614 // Call 2 is a connection so merge via call 1 (conference).
1615 conference1.onMerge(connection2);
1616 } else {
1617 // Call 2 is ALSO a conference; this should never happen.
1618 Log.wtf(this, "There can only be one conference and an attempt was made to " +
1619 "merge two conferences.");
1620 return;
1621 }
Ihab Awad50e35062014-09-30 09:17:03 -07001622 }
1623 } else {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001624 // Call 1 is a connection.
1625 if (conference2 != getNullConference()) {
1626 // Call 2 is a conference, so merge via call 2.
1627 conference2.onMerge(connection1);
1628 } else {
1629 // Call 2 is a connection, so merge together.
1630 onConference(connection1, connection2);
1631 }
Ihab Awad50e35062014-09-30 09:17:03 -07001632 }
Santos Cordon980acb92014-05-31 10:31:19 -07001633 }
1634
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001635 private void splitFromConference(String callId) {
Santos Cordonb6939982014-06-04 20:20:58 -07001636 Log.d(this, "splitFromConference(%s)", callId);
Santos Cordon980acb92014-05-31 10:31:19 -07001637
1638 Connection connection = findConnectionForAction(callId, "splitFromConference");
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001639 if (connection == getNullConnection()) {
Santos Cordon980acb92014-05-31 10:31:19 -07001640 Log.w(this, "Connection missing in conference request %s.", callId);
1641 return;
1642 }
1643
Santos Cordon0159ac02014-08-21 14:28:11 -07001644 Conference conference = connection.getConference();
1645 if (conference != null) {
1646 conference.onSeparate(connection);
1647 }
Santos Cordon980acb92014-05-31 10:31:19 -07001648 }
1649
Santos Cordona4868042014-09-04 17:39:22 -07001650 private void mergeConference(String callId) {
1651 Log.d(this, "mergeConference(%s)", callId);
1652 Conference conference = findConferenceForAction(callId, "mergeConference");
1653 if (conference != null) {
1654 conference.onMerge();
1655 }
1656 }
1657
1658 private void swapConference(String callId) {
1659 Log.d(this, "swapConference(%s)", callId);
1660 Conference conference = findConferenceForAction(callId, "swapConference");
1661 if (conference != null) {
1662 conference.onSwap();
1663 }
1664 }
1665
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001666 /**
1667 * Notifies a {@link Connection} of a request to pull an external call.
1668 *
1669 * See {@link Call#pullExternalCall()}.
1670 *
1671 * @param callId The ID of the call to pull.
1672 */
1673 private void pullExternalCall(String callId) {
1674 Log.d(this, "pullExternalCall(%s)", callId);
1675 Connection connection = findConnectionForAction(callId, "pullExternalCall");
1676 if (connection != null) {
1677 connection.onPullExternalCall();
1678 }
1679 }
1680
1681 /**
1682 * Notifies a {@link Connection} of a call event.
1683 *
1684 * See {@link Call#sendCallEvent(String, Bundle)}.
1685 *
1686 * @param callId The ID of the call receiving the event.
1687 * @param event The event.
1688 * @param extras Extras associated with the event.
1689 */
1690 private void sendCallEvent(String callId, String event, Bundle extras) {
1691 Log.d(this, "sendCallEvent(%s, %s)", callId, event);
1692 Connection connection = findConnectionForAction(callId, "sendCallEvent");
1693 if (connection != null) {
1694 connection.onCallEvent(event, extras);
1695 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001696 }
1697
Tyler Gunndee56a82016-03-23 16:06:34 -07001698 /**
1699 * Notifies a {@link Connection} or {@link Conference} of a change to the extras from Telecom.
1700 * <p>
1701 * These extra changes can originate from Telecom itself, or from an {@link InCallService} via
1702 * the {@link android.telecom.Call#putExtra(String, boolean)},
1703 * {@link android.telecom.Call#putExtra(String, int)},
1704 * {@link android.telecom.Call#putExtra(String, String)},
1705 * {@link Call#removeExtras(List)}.
1706 *
1707 * @param callId The ID of the call receiving the event.
1708 * @param extras The new extras bundle.
1709 */
1710 private void handleExtrasChanged(String callId, Bundle extras) {
1711 Log.d(this, "handleExtrasChanged(%s, %s)", callId, extras);
1712 if (mConnectionById.containsKey(callId)) {
1713 findConnectionForAction(callId, "handleExtrasChanged").handleExtrasChanged(extras);
1714 } else if (mConferenceById.containsKey(callId)) {
1715 findConferenceForAction(callId, "handleExtrasChanged").handleExtrasChanged(extras);
1716 }
1717 }
1718
Hall Liub64ac4c2017-02-06 10:49:48 -08001719 private void startRtt(String callId, Connection.RttTextStream rttTextStream) {
1720 Log.d(this, "startRtt(%s)", callId);
1721 if (mConnectionById.containsKey(callId)) {
1722 findConnectionForAction(callId, "startRtt").onStartRtt(rttTextStream);
1723 } else if (mConferenceById.containsKey(callId)) {
1724 Log.w(this, "startRtt called on a conference.");
1725 }
1726 }
1727
1728 private void stopRtt(String callId) {
1729 Log.d(this, "stopRtt(%s)", callId);
1730 if (mConnectionById.containsKey(callId)) {
1731 findConnectionForAction(callId, "stopRtt").onStopRtt();
Hall Liuffa4a812017-03-02 16:11:00 -08001732 findConnectionForAction(callId, "stopRtt").unsetRttProperty();
Hall Liub64ac4c2017-02-06 10:49:48 -08001733 } else if (mConferenceById.containsKey(callId)) {
1734 Log.w(this, "stopRtt called on a conference.");
1735 }
1736 }
1737
1738 private void handleRttUpgradeResponse(String callId, Connection.RttTextStream rttTextStream) {
1739 Log.d(this, "handleRttUpgradeResponse(%s, %s)", callId, rttTextStream == null);
1740 if (mConnectionById.containsKey(callId)) {
1741 findConnectionForAction(callId, "handleRttUpgradeResponse")
1742 .handleRttUpgradeResponse(rttTextStream);
1743 } else if (mConferenceById.containsKey(callId)) {
1744 Log.w(this, "handleRttUpgradeResponse called on a conference.");
1745 }
1746 }
1747
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001748 private void onPostDialContinue(String callId, boolean proceed) {
Evan Charlton6dea4ac2014-06-03 14:07:13 -07001749 Log.d(this, "onPostDialContinue(%s)", callId);
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001750 findConnectionForAction(callId, "stopDtmfTone").onPostDialContinue(proceed);
Evan Charlton6dea4ac2014-06-03 14:07:13 -07001751 }
1752
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001753 private void onAdapterAttached() {
Ihab Awad9c3f1882014-06-30 21:17:13 -07001754 if (mAreAccountsInitialized) {
Santos Cordon52d8a152014-06-17 19:08:45 -07001755 // No need to query again if we already did it.
1756 return;
1757 }
1758
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001759 mAdapter.queryRemoteConnectionServices(new RemoteServiceCallback.Stub() {
Santos Cordon52d8a152014-06-17 19:08:45 -07001760 @Override
1761 public void onResult(
1762 final List<ComponentName> componentNames,
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001763 final List<IBinder> services) {
Brad Ebinger0c3541b2016-11-01 14:11:38 -07001764 mHandler.post(new android.telecom.Logging.Runnable("oAA.qRCS.oR", null /*lock*/) {
Ihab Awad6107bab2014-08-18 09:23:25 -07001765 @Override
Brad Ebinger0c3541b2016-11-01 14:11:38 -07001766 public void loggedRun() {
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001767 for (int i = 0; i < componentNames.size() && i < services.size(); i++) {
Santos Cordon52d8a152014-06-17 19:08:45 -07001768 mRemoteConnectionManager.addConnectionService(
1769 componentNames.get(i),
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001770 IConnectionService.Stub.asInterface(services.get(i)));
Santos Cordon52d8a152014-06-17 19:08:45 -07001771 }
Ihab Awad5d0410f2014-07-30 10:07:40 -07001772 onAccountsInitialized();
Sailesh Nepalc5b01572014-07-14 16:29:44 -07001773 Log.d(this, "remote connection services found: " + services);
Santos Cordon52d8a152014-06-17 19:08:45 -07001774 }
Brad Ebinger0c3541b2016-11-01 14:11:38 -07001775 }.prepare());
Santos Cordon52d8a152014-06-17 19:08:45 -07001776 }
1777
1778 @Override
1779 public void onError() {
Brad Ebinger0c3541b2016-11-01 14:11:38 -07001780 mHandler.post(new android.telecom.Logging.Runnable("oAA.qRCS.oE", null /*lock*/) {
Ihab Awad6107bab2014-08-18 09:23:25 -07001781 @Override
Brad Ebinger0c3541b2016-11-01 14:11:38 -07001782 public void loggedRun() {
Ihab Awad9c3f1882014-06-30 21:17:13 -07001783 mAreAccountsInitialized = true;
Santos Cordon52d8a152014-06-17 19:08:45 -07001784 }
Brad Ebinger0c3541b2016-11-01 14:11:38 -07001785 }.prepare());
Santos Cordon52d8a152014-06-17 19:08:45 -07001786 }
1787 });
1788 }
1789
Ihab Awadf8b69882014-07-25 15:14:01 -07001790 /**
1791 * Ask some other {@code ConnectionService} to create a {@code RemoteConnection} given an
Santos Cordona663f862014-10-29 13:49:58 -07001792 * incoming request. This is used by {@code ConnectionService}s that are registered with
1793 * {@link PhoneAccount#CAPABILITY_CONNECTION_MANAGER} and want to be able to manage
1794 * SIM-based incoming calls.
Ihab Awadf8b69882014-07-25 15:14:01 -07001795 *
1796 * @param connectionManagerPhoneAccount See description at
1797 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
1798 * @param request Details about the incoming call.
1799 * @return The {@code Connection} object to satisfy this call, or {@code null} to
1800 * not handle the call.
1801 */
1802 public final RemoteConnection createRemoteIncomingConnection(
1803 PhoneAccountHandle connectionManagerPhoneAccount,
1804 ConnectionRequest request) {
1805 return mRemoteConnectionManager.createRemoteConnection(
1806 connectionManagerPhoneAccount, request, true);
Santos Cordon52d8a152014-06-17 19:08:45 -07001807 }
1808
1809 /**
Ihab Awadf8b69882014-07-25 15:14:01 -07001810 * Ask some other {@code ConnectionService} to create a {@code RemoteConnection} given an
Santos Cordona663f862014-10-29 13:49:58 -07001811 * outgoing request. This is used by {@code ConnectionService}s that are registered with
1812 * {@link PhoneAccount#CAPABILITY_CONNECTION_MANAGER} and want to be able to use the
1813 * SIM-based {@code ConnectionService} to place its outgoing calls.
Ihab Awadf8b69882014-07-25 15:14:01 -07001814 *
1815 * @param connectionManagerPhoneAccount See description at
1816 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
Cuihtlauac ALVARADO0b3b2a52016-09-13 14:49:41 +02001817 * @param request Details about the outgoing call.
Ihab Awadf8b69882014-07-25 15:14:01 -07001818 * @return The {@code Connection} object to satisfy this call, or {@code null} to
1819 * not handle the call.
1820 */
1821 public final RemoteConnection createRemoteOutgoingConnection(
1822 PhoneAccountHandle connectionManagerPhoneAccount,
1823 ConnectionRequest request) {
1824 return mRemoteConnectionManager.createRemoteConnection(
1825 connectionManagerPhoneAccount, request, false);
1826 }
1827
1828 /**
Santos Cordona663f862014-10-29 13:49:58 -07001829 * Indicates to the relevant {@code RemoteConnectionService} that the specified
1830 * {@link RemoteConnection}s should be merged into a conference call.
1831 * <p>
1832 * If the conference request is successful, the method {@link #onRemoteConferenceAdded} will
1833 * be invoked.
1834 *
1835 * @param remoteConnection1 The first of the remote connections to conference.
1836 * @param remoteConnection2 The second of the remote connections to conference.
Ihab Awadb8e85c72014-08-23 20:34:57 -07001837 */
1838 public final void conferenceRemoteConnections(
Santos Cordona663f862014-10-29 13:49:58 -07001839 RemoteConnection remoteConnection1,
1840 RemoteConnection remoteConnection2) {
1841 mRemoteConnectionManager.conferenceRemoteConnections(remoteConnection1, remoteConnection2);
Ihab Awadb8e85c72014-08-23 20:34:57 -07001842 }
1843
1844 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07001845 * Adds a new conference call. When a conference call is created either as a result of an
1846 * explicit request via {@link #onConference} or otherwise, the connection service should supply
1847 * an instance of {@link Conference} by invoking this method. A conference call provided by this
1848 * method will persist until {@link Conference#destroy} is invoked on the conference instance.
1849 *
1850 * @param conference The new conference object.
1851 */
1852 public final void addConference(Conference conference) {
Rekha Kumar07366812015-03-24 16:42:31 -07001853 Log.d(this, "addConference: conference=%s", conference);
1854
Santos Cordon823fd3c2014-08-07 18:35:18 -07001855 String id = addConferenceInternal(conference);
1856 if (id != null) {
1857 List<String> connectionIds = new ArrayList<>(2);
1858 for (Connection connection : conference.getConnections()) {
1859 if (mIdByConnection.containsKey(connection)) {
1860 connectionIds.add(mIdByConnection.get(connection));
1861 }
1862 }
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001863 conference.setTelecomCallId(id);
Santos Cordon823fd3c2014-08-07 18:35:18 -07001864 ParcelableConference parcelableConference = new ParcelableConference(
Nancy Chenea38cca2014-09-05 16:38:49 -07001865 conference.getPhoneAccountHandle(),
Santos Cordon823fd3c2014-08-07 18:35:18 -07001866 conference.getState(),
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001867 conference.getConnectionCapabilities(),
Tyler Gunn720c6642016-03-22 09:02:47 -07001868 conference.getConnectionProperties(),
Tyler Gunncd5d33c2015-01-12 09:02:01 -08001869 connectionIds,
Rekha Kumar07366812015-03-24 16:42:31 -07001870 conference.getVideoProvider() == null ?
1871 null : conference.getVideoProvider().getInterface(),
1872 conference.getVideoState(),
Andrew Lee3e3e2f22015-04-16 13:48:43 -07001873 conference.getConnectTimeMillis(),
Tyler Gunn3fa819c2017-08-04 09:27:26 -07001874 conference.getConnectElapsedTime(),
Santos Cordon6b7f9552015-05-27 17:21:45 -07001875 conference.getStatusHints(),
1876 conference.getExtras());
Andrew Lee0f51da32015-04-16 13:11:55 -07001877
Santos Cordon823fd3c2014-08-07 18:35:18 -07001878 mAdapter.addConferenceCall(id, parcelableConference);
Rekha Kumar07366812015-03-24 16:42:31 -07001879 mAdapter.setVideoProvider(id, conference.getVideoProvider());
1880 mAdapter.setVideoState(id, conference.getVideoState());
Santos Cordon823fd3c2014-08-07 18:35:18 -07001881
1882 // Go through any child calls and set the parent.
1883 for (Connection connection : conference.getConnections()) {
1884 String connectionId = mIdByConnection.get(connection);
1885 if (connectionId != null) {
1886 mAdapter.setIsConferenced(connectionId, id);
1887 }
1888 }
Pengquan Meng70c9885332017-10-02 18:09:03 -07001889 onConferenceAdded(conference);
Santos Cordon823fd3c2014-08-07 18:35:18 -07001890 }
1891 }
1892
1893 /**
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07001894 * Adds a connection created by the {@link ConnectionService} and informs telecom of the new
1895 * connection.
1896 *
1897 * @param phoneAccountHandle The phone account handle for the connection.
1898 * @param connection The connection to add.
1899 */
1900 public final void addExistingConnection(PhoneAccountHandle phoneAccountHandle,
1901 Connection connection) {
Tyler Gunn78da7812017-05-09 14:34:57 -07001902 addExistingConnection(phoneAccountHandle, connection, null /* conference */);
1903 }
1904
1905 /**
Pengquan Meng731c1a32017-11-21 18:01:13 -08001906 * Call to inform Telecom that your {@link ConnectionService} has released call resources (e.g
1907 * microphone, camera).
1908 *
1909 * @see ConnectionService#onConnectionServiceFocusLost()
1910 */
1911 public final void connectionServiceFocusReleased() {
1912 mAdapter.onConnectionServiceFocusReleased();
1913 }
1914
1915 /**
Tyler Gunn78da7812017-05-09 14:34:57 -07001916 * Adds a connection created by the {@link ConnectionService} and informs telecom of the new
1917 * connection.
1918 *
1919 * @param phoneAccountHandle The phone account handle for the connection.
1920 * @param connection The connection to add.
1921 * @param conference The parent conference of the new connection.
1922 * @hide
1923 */
1924 public final void addExistingConnection(PhoneAccountHandle phoneAccountHandle,
1925 Connection connection, Conference conference) {
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07001926
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001927 String id = addExistingConnectionInternal(phoneAccountHandle, connection);
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07001928 if (id != null) {
1929 List<String> emptyList = new ArrayList<>(0);
Tyler Gunn78da7812017-05-09 14:34:57 -07001930 String conferenceId = null;
1931 if (conference != null) {
1932 conferenceId = mIdByConference.get(conference);
1933 }
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07001934
1935 ParcelableConnection parcelableConnection = new ParcelableConnection(
1936 phoneAccountHandle,
1937 connection.getState(),
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001938 connection.getConnectionCapabilities(),
Tyler Gunn720c6642016-03-22 09:02:47 -07001939 connection.getConnectionProperties(),
Christine Hallstrom2830ce92016-11-30 16:06:42 -08001940 connection.getSupportedAudioRoutes(),
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07001941 connection.getAddress(),
1942 connection.getAddressPresentation(),
1943 connection.getCallerDisplayName(),
1944 connection.getCallerDisplayNamePresentation(),
1945 connection.getVideoProvider() == null ?
1946 null : connection.getVideoProvider().getInterface(),
1947 connection.getVideoState(),
1948 connection.isRingbackRequested(),
1949 connection.getAudioModeIsVoip(),
Roshan Piuse927ec02015-07-15 15:47:21 -07001950 connection.getConnectTimeMillis(),
Tyler Gunn3fa819c2017-08-04 09:27:26 -07001951 connection.getConnectElapsedTimeMillis(),
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07001952 connection.getStatusHints(),
1953 connection.getDisconnectCause(),
Santos Cordon6b7f9552015-05-27 17:21:45 -07001954 emptyList,
Tyler Gunn78da7812017-05-09 14:34:57 -07001955 connection.getExtras(),
1956 conferenceId);
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07001957 mAdapter.addExistingConnection(id, parcelableConnection);
1958 }
1959 }
1960
1961 /**
Ihab Awadf8b69882014-07-25 15:14:01 -07001962 * Returns all the active {@code Connection}s for which this {@code ConnectionService}
1963 * has taken responsibility.
1964 *
1965 * @return A collection of {@code Connection}s created by this {@code ConnectionService}.
Santos Cordonb6939982014-06-04 20:20:58 -07001966 */
Sailesh Nepal091768c2014-06-30 15:15:23 -07001967 public final Collection<Connection> getAllConnections() {
Santos Cordonb6939982014-06-04 20:20:58 -07001968 return mConnectionById.values();
1969 }
1970
1971 /**
Santos Cordona6018b92016-02-16 14:23:12 -08001972 * Returns all the active {@code Conference}s for which this {@code ConnectionService}
1973 * has taken responsibility.
1974 *
1975 * @return A collection of {@code Conference}s created by this {@code ConnectionService}.
1976 */
1977 public final Collection<Conference> getAllConferences() {
1978 return mConferenceById.values();
1979 }
1980
1981 /**
Ihab Awadf8b69882014-07-25 15:14:01 -07001982 * Create a {@code Connection} given an incoming request. This is used to attach to existing
1983 * incoming calls.
Evan Charltonbf11f982014-07-20 22:06:28 -07001984 *
Ihab Awadf8b69882014-07-25 15:14:01 -07001985 * @param connectionManagerPhoneAccount See description at
1986 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
1987 * @param request Details about the incoming call.
1988 * @return The {@code Connection} object to satisfy this call, or {@code null} to
1989 * not handle the call.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001990 */
Ihab Awadf8b69882014-07-25 15:14:01 -07001991 public Connection onCreateIncomingConnection(
1992 PhoneAccountHandle connectionManagerPhoneAccount,
1993 ConnectionRequest request) {
1994 return null;
1995 }
Sailesh Nepalc5b01572014-07-14 16:29:44 -07001996
1997 /**
Tyler Gunn041a1fe2017-05-12 10:04:49 -07001998 * Called after the {@link Connection} returned by
1999 * {@link #onCreateIncomingConnection(PhoneAccountHandle, ConnectionRequest)}
2000 * or {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)} has been
2001 * added to the {@link ConnectionService} and sent to Telecom.
2002 *
2003 * @param connection the {@link Connection}.
2004 * @hide
2005 */
2006 public void onCreateConnectionComplete(Connection connection) {
2007 }
2008
2009 /**
Tyler Gunnf5035432017-01-09 09:43:12 -08002010 * Called by Telecom to inform the {@link ConnectionService} that its request to create a new
2011 * incoming {@link Connection} was denied.
2012 * <p>
2013 * Used when a self-managed {@link ConnectionService} attempts to create a new incoming
2014 * {@link Connection}, but Telecom has determined that the call cannot be allowed at this time.
2015 * The {@link ConnectionService} is responsible for silently rejecting the new incoming
2016 * {@link Connection}.
2017 * <p>
2018 * See {@link TelecomManager#isIncomingCallPermitted(PhoneAccountHandle)} for more information.
2019 *
Tyler Gunn159f35c2017-03-02 09:28:37 -08002020 * @param connectionManagerPhoneAccount See description at
2021 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
Tyler Gunnf5035432017-01-09 09:43:12 -08002022 * @param request The incoming connection request.
2023 */
Tyler Gunn159f35c2017-03-02 09:28:37 -08002024 public void onCreateIncomingConnectionFailed(PhoneAccountHandle connectionManagerPhoneAccount,
2025 ConnectionRequest request) {
Tyler Gunnf5035432017-01-09 09:43:12 -08002026 }
2027
2028 /**
2029 * Called by Telecom to inform the {@link ConnectionService} that its request to create a new
2030 * outgoing {@link Connection} was denied.
2031 * <p>
2032 * Used when a self-managed {@link ConnectionService} attempts to create a new outgoing
2033 * {@link Connection}, but Telecom has determined that the call cannot be placed at this time.
2034 * The {@link ConnectionService} is responisible for informing the user that the
2035 * {@link Connection} cannot be made at this time.
2036 * <p>
2037 * See {@link TelecomManager#isOutgoingCallPermitted(PhoneAccountHandle)} for more information.
2038 *
Tyler Gunn159f35c2017-03-02 09:28:37 -08002039 * @param connectionManagerPhoneAccount See description at
2040 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
Tyler Gunnf5035432017-01-09 09:43:12 -08002041 * @param request The outgoing connection request.
2042 */
Tyler Gunn159f35c2017-03-02 09:28:37 -08002043 public void onCreateOutgoingConnectionFailed(PhoneAccountHandle connectionManagerPhoneAccount,
2044 ConnectionRequest request) {
Tyler Gunnf5035432017-01-09 09:43:12 -08002045 }
2046
2047 /**
Shriram Ganesh6bf35ac2014-12-11 17:53:38 -08002048 * Trigger recalculate functinality for conference calls. This is used when a Telephony
2049 * Connection is part of a conference controller but is not yet added to Connection
2050 * Service and hence cannot be added to the conference call.
2051 *
2052 * @hide
2053 */
2054 public void triggerConferenceRecalculate() {
2055 }
2056
2057 /**
Ihab Awadf8b69882014-07-25 15:14:01 -07002058 * Create a {@code Connection} given an outgoing request. This is used to initiate new
2059 * outgoing calls.
Sailesh Nepalc5b01572014-07-14 16:29:44 -07002060 *
Ihab Awadf8b69882014-07-25 15:14:01 -07002061 * @param connectionManagerPhoneAccount The connection manager account to use for managing
2062 * this call.
2063 * <p>
2064 * If this parameter is not {@code null}, it means that this {@code ConnectionService}
2065 * has registered one or more {@code PhoneAccount}s having
2066 * {@link PhoneAccount#CAPABILITY_CONNECTION_MANAGER}. This parameter will contain
2067 * one of these {@code PhoneAccount}s, while the {@code request} will contain another
2068 * (usually but not always distinct) {@code PhoneAccount} to be used for actually
2069 * making the connection.
2070 * <p>
2071 * If this parameter is {@code null}, it means that this {@code ConnectionService} is
2072 * being asked to make a direct connection. The
2073 * {@link ConnectionRequest#getAccountHandle()} of parameter {@code request} will be
2074 * a {@code PhoneAccount} registered by this {@code ConnectionService} to use for
2075 * making the connection.
2076 * @param request Details about the outgoing call.
2077 * @return The {@code Connection} object to satisfy this call, or the result of an invocation
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002078 * of {@link Connection#createFailedConnection(DisconnectCause)} to not handle the call.
Sailesh Nepalc5b01572014-07-14 16:29:44 -07002079 */
Ihab Awadf8b69882014-07-25 15:14:01 -07002080 public Connection onCreateOutgoingConnection(
2081 PhoneAccountHandle connectionManagerPhoneAccount,
2082 ConnectionRequest request) {
2083 return null;
2084 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002085
2086 /**
Sanket Padawea8eddd42017-11-03 11:07:35 -07002087 * Called by Telecom on the initiating side of the handover to create an instance of a
2088 * handover connection.
2089 * @param fromPhoneAccountHandle {@link PhoneAccountHandle} associated with the
2090 * ConnectionService which needs to handover the call.
2091 * @param request Details about the call which needs to be handover.
2092 * @return Connection object corresponding to the handover call.
2093 */
2094 public Connection onCreateOutgoingHandoverConnection(PhoneAccountHandle fromPhoneAccountHandle,
2095 ConnectionRequest request) {
2096 return null;
2097 }
2098
2099 /**
2100 * Called by Telecom on the receiving side of the handover to request the
2101 * {@link ConnectionService} to create an instance of a handover connection.
2102 * @param fromPhoneAccountHandle {@link PhoneAccountHandle} associated with the
2103 * ConnectionService which needs to handover the call.
2104 * @param request Details about the call which needs to be handover.
2105 * @return {@link Connection} object corresponding to the handover call.
2106 */
2107 public Connection onCreateIncomingHandoverConnection(PhoneAccountHandle fromPhoneAccountHandle,
2108 ConnectionRequest request) {
2109 return null;
2110 }
2111
2112 /**
2113 * Called by Telecom in response to a {@code TelecomManager#acceptHandover()}
2114 * invocation which failed.
2115 * @param request Details about the call which needs to be handover.
2116 * @param error Reason for handover failure as defined in
2117 * {@link android.telecom.Call.Callback#HANDOVER_FAILURE_DEST_INVALID_PERM}
2118 */
2119 public void onHandoverFailed(ConnectionRequest request, int error) {
2120 return;
2121 }
2122
2123 /**
Yorke Leec3cf9822014-10-02 09:38:39 -07002124 * Create a {@code Connection} for a new unknown call. An unknown call is a call originating
2125 * from the ConnectionService that was neither a user-initiated outgoing call, nor an incoming
2126 * call created using
2127 * {@code TelecomManager#addNewIncomingCall(PhoneAccountHandle, android.os.Bundle)}.
2128 *
Yorke Lee770ed6e2014-10-06 18:58:52 -07002129 * @hide
Yorke Leec3cf9822014-10-02 09:38:39 -07002130 */
2131 public Connection onCreateUnknownConnection(PhoneAccountHandle connectionManagerPhoneAccount,
2132 ConnectionRequest request) {
Brad Ebingerb32d4f82016-10-24 16:40:49 -07002133 return null;
Yorke Leec3cf9822014-10-02 09:38:39 -07002134 }
2135
2136 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07002137 * Conference two specified connections. Invoked when the user has made a request to merge the
2138 * specified connections into a conference call. In response, the connection service should
2139 * create an instance of {@link Conference} and pass it into {@link #addConference}.
Santos Cordonb6939982014-06-04 20:20:58 -07002140 *
Santos Cordon823fd3c2014-08-07 18:35:18 -07002141 * @param connection1 A connection to merge into a conference call.
2142 * @param connection2 A connection to merge into a conference call.
Santos Cordonb6939982014-06-04 20:20:58 -07002143 */
Santos Cordon823fd3c2014-08-07 18:35:18 -07002144 public void onConference(Connection connection1, Connection connection2) {}
Santos Cordonb6939982014-06-04 20:20:58 -07002145
Santos Cordona663f862014-10-29 13:49:58 -07002146 /**
Pengquan Meng70c9885332017-10-02 18:09:03 -07002147 * Called when a connection is added.
2148 * @hide
2149 */
2150 public void onConnectionAdded(Connection connection) {}
2151
2152 /**
2153 * Called when a connection is removed.
2154 * @hide
2155 */
2156 public void onConnectionRemoved(Connection connection) {}
2157
2158 /**
2159 * Called when a conference is added.
2160 * @hide
2161 */
2162 public void onConferenceAdded(Conference conference) {}
2163
2164 /**
2165 * Called when a conference is removed.
2166 * @hide
2167 */
2168 public void onConferenceRemoved(Conference conference) {}
2169
2170 /**
Santos Cordona663f862014-10-29 13:49:58 -07002171 * Indicates that a remote conference has been created for existing {@link RemoteConnection}s.
2172 * When this method is invoked, this {@link ConnectionService} should create its own
2173 * representation of the conference call and send it to telecom using {@link #addConference}.
2174 * <p>
2175 * This is only relevant to {@link ConnectionService}s which are registered with
2176 * {@link PhoneAccount#CAPABILITY_CONNECTION_MANAGER}.
2177 *
2178 * @param conference The remote conference call.
2179 */
Ihab Awadb8e85c72014-08-23 20:34:57 -07002180 public void onRemoteConferenceAdded(RemoteConference conference) {}
2181
Santos Cordon823fd3c2014-08-07 18:35:18 -07002182 /**
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002183 * Called when an existing connection is added remotely.
2184 * @param connection The existing connection which was added.
2185 */
2186 public void onRemoteExistingConnectionAdded(RemoteConnection connection) {}
2187
2188 /**
Pengquan Meng731c1a32017-11-21 18:01:13 -08002189 * Called when the {@link ConnectionService} has lost the call focus.
2190 * The {@link ConnectionService} should release the call resources and invokes
2191 * {@link ConnectionService#connectionServiceFocusReleased()} to inform telecom that it has
2192 * released the call resources.
2193 */
2194 public void onConnectionServiceFocusLost() {}
2195
2196 /**
2197 * Called when the {@link ConnectionService} has gained the call focus. The
2198 * {@link ConnectionService} can acquire the call resources at this time.
2199 */
2200 public void onConnectionServiceFocusGained() {}
2201
2202 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07002203 * @hide
2204 */
2205 public boolean containsConference(Conference conference) {
2206 return mIdByConference.containsKey(conference);
2207 }
2208
Ihab Awadb8e85c72014-08-23 20:34:57 -07002209 /** {@hide} */
2210 void addRemoteConference(RemoteConference remoteConference) {
2211 onRemoteConferenceAdded(remoteConference);
2212 }
2213
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002214 /** {@hide} */
2215 void addRemoteExistingConnection(RemoteConnection remoteConnection) {
2216 onRemoteExistingConnectionAdded(remoteConnection);
2217 }
2218
Ihab Awad5d0410f2014-07-30 10:07:40 -07002219 private void onAccountsInitialized() {
2220 mAreAccountsInitialized = true;
2221 for (Runnable r : mPreInitializationConnectionRequests) {
2222 r.run();
2223 }
2224 mPreInitializationConnectionRequests.clear();
2225 }
2226
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002227 /**
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002228 * Adds an existing connection to the list of connections, identified by a new call ID unique
2229 * to this connection service.
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002230 *
2231 * @param connection The connection.
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002232 * @return The ID of the connection (e.g. the call-id).
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002233 */
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002234 private String addExistingConnectionInternal(PhoneAccountHandle handle, Connection connection) {
2235 String id;
Tyler Gunncd6ccfd2016-10-17 15:48:19 -07002236
2237 if (connection.getExtras() != null && connection.getExtras()
2238 .containsKey(Connection.EXTRA_ORIGINAL_CONNECTION_ID)) {
2239 id = connection.getExtras().getString(Connection.EXTRA_ORIGINAL_CONNECTION_ID);
2240 Log.d(this, "addExistingConnectionInternal - conn %s reusing original id %s",
2241 connection.getTelecomCallId(), id);
2242 } else if (handle == null) {
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002243 // If no phone account handle was provided, we cannot be sure the call ID is unique,
2244 // so just use a random UUID.
2245 id = UUID.randomUUID().toString();
2246 } else {
2247 // Phone account handle was provided, so use the ConnectionService class name as a
2248 // prefix for a unique incremental call ID.
2249 id = handle.getComponentName().getClassName() + "@" + getNextCallId();
2250 }
Pengquan Meng70c9885332017-10-02 18:09:03 -07002251 addConnection(handle, id, connection);
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002252 return id;
2253 }
2254
Pengquan Meng70c9885332017-10-02 18:09:03 -07002255 private void addConnection(PhoneAccountHandle handle, String callId, Connection connection) {
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002256 connection.setTelecomCallId(callId);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002257 mConnectionById.put(callId, connection);
2258 mIdByConnection.put(connection, callId);
2259 connection.addConnectionListener(mConnectionListener);
Santos Cordon823fd3c2014-08-07 18:35:18 -07002260 connection.setConnectionService(this);
Pengquan Meng70c9885332017-10-02 18:09:03 -07002261 connection.setPhoneAccountHandle(handle);
2262 onConnectionAdded(connection);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002263 }
2264
Anthony Lee30e65842014-11-06 16:30:53 -08002265 /** {@hide} */
2266 protected void removeConnection(Connection connection) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07002267 connection.unsetConnectionService(this);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002268 connection.removeConnectionListener(mConnectionListener);
Chenjie Luoe370b532016-05-12 16:59:43 -07002269 String id = mIdByConnection.get(connection);
2270 if (id != null) {
2271 mConnectionById.remove(id);
2272 mIdByConnection.remove(connection);
2273 mAdapter.removeCall(id);
Pengquan Meng70c9885332017-10-02 18:09:03 -07002274 onConnectionRemoved(connection);
Chenjie Luoe370b532016-05-12 16:59:43 -07002275 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002276 }
2277
Santos Cordon823fd3c2014-08-07 18:35:18 -07002278 private String addConferenceInternal(Conference conference) {
Tyler Gunncd6ccfd2016-10-17 15:48:19 -07002279 String originalId = null;
2280 if (conference.getExtras() != null && conference.getExtras()
2281 .containsKey(Connection.EXTRA_ORIGINAL_CONNECTION_ID)) {
2282 originalId = conference.getExtras().getString(Connection.EXTRA_ORIGINAL_CONNECTION_ID);
2283 Log.d(this, "addConferenceInternal: conf %s reusing original id %s",
2284 conference.getTelecomCallId(),
2285 originalId);
2286 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07002287 if (mIdByConference.containsKey(conference)) {
2288 Log.w(this, "Re-adding an existing conference: %s.", conference);
2289 } else if (conference != null) {
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002290 // Conferences do not (yet) have a PhoneAccountHandle associated with them, so we
2291 // cannot determine a ConnectionService class name to associate with the ID, so use
2292 // a unique UUID (for now).
Tyler Gunncd6ccfd2016-10-17 15:48:19 -07002293 String id = originalId == null ? UUID.randomUUID().toString() : originalId;
Santos Cordon823fd3c2014-08-07 18:35:18 -07002294 mConferenceById.put(id, conference);
2295 mIdByConference.put(conference, id);
2296 conference.addListener(mConferenceListener);
2297 return id;
2298 }
2299
2300 return null;
2301 }
2302
2303 private void removeConference(Conference conference) {
2304 if (mIdByConference.containsKey(conference)) {
2305 conference.removeListener(mConferenceListener);
2306
2307 String id = mIdByConference.get(conference);
2308 mConferenceById.remove(id);
2309 mIdByConference.remove(conference);
2310 mAdapter.removeCall(id);
Pengquan Meng70c9885332017-10-02 18:09:03 -07002311
2312 onConferenceRemoved(conference);
Santos Cordon823fd3c2014-08-07 18:35:18 -07002313 }
2314 }
2315
Ihab Awad542e0ea2014-05-16 10:22:16 -07002316 private Connection findConnectionForAction(String callId, String action) {
Tyler Gunn0a88f2e2017-06-16 20:20:34 -07002317 if (callId != null && mConnectionById.containsKey(callId)) {
Ihab Awad542e0ea2014-05-16 10:22:16 -07002318 return mConnectionById.get(callId);
2319 }
Ihab Awad60ac30b2014-05-20 22:32:12 -07002320 Log.w(this, "%s - Cannot find Connection %s", action, callId);
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07002321 return getNullConnection();
2322 }
2323
2324 static synchronized Connection getNullConnection() {
2325 if (sNullConnection == null) {
2326 sNullConnection = new Connection() {};
2327 }
2328 return sNullConnection;
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002329 }
Santos Cordon0159ac02014-08-21 14:28:11 -07002330
2331 private Conference findConferenceForAction(String conferenceId, String action) {
2332 if (mConferenceById.containsKey(conferenceId)) {
2333 return mConferenceById.get(conferenceId);
2334 }
2335 Log.w(this, "%s - Cannot find conference %s", action, conferenceId);
2336 return getNullConference();
2337 }
2338
Ihab Awadb8e85c72014-08-23 20:34:57 -07002339 private List<String> createConnectionIdList(List<Connection> connections) {
2340 List<String> ids = new ArrayList<>();
2341 for (Connection c : connections) {
2342 if (mIdByConnection.containsKey(c)) {
2343 ids.add(mIdByConnection.get(c));
2344 }
2345 }
2346 Collections.sort(ids);
2347 return ids;
2348 }
2349
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002350 /**
2351 * Builds a list of {@link Connection} and {@link Conference} IDs based on the list of
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002352 * {@link Conferenceable}s passed in.
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002353 *
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002354 * @param conferenceables The {@link Conferenceable} connections and conferences.
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002355 * @return List of string conference and call Ids.
2356 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002357 private List<String> createIdList(List<Conferenceable> conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002358 List<String> ids = new ArrayList<>();
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002359 for (Conferenceable c : conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002360 // Only allow Connection and Conference conferenceables.
2361 if (c instanceof Connection) {
2362 Connection connection = (Connection) c;
2363 if (mIdByConnection.containsKey(connection)) {
2364 ids.add(mIdByConnection.get(connection));
2365 }
2366 } else if (c instanceof Conference) {
2367 Conference conference = (Conference) c;
2368 if (mIdByConference.containsKey(conference)) {
2369 ids.add(mIdByConference.get(conference));
2370 }
2371 }
2372 }
2373 Collections.sort(ids);
2374 return ids;
2375 }
2376
Santos Cordon0159ac02014-08-21 14:28:11 -07002377 private Conference getNullConference() {
2378 if (sNullConference == null) {
2379 sNullConference = new Conference(null) {};
2380 }
2381 return sNullConference;
2382 }
Santos Cordon29f2f2e2014-09-11 19:50:24 -07002383
2384 private void endAllConnections() {
2385 // Unbound from telecomm. We should end all connections and conferences.
2386 for (Connection connection : mIdByConnection.keySet()) {
2387 // only operate on top-level calls. Conference calls will be removed on their own.
2388 if (connection.getConference() == null) {
2389 connection.onDisconnect();
2390 }
2391 }
2392 for (Conference conference : mIdByConference.keySet()) {
2393 conference.onDisconnect();
2394 }
2395 }
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002396
2397 /**
2398 * Retrieves the next call ID as maintainted by the connection service.
2399 *
2400 * @return The call ID.
2401 */
2402 private int getNextCallId() {
Brad Ebingerb32d4f82016-10-24 16:40:49 -07002403 synchronized (mIdSyncRoot) {
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002404 return ++mId;
2405 }
2406 }
Santos Cordon980acb92014-05-31 10:31:19 -07002407}