blob: dec7b762459dc9e05219f65ec4185adaebfab9a4 [file] [log] [blame]
Ihab Awad542e0ea2014-05-16 10:22:16 -07001/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Tyler Gunnef9f6f92014-09-12 22:16:17 -070017package android.telecom;
Ihab Awad542e0ea2014-05-16 10:22:16 -070018
Santos Cordon5c6fa952014-07-20 17:47:12 -070019import android.annotation.SdkConstant;
Sailesh Nepal2a46b902014-07-04 17:21:07 -070020import android.app.Service;
Santos Cordon52d8a152014-06-17 19:08:45 -070021import android.content.ComponentName;
Santos Cordon5c6fa952014-07-20 17:47:12 -070022import android.content.Intent;
Ihab Awad542e0ea2014-05-16 10:22:16 -070023import android.net.Uri;
Sanket Padawe4cc8ed52017-12-04 16:22:20 -080024import android.os.Build;
Santos Cordon6b7f9552015-05-27 17:21:45 -070025import android.os.Bundle;
Santos Cordon52d8a152014-06-17 19:08:45 -070026import android.os.Handler;
27import android.os.IBinder;
28import android.os.Looper;
Sailesh Nepal2a46b902014-07-04 17:21:07 -070029import android.os.Message;
Hall Liub64ac4c2017-02-06 10:49:48 -080030import android.os.ParcelFileDescriptor;
31import android.os.RemoteException;
Brad Ebingerb32d4f82016-10-24 16:40:49 -070032import android.telecom.Logging.Session;
Andrew Lee14185762014-07-25 09:41:56 -070033
Sailesh Nepal2a46b902014-07-04 17:21:07 -070034import com.android.internal.os.SomeArgs;
Tyler Gunnef9f6f92014-09-12 22:16:17 -070035import com.android.internal.telecom.IConnectionService;
36import com.android.internal.telecom.IConnectionServiceAdapter;
37import com.android.internal.telecom.RemoteServiceCallback;
Santos Cordon52d8a152014-06-17 19:08:45 -070038
Ihab Awad5d0410f2014-07-30 10:07:40 -070039import java.util.ArrayList;
Santos Cordonb6939982014-06-04 20:20:58 -070040import java.util.Collection;
Santos Cordon7c7bc7f2014-07-28 18:15:48 -070041import java.util.Collections;
Santos Cordon52d8a152014-06-17 19:08:45 -070042import java.util.List;
Ihab Awad542e0ea2014-05-16 10:22:16 -070043import java.util.Map;
Santos Cordon823fd3c2014-08-07 18:35:18 -070044import java.util.UUID;
mike dooley95e80702014-09-18 14:07:52 -070045import java.util.concurrent.ConcurrentHashMap;
Ihab Awad542e0ea2014-05-16 10:22:16 -070046
47/**
Tyler Gunnf5035432017-01-09 09:43:12 -080048 * An abstract service that should be implemented by any apps which either:
49 * <ol>
50 * <li>Can make phone calls (VoIP or otherwise) and want those calls to be integrated into the
51 * built-in phone app. Referred to as a <b>system managed</b> {@link ConnectionService}.</li>
52 * <li>Are a standalone calling app and don't want their calls to be integrated into the
53 * built-in phone app. Referred to as a <b>self managed</b> {@link ConnectionService}.</li>
54 * </ol>
55 * Once implemented, the {@link ConnectionService} needs to take the following steps so that Telecom
56 * will bind to it:
Santos Cordona663f862014-10-29 13:49:58 -070057 * <p>
58 * 1. <i>Registration in AndroidManifest.xml</i>
59 * <br/>
60 * <pre>
61 * &lt;service android:name="com.example.package.MyConnectionService"
62 * android:label="@string/some_label_for_my_connection_service"
Yorke Lee249c12e2015-05-13 15:59:29 -070063 * android:permission="android.permission.BIND_TELECOM_CONNECTION_SERVICE"&gt;
Santos Cordona663f862014-10-29 13:49:58 -070064 * &lt;intent-filter&gt;
65 * &lt;action android:name="android.telecom.ConnectionService" /&gt;
66 * &lt;/intent-filter&gt;
67 * &lt;/service&gt;
68 * </pre>
69 * <p>
70 * 2. <i> Registration of {@link PhoneAccount} with {@link TelecomManager}.</i>
71 * <br/>
72 * See {@link PhoneAccount} and {@link TelecomManager#registerPhoneAccount} for more information.
73 * <p>
Tyler Gunnf5035432017-01-09 09:43:12 -080074 * System managed {@link ConnectionService}s must be enabled by the user in the phone app settings
75 * before Telecom will bind to them. Self-manged {@link ConnectionService}s must be granted the
76 * appropriate permission before Telecom will bind to them.
77 * <p>
78 * Once registered and enabled by the user in the phone app settings or granted permission, telecom
79 * will bind to a {@link ConnectionService} implementation when it wants that
80 * {@link ConnectionService} to place a call or the service has indicated that is has an incoming
81 * call through {@link TelecomManager#addNewIncomingCall}. The {@link ConnectionService} can then
82 * expect a call to {@link #onCreateIncomingConnection} or {@link #onCreateOutgoingConnection}
83 * wherein it should provide a new instance of a {@link Connection} object. It is through this
84 * {@link Connection} object that telecom receives state updates and the {@link ConnectionService}
Santos Cordona663f862014-10-29 13:49:58 -070085 * receives call-commands such as answer, reject, hold and disconnect.
86 * <p>
Tyler Gunnf5035432017-01-09 09:43:12 -080087 * When there are no more live calls, telecom will unbind from the {@link ConnectionService}.
Ihab Awad542e0ea2014-05-16 10:22:16 -070088 */
Sailesh Nepal2a46b902014-07-04 17:21:07 -070089public abstract class ConnectionService extends Service {
Santos Cordon5c6fa952014-07-20 17:47:12 -070090 /**
91 * The {@link Intent} that must be declared as handled by the service.
92 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -070093 @SdkConstant(SdkConstant.SdkConstantType.SERVICE_ACTION)
Tyler Gunnef9f6f92014-09-12 22:16:17 -070094 public static final String SERVICE_INTERFACE = "android.telecom.ConnectionService";
Santos Cordon5c6fa952014-07-20 17:47:12 -070095
Tyler Gunn8bf76572017-04-06 15:30:08 -070096 /**
97 * Boolean extra used by Telecom to inform a {@link ConnectionService} that the purpose of it
98 * being asked to create a new outgoing {@link Connection} is to perform a handover of an
99 * ongoing call on the device from another {@link PhoneAccount}/{@link ConnectionService}. Will
100 * be specified in the {@link ConnectionRequest#getExtras()} passed by Telecom when
101 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)} is called.
102 * <p>
Tyler Gunn727c6bd2017-04-11 09:51:40 -0700103 * When your {@link ConnectionService} receives this extra, it should communicate the fact that
104 * this is a handover to the other device's matching {@link ConnectionService}. That
Tyler Gunn8bf76572017-04-06 15:30:08 -0700105 * {@link ConnectionService} will continue the handover using
106 * {@link TelecomManager#addNewIncomingCall(PhoneAccountHandle, Bundle)}, specifying
Tyler Gunn727c6bd2017-04-11 09:51:40 -0700107 * {@link TelecomManager#EXTRA_IS_HANDOVER}. Telecom will match the phone numbers of the
108 * handover call on the other device with ongoing calls for {@link ConnectionService}s which
109 * support {@link PhoneAccount#EXTRA_SUPPORTS_HANDOVER_FROM}.
Tyler Gunn8bf76572017-04-06 15:30:08 -0700110 * @hide
111 */
112 public static final String EXTRA_IS_HANDOVER = TelecomManager.EXTRA_IS_HANDOVER;
113
Ihab Awad542e0ea2014-05-16 10:22:16 -0700114 // Flag controlling whether PII is emitted into the logs
Ihab Awad60ac30b2014-05-20 22:32:12 -0700115 private static final boolean PII_DEBUG = Log.isLoggable(android.util.Log.DEBUG);
Ihab Awad542e0ea2014-05-16 10:22:16 -0700116
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700117 // Session Definitions
118 private static final String SESSION_HANDLER = "H.";
119 private static final String SESSION_ADD_CS_ADAPTER = "CS.aCSA";
120 private static final String SESSION_REMOVE_CS_ADAPTER = "CS.rCSA";
121 private static final String SESSION_CREATE_CONN = "CS.crCo";
Tyler Gunn041a1fe2017-05-12 10:04:49 -0700122 private static final String SESSION_CREATE_CONN_COMPLETE = "CS.crCoC";
Tyler Gunn44e01912017-01-31 10:49:05 -0800123 private static final String SESSION_CREATE_CONN_FAILED = "CS.crCoF";
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700124 private static final String SESSION_ABORT = "CS.ab";
125 private static final String SESSION_ANSWER = "CS.an";
126 private static final String SESSION_ANSWER_VIDEO = "CS.anV";
127 private static final String SESSION_REJECT = "CS.r";
128 private static final String SESSION_REJECT_MESSAGE = "CS.rWM";
129 private static final String SESSION_SILENCE = "CS.s";
130 private static final String SESSION_DISCONNECT = "CS.d";
131 private static final String SESSION_HOLD = "CS.h";
132 private static final String SESSION_UNHOLD = "CS.u";
133 private static final String SESSION_CALL_AUDIO_SC = "CS.cASC";
134 private static final String SESSION_PLAY_DTMF = "CS.pDT";
135 private static final String SESSION_STOP_DTMF = "CS.sDT";
136 private static final String SESSION_CONFERENCE = "CS.c";
137 private static final String SESSION_SPLIT_CONFERENCE = "CS.sFC";
138 private static final String SESSION_MERGE_CONFERENCE = "CS.mC";
139 private static final String SESSION_SWAP_CONFERENCE = "CS.sC";
140 private static final String SESSION_POST_DIAL_CONT = "CS.oPDC";
141 private static final String SESSION_PULL_EXTERNAL_CALL = "CS.pEC";
142 private static final String SESSION_SEND_CALL_EVENT = "CS.sCE";
143 private static final String SESSION_EXTRAS_CHANGED = "CS.oEC";
Hall Liub64ac4c2017-02-06 10:49:48 -0800144 private static final String SESSION_START_RTT = "CS.+RTT";
145 private static final String SESSION_STOP_RTT = "CS.-RTT";
146 private static final String SESSION_RTT_UPGRADE_RESPONSE = "CS.rTRUR";
Pengquan Meng731c1a32017-11-21 18:01:13 -0800147 private static final String SESSION_CONNECTION_SERVICE_FOCUS_LOST = "CS.cSFL";
148 private static final String SESSION_CONNECTION_SERVICE_FOCUS_GAINED = "CS.cSFG";
Sanket Padawe4cc8ed52017-12-04 16:22:20 -0800149 private static final String SESSION_HANDOVER_FAILED = "CS.haF";
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700150
Ihab Awad8aecfed2014-08-08 17:06:11 -0700151 private static final int MSG_ADD_CONNECTION_SERVICE_ADAPTER = 1;
Sailesh Nepalc5b01572014-07-14 16:29:44 -0700152 private static final int MSG_CREATE_CONNECTION = 2;
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700153 private static final int MSG_ABORT = 3;
Sailesh Nepalc5b01572014-07-14 16:29:44 -0700154 private static final int MSG_ANSWER = 4;
155 private static final int MSG_REJECT = 5;
156 private static final int MSG_DISCONNECT = 6;
157 private static final int MSG_HOLD = 7;
158 private static final int MSG_UNHOLD = 8;
Yorke Lee4af59352015-05-13 14:14:54 -0700159 private static final int MSG_ON_CALL_AUDIO_STATE_CHANGED = 9;
Sailesh Nepalc5b01572014-07-14 16:29:44 -0700160 private static final int MSG_PLAY_DTMF_TONE = 10;
161 private static final int MSG_STOP_DTMF_TONE = 11;
162 private static final int MSG_CONFERENCE = 12;
163 private static final int MSG_SPLIT_FROM_CONFERENCE = 13;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700164 private static final int MSG_ON_POST_DIAL_CONTINUE = 14;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700165 private static final int MSG_REMOVE_CONNECTION_SERVICE_ADAPTER = 16;
Tyler Gunnbe74de02014-08-29 14:51:48 -0700166 private static final int MSG_ANSWER_VIDEO = 17;
Santos Cordona4868042014-09-04 17:39:22 -0700167 private static final int MSG_MERGE_CONFERENCE = 18;
168 private static final int MSG_SWAP_CONFERENCE = 19;
Bryce Lee81901682015-08-28 16:38:02 -0700169 private static final int MSG_REJECT_WITH_MESSAGE = 20;
Bryce Leecac50772015-11-17 15:13:29 -0800170 private static final int MSG_SILENCE = 21;
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700171 private static final int MSG_PULL_EXTERNAL_CALL = 22;
172 private static final int MSG_SEND_CALL_EVENT = 23;
Tyler Gunndee56a82016-03-23 16:06:34 -0700173 private static final int MSG_ON_EXTRAS_CHANGED = 24;
Tyler Gunn44e01912017-01-31 10:49:05 -0800174 private static final int MSG_CREATE_CONNECTION_FAILED = 25;
Hall Liub64ac4c2017-02-06 10:49:48 -0800175 private static final int MSG_ON_START_RTT = 26;
176 private static final int MSG_ON_STOP_RTT = 27;
177 private static final int MSG_RTT_UPGRADE_RESPONSE = 28;
Tyler Gunn041a1fe2017-05-12 10:04:49 -0700178 private static final int MSG_CREATE_CONNECTION_COMPLETE = 29;
Pengquan Meng731c1a32017-11-21 18:01:13 -0800179 private static final int MSG_CONNECTION_SERVICE_FOCUS_LOST = 30;
180 private static final int MSG_CONNECTION_SERVICE_FOCUS_GAINED = 31;
Sanket Padawe4cc8ed52017-12-04 16:22:20 -0800181 private static final int MSG_HANDOVER_FAILED = 32;
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700182
Sailesh Nepalcf7020b2014-08-20 10:07:19 -0700183 private static Connection sNullConnection;
184
mike dooley95e80702014-09-18 14:07:52 -0700185 private final Map<String, Connection> mConnectionById = new ConcurrentHashMap<>();
186 private final Map<Connection, String> mIdByConnection = new ConcurrentHashMap<>();
187 private final Map<String, Conference> mConferenceById = new ConcurrentHashMap<>();
188 private final Map<Conference, String> mIdByConference = new ConcurrentHashMap<>();
Ihab Awadb8e85c72014-08-23 20:34:57 -0700189 private final RemoteConnectionManager mRemoteConnectionManager =
190 new RemoteConnectionManager(this);
Ihab Awad5d0410f2014-07-30 10:07:40 -0700191 private final List<Runnable> mPreInitializationConnectionRequests = new ArrayList<>();
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700192 private final ConnectionServiceAdapter mAdapter = new ConnectionServiceAdapter();
Ihab Awad542e0ea2014-05-16 10:22:16 -0700193
Santos Cordon823fd3c2014-08-07 18:35:18 -0700194 private boolean mAreAccountsInitialized = false;
Santos Cordon0159ac02014-08-21 14:28:11 -0700195 private Conference sNullConference;
Tyler Gunnf0500bd2015-09-01 10:59:48 -0700196 private Object mIdSyncRoot = new Object();
197 private int mId = 0;
Santos Cordon823fd3c2014-08-07 18:35:18 -0700198
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700199 private final IBinder mBinder = new IConnectionService.Stub() {
200 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700201 public void addConnectionServiceAdapter(IConnectionServiceAdapter adapter,
202 Session.Info sessionInfo) {
203 Log.startSession(sessionInfo, SESSION_ADD_CS_ADAPTER);
204 try {
205 SomeArgs args = SomeArgs.obtain();
206 args.arg1 = adapter;
207 args.arg2 = Log.createSubsession();
208 mHandler.obtainMessage(MSG_ADD_CONNECTION_SERVICE_ADAPTER, args).sendToTarget();
209 } finally {
210 Log.endSession();
211 }
Ihab Awad8aecfed2014-08-08 17:06:11 -0700212 }
213
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700214 public void removeConnectionServiceAdapter(IConnectionServiceAdapter adapter,
215 Session.Info sessionInfo) {
216 Log.startSession(sessionInfo, SESSION_REMOVE_CS_ADAPTER);
217 try {
218 SomeArgs args = SomeArgs.obtain();
219 args.arg1 = adapter;
220 args.arg2 = Log.createSubsession();
221 mHandler.obtainMessage(MSG_REMOVE_CONNECTION_SERVICE_ADAPTER, args).sendToTarget();
222 } finally {
223 Log.endSession();
224 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700225 }
226
227 @Override
Ihab Awadf8b69882014-07-25 15:14:01 -0700228 public void createConnection(
229 PhoneAccountHandle connectionManagerPhoneAccount,
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700230 String id,
Ihab Awadf8b69882014-07-25 15:14:01 -0700231 ConnectionRequest request,
Yorke Leec3cf9822014-10-02 09:38:39 -0700232 boolean isIncoming,
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700233 boolean isUnknown,
234 Session.Info sessionInfo) {
235 Log.startSession(sessionInfo, SESSION_CREATE_CONN);
236 try {
237 SomeArgs args = SomeArgs.obtain();
238 args.arg1 = connectionManagerPhoneAccount;
239 args.arg2 = id;
240 args.arg3 = request;
241 args.arg4 = Log.createSubsession();
242 args.argi1 = isIncoming ? 1 : 0;
243 args.argi2 = isUnknown ? 1 : 0;
244 mHandler.obtainMessage(MSG_CREATE_CONNECTION, args).sendToTarget();
245 } finally {
246 Log.endSession();
247 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700248 }
249
250 @Override
Tyler Gunn041a1fe2017-05-12 10:04:49 -0700251 public void createConnectionComplete(String id, Session.Info sessionInfo) {
252 Log.startSession(sessionInfo, SESSION_CREATE_CONN_COMPLETE);
253 try {
254 SomeArgs args = SomeArgs.obtain();
255 args.arg1 = id;
256 args.arg2 = Log.createSubsession();
257 mHandler.obtainMessage(MSG_CREATE_CONNECTION_COMPLETE, args).sendToTarget();
258 } finally {
259 Log.endSession();
260 }
261 }
262
263 @Override
Tyler Gunn44e01912017-01-31 10:49:05 -0800264 public void createConnectionFailed(
Tyler Gunn159f35c2017-03-02 09:28:37 -0800265 PhoneAccountHandle connectionManagerPhoneAccount,
Tyler Gunn44e01912017-01-31 10:49:05 -0800266 String callId,
267 ConnectionRequest request,
268 boolean isIncoming,
269 Session.Info sessionInfo) {
270 Log.startSession(sessionInfo, SESSION_CREATE_CONN_FAILED);
271 try {
272 SomeArgs args = SomeArgs.obtain();
273 args.arg1 = callId;
274 args.arg2 = request;
275 args.arg3 = Log.createSubsession();
Tyler Gunn159f35c2017-03-02 09:28:37 -0800276 args.arg4 = connectionManagerPhoneAccount;
Tyler Gunn44e01912017-01-31 10:49:05 -0800277 args.argi1 = isIncoming ? 1 : 0;
278 mHandler.obtainMessage(MSG_CREATE_CONNECTION_FAILED, args).sendToTarget();
279 } finally {
280 Log.endSession();
281 }
282 }
283
284 @Override
Sanket Padawe4cc8ed52017-12-04 16:22:20 -0800285 public void handoverFailed(String callId, ConnectionRequest request, int reason,
286 Session.Info sessionInfo) {
287 Log.startSession(sessionInfo, SESSION_HANDOVER_FAILED);
288 try {
289 SomeArgs args = SomeArgs.obtain();
290 args.arg1 = callId;
291 args.arg2 = request;
292 args.arg3 = Log.createSubsession();
293 args.arg4 = reason;
294 mHandler.obtainMessage(MSG_HANDOVER_FAILED, args).sendToTarget();
295 } finally {
296 Log.endSession();
297 }
298 }
299
300 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700301 public void abort(String callId, Session.Info sessionInfo) {
302 Log.startSession(sessionInfo, SESSION_ABORT);
303 try {
304 SomeArgs args = SomeArgs.obtain();
305 args.arg1 = callId;
306 args.arg2 = Log.createSubsession();
307 mHandler.obtainMessage(MSG_ABORT, args).sendToTarget();
308 } finally {
309 Log.endSession();
310 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700311 }
312
313 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700314 public void answerVideo(String callId, int videoState, Session.Info sessionInfo) {
315 Log.startSession(sessionInfo, SESSION_ANSWER_VIDEO);
316 try {
317 SomeArgs args = SomeArgs.obtain();
318 args.arg1 = callId;
319 args.arg2 = Log.createSubsession();
320 args.argi1 = videoState;
321 mHandler.obtainMessage(MSG_ANSWER_VIDEO, args).sendToTarget();
322 } finally {
323 Log.endSession();
324 }
Tyler Gunnbe74de02014-08-29 14:51:48 -0700325 }
326
327 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700328 public void answer(String callId, Session.Info sessionInfo) {
329 Log.startSession(sessionInfo, SESSION_ANSWER);
330 try {
331 SomeArgs args = SomeArgs.obtain();
332 args.arg1 = callId;
333 args.arg2 = Log.createSubsession();
334 mHandler.obtainMessage(MSG_ANSWER, args).sendToTarget();
335 } finally {
336 Log.endSession();
337 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700338 }
339
340 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700341 public void reject(String callId, Session.Info sessionInfo) {
342 Log.startSession(sessionInfo, SESSION_REJECT);
343 try {
344 SomeArgs args = SomeArgs.obtain();
345 args.arg1 = callId;
346 args.arg2 = Log.createSubsession();
347 mHandler.obtainMessage(MSG_REJECT, args).sendToTarget();
348 } finally {
349 Log.endSession();
350 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700351 }
352
353 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700354 public void rejectWithMessage(String callId, String message, Session.Info sessionInfo) {
355 Log.startSession(sessionInfo, SESSION_REJECT_MESSAGE);
356 try {
357 SomeArgs args = SomeArgs.obtain();
358 args.arg1 = callId;
359 args.arg2 = message;
360 args.arg3 = Log.createSubsession();
361 mHandler.obtainMessage(MSG_REJECT_WITH_MESSAGE, args).sendToTarget();
362 } finally {
363 Log.endSession();
364 }
Bryce Lee81901682015-08-28 16:38:02 -0700365 }
366
367 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700368 public void silence(String callId, Session.Info sessionInfo) {
369 Log.startSession(sessionInfo, SESSION_SILENCE);
370 try {
371 SomeArgs args = SomeArgs.obtain();
372 args.arg1 = callId;
373 args.arg2 = Log.createSubsession();
374 mHandler.obtainMessage(MSG_SILENCE, args).sendToTarget();
375 } finally {
376 Log.endSession();
377 }
Bryce Leecac50772015-11-17 15:13:29 -0800378 }
379
380 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700381 public void disconnect(String callId, Session.Info sessionInfo) {
382 Log.startSession(sessionInfo, SESSION_DISCONNECT);
383 try {
384 SomeArgs args = SomeArgs.obtain();
385 args.arg1 = callId;
386 args.arg2 = Log.createSubsession();
387 mHandler.obtainMessage(MSG_DISCONNECT, args).sendToTarget();
388 } finally {
389 Log.endSession();
390 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700391 }
392
393 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700394 public void hold(String callId, Session.Info sessionInfo) {
395 Log.startSession(sessionInfo, SESSION_HOLD);
396 try {
397 SomeArgs args = SomeArgs.obtain();
398 args.arg1 = callId;
399 args.arg2 = Log.createSubsession();
400 mHandler.obtainMessage(MSG_HOLD, args).sendToTarget();
401 } finally {
402 Log.endSession();
403 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700404 }
405
406 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700407 public void unhold(String callId, Session.Info sessionInfo) {
408 Log.startSession(sessionInfo, SESSION_UNHOLD);
409 try {
410 SomeArgs args = SomeArgs.obtain();
411 args.arg1 = callId;
412 args.arg2 = Log.createSubsession();
413 mHandler.obtainMessage(MSG_UNHOLD, args).sendToTarget();
414 } finally {
415 Log.endSession();
416 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700417 }
418
419 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700420 public void onCallAudioStateChanged(String callId, CallAudioState callAudioState,
421 Session.Info sessionInfo) {
422 Log.startSession(sessionInfo, SESSION_CALL_AUDIO_SC);
423 try {
424 SomeArgs args = SomeArgs.obtain();
425 args.arg1 = callId;
426 args.arg2 = callAudioState;
427 args.arg3 = Log.createSubsession();
428 mHandler.obtainMessage(MSG_ON_CALL_AUDIO_STATE_CHANGED, args).sendToTarget();
429 } finally {
430 Log.endSession();
431 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700432 }
433
434 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700435 public void playDtmfTone(String callId, char digit, Session.Info sessionInfo) {
436 Log.startSession(sessionInfo, SESSION_PLAY_DTMF);
437 try {
438 SomeArgs args = SomeArgs.obtain();
439 args.arg1 = digit;
440 args.arg2 = callId;
441 args.arg3 = Log.createSubsession();
442 mHandler.obtainMessage(MSG_PLAY_DTMF_TONE, args).sendToTarget();
443 } finally {
444 Log.endSession();
445 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700446 }
447
448 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700449 public void stopDtmfTone(String callId, Session.Info sessionInfo) {
450 Log.startSession(sessionInfo, SESSION_STOP_DTMF);
451 try {
452 SomeArgs args = SomeArgs.obtain();
453 args.arg1 = callId;
454 args.arg2 = Log.createSubsession();
455 mHandler.obtainMessage(MSG_STOP_DTMF_TONE, args).sendToTarget();
456 } finally {
457 Log.endSession();
458 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700459 }
460
461 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700462 public void conference(String callId1, String callId2, Session.Info sessionInfo) {
463 Log.startSession(sessionInfo, SESSION_CONFERENCE);
464 try {
465 SomeArgs args = SomeArgs.obtain();
466 args.arg1 = callId1;
467 args.arg2 = callId2;
468 args.arg3 = Log.createSubsession();
469 mHandler.obtainMessage(MSG_CONFERENCE, args).sendToTarget();
470 } finally {
471 Log.endSession();
472 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700473 }
474
475 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700476 public void splitFromConference(String callId, Session.Info sessionInfo) {
477 Log.startSession(sessionInfo, SESSION_SPLIT_CONFERENCE);
478 try {
479 SomeArgs args = SomeArgs.obtain();
480 args.arg1 = callId;
481 args.arg2 = Log.createSubsession();
482 mHandler.obtainMessage(MSG_SPLIT_FROM_CONFERENCE, args).sendToTarget();
483 } finally {
484 Log.endSession();
485 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700486 }
487
488 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700489 public void mergeConference(String callId, Session.Info sessionInfo) {
490 Log.startSession(sessionInfo, SESSION_MERGE_CONFERENCE);
491 try {
492 SomeArgs args = SomeArgs.obtain();
493 args.arg1 = callId;
494 args.arg2 = Log.createSubsession();
495 mHandler.obtainMessage(MSG_MERGE_CONFERENCE, args).sendToTarget();
496 } finally {
497 Log.endSession();
498 }
Santos Cordona4868042014-09-04 17:39:22 -0700499 }
500
501 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700502 public void swapConference(String callId, Session.Info sessionInfo) {
503 Log.startSession(sessionInfo, SESSION_SWAP_CONFERENCE);
504 try {
505 SomeArgs args = SomeArgs.obtain();
506 args.arg1 = callId;
507 args.arg2 = Log.createSubsession();
508 mHandler.obtainMessage(MSG_SWAP_CONFERENCE, args).sendToTarget();
509 } finally {
510 Log.endSession();
511 }
Santos Cordona4868042014-09-04 17:39:22 -0700512 }
513
514 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700515 public void onPostDialContinue(String callId, boolean proceed, Session.Info sessionInfo) {
516 Log.startSession(sessionInfo, SESSION_POST_DIAL_CONT);
517 try {
518 SomeArgs args = SomeArgs.obtain();
519 args.arg1 = callId;
520 args.arg2 = Log.createSubsession();
521 args.argi1 = proceed ? 1 : 0;
522 mHandler.obtainMessage(MSG_ON_POST_DIAL_CONTINUE, args).sendToTarget();
523 } finally {
524 Log.endSession();
525 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700526 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700527
528 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700529 public void pullExternalCall(String callId, Session.Info sessionInfo) {
530 Log.startSession(sessionInfo, SESSION_PULL_EXTERNAL_CALL);
531 try {
532 SomeArgs args = SomeArgs.obtain();
533 args.arg1 = callId;
534 args.arg2 = Log.createSubsession();
535 mHandler.obtainMessage(MSG_PULL_EXTERNAL_CALL, args).sendToTarget();
536 } finally {
537 Log.endSession();
538 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700539 }
540
541 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700542 public void sendCallEvent(String callId, String event, Bundle extras,
543 Session.Info sessionInfo) {
544 Log.startSession(sessionInfo, SESSION_SEND_CALL_EVENT);
545 try {
546 SomeArgs args = SomeArgs.obtain();
547 args.arg1 = callId;
548 args.arg2 = event;
549 args.arg3 = extras;
550 args.arg4 = Log.createSubsession();
551 mHandler.obtainMessage(MSG_SEND_CALL_EVENT, args).sendToTarget();
552 } finally {
553 Log.endSession();
554 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700555 }
Tyler Gunndee56a82016-03-23 16:06:34 -0700556
557 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700558 public void onExtrasChanged(String callId, Bundle extras, Session.Info sessionInfo) {
559 Log.startSession(sessionInfo, SESSION_EXTRAS_CHANGED);
560 try {
561 SomeArgs args = SomeArgs.obtain();
562 args.arg1 = callId;
563 args.arg2 = extras;
564 args.arg3 = Log.createSubsession();
565 mHandler.obtainMessage(MSG_ON_EXTRAS_CHANGED, args).sendToTarget();
566 } finally {
567 Log.endSession();
568 }
Tyler Gunndee56a82016-03-23 16:06:34 -0700569 }
Hall Liub64ac4c2017-02-06 10:49:48 -0800570
571 @Override
572 public void startRtt(String callId, ParcelFileDescriptor fromInCall,
573 ParcelFileDescriptor toInCall, Session.Info sessionInfo) throws RemoteException {
574 Log.startSession(sessionInfo, SESSION_START_RTT);
575 try {
576 SomeArgs args = SomeArgs.obtain();
577 args.arg1 = callId;
578 args.arg2 = new Connection.RttTextStream(toInCall, fromInCall);
579 args.arg3 = Log.createSubsession();
580 mHandler.obtainMessage(MSG_ON_START_RTT, args).sendToTarget();
581 } finally {
582 Log.endSession();
583 }
584 }
585
586 @Override
587 public void stopRtt(String callId, Session.Info sessionInfo) throws RemoteException {
588 Log.startSession(sessionInfo, SESSION_STOP_RTT);
589 try {
590 SomeArgs args = SomeArgs.obtain();
591 args.arg1 = callId;
592 args.arg2 = Log.createSubsession();
593 mHandler.obtainMessage(MSG_ON_STOP_RTT, args).sendToTarget();
594 } finally {
595 Log.endSession();
596 }
597 }
598
599 @Override
600 public void respondToRttUpgradeRequest(String callId, ParcelFileDescriptor fromInCall,
601 ParcelFileDescriptor toInCall, Session.Info sessionInfo) throws RemoteException {
602 Log.startSession(sessionInfo, SESSION_RTT_UPGRADE_RESPONSE);
603 try {
604 SomeArgs args = SomeArgs.obtain();
605 args.arg1 = callId;
606 if (toInCall == null || fromInCall == null) {
607 args.arg2 = null;
608 } else {
609 args.arg2 = new Connection.RttTextStream(toInCall, fromInCall);
610 }
611 args.arg3 = Log.createSubsession();
612 mHandler.obtainMessage(MSG_RTT_UPGRADE_RESPONSE, args).sendToTarget();
613 } finally {
614 Log.endSession();
615 }
616 }
Pengquan Meng731c1a32017-11-21 18:01:13 -0800617
618 @Override
619 public void connectionServiceFocusLost(Session.Info sessionInfo) throws RemoteException {
620 Log.startSession(sessionInfo, SESSION_CONNECTION_SERVICE_FOCUS_LOST);
621 try {
622 mHandler.obtainMessage(MSG_CONNECTION_SERVICE_FOCUS_LOST).sendToTarget();
623 } finally {
624 Log.endSession();
625 }
626 }
627
628 @Override
629 public void connectionServiceFocusGained(Session.Info sessionInfo) throws RemoteException {
630 Log.startSession(sessionInfo, SESSION_CONNECTION_SERVICE_FOCUS_GAINED);
631 try {
632 mHandler.obtainMessage(MSG_CONNECTION_SERVICE_FOCUS_GAINED).sendToTarget();
633 } finally {
634 Log.endSession();
635 }
636 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700637 };
638
639 private final Handler mHandler = new Handler(Looper.getMainLooper()) {
640 @Override
641 public void handleMessage(Message msg) {
642 switch (msg.what) {
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700643 case MSG_ADD_CONNECTION_SERVICE_ADAPTER: {
644 SomeArgs args = (SomeArgs) msg.obj;
645 try {
646 IConnectionServiceAdapter adapter = (IConnectionServiceAdapter) args.arg1;
647 Log.continueSession((Session) args.arg2,
648 SESSION_HANDLER + SESSION_ADD_CS_ADAPTER);
649 mAdapter.addAdapter(adapter);
650 onAdapterAttached();
651 } finally {
652 args.recycle();
653 Log.endSession();
654 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700655 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700656 }
657 case MSG_REMOVE_CONNECTION_SERVICE_ADAPTER: {
658 SomeArgs args = (SomeArgs) msg.obj;
659 try {
660 Log.continueSession((Session) args.arg2,
661 SESSION_HANDLER + SESSION_REMOVE_CS_ADAPTER);
662 mAdapter.removeAdapter((IConnectionServiceAdapter) args.arg1);
663 } finally {
664 args.recycle();
665 Log.endSession();
666 }
Ihab Awad8aecfed2014-08-08 17:06:11 -0700667 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700668 }
Ihab Awadf8b69882014-07-25 15:14:01 -0700669 case MSG_CREATE_CONNECTION: {
670 SomeArgs args = (SomeArgs) msg.obj;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700671 Log.continueSession((Session) args.arg4, SESSION_HANDLER + SESSION_CREATE_CONN);
Ihab Awadf8b69882014-07-25 15:14:01 -0700672 try {
Ihab Awad5d0410f2014-07-30 10:07:40 -0700673 final PhoneAccountHandle connectionManagerPhoneAccount =
Ihab Awadf8b69882014-07-25 15:14:01 -0700674 (PhoneAccountHandle) args.arg1;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700675 final String id = (String) args.arg2;
676 final ConnectionRequest request = (ConnectionRequest) args.arg3;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700677 final boolean isIncoming = args.argi1 == 1;
Yorke Leec3cf9822014-10-02 09:38:39 -0700678 final boolean isUnknown = args.argi2 == 1;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700679 if (!mAreAccountsInitialized) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700680 Log.d(this, "Enqueueing pre-init request %s", id);
Brad Ebinger0c3541b2016-11-01 14:11:38 -0700681 mPreInitializationConnectionRequests.add(
682 new android.telecom.Logging.Runnable(
683 SESSION_HANDLER + SESSION_CREATE_CONN + ".pICR",
684 null /*lock*/) {
Ihab Awad5d0410f2014-07-30 10:07:40 -0700685 @Override
Brad Ebinger0c3541b2016-11-01 14:11:38 -0700686 public void loggedRun() {
Ihab Awad5d0410f2014-07-30 10:07:40 -0700687 createConnection(
688 connectionManagerPhoneAccount,
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700689 id,
Ihab Awad5d0410f2014-07-30 10:07:40 -0700690 request,
Yorke Leec3cf9822014-10-02 09:38:39 -0700691 isIncoming,
692 isUnknown);
Ihab Awad5d0410f2014-07-30 10:07:40 -0700693 }
Brad Ebinger0c3541b2016-11-01 14:11:38 -0700694 }.prepare());
Ihab Awad5d0410f2014-07-30 10:07:40 -0700695 } else {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700696 createConnection(
697 connectionManagerPhoneAccount,
698 id,
699 request,
Yorke Leec3cf9822014-10-02 09:38:39 -0700700 isIncoming,
701 isUnknown);
Ihab Awad5d0410f2014-07-30 10:07:40 -0700702 }
Ihab Awadf8b69882014-07-25 15:14:01 -0700703 } finally {
704 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700705 Log.endSession();
Ihab Awadf8b69882014-07-25 15:14:01 -0700706 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700707 break;
Ihab Awadf8b69882014-07-25 15:14:01 -0700708 }
Tyler Gunn041a1fe2017-05-12 10:04:49 -0700709 case MSG_CREATE_CONNECTION_COMPLETE: {
710 SomeArgs args = (SomeArgs) msg.obj;
711 Log.continueSession((Session) args.arg2,
712 SESSION_HANDLER + SESSION_CREATE_CONN_COMPLETE);
713 try {
714 final String id = (String) args.arg1;
715 if (!mAreAccountsInitialized) {
716 Log.d(this, "Enqueueing pre-init request %s", id);
717 mPreInitializationConnectionRequests.add(
718 new android.telecom.Logging.Runnable(
719 SESSION_HANDLER + SESSION_CREATE_CONN_COMPLETE
720 + ".pICR",
721 null /*lock*/) {
722 @Override
723 public void loggedRun() {
724 notifyCreateConnectionComplete(id);
725 }
726 }.prepare());
727 } else {
728 notifyCreateConnectionComplete(id);
729 }
730 } finally {
731 args.recycle();
732 Log.endSession();
733 }
734 break;
735 }
Tyler Gunn44e01912017-01-31 10:49:05 -0800736 case MSG_CREATE_CONNECTION_FAILED: {
737 SomeArgs args = (SomeArgs) msg.obj;
738 Log.continueSession((Session) args.arg3, SESSION_HANDLER +
739 SESSION_CREATE_CONN_FAILED);
740 try {
741 final String id = (String) args.arg1;
742 final ConnectionRequest request = (ConnectionRequest) args.arg2;
743 final boolean isIncoming = args.argi1 == 1;
Tyler Gunn159f35c2017-03-02 09:28:37 -0800744 final PhoneAccountHandle connectionMgrPhoneAccount =
745 (PhoneAccountHandle) args.arg4;
Tyler Gunn44e01912017-01-31 10:49:05 -0800746 if (!mAreAccountsInitialized) {
747 Log.d(this, "Enqueueing pre-init request %s", id);
748 mPreInitializationConnectionRequests.add(
749 new android.telecom.Logging.Runnable(
750 SESSION_HANDLER + SESSION_CREATE_CONN_FAILED + ".pICR",
751 null /*lock*/) {
752 @Override
753 public void loggedRun() {
Tyler Gunn159f35c2017-03-02 09:28:37 -0800754 createConnectionFailed(connectionMgrPhoneAccount, id,
755 request, isIncoming);
Tyler Gunn44e01912017-01-31 10:49:05 -0800756 }
757 }.prepare());
758 } else {
759 Log.i(this, "createConnectionFailed %s", id);
Tyler Gunn159f35c2017-03-02 09:28:37 -0800760 createConnectionFailed(connectionMgrPhoneAccount, id, request,
761 isIncoming);
Tyler Gunn44e01912017-01-31 10:49:05 -0800762 }
763 } finally {
764 args.recycle();
765 Log.endSession();
766 }
767 break;
768 }
Sanket Padawe4cc8ed52017-12-04 16:22:20 -0800769 case MSG_HANDOVER_FAILED: {
770 SomeArgs args = (SomeArgs) msg.obj;
771 Log.continueSession((Session) args.arg3, SESSION_HANDLER +
772 SESSION_HANDOVER_FAILED);
773 try {
774 final String id = (String) args.arg1;
775 final ConnectionRequest request = (ConnectionRequest) args.arg2;
776 final int reason = (int) args.arg4;
777 if (!mAreAccountsInitialized) {
778 Log.d(this, "Enqueueing pre-init request %s", id);
779 mPreInitializationConnectionRequests.add(
780 new android.telecom.Logging.Runnable(
781 SESSION_HANDLER
782 + SESSION_HANDOVER_FAILED + ".pICR",
783 null /*lock*/) {
784 @Override
785 public void loggedRun() {
786 handoverFailed(id, request, reason);
787 }
788 }.prepare());
789 } else {
790 Log.i(this, "createConnectionFailed %s", id);
791 handoverFailed(id, request, reason);
792 }
793 } finally {
794 args.recycle();
795 Log.endSession();
796 }
797 break;
798 }
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700799 case MSG_ABORT: {
800 SomeArgs args = (SomeArgs) msg.obj;
801 Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_ABORT);
802 try {
803 abort((String) args.arg1);
804 } finally {
805 args.recycle();
806 Log.endSession();
807 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700808 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700809 }
810 case MSG_ANSWER: {
811 SomeArgs args = (SomeArgs) msg.obj;
812 Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_ANSWER);
813 try {
814 answer((String) args.arg1);
815 } finally {
816 args.recycle();
817 Log.endSession();
818 }
Tyler Gunnbe74de02014-08-29 14:51:48 -0700819 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700820 }
Tyler Gunnbe74de02014-08-29 14:51:48 -0700821 case MSG_ANSWER_VIDEO: {
Andrew Lee8da4c3c2014-07-16 10:11:42 -0700822 SomeArgs args = (SomeArgs) msg.obj;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700823 Log.continueSession((Session) args.arg2,
824 SESSION_HANDLER + SESSION_ANSWER_VIDEO);
Andrew Lee8da4c3c2014-07-16 10:11:42 -0700825 try {
826 String callId = (String) args.arg1;
Evan Charltonbf11f982014-07-20 22:06:28 -0700827 int videoState = args.argi1;
Tyler Gunnbe74de02014-08-29 14:51:48 -0700828 answerVideo(callId, videoState);
Andrew Lee8da4c3c2014-07-16 10:11:42 -0700829 } finally {
830 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700831 Log.endSession();
Andrew Lee8da4c3c2014-07-16 10:11:42 -0700832 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700833 break;
Andrew Lee8da4c3c2014-07-16 10:11:42 -0700834 }
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700835 case MSG_REJECT: {
836 SomeArgs args = (SomeArgs) msg.obj;
837 Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_REJECT);
838 try {
839 reject((String) args.arg1);
840 } finally {
841 args.recycle();
842 Log.endSession();
843 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700844 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700845 }
Bryce Lee81901682015-08-28 16:38:02 -0700846 case MSG_REJECT_WITH_MESSAGE: {
847 SomeArgs args = (SomeArgs) msg.obj;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700848 Log.continueSession((Session) args.arg3,
849 SESSION_HANDLER + SESSION_REJECT_MESSAGE);
Bryce Lee81901682015-08-28 16:38:02 -0700850 try {
851 reject((String) args.arg1, (String) args.arg2);
852 } finally {
853 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700854 Log.endSession();
Bryce Lee81901682015-08-28 16:38:02 -0700855 }
856 break;
857 }
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700858 case MSG_DISCONNECT: {
859 SomeArgs args = (SomeArgs) msg.obj;
860 Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_DISCONNECT);
861 try {
862 disconnect((String) args.arg1);
863 } finally {
864 args.recycle();
865 Log.endSession();
866 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700867 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700868 }
869 case MSG_SILENCE: {
870 SomeArgs args = (SomeArgs) msg.obj;
871 Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_SILENCE);
872 try {
873 silence((String) args.arg1);
874 } finally {
875 args.recycle();
876 Log.endSession();
877 }
Bryce Leecac50772015-11-17 15:13:29 -0800878 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700879 }
880 case MSG_HOLD: {
881 SomeArgs args = (SomeArgs) msg.obj;
882 Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_REJECT);
883 try {
884 hold((String) args.arg1);
885 } finally {
886 args.recycle();
887 Log.endSession();
888 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700889 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700890 }
891 case MSG_UNHOLD: {
892 SomeArgs args = (SomeArgs) msg.obj;
893 Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_UNHOLD);
894 try {
895 unhold((String) args.arg1);
896 } finally {
897 args.recycle();
898 Log.endSession();
899 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700900 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700901 }
Yorke Lee4af59352015-05-13 14:14:54 -0700902 case MSG_ON_CALL_AUDIO_STATE_CHANGED: {
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700903 SomeArgs args = (SomeArgs) msg.obj;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700904 Log.continueSession((Session) args.arg3,
905 SESSION_HANDLER + SESSION_CALL_AUDIO_SC);
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700906 try {
907 String callId = (String) args.arg1;
Yorke Lee4af59352015-05-13 14:14:54 -0700908 CallAudioState audioState = (CallAudioState) args.arg2;
909 onCallAudioStateChanged(callId, new CallAudioState(audioState));
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700910 } finally {
911 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700912 Log.endSession();
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700913 }
914 break;
915 }
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700916 case MSG_PLAY_DTMF_TONE: {
917 SomeArgs args = (SomeArgs) msg.obj;
918 try {
919 Log.continueSession((Session) args.arg3,
920 SESSION_HANDLER + SESSION_PLAY_DTMF);
921 playDtmfTone((String) args.arg2, (char) args.arg1);
922 } finally {
923 args.recycle();
924 Log.endSession();
925 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700926 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700927 }
928 case MSG_STOP_DTMF_TONE: {
929 SomeArgs args = (SomeArgs) msg.obj;
930 try {
931 Log.continueSession((Session) args.arg2,
932 SESSION_HANDLER + SESSION_STOP_DTMF);
933 stopDtmfTone((String) args.arg1);
934 } finally {
935 args.recycle();
936 Log.endSession();
937 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700938 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700939 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700940 case MSG_CONFERENCE: {
941 SomeArgs args = (SomeArgs) msg.obj;
942 try {
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700943 Log.continueSession((Session) args.arg3,
944 SESSION_HANDLER + SESSION_CONFERENCE);
Santos Cordon823fd3c2014-08-07 18:35:18 -0700945 String callId1 = (String) args.arg1;
946 String callId2 = (String) args.arg2;
947 conference(callId1, callId2);
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700948 } finally {
949 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700950 Log.endSession();
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700951 }
952 break;
953 }
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700954 case MSG_SPLIT_FROM_CONFERENCE: {
955 SomeArgs args = (SomeArgs) msg.obj;
956 try {
957 Log.continueSession((Session) args.arg2,
958 SESSION_HANDLER + SESSION_SPLIT_CONFERENCE);
959 splitFromConference((String) args.arg1);
960 } finally {
961 args.recycle();
962 Log.endSession();
963 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700964 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700965 }
966 case MSG_MERGE_CONFERENCE: {
967 SomeArgs args = (SomeArgs) msg.obj;
968 try {
969 Log.continueSession((Session) args.arg2,
970 SESSION_HANDLER + SESSION_MERGE_CONFERENCE);
971 mergeConference((String) args.arg1);
972 } finally {
973 args.recycle();
974 Log.endSession();
975 }
Santos Cordona4868042014-09-04 17:39:22 -0700976 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700977 }
978 case MSG_SWAP_CONFERENCE: {
979 SomeArgs args = (SomeArgs) msg.obj;
980 try {
981 Log.continueSession((Session) args.arg2,
982 SESSION_HANDLER + SESSION_SWAP_CONFERENCE);
983 swapConference((String) args.arg1);
984 } finally {
985 args.recycle();
986 Log.endSession();
987 }
Santos Cordona4868042014-09-04 17:39:22 -0700988 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700989 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700990 case MSG_ON_POST_DIAL_CONTINUE: {
991 SomeArgs args = (SomeArgs) msg.obj;
992 try {
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700993 Log.continueSession((Session) args.arg2,
994 SESSION_HANDLER + SESSION_POST_DIAL_CONT);
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700995 String callId = (String) args.arg1;
996 boolean proceed = (args.argi1 == 1);
997 onPostDialContinue(callId, proceed);
998 } finally {
999 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001000 Log.endSession();
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001001 }
1002 break;
1003 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001004 case MSG_PULL_EXTERNAL_CALL: {
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001005 SomeArgs args = (SomeArgs) msg.obj;
1006 try {
1007 Log.continueSession((Session) args.arg2,
1008 SESSION_HANDLER + SESSION_PULL_EXTERNAL_CALL);
1009 pullExternalCall((String) args.arg1);
1010 } finally {
1011 args.recycle();
1012 Log.endSession();
1013 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001014 break;
1015 }
1016 case MSG_SEND_CALL_EVENT: {
1017 SomeArgs args = (SomeArgs) msg.obj;
1018 try {
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001019 Log.continueSession((Session) args.arg4,
1020 SESSION_HANDLER + SESSION_SEND_CALL_EVENT);
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001021 String callId = (String) args.arg1;
1022 String event = (String) args.arg2;
1023 Bundle extras = (Bundle) args.arg3;
1024 sendCallEvent(callId, event, extras);
1025 } finally {
1026 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001027 Log.endSession();
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001028 }
1029 break;
1030 }
Tyler Gunndee56a82016-03-23 16:06:34 -07001031 case MSG_ON_EXTRAS_CHANGED: {
1032 SomeArgs args = (SomeArgs) msg.obj;
1033 try {
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001034 Log.continueSession((Session) args.arg3,
1035 SESSION_HANDLER + SESSION_EXTRAS_CHANGED);
Tyler Gunndee56a82016-03-23 16:06:34 -07001036 String callId = (String) args.arg1;
1037 Bundle extras = (Bundle) args.arg2;
1038 handleExtrasChanged(callId, extras);
1039 } finally {
1040 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001041 Log.endSession();
Tyler Gunndee56a82016-03-23 16:06:34 -07001042 }
1043 break;
1044 }
Hall Liub64ac4c2017-02-06 10:49:48 -08001045 case MSG_ON_START_RTT: {
1046 SomeArgs args = (SomeArgs) msg.obj;
1047 try {
1048 Log.continueSession((Session) args.arg3,
1049 SESSION_HANDLER + SESSION_START_RTT);
1050 String callId = (String) args.arg1;
1051 Connection.RttTextStream rttTextStream =
1052 (Connection.RttTextStream) args.arg2;
1053 startRtt(callId, rttTextStream);
1054 } finally {
1055 args.recycle();
1056 Log.endSession();
1057 }
1058 break;
1059 }
1060 case MSG_ON_STOP_RTT: {
1061 SomeArgs args = (SomeArgs) msg.obj;
1062 try {
1063 Log.continueSession((Session) args.arg2,
1064 SESSION_HANDLER + SESSION_STOP_RTT);
1065 String callId = (String) args.arg1;
1066 stopRtt(callId);
1067 } finally {
1068 args.recycle();
1069 Log.endSession();
1070 }
1071 break;
1072 }
1073 case MSG_RTT_UPGRADE_RESPONSE: {
1074 SomeArgs args = (SomeArgs) msg.obj;
1075 try {
1076 Log.continueSession((Session) args.arg3,
1077 SESSION_HANDLER + SESSION_RTT_UPGRADE_RESPONSE);
1078 String callId = (String) args.arg1;
1079 Connection.RttTextStream rttTextStream =
1080 (Connection.RttTextStream) args.arg2;
1081 handleRttUpgradeResponse(callId, rttTextStream);
1082 } finally {
1083 args.recycle();
1084 Log.endSession();
1085 }
1086 break;
1087 }
Pengquan Meng731c1a32017-11-21 18:01:13 -08001088 case MSG_CONNECTION_SERVICE_FOCUS_GAINED:
1089 onConnectionServiceFocusGained();
1090 break;
1091 case MSG_CONNECTION_SERVICE_FOCUS_LOST:
1092 onConnectionServiceFocusLost();
1093 break;
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001094 default:
1095 break;
1096 }
1097 }
1098 };
1099
Santos Cordon823fd3c2014-08-07 18:35:18 -07001100 private final Conference.Listener mConferenceListener = new Conference.Listener() {
1101 @Override
1102 public void onStateChanged(Conference conference, int oldState, int newState) {
1103 String id = mIdByConference.get(conference);
1104 switch (newState) {
1105 case Connection.STATE_ACTIVE:
1106 mAdapter.setActive(id);
1107 break;
1108 case Connection.STATE_HOLDING:
1109 mAdapter.setOnHold(id);
1110 break;
1111 case Connection.STATE_DISCONNECTED:
1112 // handled by onDisconnected
1113 break;
1114 }
1115 }
1116
1117 @Override
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001118 public void onDisconnected(Conference conference, DisconnectCause disconnectCause) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07001119 String id = mIdByConference.get(conference);
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001120 mAdapter.setDisconnected(id, disconnectCause);
Santos Cordon823fd3c2014-08-07 18:35:18 -07001121 }
1122
1123 @Override
1124 public void onConnectionAdded(Conference conference, Connection connection) {
1125 }
1126
1127 @Override
1128 public void onConnectionRemoved(Conference conference, Connection connection) {
1129 }
1130
1131 @Override
Ihab Awad50e35062014-09-30 09:17:03 -07001132 public void onConferenceableConnectionsChanged(
1133 Conference conference, List<Connection> conferenceableConnections) {
1134 mAdapter.setConferenceableConnections(
1135 mIdByConference.get(conference),
1136 createConnectionIdList(conferenceableConnections));
1137 }
1138
1139 @Override
Santos Cordon823fd3c2014-08-07 18:35:18 -07001140 public void onDestroyed(Conference conference) {
1141 removeConference(conference);
1142 }
1143
1144 @Override
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001145 public void onConnectionCapabilitiesChanged(
1146 Conference conference,
1147 int connectionCapabilities) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07001148 String id = mIdByConference.get(conference);
1149 Log.d(this, "call capabilities: conference: %s",
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001150 Connection.capabilitiesToString(connectionCapabilities));
1151 mAdapter.setConnectionCapabilities(id, connectionCapabilities);
Santos Cordon823fd3c2014-08-07 18:35:18 -07001152 }
Rekha Kumar07366812015-03-24 16:42:31 -07001153
1154 @Override
Tyler Gunn720c6642016-03-22 09:02:47 -07001155 public void onConnectionPropertiesChanged(
1156 Conference conference,
1157 int connectionProperties) {
1158 String id = mIdByConference.get(conference);
1159 Log.d(this, "call capabilities: conference: %s",
1160 Connection.propertiesToString(connectionProperties));
1161 mAdapter.setConnectionProperties(id, connectionProperties);
1162 }
1163
1164 @Override
Rekha Kumar07366812015-03-24 16:42:31 -07001165 public void onVideoStateChanged(Conference c, int videoState) {
1166 String id = mIdByConference.get(c);
1167 Log.d(this, "onVideoStateChanged set video state %d", videoState);
1168 mAdapter.setVideoState(id, videoState);
1169 }
1170
1171 @Override
1172 public void onVideoProviderChanged(Conference c, Connection.VideoProvider videoProvider) {
1173 String id = mIdByConference.get(c);
1174 Log.d(this, "onVideoProviderChanged: Connection: %s, VideoProvider: %s", c,
1175 videoProvider);
1176 mAdapter.setVideoProvider(id, videoProvider);
1177 }
Andrew Lee0f51da32015-04-16 13:11:55 -07001178
1179 @Override
Andrew Leeedc625f2015-04-14 13:38:12 -07001180 public void onStatusHintsChanged(Conference conference, StatusHints statusHints) {
1181 String id = mIdByConference.get(conference);
Tyler Gunndee56a82016-03-23 16:06:34 -07001182 if (id != null) {
1183 mAdapter.setStatusHints(id, statusHints);
1184 }
Andrew Leeedc625f2015-04-14 13:38:12 -07001185 }
Santos Cordon6b7f9552015-05-27 17:21:45 -07001186
1187 @Override
Tyler Gunndee56a82016-03-23 16:06:34 -07001188 public void onExtrasChanged(Conference c, Bundle extras) {
1189 String id = mIdByConference.get(c);
1190 if (id != null) {
1191 mAdapter.putExtras(id, extras);
1192 }
1193 }
1194
1195 @Override
1196 public void onExtrasRemoved(Conference c, List<String> keys) {
1197 String id = mIdByConference.get(c);
1198 if (id != null) {
1199 mAdapter.removeExtras(id, keys);
1200 }
Santos Cordon6b7f9552015-05-27 17:21:45 -07001201 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07001202 };
1203
Ihab Awad542e0ea2014-05-16 10:22:16 -07001204 private final Connection.Listener mConnectionListener = new Connection.Listener() {
1205 @Override
1206 public void onStateChanged(Connection c, int state) {
1207 String id = mIdByConnection.get(c);
Ihab Awad42b30e12014-05-22 09:49:34 -07001208 Log.d(this, "Adapter set state %s %s", id, Connection.stateToString(state));
Ihab Awad542e0ea2014-05-16 10:22:16 -07001209 switch (state) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001210 case Connection.STATE_ACTIVE:
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001211 mAdapter.setActive(id);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001212 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001213 case Connection.STATE_DIALING:
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001214 mAdapter.setDialing(id);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001215 break;
Tyler Gunnc96b5e02016-07-07 22:53:57 -07001216 case Connection.STATE_PULLING_CALL:
1217 mAdapter.setPulling(id);
1218 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001219 case Connection.STATE_DISCONNECTED:
Ihab Awad542e0ea2014-05-16 10:22:16 -07001220 // Handled in onDisconnected()
1221 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001222 case Connection.STATE_HOLDING:
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001223 mAdapter.setOnHold(id);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001224 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001225 case Connection.STATE_NEW:
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001226 // Nothing to tell Telecom
Ihab Awad542e0ea2014-05-16 10:22:16 -07001227 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001228 case Connection.STATE_RINGING:
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001229 mAdapter.setRinging(id);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001230 break;
1231 }
1232 }
1233
1234 @Override
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001235 public void onDisconnected(Connection c, DisconnectCause disconnectCause) {
Ihab Awad542e0ea2014-05-16 10:22:16 -07001236 String id = mIdByConnection.get(c);
Andrew Lee26786392014-09-16 18:14:59 -07001237 Log.d(this, "Adapter set disconnected %s", disconnectCause);
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001238 mAdapter.setDisconnected(id, disconnectCause);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001239 }
1240
1241 @Override
Tyler Gunnaa07df82014-07-17 07:50:22 -07001242 public void onVideoStateChanged(Connection c, int videoState) {
1243 String id = mIdByConnection.get(c);
1244 Log.d(this, "Adapter set video state %d", videoState);
1245 mAdapter.setVideoState(id, videoState);
1246 }
1247
1248 @Override
Andrew Lee100e2932014-09-08 15:34:24 -07001249 public void onAddressChanged(Connection c, Uri address, int presentation) {
Sailesh Nepal61203862014-07-11 14:50:13 -07001250 String id = mIdByConnection.get(c);
Andrew Lee100e2932014-09-08 15:34:24 -07001251 mAdapter.setAddress(id, address, presentation);
Sailesh Nepal61203862014-07-11 14:50:13 -07001252 }
1253
1254 @Override
1255 public void onCallerDisplayNameChanged(
1256 Connection c, String callerDisplayName, int presentation) {
1257 String id = mIdByConnection.get(c);
1258 mAdapter.setCallerDisplayName(id, callerDisplayName, presentation);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001259 }
1260
1261 @Override
Ihab Awad542e0ea2014-05-16 10:22:16 -07001262 public void onDestroyed(Connection c) {
1263 removeConnection(c);
1264 }
Ihab Awadf8358972014-05-28 16:46:42 -07001265
1266 @Override
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001267 public void onPostDialWait(Connection c, String remaining) {
Sailesh Nepal091768c2014-06-30 15:15:23 -07001268 String id = mIdByConnection.get(c);
1269 Log.d(this, "Adapter onPostDialWait %s, %s", c, remaining);
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001270 mAdapter.onPostDialWait(id, remaining);
Sailesh Nepal091768c2014-06-30 15:15:23 -07001271 }
1272
1273 @Override
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001274 public void onPostDialChar(Connection c, char nextChar) {
1275 String id = mIdByConnection.get(c);
1276 Log.d(this, "Adapter onPostDialChar %s, %s", c, nextChar);
1277 mAdapter.onPostDialChar(id, nextChar);
1278 }
1279
1280 @Override
Andrew Lee100e2932014-09-08 15:34:24 -07001281 public void onRingbackRequested(Connection c, boolean ringback) {
Ihab Awadf8358972014-05-28 16:46:42 -07001282 String id = mIdByConnection.get(c);
1283 Log.d(this, "Adapter onRingback %b", ringback);
Andrew Lee100e2932014-09-08 15:34:24 -07001284 mAdapter.setRingbackRequested(id, ringback);
Ihab Awadf8358972014-05-28 16:46:42 -07001285 }
Santos Cordonb6939982014-06-04 20:20:58 -07001286
1287 @Override
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001288 public void onConnectionCapabilitiesChanged(Connection c, int capabilities) {
Santos Cordonb6939982014-06-04 20:20:58 -07001289 String id = mIdByConnection.get(c);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001290 Log.d(this, "capabilities: parcelableconnection: %s",
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001291 Connection.capabilitiesToString(capabilities));
1292 mAdapter.setConnectionCapabilities(id, capabilities);
Santos Cordonb6939982014-06-04 20:20:58 -07001293 }
1294
Santos Cordonb6939982014-06-04 20:20:58 -07001295 @Override
Tyler Gunn720c6642016-03-22 09:02:47 -07001296 public void onConnectionPropertiesChanged(Connection c, int properties) {
1297 String id = mIdByConnection.get(c);
1298 Log.d(this, "properties: parcelableconnection: %s",
1299 Connection.propertiesToString(properties));
1300 mAdapter.setConnectionProperties(id, properties);
1301 }
1302
1303 @Override
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001304 public void onVideoProviderChanged(Connection c, Connection.VideoProvider videoProvider) {
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07001305 String id = mIdByConnection.get(c);
Rekha Kumar07366812015-03-24 16:42:31 -07001306 Log.d(this, "onVideoProviderChanged: Connection: %s, VideoProvider: %s", c,
1307 videoProvider);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001308 mAdapter.setVideoProvider(id, videoProvider);
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07001309 }
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001310
1311 @Override
Sailesh Nepal001bbbb2014-07-15 14:40:39 -07001312 public void onAudioModeIsVoipChanged(Connection c, boolean isVoip) {
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001313 String id = mIdByConnection.get(c);
Andrew Lee100e2932014-09-08 15:34:24 -07001314 mAdapter.setIsVoipAudioMode(id, isVoip);
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001315 }
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001316
1317 @Override
Sailesh Nepal001bbbb2014-07-15 14:40:39 -07001318 public void onStatusHintsChanged(Connection c, StatusHints statusHints) {
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001319 String id = mIdByConnection.get(c);
1320 mAdapter.setStatusHints(id, statusHints);
1321 }
Sailesh Nepal2ab88cc2014-07-18 14:49:18 -07001322
1323 @Override
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001324 public void onConferenceablesChanged(
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001325 Connection connection, List<Conferenceable> conferenceables) {
Ihab Awadb8e85c72014-08-23 20:34:57 -07001326 mAdapter.setConferenceableConnections(
1327 mIdByConnection.get(connection),
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001328 createIdList(conferenceables));
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001329 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07001330
1331 @Override
1332 public void onConferenceChanged(Connection connection, Conference conference) {
1333 String id = mIdByConnection.get(connection);
1334 if (id != null) {
1335 String conferenceId = null;
1336 if (conference != null) {
1337 conferenceId = mIdByConference.get(conference);
1338 }
1339 mAdapter.setIsConferenced(id, conferenceId);
1340 }
1341 }
Anthony Lee17455a32015-04-24 15:25:29 -07001342
1343 @Override
1344 public void onConferenceMergeFailed(Connection connection) {
1345 String id = mIdByConnection.get(connection);
1346 if (id != null) {
1347 mAdapter.onConferenceMergeFailed(id);
1348 }
1349 }
Santos Cordon6b7f9552015-05-27 17:21:45 -07001350
1351 @Override
Tyler Gunndee56a82016-03-23 16:06:34 -07001352 public void onExtrasChanged(Connection c, Bundle extras) {
1353 String id = mIdByConnection.get(c);
Santos Cordon6b7f9552015-05-27 17:21:45 -07001354 if (id != null) {
Tyler Gunndee56a82016-03-23 16:06:34 -07001355 mAdapter.putExtras(id, extras);
Santos Cordon6b7f9552015-05-27 17:21:45 -07001356 }
1357 }
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001358
Tyler Gunnf5035432017-01-09 09:43:12 -08001359 @Override
Tyler Gunndee56a82016-03-23 16:06:34 -07001360 public void onExtrasRemoved(Connection c, List<String> keys) {
1361 String id = mIdByConnection.get(c);
1362 if (id != null) {
1363 mAdapter.removeExtras(id, keys);
1364 }
1365 }
1366
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08001367 @Override
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001368 public void onConnectionEvent(Connection connection, String event, Bundle extras) {
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08001369 String id = mIdByConnection.get(connection);
1370 if (id != null) {
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001371 mAdapter.onConnectionEvent(id, event, extras);
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08001372 }
1373 }
Tyler Gunnf5035432017-01-09 09:43:12 -08001374
1375 @Override
Hall Liua98f58b52017-11-07 17:59:28 -08001376 public void onAudioRouteChanged(Connection c, int audioRoute, String bluetoothAddress) {
Tyler Gunnf5035432017-01-09 09:43:12 -08001377 String id = mIdByConnection.get(c);
1378 if (id != null) {
Hall Liua98f58b52017-11-07 17:59:28 -08001379 mAdapter.setAudioRoute(id, audioRoute, bluetoothAddress);
Tyler Gunnf5035432017-01-09 09:43:12 -08001380 }
1381 }
Hall Liub64ac4c2017-02-06 10:49:48 -08001382
1383 @Override
1384 public void onRttInitiationSuccess(Connection c) {
1385 String id = mIdByConnection.get(c);
1386 if (id != null) {
1387 mAdapter.onRttInitiationSuccess(id);
1388 }
1389 }
1390
1391 @Override
1392 public void onRttInitiationFailure(Connection c, int reason) {
1393 String id = mIdByConnection.get(c);
1394 if (id != null) {
1395 mAdapter.onRttInitiationFailure(id, reason);
1396 }
1397 }
1398
1399 @Override
1400 public void onRttSessionRemotelyTerminated(Connection c) {
1401 String id = mIdByConnection.get(c);
1402 if (id != null) {
1403 mAdapter.onRttSessionRemotelyTerminated(id);
1404 }
1405 }
1406
1407 @Override
1408 public void onRemoteRttRequest(Connection c) {
1409 String id = mIdByConnection.get(c);
1410 if (id != null) {
1411 mAdapter.onRemoteRttRequest(id);
1412 }
1413 }
Srikanth Chintalafcb15012017-05-04 20:58:34 +05301414
1415 @Override
1416 public void onPhoneAccountChanged(Connection c, PhoneAccountHandle pHandle) {
1417 String id = mIdByConnection.get(c);
1418 if (id != null) {
1419 mAdapter.onPhoneAccountChanged(id, pHandle);
1420 }
1421 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001422 };
1423
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001424 /** {@inheritDoc} */
Ihab Awad542e0ea2014-05-16 10:22:16 -07001425 @Override
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001426 public final IBinder onBind(Intent intent) {
1427 return mBinder;
1428 }
1429
Santos Cordon29f2f2e2014-09-11 19:50:24 -07001430 /** {@inheritDoc} */
1431 @Override
1432 public boolean onUnbind(Intent intent) {
1433 endAllConnections();
1434 return super.onUnbind(intent);
1435 }
1436
Sailesh Nepalc5b01572014-07-14 16:29:44 -07001437 /**
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001438 * This can be used by telecom to either create a new outgoing call or attach to an existing
1439 * incoming call. In either case, telecom will cycle through a set of services and call
Sailesh Nepalc5b01572014-07-14 16:29:44 -07001440 * createConnection util a connection service cancels the process or completes it successfully.
1441 */
Ihab Awadf8b69882014-07-25 15:14:01 -07001442 private void createConnection(
1443 final PhoneAccountHandle callManagerAccount,
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001444 final String callId,
Ihab Awadf8b69882014-07-25 15:14:01 -07001445 final ConnectionRequest request,
Yorke Leec3cf9822014-10-02 09:38:39 -07001446 boolean isIncoming,
1447 boolean isUnknown) {
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001448 Log.d(this, "createConnection, callManagerAccount: %s, callId: %s, request: %s, " +
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001449 "isIncoming: %b, isUnknown: %b", callManagerAccount, callId, request,
1450 isIncoming,
Yorke Leec3cf9822014-10-02 09:38:39 -07001451 isUnknown);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001452
Sanket Padawee29a2662017-12-01 13:59:27 -08001453 Connection connection = null;
Sanket Padawe4cc8ed52017-12-04 16:22:20 -08001454 if (getApplicationContext().getApplicationInfo().targetSdkVersion >
1455 Build.VERSION_CODES.O_MR1 && request.getExtras() != null &&
1456 request.getExtras().getBoolean(TelecomManager.EXTRA_IS_HANDOVER,false)) {
Sanket Padawee29a2662017-12-01 13:59:27 -08001457 if (!isIncoming) {
1458 connection = onCreateOutgoingHandoverConnection(callManagerAccount, request);
1459 } else {
Sanket Padawe4cc8ed52017-12-04 16:22:20 -08001460 connection = onCreateIncomingHandoverConnection(callManagerAccount, request);
Sanket Padawee29a2662017-12-01 13:59:27 -08001461 }
1462 } else {
1463 connection = isUnknown ? onCreateUnknownConnection(callManagerAccount, request)
1464 : isIncoming ? onCreateIncomingConnection(callManagerAccount, request)
1465 : onCreateOutgoingConnection(callManagerAccount, request);
1466 }
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001467 Log.d(this, "createConnection, connection: %s", connection);
1468 if (connection == null) {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001469 connection = Connection.createFailedConnection(
1470 new DisconnectCause(DisconnectCause.ERROR));
Sailesh Nepalc5b01572014-07-14 16:29:44 -07001471 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001472
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001473 connection.setTelecomCallId(callId);
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001474 if (connection.getState() != Connection.STATE_DISCONNECTED) {
Pengquan Meng70c9885332017-10-02 18:09:03 -07001475 addConnection(request.getAccountHandle(), callId, connection);
Ihab Awad6107bab2014-08-18 09:23:25 -07001476 }
1477
Andrew Lee100e2932014-09-08 15:34:24 -07001478 Uri address = connection.getAddress();
1479 String number = address == null ? "null" : address.getSchemeSpecificPart();
Tyler Gunn720c6642016-03-22 09:02:47 -07001480 Log.v(this, "createConnection, number: %s, state: %s, capabilities: %s, properties: %s",
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001481 Connection.toLogSafePhoneNumber(number),
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001482 Connection.stateToString(connection.getState()),
Tyler Gunn720c6642016-03-22 09:02:47 -07001483 Connection.capabilitiesToString(connection.getConnectionCapabilities()),
1484 Connection.propertiesToString(connection.getConnectionProperties()));
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001485
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001486 Log.d(this, "createConnection, calling handleCreateConnectionSuccessful %s", callId);
Ihab Awad6107bab2014-08-18 09:23:25 -07001487 mAdapter.handleCreateConnectionComplete(
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001488 callId,
Evan Charltonbf11f982014-07-20 22:06:28 -07001489 request,
1490 new ParcelableConnection(
1491 request.getAccountHandle(),
1492 connection.getState(),
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001493 connection.getConnectionCapabilities(),
Tyler Gunn720c6642016-03-22 09:02:47 -07001494 connection.getConnectionProperties(),
Christine Hallstrom2830ce92016-11-30 16:06:42 -08001495 connection.getSupportedAudioRoutes(),
Andrew Lee100e2932014-09-08 15:34:24 -07001496 connection.getAddress(),
1497 connection.getAddressPresentation(),
Evan Charltonbf11f982014-07-20 22:06:28 -07001498 connection.getCallerDisplayName(),
1499 connection.getCallerDisplayNamePresentation(),
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001500 connection.getVideoProvider() == null ?
1501 null : connection.getVideoProvider().getInterface(),
Sailesh Nepal8b9d3ca2014-08-14 17:39:34 -07001502 connection.getVideoState(),
Andrew Lee100e2932014-09-08 15:34:24 -07001503 connection.isRingbackRequested(),
Sailesh Nepal8b9d3ca2014-08-14 17:39:34 -07001504 connection.getAudioModeIsVoip(),
Roshan Piuse927ec02015-07-15 15:47:21 -07001505 connection.getConnectTimeMillis(),
Tyler Gunn3fa819c2017-08-04 09:27:26 -07001506 connection.getConnectElapsedTimeMillis(),
Ihab Awad6107bab2014-08-18 09:23:25 -07001507 connection.getStatusHints(),
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001508 connection.getDisconnectCause(),
Santos Cordon6b7f9552015-05-27 17:21:45 -07001509 createIdList(connection.getConferenceables()),
1510 connection.getExtras()));
Tyler Gunnf5035432017-01-09 09:43:12 -08001511
1512 if (isIncoming && request.shouldShowIncomingCallUi() &&
1513 (connection.getConnectionProperties() & Connection.PROPERTY_SELF_MANAGED) ==
1514 Connection.PROPERTY_SELF_MANAGED) {
1515 // Tell ConnectionService to show its incoming call UX.
1516 connection.onShowIncomingCallUi();
1517 }
Shriram Ganesh6bf35ac2014-12-11 17:53:38 -08001518 if (isUnknown) {
1519 triggerConferenceRecalculate();
1520 }
Evan Charltonbf11f982014-07-20 22:06:28 -07001521 }
1522
Tyler Gunn159f35c2017-03-02 09:28:37 -08001523 private void createConnectionFailed(final PhoneAccountHandle callManagerAccount,
1524 final String callId, final ConnectionRequest request,
1525 boolean isIncoming) {
Tyler Gunn44e01912017-01-31 10:49:05 -08001526
1527 Log.i(this, "createConnectionFailed %s", callId);
1528 if (isIncoming) {
Tyler Gunn159f35c2017-03-02 09:28:37 -08001529 onCreateIncomingConnectionFailed(callManagerAccount, request);
Tyler Gunn44e01912017-01-31 10:49:05 -08001530 } else {
Tyler Gunn159f35c2017-03-02 09:28:37 -08001531 onCreateOutgoingConnectionFailed(callManagerAccount, request);
Tyler Gunn44e01912017-01-31 10:49:05 -08001532 }
1533 }
1534
Sanket Padawe4cc8ed52017-12-04 16:22:20 -08001535 private void handoverFailed(final String callId, final ConnectionRequest request,
1536 int reason) {
1537
1538 Log.i(this, "handoverFailed %s", callId);
1539 onHandoverFailed(request, reason);
1540 }
1541
Tyler Gunn041a1fe2017-05-12 10:04:49 -07001542 /**
1543 * Called by Telecom when the creation of a new Connection has completed and it is now added
1544 * to Telecom.
1545 * @param callId The ID of the connection.
1546 */
1547 private void notifyCreateConnectionComplete(final String callId) {
1548 Log.i(this, "notifyCreateConnectionComplete %s", callId);
Tyler Gunn0a88f2e2017-06-16 20:20:34 -07001549 if (callId == null) {
1550 // This could happen if the connection fails quickly and is removed from the
1551 // ConnectionService before Telecom sends the create connection complete callback.
1552 Log.w(this, "notifyCreateConnectionComplete: callId is null.");
1553 return;
1554 }
Tyler Gunn041a1fe2017-05-12 10:04:49 -07001555 onCreateConnectionComplete(findConnectionForAction(callId,
1556 "notifyCreateConnectionComplete"));
1557 }
1558
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001559 private void abort(String callId) {
Ihab Awad60ac30b2014-05-20 22:32:12 -07001560 Log.d(this, "abort %s", callId);
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001561 findConnectionForAction(callId, "abort").onAbort();
Ihab Awad542e0ea2014-05-16 10:22:16 -07001562 }
1563
Tyler Gunnbe74de02014-08-29 14:51:48 -07001564 private void answerVideo(String callId, int videoState) {
1565 Log.d(this, "answerVideo %s", callId);
Andrew Lee8da4c3c2014-07-16 10:11:42 -07001566 findConnectionForAction(callId, "answer").onAnswer(videoState);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001567 }
1568
Tyler Gunnbe74de02014-08-29 14:51:48 -07001569 private void answer(String callId) {
1570 Log.d(this, "answer %s", callId);
1571 findConnectionForAction(callId, "answer").onAnswer();
1572 }
1573
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001574 private void reject(String callId) {
Ihab Awad60ac30b2014-05-20 22:32:12 -07001575 Log.d(this, "reject %s", callId);
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001576 findConnectionForAction(callId, "reject").onReject();
Ihab Awad542e0ea2014-05-16 10:22:16 -07001577 }
1578
Bryce Lee81901682015-08-28 16:38:02 -07001579 private void reject(String callId, String rejectWithMessage) {
1580 Log.d(this, "reject %s with message", callId);
1581 findConnectionForAction(callId, "reject").onReject(rejectWithMessage);
1582 }
1583
Bryce Leecac50772015-11-17 15:13:29 -08001584 private void silence(String callId) {
1585 Log.d(this, "silence %s", callId);
1586 findConnectionForAction(callId, "silence").onSilence();
1587 }
1588
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001589 private void disconnect(String callId) {
Ihab Awad60ac30b2014-05-20 22:32:12 -07001590 Log.d(this, "disconnect %s", callId);
Santos Cordon0159ac02014-08-21 14:28:11 -07001591 if (mConnectionById.containsKey(callId)) {
1592 findConnectionForAction(callId, "disconnect").onDisconnect();
1593 } else {
1594 findConferenceForAction(callId, "disconnect").onDisconnect();
1595 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001596 }
1597
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001598 private void hold(String callId) {
Ihab Awad60ac30b2014-05-20 22:32:12 -07001599 Log.d(this, "hold %s", callId);
Santos Cordon0159ac02014-08-21 14:28:11 -07001600 if (mConnectionById.containsKey(callId)) {
1601 findConnectionForAction(callId, "hold").onHold();
1602 } else {
1603 findConferenceForAction(callId, "hold").onHold();
1604 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001605 }
1606
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001607 private void unhold(String callId) {
Ihab Awad60ac30b2014-05-20 22:32:12 -07001608 Log.d(this, "unhold %s", callId);
Santos Cordon0159ac02014-08-21 14:28:11 -07001609 if (mConnectionById.containsKey(callId)) {
1610 findConnectionForAction(callId, "unhold").onUnhold();
1611 } else {
1612 findConferenceForAction(callId, "unhold").onUnhold();
1613 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001614 }
1615
Yorke Lee4af59352015-05-13 14:14:54 -07001616 private void onCallAudioStateChanged(String callId, CallAudioState callAudioState) {
1617 Log.d(this, "onAudioStateChanged %s %s", callId, callAudioState);
Yorke Leea0d3ca92014-09-15 19:18:13 -07001618 if (mConnectionById.containsKey(callId)) {
Yorke Lee4af59352015-05-13 14:14:54 -07001619 findConnectionForAction(callId, "onCallAudioStateChanged").setCallAudioState(
1620 callAudioState);
Yorke Leea0d3ca92014-09-15 19:18:13 -07001621 } else {
Yorke Lee4af59352015-05-13 14:14:54 -07001622 findConferenceForAction(callId, "onCallAudioStateChanged").setCallAudioState(
1623 callAudioState);
Yorke Leea0d3ca92014-09-15 19:18:13 -07001624 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001625 }
1626
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001627 private void playDtmfTone(String callId, char digit) {
1628 Log.d(this, "playDtmfTone %s %c", callId, digit);
Yorke Leea0d3ca92014-09-15 19:18:13 -07001629 if (mConnectionById.containsKey(callId)) {
1630 findConnectionForAction(callId, "playDtmfTone").onPlayDtmfTone(digit);
1631 } else {
1632 findConferenceForAction(callId, "playDtmfTone").onPlayDtmfTone(digit);
1633 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001634 }
1635
1636 private void stopDtmfTone(String callId) {
1637 Log.d(this, "stopDtmfTone %s", callId);
Yorke Leea0d3ca92014-09-15 19:18:13 -07001638 if (mConnectionById.containsKey(callId)) {
1639 findConnectionForAction(callId, "stopDtmfTone").onStopDtmfTone();
1640 } else {
1641 findConferenceForAction(callId, "stopDtmfTone").onStopDtmfTone();
1642 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001643 }
1644
Santos Cordon823fd3c2014-08-07 18:35:18 -07001645 private void conference(String callId1, String callId2) {
1646 Log.d(this, "conference %s, %s", callId1, callId2);
Santos Cordon980acb92014-05-31 10:31:19 -07001647
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001648 // Attempt to get second connection or conference.
Santos Cordon823fd3c2014-08-07 18:35:18 -07001649 Connection connection2 = findConnectionForAction(callId2, "conference");
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001650 Conference conference2 = getNullConference();
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001651 if (connection2 == getNullConnection()) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001652 conference2 = findConferenceForAction(callId2, "conference");
1653 if (conference2 == getNullConference()) {
1654 Log.w(this, "Connection2 or Conference2 missing in conference request %s.",
1655 callId2);
1656 return;
1657 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07001658 }
Santos Cordonb6939982014-06-04 20:20:58 -07001659
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001660 // Attempt to get first connection or conference and perform merge.
Ihab Awad50e35062014-09-30 09:17:03 -07001661 Connection connection1 = findConnectionForAction(callId1, "conference");
1662 if (connection1 == getNullConnection()) {
1663 Conference conference1 = findConferenceForAction(callId1, "addConnection");
1664 if (conference1 == getNullConference()) {
1665 Log.w(this,
1666 "Connection1 or Conference1 missing in conference request %s.",
1667 callId1);
1668 } else {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001669 // Call 1 is a conference.
1670 if (connection2 != getNullConnection()) {
1671 // Call 2 is a connection so merge via call 1 (conference).
1672 conference1.onMerge(connection2);
1673 } else {
1674 // Call 2 is ALSO a conference; this should never happen.
1675 Log.wtf(this, "There can only be one conference and an attempt was made to " +
1676 "merge two conferences.");
1677 return;
1678 }
Ihab Awad50e35062014-09-30 09:17:03 -07001679 }
1680 } else {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001681 // Call 1 is a connection.
1682 if (conference2 != getNullConference()) {
1683 // Call 2 is a conference, so merge via call 2.
1684 conference2.onMerge(connection1);
1685 } else {
1686 // Call 2 is a connection, so merge together.
1687 onConference(connection1, connection2);
1688 }
Ihab Awad50e35062014-09-30 09:17:03 -07001689 }
Santos Cordon980acb92014-05-31 10:31:19 -07001690 }
1691
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001692 private void splitFromConference(String callId) {
Santos Cordonb6939982014-06-04 20:20:58 -07001693 Log.d(this, "splitFromConference(%s)", callId);
Santos Cordon980acb92014-05-31 10:31:19 -07001694
1695 Connection connection = findConnectionForAction(callId, "splitFromConference");
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001696 if (connection == getNullConnection()) {
Santos Cordon980acb92014-05-31 10:31:19 -07001697 Log.w(this, "Connection missing in conference request %s.", callId);
1698 return;
1699 }
1700
Santos Cordon0159ac02014-08-21 14:28:11 -07001701 Conference conference = connection.getConference();
1702 if (conference != null) {
1703 conference.onSeparate(connection);
1704 }
Santos Cordon980acb92014-05-31 10:31:19 -07001705 }
1706
Santos Cordona4868042014-09-04 17:39:22 -07001707 private void mergeConference(String callId) {
1708 Log.d(this, "mergeConference(%s)", callId);
1709 Conference conference = findConferenceForAction(callId, "mergeConference");
1710 if (conference != null) {
1711 conference.onMerge();
1712 }
1713 }
1714
1715 private void swapConference(String callId) {
1716 Log.d(this, "swapConference(%s)", callId);
1717 Conference conference = findConferenceForAction(callId, "swapConference");
1718 if (conference != null) {
1719 conference.onSwap();
1720 }
1721 }
1722
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001723 /**
1724 * Notifies a {@link Connection} of a request to pull an external call.
1725 *
1726 * See {@link Call#pullExternalCall()}.
1727 *
1728 * @param callId The ID of the call to pull.
1729 */
1730 private void pullExternalCall(String callId) {
1731 Log.d(this, "pullExternalCall(%s)", callId);
1732 Connection connection = findConnectionForAction(callId, "pullExternalCall");
1733 if (connection != null) {
1734 connection.onPullExternalCall();
1735 }
1736 }
1737
1738 /**
1739 * Notifies a {@link Connection} of a call event.
1740 *
1741 * See {@link Call#sendCallEvent(String, Bundle)}.
1742 *
1743 * @param callId The ID of the call receiving the event.
1744 * @param event The event.
1745 * @param extras Extras associated with the event.
1746 */
1747 private void sendCallEvent(String callId, String event, Bundle extras) {
1748 Log.d(this, "sendCallEvent(%s, %s)", callId, event);
1749 Connection connection = findConnectionForAction(callId, "sendCallEvent");
1750 if (connection != null) {
1751 connection.onCallEvent(event, extras);
1752 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001753 }
1754
Tyler Gunndee56a82016-03-23 16:06:34 -07001755 /**
1756 * Notifies a {@link Connection} or {@link Conference} of a change to the extras from Telecom.
1757 * <p>
1758 * These extra changes can originate from Telecom itself, or from an {@link InCallService} via
1759 * the {@link android.telecom.Call#putExtra(String, boolean)},
1760 * {@link android.telecom.Call#putExtra(String, int)},
1761 * {@link android.telecom.Call#putExtra(String, String)},
1762 * {@link Call#removeExtras(List)}.
1763 *
1764 * @param callId The ID of the call receiving the event.
1765 * @param extras The new extras bundle.
1766 */
1767 private void handleExtrasChanged(String callId, Bundle extras) {
1768 Log.d(this, "handleExtrasChanged(%s, %s)", callId, extras);
1769 if (mConnectionById.containsKey(callId)) {
1770 findConnectionForAction(callId, "handleExtrasChanged").handleExtrasChanged(extras);
1771 } else if (mConferenceById.containsKey(callId)) {
1772 findConferenceForAction(callId, "handleExtrasChanged").handleExtrasChanged(extras);
1773 }
1774 }
1775
Hall Liub64ac4c2017-02-06 10:49:48 -08001776 private void startRtt(String callId, Connection.RttTextStream rttTextStream) {
1777 Log.d(this, "startRtt(%s)", callId);
1778 if (mConnectionById.containsKey(callId)) {
1779 findConnectionForAction(callId, "startRtt").onStartRtt(rttTextStream);
1780 } else if (mConferenceById.containsKey(callId)) {
1781 Log.w(this, "startRtt called on a conference.");
1782 }
1783 }
1784
1785 private void stopRtt(String callId) {
1786 Log.d(this, "stopRtt(%s)", callId);
1787 if (mConnectionById.containsKey(callId)) {
1788 findConnectionForAction(callId, "stopRtt").onStopRtt();
Hall Liuffa4a812017-03-02 16:11:00 -08001789 findConnectionForAction(callId, "stopRtt").unsetRttProperty();
Hall Liub64ac4c2017-02-06 10:49:48 -08001790 } else if (mConferenceById.containsKey(callId)) {
1791 Log.w(this, "stopRtt called on a conference.");
1792 }
1793 }
1794
1795 private void handleRttUpgradeResponse(String callId, Connection.RttTextStream rttTextStream) {
1796 Log.d(this, "handleRttUpgradeResponse(%s, %s)", callId, rttTextStream == null);
1797 if (mConnectionById.containsKey(callId)) {
1798 findConnectionForAction(callId, "handleRttUpgradeResponse")
1799 .handleRttUpgradeResponse(rttTextStream);
1800 } else if (mConferenceById.containsKey(callId)) {
1801 Log.w(this, "handleRttUpgradeResponse called on a conference.");
1802 }
1803 }
1804
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001805 private void onPostDialContinue(String callId, boolean proceed) {
Evan Charlton6dea4ac2014-06-03 14:07:13 -07001806 Log.d(this, "onPostDialContinue(%s)", callId);
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001807 findConnectionForAction(callId, "stopDtmfTone").onPostDialContinue(proceed);
Evan Charlton6dea4ac2014-06-03 14:07:13 -07001808 }
1809
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001810 private void onAdapterAttached() {
Ihab Awad9c3f1882014-06-30 21:17:13 -07001811 if (mAreAccountsInitialized) {
Santos Cordon52d8a152014-06-17 19:08:45 -07001812 // No need to query again if we already did it.
1813 return;
1814 }
1815
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001816 mAdapter.queryRemoteConnectionServices(new RemoteServiceCallback.Stub() {
Santos Cordon52d8a152014-06-17 19:08:45 -07001817 @Override
1818 public void onResult(
1819 final List<ComponentName> componentNames,
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001820 final List<IBinder> services) {
Brad Ebinger0c3541b2016-11-01 14:11:38 -07001821 mHandler.post(new android.telecom.Logging.Runnable("oAA.qRCS.oR", null /*lock*/) {
Ihab Awad6107bab2014-08-18 09:23:25 -07001822 @Override
Brad Ebinger0c3541b2016-11-01 14:11:38 -07001823 public void loggedRun() {
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001824 for (int i = 0; i < componentNames.size() && i < services.size(); i++) {
Santos Cordon52d8a152014-06-17 19:08:45 -07001825 mRemoteConnectionManager.addConnectionService(
1826 componentNames.get(i),
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001827 IConnectionService.Stub.asInterface(services.get(i)));
Santos Cordon52d8a152014-06-17 19:08:45 -07001828 }
Ihab Awad5d0410f2014-07-30 10:07:40 -07001829 onAccountsInitialized();
Sailesh Nepalc5b01572014-07-14 16:29:44 -07001830 Log.d(this, "remote connection services found: " + services);
Santos Cordon52d8a152014-06-17 19:08:45 -07001831 }
Brad Ebinger0c3541b2016-11-01 14:11:38 -07001832 }.prepare());
Santos Cordon52d8a152014-06-17 19:08:45 -07001833 }
1834
1835 @Override
1836 public void onError() {
Brad Ebinger0c3541b2016-11-01 14:11:38 -07001837 mHandler.post(new android.telecom.Logging.Runnable("oAA.qRCS.oE", null /*lock*/) {
Ihab Awad6107bab2014-08-18 09:23:25 -07001838 @Override
Brad Ebinger0c3541b2016-11-01 14:11:38 -07001839 public void loggedRun() {
Ihab Awad9c3f1882014-06-30 21:17:13 -07001840 mAreAccountsInitialized = true;
Santos Cordon52d8a152014-06-17 19:08:45 -07001841 }
Brad Ebinger0c3541b2016-11-01 14:11:38 -07001842 }.prepare());
Santos Cordon52d8a152014-06-17 19:08:45 -07001843 }
1844 });
1845 }
1846
Ihab Awadf8b69882014-07-25 15:14:01 -07001847 /**
1848 * Ask some other {@code ConnectionService} to create a {@code RemoteConnection} given an
Santos Cordona663f862014-10-29 13:49:58 -07001849 * incoming request. This is used by {@code ConnectionService}s that are registered with
1850 * {@link PhoneAccount#CAPABILITY_CONNECTION_MANAGER} and want to be able to manage
1851 * SIM-based incoming calls.
Ihab Awadf8b69882014-07-25 15:14:01 -07001852 *
1853 * @param connectionManagerPhoneAccount See description at
1854 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
1855 * @param request Details about the incoming call.
1856 * @return The {@code Connection} object to satisfy this call, or {@code null} to
1857 * not handle the call.
1858 */
1859 public final RemoteConnection createRemoteIncomingConnection(
1860 PhoneAccountHandle connectionManagerPhoneAccount,
1861 ConnectionRequest request) {
1862 return mRemoteConnectionManager.createRemoteConnection(
1863 connectionManagerPhoneAccount, request, true);
Santos Cordon52d8a152014-06-17 19:08:45 -07001864 }
1865
1866 /**
Ihab Awadf8b69882014-07-25 15:14:01 -07001867 * Ask some other {@code ConnectionService} to create a {@code RemoteConnection} given an
Santos Cordona663f862014-10-29 13:49:58 -07001868 * outgoing request. This is used by {@code ConnectionService}s that are registered with
1869 * {@link PhoneAccount#CAPABILITY_CONNECTION_MANAGER} and want to be able to use the
1870 * SIM-based {@code ConnectionService} to place its outgoing calls.
Ihab Awadf8b69882014-07-25 15:14:01 -07001871 *
1872 * @param connectionManagerPhoneAccount See description at
1873 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
Cuihtlauac ALVARADO0b3b2a52016-09-13 14:49:41 +02001874 * @param request Details about the outgoing call.
Ihab Awadf8b69882014-07-25 15:14:01 -07001875 * @return The {@code Connection} object to satisfy this call, or {@code null} to
1876 * not handle the call.
1877 */
1878 public final RemoteConnection createRemoteOutgoingConnection(
1879 PhoneAccountHandle connectionManagerPhoneAccount,
1880 ConnectionRequest request) {
1881 return mRemoteConnectionManager.createRemoteConnection(
1882 connectionManagerPhoneAccount, request, false);
1883 }
1884
1885 /**
Santos Cordona663f862014-10-29 13:49:58 -07001886 * Indicates to the relevant {@code RemoteConnectionService} that the specified
1887 * {@link RemoteConnection}s should be merged into a conference call.
1888 * <p>
1889 * If the conference request is successful, the method {@link #onRemoteConferenceAdded} will
1890 * be invoked.
1891 *
1892 * @param remoteConnection1 The first of the remote connections to conference.
1893 * @param remoteConnection2 The second of the remote connections to conference.
Ihab Awadb8e85c72014-08-23 20:34:57 -07001894 */
1895 public final void conferenceRemoteConnections(
Santos Cordona663f862014-10-29 13:49:58 -07001896 RemoteConnection remoteConnection1,
1897 RemoteConnection remoteConnection2) {
1898 mRemoteConnectionManager.conferenceRemoteConnections(remoteConnection1, remoteConnection2);
Ihab Awadb8e85c72014-08-23 20:34:57 -07001899 }
1900
1901 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07001902 * Adds a new conference call. When a conference call is created either as a result of an
1903 * explicit request via {@link #onConference} or otherwise, the connection service should supply
1904 * an instance of {@link Conference} by invoking this method. A conference call provided by this
1905 * method will persist until {@link Conference#destroy} is invoked on the conference instance.
1906 *
1907 * @param conference The new conference object.
1908 */
1909 public final void addConference(Conference conference) {
Rekha Kumar07366812015-03-24 16:42:31 -07001910 Log.d(this, "addConference: conference=%s", conference);
1911
Santos Cordon823fd3c2014-08-07 18:35:18 -07001912 String id = addConferenceInternal(conference);
1913 if (id != null) {
1914 List<String> connectionIds = new ArrayList<>(2);
1915 for (Connection connection : conference.getConnections()) {
1916 if (mIdByConnection.containsKey(connection)) {
1917 connectionIds.add(mIdByConnection.get(connection));
1918 }
1919 }
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001920 conference.setTelecomCallId(id);
Santos Cordon823fd3c2014-08-07 18:35:18 -07001921 ParcelableConference parcelableConference = new ParcelableConference(
Nancy Chenea38cca2014-09-05 16:38:49 -07001922 conference.getPhoneAccountHandle(),
Santos Cordon823fd3c2014-08-07 18:35:18 -07001923 conference.getState(),
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001924 conference.getConnectionCapabilities(),
Tyler Gunn720c6642016-03-22 09:02:47 -07001925 conference.getConnectionProperties(),
Tyler Gunncd5d33c2015-01-12 09:02:01 -08001926 connectionIds,
Rekha Kumar07366812015-03-24 16:42:31 -07001927 conference.getVideoProvider() == null ?
1928 null : conference.getVideoProvider().getInterface(),
1929 conference.getVideoState(),
Andrew Lee3e3e2f22015-04-16 13:48:43 -07001930 conference.getConnectTimeMillis(),
Tyler Gunn3fa819c2017-08-04 09:27:26 -07001931 conference.getConnectElapsedTime(),
Santos Cordon6b7f9552015-05-27 17:21:45 -07001932 conference.getStatusHints(),
1933 conference.getExtras());
Andrew Lee0f51da32015-04-16 13:11:55 -07001934
Santos Cordon823fd3c2014-08-07 18:35:18 -07001935 mAdapter.addConferenceCall(id, parcelableConference);
Rekha Kumar07366812015-03-24 16:42:31 -07001936 mAdapter.setVideoProvider(id, conference.getVideoProvider());
1937 mAdapter.setVideoState(id, conference.getVideoState());
Santos Cordon823fd3c2014-08-07 18:35:18 -07001938
1939 // Go through any child calls and set the parent.
1940 for (Connection connection : conference.getConnections()) {
1941 String connectionId = mIdByConnection.get(connection);
1942 if (connectionId != null) {
1943 mAdapter.setIsConferenced(connectionId, id);
1944 }
1945 }
Pengquan Meng70c9885332017-10-02 18:09:03 -07001946 onConferenceAdded(conference);
Santos Cordon823fd3c2014-08-07 18:35:18 -07001947 }
1948 }
1949
1950 /**
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07001951 * Adds a connection created by the {@link ConnectionService} and informs telecom of the new
1952 * connection.
1953 *
1954 * @param phoneAccountHandle The phone account handle for the connection.
1955 * @param connection The connection to add.
1956 */
1957 public final void addExistingConnection(PhoneAccountHandle phoneAccountHandle,
1958 Connection connection) {
Tyler Gunn78da7812017-05-09 14:34:57 -07001959 addExistingConnection(phoneAccountHandle, connection, null /* conference */);
1960 }
1961
1962 /**
Pengquan Meng731c1a32017-11-21 18:01:13 -08001963 * Call to inform Telecom that your {@link ConnectionService} has released call resources (e.g
1964 * microphone, camera).
1965 *
1966 * @see ConnectionService#onConnectionServiceFocusLost()
1967 */
1968 public final void connectionServiceFocusReleased() {
1969 mAdapter.onConnectionServiceFocusReleased();
1970 }
1971
1972 /**
Tyler Gunn78da7812017-05-09 14:34:57 -07001973 * Adds a connection created by the {@link ConnectionService} and informs telecom of the new
1974 * connection.
1975 *
1976 * @param phoneAccountHandle The phone account handle for the connection.
1977 * @param connection The connection to add.
1978 * @param conference The parent conference of the new connection.
1979 * @hide
1980 */
1981 public final void addExistingConnection(PhoneAccountHandle phoneAccountHandle,
1982 Connection connection, Conference conference) {
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07001983
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001984 String id = addExistingConnectionInternal(phoneAccountHandle, connection);
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07001985 if (id != null) {
1986 List<String> emptyList = new ArrayList<>(0);
Tyler Gunn78da7812017-05-09 14:34:57 -07001987 String conferenceId = null;
1988 if (conference != null) {
1989 conferenceId = mIdByConference.get(conference);
1990 }
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07001991
1992 ParcelableConnection parcelableConnection = new ParcelableConnection(
1993 phoneAccountHandle,
1994 connection.getState(),
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001995 connection.getConnectionCapabilities(),
Tyler Gunn720c6642016-03-22 09:02:47 -07001996 connection.getConnectionProperties(),
Christine Hallstrom2830ce92016-11-30 16:06:42 -08001997 connection.getSupportedAudioRoutes(),
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07001998 connection.getAddress(),
1999 connection.getAddressPresentation(),
2000 connection.getCallerDisplayName(),
2001 connection.getCallerDisplayNamePresentation(),
2002 connection.getVideoProvider() == null ?
2003 null : connection.getVideoProvider().getInterface(),
2004 connection.getVideoState(),
2005 connection.isRingbackRequested(),
2006 connection.getAudioModeIsVoip(),
Roshan Piuse927ec02015-07-15 15:47:21 -07002007 connection.getConnectTimeMillis(),
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002008 connection.getConnectElapsedTimeMillis(),
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002009 connection.getStatusHints(),
2010 connection.getDisconnectCause(),
Santos Cordon6b7f9552015-05-27 17:21:45 -07002011 emptyList,
Tyler Gunn78da7812017-05-09 14:34:57 -07002012 connection.getExtras(),
2013 conferenceId);
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002014 mAdapter.addExistingConnection(id, parcelableConnection);
2015 }
2016 }
2017
2018 /**
Ihab Awadf8b69882014-07-25 15:14:01 -07002019 * Returns all the active {@code Connection}s for which this {@code ConnectionService}
2020 * has taken responsibility.
2021 *
2022 * @return A collection of {@code Connection}s created by this {@code ConnectionService}.
Santos Cordonb6939982014-06-04 20:20:58 -07002023 */
Sailesh Nepal091768c2014-06-30 15:15:23 -07002024 public final Collection<Connection> getAllConnections() {
Santos Cordonb6939982014-06-04 20:20:58 -07002025 return mConnectionById.values();
2026 }
2027
2028 /**
Santos Cordona6018b92016-02-16 14:23:12 -08002029 * Returns all the active {@code Conference}s for which this {@code ConnectionService}
2030 * has taken responsibility.
2031 *
2032 * @return A collection of {@code Conference}s created by this {@code ConnectionService}.
2033 */
2034 public final Collection<Conference> getAllConferences() {
2035 return mConferenceById.values();
2036 }
2037
2038 /**
Ihab Awadf8b69882014-07-25 15:14:01 -07002039 * Create a {@code Connection} given an incoming request. This is used to attach to existing
2040 * incoming calls.
Evan Charltonbf11f982014-07-20 22:06:28 -07002041 *
Ihab Awadf8b69882014-07-25 15:14:01 -07002042 * @param connectionManagerPhoneAccount See description at
2043 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
2044 * @param request Details about the incoming call.
2045 * @return The {@code Connection} object to satisfy this call, or {@code null} to
2046 * not handle the call.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002047 */
Ihab Awadf8b69882014-07-25 15:14:01 -07002048 public Connection onCreateIncomingConnection(
2049 PhoneAccountHandle connectionManagerPhoneAccount,
2050 ConnectionRequest request) {
2051 return null;
2052 }
Sailesh Nepalc5b01572014-07-14 16:29:44 -07002053
2054 /**
Tyler Gunn041a1fe2017-05-12 10:04:49 -07002055 * Called after the {@link Connection} returned by
2056 * {@link #onCreateIncomingConnection(PhoneAccountHandle, ConnectionRequest)}
2057 * or {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)} has been
2058 * added to the {@link ConnectionService} and sent to Telecom.
2059 *
2060 * @param connection the {@link Connection}.
2061 * @hide
2062 */
2063 public void onCreateConnectionComplete(Connection connection) {
2064 }
2065
2066 /**
Tyler Gunnf5035432017-01-09 09:43:12 -08002067 * Called by Telecom to inform the {@link ConnectionService} that its request to create a new
2068 * incoming {@link Connection} was denied.
2069 * <p>
2070 * Used when a self-managed {@link ConnectionService} attempts to create a new incoming
2071 * {@link Connection}, but Telecom has determined that the call cannot be allowed at this time.
2072 * The {@link ConnectionService} is responsible for silently rejecting the new incoming
2073 * {@link Connection}.
2074 * <p>
2075 * See {@link TelecomManager#isIncomingCallPermitted(PhoneAccountHandle)} for more information.
2076 *
Tyler Gunn159f35c2017-03-02 09:28:37 -08002077 * @param connectionManagerPhoneAccount See description at
2078 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
Tyler Gunnf5035432017-01-09 09:43:12 -08002079 * @param request The incoming connection request.
2080 */
Tyler Gunn159f35c2017-03-02 09:28:37 -08002081 public void onCreateIncomingConnectionFailed(PhoneAccountHandle connectionManagerPhoneAccount,
2082 ConnectionRequest request) {
Tyler Gunnf5035432017-01-09 09:43:12 -08002083 }
2084
2085 /**
2086 * Called by Telecom to inform the {@link ConnectionService} that its request to create a new
2087 * outgoing {@link Connection} was denied.
2088 * <p>
2089 * Used when a self-managed {@link ConnectionService} attempts to create a new outgoing
2090 * {@link Connection}, but Telecom has determined that the call cannot be placed at this time.
2091 * The {@link ConnectionService} is responisible for informing the user that the
2092 * {@link Connection} cannot be made at this time.
2093 * <p>
2094 * See {@link TelecomManager#isOutgoingCallPermitted(PhoneAccountHandle)} for more information.
2095 *
Tyler Gunn159f35c2017-03-02 09:28:37 -08002096 * @param connectionManagerPhoneAccount See description at
2097 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
Tyler Gunnf5035432017-01-09 09:43:12 -08002098 * @param request The outgoing connection request.
2099 */
Tyler Gunn159f35c2017-03-02 09:28:37 -08002100 public void onCreateOutgoingConnectionFailed(PhoneAccountHandle connectionManagerPhoneAccount,
2101 ConnectionRequest request) {
Tyler Gunnf5035432017-01-09 09:43:12 -08002102 }
2103
2104 /**
Shriram Ganesh6bf35ac2014-12-11 17:53:38 -08002105 * Trigger recalculate functinality for conference calls. This is used when a Telephony
2106 * Connection is part of a conference controller but is not yet added to Connection
2107 * Service and hence cannot be added to the conference call.
2108 *
2109 * @hide
2110 */
2111 public void triggerConferenceRecalculate() {
2112 }
2113
2114 /**
Ihab Awadf8b69882014-07-25 15:14:01 -07002115 * Create a {@code Connection} given an outgoing request. This is used to initiate new
2116 * outgoing calls.
Sailesh Nepalc5b01572014-07-14 16:29:44 -07002117 *
Ihab Awadf8b69882014-07-25 15:14:01 -07002118 * @param connectionManagerPhoneAccount The connection manager account to use for managing
2119 * this call.
2120 * <p>
2121 * If this parameter is not {@code null}, it means that this {@code ConnectionService}
2122 * has registered one or more {@code PhoneAccount}s having
2123 * {@link PhoneAccount#CAPABILITY_CONNECTION_MANAGER}. This parameter will contain
2124 * one of these {@code PhoneAccount}s, while the {@code request} will contain another
2125 * (usually but not always distinct) {@code PhoneAccount} to be used for actually
2126 * making the connection.
2127 * <p>
2128 * If this parameter is {@code null}, it means that this {@code ConnectionService} is
2129 * being asked to make a direct connection. The
2130 * {@link ConnectionRequest#getAccountHandle()} of parameter {@code request} will be
2131 * a {@code PhoneAccount} registered by this {@code ConnectionService} to use for
2132 * making the connection.
2133 * @param request Details about the outgoing call.
2134 * @return The {@code Connection} object to satisfy this call, or the result of an invocation
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002135 * of {@link Connection#createFailedConnection(DisconnectCause)} to not handle the call.
Sailesh Nepalc5b01572014-07-14 16:29:44 -07002136 */
Ihab Awadf8b69882014-07-25 15:14:01 -07002137 public Connection onCreateOutgoingConnection(
2138 PhoneAccountHandle connectionManagerPhoneAccount,
2139 ConnectionRequest request) {
2140 return null;
2141 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002142
2143 /**
Sanket Padawea8eddd42017-11-03 11:07:35 -07002144 * Called by Telecom on the initiating side of the handover to create an instance of a
2145 * handover connection.
2146 * @param fromPhoneAccountHandle {@link PhoneAccountHandle} associated with the
2147 * ConnectionService which needs to handover the call.
2148 * @param request Details about the call which needs to be handover.
2149 * @return Connection object corresponding to the handover call.
2150 */
2151 public Connection onCreateOutgoingHandoverConnection(PhoneAccountHandle fromPhoneAccountHandle,
2152 ConnectionRequest request) {
2153 return null;
2154 }
2155
2156 /**
2157 * Called by Telecom on the receiving side of the handover to request the
2158 * {@link ConnectionService} to create an instance of a handover connection.
2159 * @param fromPhoneAccountHandle {@link PhoneAccountHandle} associated with the
2160 * ConnectionService which needs to handover the call.
2161 * @param request Details about the call which needs to be handover.
2162 * @return {@link Connection} object corresponding to the handover call.
2163 */
2164 public Connection onCreateIncomingHandoverConnection(PhoneAccountHandle fromPhoneAccountHandle,
2165 ConnectionRequest request) {
2166 return null;
2167 }
2168
2169 /**
2170 * Called by Telecom in response to a {@code TelecomManager#acceptHandover()}
2171 * invocation which failed.
2172 * @param request Details about the call which needs to be handover.
2173 * @param error Reason for handover failure as defined in
2174 * {@link android.telecom.Call.Callback#HANDOVER_FAILURE_DEST_INVALID_PERM}
2175 */
2176 public void onHandoverFailed(ConnectionRequest request, int error) {
2177 return;
2178 }
2179
2180 /**
Yorke Leec3cf9822014-10-02 09:38:39 -07002181 * Create a {@code Connection} for a new unknown call. An unknown call is a call originating
2182 * from the ConnectionService that was neither a user-initiated outgoing call, nor an incoming
2183 * call created using
2184 * {@code TelecomManager#addNewIncomingCall(PhoneAccountHandle, android.os.Bundle)}.
2185 *
Yorke Lee770ed6e2014-10-06 18:58:52 -07002186 * @hide
Yorke Leec3cf9822014-10-02 09:38:39 -07002187 */
2188 public Connection onCreateUnknownConnection(PhoneAccountHandle connectionManagerPhoneAccount,
2189 ConnectionRequest request) {
Brad Ebingerb32d4f82016-10-24 16:40:49 -07002190 return null;
Yorke Leec3cf9822014-10-02 09:38:39 -07002191 }
2192
2193 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07002194 * Conference two specified connections. Invoked when the user has made a request to merge the
2195 * specified connections into a conference call. In response, the connection service should
2196 * create an instance of {@link Conference} and pass it into {@link #addConference}.
Santos Cordonb6939982014-06-04 20:20:58 -07002197 *
Santos Cordon823fd3c2014-08-07 18:35:18 -07002198 * @param connection1 A connection to merge into a conference call.
2199 * @param connection2 A connection to merge into a conference call.
Santos Cordonb6939982014-06-04 20:20:58 -07002200 */
Santos Cordon823fd3c2014-08-07 18:35:18 -07002201 public void onConference(Connection connection1, Connection connection2) {}
Santos Cordonb6939982014-06-04 20:20:58 -07002202
Santos Cordona663f862014-10-29 13:49:58 -07002203 /**
Pengquan Meng70c9885332017-10-02 18:09:03 -07002204 * Called when a connection is added.
2205 * @hide
2206 */
2207 public void onConnectionAdded(Connection connection) {}
2208
2209 /**
2210 * Called when a connection is removed.
2211 * @hide
2212 */
2213 public void onConnectionRemoved(Connection connection) {}
2214
2215 /**
2216 * Called when a conference is added.
2217 * @hide
2218 */
2219 public void onConferenceAdded(Conference conference) {}
2220
2221 /**
2222 * Called when a conference is removed.
2223 * @hide
2224 */
2225 public void onConferenceRemoved(Conference conference) {}
2226
2227 /**
Santos Cordona663f862014-10-29 13:49:58 -07002228 * Indicates that a remote conference has been created for existing {@link RemoteConnection}s.
2229 * When this method is invoked, this {@link ConnectionService} should create its own
2230 * representation of the conference call and send it to telecom using {@link #addConference}.
2231 * <p>
2232 * This is only relevant to {@link ConnectionService}s which are registered with
2233 * {@link PhoneAccount#CAPABILITY_CONNECTION_MANAGER}.
2234 *
2235 * @param conference The remote conference call.
2236 */
Ihab Awadb8e85c72014-08-23 20:34:57 -07002237 public void onRemoteConferenceAdded(RemoteConference conference) {}
2238
Santos Cordon823fd3c2014-08-07 18:35:18 -07002239 /**
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002240 * Called when an existing connection is added remotely.
2241 * @param connection The existing connection which was added.
2242 */
2243 public void onRemoteExistingConnectionAdded(RemoteConnection connection) {}
2244
2245 /**
Pengquan Meng731c1a32017-11-21 18:01:13 -08002246 * Called when the {@link ConnectionService} has lost the call focus.
2247 * The {@link ConnectionService} should release the call resources and invokes
2248 * {@link ConnectionService#connectionServiceFocusReleased()} to inform telecom that it has
2249 * released the call resources.
2250 */
2251 public void onConnectionServiceFocusLost() {}
2252
2253 /**
2254 * Called when the {@link ConnectionService} has gained the call focus. The
2255 * {@link ConnectionService} can acquire the call resources at this time.
2256 */
2257 public void onConnectionServiceFocusGained() {}
2258
2259 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07002260 * @hide
2261 */
2262 public boolean containsConference(Conference conference) {
2263 return mIdByConference.containsKey(conference);
2264 }
2265
Ihab Awadb8e85c72014-08-23 20:34:57 -07002266 /** {@hide} */
2267 void addRemoteConference(RemoteConference remoteConference) {
2268 onRemoteConferenceAdded(remoteConference);
2269 }
2270
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002271 /** {@hide} */
2272 void addRemoteExistingConnection(RemoteConnection remoteConnection) {
2273 onRemoteExistingConnectionAdded(remoteConnection);
2274 }
2275
Ihab Awad5d0410f2014-07-30 10:07:40 -07002276 private void onAccountsInitialized() {
2277 mAreAccountsInitialized = true;
2278 for (Runnable r : mPreInitializationConnectionRequests) {
2279 r.run();
2280 }
2281 mPreInitializationConnectionRequests.clear();
2282 }
2283
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002284 /**
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002285 * Adds an existing connection to the list of connections, identified by a new call ID unique
2286 * to this connection service.
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002287 *
2288 * @param connection The connection.
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002289 * @return The ID of the connection (e.g. the call-id).
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002290 */
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002291 private String addExistingConnectionInternal(PhoneAccountHandle handle, Connection connection) {
2292 String id;
Tyler Gunncd6ccfd2016-10-17 15:48:19 -07002293
2294 if (connection.getExtras() != null && connection.getExtras()
2295 .containsKey(Connection.EXTRA_ORIGINAL_CONNECTION_ID)) {
2296 id = connection.getExtras().getString(Connection.EXTRA_ORIGINAL_CONNECTION_ID);
2297 Log.d(this, "addExistingConnectionInternal - conn %s reusing original id %s",
2298 connection.getTelecomCallId(), id);
2299 } else if (handle == null) {
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002300 // If no phone account handle was provided, we cannot be sure the call ID is unique,
2301 // so just use a random UUID.
2302 id = UUID.randomUUID().toString();
2303 } else {
2304 // Phone account handle was provided, so use the ConnectionService class name as a
2305 // prefix for a unique incremental call ID.
2306 id = handle.getComponentName().getClassName() + "@" + getNextCallId();
2307 }
Pengquan Meng70c9885332017-10-02 18:09:03 -07002308 addConnection(handle, id, connection);
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002309 return id;
2310 }
2311
Pengquan Meng70c9885332017-10-02 18:09:03 -07002312 private void addConnection(PhoneAccountHandle handle, String callId, Connection connection) {
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002313 connection.setTelecomCallId(callId);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002314 mConnectionById.put(callId, connection);
2315 mIdByConnection.put(connection, callId);
2316 connection.addConnectionListener(mConnectionListener);
Santos Cordon823fd3c2014-08-07 18:35:18 -07002317 connection.setConnectionService(this);
Pengquan Meng70c9885332017-10-02 18:09:03 -07002318 connection.setPhoneAccountHandle(handle);
2319 onConnectionAdded(connection);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002320 }
2321
Anthony Lee30e65842014-11-06 16:30:53 -08002322 /** {@hide} */
2323 protected void removeConnection(Connection connection) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07002324 connection.unsetConnectionService(this);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002325 connection.removeConnectionListener(mConnectionListener);
Chenjie Luoe370b532016-05-12 16:59:43 -07002326 String id = mIdByConnection.get(connection);
2327 if (id != null) {
2328 mConnectionById.remove(id);
2329 mIdByConnection.remove(connection);
2330 mAdapter.removeCall(id);
Pengquan Meng70c9885332017-10-02 18:09:03 -07002331 onConnectionRemoved(connection);
Chenjie Luoe370b532016-05-12 16:59:43 -07002332 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002333 }
2334
Santos Cordon823fd3c2014-08-07 18:35:18 -07002335 private String addConferenceInternal(Conference conference) {
Tyler Gunncd6ccfd2016-10-17 15:48:19 -07002336 String originalId = null;
2337 if (conference.getExtras() != null && conference.getExtras()
2338 .containsKey(Connection.EXTRA_ORIGINAL_CONNECTION_ID)) {
2339 originalId = conference.getExtras().getString(Connection.EXTRA_ORIGINAL_CONNECTION_ID);
2340 Log.d(this, "addConferenceInternal: conf %s reusing original id %s",
2341 conference.getTelecomCallId(),
2342 originalId);
2343 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07002344 if (mIdByConference.containsKey(conference)) {
2345 Log.w(this, "Re-adding an existing conference: %s.", conference);
2346 } else if (conference != null) {
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002347 // Conferences do not (yet) have a PhoneAccountHandle associated with them, so we
2348 // cannot determine a ConnectionService class name to associate with the ID, so use
2349 // a unique UUID (for now).
Tyler Gunncd6ccfd2016-10-17 15:48:19 -07002350 String id = originalId == null ? UUID.randomUUID().toString() : originalId;
Santos Cordon823fd3c2014-08-07 18:35:18 -07002351 mConferenceById.put(id, conference);
2352 mIdByConference.put(conference, id);
2353 conference.addListener(mConferenceListener);
2354 return id;
2355 }
2356
2357 return null;
2358 }
2359
2360 private void removeConference(Conference conference) {
2361 if (mIdByConference.containsKey(conference)) {
2362 conference.removeListener(mConferenceListener);
2363
2364 String id = mIdByConference.get(conference);
2365 mConferenceById.remove(id);
2366 mIdByConference.remove(conference);
2367 mAdapter.removeCall(id);
Pengquan Meng70c9885332017-10-02 18:09:03 -07002368
2369 onConferenceRemoved(conference);
Santos Cordon823fd3c2014-08-07 18:35:18 -07002370 }
2371 }
2372
Ihab Awad542e0ea2014-05-16 10:22:16 -07002373 private Connection findConnectionForAction(String callId, String action) {
Tyler Gunn0a88f2e2017-06-16 20:20:34 -07002374 if (callId != null && mConnectionById.containsKey(callId)) {
Ihab Awad542e0ea2014-05-16 10:22:16 -07002375 return mConnectionById.get(callId);
2376 }
Ihab Awad60ac30b2014-05-20 22:32:12 -07002377 Log.w(this, "%s - Cannot find Connection %s", action, callId);
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07002378 return getNullConnection();
2379 }
2380
2381 static synchronized Connection getNullConnection() {
2382 if (sNullConnection == null) {
2383 sNullConnection = new Connection() {};
2384 }
2385 return sNullConnection;
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002386 }
Santos Cordon0159ac02014-08-21 14:28:11 -07002387
2388 private Conference findConferenceForAction(String conferenceId, String action) {
2389 if (mConferenceById.containsKey(conferenceId)) {
2390 return mConferenceById.get(conferenceId);
2391 }
2392 Log.w(this, "%s - Cannot find conference %s", action, conferenceId);
2393 return getNullConference();
2394 }
2395
Ihab Awadb8e85c72014-08-23 20:34:57 -07002396 private List<String> createConnectionIdList(List<Connection> connections) {
2397 List<String> ids = new ArrayList<>();
2398 for (Connection c : connections) {
2399 if (mIdByConnection.containsKey(c)) {
2400 ids.add(mIdByConnection.get(c));
2401 }
2402 }
2403 Collections.sort(ids);
2404 return ids;
2405 }
2406
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002407 /**
2408 * Builds a list of {@link Connection} and {@link Conference} IDs based on the list of
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002409 * {@link Conferenceable}s passed in.
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002410 *
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002411 * @param conferenceables The {@link Conferenceable} connections and conferences.
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002412 * @return List of string conference and call Ids.
2413 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002414 private List<String> createIdList(List<Conferenceable> conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002415 List<String> ids = new ArrayList<>();
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002416 for (Conferenceable c : conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002417 // Only allow Connection and Conference conferenceables.
2418 if (c instanceof Connection) {
2419 Connection connection = (Connection) c;
2420 if (mIdByConnection.containsKey(connection)) {
2421 ids.add(mIdByConnection.get(connection));
2422 }
2423 } else if (c instanceof Conference) {
2424 Conference conference = (Conference) c;
2425 if (mIdByConference.containsKey(conference)) {
2426 ids.add(mIdByConference.get(conference));
2427 }
2428 }
2429 }
2430 Collections.sort(ids);
2431 return ids;
2432 }
2433
Santos Cordon0159ac02014-08-21 14:28:11 -07002434 private Conference getNullConference() {
2435 if (sNullConference == null) {
2436 sNullConference = new Conference(null) {};
2437 }
2438 return sNullConference;
2439 }
Santos Cordon29f2f2e2014-09-11 19:50:24 -07002440
2441 private void endAllConnections() {
2442 // Unbound from telecomm. We should end all connections and conferences.
2443 for (Connection connection : mIdByConnection.keySet()) {
2444 // only operate on top-level calls. Conference calls will be removed on their own.
2445 if (connection.getConference() == null) {
2446 connection.onDisconnect();
2447 }
2448 }
2449 for (Conference conference : mIdByConference.keySet()) {
2450 conference.onDisconnect();
2451 }
2452 }
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002453
2454 /**
2455 * Retrieves the next call ID as maintainted by the connection service.
2456 *
2457 * @return The call ID.
2458 */
2459 private int getNextCallId() {
Brad Ebingerb32d4f82016-10-24 16:40:49 -07002460 synchronized (mIdSyncRoot) {
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002461 return ++mId;
2462 }
2463 }
Santos Cordon980acb92014-05-31 10:31:19 -07002464}