blob: 9bc77b81e3aa6f834ad1279db5bb00e326070913 [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
Ihab Awad542e0ea2014-05-16 10:22:16 -070095 // Flag controlling whether PII is emitted into the logs
Ihab Awad60ac30b2014-05-20 22:32:12 -070096 private static final boolean PII_DEBUG = Log.isLoggable(android.util.Log.DEBUG);
Ihab Awad542e0ea2014-05-16 10:22:16 -070097
Brad Ebingerb32d4f82016-10-24 16:40:49 -070098 // Session Definitions
99 private static final String SESSION_HANDLER = "H.";
100 private static final String SESSION_ADD_CS_ADAPTER = "CS.aCSA";
101 private static final String SESSION_REMOVE_CS_ADAPTER = "CS.rCSA";
102 private static final String SESSION_CREATE_CONN = "CS.crCo";
Tyler Gunn44e01912017-01-31 10:49:05 -0800103 private static final String SESSION_CREATE_CONN_FAILED = "CS.crCoF";
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700104 private static final String SESSION_ABORT = "CS.ab";
105 private static final String SESSION_ANSWER = "CS.an";
106 private static final String SESSION_ANSWER_VIDEO = "CS.anV";
107 private static final String SESSION_REJECT = "CS.r";
108 private static final String SESSION_REJECT_MESSAGE = "CS.rWM";
109 private static final String SESSION_SILENCE = "CS.s";
110 private static final String SESSION_DISCONNECT = "CS.d";
111 private static final String SESSION_HOLD = "CS.h";
112 private static final String SESSION_UNHOLD = "CS.u";
113 private static final String SESSION_CALL_AUDIO_SC = "CS.cASC";
114 private static final String SESSION_PLAY_DTMF = "CS.pDT";
115 private static final String SESSION_STOP_DTMF = "CS.sDT";
116 private static final String SESSION_CONFERENCE = "CS.c";
117 private static final String SESSION_SPLIT_CONFERENCE = "CS.sFC";
118 private static final String SESSION_MERGE_CONFERENCE = "CS.mC";
119 private static final String SESSION_SWAP_CONFERENCE = "CS.sC";
120 private static final String SESSION_POST_DIAL_CONT = "CS.oPDC";
121 private static final String SESSION_PULL_EXTERNAL_CALL = "CS.pEC";
122 private static final String SESSION_SEND_CALL_EVENT = "CS.sCE";
123 private static final String SESSION_EXTRAS_CHANGED = "CS.oEC";
Hall Liub64ac4c2017-02-06 10:49:48 -0800124 private static final String SESSION_START_RTT = "CS.+RTT";
125 private static final String SESSION_STOP_RTT = "CS.-RTT";
126 private static final String SESSION_RTT_UPGRADE_RESPONSE = "CS.rTRUR";
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700127
Ihab Awad8aecfed2014-08-08 17:06:11 -0700128 private static final int MSG_ADD_CONNECTION_SERVICE_ADAPTER = 1;
Sailesh Nepalc5b01572014-07-14 16:29:44 -0700129 private static final int MSG_CREATE_CONNECTION = 2;
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700130 private static final int MSG_ABORT = 3;
Sailesh Nepalc5b01572014-07-14 16:29:44 -0700131 private static final int MSG_ANSWER = 4;
132 private static final int MSG_REJECT = 5;
133 private static final int MSG_DISCONNECT = 6;
134 private static final int MSG_HOLD = 7;
135 private static final int MSG_UNHOLD = 8;
Yorke Lee4af59352015-05-13 14:14:54 -0700136 private static final int MSG_ON_CALL_AUDIO_STATE_CHANGED = 9;
Sailesh Nepalc5b01572014-07-14 16:29:44 -0700137 private static final int MSG_PLAY_DTMF_TONE = 10;
138 private static final int MSG_STOP_DTMF_TONE = 11;
139 private static final int MSG_CONFERENCE = 12;
140 private static final int MSG_SPLIT_FROM_CONFERENCE = 13;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700141 private static final int MSG_ON_POST_DIAL_CONTINUE = 14;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700142 private static final int MSG_REMOVE_CONNECTION_SERVICE_ADAPTER = 16;
Tyler Gunnbe74de02014-08-29 14:51:48 -0700143 private static final int MSG_ANSWER_VIDEO = 17;
Santos Cordona4868042014-09-04 17:39:22 -0700144 private static final int MSG_MERGE_CONFERENCE = 18;
145 private static final int MSG_SWAP_CONFERENCE = 19;
Bryce Lee81901682015-08-28 16:38:02 -0700146 private static final int MSG_REJECT_WITH_MESSAGE = 20;
Bryce Leecac50772015-11-17 15:13:29 -0800147 private static final int MSG_SILENCE = 21;
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700148 private static final int MSG_PULL_EXTERNAL_CALL = 22;
149 private static final int MSG_SEND_CALL_EVENT = 23;
Tyler Gunndee56a82016-03-23 16:06:34 -0700150 private static final int MSG_ON_EXTRAS_CHANGED = 24;
Tyler Gunn44e01912017-01-31 10:49:05 -0800151 private static final int MSG_CREATE_CONNECTION_FAILED = 25;
Hall Liub64ac4c2017-02-06 10:49:48 -0800152 private static final int MSG_ON_START_RTT = 26;
153 private static final int MSG_ON_STOP_RTT = 27;
154 private static final int MSG_RTT_UPGRADE_RESPONSE = 28;
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700155
Sailesh Nepalcf7020b2014-08-20 10:07:19 -0700156 private static Connection sNullConnection;
157
mike dooley95e80702014-09-18 14:07:52 -0700158 private final Map<String, Connection> mConnectionById = new ConcurrentHashMap<>();
159 private final Map<Connection, String> mIdByConnection = new ConcurrentHashMap<>();
160 private final Map<String, Conference> mConferenceById = new ConcurrentHashMap<>();
161 private final Map<Conference, String> mIdByConference = new ConcurrentHashMap<>();
Ihab Awadb8e85c72014-08-23 20:34:57 -0700162 private final RemoteConnectionManager mRemoteConnectionManager =
163 new RemoteConnectionManager(this);
Ihab Awad5d0410f2014-07-30 10:07:40 -0700164 private final List<Runnable> mPreInitializationConnectionRequests = new ArrayList<>();
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700165 private final ConnectionServiceAdapter mAdapter = new ConnectionServiceAdapter();
Ihab Awad542e0ea2014-05-16 10:22:16 -0700166
Santos Cordon823fd3c2014-08-07 18:35:18 -0700167 private boolean mAreAccountsInitialized = false;
Santos Cordon0159ac02014-08-21 14:28:11 -0700168 private Conference sNullConference;
Tyler Gunnf0500bd2015-09-01 10:59:48 -0700169 private Object mIdSyncRoot = new Object();
170 private int mId = 0;
Santos Cordon823fd3c2014-08-07 18:35:18 -0700171
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700172 private final IBinder mBinder = new IConnectionService.Stub() {
173 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700174 public void addConnectionServiceAdapter(IConnectionServiceAdapter adapter,
175 Session.Info sessionInfo) {
176 Log.startSession(sessionInfo, SESSION_ADD_CS_ADAPTER);
177 try {
178 SomeArgs args = SomeArgs.obtain();
179 args.arg1 = adapter;
180 args.arg2 = Log.createSubsession();
181 mHandler.obtainMessage(MSG_ADD_CONNECTION_SERVICE_ADAPTER, args).sendToTarget();
182 } finally {
183 Log.endSession();
184 }
Ihab Awad8aecfed2014-08-08 17:06:11 -0700185 }
186
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700187 public void removeConnectionServiceAdapter(IConnectionServiceAdapter adapter,
188 Session.Info sessionInfo) {
189 Log.startSession(sessionInfo, SESSION_REMOVE_CS_ADAPTER);
190 try {
191 SomeArgs args = SomeArgs.obtain();
192 args.arg1 = adapter;
193 args.arg2 = Log.createSubsession();
194 mHandler.obtainMessage(MSG_REMOVE_CONNECTION_SERVICE_ADAPTER, args).sendToTarget();
195 } finally {
196 Log.endSession();
197 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700198 }
199
200 @Override
Ihab Awadf8b69882014-07-25 15:14:01 -0700201 public void createConnection(
202 PhoneAccountHandle connectionManagerPhoneAccount,
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700203 String id,
Ihab Awadf8b69882014-07-25 15:14:01 -0700204 ConnectionRequest request,
Yorke Leec3cf9822014-10-02 09:38:39 -0700205 boolean isIncoming,
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700206 boolean isUnknown,
207 Session.Info sessionInfo) {
208 Log.startSession(sessionInfo, SESSION_CREATE_CONN);
209 try {
210 SomeArgs args = SomeArgs.obtain();
211 args.arg1 = connectionManagerPhoneAccount;
212 args.arg2 = id;
213 args.arg3 = request;
214 args.arg4 = Log.createSubsession();
215 args.argi1 = isIncoming ? 1 : 0;
216 args.argi2 = isUnknown ? 1 : 0;
217 mHandler.obtainMessage(MSG_CREATE_CONNECTION, args).sendToTarget();
218 } finally {
219 Log.endSession();
220 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700221 }
222
223 @Override
Tyler Gunn44e01912017-01-31 10:49:05 -0800224 public void createConnectionFailed(
225 String callId,
226 ConnectionRequest request,
227 boolean isIncoming,
228 Session.Info sessionInfo) {
229 Log.startSession(sessionInfo, SESSION_CREATE_CONN_FAILED);
230 try {
231 SomeArgs args = SomeArgs.obtain();
232 args.arg1 = callId;
233 args.arg2 = request;
234 args.arg3 = Log.createSubsession();
235 args.argi1 = isIncoming ? 1 : 0;
236 mHandler.obtainMessage(MSG_CREATE_CONNECTION_FAILED, args).sendToTarget();
237 } finally {
238 Log.endSession();
239 }
240 }
241
242 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700243 public void abort(String callId, Session.Info sessionInfo) {
244 Log.startSession(sessionInfo, SESSION_ABORT);
245 try {
246 SomeArgs args = SomeArgs.obtain();
247 args.arg1 = callId;
248 args.arg2 = Log.createSubsession();
249 mHandler.obtainMessage(MSG_ABORT, args).sendToTarget();
250 } finally {
251 Log.endSession();
252 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700253 }
254
255 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700256 public void answerVideo(String callId, int videoState, Session.Info sessionInfo) {
257 Log.startSession(sessionInfo, SESSION_ANSWER_VIDEO);
258 try {
259 SomeArgs args = SomeArgs.obtain();
260 args.arg1 = callId;
261 args.arg2 = Log.createSubsession();
262 args.argi1 = videoState;
263 mHandler.obtainMessage(MSG_ANSWER_VIDEO, args).sendToTarget();
264 } finally {
265 Log.endSession();
266 }
Tyler Gunnbe74de02014-08-29 14:51:48 -0700267 }
268
269 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700270 public void answer(String callId, Session.Info sessionInfo) {
271 Log.startSession(sessionInfo, SESSION_ANSWER);
272 try {
273 SomeArgs args = SomeArgs.obtain();
274 args.arg1 = callId;
275 args.arg2 = Log.createSubsession();
276 mHandler.obtainMessage(MSG_ANSWER, args).sendToTarget();
277 } finally {
278 Log.endSession();
279 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700280 }
281
282 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700283 public void reject(String callId, Session.Info sessionInfo) {
284 Log.startSession(sessionInfo, SESSION_REJECT);
285 try {
286 SomeArgs args = SomeArgs.obtain();
287 args.arg1 = callId;
288 args.arg2 = Log.createSubsession();
289 mHandler.obtainMessage(MSG_REJECT, args).sendToTarget();
290 } finally {
291 Log.endSession();
292 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700293 }
294
295 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700296 public void rejectWithMessage(String callId, String message, Session.Info sessionInfo) {
297 Log.startSession(sessionInfo, SESSION_REJECT_MESSAGE);
298 try {
299 SomeArgs args = SomeArgs.obtain();
300 args.arg1 = callId;
301 args.arg2 = message;
302 args.arg3 = Log.createSubsession();
303 mHandler.obtainMessage(MSG_REJECT_WITH_MESSAGE, args).sendToTarget();
304 } finally {
305 Log.endSession();
306 }
Bryce Lee81901682015-08-28 16:38:02 -0700307 }
308
309 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700310 public void silence(String callId, Session.Info sessionInfo) {
311 Log.startSession(sessionInfo, SESSION_SILENCE);
312 try {
313 SomeArgs args = SomeArgs.obtain();
314 args.arg1 = callId;
315 args.arg2 = Log.createSubsession();
316 mHandler.obtainMessage(MSG_SILENCE, args).sendToTarget();
317 } finally {
318 Log.endSession();
319 }
Bryce Leecac50772015-11-17 15:13:29 -0800320 }
321
322 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700323 public void disconnect(String callId, Session.Info sessionInfo) {
324 Log.startSession(sessionInfo, SESSION_DISCONNECT);
325 try {
326 SomeArgs args = SomeArgs.obtain();
327 args.arg1 = callId;
328 args.arg2 = Log.createSubsession();
329 mHandler.obtainMessage(MSG_DISCONNECT, args).sendToTarget();
330 } finally {
331 Log.endSession();
332 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700333 }
334
335 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700336 public void hold(String callId, Session.Info sessionInfo) {
337 Log.startSession(sessionInfo, SESSION_HOLD);
338 try {
339 SomeArgs args = SomeArgs.obtain();
340 args.arg1 = callId;
341 args.arg2 = Log.createSubsession();
342 mHandler.obtainMessage(MSG_HOLD, args).sendToTarget();
343 } finally {
344 Log.endSession();
345 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700346 }
347
348 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700349 public void unhold(String callId, Session.Info sessionInfo) {
350 Log.startSession(sessionInfo, SESSION_UNHOLD);
351 try {
352 SomeArgs args = SomeArgs.obtain();
353 args.arg1 = callId;
354 args.arg2 = Log.createSubsession();
355 mHandler.obtainMessage(MSG_UNHOLD, args).sendToTarget();
356 } finally {
357 Log.endSession();
358 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700359 }
360
361 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700362 public void onCallAudioStateChanged(String callId, CallAudioState callAudioState,
363 Session.Info sessionInfo) {
364 Log.startSession(sessionInfo, SESSION_CALL_AUDIO_SC);
365 try {
366 SomeArgs args = SomeArgs.obtain();
367 args.arg1 = callId;
368 args.arg2 = callAudioState;
369 args.arg3 = Log.createSubsession();
370 mHandler.obtainMessage(MSG_ON_CALL_AUDIO_STATE_CHANGED, args).sendToTarget();
371 } finally {
372 Log.endSession();
373 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700374 }
375
376 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700377 public void playDtmfTone(String callId, char digit, Session.Info sessionInfo) {
378 Log.startSession(sessionInfo, SESSION_PLAY_DTMF);
379 try {
380 SomeArgs args = SomeArgs.obtain();
381 args.arg1 = digit;
382 args.arg2 = callId;
383 args.arg3 = Log.createSubsession();
384 mHandler.obtainMessage(MSG_PLAY_DTMF_TONE, args).sendToTarget();
385 } finally {
386 Log.endSession();
387 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700388 }
389
390 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700391 public void stopDtmfTone(String callId, Session.Info sessionInfo) {
392 Log.startSession(sessionInfo, SESSION_STOP_DTMF);
393 try {
394 SomeArgs args = SomeArgs.obtain();
395 args.arg1 = callId;
396 args.arg2 = Log.createSubsession();
397 mHandler.obtainMessage(MSG_STOP_DTMF_TONE, args).sendToTarget();
398 } finally {
399 Log.endSession();
400 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700401 }
402
403 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700404 public void conference(String callId1, String callId2, Session.Info sessionInfo) {
405 Log.startSession(sessionInfo, SESSION_CONFERENCE);
406 try {
407 SomeArgs args = SomeArgs.obtain();
408 args.arg1 = callId1;
409 args.arg2 = callId2;
410 args.arg3 = Log.createSubsession();
411 mHandler.obtainMessage(MSG_CONFERENCE, args).sendToTarget();
412 } finally {
413 Log.endSession();
414 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700415 }
416
417 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700418 public void splitFromConference(String callId, Session.Info sessionInfo) {
419 Log.startSession(sessionInfo, SESSION_SPLIT_CONFERENCE);
420 try {
421 SomeArgs args = SomeArgs.obtain();
422 args.arg1 = callId;
423 args.arg2 = Log.createSubsession();
424 mHandler.obtainMessage(MSG_SPLIT_FROM_CONFERENCE, args).sendToTarget();
425 } finally {
426 Log.endSession();
427 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700428 }
429
430 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700431 public void mergeConference(String callId, Session.Info sessionInfo) {
432 Log.startSession(sessionInfo, SESSION_MERGE_CONFERENCE);
433 try {
434 SomeArgs args = SomeArgs.obtain();
435 args.arg1 = callId;
436 args.arg2 = Log.createSubsession();
437 mHandler.obtainMessage(MSG_MERGE_CONFERENCE, args).sendToTarget();
438 } finally {
439 Log.endSession();
440 }
Santos Cordona4868042014-09-04 17:39:22 -0700441 }
442
443 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700444 public void swapConference(String callId, Session.Info sessionInfo) {
445 Log.startSession(sessionInfo, SESSION_SWAP_CONFERENCE);
446 try {
447 SomeArgs args = SomeArgs.obtain();
448 args.arg1 = callId;
449 args.arg2 = Log.createSubsession();
450 mHandler.obtainMessage(MSG_SWAP_CONFERENCE, args).sendToTarget();
451 } finally {
452 Log.endSession();
453 }
Santos Cordona4868042014-09-04 17:39:22 -0700454 }
455
456 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700457 public void onPostDialContinue(String callId, boolean proceed, Session.Info sessionInfo) {
458 Log.startSession(sessionInfo, SESSION_POST_DIAL_CONT);
459 try {
460 SomeArgs args = SomeArgs.obtain();
461 args.arg1 = callId;
462 args.arg2 = Log.createSubsession();
463 args.argi1 = proceed ? 1 : 0;
464 mHandler.obtainMessage(MSG_ON_POST_DIAL_CONTINUE, args).sendToTarget();
465 } finally {
466 Log.endSession();
467 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700468 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700469
470 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700471 public void pullExternalCall(String callId, Session.Info sessionInfo) {
472 Log.startSession(sessionInfo, SESSION_PULL_EXTERNAL_CALL);
473 try {
474 SomeArgs args = SomeArgs.obtain();
475 args.arg1 = callId;
476 args.arg2 = Log.createSubsession();
477 mHandler.obtainMessage(MSG_PULL_EXTERNAL_CALL, args).sendToTarget();
478 } finally {
479 Log.endSession();
480 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700481 }
482
483 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700484 public void sendCallEvent(String callId, String event, Bundle extras,
485 Session.Info sessionInfo) {
486 Log.startSession(sessionInfo, SESSION_SEND_CALL_EVENT);
487 try {
488 SomeArgs args = SomeArgs.obtain();
489 args.arg1 = callId;
490 args.arg2 = event;
491 args.arg3 = extras;
492 args.arg4 = Log.createSubsession();
493 mHandler.obtainMessage(MSG_SEND_CALL_EVENT, args).sendToTarget();
494 } finally {
495 Log.endSession();
496 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700497 }
Tyler Gunndee56a82016-03-23 16:06:34 -0700498
499 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700500 public void onExtrasChanged(String callId, Bundle extras, Session.Info sessionInfo) {
501 Log.startSession(sessionInfo, SESSION_EXTRAS_CHANGED);
502 try {
503 SomeArgs args = SomeArgs.obtain();
504 args.arg1 = callId;
505 args.arg2 = extras;
506 args.arg3 = Log.createSubsession();
507 mHandler.obtainMessage(MSG_ON_EXTRAS_CHANGED, args).sendToTarget();
508 } finally {
509 Log.endSession();
510 }
Tyler Gunndee56a82016-03-23 16:06:34 -0700511 }
Hall Liub64ac4c2017-02-06 10:49:48 -0800512
513 @Override
514 public void startRtt(String callId, ParcelFileDescriptor fromInCall,
515 ParcelFileDescriptor toInCall, Session.Info sessionInfo) throws RemoteException {
516 Log.startSession(sessionInfo, SESSION_START_RTT);
517 try {
518 SomeArgs args = SomeArgs.obtain();
519 args.arg1 = callId;
520 args.arg2 = new Connection.RttTextStream(toInCall, fromInCall);
521 args.arg3 = Log.createSubsession();
522 mHandler.obtainMessage(MSG_ON_START_RTT, args).sendToTarget();
523 } finally {
524 Log.endSession();
525 }
526 }
527
528 @Override
529 public void stopRtt(String callId, Session.Info sessionInfo) throws RemoteException {
530 Log.startSession(sessionInfo, SESSION_STOP_RTT);
531 try {
532 SomeArgs args = SomeArgs.obtain();
533 args.arg1 = callId;
534 args.arg2 = Log.createSubsession();
535 mHandler.obtainMessage(MSG_ON_STOP_RTT, args).sendToTarget();
536 } finally {
537 Log.endSession();
538 }
539 }
540
541 @Override
542 public void respondToRttUpgradeRequest(String callId, ParcelFileDescriptor fromInCall,
543 ParcelFileDescriptor toInCall, Session.Info sessionInfo) throws RemoteException {
544 Log.startSession(sessionInfo, SESSION_RTT_UPGRADE_RESPONSE);
545 try {
546 SomeArgs args = SomeArgs.obtain();
547 args.arg1 = callId;
548 if (toInCall == null || fromInCall == null) {
549 args.arg2 = null;
550 } else {
551 args.arg2 = new Connection.RttTextStream(toInCall, fromInCall);
552 }
553 args.arg3 = Log.createSubsession();
554 mHandler.obtainMessage(MSG_RTT_UPGRADE_RESPONSE, args).sendToTarget();
555 } finally {
556 Log.endSession();
557 }
558 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700559 };
560
561 private final Handler mHandler = new Handler(Looper.getMainLooper()) {
562 @Override
563 public void handleMessage(Message msg) {
564 switch (msg.what) {
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700565 case MSG_ADD_CONNECTION_SERVICE_ADAPTER: {
566 SomeArgs args = (SomeArgs) msg.obj;
567 try {
568 IConnectionServiceAdapter adapter = (IConnectionServiceAdapter) args.arg1;
569 Log.continueSession((Session) args.arg2,
570 SESSION_HANDLER + SESSION_ADD_CS_ADAPTER);
571 mAdapter.addAdapter(adapter);
572 onAdapterAttached();
573 } finally {
574 args.recycle();
575 Log.endSession();
576 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700577 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700578 }
579 case MSG_REMOVE_CONNECTION_SERVICE_ADAPTER: {
580 SomeArgs args = (SomeArgs) msg.obj;
581 try {
582 Log.continueSession((Session) args.arg2,
583 SESSION_HANDLER + SESSION_REMOVE_CS_ADAPTER);
584 mAdapter.removeAdapter((IConnectionServiceAdapter) args.arg1);
585 } finally {
586 args.recycle();
587 Log.endSession();
588 }
Ihab Awad8aecfed2014-08-08 17:06:11 -0700589 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700590 }
Ihab Awadf8b69882014-07-25 15:14:01 -0700591 case MSG_CREATE_CONNECTION: {
592 SomeArgs args = (SomeArgs) msg.obj;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700593 Log.continueSession((Session) args.arg4, SESSION_HANDLER + SESSION_CREATE_CONN);
Ihab Awadf8b69882014-07-25 15:14:01 -0700594 try {
Ihab Awad5d0410f2014-07-30 10:07:40 -0700595 final PhoneAccountHandle connectionManagerPhoneAccount =
Ihab Awadf8b69882014-07-25 15:14:01 -0700596 (PhoneAccountHandle) args.arg1;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700597 final String id = (String) args.arg2;
598 final ConnectionRequest request = (ConnectionRequest) args.arg3;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700599 final boolean isIncoming = args.argi1 == 1;
Yorke Leec3cf9822014-10-02 09:38:39 -0700600 final boolean isUnknown = args.argi2 == 1;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700601 if (!mAreAccountsInitialized) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700602 Log.d(this, "Enqueueing pre-init request %s", id);
Brad Ebinger0c3541b2016-11-01 14:11:38 -0700603 mPreInitializationConnectionRequests.add(
604 new android.telecom.Logging.Runnable(
605 SESSION_HANDLER + SESSION_CREATE_CONN + ".pICR",
606 null /*lock*/) {
Ihab Awad5d0410f2014-07-30 10:07:40 -0700607 @Override
Brad Ebinger0c3541b2016-11-01 14:11:38 -0700608 public void loggedRun() {
Ihab Awad5d0410f2014-07-30 10:07:40 -0700609 createConnection(
610 connectionManagerPhoneAccount,
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700611 id,
Ihab Awad5d0410f2014-07-30 10:07:40 -0700612 request,
Yorke Leec3cf9822014-10-02 09:38:39 -0700613 isIncoming,
614 isUnknown);
Ihab Awad5d0410f2014-07-30 10:07:40 -0700615 }
Brad Ebinger0c3541b2016-11-01 14:11:38 -0700616 }.prepare());
Ihab Awad5d0410f2014-07-30 10:07:40 -0700617 } else {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700618 createConnection(
619 connectionManagerPhoneAccount,
620 id,
621 request,
Yorke Leec3cf9822014-10-02 09:38:39 -0700622 isIncoming,
623 isUnknown);
Ihab Awad5d0410f2014-07-30 10:07:40 -0700624 }
Ihab Awadf8b69882014-07-25 15:14:01 -0700625 } finally {
626 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700627 Log.endSession();
Ihab Awadf8b69882014-07-25 15:14:01 -0700628 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700629 break;
Ihab Awadf8b69882014-07-25 15:14:01 -0700630 }
Tyler Gunn44e01912017-01-31 10:49:05 -0800631 case MSG_CREATE_CONNECTION_FAILED: {
632 SomeArgs args = (SomeArgs) msg.obj;
633 Log.continueSession((Session) args.arg3, SESSION_HANDLER +
634 SESSION_CREATE_CONN_FAILED);
635 try {
636 final String id = (String) args.arg1;
637 final ConnectionRequest request = (ConnectionRequest) args.arg2;
638 final boolean isIncoming = args.argi1 == 1;
639 if (!mAreAccountsInitialized) {
640 Log.d(this, "Enqueueing pre-init request %s", id);
641 mPreInitializationConnectionRequests.add(
642 new android.telecom.Logging.Runnable(
643 SESSION_HANDLER + SESSION_CREATE_CONN_FAILED + ".pICR",
644 null /*lock*/) {
645 @Override
646 public void loggedRun() {
647 createConnectionFailed(id, request, isIncoming);
648 }
649 }.prepare());
650 } else {
651 Log.i(this, "createConnectionFailed %s", id);
652 createConnectionFailed(id, request, isIncoming);
653 }
654 } finally {
655 args.recycle();
656 Log.endSession();
657 }
658 break;
659 }
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700660 case MSG_ABORT: {
661 SomeArgs args = (SomeArgs) msg.obj;
662 Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_ABORT);
663 try {
664 abort((String) args.arg1);
665 } finally {
666 args.recycle();
667 Log.endSession();
668 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700669 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700670 }
671 case MSG_ANSWER: {
672 SomeArgs args = (SomeArgs) msg.obj;
673 Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_ANSWER);
674 try {
675 answer((String) args.arg1);
676 } finally {
677 args.recycle();
678 Log.endSession();
679 }
Tyler Gunnbe74de02014-08-29 14:51:48 -0700680 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700681 }
Tyler Gunnbe74de02014-08-29 14:51:48 -0700682 case MSG_ANSWER_VIDEO: {
Andrew Lee8da4c3c2014-07-16 10:11:42 -0700683 SomeArgs args = (SomeArgs) msg.obj;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700684 Log.continueSession((Session) args.arg2,
685 SESSION_HANDLER + SESSION_ANSWER_VIDEO);
Andrew Lee8da4c3c2014-07-16 10:11:42 -0700686 try {
687 String callId = (String) args.arg1;
Evan Charltonbf11f982014-07-20 22:06:28 -0700688 int videoState = args.argi1;
Tyler Gunnbe74de02014-08-29 14:51:48 -0700689 answerVideo(callId, videoState);
Andrew Lee8da4c3c2014-07-16 10:11:42 -0700690 } finally {
691 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700692 Log.endSession();
Andrew Lee8da4c3c2014-07-16 10:11:42 -0700693 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700694 break;
Andrew Lee8da4c3c2014-07-16 10:11:42 -0700695 }
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700696 case MSG_REJECT: {
697 SomeArgs args = (SomeArgs) msg.obj;
698 Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_REJECT);
699 try {
700 reject((String) args.arg1);
701 } finally {
702 args.recycle();
703 Log.endSession();
704 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700705 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700706 }
Bryce Lee81901682015-08-28 16:38:02 -0700707 case MSG_REJECT_WITH_MESSAGE: {
708 SomeArgs args = (SomeArgs) msg.obj;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700709 Log.continueSession((Session) args.arg3,
710 SESSION_HANDLER + SESSION_REJECT_MESSAGE);
Bryce Lee81901682015-08-28 16:38:02 -0700711 try {
712 reject((String) args.arg1, (String) args.arg2);
713 } finally {
714 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700715 Log.endSession();
Bryce Lee81901682015-08-28 16:38:02 -0700716 }
717 break;
718 }
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700719 case MSG_DISCONNECT: {
720 SomeArgs args = (SomeArgs) msg.obj;
721 Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_DISCONNECT);
722 try {
723 disconnect((String) args.arg1);
724 } finally {
725 args.recycle();
726 Log.endSession();
727 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700728 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700729 }
730 case MSG_SILENCE: {
731 SomeArgs args = (SomeArgs) msg.obj;
732 Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_SILENCE);
733 try {
734 silence((String) args.arg1);
735 } finally {
736 args.recycle();
737 Log.endSession();
738 }
Bryce Leecac50772015-11-17 15:13:29 -0800739 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700740 }
741 case MSG_HOLD: {
742 SomeArgs args = (SomeArgs) msg.obj;
743 Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_REJECT);
744 try {
745 hold((String) args.arg1);
746 } finally {
747 args.recycle();
748 Log.endSession();
749 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700750 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700751 }
752 case MSG_UNHOLD: {
753 SomeArgs args = (SomeArgs) msg.obj;
754 Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_UNHOLD);
755 try {
756 unhold((String) args.arg1);
757 } finally {
758 args.recycle();
759 Log.endSession();
760 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700761 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700762 }
Yorke Lee4af59352015-05-13 14:14:54 -0700763 case MSG_ON_CALL_AUDIO_STATE_CHANGED: {
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700764 SomeArgs args = (SomeArgs) msg.obj;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700765 Log.continueSession((Session) args.arg3,
766 SESSION_HANDLER + SESSION_CALL_AUDIO_SC);
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700767 try {
768 String callId = (String) args.arg1;
Yorke Lee4af59352015-05-13 14:14:54 -0700769 CallAudioState audioState = (CallAudioState) args.arg2;
770 onCallAudioStateChanged(callId, new CallAudioState(audioState));
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700771 } finally {
772 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700773 Log.endSession();
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700774 }
775 break;
776 }
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700777 case MSG_PLAY_DTMF_TONE: {
778 SomeArgs args = (SomeArgs) msg.obj;
779 try {
780 Log.continueSession((Session) args.arg3,
781 SESSION_HANDLER + SESSION_PLAY_DTMF);
782 playDtmfTone((String) args.arg2, (char) args.arg1);
783 } finally {
784 args.recycle();
785 Log.endSession();
786 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700787 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700788 }
789 case MSG_STOP_DTMF_TONE: {
790 SomeArgs args = (SomeArgs) msg.obj;
791 try {
792 Log.continueSession((Session) args.arg2,
793 SESSION_HANDLER + SESSION_STOP_DTMF);
794 stopDtmfTone((String) args.arg1);
795 } finally {
796 args.recycle();
797 Log.endSession();
798 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700799 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700800 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700801 case MSG_CONFERENCE: {
802 SomeArgs args = (SomeArgs) msg.obj;
803 try {
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700804 Log.continueSession((Session) args.arg3,
805 SESSION_HANDLER + SESSION_CONFERENCE);
Santos Cordon823fd3c2014-08-07 18:35:18 -0700806 String callId1 = (String) args.arg1;
807 String callId2 = (String) args.arg2;
808 conference(callId1, callId2);
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700809 } finally {
810 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700811 Log.endSession();
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700812 }
813 break;
814 }
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700815 case MSG_SPLIT_FROM_CONFERENCE: {
816 SomeArgs args = (SomeArgs) msg.obj;
817 try {
818 Log.continueSession((Session) args.arg2,
819 SESSION_HANDLER + SESSION_SPLIT_CONFERENCE);
820 splitFromConference((String) args.arg1);
821 } finally {
822 args.recycle();
823 Log.endSession();
824 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700825 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700826 }
827 case MSG_MERGE_CONFERENCE: {
828 SomeArgs args = (SomeArgs) msg.obj;
829 try {
830 Log.continueSession((Session) args.arg2,
831 SESSION_HANDLER + SESSION_MERGE_CONFERENCE);
832 mergeConference((String) args.arg1);
833 } finally {
834 args.recycle();
835 Log.endSession();
836 }
Santos Cordona4868042014-09-04 17:39:22 -0700837 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700838 }
839 case MSG_SWAP_CONFERENCE: {
840 SomeArgs args = (SomeArgs) msg.obj;
841 try {
842 Log.continueSession((Session) args.arg2,
843 SESSION_HANDLER + SESSION_SWAP_CONFERENCE);
844 swapConference((String) args.arg1);
845 } finally {
846 args.recycle();
847 Log.endSession();
848 }
Santos Cordona4868042014-09-04 17:39:22 -0700849 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700850 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700851 case MSG_ON_POST_DIAL_CONTINUE: {
852 SomeArgs args = (SomeArgs) msg.obj;
853 try {
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700854 Log.continueSession((Session) args.arg2,
855 SESSION_HANDLER + SESSION_POST_DIAL_CONT);
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700856 String callId = (String) args.arg1;
857 boolean proceed = (args.argi1 == 1);
858 onPostDialContinue(callId, proceed);
859 } finally {
860 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700861 Log.endSession();
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700862 }
863 break;
864 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700865 case MSG_PULL_EXTERNAL_CALL: {
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700866 SomeArgs args = (SomeArgs) msg.obj;
867 try {
868 Log.continueSession((Session) args.arg2,
869 SESSION_HANDLER + SESSION_PULL_EXTERNAL_CALL);
870 pullExternalCall((String) args.arg1);
871 } finally {
872 args.recycle();
873 Log.endSession();
874 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700875 break;
876 }
877 case MSG_SEND_CALL_EVENT: {
878 SomeArgs args = (SomeArgs) msg.obj;
879 try {
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700880 Log.continueSession((Session) args.arg4,
881 SESSION_HANDLER + SESSION_SEND_CALL_EVENT);
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700882 String callId = (String) args.arg1;
883 String event = (String) args.arg2;
884 Bundle extras = (Bundle) args.arg3;
885 sendCallEvent(callId, event, extras);
886 } finally {
887 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700888 Log.endSession();
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700889 }
890 break;
891 }
Tyler Gunndee56a82016-03-23 16:06:34 -0700892 case MSG_ON_EXTRAS_CHANGED: {
893 SomeArgs args = (SomeArgs) msg.obj;
894 try {
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700895 Log.continueSession((Session) args.arg3,
896 SESSION_HANDLER + SESSION_EXTRAS_CHANGED);
Tyler Gunndee56a82016-03-23 16:06:34 -0700897 String callId = (String) args.arg1;
898 Bundle extras = (Bundle) args.arg2;
899 handleExtrasChanged(callId, extras);
900 } finally {
901 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700902 Log.endSession();
Tyler Gunndee56a82016-03-23 16:06:34 -0700903 }
904 break;
905 }
Hall Liub64ac4c2017-02-06 10:49:48 -0800906 case MSG_ON_START_RTT: {
907 SomeArgs args = (SomeArgs) msg.obj;
908 try {
909 Log.continueSession((Session) args.arg3,
910 SESSION_HANDLER + SESSION_START_RTT);
911 String callId = (String) args.arg1;
912 Connection.RttTextStream rttTextStream =
913 (Connection.RttTextStream) args.arg2;
914 startRtt(callId, rttTextStream);
915 } finally {
916 args.recycle();
917 Log.endSession();
918 }
919 break;
920 }
921 case MSG_ON_STOP_RTT: {
922 SomeArgs args = (SomeArgs) msg.obj;
923 try {
924 Log.continueSession((Session) args.arg2,
925 SESSION_HANDLER + SESSION_STOP_RTT);
926 String callId = (String) args.arg1;
927 stopRtt(callId);
928 } finally {
929 args.recycle();
930 Log.endSession();
931 }
932 break;
933 }
934 case MSG_RTT_UPGRADE_RESPONSE: {
935 SomeArgs args = (SomeArgs) msg.obj;
936 try {
937 Log.continueSession((Session) args.arg3,
938 SESSION_HANDLER + SESSION_RTT_UPGRADE_RESPONSE);
939 String callId = (String) args.arg1;
940 Connection.RttTextStream rttTextStream =
941 (Connection.RttTextStream) args.arg2;
942 handleRttUpgradeResponse(callId, rttTextStream);
943 } finally {
944 args.recycle();
945 Log.endSession();
946 }
947 break;
948 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700949 default:
950 break;
951 }
952 }
953 };
954
Santos Cordon823fd3c2014-08-07 18:35:18 -0700955 private final Conference.Listener mConferenceListener = new Conference.Listener() {
956 @Override
957 public void onStateChanged(Conference conference, int oldState, int newState) {
958 String id = mIdByConference.get(conference);
959 switch (newState) {
960 case Connection.STATE_ACTIVE:
961 mAdapter.setActive(id);
962 break;
963 case Connection.STATE_HOLDING:
964 mAdapter.setOnHold(id);
965 break;
966 case Connection.STATE_DISCONNECTED:
967 // handled by onDisconnected
968 break;
969 }
970 }
971
972 @Override
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700973 public void onDisconnected(Conference conference, DisconnectCause disconnectCause) {
Santos Cordon823fd3c2014-08-07 18:35:18 -0700974 String id = mIdByConference.get(conference);
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700975 mAdapter.setDisconnected(id, disconnectCause);
Santos Cordon823fd3c2014-08-07 18:35:18 -0700976 }
977
978 @Override
979 public void onConnectionAdded(Conference conference, Connection connection) {
980 }
981
982 @Override
983 public void onConnectionRemoved(Conference conference, Connection connection) {
984 }
985
986 @Override
Ihab Awad50e35062014-09-30 09:17:03 -0700987 public void onConferenceableConnectionsChanged(
988 Conference conference, List<Connection> conferenceableConnections) {
989 mAdapter.setConferenceableConnections(
990 mIdByConference.get(conference),
991 createConnectionIdList(conferenceableConnections));
992 }
993
994 @Override
Santos Cordon823fd3c2014-08-07 18:35:18 -0700995 public void onDestroyed(Conference conference) {
996 removeConference(conference);
997 }
998
999 @Override
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001000 public void onConnectionCapabilitiesChanged(
1001 Conference conference,
1002 int connectionCapabilities) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07001003 String id = mIdByConference.get(conference);
1004 Log.d(this, "call capabilities: conference: %s",
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001005 Connection.capabilitiesToString(connectionCapabilities));
1006 mAdapter.setConnectionCapabilities(id, connectionCapabilities);
Santos Cordon823fd3c2014-08-07 18:35:18 -07001007 }
Rekha Kumar07366812015-03-24 16:42:31 -07001008
1009 @Override
Tyler Gunn720c6642016-03-22 09:02:47 -07001010 public void onConnectionPropertiesChanged(
1011 Conference conference,
1012 int connectionProperties) {
1013 String id = mIdByConference.get(conference);
1014 Log.d(this, "call capabilities: conference: %s",
1015 Connection.propertiesToString(connectionProperties));
1016 mAdapter.setConnectionProperties(id, connectionProperties);
1017 }
1018
1019 @Override
Rekha Kumar07366812015-03-24 16:42:31 -07001020 public void onVideoStateChanged(Conference c, int videoState) {
1021 String id = mIdByConference.get(c);
1022 Log.d(this, "onVideoStateChanged set video state %d", videoState);
1023 mAdapter.setVideoState(id, videoState);
1024 }
1025
1026 @Override
1027 public void onVideoProviderChanged(Conference c, Connection.VideoProvider videoProvider) {
1028 String id = mIdByConference.get(c);
1029 Log.d(this, "onVideoProviderChanged: Connection: %s, VideoProvider: %s", c,
1030 videoProvider);
1031 mAdapter.setVideoProvider(id, videoProvider);
1032 }
Andrew Lee0f51da32015-04-16 13:11:55 -07001033
1034 @Override
Andrew Leeedc625f2015-04-14 13:38:12 -07001035 public void onStatusHintsChanged(Conference conference, StatusHints statusHints) {
1036 String id = mIdByConference.get(conference);
Tyler Gunndee56a82016-03-23 16:06:34 -07001037 if (id != null) {
1038 mAdapter.setStatusHints(id, statusHints);
1039 }
Andrew Leeedc625f2015-04-14 13:38:12 -07001040 }
Santos Cordon6b7f9552015-05-27 17:21:45 -07001041
1042 @Override
Tyler Gunndee56a82016-03-23 16:06:34 -07001043 public void onExtrasChanged(Conference c, Bundle extras) {
1044 String id = mIdByConference.get(c);
1045 if (id != null) {
1046 mAdapter.putExtras(id, extras);
1047 }
1048 }
1049
1050 @Override
1051 public void onExtrasRemoved(Conference c, List<String> keys) {
1052 String id = mIdByConference.get(c);
1053 if (id != null) {
1054 mAdapter.removeExtras(id, keys);
1055 }
Santos Cordon6b7f9552015-05-27 17:21:45 -07001056 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07001057 };
1058
Ihab Awad542e0ea2014-05-16 10:22:16 -07001059 private final Connection.Listener mConnectionListener = new Connection.Listener() {
1060 @Override
1061 public void onStateChanged(Connection c, int state) {
1062 String id = mIdByConnection.get(c);
Ihab Awad42b30e12014-05-22 09:49:34 -07001063 Log.d(this, "Adapter set state %s %s", id, Connection.stateToString(state));
Ihab Awad542e0ea2014-05-16 10:22:16 -07001064 switch (state) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001065 case Connection.STATE_ACTIVE:
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001066 mAdapter.setActive(id);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001067 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001068 case Connection.STATE_DIALING:
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001069 mAdapter.setDialing(id);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001070 break;
Tyler Gunnc96b5e02016-07-07 22:53:57 -07001071 case Connection.STATE_PULLING_CALL:
1072 mAdapter.setPulling(id);
1073 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001074 case Connection.STATE_DISCONNECTED:
Ihab Awad542e0ea2014-05-16 10:22:16 -07001075 // Handled in onDisconnected()
1076 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001077 case Connection.STATE_HOLDING:
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001078 mAdapter.setOnHold(id);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001079 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001080 case Connection.STATE_NEW:
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001081 // Nothing to tell Telecom
Ihab Awad542e0ea2014-05-16 10:22:16 -07001082 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001083 case Connection.STATE_RINGING:
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001084 mAdapter.setRinging(id);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001085 break;
1086 }
1087 }
1088
1089 @Override
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001090 public void onDisconnected(Connection c, DisconnectCause disconnectCause) {
Ihab Awad542e0ea2014-05-16 10:22:16 -07001091 String id = mIdByConnection.get(c);
Andrew Lee26786392014-09-16 18:14:59 -07001092 Log.d(this, "Adapter set disconnected %s", disconnectCause);
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001093 mAdapter.setDisconnected(id, disconnectCause);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001094 }
1095
1096 @Override
Tyler Gunnaa07df82014-07-17 07:50:22 -07001097 public void onVideoStateChanged(Connection c, int videoState) {
1098 String id = mIdByConnection.get(c);
1099 Log.d(this, "Adapter set video state %d", videoState);
1100 mAdapter.setVideoState(id, videoState);
1101 }
1102
1103 @Override
Andrew Lee100e2932014-09-08 15:34:24 -07001104 public void onAddressChanged(Connection c, Uri address, int presentation) {
Sailesh Nepal61203862014-07-11 14:50:13 -07001105 String id = mIdByConnection.get(c);
Andrew Lee100e2932014-09-08 15:34:24 -07001106 mAdapter.setAddress(id, address, presentation);
Sailesh Nepal61203862014-07-11 14:50:13 -07001107 }
1108
1109 @Override
1110 public void onCallerDisplayNameChanged(
1111 Connection c, String callerDisplayName, int presentation) {
1112 String id = mIdByConnection.get(c);
1113 mAdapter.setCallerDisplayName(id, callerDisplayName, presentation);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001114 }
1115
1116 @Override
Ihab Awad542e0ea2014-05-16 10:22:16 -07001117 public void onDestroyed(Connection c) {
1118 removeConnection(c);
1119 }
Ihab Awadf8358972014-05-28 16:46:42 -07001120
1121 @Override
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001122 public void onPostDialWait(Connection c, String remaining) {
Sailesh Nepal091768c2014-06-30 15:15:23 -07001123 String id = mIdByConnection.get(c);
1124 Log.d(this, "Adapter onPostDialWait %s, %s", c, remaining);
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001125 mAdapter.onPostDialWait(id, remaining);
Sailesh Nepal091768c2014-06-30 15:15:23 -07001126 }
1127
1128 @Override
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001129 public void onPostDialChar(Connection c, char nextChar) {
1130 String id = mIdByConnection.get(c);
1131 Log.d(this, "Adapter onPostDialChar %s, %s", c, nextChar);
1132 mAdapter.onPostDialChar(id, nextChar);
1133 }
1134
1135 @Override
Andrew Lee100e2932014-09-08 15:34:24 -07001136 public void onRingbackRequested(Connection c, boolean ringback) {
Ihab Awadf8358972014-05-28 16:46:42 -07001137 String id = mIdByConnection.get(c);
1138 Log.d(this, "Adapter onRingback %b", ringback);
Andrew Lee100e2932014-09-08 15:34:24 -07001139 mAdapter.setRingbackRequested(id, ringback);
Ihab Awadf8358972014-05-28 16:46:42 -07001140 }
Santos Cordonb6939982014-06-04 20:20:58 -07001141
1142 @Override
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001143 public void onConnectionCapabilitiesChanged(Connection c, int capabilities) {
Santos Cordonb6939982014-06-04 20:20:58 -07001144 String id = mIdByConnection.get(c);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001145 Log.d(this, "capabilities: parcelableconnection: %s",
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001146 Connection.capabilitiesToString(capabilities));
1147 mAdapter.setConnectionCapabilities(id, capabilities);
Santos Cordonb6939982014-06-04 20:20:58 -07001148 }
1149
Santos Cordonb6939982014-06-04 20:20:58 -07001150 @Override
Tyler Gunn720c6642016-03-22 09:02:47 -07001151 public void onConnectionPropertiesChanged(Connection c, int properties) {
1152 String id = mIdByConnection.get(c);
1153 Log.d(this, "properties: parcelableconnection: %s",
1154 Connection.propertiesToString(properties));
1155 mAdapter.setConnectionProperties(id, properties);
1156 }
1157
1158 @Override
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001159 public void onVideoProviderChanged(Connection c, Connection.VideoProvider videoProvider) {
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07001160 String id = mIdByConnection.get(c);
Rekha Kumar07366812015-03-24 16:42:31 -07001161 Log.d(this, "onVideoProviderChanged: Connection: %s, VideoProvider: %s", c,
1162 videoProvider);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001163 mAdapter.setVideoProvider(id, videoProvider);
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07001164 }
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001165
1166 @Override
Sailesh Nepal001bbbb2014-07-15 14:40:39 -07001167 public void onAudioModeIsVoipChanged(Connection c, boolean isVoip) {
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001168 String id = mIdByConnection.get(c);
Andrew Lee100e2932014-09-08 15:34:24 -07001169 mAdapter.setIsVoipAudioMode(id, isVoip);
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001170 }
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001171
1172 @Override
Sailesh Nepal001bbbb2014-07-15 14:40:39 -07001173 public void onStatusHintsChanged(Connection c, StatusHints statusHints) {
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001174 String id = mIdByConnection.get(c);
1175 mAdapter.setStatusHints(id, statusHints);
1176 }
Sailesh Nepal2ab88cc2014-07-18 14:49:18 -07001177
1178 @Override
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001179 public void onConferenceablesChanged(
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001180 Connection connection, List<Conferenceable> conferenceables) {
Ihab Awadb8e85c72014-08-23 20:34:57 -07001181 mAdapter.setConferenceableConnections(
1182 mIdByConnection.get(connection),
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001183 createIdList(conferenceables));
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001184 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07001185
1186 @Override
1187 public void onConferenceChanged(Connection connection, Conference conference) {
1188 String id = mIdByConnection.get(connection);
1189 if (id != null) {
1190 String conferenceId = null;
1191 if (conference != null) {
1192 conferenceId = mIdByConference.get(conference);
1193 }
1194 mAdapter.setIsConferenced(id, conferenceId);
1195 }
1196 }
Anthony Lee17455a32015-04-24 15:25:29 -07001197
1198 @Override
1199 public void onConferenceMergeFailed(Connection connection) {
1200 String id = mIdByConnection.get(connection);
1201 if (id != null) {
1202 mAdapter.onConferenceMergeFailed(id);
1203 }
1204 }
Santos Cordon6b7f9552015-05-27 17:21:45 -07001205
1206 @Override
Tyler Gunndee56a82016-03-23 16:06:34 -07001207 public void onExtrasChanged(Connection c, Bundle extras) {
1208 String id = mIdByConnection.get(c);
Santos Cordon6b7f9552015-05-27 17:21:45 -07001209 if (id != null) {
Tyler Gunndee56a82016-03-23 16:06:34 -07001210 mAdapter.putExtras(id, extras);
Santos Cordon6b7f9552015-05-27 17:21:45 -07001211 }
1212 }
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001213
Tyler Gunnf5035432017-01-09 09:43:12 -08001214 @Override
Tyler Gunndee56a82016-03-23 16:06:34 -07001215 public void onExtrasRemoved(Connection c, List<String> keys) {
1216 String id = mIdByConnection.get(c);
1217 if (id != null) {
1218 mAdapter.removeExtras(id, keys);
1219 }
1220 }
1221
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08001222 @Override
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001223 public void onConnectionEvent(Connection connection, String event, Bundle extras) {
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08001224 String id = mIdByConnection.get(connection);
1225 if (id != null) {
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001226 mAdapter.onConnectionEvent(id, event, extras);
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08001227 }
1228 }
Tyler Gunnf5035432017-01-09 09:43:12 -08001229
1230 @Override
1231 public void onAudioRouteChanged(Connection c, int audioRoute) {
1232 String id = mIdByConnection.get(c);
1233 if (id != null) {
1234 mAdapter.setAudioRoute(id, audioRoute);
1235 }
1236 }
Hall Liub64ac4c2017-02-06 10:49:48 -08001237
1238 @Override
1239 public void onRttInitiationSuccess(Connection c) {
1240 String id = mIdByConnection.get(c);
1241 if (id != null) {
1242 mAdapter.onRttInitiationSuccess(id);
1243 }
1244 }
1245
1246 @Override
1247 public void onRttInitiationFailure(Connection c, int reason) {
1248 String id = mIdByConnection.get(c);
1249 if (id != null) {
1250 mAdapter.onRttInitiationFailure(id, reason);
1251 }
1252 }
1253
1254 @Override
1255 public void onRttSessionRemotelyTerminated(Connection c) {
1256 String id = mIdByConnection.get(c);
1257 if (id != null) {
1258 mAdapter.onRttSessionRemotelyTerminated(id);
1259 }
1260 }
1261
1262 @Override
1263 public void onRemoteRttRequest(Connection c) {
1264 String id = mIdByConnection.get(c);
1265 if (id != null) {
1266 mAdapter.onRemoteRttRequest(id);
1267 }
1268 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001269 };
1270
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001271 /** {@inheritDoc} */
Ihab Awad542e0ea2014-05-16 10:22:16 -07001272 @Override
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001273 public final IBinder onBind(Intent intent) {
1274 return mBinder;
1275 }
1276
Santos Cordon29f2f2e2014-09-11 19:50:24 -07001277 /** {@inheritDoc} */
1278 @Override
1279 public boolean onUnbind(Intent intent) {
1280 endAllConnections();
1281 return super.onUnbind(intent);
1282 }
1283
Sailesh Nepalc5b01572014-07-14 16:29:44 -07001284 /**
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001285 * This can be used by telecom to either create a new outgoing call or attach to an existing
1286 * incoming call. In either case, telecom will cycle through a set of services and call
Sailesh Nepalc5b01572014-07-14 16:29:44 -07001287 * createConnection util a connection service cancels the process or completes it successfully.
1288 */
Ihab Awadf8b69882014-07-25 15:14:01 -07001289 private void createConnection(
1290 final PhoneAccountHandle callManagerAccount,
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001291 final String callId,
Ihab Awadf8b69882014-07-25 15:14:01 -07001292 final ConnectionRequest request,
Yorke Leec3cf9822014-10-02 09:38:39 -07001293 boolean isIncoming,
1294 boolean isUnknown) {
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001295 Log.d(this, "createConnection, callManagerAccount: %s, callId: %s, request: %s, " +
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001296 "isIncoming: %b, isUnknown: %b", callManagerAccount, callId, request,
1297 isIncoming,
Yorke Leec3cf9822014-10-02 09:38:39 -07001298 isUnknown);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001299
Yorke Leec3cf9822014-10-02 09:38:39 -07001300 Connection connection = isUnknown ? onCreateUnknownConnection(callManagerAccount, request)
1301 : isIncoming ? onCreateIncomingConnection(callManagerAccount, request)
Ihab Awad6107bab2014-08-18 09:23:25 -07001302 : onCreateOutgoingConnection(callManagerAccount, request);
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001303 Log.d(this, "createConnection, connection: %s", connection);
1304 if (connection == null) {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001305 connection = Connection.createFailedConnection(
1306 new DisconnectCause(DisconnectCause.ERROR));
Sailesh Nepalc5b01572014-07-14 16:29:44 -07001307 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001308
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001309 connection.setTelecomCallId(callId);
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001310 if (connection.getState() != Connection.STATE_DISCONNECTED) {
Ihab Awad6107bab2014-08-18 09:23:25 -07001311 addConnection(callId, connection);
1312 }
1313
Andrew Lee100e2932014-09-08 15:34:24 -07001314 Uri address = connection.getAddress();
1315 String number = address == null ? "null" : address.getSchemeSpecificPart();
Tyler Gunn720c6642016-03-22 09:02:47 -07001316 Log.v(this, "createConnection, number: %s, state: %s, capabilities: %s, properties: %s",
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001317 Connection.toLogSafePhoneNumber(number),
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001318 Connection.stateToString(connection.getState()),
Tyler Gunn720c6642016-03-22 09:02:47 -07001319 Connection.capabilitiesToString(connection.getConnectionCapabilities()),
1320 Connection.propertiesToString(connection.getConnectionProperties()));
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001321
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001322 Log.d(this, "createConnection, calling handleCreateConnectionSuccessful %s", callId);
Ihab Awad6107bab2014-08-18 09:23:25 -07001323 mAdapter.handleCreateConnectionComplete(
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001324 callId,
Evan Charltonbf11f982014-07-20 22:06:28 -07001325 request,
1326 new ParcelableConnection(
1327 request.getAccountHandle(),
1328 connection.getState(),
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001329 connection.getConnectionCapabilities(),
Tyler Gunn720c6642016-03-22 09:02:47 -07001330 connection.getConnectionProperties(),
Christine Hallstrom2830ce92016-11-30 16:06:42 -08001331 connection.getSupportedAudioRoutes(),
Andrew Lee100e2932014-09-08 15:34:24 -07001332 connection.getAddress(),
1333 connection.getAddressPresentation(),
Evan Charltonbf11f982014-07-20 22:06:28 -07001334 connection.getCallerDisplayName(),
1335 connection.getCallerDisplayNamePresentation(),
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001336 connection.getVideoProvider() == null ?
1337 null : connection.getVideoProvider().getInterface(),
Sailesh Nepal8b9d3ca2014-08-14 17:39:34 -07001338 connection.getVideoState(),
Andrew Lee100e2932014-09-08 15:34:24 -07001339 connection.isRingbackRequested(),
Sailesh Nepal8b9d3ca2014-08-14 17:39:34 -07001340 connection.getAudioModeIsVoip(),
Roshan Piuse927ec02015-07-15 15:47:21 -07001341 connection.getConnectTimeMillis(),
Ihab Awad6107bab2014-08-18 09:23:25 -07001342 connection.getStatusHints(),
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001343 connection.getDisconnectCause(),
Santos Cordon6b7f9552015-05-27 17:21:45 -07001344 createIdList(connection.getConferenceables()),
1345 connection.getExtras()));
Tyler Gunnf5035432017-01-09 09:43:12 -08001346
1347 if (isIncoming && request.shouldShowIncomingCallUi() &&
1348 (connection.getConnectionProperties() & Connection.PROPERTY_SELF_MANAGED) ==
1349 Connection.PROPERTY_SELF_MANAGED) {
1350 // Tell ConnectionService to show its incoming call UX.
1351 connection.onShowIncomingCallUi();
1352 }
Shriram Ganesh6bf35ac2014-12-11 17:53:38 -08001353 if (isUnknown) {
1354 triggerConferenceRecalculate();
1355 }
Evan Charltonbf11f982014-07-20 22:06:28 -07001356 }
1357
Tyler Gunn44e01912017-01-31 10:49:05 -08001358 private void createConnectionFailed(final String callId, final ConnectionRequest request,
1359 boolean isIncoming) {
1360
1361 Log.i(this, "createConnectionFailed %s", callId);
1362 if (isIncoming) {
1363 onCreateIncomingConnectionFailed(request);
1364 } else {
1365 onCreateOutgoingConnectionFailed(request);
1366 }
1367 }
1368
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001369 private void abort(String callId) {
Ihab Awad60ac30b2014-05-20 22:32:12 -07001370 Log.d(this, "abort %s", callId);
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001371 findConnectionForAction(callId, "abort").onAbort();
Ihab Awad542e0ea2014-05-16 10:22:16 -07001372 }
1373
Tyler Gunnbe74de02014-08-29 14:51:48 -07001374 private void answerVideo(String callId, int videoState) {
1375 Log.d(this, "answerVideo %s", callId);
Andrew Lee8da4c3c2014-07-16 10:11:42 -07001376 findConnectionForAction(callId, "answer").onAnswer(videoState);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001377 }
1378
Tyler Gunnbe74de02014-08-29 14:51:48 -07001379 private void answer(String callId) {
1380 Log.d(this, "answer %s", callId);
1381 findConnectionForAction(callId, "answer").onAnswer();
1382 }
1383
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001384 private void reject(String callId) {
Ihab Awad60ac30b2014-05-20 22:32:12 -07001385 Log.d(this, "reject %s", callId);
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001386 findConnectionForAction(callId, "reject").onReject();
Ihab Awad542e0ea2014-05-16 10:22:16 -07001387 }
1388
Bryce Lee81901682015-08-28 16:38:02 -07001389 private void reject(String callId, String rejectWithMessage) {
1390 Log.d(this, "reject %s with message", callId);
1391 findConnectionForAction(callId, "reject").onReject(rejectWithMessage);
1392 }
1393
Bryce Leecac50772015-11-17 15:13:29 -08001394 private void silence(String callId) {
1395 Log.d(this, "silence %s", callId);
1396 findConnectionForAction(callId, "silence").onSilence();
1397 }
1398
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001399 private void disconnect(String callId) {
Ihab Awad60ac30b2014-05-20 22:32:12 -07001400 Log.d(this, "disconnect %s", callId);
Santos Cordon0159ac02014-08-21 14:28:11 -07001401 if (mConnectionById.containsKey(callId)) {
1402 findConnectionForAction(callId, "disconnect").onDisconnect();
1403 } else {
1404 findConferenceForAction(callId, "disconnect").onDisconnect();
1405 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001406 }
1407
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001408 private void hold(String callId) {
Ihab Awad60ac30b2014-05-20 22:32:12 -07001409 Log.d(this, "hold %s", callId);
Santos Cordon0159ac02014-08-21 14:28:11 -07001410 if (mConnectionById.containsKey(callId)) {
1411 findConnectionForAction(callId, "hold").onHold();
1412 } else {
1413 findConferenceForAction(callId, "hold").onHold();
1414 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001415 }
1416
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001417 private void unhold(String callId) {
Ihab Awad60ac30b2014-05-20 22:32:12 -07001418 Log.d(this, "unhold %s", callId);
Santos Cordon0159ac02014-08-21 14:28:11 -07001419 if (mConnectionById.containsKey(callId)) {
1420 findConnectionForAction(callId, "unhold").onUnhold();
1421 } else {
1422 findConferenceForAction(callId, "unhold").onUnhold();
1423 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001424 }
1425
Yorke Lee4af59352015-05-13 14:14:54 -07001426 private void onCallAudioStateChanged(String callId, CallAudioState callAudioState) {
1427 Log.d(this, "onAudioStateChanged %s %s", callId, callAudioState);
Yorke Leea0d3ca92014-09-15 19:18:13 -07001428 if (mConnectionById.containsKey(callId)) {
Yorke Lee4af59352015-05-13 14:14:54 -07001429 findConnectionForAction(callId, "onCallAudioStateChanged").setCallAudioState(
1430 callAudioState);
Yorke Leea0d3ca92014-09-15 19:18:13 -07001431 } else {
Yorke Lee4af59352015-05-13 14:14:54 -07001432 findConferenceForAction(callId, "onCallAudioStateChanged").setCallAudioState(
1433 callAudioState);
Yorke Leea0d3ca92014-09-15 19:18:13 -07001434 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001435 }
1436
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001437 private void playDtmfTone(String callId, char digit) {
1438 Log.d(this, "playDtmfTone %s %c", callId, digit);
Yorke Leea0d3ca92014-09-15 19:18:13 -07001439 if (mConnectionById.containsKey(callId)) {
1440 findConnectionForAction(callId, "playDtmfTone").onPlayDtmfTone(digit);
1441 } else {
1442 findConferenceForAction(callId, "playDtmfTone").onPlayDtmfTone(digit);
1443 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001444 }
1445
1446 private void stopDtmfTone(String callId) {
1447 Log.d(this, "stopDtmfTone %s", callId);
Yorke Leea0d3ca92014-09-15 19:18:13 -07001448 if (mConnectionById.containsKey(callId)) {
1449 findConnectionForAction(callId, "stopDtmfTone").onStopDtmfTone();
1450 } else {
1451 findConferenceForAction(callId, "stopDtmfTone").onStopDtmfTone();
1452 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001453 }
1454
Santos Cordon823fd3c2014-08-07 18:35:18 -07001455 private void conference(String callId1, String callId2) {
1456 Log.d(this, "conference %s, %s", callId1, callId2);
Santos Cordon980acb92014-05-31 10:31:19 -07001457
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001458 // Attempt to get second connection or conference.
Santos Cordon823fd3c2014-08-07 18:35:18 -07001459 Connection connection2 = findConnectionForAction(callId2, "conference");
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001460 Conference conference2 = getNullConference();
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001461 if (connection2 == getNullConnection()) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001462 conference2 = findConferenceForAction(callId2, "conference");
1463 if (conference2 == getNullConference()) {
1464 Log.w(this, "Connection2 or Conference2 missing in conference request %s.",
1465 callId2);
1466 return;
1467 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07001468 }
Santos Cordonb6939982014-06-04 20:20:58 -07001469
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001470 // Attempt to get first connection or conference and perform merge.
Ihab Awad50e35062014-09-30 09:17:03 -07001471 Connection connection1 = findConnectionForAction(callId1, "conference");
1472 if (connection1 == getNullConnection()) {
1473 Conference conference1 = findConferenceForAction(callId1, "addConnection");
1474 if (conference1 == getNullConference()) {
1475 Log.w(this,
1476 "Connection1 or Conference1 missing in conference request %s.",
1477 callId1);
1478 } else {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001479 // Call 1 is a conference.
1480 if (connection2 != getNullConnection()) {
1481 // Call 2 is a connection so merge via call 1 (conference).
1482 conference1.onMerge(connection2);
1483 } else {
1484 // Call 2 is ALSO a conference; this should never happen.
1485 Log.wtf(this, "There can only be one conference and an attempt was made to " +
1486 "merge two conferences.");
1487 return;
1488 }
Ihab Awad50e35062014-09-30 09:17:03 -07001489 }
1490 } else {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001491 // Call 1 is a connection.
1492 if (conference2 != getNullConference()) {
1493 // Call 2 is a conference, so merge via call 2.
1494 conference2.onMerge(connection1);
1495 } else {
1496 // Call 2 is a connection, so merge together.
1497 onConference(connection1, connection2);
1498 }
Ihab Awad50e35062014-09-30 09:17:03 -07001499 }
Santos Cordon980acb92014-05-31 10:31:19 -07001500 }
1501
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001502 private void splitFromConference(String callId) {
Santos Cordonb6939982014-06-04 20:20:58 -07001503 Log.d(this, "splitFromConference(%s)", callId);
Santos Cordon980acb92014-05-31 10:31:19 -07001504
1505 Connection connection = findConnectionForAction(callId, "splitFromConference");
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001506 if (connection == getNullConnection()) {
Santos Cordon980acb92014-05-31 10:31:19 -07001507 Log.w(this, "Connection missing in conference request %s.", callId);
1508 return;
1509 }
1510
Santos Cordon0159ac02014-08-21 14:28:11 -07001511 Conference conference = connection.getConference();
1512 if (conference != null) {
1513 conference.onSeparate(connection);
1514 }
Santos Cordon980acb92014-05-31 10:31:19 -07001515 }
1516
Santos Cordona4868042014-09-04 17:39:22 -07001517 private void mergeConference(String callId) {
1518 Log.d(this, "mergeConference(%s)", callId);
1519 Conference conference = findConferenceForAction(callId, "mergeConference");
1520 if (conference != null) {
1521 conference.onMerge();
1522 }
1523 }
1524
1525 private void swapConference(String callId) {
1526 Log.d(this, "swapConference(%s)", callId);
1527 Conference conference = findConferenceForAction(callId, "swapConference");
1528 if (conference != null) {
1529 conference.onSwap();
1530 }
1531 }
1532
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001533 /**
1534 * Notifies a {@link Connection} of a request to pull an external call.
1535 *
1536 * See {@link Call#pullExternalCall()}.
1537 *
1538 * @param callId The ID of the call to pull.
1539 */
1540 private void pullExternalCall(String callId) {
1541 Log.d(this, "pullExternalCall(%s)", callId);
1542 Connection connection = findConnectionForAction(callId, "pullExternalCall");
1543 if (connection != null) {
1544 connection.onPullExternalCall();
1545 }
1546 }
1547
1548 /**
1549 * Notifies a {@link Connection} of a call event.
1550 *
1551 * See {@link Call#sendCallEvent(String, Bundle)}.
1552 *
1553 * @param callId The ID of the call receiving the event.
1554 * @param event The event.
1555 * @param extras Extras associated with the event.
1556 */
1557 private void sendCallEvent(String callId, String event, Bundle extras) {
1558 Log.d(this, "sendCallEvent(%s, %s)", callId, event);
1559 Connection connection = findConnectionForAction(callId, "sendCallEvent");
1560 if (connection != null) {
1561 connection.onCallEvent(event, extras);
1562 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001563 }
1564
Tyler Gunndee56a82016-03-23 16:06:34 -07001565 /**
1566 * Notifies a {@link Connection} or {@link Conference} of a change to the extras from Telecom.
1567 * <p>
1568 * These extra changes can originate from Telecom itself, or from an {@link InCallService} via
1569 * the {@link android.telecom.Call#putExtra(String, boolean)},
1570 * {@link android.telecom.Call#putExtra(String, int)},
1571 * {@link android.telecom.Call#putExtra(String, String)},
1572 * {@link Call#removeExtras(List)}.
1573 *
1574 * @param callId The ID of the call receiving the event.
1575 * @param extras The new extras bundle.
1576 */
1577 private void handleExtrasChanged(String callId, Bundle extras) {
1578 Log.d(this, "handleExtrasChanged(%s, %s)", callId, extras);
1579 if (mConnectionById.containsKey(callId)) {
1580 findConnectionForAction(callId, "handleExtrasChanged").handleExtrasChanged(extras);
1581 } else if (mConferenceById.containsKey(callId)) {
1582 findConferenceForAction(callId, "handleExtrasChanged").handleExtrasChanged(extras);
1583 }
1584 }
1585
Hall Liub64ac4c2017-02-06 10:49:48 -08001586 private void startRtt(String callId, Connection.RttTextStream rttTextStream) {
1587 Log.d(this, "startRtt(%s)", callId);
1588 if (mConnectionById.containsKey(callId)) {
1589 findConnectionForAction(callId, "startRtt").onStartRtt(rttTextStream);
1590 } else if (mConferenceById.containsKey(callId)) {
1591 Log.w(this, "startRtt called on a conference.");
1592 }
1593 }
1594
1595 private void stopRtt(String callId) {
1596 Log.d(this, "stopRtt(%s)", callId);
1597 if (mConnectionById.containsKey(callId)) {
1598 findConnectionForAction(callId, "stopRtt").onStopRtt();
1599 } else if (mConferenceById.containsKey(callId)) {
1600 Log.w(this, "stopRtt called on a conference.");
1601 }
1602 }
1603
1604 private void handleRttUpgradeResponse(String callId, Connection.RttTextStream rttTextStream) {
1605 Log.d(this, "handleRttUpgradeResponse(%s, %s)", callId, rttTextStream == null);
1606 if (mConnectionById.containsKey(callId)) {
1607 findConnectionForAction(callId, "handleRttUpgradeResponse")
1608 .handleRttUpgradeResponse(rttTextStream);
1609 } else if (mConferenceById.containsKey(callId)) {
1610 Log.w(this, "handleRttUpgradeResponse called on a conference.");
1611 }
1612 }
1613
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001614 private void onPostDialContinue(String callId, boolean proceed) {
Evan Charlton6dea4ac2014-06-03 14:07:13 -07001615 Log.d(this, "onPostDialContinue(%s)", callId);
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001616 findConnectionForAction(callId, "stopDtmfTone").onPostDialContinue(proceed);
Evan Charlton6dea4ac2014-06-03 14:07:13 -07001617 }
1618
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001619 private void onAdapterAttached() {
Ihab Awad9c3f1882014-06-30 21:17:13 -07001620 if (mAreAccountsInitialized) {
Santos Cordon52d8a152014-06-17 19:08:45 -07001621 // No need to query again if we already did it.
1622 return;
1623 }
1624
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001625 mAdapter.queryRemoteConnectionServices(new RemoteServiceCallback.Stub() {
Santos Cordon52d8a152014-06-17 19:08:45 -07001626 @Override
1627 public void onResult(
1628 final List<ComponentName> componentNames,
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001629 final List<IBinder> services) {
Brad Ebinger0c3541b2016-11-01 14:11:38 -07001630 mHandler.post(new android.telecom.Logging.Runnable("oAA.qRCS.oR", null /*lock*/) {
Ihab Awad6107bab2014-08-18 09:23:25 -07001631 @Override
Brad Ebinger0c3541b2016-11-01 14:11:38 -07001632 public void loggedRun() {
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001633 for (int i = 0; i < componentNames.size() && i < services.size(); i++) {
Santos Cordon52d8a152014-06-17 19:08:45 -07001634 mRemoteConnectionManager.addConnectionService(
1635 componentNames.get(i),
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001636 IConnectionService.Stub.asInterface(services.get(i)));
Santos Cordon52d8a152014-06-17 19:08:45 -07001637 }
Ihab Awad5d0410f2014-07-30 10:07:40 -07001638 onAccountsInitialized();
Sailesh Nepalc5b01572014-07-14 16:29:44 -07001639 Log.d(this, "remote connection services found: " + services);
Santos Cordon52d8a152014-06-17 19:08:45 -07001640 }
Brad Ebinger0c3541b2016-11-01 14:11:38 -07001641 }.prepare());
Santos Cordon52d8a152014-06-17 19:08:45 -07001642 }
1643
1644 @Override
1645 public void onError() {
Brad Ebinger0c3541b2016-11-01 14:11:38 -07001646 mHandler.post(new android.telecom.Logging.Runnable("oAA.qRCS.oE", null /*lock*/) {
Ihab Awad6107bab2014-08-18 09:23:25 -07001647 @Override
Brad Ebinger0c3541b2016-11-01 14:11:38 -07001648 public void loggedRun() {
Ihab Awad9c3f1882014-06-30 21:17:13 -07001649 mAreAccountsInitialized = true;
Santos Cordon52d8a152014-06-17 19:08:45 -07001650 }
Brad Ebinger0c3541b2016-11-01 14:11:38 -07001651 }.prepare());
Santos Cordon52d8a152014-06-17 19:08:45 -07001652 }
1653 });
1654 }
1655
Ihab Awadf8b69882014-07-25 15:14:01 -07001656 /**
1657 * Ask some other {@code ConnectionService} to create a {@code RemoteConnection} given an
Santos Cordona663f862014-10-29 13:49:58 -07001658 * incoming request. This is used by {@code ConnectionService}s that are registered with
1659 * {@link PhoneAccount#CAPABILITY_CONNECTION_MANAGER} and want to be able to manage
1660 * SIM-based incoming calls.
Ihab Awadf8b69882014-07-25 15:14:01 -07001661 *
1662 * @param connectionManagerPhoneAccount See description at
1663 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
1664 * @param request Details about the incoming call.
1665 * @return The {@code Connection} object to satisfy this call, or {@code null} to
1666 * not handle the call.
1667 */
1668 public final RemoteConnection createRemoteIncomingConnection(
1669 PhoneAccountHandle connectionManagerPhoneAccount,
1670 ConnectionRequest request) {
1671 return mRemoteConnectionManager.createRemoteConnection(
1672 connectionManagerPhoneAccount, request, true);
Santos Cordon52d8a152014-06-17 19:08:45 -07001673 }
1674
1675 /**
Ihab Awadf8b69882014-07-25 15:14:01 -07001676 * Ask some other {@code ConnectionService} to create a {@code RemoteConnection} given an
Santos Cordona663f862014-10-29 13:49:58 -07001677 * outgoing request. This is used by {@code ConnectionService}s that are registered with
1678 * {@link PhoneAccount#CAPABILITY_CONNECTION_MANAGER} and want to be able to use the
1679 * SIM-based {@code ConnectionService} to place its outgoing calls.
Ihab Awadf8b69882014-07-25 15:14:01 -07001680 *
1681 * @param connectionManagerPhoneAccount See description at
1682 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
Cuihtlauac ALVARADO0b3b2a52016-09-13 14:49:41 +02001683 * @param request Details about the outgoing call.
Ihab Awadf8b69882014-07-25 15:14:01 -07001684 * @return The {@code Connection} object to satisfy this call, or {@code null} to
1685 * not handle the call.
1686 */
1687 public final RemoteConnection createRemoteOutgoingConnection(
1688 PhoneAccountHandle connectionManagerPhoneAccount,
1689 ConnectionRequest request) {
1690 return mRemoteConnectionManager.createRemoteConnection(
1691 connectionManagerPhoneAccount, request, false);
1692 }
1693
1694 /**
Santos Cordona663f862014-10-29 13:49:58 -07001695 * Indicates to the relevant {@code RemoteConnectionService} that the specified
1696 * {@link RemoteConnection}s should be merged into a conference call.
1697 * <p>
1698 * If the conference request is successful, the method {@link #onRemoteConferenceAdded} will
1699 * be invoked.
1700 *
1701 * @param remoteConnection1 The first of the remote connections to conference.
1702 * @param remoteConnection2 The second of the remote connections to conference.
Ihab Awadb8e85c72014-08-23 20:34:57 -07001703 */
1704 public final void conferenceRemoteConnections(
Santos Cordona663f862014-10-29 13:49:58 -07001705 RemoteConnection remoteConnection1,
1706 RemoteConnection remoteConnection2) {
1707 mRemoteConnectionManager.conferenceRemoteConnections(remoteConnection1, remoteConnection2);
Ihab Awadb8e85c72014-08-23 20:34:57 -07001708 }
1709
1710 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07001711 * Adds a new conference call. When a conference call is created either as a result of an
1712 * explicit request via {@link #onConference} or otherwise, the connection service should supply
1713 * an instance of {@link Conference} by invoking this method. A conference call provided by this
1714 * method will persist until {@link Conference#destroy} is invoked on the conference instance.
1715 *
1716 * @param conference The new conference object.
1717 */
1718 public final void addConference(Conference conference) {
Rekha Kumar07366812015-03-24 16:42:31 -07001719 Log.d(this, "addConference: conference=%s", conference);
1720
Santos Cordon823fd3c2014-08-07 18:35:18 -07001721 String id = addConferenceInternal(conference);
1722 if (id != null) {
1723 List<String> connectionIds = new ArrayList<>(2);
1724 for (Connection connection : conference.getConnections()) {
1725 if (mIdByConnection.containsKey(connection)) {
1726 connectionIds.add(mIdByConnection.get(connection));
1727 }
1728 }
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001729 conference.setTelecomCallId(id);
Santos Cordon823fd3c2014-08-07 18:35:18 -07001730 ParcelableConference parcelableConference = new ParcelableConference(
Nancy Chenea38cca2014-09-05 16:38:49 -07001731 conference.getPhoneAccountHandle(),
Santos Cordon823fd3c2014-08-07 18:35:18 -07001732 conference.getState(),
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001733 conference.getConnectionCapabilities(),
Tyler Gunn720c6642016-03-22 09:02:47 -07001734 conference.getConnectionProperties(),
Tyler Gunncd5d33c2015-01-12 09:02:01 -08001735 connectionIds,
Rekha Kumar07366812015-03-24 16:42:31 -07001736 conference.getVideoProvider() == null ?
1737 null : conference.getVideoProvider().getInterface(),
1738 conference.getVideoState(),
Andrew Lee3e3e2f22015-04-16 13:48:43 -07001739 conference.getConnectTimeMillis(),
Santos Cordon6b7f9552015-05-27 17:21:45 -07001740 conference.getStatusHints(),
1741 conference.getExtras());
Andrew Lee0f51da32015-04-16 13:11:55 -07001742
Santos Cordon823fd3c2014-08-07 18:35:18 -07001743 mAdapter.addConferenceCall(id, parcelableConference);
Rekha Kumar07366812015-03-24 16:42:31 -07001744 mAdapter.setVideoProvider(id, conference.getVideoProvider());
1745 mAdapter.setVideoState(id, conference.getVideoState());
Santos Cordon823fd3c2014-08-07 18:35:18 -07001746
1747 // Go through any child calls and set the parent.
1748 for (Connection connection : conference.getConnections()) {
1749 String connectionId = mIdByConnection.get(connection);
1750 if (connectionId != null) {
1751 mAdapter.setIsConferenced(connectionId, id);
1752 }
1753 }
1754 }
1755 }
1756
1757 /**
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07001758 * Adds a connection created by the {@link ConnectionService} and informs telecom of the new
1759 * connection.
1760 *
1761 * @param phoneAccountHandle The phone account handle for the connection.
1762 * @param connection The connection to add.
1763 */
1764 public final void addExistingConnection(PhoneAccountHandle phoneAccountHandle,
1765 Connection connection) {
1766
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001767 String id = addExistingConnectionInternal(phoneAccountHandle, connection);
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07001768 if (id != null) {
1769 List<String> emptyList = new ArrayList<>(0);
1770
1771 ParcelableConnection parcelableConnection = new ParcelableConnection(
1772 phoneAccountHandle,
1773 connection.getState(),
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001774 connection.getConnectionCapabilities(),
Tyler Gunn720c6642016-03-22 09:02:47 -07001775 connection.getConnectionProperties(),
Christine Hallstrom2830ce92016-11-30 16:06:42 -08001776 connection.getSupportedAudioRoutes(),
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07001777 connection.getAddress(),
1778 connection.getAddressPresentation(),
1779 connection.getCallerDisplayName(),
1780 connection.getCallerDisplayNamePresentation(),
1781 connection.getVideoProvider() == null ?
1782 null : connection.getVideoProvider().getInterface(),
1783 connection.getVideoState(),
1784 connection.isRingbackRequested(),
1785 connection.getAudioModeIsVoip(),
Roshan Piuse927ec02015-07-15 15:47:21 -07001786 connection.getConnectTimeMillis(),
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07001787 connection.getStatusHints(),
1788 connection.getDisconnectCause(),
Santos Cordon6b7f9552015-05-27 17:21:45 -07001789 emptyList,
1790 connection.getExtras());
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07001791 mAdapter.addExistingConnection(id, parcelableConnection);
1792 }
1793 }
1794
1795 /**
Ihab Awadf8b69882014-07-25 15:14:01 -07001796 * Returns all the active {@code Connection}s for which this {@code ConnectionService}
1797 * has taken responsibility.
1798 *
1799 * @return A collection of {@code Connection}s created by this {@code ConnectionService}.
Santos Cordonb6939982014-06-04 20:20:58 -07001800 */
Sailesh Nepal091768c2014-06-30 15:15:23 -07001801 public final Collection<Connection> getAllConnections() {
Santos Cordonb6939982014-06-04 20:20:58 -07001802 return mConnectionById.values();
1803 }
1804
1805 /**
Santos Cordona6018b92016-02-16 14:23:12 -08001806 * Returns all the active {@code Conference}s for which this {@code ConnectionService}
1807 * has taken responsibility.
1808 *
1809 * @return A collection of {@code Conference}s created by this {@code ConnectionService}.
1810 */
1811 public final Collection<Conference> getAllConferences() {
1812 return mConferenceById.values();
1813 }
1814
1815 /**
Ihab Awadf8b69882014-07-25 15:14:01 -07001816 * Create a {@code Connection} given an incoming request. This is used to attach to existing
1817 * incoming calls.
Evan Charltonbf11f982014-07-20 22:06:28 -07001818 *
Ihab Awadf8b69882014-07-25 15:14:01 -07001819 * @param connectionManagerPhoneAccount See description at
1820 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
1821 * @param request Details about the incoming call.
1822 * @return The {@code Connection} object to satisfy this call, or {@code null} to
1823 * not handle the call.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001824 */
Ihab Awadf8b69882014-07-25 15:14:01 -07001825 public Connection onCreateIncomingConnection(
1826 PhoneAccountHandle connectionManagerPhoneAccount,
1827 ConnectionRequest request) {
1828 return null;
1829 }
Sailesh Nepalc5b01572014-07-14 16:29:44 -07001830
1831 /**
Tyler Gunnf5035432017-01-09 09:43:12 -08001832 * Called by Telecom to inform the {@link ConnectionService} that its request to create a new
1833 * incoming {@link Connection} was denied.
1834 * <p>
1835 * Used when a self-managed {@link ConnectionService} attempts to create a new incoming
1836 * {@link Connection}, but Telecom has determined that the call cannot be allowed at this time.
1837 * The {@link ConnectionService} is responsible for silently rejecting the new incoming
1838 * {@link Connection}.
1839 * <p>
1840 * See {@link TelecomManager#isIncomingCallPermitted(PhoneAccountHandle)} for more information.
1841 *
1842 * @param request The incoming connection request.
1843 */
1844 public void onCreateIncomingConnectionFailed(ConnectionRequest request) {
1845 }
1846
1847 /**
1848 * Called by Telecom to inform the {@link ConnectionService} that its request to create a new
1849 * outgoing {@link Connection} was denied.
1850 * <p>
1851 * Used when a self-managed {@link ConnectionService} attempts to create a new outgoing
1852 * {@link Connection}, but Telecom has determined that the call cannot be placed at this time.
1853 * The {@link ConnectionService} is responisible for informing the user that the
1854 * {@link Connection} cannot be made at this time.
1855 * <p>
1856 * See {@link TelecomManager#isOutgoingCallPermitted(PhoneAccountHandle)} for more information.
1857 *
1858 * @param request The outgoing connection request.
1859 */
1860 public void onCreateOutgoingConnectionFailed(ConnectionRequest request) {
1861 }
1862
1863 /**
Shriram Ganesh6bf35ac2014-12-11 17:53:38 -08001864 * Trigger recalculate functinality for conference calls. This is used when a Telephony
1865 * Connection is part of a conference controller but is not yet added to Connection
1866 * Service and hence cannot be added to the conference call.
1867 *
1868 * @hide
1869 */
1870 public void triggerConferenceRecalculate() {
1871 }
1872
1873 /**
Ihab Awadf8b69882014-07-25 15:14:01 -07001874 * Create a {@code Connection} given an outgoing request. This is used to initiate new
1875 * outgoing calls.
Sailesh Nepalc5b01572014-07-14 16:29:44 -07001876 *
Ihab Awadf8b69882014-07-25 15:14:01 -07001877 * @param connectionManagerPhoneAccount The connection manager account to use for managing
1878 * this call.
1879 * <p>
1880 * If this parameter is not {@code null}, it means that this {@code ConnectionService}
1881 * has registered one or more {@code PhoneAccount}s having
1882 * {@link PhoneAccount#CAPABILITY_CONNECTION_MANAGER}. This parameter will contain
1883 * one of these {@code PhoneAccount}s, while the {@code request} will contain another
1884 * (usually but not always distinct) {@code PhoneAccount} to be used for actually
1885 * making the connection.
1886 * <p>
1887 * If this parameter is {@code null}, it means that this {@code ConnectionService} is
1888 * being asked to make a direct connection. The
1889 * {@link ConnectionRequest#getAccountHandle()} of parameter {@code request} will be
1890 * a {@code PhoneAccount} registered by this {@code ConnectionService} to use for
1891 * making the connection.
1892 * @param request Details about the outgoing call.
1893 * @return The {@code Connection} object to satisfy this call, or the result of an invocation
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001894 * of {@link Connection#createFailedConnection(DisconnectCause)} to not handle the call.
Sailesh Nepalc5b01572014-07-14 16:29:44 -07001895 */
Ihab Awadf8b69882014-07-25 15:14:01 -07001896 public Connection onCreateOutgoingConnection(
1897 PhoneAccountHandle connectionManagerPhoneAccount,
1898 ConnectionRequest request) {
1899 return null;
1900 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001901
1902 /**
Yorke Leec3cf9822014-10-02 09:38:39 -07001903 * Create a {@code Connection} for a new unknown call. An unknown call is a call originating
1904 * from the ConnectionService that was neither a user-initiated outgoing call, nor an incoming
1905 * call created using
1906 * {@code TelecomManager#addNewIncomingCall(PhoneAccountHandle, android.os.Bundle)}.
1907 *
Yorke Lee770ed6e2014-10-06 18:58:52 -07001908 * @hide
Yorke Leec3cf9822014-10-02 09:38:39 -07001909 */
1910 public Connection onCreateUnknownConnection(PhoneAccountHandle connectionManagerPhoneAccount,
1911 ConnectionRequest request) {
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001912 return null;
Yorke Leec3cf9822014-10-02 09:38:39 -07001913 }
1914
1915 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07001916 * Conference two specified connections. Invoked when the user has made a request to merge the
1917 * specified connections into a conference call. In response, the connection service should
1918 * create an instance of {@link Conference} and pass it into {@link #addConference}.
Santos Cordonb6939982014-06-04 20:20:58 -07001919 *
Santos Cordon823fd3c2014-08-07 18:35:18 -07001920 * @param connection1 A connection to merge into a conference call.
1921 * @param connection2 A connection to merge into a conference call.
Santos Cordonb6939982014-06-04 20:20:58 -07001922 */
Santos Cordon823fd3c2014-08-07 18:35:18 -07001923 public void onConference(Connection connection1, Connection connection2) {}
Santos Cordonb6939982014-06-04 20:20:58 -07001924
Santos Cordona663f862014-10-29 13:49:58 -07001925 /**
1926 * Indicates that a remote conference has been created for existing {@link RemoteConnection}s.
1927 * When this method is invoked, this {@link ConnectionService} should create its own
1928 * representation of the conference call and send it to telecom using {@link #addConference}.
1929 * <p>
1930 * This is only relevant to {@link ConnectionService}s which are registered with
1931 * {@link PhoneAccount#CAPABILITY_CONNECTION_MANAGER}.
1932 *
1933 * @param conference The remote conference call.
1934 */
Ihab Awadb8e85c72014-08-23 20:34:57 -07001935 public void onRemoteConferenceAdded(RemoteConference conference) {}
1936
Santos Cordon823fd3c2014-08-07 18:35:18 -07001937 /**
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07001938 * Called when an existing connection is added remotely.
1939 * @param connection The existing connection which was added.
1940 */
1941 public void onRemoteExistingConnectionAdded(RemoteConnection connection) {}
1942
1943 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07001944 * @hide
1945 */
1946 public boolean containsConference(Conference conference) {
1947 return mIdByConference.containsKey(conference);
1948 }
1949
Ihab Awadb8e85c72014-08-23 20:34:57 -07001950 /** {@hide} */
1951 void addRemoteConference(RemoteConference remoteConference) {
1952 onRemoteConferenceAdded(remoteConference);
1953 }
1954
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07001955 /** {@hide} */
1956 void addRemoteExistingConnection(RemoteConnection remoteConnection) {
1957 onRemoteExistingConnectionAdded(remoteConnection);
1958 }
1959
Ihab Awad5d0410f2014-07-30 10:07:40 -07001960 private void onAccountsInitialized() {
1961 mAreAccountsInitialized = true;
1962 for (Runnable r : mPreInitializationConnectionRequests) {
1963 r.run();
1964 }
1965 mPreInitializationConnectionRequests.clear();
1966 }
1967
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07001968 /**
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001969 * Adds an existing connection to the list of connections, identified by a new call ID unique
1970 * to this connection service.
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07001971 *
1972 * @param connection The connection.
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001973 * @return The ID of the connection (e.g. the call-id).
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07001974 */
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001975 private String addExistingConnectionInternal(PhoneAccountHandle handle, Connection connection) {
1976 String id;
Tyler Gunncd6ccfd2016-10-17 15:48:19 -07001977
1978 if (connection.getExtras() != null && connection.getExtras()
1979 .containsKey(Connection.EXTRA_ORIGINAL_CONNECTION_ID)) {
1980 id = connection.getExtras().getString(Connection.EXTRA_ORIGINAL_CONNECTION_ID);
1981 Log.d(this, "addExistingConnectionInternal - conn %s reusing original id %s",
1982 connection.getTelecomCallId(), id);
1983 } else if (handle == null) {
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001984 // If no phone account handle was provided, we cannot be sure the call ID is unique,
1985 // so just use a random UUID.
1986 id = UUID.randomUUID().toString();
1987 } else {
1988 // Phone account handle was provided, so use the ConnectionService class name as a
1989 // prefix for a unique incremental call ID.
1990 id = handle.getComponentName().getClassName() + "@" + getNextCallId();
1991 }
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07001992 addConnection(id, connection);
1993 return id;
1994 }
1995
Ihab Awad542e0ea2014-05-16 10:22:16 -07001996 private void addConnection(String callId, Connection connection) {
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001997 connection.setTelecomCallId(callId);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001998 mConnectionById.put(callId, connection);
1999 mIdByConnection.put(connection, callId);
2000 connection.addConnectionListener(mConnectionListener);
Santos Cordon823fd3c2014-08-07 18:35:18 -07002001 connection.setConnectionService(this);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002002 }
2003
Anthony Lee30e65842014-11-06 16:30:53 -08002004 /** {@hide} */
2005 protected void removeConnection(Connection connection) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07002006 connection.unsetConnectionService(this);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002007 connection.removeConnectionListener(mConnectionListener);
Chenjie Luoe370b532016-05-12 16:59:43 -07002008 String id = mIdByConnection.get(connection);
2009 if (id != null) {
2010 mConnectionById.remove(id);
2011 mIdByConnection.remove(connection);
2012 mAdapter.removeCall(id);
2013 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002014 }
2015
Santos Cordon823fd3c2014-08-07 18:35:18 -07002016 private String addConferenceInternal(Conference conference) {
Tyler Gunncd6ccfd2016-10-17 15:48:19 -07002017 String originalId = null;
2018 if (conference.getExtras() != null && conference.getExtras()
2019 .containsKey(Connection.EXTRA_ORIGINAL_CONNECTION_ID)) {
2020 originalId = conference.getExtras().getString(Connection.EXTRA_ORIGINAL_CONNECTION_ID);
2021 Log.d(this, "addConferenceInternal: conf %s reusing original id %s",
2022 conference.getTelecomCallId(),
2023 originalId);
2024 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07002025 if (mIdByConference.containsKey(conference)) {
2026 Log.w(this, "Re-adding an existing conference: %s.", conference);
2027 } else if (conference != null) {
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002028 // Conferences do not (yet) have a PhoneAccountHandle associated with them, so we
2029 // cannot determine a ConnectionService class name to associate with the ID, so use
2030 // a unique UUID (for now).
Tyler Gunncd6ccfd2016-10-17 15:48:19 -07002031 String id = originalId == null ? UUID.randomUUID().toString() : originalId;
Santos Cordon823fd3c2014-08-07 18:35:18 -07002032 mConferenceById.put(id, conference);
2033 mIdByConference.put(conference, id);
2034 conference.addListener(mConferenceListener);
2035 return id;
2036 }
2037
2038 return null;
2039 }
2040
2041 private void removeConference(Conference conference) {
2042 if (mIdByConference.containsKey(conference)) {
2043 conference.removeListener(mConferenceListener);
2044
2045 String id = mIdByConference.get(conference);
2046 mConferenceById.remove(id);
2047 mIdByConference.remove(conference);
2048 mAdapter.removeCall(id);
2049 }
2050 }
2051
Ihab Awad542e0ea2014-05-16 10:22:16 -07002052 private Connection findConnectionForAction(String callId, String action) {
2053 if (mConnectionById.containsKey(callId)) {
2054 return mConnectionById.get(callId);
2055 }
Ihab Awad60ac30b2014-05-20 22:32:12 -07002056 Log.w(this, "%s - Cannot find Connection %s", action, callId);
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07002057 return getNullConnection();
2058 }
2059
2060 static synchronized Connection getNullConnection() {
2061 if (sNullConnection == null) {
2062 sNullConnection = new Connection() {};
2063 }
2064 return sNullConnection;
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002065 }
Santos Cordon0159ac02014-08-21 14:28:11 -07002066
2067 private Conference findConferenceForAction(String conferenceId, String action) {
2068 if (mConferenceById.containsKey(conferenceId)) {
2069 return mConferenceById.get(conferenceId);
2070 }
2071 Log.w(this, "%s - Cannot find conference %s", action, conferenceId);
2072 return getNullConference();
2073 }
2074
Ihab Awadb8e85c72014-08-23 20:34:57 -07002075 private List<String> createConnectionIdList(List<Connection> connections) {
2076 List<String> ids = new ArrayList<>();
2077 for (Connection c : connections) {
2078 if (mIdByConnection.containsKey(c)) {
2079 ids.add(mIdByConnection.get(c));
2080 }
2081 }
2082 Collections.sort(ids);
2083 return ids;
2084 }
2085
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002086 /**
2087 * Builds a list of {@link Connection} and {@link Conference} IDs based on the list of
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002088 * {@link Conferenceable}s passed in.
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002089 *
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002090 * @param conferenceables The {@link Conferenceable} connections and conferences.
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002091 * @return List of string conference and call Ids.
2092 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002093 private List<String> createIdList(List<Conferenceable> conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002094 List<String> ids = new ArrayList<>();
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002095 for (Conferenceable c : conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002096 // Only allow Connection and Conference conferenceables.
2097 if (c instanceof Connection) {
2098 Connection connection = (Connection) c;
2099 if (mIdByConnection.containsKey(connection)) {
2100 ids.add(mIdByConnection.get(connection));
2101 }
2102 } else if (c instanceof Conference) {
2103 Conference conference = (Conference) c;
2104 if (mIdByConference.containsKey(conference)) {
2105 ids.add(mIdByConference.get(conference));
2106 }
2107 }
2108 }
2109 Collections.sort(ids);
2110 return ids;
2111 }
2112
Santos Cordon0159ac02014-08-21 14:28:11 -07002113 private Conference getNullConference() {
2114 if (sNullConference == null) {
2115 sNullConference = new Conference(null) {};
2116 }
2117 return sNullConference;
2118 }
Santos Cordon29f2f2e2014-09-11 19:50:24 -07002119
2120 private void endAllConnections() {
2121 // Unbound from telecomm. We should end all connections and conferences.
2122 for (Connection connection : mIdByConnection.keySet()) {
2123 // only operate on top-level calls. Conference calls will be removed on their own.
2124 if (connection.getConference() == null) {
2125 connection.onDisconnect();
2126 }
2127 }
2128 for (Conference conference : mIdByConference.keySet()) {
2129 conference.onDisconnect();
2130 }
2131 }
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002132
2133 /**
2134 * Retrieves the next call ID as maintainted by the connection service.
2135 *
2136 * @return The call ID.
2137 */
2138 private int getNextCallId() {
Brad Ebingerb32d4f82016-10-24 16:40:49 -07002139 synchronized (mIdSyncRoot) {
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002140 return ++mId;
2141 }
2142 }
Santos Cordon980acb92014-05-31 10:31:19 -07002143}