blob: ec2794e3aa8a7d1487920ea298fa5d0e1000d915 [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";
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700146
Ihab Awad8aecfed2014-08-08 17:06:11 -0700147 private static final int MSG_ADD_CONNECTION_SERVICE_ADAPTER = 1;
Sailesh Nepalc5b01572014-07-14 16:29:44 -0700148 private static final int MSG_CREATE_CONNECTION = 2;
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700149 private static final int MSG_ABORT = 3;
Sailesh Nepalc5b01572014-07-14 16:29:44 -0700150 private static final int MSG_ANSWER = 4;
151 private static final int MSG_REJECT = 5;
152 private static final int MSG_DISCONNECT = 6;
153 private static final int MSG_HOLD = 7;
154 private static final int MSG_UNHOLD = 8;
Yorke Lee4af59352015-05-13 14:14:54 -0700155 private static final int MSG_ON_CALL_AUDIO_STATE_CHANGED = 9;
Sailesh Nepalc5b01572014-07-14 16:29:44 -0700156 private static final int MSG_PLAY_DTMF_TONE = 10;
157 private static final int MSG_STOP_DTMF_TONE = 11;
158 private static final int MSG_CONFERENCE = 12;
159 private static final int MSG_SPLIT_FROM_CONFERENCE = 13;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700160 private static final int MSG_ON_POST_DIAL_CONTINUE = 14;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700161 private static final int MSG_REMOVE_CONNECTION_SERVICE_ADAPTER = 16;
Tyler Gunnbe74de02014-08-29 14:51:48 -0700162 private static final int MSG_ANSWER_VIDEO = 17;
Santos Cordona4868042014-09-04 17:39:22 -0700163 private static final int MSG_MERGE_CONFERENCE = 18;
164 private static final int MSG_SWAP_CONFERENCE = 19;
Bryce Lee81901682015-08-28 16:38:02 -0700165 private static final int MSG_REJECT_WITH_MESSAGE = 20;
Bryce Leecac50772015-11-17 15:13:29 -0800166 private static final int MSG_SILENCE = 21;
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700167 private static final int MSG_PULL_EXTERNAL_CALL = 22;
168 private static final int MSG_SEND_CALL_EVENT = 23;
Tyler Gunndee56a82016-03-23 16:06:34 -0700169 private static final int MSG_ON_EXTRAS_CHANGED = 24;
Tyler Gunn44e01912017-01-31 10:49:05 -0800170 private static final int MSG_CREATE_CONNECTION_FAILED = 25;
Hall Liub64ac4c2017-02-06 10:49:48 -0800171 private static final int MSG_ON_START_RTT = 26;
172 private static final int MSG_ON_STOP_RTT = 27;
173 private static final int MSG_RTT_UPGRADE_RESPONSE = 28;
Tyler Gunn041a1fe2017-05-12 10:04:49 -0700174 private static final int MSG_CREATE_CONNECTION_COMPLETE = 29;
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700175
Sailesh Nepalcf7020b2014-08-20 10:07:19 -0700176 private static Connection sNullConnection;
177
mike dooley95e80702014-09-18 14:07:52 -0700178 private final Map<String, Connection> mConnectionById = new ConcurrentHashMap<>();
179 private final Map<Connection, String> mIdByConnection = new ConcurrentHashMap<>();
180 private final Map<String, Conference> mConferenceById = new ConcurrentHashMap<>();
181 private final Map<Conference, String> mIdByConference = new ConcurrentHashMap<>();
Ihab Awadb8e85c72014-08-23 20:34:57 -0700182 private final RemoteConnectionManager mRemoteConnectionManager =
183 new RemoteConnectionManager(this);
Ihab Awad5d0410f2014-07-30 10:07:40 -0700184 private final List<Runnable> mPreInitializationConnectionRequests = new ArrayList<>();
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700185 private final ConnectionServiceAdapter mAdapter = new ConnectionServiceAdapter();
Ihab Awad542e0ea2014-05-16 10:22:16 -0700186
Santos Cordon823fd3c2014-08-07 18:35:18 -0700187 private boolean mAreAccountsInitialized = false;
Santos Cordon0159ac02014-08-21 14:28:11 -0700188 private Conference sNullConference;
Tyler Gunnf0500bd2015-09-01 10:59:48 -0700189 private Object mIdSyncRoot = new Object();
190 private int mId = 0;
Santos Cordon823fd3c2014-08-07 18:35:18 -0700191
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700192 private final IBinder mBinder = new IConnectionService.Stub() {
193 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700194 public void addConnectionServiceAdapter(IConnectionServiceAdapter adapter,
195 Session.Info sessionInfo) {
196 Log.startSession(sessionInfo, SESSION_ADD_CS_ADAPTER);
197 try {
198 SomeArgs args = SomeArgs.obtain();
199 args.arg1 = adapter;
200 args.arg2 = Log.createSubsession();
201 mHandler.obtainMessage(MSG_ADD_CONNECTION_SERVICE_ADAPTER, args).sendToTarget();
202 } finally {
203 Log.endSession();
204 }
Ihab Awad8aecfed2014-08-08 17:06:11 -0700205 }
206
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700207 public void removeConnectionServiceAdapter(IConnectionServiceAdapter adapter,
208 Session.Info sessionInfo) {
209 Log.startSession(sessionInfo, SESSION_REMOVE_CS_ADAPTER);
210 try {
211 SomeArgs args = SomeArgs.obtain();
212 args.arg1 = adapter;
213 args.arg2 = Log.createSubsession();
214 mHandler.obtainMessage(MSG_REMOVE_CONNECTION_SERVICE_ADAPTER, args).sendToTarget();
215 } finally {
216 Log.endSession();
217 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700218 }
219
220 @Override
Ihab Awadf8b69882014-07-25 15:14:01 -0700221 public void createConnection(
222 PhoneAccountHandle connectionManagerPhoneAccount,
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700223 String id,
Ihab Awadf8b69882014-07-25 15:14:01 -0700224 ConnectionRequest request,
Yorke Leec3cf9822014-10-02 09:38:39 -0700225 boolean isIncoming,
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700226 boolean isUnknown,
227 Session.Info sessionInfo) {
228 Log.startSession(sessionInfo, SESSION_CREATE_CONN);
229 try {
230 SomeArgs args = SomeArgs.obtain();
231 args.arg1 = connectionManagerPhoneAccount;
232 args.arg2 = id;
233 args.arg3 = request;
234 args.arg4 = Log.createSubsession();
235 args.argi1 = isIncoming ? 1 : 0;
236 args.argi2 = isUnknown ? 1 : 0;
237 mHandler.obtainMessage(MSG_CREATE_CONNECTION, args).sendToTarget();
238 } finally {
239 Log.endSession();
240 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700241 }
242
243 @Override
Tyler Gunn041a1fe2017-05-12 10:04:49 -0700244 public void createConnectionComplete(String id, Session.Info sessionInfo) {
245 Log.startSession(sessionInfo, SESSION_CREATE_CONN_COMPLETE);
246 try {
247 SomeArgs args = SomeArgs.obtain();
248 args.arg1 = id;
249 args.arg2 = Log.createSubsession();
250 mHandler.obtainMessage(MSG_CREATE_CONNECTION_COMPLETE, args).sendToTarget();
251 } finally {
252 Log.endSession();
253 }
254 }
255
256 @Override
Tyler Gunn44e01912017-01-31 10:49:05 -0800257 public void createConnectionFailed(
Tyler Gunn159f35c2017-03-02 09:28:37 -0800258 PhoneAccountHandle connectionManagerPhoneAccount,
Tyler Gunn44e01912017-01-31 10:49:05 -0800259 String callId,
260 ConnectionRequest request,
261 boolean isIncoming,
262 Session.Info sessionInfo) {
263 Log.startSession(sessionInfo, SESSION_CREATE_CONN_FAILED);
264 try {
265 SomeArgs args = SomeArgs.obtain();
266 args.arg1 = callId;
267 args.arg2 = request;
268 args.arg3 = Log.createSubsession();
Tyler Gunn159f35c2017-03-02 09:28:37 -0800269 args.arg4 = connectionManagerPhoneAccount;
Tyler Gunn44e01912017-01-31 10:49:05 -0800270 args.argi1 = isIncoming ? 1 : 0;
271 mHandler.obtainMessage(MSG_CREATE_CONNECTION_FAILED, args).sendToTarget();
272 } finally {
273 Log.endSession();
274 }
275 }
276
277 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700278 public void abort(String callId, Session.Info sessionInfo) {
279 Log.startSession(sessionInfo, SESSION_ABORT);
280 try {
281 SomeArgs args = SomeArgs.obtain();
282 args.arg1 = callId;
283 args.arg2 = Log.createSubsession();
284 mHandler.obtainMessage(MSG_ABORT, args).sendToTarget();
285 } finally {
286 Log.endSession();
287 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700288 }
289
290 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700291 public void answerVideo(String callId, int videoState, Session.Info sessionInfo) {
292 Log.startSession(sessionInfo, SESSION_ANSWER_VIDEO);
293 try {
294 SomeArgs args = SomeArgs.obtain();
295 args.arg1 = callId;
296 args.arg2 = Log.createSubsession();
297 args.argi1 = videoState;
298 mHandler.obtainMessage(MSG_ANSWER_VIDEO, args).sendToTarget();
299 } finally {
300 Log.endSession();
301 }
Tyler Gunnbe74de02014-08-29 14:51:48 -0700302 }
303
304 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700305 public void answer(String callId, Session.Info sessionInfo) {
306 Log.startSession(sessionInfo, SESSION_ANSWER);
307 try {
308 SomeArgs args = SomeArgs.obtain();
309 args.arg1 = callId;
310 args.arg2 = Log.createSubsession();
311 mHandler.obtainMessage(MSG_ANSWER, args).sendToTarget();
312 } finally {
313 Log.endSession();
314 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700315 }
316
317 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700318 public void reject(String callId, Session.Info sessionInfo) {
319 Log.startSession(sessionInfo, SESSION_REJECT);
320 try {
321 SomeArgs args = SomeArgs.obtain();
322 args.arg1 = callId;
323 args.arg2 = Log.createSubsession();
324 mHandler.obtainMessage(MSG_REJECT, args).sendToTarget();
325 } finally {
326 Log.endSession();
327 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700328 }
329
330 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700331 public void rejectWithMessage(String callId, String message, Session.Info sessionInfo) {
332 Log.startSession(sessionInfo, SESSION_REJECT_MESSAGE);
333 try {
334 SomeArgs args = SomeArgs.obtain();
335 args.arg1 = callId;
336 args.arg2 = message;
337 args.arg3 = Log.createSubsession();
338 mHandler.obtainMessage(MSG_REJECT_WITH_MESSAGE, args).sendToTarget();
339 } finally {
340 Log.endSession();
341 }
Bryce Lee81901682015-08-28 16:38:02 -0700342 }
343
344 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700345 public void silence(String callId, Session.Info sessionInfo) {
346 Log.startSession(sessionInfo, SESSION_SILENCE);
347 try {
348 SomeArgs args = SomeArgs.obtain();
349 args.arg1 = callId;
350 args.arg2 = Log.createSubsession();
351 mHandler.obtainMessage(MSG_SILENCE, args).sendToTarget();
352 } finally {
353 Log.endSession();
354 }
Bryce Leecac50772015-11-17 15:13:29 -0800355 }
356
357 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700358 public void disconnect(String callId, Session.Info sessionInfo) {
359 Log.startSession(sessionInfo, SESSION_DISCONNECT);
360 try {
361 SomeArgs args = SomeArgs.obtain();
362 args.arg1 = callId;
363 args.arg2 = Log.createSubsession();
364 mHandler.obtainMessage(MSG_DISCONNECT, args).sendToTarget();
365 } finally {
366 Log.endSession();
367 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700368 }
369
370 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700371 public void hold(String callId, Session.Info sessionInfo) {
372 Log.startSession(sessionInfo, SESSION_HOLD);
373 try {
374 SomeArgs args = SomeArgs.obtain();
375 args.arg1 = callId;
376 args.arg2 = Log.createSubsession();
377 mHandler.obtainMessage(MSG_HOLD, args).sendToTarget();
378 } finally {
379 Log.endSession();
380 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700381 }
382
383 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700384 public void unhold(String callId, Session.Info sessionInfo) {
385 Log.startSession(sessionInfo, SESSION_UNHOLD);
386 try {
387 SomeArgs args = SomeArgs.obtain();
388 args.arg1 = callId;
389 args.arg2 = Log.createSubsession();
390 mHandler.obtainMessage(MSG_UNHOLD, args).sendToTarget();
391 } finally {
392 Log.endSession();
393 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700394 }
395
396 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700397 public void onCallAudioStateChanged(String callId, CallAudioState callAudioState,
398 Session.Info sessionInfo) {
399 Log.startSession(sessionInfo, SESSION_CALL_AUDIO_SC);
400 try {
401 SomeArgs args = SomeArgs.obtain();
402 args.arg1 = callId;
403 args.arg2 = callAudioState;
404 args.arg3 = Log.createSubsession();
405 mHandler.obtainMessage(MSG_ON_CALL_AUDIO_STATE_CHANGED, args).sendToTarget();
406 } finally {
407 Log.endSession();
408 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700409 }
410
411 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700412 public void playDtmfTone(String callId, char digit, Session.Info sessionInfo) {
413 Log.startSession(sessionInfo, SESSION_PLAY_DTMF);
414 try {
415 SomeArgs args = SomeArgs.obtain();
416 args.arg1 = digit;
417 args.arg2 = callId;
418 args.arg3 = Log.createSubsession();
419 mHandler.obtainMessage(MSG_PLAY_DTMF_TONE, args).sendToTarget();
420 } finally {
421 Log.endSession();
422 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700423 }
424
425 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700426 public void stopDtmfTone(String callId, Session.Info sessionInfo) {
427 Log.startSession(sessionInfo, SESSION_STOP_DTMF);
428 try {
429 SomeArgs args = SomeArgs.obtain();
430 args.arg1 = callId;
431 args.arg2 = Log.createSubsession();
432 mHandler.obtainMessage(MSG_STOP_DTMF_TONE, args).sendToTarget();
433 } finally {
434 Log.endSession();
435 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700436 }
437
438 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700439 public void conference(String callId1, String callId2, Session.Info sessionInfo) {
440 Log.startSession(sessionInfo, SESSION_CONFERENCE);
441 try {
442 SomeArgs args = SomeArgs.obtain();
443 args.arg1 = callId1;
444 args.arg2 = callId2;
445 args.arg3 = Log.createSubsession();
446 mHandler.obtainMessage(MSG_CONFERENCE, args).sendToTarget();
447 } finally {
448 Log.endSession();
449 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700450 }
451
452 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700453 public void splitFromConference(String callId, Session.Info sessionInfo) {
454 Log.startSession(sessionInfo, SESSION_SPLIT_CONFERENCE);
455 try {
456 SomeArgs args = SomeArgs.obtain();
457 args.arg1 = callId;
458 args.arg2 = Log.createSubsession();
459 mHandler.obtainMessage(MSG_SPLIT_FROM_CONFERENCE, args).sendToTarget();
460 } finally {
461 Log.endSession();
462 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700463 }
464
465 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700466 public void mergeConference(String callId, Session.Info sessionInfo) {
467 Log.startSession(sessionInfo, SESSION_MERGE_CONFERENCE);
468 try {
469 SomeArgs args = SomeArgs.obtain();
470 args.arg1 = callId;
471 args.arg2 = Log.createSubsession();
472 mHandler.obtainMessage(MSG_MERGE_CONFERENCE, args).sendToTarget();
473 } finally {
474 Log.endSession();
475 }
Santos Cordona4868042014-09-04 17:39:22 -0700476 }
477
478 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700479 public void swapConference(String callId, Session.Info sessionInfo) {
480 Log.startSession(sessionInfo, SESSION_SWAP_CONFERENCE);
481 try {
482 SomeArgs args = SomeArgs.obtain();
483 args.arg1 = callId;
484 args.arg2 = Log.createSubsession();
485 mHandler.obtainMessage(MSG_SWAP_CONFERENCE, args).sendToTarget();
486 } finally {
487 Log.endSession();
488 }
Santos Cordona4868042014-09-04 17:39:22 -0700489 }
490
491 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700492 public void onPostDialContinue(String callId, boolean proceed, Session.Info sessionInfo) {
493 Log.startSession(sessionInfo, SESSION_POST_DIAL_CONT);
494 try {
495 SomeArgs args = SomeArgs.obtain();
496 args.arg1 = callId;
497 args.arg2 = Log.createSubsession();
498 args.argi1 = proceed ? 1 : 0;
499 mHandler.obtainMessage(MSG_ON_POST_DIAL_CONTINUE, args).sendToTarget();
500 } finally {
501 Log.endSession();
502 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700503 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700504
505 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700506 public void pullExternalCall(String callId, Session.Info sessionInfo) {
507 Log.startSession(sessionInfo, SESSION_PULL_EXTERNAL_CALL);
508 try {
509 SomeArgs args = SomeArgs.obtain();
510 args.arg1 = callId;
511 args.arg2 = Log.createSubsession();
512 mHandler.obtainMessage(MSG_PULL_EXTERNAL_CALL, args).sendToTarget();
513 } finally {
514 Log.endSession();
515 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700516 }
517
518 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700519 public void sendCallEvent(String callId, String event, Bundle extras,
520 Session.Info sessionInfo) {
521 Log.startSession(sessionInfo, SESSION_SEND_CALL_EVENT);
522 try {
523 SomeArgs args = SomeArgs.obtain();
524 args.arg1 = callId;
525 args.arg2 = event;
526 args.arg3 = extras;
527 args.arg4 = Log.createSubsession();
528 mHandler.obtainMessage(MSG_SEND_CALL_EVENT, args).sendToTarget();
529 } finally {
530 Log.endSession();
531 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700532 }
Tyler Gunndee56a82016-03-23 16:06:34 -0700533
534 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700535 public void onExtrasChanged(String callId, Bundle extras, Session.Info sessionInfo) {
536 Log.startSession(sessionInfo, SESSION_EXTRAS_CHANGED);
537 try {
538 SomeArgs args = SomeArgs.obtain();
539 args.arg1 = callId;
540 args.arg2 = extras;
541 args.arg3 = Log.createSubsession();
542 mHandler.obtainMessage(MSG_ON_EXTRAS_CHANGED, args).sendToTarget();
543 } finally {
544 Log.endSession();
545 }
Tyler Gunndee56a82016-03-23 16:06:34 -0700546 }
Hall Liub64ac4c2017-02-06 10:49:48 -0800547
548 @Override
549 public void startRtt(String callId, ParcelFileDescriptor fromInCall,
550 ParcelFileDescriptor toInCall, Session.Info sessionInfo) throws RemoteException {
551 Log.startSession(sessionInfo, SESSION_START_RTT);
552 try {
553 SomeArgs args = SomeArgs.obtain();
554 args.arg1 = callId;
555 args.arg2 = new Connection.RttTextStream(toInCall, fromInCall);
556 args.arg3 = Log.createSubsession();
557 mHandler.obtainMessage(MSG_ON_START_RTT, args).sendToTarget();
558 } finally {
559 Log.endSession();
560 }
561 }
562
563 @Override
564 public void stopRtt(String callId, Session.Info sessionInfo) throws RemoteException {
565 Log.startSession(sessionInfo, SESSION_STOP_RTT);
566 try {
567 SomeArgs args = SomeArgs.obtain();
568 args.arg1 = callId;
569 args.arg2 = Log.createSubsession();
570 mHandler.obtainMessage(MSG_ON_STOP_RTT, args).sendToTarget();
571 } finally {
572 Log.endSession();
573 }
574 }
575
576 @Override
577 public void respondToRttUpgradeRequest(String callId, ParcelFileDescriptor fromInCall,
578 ParcelFileDescriptor toInCall, Session.Info sessionInfo) throws RemoteException {
579 Log.startSession(sessionInfo, SESSION_RTT_UPGRADE_RESPONSE);
580 try {
581 SomeArgs args = SomeArgs.obtain();
582 args.arg1 = callId;
583 if (toInCall == null || fromInCall == null) {
584 args.arg2 = null;
585 } else {
586 args.arg2 = new Connection.RttTextStream(toInCall, fromInCall);
587 }
588 args.arg3 = Log.createSubsession();
589 mHandler.obtainMessage(MSG_RTT_UPGRADE_RESPONSE, args).sendToTarget();
590 } finally {
591 Log.endSession();
592 }
593 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700594 };
595
596 private final Handler mHandler = new Handler(Looper.getMainLooper()) {
597 @Override
598 public void handleMessage(Message msg) {
599 switch (msg.what) {
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700600 case MSG_ADD_CONNECTION_SERVICE_ADAPTER: {
601 SomeArgs args = (SomeArgs) msg.obj;
602 try {
603 IConnectionServiceAdapter adapter = (IConnectionServiceAdapter) args.arg1;
604 Log.continueSession((Session) args.arg2,
605 SESSION_HANDLER + SESSION_ADD_CS_ADAPTER);
606 mAdapter.addAdapter(adapter);
607 onAdapterAttached();
608 } finally {
609 args.recycle();
610 Log.endSession();
611 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700612 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700613 }
614 case MSG_REMOVE_CONNECTION_SERVICE_ADAPTER: {
615 SomeArgs args = (SomeArgs) msg.obj;
616 try {
617 Log.continueSession((Session) args.arg2,
618 SESSION_HANDLER + SESSION_REMOVE_CS_ADAPTER);
619 mAdapter.removeAdapter((IConnectionServiceAdapter) args.arg1);
620 } finally {
621 args.recycle();
622 Log.endSession();
623 }
Ihab Awad8aecfed2014-08-08 17:06:11 -0700624 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700625 }
Ihab Awadf8b69882014-07-25 15:14:01 -0700626 case MSG_CREATE_CONNECTION: {
627 SomeArgs args = (SomeArgs) msg.obj;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700628 Log.continueSession((Session) args.arg4, SESSION_HANDLER + SESSION_CREATE_CONN);
Ihab Awadf8b69882014-07-25 15:14:01 -0700629 try {
Ihab Awad5d0410f2014-07-30 10:07:40 -0700630 final PhoneAccountHandle connectionManagerPhoneAccount =
Ihab Awadf8b69882014-07-25 15:14:01 -0700631 (PhoneAccountHandle) args.arg1;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700632 final String id = (String) args.arg2;
633 final ConnectionRequest request = (ConnectionRequest) args.arg3;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700634 final boolean isIncoming = args.argi1 == 1;
Yorke Leec3cf9822014-10-02 09:38:39 -0700635 final boolean isUnknown = args.argi2 == 1;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700636 if (!mAreAccountsInitialized) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700637 Log.d(this, "Enqueueing pre-init request %s", id);
Brad Ebinger0c3541b2016-11-01 14:11:38 -0700638 mPreInitializationConnectionRequests.add(
639 new android.telecom.Logging.Runnable(
640 SESSION_HANDLER + SESSION_CREATE_CONN + ".pICR",
641 null /*lock*/) {
Ihab Awad5d0410f2014-07-30 10:07:40 -0700642 @Override
Brad Ebinger0c3541b2016-11-01 14:11:38 -0700643 public void loggedRun() {
Ihab Awad5d0410f2014-07-30 10:07:40 -0700644 createConnection(
645 connectionManagerPhoneAccount,
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700646 id,
Ihab Awad5d0410f2014-07-30 10:07:40 -0700647 request,
Yorke Leec3cf9822014-10-02 09:38:39 -0700648 isIncoming,
649 isUnknown);
Ihab Awad5d0410f2014-07-30 10:07:40 -0700650 }
Brad Ebinger0c3541b2016-11-01 14:11:38 -0700651 }.prepare());
Ihab Awad5d0410f2014-07-30 10:07:40 -0700652 } else {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700653 createConnection(
654 connectionManagerPhoneAccount,
655 id,
656 request,
Yorke Leec3cf9822014-10-02 09:38:39 -0700657 isIncoming,
658 isUnknown);
Ihab Awad5d0410f2014-07-30 10:07:40 -0700659 }
Ihab Awadf8b69882014-07-25 15:14:01 -0700660 } finally {
661 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700662 Log.endSession();
Ihab Awadf8b69882014-07-25 15:14:01 -0700663 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700664 break;
Ihab Awadf8b69882014-07-25 15:14:01 -0700665 }
Tyler Gunn041a1fe2017-05-12 10:04:49 -0700666 case MSG_CREATE_CONNECTION_COMPLETE: {
667 SomeArgs args = (SomeArgs) msg.obj;
668 Log.continueSession((Session) args.arg2,
669 SESSION_HANDLER + SESSION_CREATE_CONN_COMPLETE);
670 try {
671 final String id = (String) args.arg1;
672 if (!mAreAccountsInitialized) {
673 Log.d(this, "Enqueueing pre-init request %s", id);
674 mPreInitializationConnectionRequests.add(
675 new android.telecom.Logging.Runnable(
676 SESSION_HANDLER + SESSION_CREATE_CONN_COMPLETE
677 + ".pICR",
678 null /*lock*/) {
679 @Override
680 public void loggedRun() {
681 notifyCreateConnectionComplete(id);
682 }
683 }.prepare());
684 } else {
685 notifyCreateConnectionComplete(id);
686 }
687 } finally {
688 args.recycle();
689 Log.endSession();
690 }
691 break;
692 }
Tyler Gunn44e01912017-01-31 10:49:05 -0800693 case MSG_CREATE_CONNECTION_FAILED: {
694 SomeArgs args = (SomeArgs) msg.obj;
695 Log.continueSession((Session) args.arg3, SESSION_HANDLER +
696 SESSION_CREATE_CONN_FAILED);
697 try {
698 final String id = (String) args.arg1;
699 final ConnectionRequest request = (ConnectionRequest) args.arg2;
700 final boolean isIncoming = args.argi1 == 1;
Tyler Gunn159f35c2017-03-02 09:28:37 -0800701 final PhoneAccountHandle connectionMgrPhoneAccount =
702 (PhoneAccountHandle) args.arg4;
Tyler Gunn44e01912017-01-31 10:49:05 -0800703 if (!mAreAccountsInitialized) {
704 Log.d(this, "Enqueueing pre-init request %s", id);
705 mPreInitializationConnectionRequests.add(
706 new android.telecom.Logging.Runnable(
707 SESSION_HANDLER + SESSION_CREATE_CONN_FAILED + ".pICR",
708 null /*lock*/) {
709 @Override
710 public void loggedRun() {
Tyler Gunn159f35c2017-03-02 09:28:37 -0800711 createConnectionFailed(connectionMgrPhoneAccount, id,
712 request, isIncoming);
Tyler Gunn44e01912017-01-31 10:49:05 -0800713 }
714 }.prepare());
715 } else {
716 Log.i(this, "createConnectionFailed %s", id);
Tyler Gunn159f35c2017-03-02 09:28:37 -0800717 createConnectionFailed(connectionMgrPhoneAccount, id, request,
718 isIncoming);
Tyler Gunn44e01912017-01-31 10:49:05 -0800719 }
720 } finally {
721 args.recycle();
722 Log.endSession();
723 }
724 break;
725 }
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700726 case MSG_ABORT: {
727 SomeArgs args = (SomeArgs) msg.obj;
728 Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_ABORT);
729 try {
730 abort((String) args.arg1);
731 } finally {
732 args.recycle();
733 Log.endSession();
734 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700735 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700736 }
737 case MSG_ANSWER: {
738 SomeArgs args = (SomeArgs) msg.obj;
739 Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_ANSWER);
740 try {
741 answer((String) args.arg1);
742 } finally {
743 args.recycle();
744 Log.endSession();
745 }
Tyler Gunnbe74de02014-08-29 14:51:48 -0700746 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700747 }
Tyler Gunnbe74de02014-08-29 14:51:48 -0700748 case MSG_ANSWER_VIDEO: {
Andrew Lee8da4c3c2014-07-16 10:11:42 -0700749 SomeArgs args = (SomeArgs) msg.obj;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700750 Log.continueSession((Session) args.arg2,
751 SESSION_HANDLER + SESSION_ANSWER_VIDEO);
Andrew Lee8da4c3c2014-07-16 10:11:42 -0700752 try {
753 String callId = (String) args.arg1;
Evan Charltonbf11f982014-07-20 22:06:28 -0700754 int videoState = args.argi1;
Tyler Gunnbe74de02014-08-29 14:51:48 -0700755 answerVideo(callId, videoState);
Andrew Lee8da4c3c2014-07-16 10:11:42 -0700756 } finally {
757 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700758 Log.endSession();
Andrew Lee8da4c3c2014-07-16 10:11:42 -0700759 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700760 break;
Andrew Lee8da4c3c2014-07-16 10:11:42 -0700761 }
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700762 case MSG_REJECT: {
763 SomeArgs args = (SomeArgs) msg.obj;
764 Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_REJECT);
765 try {
766 reject((String) args.arg1);
767 } finally {
768 args.recycle();
769 Log.endSession();
770 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700771 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700772 }
Bryce Lee81901682015-08-28 16:38:02 -0700773 case MSG_REJECT_WITH_MESSAGE: {
774 SomeArgs args = (SomeArgs) msg.obj;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700775 Log.continueSession((Session) args.arg3,
776 SESSION_HANDLER + SESSION_REJECT_MESSAGE);
Bryce Lee81901682015-08-28 16:38:02 -0700777 try {
778 reject((String) args.arg1, (String) args.arg2);
779 } finally {
780 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700781 Log.endSession();
Bryce Lee81901682015-08-28 16:38:02 -0700782 }
783 break;
784 }
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700785 case MSG_DISCONNECT: {
786 SomeArgs args = (SomeArgs) msg.obj;
787 Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_DISCONNECT);
788 try {
789 disconnect((String) args.arg1);
790 } finally {
791 args.recycle();
792 Log.endSession();
793 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700794 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700795 }
796 case MSG_SILENCE: {
797 SomeArgs args = (SomeArgs) msg.obj;
798 Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_SILENCE);
799 try {
800 silence((String) args.arg1);
801 } finally {
802 args.recycle();
803 Log.endSession();
804 }
Bryce Leecac50772015-11-17 15:13:29 -0800805 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700806 }
807 case MSG_HOLD: {
808 SomeArgs args = (SomeArgs) msg.obj;
809 Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_REJECT);
810 try {
811 hold((String) args.arg1);
812 } finally {
813 args.recycle();
814 Log.endSession();
815 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700816 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700817 }
818 case MSG_UNHOLD: {
819 SomeArgs args = (SomeArgs) msg.obj;
820 Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_UNHOLD);
821 try {
822 unhold((String) args.arg1);
823 } finally {
824 args.recycle();
825 Log.endSession();
826 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700827 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700828 }
Yorke Lee4af59352015-05-13 14:14:54 -0700829 case MSG_ON_CALL_AUDIO_STATE_CHANGED: {
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700830 SomeArgs args = (SomeArgs) msg.obj;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700831 Log.continueSession((Session) args.arg3,
832 SESSION_HANDLER + SESSION_CALL_AUDIO_SC);
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700833 try {
834 String callId = (String) args.arg1;
Yorke Lee4af59352015-05-13 14:14:54 -0700835 CallAudioState audioState = (CallAudioState) args.arg2;
836 onCallAudioStateChanged(callId, new CallAudioState(audioState));
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700837 } finally {
838 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700839 Log.endSession();
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700840 }
841 break;
842 }
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700843 case MSG_PLAY_DTMF_TONE: {
844 SomeArgs args = (SomeArgs) msg.obj;
845 try {
846 Log.continueSession((Session) args.arg3,
847 SESSION_HANDLER + SESSION_PLAY_DTMF);
848 playDtmfTone((String) args.arg2, (char) args.arg1);
849 } finally {
850 args.recycle();
851 Log.endSession();
852 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700853 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700854 }
855 case MSG_STOP_DTMF_TONE: {
856 SomeArgs args = (SomeArgs) msg.obj;
857 try {
858 Log.continueSession((Session) args.arg2,
859 SESSION_HANDLER + SESSION_STOP_DTMF);
860 stopDtmfTone((String) args.arg1);
861 } finally {
862 args.recycle();
863 Log.endSession();
864 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700865 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700866 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700867 case MSG_CONFERENCE: {
868 SomeArgs args = (SomeArgs) msg.obj;
869 try {
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700870 Log.continueSession((Session) args.arg3,
871 SESSION_HANDLER + SESSION_CONFERENCE);
Santos Cordon823fd3c2014-08-07 18:35:18 -0700872 String callId1 = (String) args.arg1;
873 String callId2 = (String) args.arg2;
874 conference(callId1, callId2);
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700875 } finally {
876 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700877 Log.endSession();
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700878 }
879 break;
880 }
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700881 case MSG_SPLIT_FROM_CONFERENCE: {
882 SomeArgs args = (SomeArgs) msg.obj;
883 try {
884 Log.continueSession((Session) args.arg2,
885 SESSION_HANDLER + SESSION_SPLIT_CONFERENCE);
886 splitFromConference((String) args.arg1);
887 } finally {
888 args.recycle();
889 Log.endSession();
890 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700891 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700892 }
893 case MSG_MERGE_CONFERENCE: {
894 SomeArgs args = (SomeArgs) msg.obj;
895 try {
896 Log.continueSession((Session) args.arg2,
897 SESSION_HANDLER + SESSION_MERGE_CONFERENCE);
898 mergeConference((String) args.arg1);
899 } finally {
900 args.recycle();
901 Log.endSession();
902 }
Santos Cordona4868042014-09-04 17:39:22 -0700903 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700904 }
905 case MSG_SWAP_CONFERENCE: {
906 SomeArgs args = (SomeArgs) msg.obj;
907 try {
908 Log.continueSession((Session) args.arg2,
909 SESSION_HANDLER + SESSION_SWAP_CONFERENCE);
910 swapConference((String) args.arg1);
911 } finally {
912 args.recycle();
913 Log.endSession();
914 }
Santos Cordona4868042014-09-04 17:39:22 -0700915 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700916 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700917 case MSG_ON_POST_DIAL_CONTINUE: {
918 SomeArgs args = (SomeArgs) msg.obj;
919 try {
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700920 Log.continueSession((Session) args.arg2,
921 SESSION_HANDLER + SESSION_POST_DIAL_CONT);
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700922 String callId = (String) args.arg1;
923 boolean proceed = (args.argi1 == 1);
924 onPostDialContinue(callId, proceed);
925 } finally {
926 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700927 Log.endSession();
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700928 }
929 break;
930 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700931 case MSG_PULL_EXTERNAL_CALL: {
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700932 SomeArgs args = (SomeArgs) msg.obj;
933 try {
934 Log.continueSession((Session) args.arg2,
935 SESSION_HANDLER + SESSION_PULL_EXTERNAL_CALL);
936 pullExternalCall((String) args.arg1);
937 } finally {
938 args.recycle();
939 Log.endSession();
940 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700941 break;
942 }
943 case MSG_SEND_CALL_EVENT: {
944 SomeArgs args = (SomeArgs) msg.obj;
945 try {
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700946 Log.continueSession((Session) args.arg4,
947 SESSION_HANDLER + SESSION_SEND_CALL_EVENT);
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700948 String callId = (String) args.arg1;
949 String event = (String) args.arg2;
950 Bundle extras = (Bundle) args.arg3;
951 sendCallEvent(callId, event, extras);
952 } finally {
953 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700954 Log.endSession();
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700955 }
956 break;
957 }
Tyler Gunndee56a82016-03-23 16:06:34 -0700958 case MSG_ON_EXTRAS_CHANGED: {
959 SomeArgs args = (SomeArgs) msg.obj;
960 try {
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700961 Log.continueSession((Session) args.arg3,
962 SESSION_HANDLER + SESSION_EXTRAS_CHANGED);
Tyler Gunndee56a82016-03-23 16:06:34 -0700963 String callId = (String) args.arg1;
964 Bundle extras = (Bundle) args.arg2;
965 handleExtrasChanged(callId, extras);
966 } finally {
967 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700968 Log.endSession();
Tyler Gunndee56a82016-03-23 16:06:34 -0700969 }
970 break;
971 }
Hall Liub64ac4c2017-02-06 10:49:48 -0800972 case MSG_ON_START_RTT: {
973 SomeArgs args = (SomeArgs) msg.obj;
974 try {
975 Log.continueSession((Session) args.arg3,
976 SESSION_HANDLER + SESSION_START_RTT);
977 String callId = (String) args.arg1;
978 Connection.RttTextStream rttTextStream =
979 (Connection.RttTextStream) args.arg2;
980 startRtt(callId, rttTextStream);
981 } finally {
982 args.recycle();
983 Log.endSession();
984 }
985 break;
986 }
987 case MSG_ON_STOP_RTT: {
988 SomeArgs args = (SomeArgs) msg.obj;
989 try {
990 Log.continueSession((Session) args.arg2,
991 SESSION_HANDLER + SESSION_STOP_RTT);
992 String callId = (String) args.arg1;
993 stopRtt(callId);
994 } finally {
995 args.recycle();
996 Log.endSession();
997 }
998 break;
999 }
1000 case MSG_RTT_UPGRADE_RESPONSE: {
1001 SomeArgs args = (SomeArgs) msg.obj;
1002 try {
1003 Log.continueSession((Session) args.arg3,
1004 SESSION_HANDLER + SESSION_RTT_UPGRADE_RESPONSE);
1005 String callId = (String) args.arg1;
1006 Connection.RttTextStream rttTextStream =
1007 (Connection.RttTextStream) args.arg2;
1008 handleRttUpgradeResponse(callId, rttTextStream);
1009 } finally {
1010 args.recycle();
1011 Log.endSession();
1012 }
1013 break;
1014 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001015 default:
1016 break;
1017 }
1018 }
1019 };
1020
Santos Cordon823fd3c2014-08-07 18:35:18 -07001021 private final Conference.Listener mConferenceListener = new Conference.Listener() {
1022 @Override
1023 public void onStateChanged(Conference conference, int oldState, int newState) {
1024 String id = mIdByConference.get(conference);
1025 switch (newState) {
1026 case Connection.STATE_ACTIVE:
1027 mAdapter.setActive(id);
1028 break;
1029 case Connection.STATE_HOLDING:
1030 mAdapter.setOnHold(id);
1031 break;
1032 case Connection.STATE_DISCONNECTED:
1033 // handled by onDisconnected
1034 break;
1035 }
1036 }
1037
1038 @Override
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001039 public void onDisconnected(Conference conference, DisconnectCause disconnectCause) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07001040 String id = mIdByConference.get(conference);
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001041 mAdapter.setDisconnected(id, disconnectCause);
Santos Cordon823fd3c2014-08-07 18:35:18 -07001042 }
1043
1044 @Override
1045 public void onConnectionAdded(Conference conference, Connection connection) {
1046 }
1047
1048 @Override
1049 public void onConnectionRemoved(Conference conference, Connection connection) {
1050 }
1051
1052 @Override
Ihab Awad50e35062014-09-30 09:17:03 -07001053 public void onConferenceableConnectionsChanged(
1054 Conference conference, List<Connection> conferenceableConnections) {
1055 mAdapter.setConferenceableConnections(
1056 mIdByConference.get(conference),
1057 createConnectionIdList(conferenceableConnections));
1058 }
1059
1060 @Override
Santos Cordon823fd3c2014-08-07 18:35:18 -07001061 public void onDestroyed(Conference conference) {
1062 removeConference(conference);
1063 }
1064
1065 @Override
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001066 public void onConnectionCapabilitiesChanged(
1067 Conference conference,
1068 int connectionCapabilities) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07001069 String id = mIdByConference.get(conference);
1070 Log.d(this, "call capabilities: conference: %s",
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001071 Connection.capabilitiesToString(connectionCapabilities));
1072 mAdapter.setConnectionCapabilities(id, connectionCapabilities);
Santos Cordon823fd3c2014-08-07 18:35:18 -07001073 }
Rekha Kumar07366812015-03-24 16:42:31 -07001074
1075 @Override
Tyler Gunn720c6642016-03-22 09:02:47 -07001076 public void onConnectionPropertiesChanged(
1077 Conference conference,
1078 int connectionProperties) {
1079 String id = mIdByConference.get(conference);
1080 Log.d(this, "call capabilities: conference: %s",
1081 Connection.propertiesToString(connectionProperties));
1082 mAdapter.setConnectionProperties(id, connectionProperties);
1083 }
1084
1085 @Override
Rekha Kumar07366812015-03-24 16:42:31 -07001086 public void onVideoStateChanged(Conference c, int videoState) {
1087 String id = mIdByConference.get(c);
1088 Log.d(this, "onVideoStateChanged set video state %d", videoState);
1089 mAdapter.setVideoState(id, videoState);
1090 }
1091
1092 @Override
1093 public void onVideoProviderChanged(Conference c, Connection.VideoProvider videoProvider) {
1094 String id = mIdByConference.get(c);
1095 Log.d(this, "onVideoProviderChanged: Connection: %s, VideoProvider: %s", c,
1096 videoProvider);
1097 mAdapter.setVideoProvider(id, videoProvider);
1098 }
Andrew Lee0f51da32015-04-16 13:11:55 -07001099
1100 @Override
Andrew Leeedc625f2015-04-14 13:38:12 -07001101 public void onStatusHintsChanged(Conference conference, StatusHints statusHints) {
1102 String id = mIdByConference.get(conference);
Tyler Gunndee56a82016-03-23 16:06:34 -07001103 if (id != null) {
1104 mAdapter.setStatusHints(id, statusHints);
1105 }
Andrew Leeedc625f2015-04-14 13:38:12 -07001106 }
Santos Cordon6b7f9552015-05-27 17:21:45 -07001107
1108 @Override
Tyler Gunndee56a82016-03-23 16:06:34 -07001109 public void onExtrasChanged(Conference c, Bundle extras) {
1110 String id = mIdByConference.get(c);
1111 if (id != null) {
1112 mAdapter.putExtras(id, extras);
1113 }
1114 }
1115
1116 @Override
1117 public void onExtrasRemoved(Conference c, List<String> keys) {
1118 String id = mIdByConference.get(c);
1119 if (id != null) {
1120 mAdapter.removeExtras(id, keys);
1121 }
Santos Cordon6b7f9552015-05-27 17:21:45 -07001122 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07001123 };
1124
Ihab Awad542e0ea2014-05-16 10:22:16 -07001125 private final Connection.Listener mConnectionListener = new Connection.Listener() {
1126 @Override
1127 public void onStateChanged(Connection c, int state) {
1128 String id = mIdByConnection.get(c);
Ihab Awad42b30e12014-05-22 09:49:34 -07001129 Log.d(this, "Adapter set state %s %s", id, Connection.stateToString(state));
Ihab Awad542e0ea2014-05-16 10:22:16 -07001130 switch (state) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001131 case Connection.STATE_ACTIVE:
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001132 mAdapter.setActive(id);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001133 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001134 case Connection.STATE_DIALING:
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001135 mAdapter.setDialing(id);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001136 break;
Tyler Gunnc96b5e02016-07-07 22:53:57 -07001137 case Connection.STATE_PULLING_CALL:
1138 mAdapter.setPulling(id);
1139 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001140 case Connection.STATE_DISCONNECTED:
Ihab Awad542e0ea2014-05-16 10:22:16 -07001141 // Handled in onDisconnected()
1142 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001143 case Connection.STATE_HOLDING:
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001144 mAdapter.setOnHold(id);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001145 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001146 case Connection.STATE_NEW:
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001147 // Nothing to tell Telecom
Ihab Awad542e0ea2014-05-16 10:22:16 -07001148 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001149 case Connection.STATE_RINGING:
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001150 mAdapter.setRinging(id);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001151 break;
1152 }
1153 }
1154
1155 @Override
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001156 public void onDisconnected(Connection c, DisconnectCause disconnectCause) {
Ihab Awad542e0ea2014-05-16 10:22:16 -07001157 String id = mIdByConnection.get(c);
Andrew Lee26786392014-09-16 18:14:59 -07001158 Log.d(this, "Adapter set disconnected %s", disconnectCause);
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001159 mAdapter.setDisconnected(id, disconnectCause);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001160 }
1161
1162 @Override
Tyler Gunnaa07df82014-07-17 07:50:22 -07001163 public void onVideoStateChanged(Connection c, int videoState) {
1164 String id = mIdByConnection.get(c);
1165 Log.d(this, "Adapter set video state %d", videoState);
1166 mAdapter.setVideoState(id, videoState);
1167 }
1168
1169 @Override
Andrew Lee100e2932014-09-08 15:34:24 -07001170 public void onAddressChanged(Connection c, Uri address, int presentation) {
Sailesh Nepal61203862014-07-11 14:50:13 -07001171 String id = mIdByConnection.get(c);
Andrew Lee100e2932014-09-08 15:34:24 -07001172 mAdapter.setAddress(id, address, presentation);
Sailesh Nepal61203862014-07-11 14:50:13 -07001173 }
1174
1175 @Override
1176 public void onCallerDisplayNameChanged(
1177 Connection c, String callerDisplayName, int presentation) {
1178 String id = mIdByConnection.get(c);
1179 mAdapter.setCallerDisplayName(id, callerDisplayName, presentation);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001180 }
1181
1182 @Override
Ihab Awad542e0ea2014-05-16 10:22:16 -07001183 public void onDestroyed(Connection c) {
1184 removeConnection(c);
1185 }
Ihab Awadf8358972014-05-28 16:46:42 -07001186
1187 @Override
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001188 public void onPostDialWait(Connection c, String remaining) {
Sailesh Nepal091768c2014-06-30 15:15:23 -07001189 String id = mIdByConnection.get(c);
1190 Log.d(this, "Adapter onPostDialWait %s, %s", c, remaining);
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001191 mAdapter.onPostDialWait(id, remaining);
Sailesh Nepal091768c2014-06-30 15:15:23 -07001192 }
1193
1194 @Override
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001195 public void onPostDialChar(Connection c, char nextChar) {
1196 String id = mIdByConnection.get(c);
1197 Log.d(this, "Adapter onPostDialChar %s, %s", c, nextChar);
1198 mAdapter.onPostDialChar(id, nextChar);
1199 }
1200
1201 @Override
Andrew Lee100e2932014-09-08 15:34:24 -07001202 public void onRingbackRequested(Connection c, boolean ringback) {
Ihab Awadf8358972014-05-28 16:46:42 -07001203 String id = mIdByConnection.get(c);
1204 Log.d(this, "Adapter onRingback %b", ringback);
Andrew Lee100e2932014-09-08 15:34:24 -07001205 mAdapter.setRingbackRequested(id, ringback);
Ihab Awadf8358972014-05-28 16:46:42 -07001206 }
Santos Cordonb6939982014-06-04 20:20:58 -07001207
1208 @Override
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001209 public void onConnectionCapabilitiesChanged(Connection c, int capabilities) {
Santos Cordonb6939982014-06-04 20:20:58 -07001210 String id = mIdByConnection.get(c);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001211 Log.d(this, "capabilities: parcelableconnection: %s",
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001212 Connection.capabilitiesToString(capabilities));
1213 mAdapter.setConnectionCapabilities(id, capabilities);
Santos Cordonb6939982014-06-04 20:20:58 -07001214 }
1215
Santos Cordonb6939982014-06-04 20:20:58 -07001216 @Override
Tyler Gunn720c6642016-03-22 09:02:47 -07001217 public void onConnectionPropertiesChanged(Connection c, int properties) {
1218 String id = mIdByConnection.get(c);
1219 Log.d(this, "properties: parcelableconnection: %s",
1220 Connection.propertiesToString(properties));
1221 mAdapter.setConnectionProperties(id, properties);
1222 }
1223
1224 @Override
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001225 public void onVideoProviderChanged(Connection c, Connection.VideoProvider videoProvider) {
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07001226 String id = mIdByConnection.get(c);
Rekha Kumar07366812015-03-24 16:42:31 -07001227 Log.d(this, "onVideoProviderChanged: Connection: %s, VideoProvider: %s", c,
1228 videoProvider);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001229 mAdapter.setVideoProvider(id, videoProvider);
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07001230 }
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001231
1232 @Override
Sailesh Nepal001bbbb2014-07-15 14:40:39 -07001233 public void onAudioModeIsVoipChanged(Connection c, boolean isVoip) {
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001234 String id = mIdByConnection.get(c);
Andrew Lee100e2932014-09-08 15:34:24 -07001235 mAdapter.setIsVoipAudioMode(id, isVoip);
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001236 }
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001237
1238 @Override
Sailesh Nepal001bbbb2014-07-15 14:40:39 -07001239 public void onStatusHintsChanged(Connection c, StatusHints statusHints) {
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001240 String id = mIdByConnection.get(c);
1241 mAdapter.setStatusHints(id, statusHints);
1242 }
Sailesh Nepal2ab88cc2014-07-18 14:49:18 -07001243
1244 @Override
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001245 public void onConferenceablesChanged(
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001246 Connection connection, List<Conferenceable> conferenceables) {
Ihab Awadb8e85c72014-08-23 20:34:57 -07001247 mAdapter.setConferenceableConnections(
1248 mIdByConnection.get(connection),
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001249 createIdList(conferenceables));
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001250 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07001251
1252 @Override
1253 public void onConferenceChanged(Connection connection, Conference conference) {
1254 String id = mIdByConnection.get(connection);
1255 if (id != null) {
1256 String conferenceId = null;
1257 if (conference != null) {
1258 conferenceId = mIdByConference.get(conference);
1259 }
1260 mAdapter.setIsConferenced(id, conferenceId);
1261 }
1262 }
Anthony Lee17455a32015-04-24 15:25:29 -07001263
1264 @Override
1265 public void onConferenceMergeFailed(Connection connection) {
1266 String id = mIdByConnection.get(connection);
1267 if (id != null) {
1268 mAdapter.onConferenceMergeFailed(id);
1269 }
1270 }
Santos Cordon6b7f9552015-05-27 17:21:45 -07001271
1272 @Override
Tyler Gunndee56a82016-03-23 16:06:34 -07001273 public void onExtrasChanged(Connection c, Bundle extras) {
1274 String id = mIdByConnection.get(c);
Santos Cordon6b7f9552015-05-27 17:21:45 -07001275 if (id != null) {
Tyler Gunndee56a82016-03-23 16:06:34 -07001276 mAdapter.putExtras(id, extras);
Santos Cordon6b7f9552015-05-27 17:21:45 -07001277 }
1278 }
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001279
Tyler Gunnf5035432017-01-09 09:43:12 -08001280 @Override
Tyler Gunndee56a82016-03-23 16:06:34 -07001281 public void onExtrasRemoved(Connection c, List<String> keys) {
1282 String id = mIdByConnection.get(c);
1283 if (id != null) {
1284 mAdapter.removeExtras(id, keys);
1285 }
1286 }
1287
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08001288 @Override
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001289 public void onConnectionEvent(Connection connection, String event, Bundle extras) {
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08001290 String id = mIdByConnection.get(connection);
1291 if (id != null) {
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001292 mAdapter.onConnectionEvent(id, event, extras);
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08001293 }
1294 }
Tyler Gunnf5035432017-01-09 09:43:12 -08001295
1296 @Override
Hall Liua98f58b52017-11-07 17:59:28 -08001297 public void onAudioRouteChanged(Connection c, int audioRoute, String bluetoothAddress) {
Tyler Gunnf5035432017-01-09 09:43:12 -08001298 String id = mIdByConnection.get(c);
1299 if (id != null) {
Hall Liua98f58b52017-11-07 17:59:28 -08001300 mAdapter.setAudioRoute(id, audioRoute, bluetoothAddress);
Tyler Gunnf5035432017-01-09 09:43:12 -08001301 }
1302 }
Hall Liub64ac4c2017-02-06 10:49:48 -08001303
1304 @Override
1305 public void onRttInitiationSuccess(Connection c) {
1306 String id = mIdByConnection.get(c);
1307 if (id != null) {
1308 mAdapter.onRttInitiationSuccess(id);
1309 }
1310 }
1311
1312 @Override
1313 public void onRttInitiationFailure(Connection c, int reason) {
1314 String id = mIdByConnection.get(c);
1315 if (id != null) {
1316 mAdapter.onRttInitiationFailure(id, reason);
1317 }
1318 }
1319
1320 @Override
1321 public void onRttSessionRemotelyTerminated(Connection c) {
1322 String id = mIdByConnection.get(c);
1323 if (id != null) {
1324 mAdapter.onRttSessionRemotelyTerminated(id);
1325 }
1326 }
1327
1328 @Override
1329 public void onRemoteRttRequest(Connection c) {
1330 String id = mIdByConnection.get(c);
1331 if (id != null) {
1332 mAdapter.onRemoteRttRequest(id);
1333 }
1334 }
Srikanth Chintalafcb15012017-05-04 20:58:34 +05301335
1336 @Override
1337 public void onPhoneAccountChanged(Connection c, PhoneAccountHandle pHandle) {
1338 String id = mIdByConnection.get(c);
1339 if (id != null) {
1340 mAdapter.onPhoneAccountChanged(id, pHandle);
1341 }
1342 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001343 };
1344
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001345 /** {@inheritDoc} */
Ihab Awad542e0ea2014-05-16 10:22:16 -07001346 @Override
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001347 public final IBinder onBind(Intent intent) {
1348 return mBinder;
1349 }
1350
Santos Cordon29f2f2e2014-09-11 19:50:24 -07001351 /** {@inheritDoc} */
1352 @Override
1353 public boolean onUnbind(Intent intent) {
1354 endAllConnections();
1355 return super.onUnbind(intent);
1356 }
1357
Sailesh Nepalc5b01572014-07-14 16:29:44 -07001358 /**
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001359 * This can be used by telecom to either create a new outgoing call or attach to an existing
1360 * incoming call. In either case, telecom will cycle through a set of services and call
Sailesh Nepalc5b01572014-07-14 16:29:44 -07001361 * createConnection util a connection service cancels the process or completes it successfully.
1362 */
Ihab Awadf8b69882014-07-25 15:14:01 -07001363 private void createConnection(
1364 final PhoneAccountHandle callManagerAccount,
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001365 final String callId,
Ihab Awadf8b69882014-07-25 15:14:01 -07001366 final ConnectionRequest request,
Yorke Leec3cf9822014-10-02 09:38:39 -07001367 boolean isIncoming,
1368 boolean isUnknown) {
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001369 Log.d(this, "createConnection, callManagerAccount: %s, callId: %s, request: %s, " +
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001370 "isIncoming: %b, isUnknown: %b", callManagerAccount, callId, request,
1371 isIncoming,
Yorke Leec3cf9822014-10-02 09:38:39 -07001372 isUnknown);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001373
Sanket Padawe85291f62017-12-01 13:59:27 -08001374 Connection connection = null;
1375 if (request.getExtras() != null && request.getExtras().getBoolean(
1376 TelecomManager.EXTRA_IS_HANDOVER,false)) {
1377 if (!isIncoming) {
1378 connection = onCreateOutgoingHandoverConnection(callManagerAccount, request);
1379 } else {
1380 // Todo: Call onCreateIncommingHandoverConnection()
1381 }
1382 } else {
1383 connection = isUnknown ? onCreateUnknownConnection(callManagerAccount, request)
1384 : isIncoming ? onCreateIncomingConnection(callManagerAccount, request)
1385 : onCreateOutgoingConnection(callManagerAccount, request);
1386 }
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001387 Log.d(this, "createConnection, connection: %s", connection);
1388 if (connection == null) {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001389 connection = Connection.createFailedConnection(
1390 new DisconnectCause(DisconnectCause.ERROR));
Sailesh Nepalc5b01572014-07-14 16:29:44 -07001391 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001392
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001393 connection.setTelecomCallId(callId);
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001394 if (connection.getState() != Connection.STATE_DISCONNECTED) {
Ihab Awad6107bab2014-08-18 09:23:25 -07001395 addConnection(callId, connection);
1396 }
1397
Andrew Lee100e2932014-09-08 15:34:24 -07001398 Uri address = connection.getAddress();
1399 String number = address == null ? "null" : address.getSchemeSpecificPart();
Tyler Gunn720c6642016-03-22 09:02:47 -07001400 Log.v(this, "createConnection, number: %s, state: %s, capabilities: %s, properties: %s",
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001401 Connection.toLogSafePhoneNumber(number),
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001402 Connection.stateToString(connection.getState()),
Tyler Gunn720c6642016-03-22 09:02:47 -07001403 Connection.capabilitiesToString(connection.getConnectionCapabilities()),
1404 Connection.propertiesToString(connection.getConnectionProperties()));
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001405
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001406 Log.d(this, "createConnection, calling handleCreateConnectionSuccessful %s", callId);
Ihab Awad6107bab2014-08-18 09:23:25 -07001407 mAdapter.handleCreateConnectionComplete(
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001408 callId,
Evan Charltonbf11f982014-07-20 22:06:28 -07001409 request,
1410 new ParcelableConnection(
1411 request.getAccountHandle(),
1412 connection.getState(),
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001413 connection.getConnectionCapabilities(),
Tyler Gunn720c6642016-03-22 09:02:47 -07001414 connection.getConnectionProperties(),
Christine Hallstrom2830ce92016-11-30 16:06:42 -08001415 connection.getSupportedAudioRoutes(),
Andrew Lee100e2932014-09-08 15:34:24 -07001416 connection.getAddress(),
1417 connection.getAddressPresentation(),
Evan Charltonbf11f982014-07-20 22:06:28 -07001418 connection.getCallerDisplayName(),
1419 connection.getCallerDisplayNamePresentation(),
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001420 connection.getVideoProvider() == null ?
1421 null : connection.getVideoProvider().getInterface(),
Sailesh Nepal8b9d3ca2014-08-14 17:39:34 -07001422 connection.getVideoState(),
Andrew Lee100e2932014-09-08 15:34:24 -07001423 connection.isRingbackRequested(),
Sailesh Nepal8b9d3ca2014-08-14 17:39:34 -07001424 connection.getAudioModeIsVoip(),
Roshan Piuse927ec02015-07-15 15:47:21 -07001425 connection.getConnectTimeMillis(),
Tyler Gunn3fa819c2017-08-04 09:27:26 -07001426 connection.getConnectElapsedTimeMillis(),
Ihab Awad6107bab2014-08-18 09:23:25 -07001427 connection.getStatusHints(),
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001428 connection.getDisconnectCause(),
Santos Cordon6b7f9552015-05-27 17:21:45 -07001429 createIdList(connection.getConferenceables()),
1430 connection.getExtras()));
Tyler Gunnf5035432017-01-09 09:43:12 -08001431
1432 if (isIncoming && request.shouldShowIncomingCallUi() &&
1433 (connection.getConnectionProperties() & Connection.PROPERTY_SELF_MANAGED) ==
1434 Connection.PROPERTY_SELF_MANAGED) {
1435 // Tell ConnectionService to show its incoming call UX.
1436 connection.onShowIncomingCallUi();
1437 }
Shriram Ganesh6bf35ac2014-12-11 17:53:38 -08001438 if (isUnknown) {
1439 triggerConferenceRecalculate();
1440 }
Evan Charltonbf11f982014-07-20 22:06:28 -07001441 }
1442
Tyler Gunn159f35c2017-03-02 09:28:37 -08001443 private void createConnectionFailed(final PhoneAccountHandle callManagerAccount,
1444 final String callId, final ConnectionRequest request,
1445 boolean isIncoming) {
Tyler Gunn44e01912017-01-31 10:49:05 -08001446
1447 Log.i(this, "createConnectionFailed %s", callId);
1448 if (isIncoming) {
Tyler Gunn159f35c2017-03-02 09:28:37 -08001449 onCreateIncomingConnectionFailed(callManagerAccount, request);
Tyler Gunn44e01912017-01-31 10:49:05 -08001450 } else {
Tyler Gunn159f35c2017-03-02 09:28:37 -08001451 onCreateOutgoingConnectionFailed(callManagerAccount, request);
Tyler Gunn44e01912017-01-31 10:49:05 -08001452 }
1453 }
1454
Tyler Gunn041a1fe2017-05-12 10:04:49 -07001455 /**
1456 * Called by Telecom when the creation of a new Connection has completed and it is now added
1457 * to Telecom.
1458 * @param callId The ID of the connection.
1459 */
1460 private void notifyCreateConnectionComplete(final String callId) {
1461 Log.i(this, "notifyCreateConnectionComplete %s", callId);
Tyler Gunn0a88f2e2017-06-16 20:20:34 -07001462 if (callId == null) {
1463 // This could happen if the connection fails quickly and is removed from the
1464 // ConnectionService before Telecom sends the create connection complete callback.
1465 Log.w(this, "notifyCreateConnectionComplete: callId is null.");
1466 return;
1467 }
Tyler Gunn041a1fe2017-05-12 10:04:49 -07001468 onCreateConnectionComplete(findConnectionForAction(callId,
1469 "notifyCreateConnectionComplete"));
1470 }
1471
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001472 private void abort(String callId) {
Ihab Awad60ac30b2014-05-20 22:32:12 -07001473 Log.d(this, "abort %s", callId);
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001474 findConnectionForAction(callId, "abort").onAbort();
Ihab Awad542e0ea2014-05-16 10:22:16 -07001475 }
1476
Tyler Gunnbe74de02014-08-29 14:51:48 -07001477 private void answerVideo(String callId, int videoState) {
1478 Log.d(this, "answerVideo %s", callId);
Andrew Lee8da4c3c2014-07-16 10:11:42 -07001479 findConnectionForAction(callId, "answer").onAnswer(videoState);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001480 }
1481
Tyler Gunnbe74de02014-08-29 14:51:48 -07001482 private void answer(String callId) {
1483 Log.d(this, "answer %s", callId);
1484 findConnectionForAction(callId, "answer").onAnswer();
1485 }
1486
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001487 private void reject(String callId) {
Ihab Awad60ac30b2014-05-20 22:32:12 -07001488 Log.d(this, "reject %s", callId);
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001489 findConnectionForAction(callId, "reject").onReject();
Ihab Awad542e0ea2014-05-16 10:22:16 -07001490 }
1491
Bryce Lee81901682015-08-28 16:38:02 -07001492 private void reject(String callId, String rejectWithMessage) {
1493 Log.d(this, "reject %s with message", callId);
1494 findConnectionForAction(callId, "reject").onReject(rejectWithMessage);
1495 }
1496
Bryce Leecac50772015-11-17 15:13:29 -08001497 private void silence(String callId) {
1498 Log.d(this, "silence %s", callId);
1499 findConnectionForAction(callId, "silence").onSilence();
1500 }
1501
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001502 private void disconnect(String callId) {
Ihab Awad60ac30b2014-05-20 22:32:12 -07001503 Log.d(this, "disconnect %s", callId);
Santos Cordon0159ac02014-08-21 14:28:11 -07001504 if (mConnectionById.containsKey(callId)) {
1505 findConnectionForAction(callId, "disconnect").onDisconnect();
1506 } else {
1507 findConferenceForAction(callId, "disconnect").onDisconnect();
1508 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001509 }
1510
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001511 private void hold(String callId) {
Ihab Awad60ac30b2014-05-20 22:32:12 -07001512 Log.d(this, "hold %s", callId);
Santos Cordon0159ac02014-08-21 14:28:11 -07001513 if (mConnectionById.containsKey(callId)) {
1514 findConnectionForAction(callId, "hold").onHold();
1515 } else {
1516 findConferenceForAction(callId, "hold").onHold();
1517 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001518 }
1519
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001520 private void unhold(String callId) {
Ihab Awad60ac30b2014-05-20 22:32:12 -07001521 Log.d(this, "unhold %s", callId);
Santos Cordon0159ac02014-08-21 14:28:11 -07001522 if (mConnectionById.containsKey(callId)) {
1523 findConnectionForAction(callId, "unhold").onUnhold();
1524 } else {
1525 findConferenceForAction(callId, "unhold").onUnhold();
1526 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001527 }
1528
Yorke Lee4af59352015-05-13 14:14:54 -07001529 private void onCallAudioStateChanged(String callId, CallAudioState callAudioState) {
1530 Log.d(this, "onAudioStateChanged %s %s", callId, callAudioState);
Yorke Leea0d3ca92014-09-15 19:18:13 -07001531 if (mConnectionById.containsKey(callId)) {
Yorke Lee4af59352015-05-13 14:14:54 -07001532 findConnectionForAction(callId, "onCallAudioStateChanged").setCallAudioState(
1533 callAudioState);
Yorke Leea0d3ca92014-09-15 19:18:13 -07001534 } else {
Yorke Lee4af59352015-05-13 14:14:54 -07001535 findConferenceForAction(callId, "onCallAudioStateChanged").setCallAudioState(
1536 callAudioState);
Yorke Leea0d3ca92014-09-15 19:18:13 -07001537 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001538 }
1539
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001540 private void playDtmfTone(String callId, char digit) {
1541 Log.d(this, "playDtmfTone %s %c", callId, digit);
Yorke Leea0d3ca92014-09-15 19:18:13 -07001542 if (mConnectionById.containsKey(callId)) {
1543 findConnectionForAction(callId, "playDtmfTone").onPlayDtmfTone(digit);
1544 } else {
1545 findConferenceForAction(callId, "playDtmfTone").onPlayDtmfTone(digit);
1546 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001547 }
1548
1549 private void stopDtmfTone(String callId) {
1550 Log.d(this, "stopDtmfTone %s", callId);
Yorke Leea0d3ca92014-09-15 19:18:13 -07001551 if (mConnectionById.containsKey(callId)) {
1552 findConnectionForAction(callId, "stopDtmfTone").onStopDtmfTone();
1553 } else {
1554 findConferenceForAction(callId, "stopDtmfTone").onStopDtmfTone();
1555 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001556 }
1557
Santos Cordon823fd3c2014-08-07 18:35:18 -07001558 private void conference(String callId1, String callId2) {
1559 Log.d(this, "conference %s, %s", callId1, callId2);
Santos Cordon980acb92014-05-31 10:31:19 -07001560
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001561 // Attempt to get second connection or conference.
Santos Cordon823fd3c2014-08-07 18:35:18 -07001562 Connection connection2 = findConnectionForAction(callId2, "conference");
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001563 Conference conference2 = getNullConference();
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001564 if (connection2 == getNullConnection()) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001565 conference2 = findConferenceForAction(callId2, "conference");
1566 if (conference2 == getNullConference()) {
1567 Log.w(this, "Connection2 or Conference2 missing in conference request %s.",
1568 callId2);
1569 return;
1570 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07001571 }
Santos Cordonb6939982014-06-04 20:20:58 -07001572
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001573 // Attempt to get first connection or conference and perform merge.
Ihab Awad50e35062014-09-30 09:17:03 -07001574 Connection connection1 = findConnectionForAction(callId1, "conference");
1575 if (connection1 == getNullConnection()) {
1576 Conference conference1 = findConferenceForAction(callId1, "addConnection");
1577 if (conference1 == getNullConference()) {
1578 Log.w(this,
1579 "Connection1 or Conference1 missing in conference request %s.",
1580 callId1);
1581 } else {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001582 // Call 1 is a conference.
1583 if (connection2 != getNullConnection()) {
1584 // Call 2 is a connection so merge via call 1 (conference).
1585 conference1.onMerge(connection2);
1586 } else {
1587 // Call 2 is ALSO a conference; this should never happen.
1588 Log.wtf(this, "There can only be one conference and an attempt was made to " +
1589 "merge two conferences.");
1590 return;
1591 }
Ihab Awad50e35062014-09-30 09:17:03 -07001592 }
1593 } else {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001594 // Call 1 is a connection.
1595 if (conference2 != getNullConference()) {
1596 // Call 2 is a conference, so merge via call 2.
1597 conference2.onMerge(connection1);
1598 } else {
1599 // Call 2 is a connection, so merge together.
1600 onConference(connection1, connection2);
1601 }
Ihab Awad50e35062014-09-30 09:17:03 -07001602 }
Santos Cordon980acb92014-05-31 10:31:19 -07001603 }
1604
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001605 private void splitFromConference(String callId) {
Santos Cordonb6939982014-06-04 20:20:58 -07001606 Log.d(this, "splitFromConference(%s)", callId);
Santos Cordon980acb92014-05-31 10:31:19 -07001607
1608 Connection connection = findConnectionForAction(callId, "splitFromConference");
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001609 if (connection == getNullConnection()) {
Santos Cordon980acb92014-05-31 10:31:19 -07001610 Log.w(this, "Connection missing in conference request %s.", callId);
1611 return;
1612 }
1613
Santos Cordon0159ac02014-08-21 14:28:11 -07001614 Conference conference = connection.getConference();
1615 if (conference != null) {
1616 conference.onSeparate(connection);
1617 }
Santos Cordon980acb92014-05-31 10:31:19 -07001618 }
1619
Santos Cordona4868042014-09-04 17:39:22 -07001620 private void mergeConference(String callId) {
1621 Log.d(this, "mergeConference(%s)", callId);
1622 Conference conference = findConferenceForAction(callId, "mergeConference");
1623 if (conference != null) {
1624 conference.onMerge();
1625 }
1626 }
1627
1628 private void swapConference(String callId) {
1629 Log.d(this, "swapConference(%s)", callId);
1630 Conference conference = findConferenceForAction(callId, "swapConference");
1631 if (conference != null) {
1632 conference.onSwap();
1633 }
1634 }
1635
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001636 /**
1637 * Notifies a {@link Connection} of a request to pull an external call.
1638 *
1639 * See {@link Call#pullExternalCall()}.
1640 *
1641 * @param callId The ID of the call to pull.
1642 */
1643 private void pullExternalCall(String callId) {
1644 Log.d(this, "pullExternalCall(%s)", callId);
1645 Connection connection = findConnectionForAction(callId, "pullExternalCall");
1646 if (connection != null) {
1647 connection.onPullExternalCall();
1648 }
1649 }
1650
1651 /**
1652 * Notifies a {@link Connection} of a call event.
1653 *
1654 * See {@link Call#sendCallEvent(String, Bundle)}.
1655 *
1656 * @param callId The ID of the call receiving the event.
1657 * @param event The event.
1658 * @param extras Extras associated with the event.
1659 */
1660 private void sendCallEvent(String callId, String event, Bundle extras) {
1661 Log.d(this, "sendCallEvent(%s, %s)", callId, event);
1662 Connection connection = findConnectionForAction(callId, "sendCallEvent");
1663 if (connection != null) {
1664 connection.onCallEvent(event, extras);
1665 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001666 }
1667
Tyler Gunndee56a82016-03-23 16:06:34 -07001668 /**
1669 * Notifies a {@link Connection} or {@link Conference} of a change to the extras from Telecom.
1670 * <p>
1671 * These extra changes can originate from Telecom itself, or from an {@link InCallService} via
1672 * the {@link android.telecom.Call#putExtra(String, boolean)},
1673 * {@link android.telecom.Call#putExtra(String, int)},
1674 * {@link android.telecom.Call#putExtra(String, String)},
1675 * {@link Call#removeExtras(List)}.
1676 *
1677 * @param callId The ID of the call receiving the event.
1678 * @param extras The new extras bundle.
1679 */
1680 private void handleExtrasChanged(String callId, Bundle extras) {
1681 Log.d(this, "handleExtrasChanged(%s, %s)", callId, extras);
1682 if (mConnectionById.containsKey(callId)) {
1683 findConnectionForAction(callId, "handleExtrasChanged").handleExtrasChanged(extras);
1684 } else if (mConferenceById.containsKey(callId)) {
1685 findConferenceForAction(callId, "handleExtrasChanged").handleExtrasChanged(extras);
1686 }
1687 }
1688
Hall Liub64ac4c2017-02-06 10:49:48 -08001689 private void startRtt(String callId, Connection.RttTextStream rttTextStream) {
1690 Log.d(this, "startRtt(%s)", callId);
1691 if (mConnectionById.containsKey(callId)) {
1692 findConnectionForAction(callId, "startRtt").onStartRtt(rttTextStream);
1693 } else if (mConferenceById.containsKey(callId)) {
1694 Log.w(this, "startRtt called on a conference.");
1695 }
1696 }
1697
1698 private void stopRtt(String callId) {
1699 Log.d(this, "stopRtt(%s)", callId);
1700 if (mConnectionById.containsKey(callId)) {
1701 findConnectionForAction(callId, "stopRtt").onStopRtt();
Hall Liuffa4a812017-03-02 16:11:00 -08001702 findConnectionForAction(callId, "stopRtt").unsetRttProperty();
Hall Liub64ac4c2017-02-06 10:49:48 -08001703 } else if (mConferenceById.containsKey(callId)) {
1704 Log.w(this, "stopRtt called on a conference.");
1705 }
1706 }
1707
1708 private void handleRttUpgradeResponse(String callId, Connection.RttTextStream rttTextStream) {
1709 Log.d(this, "handleRttUpgradeResponse(%s, %s)", callId, rttTextStream == null);
1710 if (mConnectionById.containsKey(callId)) {
1711 findConnectionForAction(callId, "handleRttUpgradeResponse")
1712 .handleRttUpgradeResponse(rttTextStream);
1713 } else if (mConferenceById.containsKey(callId)) {
1714 Log.w(this, "handleRttUpgradeResponse called on a conference.");
1715 }
1716 }
1717
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001718 private void onPostDialContinue(String callId, boolean proceed) {
Evan Charlton6dea4ac2014-06-03 14:07:13 -07001719 Log.d(this, "onPostDialContinue(%s)", callId);
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001720 findConnectionForAction(callId, "stopDtmfTone").onPostDialContinue(proceed);
Evan Charlton6dea4ac2014-06-03 14:07:13 -07001721 }
1722
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001723 private void onAdapterAttached() {
Ihab Awad9c3f1882014-06-30 21:17:13 -07001724 if (mAreAccountsInitialized) {
Santos Cordon52d8a152014-06-17 19:08:45 -07001725 // No need to query again if we already did it.
1726 return;
1727 }
1728
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001729 mAdapter.queryRemoteConnectionServices(new RemoteServiceCallback.Stub() {
Santos Cordon52d8a152014-06-17 19:08:45 -07001730 @Override
1731 public void onResult(
1732 final List<ComponentName> componentNames,
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001733 final List<IBinder> services) {
Brad Ebinger0c3541b2016-11-01 14:11:38 -07001734 mHandler.post(new android.telecom.Logging.Runnable("oAA.qRCS.oR", null /*lock*/) {
Ihab Awad6107bab2014-08-18 09:23:25 -07001735 @Override
Brad Ebinger0c3541b2016-11-01 14:11:38 -07001736 public void loggedRun() {
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001737 for (int i = 0; i < componentNames.size() && i < services.size(); i++) {
Santos Cordon52d8a152014-06-17 19:08:45 -07001738 mRemoteConnectionManager.addConnectionService(
1739 componentNames.get(i),
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001740 IConnectionService.Stub.asInterface(services.get(i)));
Santos Cordon52d8a152014-06-17 19:08:45 -07001741 }
Ihab Awad5d0410f2014-07-30 10:07:40 -07001742 onAccountsInitialized();
Sailesh Nepalc5b01572014-07-14 16:29:44 -07001743 Log.d(this, "remote connection services found: " + services);
Santos Cordon52d8a152014-06-17 19:08:45 -07001744 }
Brad Ebinger0c3541b2016-11-01 14:11:38 -07001745 }.prepare());
Santos Cordon52d8a152014-06-17 19:08:45 -07001746 }
1747
1748 @Override
1749 public void onError() {
Brad Ebinger0c3541b2016-11-01 14:11:38 -07001750 mHandler.post(new android.telecom.Logging.Runnable("oAA.qRCS.oE", null /*lock*/) {
Ihab Awad6107bab2014-08-18 09:23:25 -07001751 @Override
Brad Ebinger0c3541b2016-11-01 14:11:38 -07001752 public void loggedRun() {
Ihab Awad9c3f1882014-06-30 21:17:13 -07001753 mAreAccountsInitialized = true;
Santos Cordon52d8a152014-06-17 19:08:45 -07001754 }
Brad Ebinger0c3541b2016-11-01 14:11:38 -07001755 }.prepare());
Santos Cordon52d8a152014-06-17 19:08:45 -07001756 }
1757 });
1758 }
1759
Ihab Awadf8b69882014-07-25 15:14:01 -07001760 /**
1761 * Ask some other {@code ConnectionService} to create a {@code RemoteConnection} given an
Santos Cordona663f862014-10-29 13:49:58 -07001762 * incoming request. This is used by {@code ConnectionService}s that are registered with
1763 * {@link PhoneAccount#CAPABILITY_CONNECTION_MANAGER} and want to be able to manage
1764 * SIM-based incoming calls.
Ihab Awadf8b69882014-07-25 15:14:01 -07001765 *
1766 * @param connectionManagerPhoneAccount See description at
1767 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
1768 * @param request Details about the incoming call.
1769 * @return The {@code Connection} object to satisfy this call, or {@code null} to
1770 * not handle the call.
1771 */
1772 public final RemoteConnection createRemoteIncomingConnection(
1773 PhoneAccountHandle connectionManagerPhoneAccount,
1774 ConnectionRequest request) {
1775 return mRemoteConnectionManager.createRemoteConnection(
1776 connectionManagerPhoneAccount, request, true);
Santos Cordon52d8a152014-06-17 19:08:45 -07001777 }
1778
1779 /**
Ihab Awadf8b69882014-07-25 15:14:01 -07001780 * Ask some other {@code ConnectionService} to create a {@code RemoteConnection} given an
Santos Cordona663f862014-10-29 13:49:58 -07001781 * outgoing request. This is used by {@code ConnectionService}s that are registered with
1782 * {@link PhoneAccount#CAPABILITY_CONNECTION_MANAGER} and want to be able to use the
1783 * SIM-based {@code ConnectionService} to place its outgoing calls.
Ihab Awadf8b69882014-07-25 15:14:01 -07001784 *
1785 * @param connectionManagerPhoneAccount See description at
1786 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
Cuihtlauac ALVARADO0b3b2a52016-09-13 14:49:41 +02001787 * @param request Details about the outgoing call.
Ihab Awadf8b69882014-07-25 15:14:01 -07001788 * @return The {@code Connection} object to satisfy this call, or {@code null} to
1789 * not handle the call.
1790 */
1791 public final RemoteConnection createRemoteOutgoingConnection(
1792 PhoneAccountHandle connectionManagerPhoneAccount,
1793 ConnectionRequest request) {
1794 return mRemoteConnectionManager.createRemoteConnection(
1795 connectionManagerPhoneAccount, request, false);
1796 }
1797
1798 /**
Santos Cordona663f862014-10-29 13:49:58 -07001799 * Indicates to the relevant {@code RemoteConnectionService} that the specified
1800 * {@link RemoteConnection}s should be merged into a conference call.
1801 * <p>
1802 * If the conference request is successful, the method {@link #onRemoteConferenceAdded} will
1803 * be invoked.
1804 *
1805 * @param remoteConnection1 The first of the remote connections to conference.
1806 * @param remoteConnection2 The second of the remote connections to conference.
Ihab Awadb8e85c72014-08-23 20:34:57 -07001807 */
1808 public final void conferenceRemoteConnections(
Santos Cordona663f862014-10-29 13:49:58 -07001809 RemoteConnection remoteConnection1,
1810 RemoteConnection remoteConnection2) {
1811 mRemoteConnectionManager.conferenceRemoteConnections(remoteConnection1, remoteConnection2);
Ihab Awadb8e85c72014-08-23 20:34:57 -07001812 }
1813
1814 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07001815 * Adds a new conference call. When a conference call is created either as a result of an
1816 * explicit request via {@link #onConference} or otherwise, the connection service should supply
1817 * an instance of {@link Conference} by invoking this method. A conference call provided by this
1818 * method will persist until {@link Conference#destroy} is invoked on the conference instance.
1819 *
1820 * @param conference The new conference object.
1821 */
1822 public final void addConference(Conference conference) {
Rekha Kumar07366812015-03-24 16:42:31 -07001823 Log.d(this, "addConference: conference=%s", conference);
1824
Santos Cordon823fd3c2014-08-07 18:35:18 -07001825 String id = addConferenceInternal(conference);
1826 if (id != null) {
1827 List<String> connectionIds = new ArrayList<>(2);
1828 for (Connection connection : conference.getConnections()) {
1829 if (mIdByConnection.containsKey(connection)) {
1830 connectionIds.add(mIdByConnection.get(connection));
1831 }
1832 }
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001833 conference.setTelecomCallId(id);
Santos Cordon823fd3c2014-08-07 18:35:18 -07001834 ParcelableConference parcelableConference = new ParcelableConference(
Nancy Chenea38cca2014-09-05 16:38:49 -07001835 conference.getPhoneAccountHandle(),
Santos Cordon823fd3c2014-08-07 18:35:18 -07001836 conference.getState(),
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001837 conference.getConnectionCapabilities(),
Tyler Gunn720c6642016-03-22 09:02:47 -07001838 conference.getConnectionProperties(),
Tyler Gunncd5d33c2015-01-12 09:02:01 -08001839 connectionIds,
Rekha Kumar07366812015-03-24 16:42:31 -07001840 conference.getVideoProvider() == null ?
1841 null : conference.getVideoProvider().getInterface(),
1842 conference.getVideoState(),
Andrew Lee3e3e2f22015-04-16 13:48:43 -07001843 conference.getConnectTimeMillis(),
Tyler Gunn3fa819c2017-08-04 09:27:26 -07001844 conference.getConnectElapsedTime(),
Santos Cordon6b7f9552015-05-27 17:21:45 -07001845 conference.getStatusHints(),
1846 conference.getExtras());
Andrew Lee0f51da32015-04-16 13:11:55 -07001847
Santos Cordon823fd3c2014-08-07 18:35:18 -07001848 mAdapter.addConferenceCall(id, parcelableConference);
Rekha Kumar07366812015-03-24 16:42:31 -07001849 mAdapter.setVideoProvider(id, conference.getVideoProvider());
1850 mAdapter.setVideoState(id, conference.getVideoState());
Santos Cordon823fd3c2014-08-07 18:35:18 -07001851
1852 // Go through any child calls and set the parent.
1853 for (Connection connection : conference.getConnections()) {
1854 String connectionId = mIdByConnection.get(connection);
1855 if (connectionId != null) {
1856 mAdapter.setIsConferenced(connectionId, id);
1857 }
1858 }
1859 }
1860 }
1861
1862 /**
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07001863 * Adds a connection created by the {@link ConnectionService} and informs telecom of the new
1864 * connection.
1865 *
1866 * @param phoneAccountHandle The phone account handle for the connection.
1867 * @param connection The connection to add.
1868 */
1869 public final void addExistingConnection(PhoneAccountHandle phoneAccountHandle,
1870 Connection connection) {
Tyler Gunn78da7812017-05-09 14:34:57 -07001871 addExistingConnection(phoneAccountHandle, connection, null /* conference */);
1872 }
1873
1874 /**
1875 * Adds a connection created by the {@link ConnectionService} and informs telecom of the new
1876 * connection.
1877 *
1878 * @param phoneAccountHandle The phone account handle for the connection.
1879 * @param connection The connection to add.
1880 * @param conference The parent conference of the new connection.
1881 * @hide
1882 */
1883 public final void addExistingConnection(PhoneAccountHandle phoneAccountHandle,
1884 Connection connection, Conference conference) {
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07001885
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001886 String id = addExistingConnectionInternal(phoneAccountHandle, connection);
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07001887 if (id != null) {
1888 List<String> emptyList = new ArrayList<>(0);
Tyler Gunn78da7812017-05-09 14:34:57 -07001889 String conferenceId = null;
1890 if (conference != null) {
1891 conferenceId = mIdByConference.get(conference);
1892 }
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07001893
1894 ParcelableConnection parcelableConnection = new ParcelableConnection(
1895 phoneAccountHandle,
1896 connection.getState(),
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001897 connection.getConnectionCapabilities(),
Tyler Gunn720c6642016-03-22 09:02:47 -07001898 connection.getConnectionProperties(),
Christine Hallstrom2830ce92016-11-30 16:06:42 -08001899 connection.getSupportedAudioRoutes(),
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07001900 connection.getAddress(),
1901 connection.getAddressPresentation(),
1902 connection.getCallerDisplayName(),
1903 connection.getCallerDisplayNamePresentation(),
1904 connection.getVideoProvider() == null ?
1905 null : connection.getVideoProvider().getInterface(),
1906 connection.getVideoState(),
1907 connection.isRingbackRequested(),
1908 connection.getAudioModeIsVoip(),
Roshan Piuse927ec02015-07-15 15:47:21 -07001909 connection.getConnectTimeMillis(),
Tyler Gunn3fa819c2017-08-04 09:27:26 -07001910 connection.getConnectElapsedTimeMillis(),
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07001911 connection.getStatusHints(),
1912 connection.getDisconnectCause(),
Santos Cordon6b7f9552015-05-27 17:21:45 -07001913 emptyList,
Tyler Gunn78da7812017-05-09 14:34:57 -07001914 connection.getExtras(),
1915 conferenceId);
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07001916 mAdapter.addExistingConnection(id, parcelableConnection);
1917 }
1918 }
1919
1920 /**
Ihab Awadf8b69882014-07-25 15:14:01 -07001921 * Returns all the active {@code Connection}s for which this {@code ConnectionService}
1922 * has taken responsibility.
1923 *
1924 * @return A collection of {@code Connection}s created by this {@code ConnectionService}.
Santos Cordonb6939982014-06-04 20:20:58 -07001925 */
Sailesh Nepal091768c2014-06-30 15:15:23 -07001926 public final Collection<Connection> getAllConnections() {
Santos Cordonb6939982014-06-04 20:20:58 -07001927 return mConnectionById.values();
1928 }
1929
1930 /**
Santos Cordona6018b92016-02-16 14:23:12 -08001931 * Returns all the active {@code Conference}s for which this {@code ConnectionService}
1932 * has taken responsibility.
1933 *
1934 * @return A collection of {@code Conference}s created by this {@code ConnectionService}.
1935 */
1936 public final Collection<Conference> getAllConferences() {
1937 return mConferenceById.values();
1938 }
1939
1940 /**
Ihab Awadf8b69882014-07-25 15:14:01 -07001941 * Create a {@code Connection} given an incoming request. This is used to attach to existing
1942 * incoming calls.
Evan Charltonbf11f982014-07-20 22:06:28 -07001943 *
Ihab Awadf8b69882014-07-25 15:14:01 -07001944 * @param connectionManagerPhoneAccount See description at
1945 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
1946 * @param request Details about the incoming call.
1947 * @return The {@code Connection} object to satisfy this call, or {@code null} to
1948 * not handle the call.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001949 */
Ihab Awadf8b69882014-07-25 15:14:01 -07001950 public Connection onCreateIncomingConnection(
1951 PhoneAccountHandle connectionManagerPhoneAccount,
1952 ConnectionRequest request) {
1953 return null;
1954 }
Sailesh Nepalc5b01572014-07-14 16:29:44 -07001955
1956 /**
Tyler Gunn041a1fe2017-05-12 10:04:49 -07001957 * Called after the {@link Connection} returned by
1958 * {@link #onCreateIncomingConnection(PhoneAccountHandle, ConnectionRequest)}
1959 * or {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)} has been
1960 * added to the {@link ConnectionService} and sent to Telecom.
1961 *
1962 * @param connection the {@link Connection}.
1963 * @hide
1964 */
1965 public void onCreateConnectionComplete(Connection connection) {
1966 }
1967
1968 /**
Tyler Gunnf5035432017-01-09 09:43:12 -08001969 * Called by Telecom to inform the {@link ConnectionService} that its request to create a new
1970 * incoming {@link Connection} was denied.
1971 * <p>
1972 * Used when a self-managed {@link ConnectionService} attempts to create a new incoming
1973 * {@link Connection}, but Telecom has determined that the call cannot be allowed at this time.
1974 * The {@link ConnectionService} is responsible for silently rejecting the new incoming
1975 * {@link Connection}.
1976 * <p>
1977 * See {@link TelecomManager#isIncomingCallPermitted(PhoneAccountHandle)} for more information.
1978 *
Tyler Gunn159f35c2017-03-02 09:28:37 -08001979 * @param connectionManagerPhoneAccount See description at
1980 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
Tyler Gunnf5035432017-01-09 09:43:12 -08001981 * @param request The incoming connection request.
1982 */
Tyler Gunn159f35c2017-03-02 09:28:37 -08001983 public void onCreateIncomingConnectionFailed(PhoneAccountHandle connectionManagerPhoneAccount,
1984 ConnectionRequest request) {
Tyler Gunnf5035432017-01-09 09:43:12 -08001985 }
1986
1987 /**
1988 * Called by Telecom to inform the {@link ConnectionService} that its request to create a new
1989 * outgoing {@link Connection} was denied.
1990 * <p>
1991 * Used when a self-managed {@link ConnectionService} attempts to create a new outgoing
1992 * {@link Connection}, but Telecom has determined that the call cannot be placed at this time.
1993 * The {@link ConnectionService} is responisible for informing the user that the
1994 * {@link Connection} cannot be made at this time.
1995 * <p>
1996 * See {@link TelecomManager#isOutgoingCallPermitted(PhoneAccountHandle)} for more information.
1997 *
Tyler Gunn159f35c2017-03-02 09:28:37 -08001998 * @param connectionManagerPhoneAccount See description at
1999 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
Tyler Gunnf5035432017-01-09 09:43:12 -08002000 * @param request The outgoing connection request.
2001 */
Tyler Gunn159f35c2017-03-02 09:28:37 -08002002 public void onCreateOutgoingConnectionFailed(PhoneAccountHandle connectionManagerPhoneAccount,
2003 ConnectionRequest request) {
Tyler Gunnf5035432017-01-09 09:43:12 -08002004 }
2005
2006 /**
Shriram Ganesh6bf35ac2014-12-11 17:53:38 -08002007 * Trigger recalculate functinality for conference calls. This is used when a Telephony
2008 * Connection is part of a conference controller but is not yet added to Connection
2009 * Service and hence cannot be added to the conference call.
2010 *
2011 * @hide
2012 */
2013 public void triggerConferenceRecalculate() {
2014 }
2015
2016 /**
Ihab Awadf8b69882014-07-25 15:14:01 -07002017 * Create a {@code Connection} given an outgoing request. This is used to initiate new
2018 * outgoing calls.
Sailesh Nepalc5b01572014-07-14 16:29:44 -07002019 *
Ihab Awadf8b69882014-07-25 15:14:01 -07002020 * @param connectionManagerPhoneAccount The connection manager account to use for managing
2021 * this call.
2022 * <p>
2023 * If this parameter is not {@code null}, it means that this {@code ConnectionService}
2024 * has registered one or more {@code PhoneAccount}s having
2025 * {@link PhoneAccount#CAPABILITY_CONNECTION_MANAGER}. This parameter will contain
2026 * one of these {@code PhoneAccount}s, while the {@code request} will contain another
2027 * (usually but not always distinct) {@code PhoneAccount} to be used for actually
2028 * making the connection.
2029 * <p>
2030 * If this parameter is {@code null}, it means that this {@code ConnectionService} is
2031 * being asked to make a direct connection. The
2032 * {@link ConnectionRequest#getAccountHandle()} of parameter {@code request} will be
2033 * a {@code PhoneAccount} registered by this {@code ConnectionService} to use for
2034 * making the connection.
2035 * @param request Details about the outgoing call.
2036 * @return The {@code Connection} object to satisfy this call, or the result of an invocation
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002037 * of {@link Connection#createFailedConnection(DisconnectCause)} to not handle the call.
Sailesh Nepalc5b01572014-07-14 16:29:44 -07002038 */
Ihab Awadf8b69882014-07-25 15:14:01 -07002039 public Connection onCreateOutgoingConnection(
2040 PhoneAccountHandle connectionManagerPhoneAccount,
2041 ConnectionRequest request) {
2042 return null;
2043 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002044
2045 /**
Sanket Padawea8eddd42017-11-03 11:07:35 -07002046 * Called by Telecom on the initiating side of the handover to create an instance of a
2047 * handover connection.
2048 * @param fromPhoneAccountHandle {@link PhoneAccountHandle} associated with the
2049 * ConnectionService which needs to handover the call.
2050 * @param request Details about the call which needs to be handover.
2051 * @return Connection object corresponding to the handover call.
2052 */
2053 public Connection onCreateOutgoingHandoverConnection(PhoneAccountHandle fromPhoneAccountHandle,
2054 ConnectionRequest request) {
2055 return null;
2056 }
2057
2058 /**
2059 * Called by Telecom on the receiving side of the handover to request the
2060 * {@link ConnectionService} to create an instance of a handover connection.
2061 * @param fromPhoneAccountHandle {@link PhoneAccountHandle} associated with the
2062 * ConnectionService which needs to handover the call.
2063 * @param request Details about the call which needs to be handover.
2064 * @return {@link Connection} object corresponding to the handover call.
2065 */
2066 public Connection onCreateIncomingHandoverConnection(PhoneAccountHandle fromPhoneAccountHandle,
2067 ConnectionRequest request) {
2068 return null;
2069 }
2070
2071 /**
2072 * Called by Telecom in response to a {@code TelecomManager#acceptHandover()}
2073 * invocation which failed.
2074 * @param request Details about the call which needs to be handover.
2075 * @param error Reason for handover failure as defined in
2076 * {@link android.telecom.Call.Callback#HANDOVER_FAILURE_DEST_INVALID_PERM}
2077 */
2078 public void onHandoverFailed(ConnectionRequest request, int error) {
2079 return;
2080 }
2081
2082 /**
Yorke Leec3cf9822014-10-02 09:38:39 -07002083 * Create a {@code Connection} for a new unknown call. An unknown call is a call originating
2084 * from the ConnectionService that was neither a user-initiated outgoing call, nor an incoming
2085 * call created using
2086 * {@code TelecomManager#addNewIncomingCall(PhoneAccountHandle, android.os.Bundle)}.
2087 *
Yorke Lee770ed6e2014-10-06 18:58:52 -07002088 * @hide
Yorke Leec3cf9822014-10-02 09:38:39 -07002089 */
2090 public Connection onCreateUnknownConnection(PhoneAccountHandle connectionManagerPhoneAccount,
2091 ConnectionRequest request) {
Brad Ebingerb32d4f82016-10-24 16:40:49 -07002092 return null;
Yorke Leec3cf9822014-10-02 09:38:39 -07002093 }
2094
2095 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07002096 * Conference two specified connections. Invoked when the user has made a request to merge the
2097 * specified connections into a conference call. In response, the connection service should
2098 * create an instance of {@link Conference} and pass it into {@link #addConference}.
Santos Cordonb6939982014-06-04 20:20:58 -07002099 *
Santos Cordon823fd3c2014-08-07 18:35:18 -07002100 * @param connection1 A connection to merge into a conference call.
2101 * @param connection2 A connection to merge into a conference call.
Santos Cordonb6939982014-06-04 20:20:58 -07002102 */
Santos Cordon823fd3c2014-08-07 18:35:18 -07002103 public void onConference(Connection connection1, Connection connection2) {}
Santos Cordonb6939982014-06-04 20:20:58 -07002104
Santos Cordona663f862014-10-29 13:49:58 -07002105 /**
2106 * Indicates that a remote conference has been created for existing {@link RemoteConnection}s.
2107 * When this method is invoked, this {@link ConnectionService} should create its own
2108 * representation of the conference call and send it to telecom using {@link #addConference}.
2109 * <p>
2110 * This is only relevant to {@link ConnectionService}s which are registered with
2111 * {@link PhoneAccount#CAPABILITY_CONNECTION_MANAGER}.
2112 *
2113 * @param conference The remote conference call.
2114 */
Ihab Awadb8e85c72014-08-23 20:34:57 -07002115 public void onRemoteConferenceAdded(RemoteConference conference) {}
2116
Santos Cordon823fd3c2014-08-07 18:35:18 -07002117 /**
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002118 * Called when an existing connection is added remotely.
2119 * @param connection The existing connection which was added.
2120 */
2121 public void onRemoteExistingConnectionAdded(RemoteConnection connection) {}
2122
2123 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07002124 * @hide
2125 */
2126 public boolean containsConference(Conference conference) {
2127 return mIdByConference.containsKey(conference);
2128 }
2129
Ihab Awadb8e85c72014-08-23 20:34:57 -07002130 /** {@hide} */
2131 void addRemoteConference(RemoteConference remoteConference) {
2132 onRemoteConferenceAdded(remoteConference);
2133 }
2134
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002135 /** {@hide} */
2136 void addRemoteExistingConnection(RemoteConnection remoteConnection) {
2137 onRemoteExistingConnectionAdded(remoteConnection);
2138 }
2139
Ihab Awad5d0410f2014-07-30 10:07:40 -07002140 private void onAccountsInitialized() {
2141 mAreAccountsInitialized = true;
2142 for (Runnable r : mPreInitializationConnectionRequests) {
2143 r.run();
2144 }
2145 mPreInitializationConnectionRequests.clear();
2146 }
2147
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002148 /**
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002149 * Adds an existing connection to the list of connections, identified by a new call ID unique
2150 * to this connection service.
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002151 *
2152 * @param connection The connection.
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002153 * @return The ID of the connection (e.g. the call-id).
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002154 */
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002155 private String addExistingConnectionInternal(PhoneAccountHandle handle, Connection connection) {
2156 String id;
Tyler Gunncd6ccfd2016-10-17 15:48:19 -07002157
2158 if (connection.getExtras() != null && connection.getExtras()
2159 .containsKey(Connection.EXTRA_ORIGINAL_CONNECTION_ID)) {
2160 id = connection.getExtras().getString(Connection.EXTRA_ORIGINAL_CONNECTION_ID);
2161 Log.d(this, "addExistingConnectionInternal - conn %s reusing original id %s",
2162 connection.getTelecomCallId(), id);
2163 } else if (handle == null) {
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002164 // If no phone account handle was provided, we cannot be sure the call ID is unique,
2165 // so just use a random UUID.
2166 id = UUID.randomUUID().toString();
2167 } else {
2168 // Phone account handle was provided, so use the ConnectionService class name as a
2169 // prefix for a unique incremental call ID.
2170 id = handle.getComponentName().getClassName() + "@" + getNextCallId();
2171 }
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002172 addConnection(id, connection);
2173 return id;
2174 }
2175
Ihab Awad542e0ea2014-05-16 10:22:16 -07002176 private void addConnection(String callId, Connection connection) {
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002177 connection.setTelecomCallId(callId);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002178 mConnectionById.put(callId, connection);
2179 mIdByConnection.put(connection, callId);
2180 connection.addConnectionListener(mConnectionListener);
Santos Cordon823fd3c2014-08-07 18:35:18 -07002181 connection.setConnectionService(this);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002182 }
2183
Anthony Lee30e65842014-11-06 16:30:53 -08002184 /** {@hide} */
2185 protected void removeConnection(Connection connection) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07002186 connection.unsetConnectionService(this);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002187 connection.removeConnectionListener(mConnectionListener);
Chenjie Luoe370b532016-05-12 16:59:43 -07002188 String id = mIdByConnection.get(connection);
2189 if (id != null) {
2190 mConnectionById.remove(id);
2191 mIdByConnection.remove(connection);
2192 mAdapter.removeCall(id);
2193 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002194 }
2195
Santos Cordon823fd3c2014-08-07 18:35:18 -07002196 private String addConferenceInternal(Conference conference) {
Tyler Gunncd6ccfd2016-10-17 15:48:19 -07002197 String originalId = null;
2198 if (conference.getExtras() != null && conference.getExtras()
2199 .containsKey(Connection.EXTRA_ORIGINAL_CONNECTION_ID)) {
2200 originalId = conference.getExtras().getString(Connection.EXTRA_ORIGINAL_CONNECTION_ID);
2201 Log.d(this, "addConferenceInternal: conf %s reusing original id %s",
2202 conference.getTelecomCallId(),
2203 originalId);
2204 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07002205 if (mIdByConference.containsKey(conference)) {
2206 Log.w(this, "Re-adding an existing conference: %s.", conference);
2207 } else if (conference != null) {
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002208 // Conferences do not (yet) have a PhoneAccountHandle associated with them, so we
2209 // cannot determine a ConnectionService class name to associate with the ID, so use
2210 // a unique UUID (for now).
Tyler Gunncd6ccfd2016-10-17 15:48:19 -07002211 String id = originalId == null ? UUID.randomUUID().toString() : originalId;
Santos Cordon823fd3c2014-08-07 18:35:18 -07002212 mConferenceById.put(id, conference);
2213 mIdByConference.put(conference, id);
2214 conference.addListener(mConferenceListener);
2215 return id;
2216 }
2217
2218 return null;
2219 }
2220
2221 private void removeConference(Conference conference) {
2222 if (mIdByConference.containsKey(conference)) {
2223 conference.removeListener(mConferenceListener);
2224
2225 String id = mIdByConference.get(conference);
2226 mConferenceById.remove(id);
2227 mIdByConference.remove(conference);
2228 mAdapter.removeCall(id);
2229 }
2230 }
2231
Ihab Awad542e0ea2014-05-16 10:22:16 -07002232 private Connection findConnectionForAction(String callId, String action) {
Tyler Gunn0a88f2e2017-06-16 20:20:34 -07002233 if (callId != null && mConnectionById.containsKey(callId)) {
Ihab Awad542e0ea2014-05-16 10:22:16 -07002234 return mConnectionById.get(callId);
2235 }
Ihab Awad60ac30b2014-05-20 22:32:12 -07002236 Log.w(this, "%s - Cannot find Connection %s", action, callId);
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07002237 return getNullConnection();
2238 }
2239
2240 static synchronized Connection getNullConnection() {
2241 if (sNullConnection == null) {
2242 sNullConnection = new Connection() {};
2243 }
2244 return sNullConnection;
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002245 }
Santos Cordon0159ac02014-08-21 14:28:11 -07002246
2247 private Conference findConferenceForAction(String conferenceId, String action) {
2248 if (mConferenceById.containsKey(conferenceId)) {
2249 return mConferenceById.get(conferenceId);
2250 }
2251 Log.w(this, "%s - Cannot find conference %s", action, conferenceId);
2252 return getNullConference();
2253 }
2254
Ihab Awadb8e85c72014-08-23 20:34:57 -07002255 private List<String> createConnectionIdList(List<Connection> connections) {
2256 List<String> ids = new ArrayList<>();
2257 for (Connection c : connections) {
2258 if (mIdByConnection.containsKey(c)) {
2259 ids.add(mIdByConnection.get(c));
2260 }
2261 }
2262 Collections.sort(ids);
2263 return ids;
2264 }
2265
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002266 /**
2267 * Builds a list of {@link Connection} and {@link Conference} IDs based on the list of
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002268 * {@link Conferenceable}s passed in.
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002269 *
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002270 * @param conferenceables The {@link Conferenceable} connections and conferences.
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002271 * @return List of string conference and call Ids.
2272 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002273 private List<String> createIdList(List<Conferenceable> conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002274 List<String> ids = new ArrayList<>();
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002275 for (Conferenceable c : conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002276 // Only allow Connection and Conference conferenceables.
2277 if (c instanceof Connection) {
2278 Connection connection = (Connection) c;
2279 if (mIdByConnection.containsKey(connection)) {
2280 ids.add(mIdByConnection.get(connection));
2281 }
2282 } else if (c instanceof Conference) {
2283 Conference conference = (Conference) c;
2284 if (mIdByConference.containsKey(conference)) {
2285 ids.add(mIdByConference.get(conference));
2286 }
2287 }
2288 }
2289 Collections.sort(ids);
2290 return ids;
2291 }
2292
Santos Cordon0159ac02014-08-21 14:28:11 -07002293 private Conference getNullConference() {
2294 if (sNullConference == null) {
2295 sNullConference = new Conference(null) {};
2296 }
2297 return sNullConference;
2298 }
Santos Cordon29f2f2e2014-09-11 19:50:24 -07002299
2300 private void endAllConnections() {
2301 // Unbound from telecomm. We should end all connections and conferences.
2302 for (Connection connection : mIdByConnection.keySet()) {
2303 // only operate on top-level calls. Conference calls will be removed on their own.
2304 if (connection.getConference() == null) {
2305 connection.onDisconnect();
2306 }
2307 }
2308 for (Conference conference : mIdByConference.keySet()) {
2309 conference.onDisconnect();
2310 }
2311 }
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002312
2313 /**
2314 * Retrieves the next call ID as maintainted by the connection service.
2315 *
2316 * @return The call ID.
2317 */
2318 private int getNextCallId() {
Brad Ebingerb32d4f82016-10-24 16:40:49 -07002319 synchronized (mIdSyncRoot) {
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002320 return ++mId;
2321 }
2322 }
Santos Cordon980acb92014-05-31 10:31:19 -07002323}