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