blob: 618c46117cf5a1e561076f0504cb49ce9e98b64b [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";
Pooja Jaind34698d2017-12-28 14:15:31 +0530127 private static final String SESSION_DEFLECT = "CS.def";
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700128 private static final String SESSION_REJECT = "CS.r";
129 private static final String SESSION_REJECT_MESSAGE = "CS.rWM";
130 private static final String SESSION_SILENCE = "CS.s";
131 private static final String SESSION_DISCONNECT = "CS.d";
132 private static final String SESSION_HOLD = "CS.h";
133 private static final String SESSION_UNHOLD = "CS.u";
134 private static final String SESSION_CALL_AUDIO_SC = "CS.cASC";
135 private static final String SESSION_PLAY_DTMF = "CS.pDT";
136 private static final String SESSION_STOP_DTMF = "CS.sDT";
137 private static final String SESSION_CONFERENCE = "CS.c";
138 private static final String SESSION_SPLIT_CONFERENCE = "CS.sFC";
139 private static final String SESSION_MERGE_CONFERENCE = "CS.mC";
140 private static final String SESSION_SWAP_CONFERENCE = "CS.sC";
141 private static final String SESSION_POST_DIAL_CONT = "CS.oPDC";
142 private static final String SESSION_PULL_EXTERNAL_CALL = "CS.pEC";
143 private static final String SESSION_SEND_CALL_EVENT = "CS.sCE";
Tyler Gunn79bc1ec2018-01-22 15:17:54 -0800144 private static final String SESSION_HANDOVER_COMPLETE = "CS.hC";
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700145 private static final String SESSION_EXTRAS_CHANGED = "CS.oEC";
Hall Liub64ac4c2017-02-06 10:49:48 -0800146 private static final String SESSION_START_RTT = "CS.+RTT";
Hall Liua549fed2018-02-09 16:40:03 -0800147 private static final String SESSION_UPDATE_RTT_PIPES = "CS.uRTT";
Hall Liub64ac4c2017-02-06 10:49:48 -0800148 private static final String SESSION_STOP_RTT = "CS.-RTT";
149 private static final String SESSION_RTT_UPGRADE_RESPONSE = "CS.rTRUR";
Pengquan Meng731c1a32017-11-21 18:01:13 -0800150 private static final String SESSION_CONNECTION_SERVICE_FOCUS_LOST = "CS.cSFL";
151 private static final String SESSION_CONNECTION_SERVICE_FOCUS_GAINED = "CS.cSFG";
Sanket Padawe4cc8ed52017-12-04 16:22:20 -0800152 private static final String SESSION_HANDOVER_FAILED = "CS.haF";
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700153
Ihab Awad8aecfed2014-08-08 17:06:11 -0700154 private static final int MSG_ADD_CONNECTION_SERVICE_ADAPTER = 1;
Sailesh Nepalc5b01572014-07-14 16:29:44 -0700155 private static final int MSG_CREATE_CONNECTION = 2;
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700156 private static final int MSG_ABORT = 3;
Sailesh Nepalc5b01572014-07-14 16:29:44 -0700157 private static final int MSG_ANSWER = 4;
158 private static final int MSG_REJECT = 5;
159 private static final int MSG_DISCONNECT = 6;
160 private static final int MSG_HOLD = 7;
161 private static final int MSG_UNHOLD = 8;
Yorke Lee4af59352015-05-13 14:14:54 -0700162 private static final int MSG_ON_CALL_AUDIO_STATE_CHANGED = 9;
Sailesh Nepalc5b01572014-07-14 16:29:44 -0700163 private static final int MSG_PLAY_DTMF_TONE = 10;
164 private static final int MSG_STOP_DTMF_TONE = 11;
165 private static final int MSG_CONFERENCE = 12;
166 private static final int MSG_SPLIT_FROM_CONFERENCE = 13;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700167 private static final int MSG_ON_POST_DIAL_CONTINUE = 14;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700168 private static final int MSG_REMOVE_CONNECTION_SERVICE_ADAPTER = 16;
Tyler Gunnbe74de02014-08-29 14:51:48 -0700169 private static final int MSG_ANSWER_VIDEO = 17;
Santos Cordona4868042014-09-04 17:39:22 -0700170 private static final int MSG_MERGE_CONFERENCE = 18;
171 private static final int MSG_SWAP_CONFERENCE = 19;
Bryce Lee81901682015-08-28 16:38:02 -0700172 private static final int MSG_REJECT_WITH_MESSAGE = 20;
Bryce Leecac50772015-11-17 15:13:29 -0800173 private static final int MSG_SILENCE = 21;
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700174 private static final int MSG_PULL_EXTERNAL_CALL = 22;
175 private static final int MSG_SEND_CALL_EVENT = 23;
Tyler Gunndee56a82016-03-23 16:06:34 -0700176 private static final int MSG_ON_EXTRAS_CHANGED = 24;
Tyler Gunn44e01912017-01-31 10:49:05 -0800177 private static final int MSG_CREATE_CONNECTION_FAILED = 25;
Hall Liub64ac4c2017-02-06 10:49:48 -0800178 private static final int MSG_ON_START_RTT = 26;
179 private static final int MSG_ON_STOP_RTT = 27;
180 private static final int MSG_RTT_UPGRADE_RESPONSE = 28;
Tyler Gunn041a1fe2017-05-12 10:04:49 -0700181 private static final int MSG_CREATE_CONNECTION_COMPLETE = 29;
Pengquan Meng731c1a32017-11-21 18:01:13 -0800182 private static final int MSG_CONNECTION_SERVICE_FOCUS_LOST = 30;
183 private static final int MSG_CONNECTION_SERVICE_FOCUS_GAINED = 31;
Sanket Padawe4cc8ed52017-12-04 16:22:20 -0800184 private static final int MSG_HANDOVER_FAILED = 32;
Tyler Gunn79bc1ec2018-01-22 15:17:54 -0800185 private static final int MSG_HANDOVER_COMPLETE = 33;
Pooja Jaind34698d2017-12-28 14:15:31 +0530186 private static final int MSG_DEFLECT = 34;
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700187
Sailesh Nepalcf7020b2014-08-20 10:07:19 -0700188 private static Connection sNullConnection;
189
mike dooley95e80702014-09-18 14:07:52 -0700190 private final Map<String, Connection> mConnectionById = new ConcurrentHashMap<>();
191 private final Map<Connection, String> mIdByConnection = new ConcurrentHashMap<>();
192 private final Map<String, Conference> mConferenceById = new ConcurrentHashMap<>();
193 private final Map<Conference, String> mIdByConference = new ConcurrentHashMap<>();
Ihab Awadb8e85c72014-08-23 20:34:57 -0700194 private final RemoteConnectionManager mRemoteConnectionManager =
195 new RemoteConnectionManager(this);
Ihab Awad5d0410f2014-07-30 10:07:40 -0700196 private final List<Runnable> mPreInitializationConnectionRequests = new ArrayList<>();
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700197 private final ConnectionServiceAdapter mAdapter = new ConnectionServiceAdapter();
Ihab Awad542e0ea2014-05-16 10:22:16 -0700198
Santos Cordon823fd3c2014-08-07 18:35:18 -0700199 private boolean mAreAccountsInitialized = false;
Santos Cordon0159ac02014-08-21 14:28:11 -0700200 private Conference sNullConference;
Tyler Gunnf0500bd2015-09-01 10:59:48 -0700201 private Object mIdSyncRoot = new Object();
202 private int mId = 0;
Santos Cordon823fd3c2014-08-07 18:35:18 -0700203
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700204 private final IBinder mBinder = new IConnectionService.Stub() {
205 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700206 public void addConnectionServiceAdapter(IConnectionServiceAdapter adapter,
207 Session.Info sessionInfo) {
208 Log.startSession(sessionInfo, SESSION_ADD_CS_ADAPTER);
209 try {
210 SomeArgs args = SomeArgs.obtain();
211 args.arg1 = adapter;
212 args.arg2 = Log.createSubsession();
213 mHandler.obtainMessage(MSG_ADD_CONNECTION_SERVICE_ADAPTER, args).sendToTarget();
214 } finally {
215 Log.endSession();
216 }
Ihab Awad8aecfed2014-08-08 17:06:11 -0700217 }
218
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700219 public void removeConnectionServiceAdapter(IConnectionServiceAdapter adapter,
220 Session.Info sessionInfo) {
221 Log.startSession(sessionInfo, SESSION_REMOVE_CS_ADAPTER);
222 try {
223 SomeArgs args = SomeArgs.obtain();
224 args.arg1 = adapter;
225 args.arg2 = Log.createSubsession();
226 mHandler.obtainMessage(MSG_REMOVE_CONNECTION_SERVICE_ADAPTER, args).sendToTarget();
227 } finally {
228 Log.endSession();
229 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700230 }
231
232 @Override
Ihab Awadf8b69882014-07-25 15:14:01 -0700233 public void createConnection(
234 PhoneAccountHandle connectionManagerPhoneAccount,
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700235 String id,
Ihab Awadf8b69882014-07-25 15:14:01 -0700236 ConnectionRequest request,
Yorke Leec3cf9822014-10-02 09:38:39 -0700237 boolean isIncoming,
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700238 boolean isUnknown,
239 Session.Info sessionInfo) {
240 Log.startSession(sessionInfo, SESSION_CREATE_CONN);
241 try {
242 SomeArgs args = SomeArgs.obtain();
243 args.arg1 = connectionManagerPhoneAccount;
244 args.arg2 = id;
245 args.arg3 = request;
246 args.arg4 = Log.createSubsession();
247 args.argi1 = isIncoming ? 1 : 0;
248 args.argi2 = isUnknown ? 1 : 0;
249 mHandler.obtainMessage(MSG_CREATE_CONNECTION, args).sendToTarget();
250 } finally {
251 Log.endSession();
252 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700253 }
254
255 @Override
Tyler Gunn041a1fe2017-05-12 10:04:49 -0700256 public void createConnectionComplete(String id, Session.Info sessionInfo) {
257 Log.startSession(sessionInfo, SESSION_CREATE_CONN_COMPLETE);
258 try {
259 SomeArgs args = SomeArgs.obtain();
260 args.arg1 = id;
261 args.arg2 = Log.createSubsession();
262 mHandler.obtainMessage(MSG_CREATE_CONNECTION_COMPLETE, args).sendToTarget();
263 } finally {
264 Log.endSession();
265 }
266 }
267
268 @Override
Tyler Gunn44e01912017-01-31 10:49:05 -0800269 public void createConnectionFailed(
Tyler Gunn159f35c2017-03-02 09:28:37 -0800270 PhoneAccountHandle connectionManagerPhoneAccount,
Tyler Gunn44e01912017-01-31 10:49:05 -0800271 String callId,
272 ConnectionRequest request,
273 boolean isIncoming,
274 Session.Info sessionInfo) {
275 Log.startSession(sessionInfo, SESSION_CREATE_CONN_FAILED);
276 try {
277 SomeArgs args = SomeArgs.obtain();
278 args.arg1 = callId;
279 args.arg2 = request;
280 args.arg3 = Log.createSubsession();
Tyler Gunn159f35c2017-03-02 09:28:37 -0800281 args.arg4 = connectionManagerPhoneAccount;
Tyler Gunn44e01912017-01-31 10:49:05 -0800282 args.argi1 = isIncoming ? 1 : 0;
283 mHandler.obtainMessage(MSG_CREATE_CONNECTION_FAILED, args).sendToTarget();
284 } finally {
285 Log.endSession();
286 }
287 }
288
289 @Override
Sanket Padawe4cc8ed52017-12-04 16:22:20 -0800290 public void handoverFailed(String callId, ConnectionRequest request, int reason,
291 Session.Info sessionInfo) {
292 Log.startSession(sessionInfo, SESSION_HANDOVER_FAILED);
293 try {
294 SomeArgs args = SomeArgs.obtain();
295 args.arg1 = callId;
296 args.arg2 = request;
297 args.arg3 = Log.createSubsession();
298 args.arg4 = reason;
299 mHandler.obtainMessage(MSG_HANDOVER_FAILED, args).sendToTarget();
300 } finally {
301 Log.endSession();
302 }
303 }
304
305 @Override
Tyler Gunn79bc1ec2018-01-22 15:17:54 -0800306 public void handoverComplete(String callId, Session.Info sessionInfo) {
307 Log.startSession(sessionInfo, SESSION_HANDOVER_COMPLETE);
308 try {
309 SomeArgs args = SomeArgs.obtain();
310 args.arg1 = callId;
311 args.arg2 = Log.createSubsession();
312 mHandler.obtainMessage(MSG_HANDOVER_COMPLETE, args).sendToTarget();
313 } finally {
314 Log.endSession();
315 }
316 }
317
318 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700319 public void abort(String callId, Session.Info sessionInfo) {
320 Log.startSession(sessionInfo, SESSION_ABORT);
321 try {
322 SomeArgs args = SomeArgs.obtain();
323 args.arg1 = callId;
324 args.arg2 = Log.createSubsession();
325 mHandler.obtainMessage(MSG_ABORT, args).sendToTarget();
326 } finally {
327 Log.endSession();
328 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700329 }
330
331 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700332 public void answerVideo(String callId, int videoState, Session.Info sessionInfo) {
333 Log.startSession(sessionInfo, SESSION_ANSWER_VIDEO);
334 try {
335 SomeArgs args = SomeArgs.obtain();
336 args.arg1 = callId;
337 args.arg2 = Log.createSubsession();
338 args.argi1 = videoState;
339 mHandler.obtainMessage(MSG_ANSWER_VIDEO, args).sendToTarget();
340 } finally {
341 Log.endSession();
342 }
Tyler Gunnbe74de02014-08-29 14:51:48 -0700343 }
344
345 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700346 public void answer(String callId, Session.Info sessionInfo) {
347 Log.startSession(sessionInfo, SESSION_ANSWER);
348 try {
349 SomeArgs args = SomeArgs.obtain();
350 args.arg1 = callId;
351 args.arg2 = Log.createSubsession();
352 mHandler.obtainMessage(MSG_ANSWER, args).sendToTarget();
353 } finally {
354 Log.endSession();
355 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700356 }
357
358 @Override
Pooja Jaind34698d2017-12-28 14:15:31 +0530359 public void deflect(String callId, Uri address, Session.Info sessionInfo) {
360 Log.startSession(sessionInfo, SESSION_DEFLECT);
361 try {
362 SomeArgs args = SomeArgs.obtain();
363 args.arg1 = callId;
364 args.arg2 = address;
365 args.arg3 = Log.createSubsession();
366 mHandler.obtainMessage(MSG_DEFLECT, args).sendToTarget();
367 } finally {
368 Log.endSession();
369 }
370 }
371
372 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700373 public void reject(String callId, Session.Info sessionInfo) {
374 Log.startSession(sessionInfo, SESSION_REJECT);
375 try {
376 SomeArgs args = SomeArgs.obtain();
377 args.arg1 = callId;
378 args.arg2 = Log.createSubsession();
379 mHandler.obtainMessage(MSG_REJECT, args).sendToTarget();
380 } finally {
381 Log.endSession();
382 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700383 }
384
385 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700386 public void rejectWithMessage(String callId, String message, Session.Info sessionInfo) {
387 Log.startSession(sessionInfo, SESSION_REJECT_MESSAGE);
388 try {
389 SomeArgs args = SomeArgs.obtain();
390 args.arg1 = callId;
391 args.arg2 = message;
392 args.arg3 = Log.createSubsession();
393 mHandler.obtainMessage(MSG_REJECT_WITH_MESSAGE, args).sendToTarget();
394 } finally {
395 Log.endSession();
396 }
Bryce Lee81901682015-08-28 16:38:02 -0700397 }
398
399 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700400 public void silence(String callId, Session.Info sessionInfo) {
401 Log.startSession(sessionInfo, SESSION_SILENCE);
402 try {
403 SomeArgs args = SomeArgs.obtain();
404 args.arg1 = callId;
405 args.arg2 = Log.createSubsession();
406 mHandler.obtainMessage(MSG_SILENCE, args).sendToTarget();
407 } finally {
408 Log.endSession();
409 }
Bryce Leecac50772015-11-17 15:13:29 -0800410 }
411
412 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700413 public void disconnect(String callId, Session.Info sessionInfo) {
414 Log.startSession(sessionInfo, SESSION_DISCONNECT);
415 try {
416 SomeArgs args = SomeArgs.obtain();
417 args.arg1 = callId;
418 args.arg2 = Log.createSubsession();
419 mHandler.obtainMessage(MSG_DISCONNECT, args).sendToTarget();
420 } finally {
421 Log.endSession();
422 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700423 }
424
425 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700426 public void hold(String callId, Session.Info sessionInfo) {
427 Log.startSession(sessionInfo, SESSION_HOLD);
428 try {
429 SomeArgs args = SomeArgs.obtain();
430 args.arg1 = callId;
431 args.arg2 = Log.createSubsession();
432 mHandler.obtainMessage(MSG_HOLD, args).sendToTarget();
433 } finally {
434 Log.endSession();
435 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700436 }
437
438 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700439 public void unhold(String callId, Session.Info sessionInfo) {
440 Log.startSession(sessionInfo, SESSION_UNHOLD);
441 try {
442 SomeArgs args = SomeArgs.obtain();
443 args.arg1 = callId;
444 args.arg2 = Log.createSubsession();
445 mHandler.obtainMessage(MSG_UNHOLD, args).sendToTarget();
446 } finally {
447 Log.endSession();
448 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700449 }
450
451 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700452 public void onCallAudioStateChanged(String callId, CallAudioState callAudioState,
453 Session.Info sessionInfo) {
454 Log.startSession(sessionInfo, SESSION_CALL_AUDIO_SC);
455 try {
456 SomeArgs args = SomeArgs.obtain();
457 args.arg1 = callId;
458 args.arg2 = callAudioState;
459 args.arg3 = Log.createSubsession();
460 mHandler.obtainMessage(MSG_ON_CALL_AUDIO_STATE_CHANGED, args).sendToTarget();
461 } finally {
462 Log.endSession();
463 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700464 }
465
466 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700467 public void playDtmfTone(String callId, char digit, Session.Info sessionInfo) {
468 Log.startSession(sessionInfo, SESSION_PLAY_DTMF);
469 try {
470 SomeArgs args = SomeArgs.obtain();
471 args.arg1 = digit;
472 args.arg2 = callId;
473 args.arg3 = Log.createSubsession();
474 mHandler.obtainMessage(MSG_PLAY_DTMF_TONE, args).sendToTarget();
475 } finally {
476 Log.endSession();
477 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700478 }
479
480 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700481 public void stopDtmfTone(String callId, Session.Info sessionInfo) {
482 Log.startSession(sessionInfo, SESSION_STOP_DTMF);
483 try {
484 SomeArgs args = SomeArgs.obtain();
485 args.arg1 = callId;
486 args.arg2 = Log.createSubsession();
487 mHandler.obtainMessage(MSG_STOP_DTMF_TONE, args).sendToTarget();
488 } finally {
489 Log.endSession();
490 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700491 }
492
493 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700494 public void conference(String callId1, String callId2, Session.Info sessionInfo) {
495 Log.startSession(sessionInfo, SESSION_CONFERENCE);
496 try {
497 SomeArgs args = SomeArgs.obtain();
498 args.arg1 = callId1;
499 args.arg2 = callId2;
500 args.arg3 = Log.createSubsession();
501 mHandler.obtainMessage(MSG_CONFERENCE, args).sendToTarget();
502 } finally {
503 Log.endSession();
504 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700505 }
506
507 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700508 public void splitFromConference(String callId, Session.Info sessionInfo) {
509 Log.startSession(sessionInfo, SESSION_SPLIT_CONFERENCE);
510 try {
511 SomeArgs args = SomeArgs.obtain();
512 args.arg1 = callId;
513 args.arg2 = Log.createSubsession();
514 mHandler.obtainMessage(MSG_SPLIT_FROM_CONFERENCE, args).sendToTarget();
515 } finally {
516 Log.endSession();
517 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700518 }
519
520 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700521 public void mergeConference(String callId, Session.Info sessionInfo) {
522 Log.startSession(sessionInfo, SESSION_MERGE_CONFERENCE);
523 try {
524 SomeArgs args = SomeArgs.obtain();
525 args.arg1 = callId;
526 args.arg2 = Log.createSubsession();
527 mHandler.obtainMessage(MSG_MERGE_CONFERENCE, args).sendToTarget();
528 } finally {
529 Log.endSession();
530 }
Santos Cordona4868042014-09-04 17:39:22 -0700531 }
532
533 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700534 public void swapConference(String callId, Session.Info sessionInfo) {
535 Log.startSession(sessionInfo, SESSION_SWAP_CONFERENCE);
536 try {
537 SomeArgs args = SomeArgs.obtain();
538 args.arg1 = callId;
539 args.arg2 = Log.createSubsession();
540 mHandler.obtainMessage(MSG_SWAP_CONFERENCE, args).sendToTarget();
541 } finally {
542 Log.endSession();
543 }
Santos Cordona4868042014-09-04 17:39:22 -0700544 }
545
546 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700547 public void onPostDialContinue(String callId, boolean proceed, Session.Info sessionInfo) {
548 Log.startSession(sessionInfo, SESSION_POST_DIAL_CONT);
549 try {
550 SomeArgs args = SomeArgs.obtain();
551 args.arg1 = callId;
552 args.arg2 = Log.createSubsession();
553 args.argi1 = proceed ? 1 : 0;
554 mHandler.obtainMessage(MSG_ON_POST_DIAL_CONTINUE, args).sendToTarget();
555 } finally {
556 Log.endSession();
557 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700558 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700559
560 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700561 public void pullExternalCall(String callId, Session.Info sessionInfo) {
562 Log.startSession(sessionInfo, SESSION_PULL_EXTERNAL_CALL);
563 try {
564 SomeArgs args = SomeArgs.obtain();
565 args.arg1 = callId;
566 args.arg2 = Log.createSubsession();
567 mHandler.obtainMessage(MSG_PULL_EXTERNAL_CALL, args).sendToTarget();
568 } finally {
569 Log.endSession();
570 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700571 }
572
573 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700574 public void sendCallEvent(String callId, String event, Bundle extras,
575 Session.Info sessionInfo) {
576 Log.startSession(sessionInfo, SESSION_SEND_CALL_EVENT);
577 try {
578 SomeArgs args = SomeArgs.obtain();
579 args.arg1 = callId;
580 args.arg2 = event;
581 args.arg3 = extras;
582 args.arg4 = Log.createSubsession();
583 mHandler.obtainMessage(MSG_SEND_CALL_EVENT, args).sendToTarget();
584 } finally {
585 Log.endSession();
586 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700587 }
Tyler Gunndee56a82016-03-23 16:06:34 -0700588
589 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700590 public void onExtrasChanged(String callId, Bundle extras, Session.Info sessionInfo) {
591 Log.startSession(sessionInfo, SESSION_EXTRAS_CHANGED);
592 try {
593 SomeArgs args = SomeArgs.obtain();
594 args.arg1 = callId;
595 args.arg2 = extras;
596 args.arg3 = Log.createSubsession();
597 mHandler.obtainMessage(MSG_ON_EXTRAS_CHANGED, args).sendToTarget();
598 } finally {
599 Log.endSession();
600 }
Tyler Gunndee56a82016-03-23 16:06:34 -0700601 }
Hall Liub64ac4c2017-02-06 10:49:48 -0800602
603 @Override
604 public void startRtt(String callId, ParcelFileDescriptor fromInCall,
605 ParcelFileDescriptor toInCall, Session.Info sessionInfo) throws RemoteException {
606 Log.startSession(sessionInfo, SESSION_START_RTT);
607 try {
608 SomeArgs args = SomeArgs.obtain();
609 args.arg1 = callId;
610 args.arg2 = new Connection.RttTextStream(toInCall, fromInCall);
611 args.arg3 = Log.createSubsession();
612 mHandler.obtainMessage(MSG_ON_START_RTT, args).sendToTarget();
613 } finally {
614 Log.endSession();
615 }
616 }
617
618 @Override
619 public void stopRtt(String callId, Session.Info sessionInfo) throws RemoteException {
620 Log.startSession(sessionInfo, SESSION_STOP_RTT);
621 try {
622 SomeArgs args = SomeArgs.obtain();
623 args.arg1 = callId;
624 args.arg2 = Log.createSubsession();
625 mHandler.obtainMessage(MSG_ON_STOP_RTT, args).sendToTarget();
626 } finally {
627 Log.endSession();
628 }
629 }
630
631 @Override
632 public void respondToRttUpgradeRequest(String callId, ParcelFileDescriptor fromInCall,
633 ParcelFileDescriptor toInCall, Session.Info sessionInfo) throws RemoteException {
634 Log.startSession(sessionInfo, SESSION_RTT_UPGRADE_RESPONSE);
635 try {
636 SomeArgs args = SomeArgs.obtain();
637 args.arg1 = callId;
638 if (toInCall == null || fromInCall == null) {
639 args.arg2 = null;
640 } else {
641 args.arg2 = new Connection.RttTextStream(toInCall, fromInCall);
642 }
643 args.arg3 = Log.createSubsession();
644 mHandler.obtainMessage(MSG_RTT_UPGRADE_RESPONSE, args).sendToTarget();
645 } finally {
646 Log.endSession();
647 }
648 }
Pengquan Meng731c1a32017-11-21 18:01:13 -0800649
650 @Override
651 public void connectionServiceFocusLost(Session.Info sessionInfo) throws RemoteException {
652 Log.startSession(sessionInfo, SESSION_CONNECTION_SERVICE_FOCUS_LOST);
653 try {
654 mHandler.obtainMessage(MSG_CONNECTION_SERVICE_FOCUS_LOST).sendToTarget();
655 } finally {
656 Log.endSession();
657 }
658 }
659
660 @Override
661 public void connectionServiceFocusGained(Session.Info sessionInfo) throws RemoteException {
662 Log.startSession(sessionInfo, SESSION_CONNECTION_SERVICE_FOCUS_GAINED);
663 try {
664 mHandler.obtainMessage(MSG_CONNECTION_SERVICE_FOCUS_GAINED).sendToTarget();
665 } finally {
666 Log.endSession();
667 }
668 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700669 };
670
671 private final Handler mHandler = new Handler(Looper.getMainLooper()) {
672 @Override
673 public void handleMessage(Message msg) {
674 switch (msg.what) {
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700675 case MSG_ADD_CONNECTION_SERVICE_ADAPTER: {
676 SomeArgs args = (SomeArgs) msg.obj;
677 try {
678 IConnectionServiceAdapter adapter = (IConnectionServiceAdapter) args.arg1;
679 Log.continueSession((Session) args.arg2,
680 SESSION_HANDLER + SESSION_ADD_CS_ADAPTER);
681 mAdapter.addAdapter(adapter);
682 onAdapterAttached();
683 } finally {
684 args.recycle();
685 Log.endSession();
686 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700687 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700688 }
689 case MSG_REMOVE_CONNECTION_SERVICE_ADAPTER: {
690 SomeArgs args = (SomeArgs) msg.obj;
691 try {
692 Log.continueSession((Session) args.arg2,
693 SESSION_HANDLER + SESSION_REMOVE_CS_ADAPTER);
694 mAdapter.removeAdapter((IConnectionServiceAdapter) args.arg1);
695 } finally {
696 args.recycle();
697 Log.endSession();
698 }
Ihab Awad8aecfed2014-08-08 17:06:11 -0700699 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700700 }
Ihab Awadf8b69882014-07-25 15:14:01 -0700701 case MSG_CREATE_CONNECTION: {
702 SomeArgs args = (SomeArgs) msg.obj;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700703 Log.continueSession((Session) args.arg4, SESSION_HANDLER + SESSION_CREATE_CONN);
Ihab Awadf8b69882014-07-25 15:14:01 -0700704 try {
Ihab Awad5d0410f2014-07-30 10:07:40 -0700705 final PhoneAccountHandle connectionManagerPhoneAccount =
Ihab Awadf8b69882014-07-25 15:14:01 -0700706 (PhoneAccountHandle) args.arg1;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700707 final String id = (String) args.arg2;
708 final ConnectionRequest request = (ConnectionRequest) args.arg3;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700709 final boolean isIncoming = args.argi1 == 1;
Yorke Leec3cf9822014-10-02 09:38:39 -0700710 final boolean isUnknown = args.argi2 == 1;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700711 if (!mAreAccountsInitialized) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700712 Log.d(this, "Enqueueing pre-init request %s", id);
Brad Ebinger0c3541b2016-11-01 14:11:38 -0700713 mPreInitializationConnectionRequests.add(
714 new android.telecom.Logging.Runnable(
715 SESSION_HANDLER + SESSION_CREATE_CONN + ".pICR",
716 null /*lock*/) {
Ihab Awad5d0410f2014-07-30 10:07:40 -0700717 @Override
Brad Ebinger0c3541b2016-11-01 14:11:38 -0700718 public void loggedRun() {
Ihab Awad5d0410f2014-07-30 10:07:40 -0700719 createConnection(
720 connectionManagerPhoneAccount,
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700721 id,
Ihab Awad5d0410f2014-07-30 10:07:40 -0700722 request,
Yorke Leec3cf9822014-10-02 09:38:39 -0700723 isIncoming,
724 isUnknown);
Ihab Awad5d0410f2014-07-30 10:07:40 -0700725 }
Brad Ebinger0c3541b2016-11-01 14:11:38 -0700726 }.prepare());
Ihab Awad5d0410f2014-07-30 10:07:40 -0700727 } else {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700728 createConnection(
729 connectionManagerPhoneAccount,
730 id,
731 request,
Yorke Leec3cf9822014-10-02 09:38:39 -0700732 isIncoming,
733 isUnknown);
Ihab Awad5d0410f2014-07-30 10:07:40 -0700734 }
Ihab Awadf8b69882014-07-25 15:14:01 -0700735 } finally {
736 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700737 Log.endSession();
Ihab Awadf8b69882014-07-25 15:14:01 -0700738 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700739 break;
Ihab Awadf8b69882014-07-25 15:14:01 -0700740 }
Tyler Gunn041a1fe2017-05-12 10:04:49 -0700741 case MSG_CREATE_CONNECTION_COMPLETE: {
742 SomeArgs args = (SomeArgs) msg.obj;
743 Log.continueSession((Session) args.arg2,
744 SESSION_HANDLER + SESSION_CREATE_CONN_COMPLETE);
745 try {
746 final String id = (String) args.arg1;
747 if (!mAreAccountsInitialized) {
748 Log.d(this, "Enqueueing pre-init request %s", id);
749 mPreInitializationConnectionRequests.add(
750 new android.telecom.Logging.Runnable(
751 SESSION_HANDLER + SESSION_CREATE_CONN_COMPLETE
752 + ".pICR",
753 null /*lock*/) {
754 @Override
755 public void loggedRun() {
756 notifyCreateConnectionComplete(id);
757 }
758 }.prepare());
759 } else {
760 notifyCreateConnectionComplete(id);
761 }
762 } finally {
763 args.recycle();
764 Log.endSession();
765 }
766 break;
767 }
Tyler Gunn44e01912017-01-31 10:49:05 -0800768 case MSG_CREATE_CONNECTION_FAILED: {
769 SomeArgs args = (SomeArgs) msg.obj;
770 Log.continueSession((Session) args.arg3, SESSION_HANDLER +
771 SESSION_CREATE_CONN_FAILED);
772 try {
773 final String id = (String) args.arg1;
774 final ConnectionRequest request = (ConnectionRequest) args.arg2;
775 final boolean isIncoming = args.argi1 == 1;
Tyler Gunn159f35c2017-03-02 09:28:37 -0800776 final PhoneAccountHandle connectionMgrPhoneAccount =
777 (PhoneAccountHandle) args.arg4;
Tyler Gunn44e01912017-01-31 10:49:05 -0800778 if (!mAreAccountsInitialized) {
779 Log.d(this, "Enqueueing pre-init request %s", id);
780 mPreInitializationConnectionRequests.add(
781 new android.telecom.Logging.Runnable(
782 SESSION_HANDLER + SESSION_CREATE_CONN_FAILED + ".pICR",
783 null /*lock*/) {
784 @Override
785 public void loggedRun() {
Tyler Gunn159f35c2017-03-02 09:28:37 -0800786 createConnectionFailed(connectionMgrPhoneAccount, id,
787 request, isIncoming);
Tyler Gunn44e01912017-01-31 10:49:05 -0800788 }
789 }.prepare());
790 } else {
791 Log.i(this, "createConnectionFailed %s", id);
Tyler Gunn159f35c2017-03-02 09:28:37 -0800792 createConnectionFailed(connectionMgrPhoneAccount, id, request,
793 isIncoming);
Tyler Gunn44e01912017-01-31 10:49:05 -0800794 }
795 } finally {
796 args.recycle();
797 Log.endSession();
798 }
799 break;
800 }
Sanket Padawe4cc8ed52017-12-04 16:22:20 -0800801 case MSG_HANDOVER_FAILED: {
802 SomeArgs args = (SomeArgs) msg.obj;
803 Log.continueSession((Session) args.arg3, SESSION_HANDLER +
804 SESSION_HANDOVER_FAILED);
805 try {
806 final String id = (String) args.arg1;
807 final ConnectionRequest request = (ConnectionRequest) args.arg2;
808 final int reason = (int) args.arg4;
809 if (!mAreAccountsInitialized) {
810 Log.d(this, "Enqueueing pre-init request %s", id);
811 mPreInitializationConnectionRequests.add(
812 new android.telecom.Logging.Runnable(
813 SESSION_HANDLER
814 + SESSION_HANDOVER_FAILED + ".pICR",
815 null /*lock*/) {
816 @Override
817 public void loggedRun() {
818 handoverFailed(id, request, reason);
819 }
820 }.prepare());
821 } else {
822 Log.i(this, "createConnectionFailed %s", id);
823 handoverFailed(id, request, reason);
824 }
825 } finally {
826 args.recycle();
827 Log.endSession();
828 }
829 break;
830 }
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700831 case MSG_ABORT: {
832 SomeArgs args = (SomeArgs) msg.obj;
833 Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_ABORT);
834 try {
835 abort((String) args.arg1);
836 } finally {
837 args.recycle();
838 Log.endSession();
839 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700840 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700841 }
842 case MSG_ANSWER: {
843 SomeArgs args = (SomeArgs) msg.obj;
844 Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_ANSWER);
845 try {
846 answer((String) args.arg1);
847 } finally {
848 args.recycle();
849 Log.endSession();
850 }
Tyler Gunnbe74de02014-08-29 14:51:48 -0700851 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700852 }
Tyler Gunnbe74de02014-08-29 14:51:48 -0700853 case MSG_ANSWER_VIDEO: {
Andrew Lee8da4c3c2014-07-16 10:11:42 -0700854 SomeArgs args = (SomeArgs) msg.obj;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700855 Log.continueSession((Session) args.arg2,
856 SESSION_HANDLER + SESSION_ANSWER_VIDEO);
Andrew Lee8da4c3c2014-07-16 10:11:42 -0700857 try {
858 String callId = (String) args.arg1;
Evan Charltonbf11f982014-07-20 22:06:28 -0700859 int videoState = args.argi1;
Tyler Gunnbe74de02014-08-29 14:51:48 -0700860 answerVideo(callId, videoState);
Andrew Lee8da4c3c2014-07-16 10:11:42 -0700861 } finally {
862 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700863 Log.endSession();
Andrew Lee8da4c3c2014-07-16 10:11:42 -0700864 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700865 break;
Andrew Lee8da4c3c2014-07-16 10:11:42 -0700866 }
Pooja Jaind34698d2017-12-28 14:15:31 +0530867 case MSG_DEFLECT: {
868 SomeArgs args = (SomeArgs) msg.obj;
869 Log.continueSession((Session) args.arg3, SESSION_HANDLER + SESSION_DEFLECT);
870 try {
871 deflect((String) args.arg1, (Uri) args.arg2);
872 } finally {
873 args.recycle();
874 Log.endSession();
875 }
876 break;
877 }
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700878 case MSG_REJECT: {
879 SomeArgs args = (SomeArgs) msg.obj;
880 Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_REJECT);
881 try {
882 reject((String) args.arg1);
883 } finally {
884 args.recycle();
885 Log.endSession();
886 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700887 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700888 }
Bryce Lee81901682015-08-28 16:38:02 -0700889 case MSG_REJECT_WITH_MESSAGE: {
890 SomeArgs args = (SomeArgs) msg.obj;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700891 Log.continueSession((Session) args.arg3,
892 SESSION_HANDLER + SESSION_REJECT_MESSAGE);
Bryce Lee81901682015-08-28 16:38:02 -0700893 try {
894 reject((String) args.arg1, (String) args.arg2);
895 } finally {
896 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700897 Log.endSession();
Bryce Lee81901682015-08-28 16:38:02 -0700898 }
899 break;
900 }
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700901 case MSG_DISCONNECT: {
902 SomeArgs args = (SomeArgs) msg.obj;
903 Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_DISCONNECT);
904 try {
905 disconnect((String) args.arg1);
906 } finally {
907 args.recycle();
908 Log.endSession();
909 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700910 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700911 }
912 case MSG_SILENCE: {
913 SomeArgs args = (SomeArgs) msg.obj;
914 Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_SILENCE);
915 try {
916 silence((String) args.arg1);
917 } finally {
918 args.recycle();
919 Log.endSession();
920 }
Bryce Leecac50772015-11-17 15:13:29 -0800921 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700922 }
923 case MSG_HOLD: {
924 SomeArgs args = (SomeArgs) msg.obj;
925 Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_REJECT);
926 try {
927 hold((String) args.arg1);
928 } finally {
929 args.recycle();
930 Log.endSession();
931 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700932 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700933 }
934 case MSG_UNHOLD: {
935 SomeArgs args = (SomeArgs) msg.obj;
936 Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_UNHOLD);
937 try {
938 unhold((String) args.arg1);
939 } finally {
940 args.recycle();
941 Log.endSession();
942 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700943 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700944 }
Yorke Lee4af59352015-05-13 14:14:54 -0700945 case MSG_ON_CALL_AUDIO_STATE_CHANGED: {
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700946 SomeArgs args = (SomeArgs) msg.obj;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700947 Log.continueSession((Session) args.arg3,
948 SESSION_HANDLER + SESSION_CALL_AUDIO_SC);
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700949 try {
950 String callId = (String) args.arg1;
Yorke Lee4af59352015-05-13 14:14:54 -0700951 CallAudioState audioState = (CallAudioState) args.arg2;
952 onCallAudioStateChanged(callId, new CallAudioState(audioState));
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700953 } finally {
954 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700955 Log.endSession();
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700956 }
957 break;
958 }
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700959 case MSG_PLAY_DTMF_TONE: {
960 SomeArgs args = (SomeArgs) msg.obj;
961 try {
962 Log.continueSession((Session) args.arg3,
963 SESSION_HANDLER + SESSION_PLAY_DTMF);
964 playDtmfTone((String) args.arg2, (char) args.arg1);
965 } finally {
966 args.recycle();
967 Log.endSession();
968 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700969 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700970 }
971 case MSG_STOP_DTMF_TONE: {
972 SomeArgs args = (SomeArgs) msg.obj;
973 try {
974 Log.continueSession((Session) args.arg2,
975 SESSION_HANDLER + SESSION_STOP_DTMF);
976 stopDtmfTone((String) args.arg1);
977 } finally {
978 args.recycle();
979 Log.endSession();
980 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700981 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700982 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700983 case MSG_CONFERENCE: {
984 SomeArgs args = (SomeArgs) msg.obj;
985 try {
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700986 Log.continueSession((Session) args.arg3,
987 SESSION_HANDLER + SESSION_CONFERENCE);
Santos Cordon823fd3c2014-08-07 18:35:18 -0700988 String callId1 = (String) args.arg1;
989 String callId2 = (String) args.arg2;
990 conference(callId1, callId2);
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700991 } finally {
992 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700993 Log.endSession();
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700994 }
995 break;
996 }
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700997 case MSG_SPLIT_FROM_CONFERENCE: {
998 SomeArgs args = (SomeArgs) msg.obj;
999 try {
1000 Log.continueSession((Session) args.arg2,
1001 SESSION_HANDLER + SESSION_SPLIT_CONFERENCE);
1002 splitFromConference((String) args.arg1);
1003 } finally {
1004 args.recycle();
1005 Log.endSession();
1006 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001007 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001008 }
1009 case MSG_MERGE_CONFERENCE: {
1010 SomeArgs args = (SomeArgs) msg.obj;
1011 try {
1012 Log.continueSession((Session) args.arg2,
1013 SESSION_HANDLER + SESSION_MERGE_CONFERENCE);
1014 mergeConference((String) args.arg1);
1015 } finally {
1016 args.recycle();
1017 Log.endSession();
1018 }
Santos Cordona4868042014-09-04 17:39:22 -07001019 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001020 }
1021 case MSG_SWAP_CONFERENCE: {
1022 SomeArgs args = (SomeArgs) msg.obj;
1023 try {
1024 Log.continueSession((Session) args.arg2,
1025 SESSION_HANDLER + SESSION_SWAP_CONFERENCE);
1026 swapConference((String) args.arg1);
1027 } finally {
1028 args.recycle();
1029 Log.endSession();
1030 }
Santos Cordona4868042014-09-04 17:39:22 -07001031 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001032 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001033 case MSG_ON_POST_DIAL_CONTINUE: {
1034 SomeArgs args = (SomeArgs) msg.obj;
1035 try {
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001036 Log.continueSession((Session) args.arg2,
1037 SESSION_HANDLER + SESSION_POST_DIAL_CONT);
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001038 String callId = (String) args.arg1;
1039 boolean proceed = (args.argi1 == 1);
1040 onPostDialContinue(callId, proceed);
1041 } finally {
1042 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001043 Log.endSession();
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001044 }
1045 break;
1046 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001047 case MSG_PULL_EXTERNAL_CALL: {
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001048 SomeArgs args = (SomeArgs) msg.obj;
1049 try {
1050 Log.continueSession((Session) args.arg2,
1051 SESSION_HANDLER + SESSION_PULL_EXTERNAL_CALL);
1052 pullExternalCall((String) args.arg1);
1053 } finally {
1054 args.recycle();
1055 Log.endSession();
1056 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001057 break;
1058 }
1059 case MSG_SEND_CALL_EVENT: {
1060 SomeArgs args = (SomeArgs) msg.obj;
1061 try {
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001062 Log.continueSession((Session) args.arg4,
1063 SESSION_HANDLER + SESSION_SEND_CALL_EVENT);
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001064 String callId = (String) args.arg1;
1065 String event = (String) args.arg2;
1066 Bundle extras = (Bundle) args.arg3;
1067 sendCallEvent(callId, event, extras);
1068 } finally {
1069 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001070 Log.endSession();
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001071 }
1072 break;
1073 }
Tyler Gunn79bc1ec2018-01-22 15:17:54 -08001074 case MSG_HANDOVER_COMPLETE: {
1075 SomeArgs args = (SomeArgs) msg.obj;
1076 try {
1077 Log.continueSession((Session) args.arg2,
1078 SESSION_HANDLER + SESSION_HANDOVER_COMPLETE);
1079 String callId = (String) args.arg1;
1080 notifyHandoverComplete(callId);
1081 } finally {
1082 args.recycle();
1083 Log.endSession();
1084 }
1085 break;
1086 }
Tyler Gunndee56a82016-03-23 16:06:34 -07001087 case MSG_ON_EXTRAS_CHANGED: {
1088 SomeArgs args = (SomeArgs) msg.obj;
1089 try {
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001090 Log.continueSession((Session) args.arg3,
1091 SESSION_HANDLER + SESSION_EXTRAS_CHANGED);
Tyler Gunndee56a82016-03-23 16:06:34 -07001092 String callId = (String) args.arg1;
1093 Bundle extras = (Bundle) args.arg2;
1094 handleExtrasChanged(callId, extras);
1095 } finally {
1096 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001097 Log.endSession();
Tyler Gunndee56a82016-03-23 16:06:34 -07001098 }
1099 break;
1100 }
Hall Liub64ac4c2017-02-06 10:49:48 -08001101 case MSG_ON_START_RTT: {
1102 SomeArgs args = (SomeArgs) msg.obj;
1103 try {
1104 Log.continueSession((Session) args.arg3,
1105 SESSION_HANDLER + SESSION_START_RTT);
1106 String callId = (String) args.arg1;
1107 Connection.RttTextStream rttTextStream =
1108 (Connection.RttTextStream) args.arg2;
1109 startRtt(callId, rttTextStream);
1110 } finally {
1111 args.recycle();
1112 Log.endSession();
1113 }
1114 break;
1115 }
1116 case MSG_ON_STOP_RTT: {
1117 SomeArgs args = (SomeArgs) msg.obj;
1118 try {
1119 Log.continueSession((Session) args.arg2,
1120 SESSION_HANDLER + SESSION_STOP_RTT);
1121 String callId = (String) args.arg1;
1122 stopRtt(callId);
1123 } finally {
1124 args.recycle();
1125 Log.endSession();
1126 }
1127 break;
1128 }
1129 case MSG_RTT_UPGRADE_RESPONSE: {
1130 SomeArgs args = (SomeArgs) msg.obj;
1131 try {
1132 Log.continueSession((Session) args.arg3,
1133 SESSION_HANDLER + SESSION_RTT_UPGRADE_RESPONSE);
1134 String callId = (String) args.arg1;
1135 Connection.RttTextStream rttTextStream =
1136 (Connection.RttTextStream) args.arg2;
1137 handleRttUpgradeResponse(callId, rttTextStream);
1138 } finally {
1139 args.recycle();
1140 Log.endSession();
1141 }
1142 break;
1143 }
Pengquan Meng731c1a32017-11-21 18:01:13 -08001144 case MSG_CONNECTION_SERVICE_FOCUS_GAINED:
1145 onConnectionServiceFocusGained();
1146 break;
1147 case MSG_CONNECTION_SERVICE_FOCUS_LOST:
1148 onConnectionServiceFocusLost();
1149 break;
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001150 default:
1151 break;
1152 }
1153 }
1154 };
1155
Santos Cordon823fd3c2014-08-07 18:35:18 -07001156 private final Conference.Listener mConferenceListener = new Conference.Listener() {
1157 @Override
1158 public void onStateChanged(Conference conference, int oldState, int newState) {
1159 String id = mIdByConference.get(conference);
1160 switch (newState) {
1161 case Connection.STATE_ACTIVE:
1162 mAdapter.setActive(id);
1163 break;
1164 case Connection.STATE_HOLDING:
1165 mAdapter.setOnHold(id);
1166 break;
1167 case Connection.STATE_DISCONNECTED:
1168 // handled by onDisconnected
1169 break;
1170 }
1171 }
1172
1173 @Override
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001174 public void onDisconnected(Conference conference, DisconnectCause disconnectCause) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07001175 String id = mIdByConference.get(conference);
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001176 mAdapter.setDisconnected(id, disconnectCause);
Santos Cordon823fd3c2014-08-07 18:35:18 -07001177 }
1178
1179 @Override
1180 public void onConnectionAdded(Conference conference, Connection connection) {
1181 }
1182
1183 @Override
1184 public void onConnectionRemoved(Conference conference, Connection connection) {
1185 }
1186
1187 @Override
Ihab Awad50e35062014-09-30 09:17:03 -07001188 public void onConferenceableConnectionsChanged(
1189 Conference conference, List<Connection> conferenceableConnections) {
1190 mAdapter.setConferenceableConnections(
1191 mIdByConference.get(conference),
1192 createConnectionIdList(conferenceableConnections));
1193 }
1194
1195 @Override
Santos Cordon823fd3c2014-08-07 18:35:18 -07001196 public void onDestroyed(Conference conference) {
1197 removeConference(conference);
1198 }
1199
1200 @Override
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001201 public void onConnectionCapabilitiesChanged(
1202 Conference conference,
1203 int connectionCapabilities) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07001204 String id = mIdByConference.get(conference);
1205 Log.d(this, "call capabilities: conference: %s",
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001206 Connection.capabilitiesToString(connectionCapabilities));
1207 mAdapter.setConnectionCapabilities(id, connectionCapabilities);
Santos Cordon823fd3c2014-08-07 18:35:18 -07001208 }
Rekha Kumar07366812015-03-24 16:42:31 -07001209
1210 @Override
Tyler Gunn720c6642016-03-22 09:02:47 -07001211 public void onConnectionPropertiesChanged(
1212 Conference conference,
1213 int connectionProperties) {
1214 String id = mIdByConference.get(conference);
1215 Log.d(this, "call capabilities: conference: %s",
1216 Connection.propertiesToString(connectionProperties));
1217 mAdapter.setConnectionProperties(id, connectionProperties);
1218 }
1219
1220 @Override
Rekha Kumar07366812015-03-24 16:42:31 -07001221 public void onVideoStateChanged(Conference c, int videoState) {
1222 String id = mIdByConference.get(c);
1223 Log.d(this, "onVideoStateChanged set video state %d", videoState);
1224 mAdapter.setVideoState(id, videoState);
1225 }
1226
1227 @Override
1228 public void onVideoProviderChanged(Conference c, Connection.VideoProvider videoProvider) {
1229 String id = mIdByConference.get(c);
1230 Log.d(this, "onVideoProviderChanged: Connection: %s, VideoProvider: %s", c,
1231 videoProvider);
1232 mAdapter.setVideoProvider(id, videoProvider);
1233 }
Andrew Lee0f51da32015-04-16 13:11:55 -07001234
1235 @Override
Andrew Leeedc625f2015-04-14 13:38:12 -07001236 public void onStatusHintsChanged(Conference conference, StatusHints statusHints) {
1237 String id = mIdByConference.get(conference);
Tyler Gunndee56a82016-03-23 16:06:34 -07001238 if (id != null) {
1239 mAdapter.setStatusHints(id, statusHints);
1240 }
Andrew Leeedc625f2015-04-14 13:38:12 -07001241 }
Santos Cordon6b7f9552015-05-27 17:21:45 -07001242
1243 @Override
Tyler Gunndee56a82016-03-23 16:06:34 -07001244 public void onExtrasChanged(Conference c, Bundle extras) {
1245 String id = mIdByConference.get(c);
1246 if (id != null) {
1247 mAdapter.putExtras(id, extras);
1248 }
1249 }
1250
1251 @Override
1252 public void onExtrasRemoved(Conference c, List<String> keys) {
1253 String id = mIdByConference.get(c);
1254 if (id != null) {
1255 mAdapter.removeExtras(id, keys);
1256 }
Santos Cordon6b7f9552015-05-27 17:21:45 -07001257 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07001258 };
1259
Ihab Awad542e0ea2014-05-16 10:22:16 -07001260 private final Connection.Listener mConnectionListener = new Connection.Listener() {
1261 @Override
1262 public void onStateChanged(Connection c, int state) {
1263 String id = mIdByConnection.get(c);
Ihab Awad42b30e12014-05-22 09:49:34 -07001264 Log.d(this, "Adapter set state %s %s", id, Connection.stateToString(state));
Ihab Awad542e0ea2014-05-16 10:22:16 -07001265 switch (state) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001266 case Connection.STATE_ACTIVE:
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001267 mAdapter.setActive(id);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001268 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001269 case Connection.STATE_DIALING:
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001270 mAdapter.setDialing(id);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001271 break;
Tyler Gunnc96b5e02016-07-07 22:53:57 -07001272 case Connection.STATE_PULLING_CALL:
1273 mAdapter.setPulling(id);
1274 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001275 case Connection.STATE_DISCONNECTED:
Ihab Awad542e0ea2014-05-16 10:22:16 -07001276 // Handled in onDisconnected()
1277 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001278 case Connection.STATE_HOLDING:
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001279 mAdapter.setOnHold(id);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001280 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001281 case Connection.STATE_NEW:
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001282 // Nothing to tell Telecom
Ihab Awad542e0ea2014-05-16 10:22:16 -07001283 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001284 case Connection.STATE_RINGING:
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001285 mAdapter.setRinging(id);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001286 break;
1287 }
1288 }
1289
1290 @Override
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001291 public void onDisconnected(Connection c, DisconnectCause disconnectCause) {
Ihab Awad542e0ea2014-05-16 10:22:16 -07001292 String id = mIdByConnection.get(c);
Andrew Lee26786392014-09-16 18:14:59 -07001293 Log.d(this, "Adapter set disconnected %s", disconnectCause);
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001294 mAdapter.setDisconnected(id, disconnectCause);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001295 }
1296
1297 @Override
Tyler Gunnaa07df82014-07-17 07:50:22 -07001298 public void onVideoStateChanged(Connection c, int videoState) {
1299 String id = mIdByConnection.get(c);
1300 Log.d(this, "Adapter set video state %d", videoState);
1301 mAdapter.setVideoState(id, videoState);
1302 }
1303
1304 @Override
Andrew Lee100e2932014-09-08 15:34:24 -07001305 public void onAddressChanged(Connection c, Uri address, int presentation) {
Sailesh Nepal61203862014-07-11 14:50:13 -07001306 String id = mIdByConnection.get(c);
Andrew Lee100e2932014-09-08 15:34:24 -07001307 mAdapter.setAddress(id, address, presentation);
Sailesh Nepal61203862014-07-11 14:50:13 -07001308 }
1309
1310 @Override
1311 public void onCallerDisplayNameChanged(
1312 Connection c, String callerDisplayName, int presentation) {
1313 String id = mIdByConnection.get(c);
1314 mAdapter.setCallerDisplayName(id, callerDisplayName, presentation);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001315 }
1316
1317 @Override
Ihab Awad542e0ea2014-05-16 10:22:16 -07001318 public void onDestroyed(Connection c) {
1319 removeConnection(c);
1320 }
Ihab Awadf8358972014-05-28 16:46:42 -07001321
1322 @Override
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001323 public void onPostDialWait(Connection c, String remaining) {
Sailesh Nepal091768c2014-06-30 15:15:23 -07001324 String id = mIdByConnection.get(c);
1325 Log.d(this, "Adapter onPostDialWait %s, %s", c, remaining);
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001326 mAdapter.onPostDialWait(id, remaining);
Sailesh Nepal091768c2014-06-30 15:15:23 -07001327 }
1328
1329 @Override
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001330 public void onPostDialChar(Connection c, char nextChar) {
1331 String id = mIdByConnection.get(c);
1332 Log.d(this, "Adapter onPostDialChar %s, %s", c, nextChar);
1333 mAdapter.onPostDialChar(id, nextChar);
1334 }
1335
1336 @Override
Andrew Lee100e2932014-09-08 15:34:24 -07001337 public void onRingbackRequested(Connection c, boolean ringback) {
Ihab Awadf8358972014-05-28 16:46:42 -07001338 String id = mIdByConnection.get(c);
1339 Log.d(this, "Adapter onRingback %b", ringback);
Andrew Lee100e2932014-09-08 15:34:24 -07001340 mAdapter.setRingbackRequested(id, ringback);
Ihab Awadf8358972014-05-28 16:46:42 -07001341 }
Santos Cordonb6939982014-06-04 20:20:58 -07001342
1343 @Override
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001344 public void onConnectionCapabilitiesChanged(Connection c, int capabilities) {
Santos Cordonb6939982014-06-04 20:20:58 -07001345 String id = mIdByConnection.get(c);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001346 Log.d(this, "capabilities: parcelableconnection: %s",
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001347 Connection.capabilitiesToString(capabilities));
1348 mAdapter.setConnectionCapabilities(id, capabilities);
Santos Cordonb6939982014-06-04 20:20:58 -07001349 }
1350
Santos Cordonb6939982014-06-04 20:20:58 -07001351 @Override
Tyler Gunn720c6642016-03-22 09:02:47 -07001352 public void onConnectionPropertiesChanged(Connection c, int properties) {
1353 String id = mIdByConnection.get(c);
1354 Log.d(this, "properties: parcelableconnection: %s",
1355 Connection.propertiesToString(properties));
1356 mAdapter.setConnectionProperties(id, properties);
1357 }
1358
1359 @Override
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001360 public void onVideoProviderChanged(Connection c, Connection.VideoProvider videoProvider) {
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07001361 String id = mIdByConnection.get(c);
Rekha Kumar07366812015-03-24 16:42:31 -07001362 Log.d(this, "onVideoProviderChanged: Connection: %s, VideoProvider: %s", c,
1363 videoProvider);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001364 mAdapter.setVideoProvider(id, videoProvider);
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07001365 }
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001366
1367 @Override
Sailesh Nepal001bbbb2014-07-15 14:40:39 -07001368 public void onAudioModeIsVoipChanged(Connection c, boolean isVoip) {
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001369 String id = mIdByConnection.get(c);
Andrew Lee100e2932014-09-08 15:34:24 -07001370 mAdapter.setIsVoipAudioMode(id, isVoip);
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001371 }
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001372
1373 @Override
Sailesh Nepal001bbbb2014-07-15 14:40:39 -07001374 public void onStatusHintsChanged(Connection c, StatusHints statusHints) {
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001375 String id = mIdByConnection.get(c);
1376 mAdapter.setStatusHints(id, statusHints);
1377 }
Sailesh Nepal2ab88cc2014-07-18 14:49:18 -07001378
1379 @Override
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001380 public void onConferenceablesChanged(
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001381 Connection connection, List<Conferenceable> conferenceables) {
Ihab Awadb8e85c72014-08-23 20:34:57 -07001382 mAdapter.setConferenceableConnections(
1383 mIdByConnection.get(connection),
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001384 createIdList(conferenceables));
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001385 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07001386
1387 @Override
1388 public void onConferenceChanged(Connection connection, Conference conference) {
1389 String id = mIdByConnection.get(connection);
1390 if (id != null) {
1391 String conferenceId = null;
1392 if (conference != null) {
1393 conferenceId = mIdByConference.get(conference);
1394 }
1395 mAdapter.setIsConferenced(id, conferenceId);
1396 }
1397 }
Anthony Lee17455a32015-04-24 15:25:29 -07001398
1399 @Override
1400 public void onConferenceMergeFailed(Connection connection) {
1401 String id = mIdByConnection.get(connection);
1402 if (id != null) {
1403 mAdapter.onConferenceMergeFailed(id);
1404 }
1405 }
Santos Cordon6b7f9552015-05-27 17:21:45 -07001406
1407 @Override
Tyler Gunndee56a82016-03-23 16:06:34 -07001408 public void onExtrasChanged(Connection c, Bundle extras) {
1409 String id = mIdByConnection.get(c);
Santos Cordon6b7f9552015-05-27 17:21:45 -07001410 if (id != null) {
Tyler Gunndee56a82016-03-23 16:06:34 -07001411 mAdapter.putExtras(id, extras);
Santos Cordon6b7f9552015-05-27 17:21:45 -07001412 }
1413 }
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001414
Tyler Gunnf5035432017-01-09 09:43:12 -08001415 @Override
Tyler Gunndee56a82016-03-23 16:06:34 -07001416 public void onExtrasRemoved(Connection c, List<String> keys) {
1417 String id = mIdByConnection.get(c);
1418 if (id != null) {
1419 mAdapter.removeExtras(id, keys);
1420 }
1421 }
1422
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08001423 @Override
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001424 public void onConnectionEvent(Connection connection, String event, Bundle extras) {
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08001425 String id = mIdByConnection.get(connection);
1426 if (id != null) {
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001427 mAdapter.onConnectionEvent(id, event, extras);
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08001428 }
1429 }
Tyler Gunnf5035432017-01-09 09:43:12 -08001430
1431 @Override
Hall Liua98f58b52017-11-07 17:59:28 -08001432 public void onAudioRouteChanged(Connection c, int audioRoute, String bluetoothAddress) {
Tyler Gunnf5035432017-01-09 09:43:12 -08001433 String id = mIdByConnection.get(c);
1434 if (id != null) {
Hall Liua98f58b52017-11-07 17:59:28 -08001435 mAdapter.setAudioRoute(id, audioRoute, bluetoothAddress);
Tyler Gunnf5035432017-01-09 09:43:12 -08001436 }
1437 }
Hall Liub64ac4c2017-02-06 10:49:48 -08001438
1439 @Override
1440 public void onRttInitiationSuccess(Connection c) {
1441 String id = mIdByConnection.get(c);
1442 if (id != null) {
1443 mAdapter.onRttInitiationSuccess(id);
1444 }
1445 }
1446
1447 @Override
1448 public void onRttInitiationFailure(Connection c, int reason) {
1449 String id = mIdByConnection.get(c);
1450 if (id != null) {
1451 mAdapter.onRttInitiationFailure(id, reason);
1452 }
1453 }
1454
1455 @Override
1456 public void onRttSessionRemotelyTerminated(Connection c) {
1457 String id = mIdByConnection.get(c);
1458 if (id != null) {
1459 mAdapter.onRttSessionRemotelyTerminated(id);
1460 }
1461 }
1462
1463 @Override
1464 public void onRemoteRttRequest(Connection c) {
1465 String id = mIdByConnection.get(c);
1466 if (id != null) {
1467 mAdapter.onRemoteRttRequest(id);
1468 }
1469 }
Srikanth Chintalafcb15012017-05-04 20:58:34 +05301470
1471 @Override
1472 public void onPhoneAccountChanged(Connection c, PhoneAccountHandle pHandle) {
1473 String id = mIdByConnection.get(c);
1474 if (id != null) {
1475 mAdapter.onPhoneAccountChanged(id, pHandle);
1476 }
1477 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001478 };
1479
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001480 /** {@inheritDoc} */
Ihab Awad542e0ea2014-05-16 10:22:16 -07001481 @Override
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001482 public final IBinder onBind(Intent intent) {
1483 return mBinder;
1484 }
1485
Santos Cordon29f2f2e2014-09-11 19:50:24 -07001486 /** {@inheritDoc} */
1487 @Override
1488 public boolean onUnbind(Intent intent) {
1489 endAllConnections();
1490 return super.onUnbind(intent);
1491 }
1492
Sailesh Nepalc5b01572014-07-14 16:29:44 -07001493 /**
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001494 * This can be used by telecom to either create a new outgoing call or attach to an existing
1495 * incoming call. In either case, telecom will cycle through a set of services and call
Sailesh Nepalc5b01572014-07-14 16:29:44 -07001496 * createConnection util a connection service cancels the process or completes it successfully.
1497 */
Ihab Awadf8b69882014-07-25 15:14:01 -07001498 private void createConnection(
1499 final PhoneAccountHandle callManagerAccount,
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001500 final String callId,
Ihab Awadf8b69882014-07-25 15:14:01 -07001501 final ConnectionRequest request,
Yorke Leec3cf9822014-10-02 09:38:39 -07001502 boolean isIncoming,
1503 boolean isUnknown) {
Tyler Gunn79bc1ec2018-01-22 15:17:54 -08001504 boolean isLegacyHandover = request.getExtras() != null &&
1505 request.getExtras().getBoolean(TelecomManager.EXTRA_IS_HANDOVER, false);
1506 boolean isHandover = request.getExtras() != null && request.getExtras().getBoolean(
1507 TelecomManager.EXTRA_IS_HANDOVER_CONNECTION, false);
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001508 Log.d(this, "createConnection, callManagerAccount: %s, callId: %s, request: %s, " +
Tyler Gunn79bc1ec2018-01-22 15:17:54 -08001509 "isIncoming: %b, isUnknown: %b, isLegacyHandover: %b, isHandover: %b",
1510 callManagerAccount, callId, request, isIncoming, isUnknown, isLegacyHandover,
1511 isHandover);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001512
Sanket Padawee29a2662017-12-01 13:59:27 -08001513 Connection connection = null;
Tyler Gunn79bc1ec2018-01-22 15:17:54 -08001514 if (isHandover) {
1515 PhoneAccountHandle fromPhoneAccountHandle = request.getExtras() != null
1516 ? (PhoneAccountHandle) request.getExtras().getParcelable(
1517 TelecomManager.EXTRA_HANDOVER_FROM_PHONE_ACCOUNT) : null;
Sanket Padawee29a2662017-12-01 13:59:27 -08001518 if (!isIncoming) {
Tyler Gunn79bc1ec2018-01-22 15:17:54 -08001519 connection = onCreateOutgoingHandoverConnection(fromPhoneAccountHandle, request);
Sanket Padawee29a2662017-12-01 13:59:27 -08001520 } else {
Tyler Gunn79bc1ec2018-01-22 15:17:54 -08001521 connection = onCreateIncomingHandoverConnection(fromPhoneAccountHandle, request);
Sanket Padawee29a2662017-12-01 13:59:27 -08001522 }
1523 } else {
1524 connection = isUnknown ? onCreateUnknownConnection(callManagerAccount, request)
1525 : isIncoming ? onCreateIncomingConnection(callManagerAccount, request)
1526 : onCreateOutgoingConnection(callManagerAccount, request);
1527 }
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001528 Log.d(this, "createConnection, connection: %s", connection);
1529 if (connection == null) {
Tyler Gunnfba1a8e2017-12-19 15:23:59 -08001530 Log.i(this, "createConnection, implementation returned null connection.");
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001531 connection = Connection.createFailedConnection(
Tyler Gunnfba1a8e2017-12-19 15:23:59 -08001532 new DisconnectCause(DisconnectCause.ERROR, "IMPL_RETURNED_NULL_CONNECTION"));
Sailesh Nepalc5b01572014-07-14 16:29:44 -07001533 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001534
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001535 connection.setTelecomCallId(callId);
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001536 if (connection.getState() != Connection.STATE_DISCONNECTED) {
Pengquan Meng70c9885332017-10-02 18:09:03 -07001537 addConnection(request.getAccountHandle(), callId, connection);
Ihab Awad6107bab2014-08-18 09:23:25 -07001538 }
1539
Andrew Lee100e2932014-09-08 15:34:24 -07001540 Uri address = connection.getAddress();
1541 String number = address == null ? "null" : address.getSchemeSpecificPart();
Tyler Gunn720c6642016-03-22 09:02:47 -07001542 Log.v(this, "createConnection, number: %s, state: %s, capabilities: %s, properties: %s",
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001543 Connection.toLogSafePhoneNumber(number),
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001544 Connection.stateToString(connection.getState()),
Tyler Gunn720c6642016-03-22 09:02:47 -07001545 Connection.capabilitiesToString(connection.getConnectionCapabilities()),
1546 Connection.propertiesToString(connection.getConnectionProperties()));
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001547
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001548 Log.d(this, "createConnection, calling handleCreateConnectionSuccessful %s", callId);
Ihab Awad6107bab2014-08-18 09:23:25 -07001549 mAdapter.handleCreateConnectionComplete(
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001550 callId,
Evan Charltonbf11f982014-07-20 22:06:28 -07001551 request,
1552 new ParcelableConnection(
1553 request.getAccountHandle(),
1554 connection.getState(),
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001555 connection.getConnectionCapabilities(),
Tyler Gunn720c6642016-03-22 09:02:47 -07001556 connection.getConnectionProperties(),
Christine Hallstrom2830ce92016-11-30 16:06:42 -08001557 connection.getSupportedAudioRoutes(),
Andrew Lee100e2932014-09-08 15:34:24 -07001558 connection.getAddress(),
1559 connection.getAddressPresentation(),
Evan Charltonbf11f982014-07-20 22:06:28 -07001560 connection.getCallerDisplayName(),
1561 connection.getCallerDisplayNamePresentation(),
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001562 connection.getVideoProvider() == null ?
1563 null : connection.getVideoProvider().getInterface(),
Sailesh Nepal8b9d3ca2014-08-14 17:39:34 -07001564 connection.getVideoState(),
Andrew Lee100e2932014-09-08 15:34:24 -07001565 connection.isRingbackRequested(),
Sailesh Nepal8b9d3ca2014-08-14 17:39:34 -07001566 connection.getAudioModeIsVoip(),
Roshan Piuse927ec02015-07-15 15:47:21 -07001567 connection.getConnectTimeMillis(),
Tyler Gunn3fa819c2017-08-04 09:27:26 -07001568 connection.getConnectElapsedTimeMillis(),
Ihab Awad6107bab2014-08-18 09:23:25 -07001569 connection.getStatusHints(),
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001570 connection.getDisconnectCause(),
Santos Cordon6b7f9552015-05-27 17:21:45 -07001571 createIdList(connection.getConferenceables()),
1572 connection.getExtras()));
Tyler Gunnf5035432017-01-09 09:43:12 -08001573
1574 if (isIncoming && request.shouldShowIncomingCallUi() &&
1575 (connection.getConnectionProperties() & Connection.PROPERTY_SELF_MANAGED) ==
1576 Connection.PROPERTY_SELF_MANAGED) {
1577 // Tell ConnectionService to show its incoming call UX.
1578 connection.onShowIncomingCallUi();
1579 }
Shriram Ganesh6bf35ac2014-12-11 17:53:38 -08001580 if (isUnknown) {
1581 triggerConferenceRecalculate();
1582 }
Evan Charltonbf11f982014-07-20 22:06:28 -07001583 }
1584
Tyler Gunn159f35c2017-03-02 09:28:37 -08001585 private void createConnectionFailed(final PhoneAccountHandle callManagerAccount,
1586 final String callId, final ConnectionRequest request,
1587 boolean isIncoming) {
Tyler Gunn44e01912017-01-31 10:49:05 -08001588
1589 Log.i(this, "createConnectionFailed %s", callId);
1590 if (isIncoming) {
Tyler Gunn159f35c2017-03-02 09:28:37 -08001591 onCreateIncomingConnectionFailed(callManagerAccount, request);
Tyler Gunn44e01912017-01-31 10:49:05 -08001592 } else {
Tyler Gunn159f35c2017-03-02 09:28:37 -08001593 onCreateOutgoingConnectionFailed(callManagerAccount, request);
Tyler Gunn44e01912017-01-31 10:49:05 -08001594 }
1595 }
1596
Sanket Padawe4cc8ed52017-12-04 16:22:20 -08001597 private void handoverFailed(final String callId, final ConnectionRequest request,
1598 int reason) {
1599
1600 Log.i(this, "handoverFailed %s", callId);
1601 onHandoverFailed(request, reason);
1602 }
1603
Tyler Gunn041a1fe2017-05-12 10:04:49 -07001604 /**
1605 * Called by Telecom when the creation of a new Connection has completed and it is now added
1606 * to Telecom.
1607 * @param callId The ID of the connection.
1608 */
1609 private void notifyCreateConnectionComplete(final String callId) {
1610 Log.i(this, "notifyCreateConnectionComplete %s", callId);
Tyler Gunn0a88f2e2017-06-16 20:20:34 -07001611 if (callId == null) {
1612 // This could happen if the connection fails quickly and is removed from the
1613 // ConnectionService before Telecom sends the create connection complete callback.
1614 Log.w(this, "notifyCreateConnectionComplete: callId is null.");
1615 return;
1616 }
Tyler Gunn041a1fe2017-05-12 10:04:49 -07001617 onCreateConnectionComplete(findConnectionForAction(callId,
1618 "notifyCreateConnectionComplete"));
1619 }
1620
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001621 private void abort(String callId) {
Ihab Awad60ac30b2014-05-20 22:32:12 -07001622 Log.d(this, "abort %s", callId);
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001623 findConnectionForAction(callId, "abort").onAbort();
Ihab Awad542e0ea2014-05-16 10:22:16 -07001624 }
1625
Tyler Gunnbe74de02014-08-29 14:51:48 -07001626 private void answerVideo(String callId, int videoState) {
1627 Log.d(this, "answerVideo %s", callId);
Andrew Lee8da4c3c2014-07-16 10:11:42 -07001628 findConnectionForAction(callId, "answer").onAnswer(videoState);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001629 }
1630
Tyler Gunnbe74de02014-08-29 14:51:48 -07001631 private void answer(String callId) {
1632 Log.d(this, "answer %s", callId);
1633 findConnectionForAction(callId, "answer").onAnswer();
1634 }
1635
Pooja Jaind34698d2017-12-28 14:15:31 +05301636 private void deflect(String callId, Uri address) {
1637 Log.d(this, "deflect %s", callId);
1638 findConnectionForAction(callId, "deflect").onDeflect(address);
1639 }
1640
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001641 private void reject(String callId) {
Ihab Awad60ac30b2014-05-20 22:32:12 -07001642 Log.d(this, "reject %s", callId);
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001643 findConnectionForAction(callId, "reject").onReject();
Ihab Awad542e0ea2014-05-16 10:22:16 -07001644 }
1645
Bryce Lee81901682015-08-28 16:38:02 -07001646 private void reject(String callId, String rejectWithMessage) {
1647 Log.d(this, "reject %s with message", callId);
1648 findConnectionForAction(callId, "reject").onReject(rejectWithMessage);
1649 }
1650
Bryce Leecac50772015-11-17 15:13:29 -08001651 private void silence(String callId) {
1652 Log.d(this, "silence %s", callId);
1653 findConnectionForAction(callId, "silence").onSilence();
1654 }
1655
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001656 private void disconnect(String callId) {
Ihab Awad60ac30b2014-05-20 22:32:12 -07001657 Log.d(this, "disconnect %s", callId);
Santos Cordon0159ac02014-08-21 14:28:11 -07001658 if (mConnectionById.containsKey(callId)) {
1659 findConnectionForAction(callId, "disconnect").onDisconnect();
1660 } else {
1661 findConferenceForAction(callId, "disconnect").onDisconnect();
1662 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001663 }
1664
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001665 private void hold(String callId) {
Ihab Awad60ac30b2014-05-20 22:32:12 -07001666 Log.d(this, "hold %s", callId);
Santos Cordon0159ac02014-08-21 14:28:11 -07001667 if (mConnectionById.containsKey(callId)) {
1668 findConnectionForAction(callId, "hold").onHold();
1669 } else {
1670 findConferenceForAction(callId, "hold").onHold();
1671 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001672 }
1673
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001674 private void unhold(String callId) {
Ihab Awad60ac30b2014-05-20 22:32:12 -07001675 Log.d(this, "unhold %s", callId);
Santos Cordon0159ac02014-08-21 14:28:11 -07001676 if (mConnectionById.containsKey(callId)) {
1677 findConnectionForAction(callId, "unhold").onUnhold();
1678 } else {
1679 findConferenceForAction(callId, "unhold").onUnhold();
1680 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001681 }
1682
Yorke Lee4af59352015-05-13 14:14:54 -07001683 private void onCallAudioStateChanged(String callId, CallAudioState callAudioState) {
1684 Log.d(this, "onAudioStateChanged %s %s", callId, callAudioState);
Yorke Leea0d3ca92014-09-15 19:18:13 -07001685 if (mConnectionById.containsKey(callId)) {
Yorke Lee4af59352015-05-13 14:14:54 -07001686 findConnectionForAction(callId, "onCallAudioStateChanged").setCallAudioState(
1687 callAudioState);
Yorke Leea0d3ca92014-09-15 19:18:13 -07001688 } else {
Yorke Lee4af59352015-05-13 14:14:54 -07001689 findConferenceForAction(callId, "onCallAudioStateChanged").setCallAudioState(
1690 callAudioState);
Yorke Leea0d3ca92014-09-15 19:18:13 -07001691 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001692 }
1693
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001694 private void playDtmfTone(String callId, char digit) {
1695 Log.d(this, "playDtmfTone %s %c", callId, digit);
Yorke Leea0d3ca92014-09-15 19:18:13 -07001696 if (mConnectionById.containsKey(callId)) {
1697 findConnectionForAction(callId, "playDtmfTone").onPlayDtmfTone(digit);
1698 } else {
1699 findConferenceForAction(callId, "playDtmfTone").onPlayDtmfTone(digit);
1700 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001701 }
1702
1703 private void stopDtmfTone(String callId) {
1704 Log.d(this, "stopDtmfTone %s", callId);
Yorke Leea0d3ca92014-09-15 19:18:13 -07001705 if (mConnectionById.containsKey(callId)) {
1706 findConnectionForAction(callId, "stopDtmfTone").onStopDtmfTone();
1707 } else {
1708 findConferenceForAction(callId, "stopDtmfTone").onStopDtmfTone();
1709 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001710 }
1711
Santos Cordon823fd3c2014-08-07 18:35:18 -07001712 private void conference(String callId1, String callId2) {
1713 Log.d(this, "conference %s, %s", callId1, callId2);
Santos Cordon980acb92014-05-31 10:31:19 -07001714
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001715 // Attempt to get second connection or conference.
Santos Cordon823fd3c2014-08-07 18:35:18 -07001716 Connection connection2 = findConnectionForAction(callId2, "conference");
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001717 Conference conference2 = getNullConference();
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001718 if (connection2 == getNullConnection()) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001719 conference2 = findConferenceForAction(callId2, "conference");
1720 if (conference2 == getNullConference()) {
1721 Log.w(this, "Connection2 or Conference2 missing in conference request %s.",
1722 callId2);
1723 return;
1724 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07001725 }
Santos Cordonb6939982014-06-04 20:20:58 -07001726
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001727 // Attempt to get first connection or conference and perform merge.
Ihab Awad50e35062014-09-30 09:17:03 -07001728 Connection connection1 = findConnectionForAction(callId1, "conference");
1729 if (connection1 == getNullConnection()) {
1730 Conference conference1 = findConferenceForAction(callId1, "addConnection");
1731 if (conference1 == getNullConference()) {
1732 Log.w(this,
1733 "Connection1 or Conference1 missing in conference request %s.",
1734 callId1);
1735 } else {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001736 // Call 1 is a conference.
1737 if (connection2 != getNullConnection()) {
1738 // Call 2 is a connection so merge via call 1 (conference).
1739 conference1.onMerge(connection2);
1740 } else {
1741 // Call 2 is ALSO a conference; this should never happen.
1742 Log.wtf(this, "There can only be one conference and an attempt was made to " +
1743 "merge two conferences.");
1744 return;
1745 }
Ihab Awad50e35062014-09-30 09:17:03 -07001746 }
1747 } else {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001748 // Call 1 is a connection.
1749 if (conference2 != getNullConference()) {
1750 // Call 2 is a conference, so merge via call 2.
1751 conference2.onMerge(connection1);
1752 } else {
1753 // Call 2 is a connection, so merge together.
1754 onConference(connection1, connection2);
1755 }
Ihab Awad50e35062014-09-30 09:17:03 -07001756 }
Santos Cordon980acb92014-05-31 10:31:19 -07001757 }
1758
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001759 private void splitFromConference(String callId) {
Santos Cordonb6939982014-06-04 20:20:58 -07001760 Log.d(this, "splitFromConference(%s)", callId);
Santos Cordon980acb92014-05-31 10:31:19 -07001761
1762 Connection connection = findConnectionForAction(callId, "splitFromConference");
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001763 if (connection == getNullConnection()) {
Santos Cordon980acb92014-05-31 10:31:19 -07001764 Log.w(this, "Connection missing in conference request %s.", callId);
1765 return;
1766 }
1767
Santos Cordon0159ac02014-08-21 14:28:11 -07001768 Conference conference = connection.getConference();
1769 if (conference != null) {
1770 conference.onSeparate(connection);
1771 }
Santos Cordon980acb92014-05-31 10:31:19 -07001772 }
1773
Santos Cordona4868042014-09-04 17:39:22 -07001774 private void mergeConference(String callId) {
1775 Log.d(this, "mergeConference(%s)", callId);
1776 Conference conference = findConferenceForAction(callId, "mergeConference");
1777 if (conference != null) {
1778 conference.onMerge();
1779 }
1780 }
1781
1782 private void swapConference(String callId) {
1783 Log.d(this, "swapConference(%s)", callId);
1784 Conference conference = findConferenceForAction(callId, "swapConference");
1785 if (conference != null) {
1786 conference.onSwap();
1787 }
1788 }
1789
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001790 /**
1791 * Notifies a {@link Connection} of a request to pull an external call.
1792 *
1793 * See {@link Call#pullExternalCall()}.
1794 *
1795 * @param callId The ID of the call to pull.
1796 */
1797 private void pullExternalCall(String callId) {
1798 Log.d(this, "pullExternalCall(%s)", callId);
1799 Connection connection = findConnectionForAction(callId, "pullExternalCall");
1800 if (connection != null) {
1801 connection.onPullExternalCall();
1802 }
1803 }
1804
1805 /**
1806 * Notifies a {@link Connection} of a call event.
1807 *
1808 * See {@link Call#sendCallEvent(String, Bundle)}.
1809 *
1810 * @param callId The ID of the call receiving the event.
1811 * @param event The event.
1812 * @param extras Extras associated with the event.
1813 */
1814 private void sendCallEvent(String callId, String event, Bundle extras) {
1815 Log.d(this, "sendCallEvent(%s, %s)", callId, event);
1816 Connection connection = findConnectionForAction(callId, "sendCallEvent");
1817 if (connection != null) {
1818 connection.onCallEvent(event, extras);
1819 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001820 }
1821
Tyler Gunndee56a82016-03-23 16:06:34 -07001822 /**
Tyler Gunn79bc1ec2018-01-22 15:17:54 -08001823 * Notifies a {@link Connection} that a handover has completed.
1824 *
1825 * @param callId The ID of the call which completed handover.
1826 */
1827 private void notifyHandoverComplete(String callId) {
1828 Log.d(this, "notifyHandoverComplete(%s)", callId);
1829 Connection connection = findConnectionForAction(callId, "notifyHandoverComplete");
1830 if (connection != null) {
1831 connection.onHandoverComplete();
1832 }
1833 }
1834
1835 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001836 * Notifies a {@link Connection} or {@link Conference} of a change to the extras from Telecom.
1837 * <p>
1838 * These extra changes can originate from Telecom itself, or from an {@link InCallService} via
1839 * the {@link android.telecom.Call#putExtra(String, boolean)},
1840 * {@link android.telecom.Call#putExtra(String, int)},
1841 * {@link android.telecom.Call#putExtra(String, String)},
1842 * {@link Call#removeExtras(List)}.
1843 *
1844 * @param callId The ID of the call receiving the event.
1845 * @param extras The new extras bundle.
1846 */
1847 private void handleExtrasChanged(String callId, Bundle extras) {
1848 Log.d(this, "handleExtrasChanged(%s, %s)", callId, extras);
1849 if (mConnectionById.containsKey(callId)) {
1850 findConnectionForAction(callId, "handleExtrasChanged").handleExtrasChanged(extras);
1851 } else if (mConferenceById.containsKey(callId)) {
1852 findConferenceForAction(callId, "handleExtrasChanged").handleExtrasChanged(extras);
1853 }
1854 }
1855
Hall Liub64ac4c2017-02-06 10:49:48 -08001856 private void startRtt(String callId, Connection.RttTextStream rttTextStream) {
1857 Log.d(this, "startRtt(%s)", callId);
1858 if (mConnectionById.containsKey(callId)) {
1859 findConnectionForAction(callId, "startRtt").onStartRtt(rttTextStream);
1860 } else if (mConferenceById.containsKey(callId)) {
1861 Log.w(this, "startRtt called on a conference.");
1862 }
1863 }
1864
1865 private void stopRtt(String callId) {
1866 Log.d(this, "stopRtt(%s)", callId);
1867 if (mConnectionById.containsKey(callId)) {
1868 findConnectionForAction(callId, "stopRtt").onStopRtt();
1869 } else if (mConferenceById.containsKey(callId)) {
1870 Log.w(this, "stopRtt called on a conference.");
1871 }
1872 }
1873
1874 private void handleRttUpgradeResponse(String callId, Connection.RttTextStream rttTextStream) {
1875 Log.d(this, "handleRttUpgradeResponse(%s, %s)", callId, rttTextStream == null);
1876 if (mConnectionById.containsKey(callId)) {
1877 findConnectionForAction(callId, "handleRttUpgradeResponse")
1878 .handleRttUpgradeResponse(rttTextStream);
1879 } else if (mConferenceById.containsKey(callId)) {
1880 Log.w(this, "handleRttUpgradeResponse called on a conference.");
1881 }
1882 }
1883
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001884 private void onPostDialContinue(String callId, boolean proceed) {
Evan Charlton6dea4ac2014-06-03 14:07:13 -07001885 Log.d(this, "onPostDialContinue(%s)", callId);
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001886 findConnectionForAction(callId, "stopDtmfTone").onPostDialContinue(proceed);
Evan Charlton6dea4ac2014-06-03 14:07:13 -07001887 }
1888
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001889 private void onAdapterAttached() {
Ihab Awad9c3f1882014-06-30 21:17:13 -07001890 if (mAreAccountsInitialized) {
Santos Cordon52d8a152014-06-17 19:08:45 -07001891 // No need to query again if we already did it.
1892 return;
1893 }
1894
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001895 mAdapter.queryRemoteConnectionServices(new RemoteServiceCallback.Stub() {
Santos Cordon52d8a152014-06-17 19:08:45 -07001896 @Override
1897 public void onResult(
1898 final List<ComponentName> componentNames,
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001899 final List<IBinder> services) {
Brad Ebinger0c3541b2016-11-01 14:11:38 -07001900 mHandler.post(new android.telecom.Logging.Runnable("oAA.qRCS.oR", null /*lock*/) {
Ihab Awad6107bab2014-08-18 09:23:25 -07001901 @Override
Brad Ebinger0c3541b2016-11-01 14:11:38 -07001902 public void loggedRun() {
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001903 for (int i = 0; i < componentNames.size() && i < services.size(); i++) {
Santos Cordon52d8a152014-06-17 19:08:45 -07001904 mRemoteConnectionManager.addConnectionService(
1905 componentNames.get(i),
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001906 IConnectionService.Stub.asInterface(services.get(i)));
Santos Cordon52d8a152014-06-17 19:08:45 -07001907 }
Ihab Awad5d0410f2014-07-30 10:07:40 -07001908 onAccountsInitialized();
Sailesh Nepalc5b01572014-07-14 16:29:44 -07001909 Log.d(this, "remote connection services found: " + services);
Santos Cordon52d8a152014-06-17 19:08:45 -07001910 }
Brad Ebinger0c3541b2016-11-01 14:11:38 -07001911 }.prepare());
Santos Cordon52d8a152014-06-17 19:08:45 -07001912 }
1913
1914 @Override
1915 public void onError() {
Brad Ebinger0c3541b2016-11-01 14:11:38 -07001916 mHandler.post(new android.telecom.Logging.Runnable("oAA.qRCS.oE", null /*lock*/) {
Ihab Awad6107bab2014-08-18 09:23:25 -07001917 @Override
Brad Ebinger0c3541b2016-11-01 14:11:38 -07001918 public void loggedRun() {
Ihab Awad9c3f1882014-06-30 21:17:13 -07001919 mAreAccountsInitialized = true;
Santos Cordon52d8a152014-06-17 19:08:45 -07001920 }
Brad Ebinger0c3541b2016-11-01 14:11:38 -07001921 }.prepare());
Santos Cordon52d8a152014-06-17 19:08:45 -07001922 }
1923 });
1924 }
1925
Ihab Awadf8b69882014-07-25 15:14:01 -07001926 /**
1927 * Ask some other {@code ConnectionService} to create a {@code RemoteConnection} given an
Santos Cordona663f862014-10-29 13:49:58 -07001928 * incoming request. This is used by {@code ConnectionService}s that are registered with
1929 * {@link PhoneAccount#CAPABILITY_CONNECTION_MANAGER} and want to be able to manage
1930 * SIM-based incoming calls.
Ihab Awadf8b69882014-07-25 15:14:01 -07001931 *
1932 * @param connectionManagerPhoneAccount See description at
1933 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
1934 * @param request Details about the incoming call.
1935 * @return The {@code Connection} object to satisfy this call, or {@code null} to
1936 * not handle the call.
1937 */
1938 public final RemoteConnection createRemoteIncomingConnection(
1939 PhoneAccountHandle connectionManagerPhoneAccount,
1940 ConnectionRequest request) {
1941 return mRemoteConnectionManager.createRemoteConnection(
1942 connectionManagerPhoneAccount, request, true);
Santos Cordon52d8a152014-06-17 19:08:45 -07001943 }
1944
1945 /**
Ihab Awadf8b69882014-07-25 15:14:01 -07001946 * Ask some other {@code ConnectionService} to create a {@code RemoteConnection} given an
Santos Cordona663f862014-10-29 13:49:58 -07001947 * outgoing request. This is used by {@code ConnectionService}s that are registered with
1948 * {@link PhoneAccount#CAPABILITY_CONNECTION_MANAGER} and want to be able to use the
1949 * SIM-based {@code ConnectionService} to place its outgoing calls.
Ihab Awadf8b69882014-07-25 15:14:01 -07001950 *
1951 * @param connectionManagerPhoneAccount See description at
1952 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
Cuihtlauac ALVARADO0b3b2a52016-09-13 14:49:41 +02001953 * @param request Details about the outgoing call.
Ihab Awadf8b69882014-07-25 15:14:01 -07001954 * @return The {@code Connection} object to satisfy this call, or {@code null} to
1955 * not handle the call.
1956 */
1957 public final RemoteConnection createRemoteOutgoingConnection(
1958 PhoneAccountHandle connectionManagerPhoneAccount,
1959 ConnectionRequest request) {
1960 return mRemoteConnectionManager.createRemoteConnection(
1961 connectionManagerPhoneAccount, request, false);
1962 }
1963
1964 /**
Santos Cordona663f862014-10-29 13:49:58 -07001965 * Indicates to the relevant {@code RemoteConnectionService} that the specified
1966 * {@link RemoteConnection}s should be merged into a conference call.
1967 * <p>
1968 * If the conference request is successful, the method {@link #onRemoteConferenceAdded} will
1969 * be invoked.
1970 *
1971 * @param remoteConnection1 The first of the remote connections to conference.
1972 * @param remoteConnection2 The second of the remote connections to conference.
Ihab Awadb8e85c72014-08-23 20:34:57 -07001973 */
1974 public final void conferenceRemoteConnections(
Santos Cordona663f862014-10-29 13:49:58 -07001975 RemoteConnection remoteConnection1,
1976 RemoteConnection remoteConnection2) {
1977 mRemoteConnectionManager.conferenceRemoteConnections(remoteConnection1, remoteConnection2);
Ihab Awadb8e85c72014-08-23 20:34:57 -07001978 }
1979
1980 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07001981 * Adds a new conference call. When a conference call is created either as a result of an
1982 * explicit request via {@link #onConference} or otherwise, the connection service should supply
1983 * an instance of {@link Conference} by invoking this method. A conference call provided by this
1984 * method will persist until {@link Conference#destroy} is invoked on the conference instance.
1985 *
1986 * @param conference The new conference object.
1987 */
1988 public final void addConference(Conference conference) {
Rekha Kumar07366812015-03-24 16:42:31 -07001989 Log.d(this, "addConference: conference=%s", conference);
1990
Santos Cordon823fd3c2014-08-07 18:35:18 -07001991 String id = addConferenceInternal(conference);
1992 if (id != null) {
1993 List<String> connectionIds = new ArrayList<>(2);
1994 for (Connection connection : conference.getConnections()) {
1995 if (mIdByConnection.containsKey(connection)) {
1996 connectionIds.add(mIdByConnection.get(connection));
1997 }
1998 }
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001999 conference.setTelecomCallId(id);
Santos Cordon823fd3c2014-08-07 18:35:18 -07002000 ParcelableConference parcelableConference = new ParcelableConference(
Nancy Chenea38cca2014-09-05 16:38:49 -07002001 conference.getPhoneAccountHandle(),
Santos Cordon823fd3c2014-08-07 18:35:18 -07002002 conference.getState(),
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002003 conference.getConnectionCapabilities(),
Tyler Gunn720c6642016-03-22 09:02:47 -07002004 conference.getConnectionProperties(),
Tyler Gunncd5d33c2015-01-12 09:02:01 -08002005 connectionIds,
Rekha Kumar07366812015-03-24 16:42:31 -07002006 conference.getVideoProvider() == null ?
2007 null : conference.getVideoProvider().getInterface(),
2008 conference.getVideoState(),
Andrew Lee3e3e2f22015-04-16 13:48:43 -07002009 conference.getConnectTimeMillis(),
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002010 conference.getConnectElapsedTime(),
Santos Cordon6b7f9552015-05-27 17:21:45 -07002011 conference.getStatusHints(),
2012 conference.getExtras());
Andrew Lee0f51da32015-04-16 13:11:55 -07002013
Santos Cordon823fd3c2014-08-07 18:35:18 -07002014 mAdapter.addConferenceCall(id, parcelableConference);
Rekha Kumar07366812015-03-24 16:42:31 -07002015 mAdapter.setVideoProvider(id, conference.getVideoProvider());
2016 mAdapter.setVideoState(id, conference.getVideoState());
Santos Cordon823fd3c2014-08-07 18:35:18 -07002017
2018 // Go through any child calls and set the parent.
2019 for (Connection connection : conference.getConnections()) {
2020 String connectionId = mIdByConnection.get(connection);
2021 if (connectionId != null) {
2022 mAdapter.setIsConferenced(connectionId, id);
2023 }
2024 }
Pengquan Meng70c9885332017-10-02 18:09:03 -07002025 onConferenceAdded(conference);
Santos Cordon823fd3c2014-08-07 18:35:18 -07002026 }
2027 }
2028
2029 /**
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002030 * Adds a connection created by the {@link ConnectionService} and informs telecom of the new
2031 * connection.
2032 *
2033 * @param phoneAccountHandle The phone account handle for the connection.
2034 * @param connection The connection to add.
2035 */
2036 public final void addExistingConnection(PhoneAccountHandle phoneAccountHandle,
2037 Connection connection) {
Tyler Gunn78da7812017-05-09 14:34:57 -07002038 addExistingConnection(phoneAccountHandle, connection, null /* conference */);
2039 }
2040
2041 /**
Pengquan Meng731c1a32017-11-21 18:01:13 -08002042 * Call to inform Telecom that your {@link ConnectionService} has released call resources (e.g
2043 * microphone, camera).
2044 *
2045 * @see ConnectionService#onConnectionServiceFocusLost()
2046 */
2047 public final void connectionServiceFocusReleased() {
2048 mAdapter.onConnectionServiceFocusReleased();
2049 }
2050
2051 /**
Tyler Gunn78da7812017-05-09 14:34:57 -07002052 * Adds a connection created by the {@link ConnectionService} and informs telecom of the new
2053 * connection.
2054 *
2055 * @param phoneAccountHandle The phone account handle for the connection.
2056 * @param connection The connection to add.
2057 * @param conference The parent conference of the new connection.
2058 * @hide
2059 */
2060 public final void addExistingConnection(PhoneAccountHandle phoneAccountHandle,
2061 Connection connection, Conference conference) {
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002062
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002063 String id = addExistingConnectionInternal(phoneAccountHandle, connection);
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002064 if (id != null) {
2065 List<String> emptyList = new ArrayList<>(0);
Tyler Gunn78da7812017-05-09 14:34:57 -07002066 String conferenceId = null;
2067 if (conference != null) {
2068 conferenceId = mIdByConference.get(conference);
2069 }
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002070
2071 ParcelableConnection parcelableConnection = new ParcelableConnection(
2072 phoneAccountHandle,
2073 connection.getState(),
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002074 connection.getConnectionCapabilities(),
Tyler Gunn720c6642016-03-22 09:02:47 -07002075 connection.getConnectionProperties(),
Christine Hallstrom2830ce92016-11-30 16:06:42 -08002076 connection.getSupportedAudioRoutes(),
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002077 connection.getAddress(),
2078 connection.getAddressPresentation(),
2079 connection.getCallerDisplayName(),
2080 connection.getCallerDisplayNamePresentation(),
2081 connection.getVideoProvider() == null ?
2082 null : connection.getVideoProvider().getInterface(),
2083 connection.getVideoState(),
2084 connection.isRingbackRequested(),
2085 connection.getAudioModeIsVoip(),
Roshan Piuse927ec02015-07-15 15:47:21 -07002086 connection.getConnectTimeMillis(),
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002087 connection.getConnectElapsedTimeMillis(),
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002088 connection.getStatusHints(),
2089 connection.getDisconnectCause(),
Santos Cordon6b7f9552015-05-27 17:21:45 -07002090 emptyList,
Tyler Gunn78da7812017-05-09 14:34:57 -07002091 connection.getExtras(),
2092 conferenceId);
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002093 mAdapter.addExistingConnection(id, parcelableConnection);
2094 }
2095 }
2096
2097 /**
Ihab Awadf8b69882014-07-25 15:14:01 -07002098 * Returns all the active {@code Connection}s for which this {@code ConnectionService}
2099 * has taken responsibility.
2100 *
2101 * @return A collection of {@code Connection}s created by this {@code ConnectionService}.
Santos Cordonb6939982014-06-04 20:20:58 -07002102 */
Sailesh Nepal091768c2014-06-30 15:15:23 -07002103 public final Collection<Connection> getAllConnections() {
Santos Cordonb6939982014-06-04 20:20:58 -07002104 return mConnectionById.values();
2105 }
2106
2107 /**
Santos Cordona6018b92016-02-16 14:23:12 -08002108 * Returns all the active {@code Conference}s for which this {@code ConnectionService}
2109 * has taken responsibility.
2110 *
2111 * @return A collection of {@code Conference}s created by this {@code ConnectionService}.
2112 */
2113 public final Collection<Conference> getAllConferences() {
2114 return mConferenceById.values();
2115 }
2116
2117 /**
Ihab Awadf8b69882014-07-25 15:14:01 -07002118 * Create a {@code Connection} given an incoming request. This is used to attach to existing
2119 * incoming calls.
Evan Charltonbf11f982014-07-20 22:06:28 -07002120 *
Ihab Awadf8b69882014-07-25 15:14:01 -07002121 * @param connectionManagerPhoneAccount See description at
2122 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
2123 * @param request Details about the incoming call.
2124 * @return The {@code Connection} object to satisfy this call, or {@code null} to
2125 * not handle the call.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002126 */
Ihab Awadf8b69882014-07-25 15:14:01 -07002127 public Connection onCreateIncomingConnection(
2128 PhoneAccountHandle connectionManagerPhoneAccount,
2129 ConnectionRequest request) {
2130 return null;
2131 }
Sailesh Nepalc5b01572014-07-14 16:29:44 -07002132
2133 /**
Tyler Gunn041a1fe2017-05-12 10:04:49 -07002134 * Called after the {@link Connection} returned by
2135 * {@link #onCreateIncomingConnection(PhoneAccountHandle, ConnectionRequest)}
2136 * or {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)} has been
2137 * added to the {@link ConnectionService} and sent to Telecom.
2138 *
2139 * @param connection the {@link Connection}.
2140 * @hide
2141 */
2142 public void onCreateConnectionComplete(Connection connection) {
2143 }
2144
2145 /**
Tyler Gunnf5035432017-01-09 09:43:12 -08002146 * Called by Telecom to inform the {@link ConnectionService} that its request to create a new
2147 * incoming {@link Connection} was denied.
2148 * <p>
2149 * Used when a self-managed {@link ConnectionService} attempts to create a new incoming
2150 * {@link Connection}, but Telecom has determined that the call cannot be allowed at this time.
2151 * The {@link ConnectionService} is responsible for silently rejecting the new incoming
2152 * {@link Connection}.
2153 * <p>
2154 * See {@link TelecomManager#isIncomingCallPermitted(PhoneAccountHandle)} for more information.
2155 *
Tyler Gunn159f35c2017-03-02 09:28:37 -08002156 * @param connectionManagerPhoneAccount See description at
2157 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
Tyler Gunnf5035432017-01-09 09:43:12 -08002158 * @param request The incoming connection request.
2159 */
Tyler Gunn159f35c2017-03-02 09:28:37 -08002160 public void onCreateIncomingConnectionFailed(PhoneAccountHandle connectionManagerPhoneAccount,
2161 ConnectionRequest request) {
Tyler Gunnf5035432017-01-09 09:43:12 -08002162 }
2163
2164 /**
2165 * Called by Telecom to inform the {@link ConnectionService} that its request to create a new
2166 * outgoing {@link Connection} was denied.
2167 * <p>
2168 * Used when a self-managed {@link ConnectionService} attempts to create a new outgoing
2169 * {@link Connection}, but Telecom has determined that the call cannot be placed at this time.
2170 * The {@link ConnectionService} is responisible for informing the user that the
2171 * {@link Connection} cannot be made at this time.
2172 * <p>
2173 * See {@link TelecomManager#isOutgoingCallPermitted(PhoneAccountHandle)} for more information.
2174 *
Tyler Gunn159f35c2017-03-02 09:28:37 -08002175 * @param connectionManagerPhoneAccount See description at
2176 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
Tyler Gunnf5035432017-01-09 09:43:12 -08002177 * @param request The outgoing connection request.
2178 */
Tyler Gunn159f35c2017-03-02 09:28:37 -08002179 public void onCreateOutgoingConnectionFailed(PhoneAccountHandle connectionManagerPhoneAccount,
2180 ConnectionRequest request) {
Tyler Gunnf5035432017-01-09 09:43:12 -08002181 }
2182
2183 /**
Shriram Ganesh6bf35ac2014-12-11 17:53:38 -08002184 * Trigger recalculate functinality for conference calls. This is used when a Telephony
2185 * Connection is part of a conference controller but is not yet added to Connection
2186 * Service and hence cannot be added to the conference call.
2187 *
2188 * @hide
2189 */
2190 public void triggerConferenceRecalculate() {
2191 }
2192
2193 /**
Ihab Awadf8b69882014-07-25 15:14:01 -07002194 * Create a {@code Connection} given an outgoing request. This is used to initiate new
2195 * outgoing calls.
Sailesh Nepalc5b01572014-07-14 16:29:44 -07002196 *
Ihab Awadf8b69882014-07-25 15:14:01 -07002197 * @param connectionManagerPhoneAccount The connection manager account to use for managing
2198 * this call.
2199 * <p>
2200 * If this parameter is not {@code null}, it means that this {@code ConnectionService}
2201 * has registered one or more {@code PhoneAccount}s having
2202 * {@link PhoneAccount#CAPABILITY_CONNECTION_MANAGER}. This parameter will contain
2203 * one of these {@code PhoneAccount}s, while the {@code request} will contain another
2204 * (usually but not always distinct) {@code PhoneAccount} to be used for actually
2205 * making the connection.
2206 * <p>
2207 * If this parameter is {@code null}, it means that this {@code ConnectionService} is
2208 * being asked to make a direct connection. The
2209 * {@link ConnectionRequest#getAccountHandle()} of parameter {@code request} will be
2210 * a {@code PhoneAccount} registered by this {@code ConnectionService} to use for
2211 * making the connection.
2212 * @param request Details about the outgoing call.
2213 * @return The {@code Connection} object to satisfy this call, or the result of an invocation
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002214 * of {@link Connection#createFailedConnection(DisconnectCause)} to not handle the call.
Sailesh Nepalc5b01572014-07-14 16:29:44 -07002215 */
Ihab Awadf8b69882014-07-25 15:14:01 -07002216 public Connection onCreateOutgoingConnection(
2217 PhoneAccountHandle connectionManagerPhoneAccount,
2218 ConnectionRequest request) {
2219 return null;
2220 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002221
2222 /**
Sanket Padawea8eddd42017-11-03 11:07:35 -07002223 * Called by Telecom on the initiating side of the handover to create an instance of a
2224 * handover connection.
2225 * @param fromPhoneAccountHandle {@link PhoneAccountHandle} associated with the
2226 * ConnectionService which needs to handover the call.
2227 * @param request Details about the call which needs to be handover.
2228 * @return Connection object corresponding to the handover call.
2229 */
2230 public Connection onCreateOutgoingHandoverConnection(PhoneAccountHandle fromPhoneAccountHandle,
2231 ConnectionRequest request) {
2232 return null;
2233 }
2234
2235 /**
2236 * Called by Telecom on the receiving side of the handover to request the
2237 * {@link ConnectionService} to create an instance of a handover connection.
2238 * @param fromPhoneAccountHandle {@link PhoneAccountHandle} associated with the
2239 * ConnectionService which needs to handover the call.
2240 * @param request Details about the call which needs to be handover.
2241 * @return {@link Connection} object corresponding to the handover call.
2242 */
2243 public Connection onCreateIncomingHandoverConnection(PhoneAccountHandle fromPhoneAccountHandle,
2244 ConnectionRequest request) {
2245 return null;
2246 }
2247
2248 /**
2249 * Called by Telecom in response to a {@code TelecomManager#acceptHandover()}
2250 * invocation which failed.
2251 * @param request Details about the call which needs to be handover.
2252 * @param error Reason for handover failure as defined in
2253 * {@link android.telecom.Call.Callback#HANDOVER_FAILURE_DEST_INVALID_PERM}
2254 */
2255 public void onHandoverFailed(ConnectionRequest request, int error) {
2256 return;
2257 }
2258
2259 /**
Yorke Leec3cf9822014-10-02 09:38:39 -07002260 * Create a {@code Connection} for a new unknown call. An unknown call is a call originating
2261 * from the ConnectionService that was neither a user-initiated outgoing call, nor an incoming
2262 * call created using
2263 * {@code TelecomManager#addNewIncomingCall(PhoneAccountHandle, android.os.Bundle)}.
2264 *
Yorke Lee770ed6e2014-10-06 18:58:52 -07002265 * @hide
Yorke Leec3cf9822014-10-02 09:38:39 -07002266 */
2267 public Connection onCreateUnknownConnection(PhoneAccountHandle connectionManagerPhoneAccount,
2268 ConnectionRequest request) {
Brad Ebingerb32d4f82016-10-24 16:40:49 -07002269 return null;
Yorke Leec3cf9822014-10-02 09:38:39 -07002270 }
2271
2272 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07002273 * Conference two specified connections. Invoked when the user has made a request to merge the
2274 * specified connections into a conference call. In response, the connection service should
2275 * create an instance of {@link Conference} and pass it into {@link #addConference}.
Santos Cordonb6939982014-06-04 20:20:58 -07002276 *
Santos Cordon823fd3c2014-08-07 18:35:18 -07002277 * @param connection1 A connection to merge into a conference call.
2278 * @param connection2 A connection to merge into a conference call.
Santos Cordonb6939982014-06-04 20:20:58 -07002279 */
Santos Cordon823fd3c2014-08-07 18:35:18 -07002280 public void onConference(Connection connection1, Connection connection2) {}
Santos Cordonb6939982014-06-04 20:20:58 -07002281
Santos Cordona663f862014-10-29 13:49:58 -07002282 /**
Pengquan Meng70c9885332017-10-02 18:09:03 -07002283 * Called when a connection is added.
2284 * @hide
2285 */
2286 public void onConnectionAdded(Connection connection) {}
2287
2288 /**
2289 * Called when a connection is removed.
2290 * @hide
2291 */
2292 public void onConnectionRemoved(Connection connection) {}
2293
2294 /**
2295 * Called when a conference is added.
2296 * @hide
2297 */
2298 public void onConferenceAdded(Conference conference) {}
2299
2300 /**
2301 * Called when a conference is removed.
2302 * @hide
2303 */
2304 public void onConferenceRemoved(Conference conference) {}
2305
2306 /**
Santos Cordona663f862014-10-29 13:49:58 -07002307 * Indicates that a remote conference has been created for existing {@link RemoteConnection}s.
2308 * When this method is invoked, this {@link ConnectionService} should create its own
2309 * representation of the conference call and send it to telecom using {@link #addConference}.
2310 * <p>
2311 * This is only relevant to {@link ConnectionService}s which are registered with
2312 * {@link PhoneAccount#CAPABILITY_CONNECTION_MANAGER}.
2313 *
2314 * @param conference The remote conference call.
2315 */
Ihab Awadb8e85c72014-08-23 20:34:57 -07002316 public void onRemoteConferenceAdded(RemoteConference conference) {}
2317
Santos Cordon823fd3c2014-08-07 18:35:18 -07002318 /**
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002319 * Called when an existing connection is added remotely.
2320 * @param connection The existing connection which was added.
2321 */
2322 public void onRemoteExistingConnectionAdded(RemoteConnection connection) {}
2323
2324 /**
Pengquan Meng731c1a32017-11-21 18:01:13 -08002325 * Called when the {@link ConnectionService} has lost the call focus.
2326 * The {@link ConnectionService} should release the call resources and invokes
2327 * {@link ConnectionService#connectionServiceFocusReleased()} to inform telecom that it has
2328 * released the call resources.
2329 */
2330 public void onConnectionServiceFocusLost() {}
2331
2332 /**
2333 * Called when the {@link ConnectionService} has gained the call focus. The
2334 * {@link ConnectionService} can acquire the call resources at this time.
2335 */
2336 public void onConnectionServiceFocusGained() {}
2337
2338 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07002339 * @hide
2340 */
2341 public boolean containsConference(Conference conference) {
2342 return mIdByConference.containsKey(conference);
2343 }
2344
Ihab Awadb8e85c72014-08-23 20:34:57 -07002345 /** {@hide} */
2346 void addRemoteConference(RemoteConference remoteConference) {
2347 onRemoteConferenceAdded(remoteConference);
2348 }
2349
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002350 /** {@hide} */
2351 void addRemoteExistingConnection(RemoteConnection remoteConnection) {
2352 onRemoteExistingConnectionAdded(remoteConnection);
2353 }
2354
Ihab Awad5d0410f2014-07-30 10:07:40 -07002355 private void onAccountsInitialized() {
2356 mAreAccountsInitialized = true;
2357 for (Runnable r : mPreInitializationConnectionRequests) {
2358 r.run();
2359 }
2360 mPreInitializationConnectionRequests.clear();
2361 }
2362
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002363 /**
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002364 * Adds an existing connection to the list of connections, identified by a new call ID unique
2365 * to this connection service.
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002366 *
2367 * @param connection The connection.
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002368 * @return The ID of the connection (e.g. the call-id).
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002369 */
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002370 private String addExistingConnectionInternal(PhoneAccountHandle handle, Connection connection) {
2371 String id;
Tyler Gunncd6ccfd2016-10-17 15:48:19 -07002372
2373 if (connection.getExtras() != null && connection.getExtras()
2374 .containsKey(Connection.EXTRA_ORIGINAL_CONNECTION_ID)) {
2375 id = connection.getExtras().getString(Connection.EXTRA_ORIGINAL_CONNECTION_ID);
2376 Log.d(this, "addExistingConnectionInternal - conn %s reusing original id %s",
2377 connection.getTelecomCallId(), id);
2378 } else if (handle == null) {
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002379 // If no phone account handle was provided, we cannot be sure the call ID is unique,
2380 // so just use a random UUID.
2381 id = UUID.randomUUID().toString();
2382 } else {
2383 // Phone account handle was provided, so use the ConnectionService class name as a
2384 // prefix for a unique incremental call ID.
2385 id = handle.getComponentName().getClassName() + "@" + getNextCallId();
2386 }
Pengquan Meng70c9885332017-10-02 18:09:03 -07002387 addConnection(handle, id, connection);
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002388 return id;
2389 }
2390
Pengquan Meng70c9885332017-10-02 18:09:03 -07002391 private void addConnection(PhoneAccountHandle handle, String callId, Connection connection) {
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002392 connection.setTelecomCallId(callId);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002393 mConnectionById.put(callId, connection);
2394 mIdByConnection.put(connection, callId);
2395 connection.addConnectionListener(mConnectionListener);
Santos Cordon823fd3c2014-08-07 18:35:18 -07002396 connection.setConnectionService(this);
Pengquan Meng70c9885332017-10-02 18:09:03 -07002397 connection.setPhoneAccountHandle(handle);
2398 onConnectionAdded(connection);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002399 }
2400
Anthony Lee30e65842014-11-06 16:30:53 -08002401 /** {@hide} */
2402 protected void removeConnection(Connection connection) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07002403 connection.unsetConnectionService(this);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002404 connection.removeConnectionListener(mConnectionListener);
Chenjie Luoe370b532016-05-12 16:59:43 -07002405 String id = mIdByConnection.get(connection);
2406 if (id != null) {
2407 mConnectionById.remove(id);
2408 mIdByConnection.remove(connection);
2409 mAdapter.removeCall(id);
Pengquan Meng70c9885332017-10-02 18:09:03 -07002410 onConnectionRemoved(connection);
Chenjie Luoe370b532016-05-12 16:59:43 -07002411 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002412 }
2413
Santos Cordon823fd3c2014-08-07 18:35:18 -07002414 private String addConferenceInternal(Conference conference) {
Tyler Gunncd6ccfd2016-10-17 15:48:19 -07002415 String originalId = null;
2416 if (conference.getExtras() != null && conference.getExtras()
2417 .containsKey(Connection.EXTRA_ORIGINAL_CONNECTION_ID)) {
2418 originalId = conference.getExtras().getString(Connection.EXTRA_ORIGINAL_CONNECTION_ID);
2419 Log.d(this, "addConferenceInternal: conf %s reusing original id %s",
2420 conference.getTelecomCallId(),
2421 originalId);
2422 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07002423 if (mIdByConference.containsKey(conference)) {
2424 Log.w(this, "Re-adding an existing conference: %s.", conference);
2425 } else if (conference != null) {
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002426 // Conferences do not (yet) have a PhoneAccountHandle associated with them, so we
2427 // cannot determine a ConnectionService class name to associate with the ID, so use
2428 // a unique UUID (for now).
Tyler Gunncd6ccfd2016-10-17 15:48:19 -07002429 String id = originalId == null ? UUID.randomUUID().toString() : originalId;
Santos Cordon823fd3c2014-08-07 18:35:18 -07002430 mConferenceById.put(id, conference);
2431 mIdByConference.put(conference, id);
2432 conference.addListener(mConferenceListener);
2433 return id;
2434 }
2435
2436 return null;
2437 }
2438
2439 private void removeConference(Conference conference) {
2440 if (mIdByConference.containsKey(conference)) {
2441 conference.removeListener(mConferenceListener);
2442
2443 String id = mIdByConference.get(conference);
2444 mConferenceById.remove(id);
2445 mIdByConference.remove(conference);
2446 mAdapter.removeCall(id);
Pengquan Meng70c9885332017-10-02 18:09:03 -07002447
2448 onConferenceRemoved(conference);
Santos Cordon823fd3c2014-08-07 18:35:18 -07002449 }
2450 }
2451
Ihab Awad542e0ea2014-05-16 10:22:16 -07002452 private Connection findConnectionForAction(String callId, String action) {
Tyler Gunn0a88f2e2017-06-16 20:20:34 -07002453 if (callId != null && mConnectionById.containsKey(callId)) {
Ihab Awad542e0ea2014-05-16 10:22:16 -07002454 return mConnectionById.get(callId);
2455 }
Ihab Awad60ac30b2014-05-20 22:32:12 -07002456 Log.w(this, "%s - Cannot find Connection %s", action, callId);
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07002457 return getNullConnection();
2458 }
2459
2460 static synchronized Connection getNullConnection() {
2461 if (sNullConnection == null) {
2462 sNullConnection = new Connection() {};
2463 }
2464 return sNullConnection;
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002465 }
Santos Cordon0159ac02014-08-21 14:28:11 -07002466
2467 private Conference findConferenceForAction(String conferenceId, String action) {
2468 if (mConferenceById.containsKey(conferenceId)) {
2469 return mConferenceById.get(conferenceId);
2470 }
2471 Log.w(this, "%s - Cannot find conference %s", action, conferenceId);
2472 return getNullConference();
2473 }
2474
Ihab Awadb8e85c72014-08-23 20:34:57 -07002475 private List<String> createConnectionIdList(List<Connection> connections) {
2476 List<String> ids = new ArrayList<>();
2477 for (Connection c : connections) {
2478 if (mIdByConnection.containsKey(c)) {
2479 ids.add(mIdByConnection.get(c));
2480 }
2481 }
2482 Collections.sort(ids);
2483 return ids;
2484 }
2485
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002486 /**
2487 * Builds a list of {@link Connection} and {@link Conference} IDs based on the list of
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002488 * {@link Conferenceable}s passed in.
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002489 *
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002490 * @param conferenceables The {@link Conferenceable} connections and conferences.
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002491 * @return List of string conference and call Ids.
2492 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002493 private List<String> createIdList(List<Conferenceable> conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002494 List<String> ids = new ArrayList<>();
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002495 for (Conferenceable c : conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002496 // Only allow Connection and Conference conferenceables.
2497 if (c instanceof Connection) {
2498 Connection connection = (Connection) c;
2499 if (mIdByConnection.containsKey(connection)) {
2500 ids.add(mIdByConnection.get(connection));
2501 }
2502 } else if (c instanceof Conference) {
2503 Conference conference = (Conference) c;
2504 if (mIdByConference.containsKey(conference)) {
2505 ids.add(mIdByConference.get(conference));
2506 }
2507 }
2508 }
2509 Collections.sort(ids);
2510 return ids;
2511 }
2512
Santos Cordon0159ac02014-08-21 14:28:11 -07002513 private Conference getNullConference() {
2514 if (sNullConference == null) {
2515 sNullConference = new Conference(null) {};
2516 }
2517 return sNullConference;
2518 }
Santos Cordon29f2f2e2014-09-11 19:50:24 -07002519
2520 private void endAllConnections() {
2521 // Unbound from telecomm. We should end all connections and conferences.
2522 for (Connection connection : mIdByConnection.keySet()) {
2523 // only operate on top-level calls. Conference calls will be removed on their own.
2524 if (connection.getConference() == null) {
2525 connection.onDisconnect();
2526 }
2527 }
2528 for (Conference conference : mIdByConference.keySet()) {
2529 conference.onDisconnect();
2530 }
2531 }
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002532
2533 /**
2534 * Retrieves the next call ID as maintainted by the connection service.
2535 *
2536 * @return The call ID.
2537 */
2538 private int getNextCallId() {
Brad Ebingerb32d4f82016-10-24 16:40:49 -07002539 synchronized (mIdSyncRoot) {
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002540 return ++mId;
2541 }
2542 }
Santos Cordon980acb92014-05-31 10:31:19 -07002543}