blob: c1040adc5163f4a57eef7d52dea6efad06e407f3 [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";
Tyler Gunn79bc1ec2018-01-22 15:17:54 -0800143 private static final String SESSION_HANDOVER_COMPLETE = "CS.hC";
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700144 private static final String SESSION_EXTRAS_CHANGED = "CS.oEC";
Hall Liub64ac4c2017-02-06 10:49:48 -0800145 private static final String SESSION_START_RTT = "CS.+RTT";
146 private static final String SESSION_STOP_RTT = "CS.-RTT";
147 private static final String SESSION_RTT_UPGRADE_RESPONSE = "CS.rTRUR";
Pengquan Meng731c1a32017-11-21 18:01:13 -0800148 private static final String SESSION_CONNECTION_SERVICE_FOCUS_LOST = "CS.cSFL";
149 private static final String SESSION_CONNECTION_SERVICE_FOCUS_GAINED = "CS.cSFG";
Sanket Padawe4cc8ed532017-12-04 16:22:20 -0800150 private static final String SESSION_HANDOVER_FAILED = "CS.haF";
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700151
Ihab Awad8aecfed2014-08-08 17:06:11 -0700152 private static final int MSG_ADD_CONNECTION_SERVICE_ADAPTER = 1;
Sailesh Nepalc5b01572014-07-14 16:29:44 -0700153 private static final int MSG_CREATE_CONNECTION = 2;
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700154 private static final int MSG_ABORT = 3;
Sailesh Nepalc5b01572014-07-14 16:29:44 -0700155 private static final int MSG_ANSWER = 4;
156 private static final int MSG_REJECT = 5;
157 private static final int MSG_DISCONNECT = 6;
158 private static final int MSG_HOLD = 7;
159 private static final int MSG_UNHOLD = 8;
Yorke Lee4af59352015-05-13 14:14:54 -0700160 private static final int MSG_ON_CALL_AUDIO_STATE_CHANGED = 9;
Sailesh Nepalc5b01572014-07-14 16:29:44 -0700161 private static final int MSG_PLAY_DTMF_TONE = 10;
162 private static final int MSG_STOP_DTMF_TONE = 11;
163 private static final int MSG_CONFERENCE = 12;
164 private static final int MSG_SPLIT_FROM_CONFERENCE = 13;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700165 private static final int MSG_ON_POST_DIAL_CONTINUE = 14;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700166 private static final int MSG_REMOVE_CONNECTION_SERVICE_ADAPTER = 16;
Tyler Gunnbe74de02014-08-29 14:51:48 -0700167 private static final int MSG_ANSWER_VIDEO = 17;
Santos Cordona4868042014-09-04 17:39:22 -0700168 private static final int MSG_MERGE_CONFERENCE = 18;
169 private static final int MSG_SWAP_CONFERENCE = 19;
Bryce Lee81901682015-08-28 16:38:02 -0700170 private static final int MSG_REJECT_WITH_MESSAGE = 20;
Bryce Leecac50772015-11-17 15:13:29 -0800171 private static final int MSG_SILENCE = 21;
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700172 private static final int MSG_PULL_EXTERNAL_CALL = 22;
173 private static final int MSG_SEND_CALL_EVENT = 23;
Tyler Gunndee56a82016-03-23 16:06:34 -0700174 private static final int MSG_ON_EXTRAS_CHANGED = 24;
Tyler Gunn44e01912017-01-31 10:49:05 -0800175 private static final int MSG_CREATE_CONNECTION_FAILED = 25;
Hall Liub64ac4c2017-02-06 10:49:48 -0800176 private static final int MSG_ON_START_RTT = 26;
177 private static final int MSG_ON_STOP_RTT = 27;
178 private static final int MSG_RTT_UPGRADE_RESPONSE = 28;
Tyler Gunn041a1fe2017-05-12 10:04:49 -0700179 private static final int MSG_CREATE_CONNECTION_COMPLETE = 29;
Pengquan Meng731c1a32017-11-21 18:01:13 -0800180 private static final int MSG_CONNECTION_SERVICE_FOCUS_LOST = 30;
181 private static final int MSG_CONNECTION_SERVICE_FOCUS_GAINED = 31;
Sanket Padawe4cc8ed532017-12-04 16:22:20 -0800182 private static final int MSG_HANDOVER_FAILED = 32;
Tyler Gunn79bc1ec2018-01-22 15:17:54 -0800183 private static final int MSG_HANDOVER_COMPLETE = 33;
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700184
Sailesh Nepalcf7020b2014-08-20 10:07:19 -0700185 private static Connection sNullConnection;
186
mike dooley95e80702014-09-18 14:07:52 -0700187 private final Map<String, Connection> mConnectionById = new ConcurrentHashMap<>();
188 private final Map<Connection, String> mIdByConnection = new ConcurrentHashMap<>();
189 private final Map<String, Conference> mConferenceById = new ConcurrentHashMap<>();
190 private final Map<Conference, String> mIdByConference = new ConcurrentHashMap<>();
Ihab Awadb8e85c72014-08-23 20:34:57 -0700191 private final RemoteConnectionManager mRemoteConnectionManager =
192 new RemoteConnectionManager(this);
Ihab Awad5d0410f2014-07-30 10:07:40 -0700193 private final List<Runnable> mPreInitializationConnectionRequests = new ArrayList<>();
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700194 private final ConnectionServiceAdapter mAdapter = new ConnectionServiceAdapter();
Ihab Awad542e0ea2014-05-16 10:22:16 -0700195
Santos Cordon823fd3c2014-08-07 18:35:18 -0700196 private boolean mAreAccountsInitialized = false;
Santos Cordon0159ac02014-08-21 14:28:11 -0700197 private Conference sNullConference;
Tyler Gunnf0500bd2015-09-01 10:59:48 -0700198 private Object mIdSyncRoot = new Object();
199 private int mId = 0;
Santos Cordon823fd3c2014-08-07 18:35:18 -0700200
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700201 private final IBinder mBinder = new IConnectionService.Stub() {
202 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700203 public void addConnectionServiceAdapter(IConnectionServiceAdapter adapter,
204 Session.Info sessionInfo) {
205 Log.startSession(sessionInfo, SESSION_ADD_CS_ADAPTER);
206 try {
207 SomeArgs args = SomeArgs.obtain();
208 args.arg1 = adapter;
209 args.arg2 = Log.createSubsession();
210 mHandler.obtainMessage(MSG_ADD_CONNECTION_SERVICE_ADAPTER, args).sendToTarget();
211 } finally {
212 Log.endSession();
213 }
Ihab Awad8aecfed2014-08-08 17:06:11 -0700214 }
215
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700216 public void removeConnectionServiceAdapter(IConnectionServiceAdapter adapter,
217 Session.Info sessionInfo) {
218 Log.startSession(sessionInfo, SESSION_REMOVE_CS_ADAPTER);
219 try {
220 SomeArgs args = SomeArgs.obtain();
221 args.arg1 = adapter;
222 args.arg2 = Log.createSubsession();
223 mHandler.obtainMessage(MSG_REMOVE_CONNECTION_SERVICE_ADAPTER, args).sendToTarget();
224 } finally {
225 Log.endSession();
226 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700227 }
228
229 @Override
Ihab Awadf8b69882014-07-25 15:14:01 -0700230 public void createConnection(
231 PhoneAccountHandle connectionManagerPhoneAccount,
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700232 String id,
Ihab Awadf8b69882014-07-25 15:14:01 -0700233 ConnectionRequest request,
Yorke Leec3cf9822014-10-02 09:38:39 -0700234 boolean isIncoming,
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700235 boolean isUnknown,
236 Session.Info sessionInfo) {
237 Log.startSession(sessionInfo, SESSION_CREATE_CONN);
238 try {
239 SomeArgs args = SomeArgs.obtain();
240 args.arg1 = connectionManagerPhoneAccount;
241 args.arg2 = id;
242 args.arg3 = request;
243 args.arg4 = Log.createSubsession();
244 args.argi1 = isIncoming ? 1 : 0;
245 args.argi2 = isUnknown ? 1 : 0;
246 mHandler.obtainMessage(MSG_CREATE_CONNECTION, args).sendToTarget();
247 } finally {
248 Log.endSession();
249 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700250 }
251
252 @Override
Tyler Gunn041a1fe2017-05-12 10:04:49 -0700253 public void createConnectionComplete(String id, Session.Info sessionInfo) {
254 Log.startSession(sessionInfo, SESSION_CREATE_CONN_COMPLETE);
255 try {
256 SomeArgs args = SomeArgs.obtain();
257 args.arg1 = id;
258 args.arg2 = Log.createSubsession();
259 mHandler.obtainMessage(MSG_CREATE_CONNECTION_COMPLETE, args).sendToTarget();
260 } finally {
261 Log.endSession();
262 }
263 }
264
265 @Override
Tyler Gunn44e01912017-01-31 10:49:05 -0800266 public void createConnectionFailed(
Tyler Gunn159f35c2017-03-02 09:28:37 -0800267 PhoneAccountHandle connectionManagerPhoneAccount,
Tyler Gunn44e01912017-01-31 10:49:05 -0800268 String callId,
269 ConnectionRequest request,
270 boolean isIncoming,
271 Session.Info sessionInfo) {
272 Log.startSession(sessionInfo, SESSION_CREATE_CONN_FAILED);
273 try {
274 SomeArgs args = SomeArgs.obtain();
275 args.arg1 = callId;
276 args.arg2 = request;
277 args.arg3 = Log.createSubsession();
Tyler Gunn159f35c2017-03-02 09:28:37 -0800278 args.arg4 = connectionManagerPhoneAccount;
Tyler Gunn44e01912017-01-31 10:49:05 -0800279 args.argi1 = isIncoming ? 1 : 0;
280 mHandler.obtainMessage(MSG_CREATE_CONNECTION_FAILED, args).sendToTarget();
281 } finally {
282 Log.endSession();
283 }
284 }
285
286 @Override
Sanket Padawe4cc8ed532017-12-04 16:22:20 -0800287 public void handoverFailed(String callId, ConnectionRequest request, int reason,
288 Session.Info sessionInfo) {
289 Log.startSession(sessionInfo, SESSION_HANDOVER_FAILED);
290 try {
291 SomeArgs args = SomeArgs.obtain();
292 args.arg1 = callId;
293 args.arg2 = request;
294 args.arg3 = Log.createSubsession();
295 args.arg4 = reason;
296 mHandler.obtainMessage(MSG_HANDOVER_FAILED, args).sendToTarget();
297 } finally {
298 Log.endSession();
299 }
300 }
301
302 @Override
Tyler Gunn79bc1ec2018-01-22 15:17:54 -0800303 public void handoverComplete(String callId, Session.Info sessionInfo) {
304 Log.startSession(sessionInfo, SESSION_HANDOVER_COMPLETE);
305 try {
306 SomeArgs args = SomeArgs.obtain();
307 args.arg1 = callId;
308 args.arg2 = Log.createSubsession();
309 mHandler.obtainMessage(MSG_HANDOVER_COMPLETE, args).sendToTarget();
310 } finally {
311 Log.endSession();
312 }
313 }
314
315 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700316 public void abort(String callId, Session.Info sessionInfo) {
317 Log.startSession(sessionInfo, SESSION_ABORT);
318 try {
319 SomeArgs args = SomeArgs.obtain();
320 args.arg1 = callId;
321 args.arg2 = Log.createSubsession();
322 mHandler.obtainMessage(MSG_ABORT, args).sendToTarget();
323 } finally {
324 Log.endSession();
325 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700326 }
327
328 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700329 public void answerVideo(String callId, int videoState, Session.Info sessionInfo) {
330 Log.startSession(sessionInfo, SESSION_ANSWER_VIDEO);
331 try {
332 SomeArgs args = SomeArgs.obtain();
333 args.arg1 = callId;
334 args.arg2 = Log.createSubsession();
335 args.argi1 = videoState;
336 mHandler.obtainMessage(MSG_ANSWER_VIDEO, args).sendToTarget();
337 } finally {
338 Log.endSession();
339 }
Tyler Gunnbe74de02014-08-29 14:51:48 -0700340 }
341
342 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700343 public void answer(String callId, Session.Info sessionInfo) {
344 Log.startSession(sessionInfo, SESSION_ANSWER);
345 try {
346 SomeArgs args = SomeArgs.obtain();
347 args.arg1 = callId;
348 args.arg2 = Log.createSubsession();
349 mHandler.obtainMessage(MSG_ANSWER, args).sendToTarget();
350 } finally {
351 Log.endSession();
352 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700353 }
354
355 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700356 public void reject(String callId, Session.Info sessionInfo) {
357 Log.startSession(sessionInfo, SESSION_REJECT);
358 try {
359 SomeArgs args = SomeArgs.obtain();
360 args.arg1 = callId;
361 args.arg2 = Log.createSubsession();
362 mHandler.obtainMessage(MSG_REJECT, args).sendToTarget();
363 } finally {
364 Log.endSession();
365 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700366 }
367
368 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700369 public void rejectWithMessage(String callId, String message, Session.Info sessionInfo) {
370 Log.startSession(sessionInfo, SESSION_REJECT_MESSAGE);
371 try {
372 SomeArgs args = SomeArgs.obtain();
373 args.arg1 = callId;
374 args.arg2 = message;
375 args.arg3 = Log.createSubsession();
376 mHandler.obtainMessage(MSG_REJECT_WITH_MESSAGE, args).sendToTarget();
377 } finally {
378 Log.endSession();
379 }
Bryce Lee81901682015-08-28 16:38:02 -0700380 }
381
382 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700383 public void silence(String callId, Session.Info sessionInfo) {
384 Log.startSession(sessionInfo, SESSION_SILENCE);
385 try {
386 SomeArgs args = SomeArgs.obtain();
387 args.arg1 = callId;
388 args.arg2 = Log.createSubsession();
389 mHandler.obtainMessage(MSG_SILENCE, args).sendToTarget();
390 } finally {
391 Log.endSession();
392 }
Bryce Leecac50772015-11-17 15:13:29 -0800393 }
394
395 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700396 public void disconnect(String callId, Session.Info sessionInfo) {
397 Log.startSession(sessionInfo, SESSION_DISCONNECT);
398 try {
399 SomeArgs args = SomeArgs.obtain();
400 args.arg1 = callId;
401 args.arg2 = Log.createSubsession();
402 mHandler.obtainMessage(MSG_DISCONNECT, args).sendToTarget();
403 } finally {
404 Log.endSession();
405 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700406 }
407
408 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700409 public void hold(String callId, Session.Info sessionInfo) {
410 Log.startSession(sessionInfo, SESSION_HOLD);
411 try {
412 SomeArgs args = SomeArgs.obtain();
413 args.arg1 = callId;
414 args.arg2 = Log.createSubsession();
415 mHandler.obtainMessage(MSG_HOLD, args).sendToTarget();
416 } finally {
417 Log.endSession();
418 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700419 }
420
421 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700422 public void unhold(String callId, Session.Info sessionInfo) {
423 Log.startSession(sessionInfo, SESSION_UNHOLD);
424 try {
425 SomeArgs args = SomeArgs.obtain();
426 args.arg1 = callId;
427 args.arg2 = Log.createSubsession();
428 mHandler.obtainMessage(MSG_UNHOLD, 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 onCallAudioStateChanged(String callId, CallAudioState callAudioState,
436 Session.Info sessionInfo) {
437 Log.startSession(sessionInfo, SESSION_CALL_AUDIO_SC);
438 try {
439 SomeArgs args = SomeArgs.obtain();
440 args.arg1 = callId;
441 args.arg2 = callAudioState;
442 args.arg3 = Log.createSubsession();
443 mHandler.obtainMessage(MSG_ON_CALL_AUDIO_STATE_CHANGED, args).sendToTarget();
444 } finally {
445 Log.endSession();
446 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700447 }
448
449 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700450 public void playDtmfTone(String callId, char digit, Session.Info sessionInfo) {
451 Log.startSession(sessionInfo, SESSION_PLAY_DTMF);
452 try {
453 SomeArgs args = SomeArgs.obtain();
454 args.arg1 = digit;
455 args.arg2 = callId;
456 args.arg3 = Log.createSubsession();
457 mHandler.obtainMessage(MSG_PLAY_DTMF_TONE, args).sendToTarget();
458 } finally {
459 Log.endSession();
460 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700461 }
462
463 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700464 public void stopDtmfTone(String callId, Session.Info sessionInfo) {
465 Log.startSession(sessionInfo, SESSION_STOP_DTMF);
466 try {
467 SomeArgs args = SomeArgs.obtain();
468 args.arg1 = callId;
469 args.arg2 = Log.createSubsession();
470 mHandler.obtainMessage(MSG_STOP_DTMF_TONE, args).sendToTarget();
471 } finally {
472 Log.endSession();
473 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700474 }
475
476 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700477 public void conference(String callId1, String callId2, Session.Info sessionInfo) {
478 Log.startSession(sessionInfo, SESSION_CONFERENCE);
479 try {
480 SomeArgs args = SomeArgs.obtain();
481 args.arg1 = callId1;
482 args.arg2 = callId2;
483 args.arg3 = Log.createSubsession();
484 mHandler.obtainMessage(MSG_CONFERENCE, args).sendToTarget();
485 } finally {
486 Log.endSession();
487 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700488 }
489
490 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700491 public void splitFromConference(String callId, Session.Info sessionInfo) {
492 Log.startSession(sessionInfo, SESSION_SPLIT_CONFERENCE);
493 try {
494 SomeArgs args = SomeArgs.obtain();
495 args.arg1 = callId;
496 args.arg2 = Log.createSubsession();
497 mHandler.obtainMessage(MSG_SPLIT_FROM_CONFERENCE, args).sendToTarget();
498 } finally {
499 Log.endSession();
500 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700501 }
502
503 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700504 public void mergeConference(String callId, Session.Info sessionInfo) {
505 Log.startSession(sessionInfo, SESSION_MERGE_CONFERENCE);
506 try {
507 SomeArgs args = SomeArgs.obtain();
508 args.arg1 = callId;
509 args.arg2 = Log.createSubsession();
510 mHandler.obtainMessage(MSG_MERGE_CONFERENCE, args).sendToTarget();
511 } finally {
512 Log.endSession();
513 }
Santos Cordona4868042014-09-04 17:39:22 -0700514 }
515
516 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700517 public void swapConference(String callId, Session.Info sessionInfo) {
518 Log.startSession(sessionInfo, SESSION_SWAP_CONFERENCE);
519 try {
520 SomeArgs args = SomeArgs.obtain();
521 args.arg1 = callId;
522 args.arg2 = Log.createSubsession();
523 mHandler.obtainMessage(MSG_SWAP_CONFERENCE, args).sendToTarget();
524 } finally {
525 Log.endSession();
526 }
Santos Cordona4868042014-09-04 17:39:22 -0700527 }
528
529 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700530 public void onPostDialContinue(String callId, boolean proceed, Session.Info sessionInfo) {
531 Log.startSession(sessionInfo, SESSION_POST_DIAL_CONT);
532 try {
533 SomeArgs args = SomeArgs.obtain();
534 args.arg1 = callId;
535 args.arg2 = Log.createSubsession();
536 args.argi1 = proceed ? 1 : 0;
537 mHandler.obtainMessage(MSG_ON_POST_DIAL_CONTINUE, args).sendToTarget();
538 } finally {
539 Log.endSession();
540 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700541 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700542
543 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700544 public void pullExternalCall(String callId, Session.Info sessionInfo) {
545 Log.startSession(sessionInfo, SESSION_PULL_EXTERNAL_CALL);
546 try {
547 SomeArgs args = SomeArgs.obtain();
548 args.arg1 = callId;
549 args.arg2 = Log.createSubsession();
550 mHandler.obtainMessage(MSG_PULL_EXTERNAL_CALL, args).sendToTarget();
551 } finally {
552 Log.endSession();
553 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700554 }
555
556 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700557 public void sendCallEvent(String callId, String event, Bundle extras,
558 Session.Info sessionInfo) {
559 Log.startSession(sessionInfo, SESSION_SEND_CALL_EVENT);
560 try {
561 SomeArgs args = SomeArgs.obtain();
562 args.arg1 = callId;
563 args.arg2 = event;
564 args.arg3 = extras;
565 args.arg4 = Log.createSubsession();
566 mHandler.obtainMessage(MSG_SEND_CALL_EVENT, args).sendToTarget();
567 } finally {
568 Log.endSession();
569 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700570 }
Tyler Gunndee56a82016-03-23 16:06:34 -0700571
572 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700573 public void onExtrasChanged(String callId, Bundle extras, Session.Info sessionInfo) {
574 Log.startSession(sessionInfo, SESSION_EXTRAS_CHANGED);
575 try {
576 SomeArgs args = SomeArgs.obtain();
577 args.arg1 = callId;
578 args.arg2 = extras;
579 args.arg3 = Log.createSubsession();
580 mHandler.obtainMessage(MSG_ON_EXTRAS_CHANGED, args).sendToTarget();
581 } finally {
582 Log.endSession();
583 }
Tyler Gunndee56a82016-03-23 16:06:34 -0700584 }
Hall Liub64ac4c2017-02-06 10:49:48 -0800585
586 @Override
587 public void startRtt(String callId, ParcelFileDescriptor fromInCall,
588 ParcelFileDescriptor toInCall, Session.Info sessionInfo) throws RemoteException {
589 Log.startSession(sessionInfo, SESSION_START_RTT);
590 try {
591 SomeArgs args = SomeArgs.obtain();
592 args.arg1 = callId;
593 args.arg2 = new Connection.RttTextStream(toInCall, fromInCall);
594 args.arg3 = Log.createSubsession();
595 mHandler.obtainMessage(MSG_ON_START_RTT, args).sendToTarget();
596 } finally {
597 Log.endSession();
598 }
599 }
600
601 @Override
602 public void stopRtt(String callId, Session.Info sessionInfo) throws RemoteException {
603 Log.startSession(sessionInfo, SESSION_STOP_RTT);
604 try {
605 SomeArgs args = SomeArgs.obtain();
606 args.arg1 = callId;
607 args.arg2 = Log.createSubsession();
608 mHandler.obtainMessage(MSG_ON_STOP_RTT, args).sendToTarget();
609 } finally {
610 Log.endSession();
611 }
612 }
613
614 @Override
615 public void respondToRttUpgradeRequest(String callId, ParcelFileDescriptor fromInCall,
616 ParcelFileDescriptor toInCall, Session.Info sessionInfo) throws RemoteException {
617 Log.startSession(sessionInfo, SESSION_RTT_UPGRADE_RESPONSE);
618 try {
619 SomeArgs args = SomeArgs.obtain();
620 args.arg1 = callId;
621 if (toInCall == null || fromInCall == null) {
622 args.arg2 = null;
623 } else {
624 args.arg2 = new Connection.RttTextStream(toInCall, fromInCall);
625 }
626 args.arg3 = Log.createSubsession();
627 mHandler.obtainMessage(MSG_RTT_UPGRADE_RESPONSE, args).sendToTarget();
628 } finally {
629 Log.endSession();
630 }
631 }
Pengquan Meng731c1a32017-11-21 18:01:13 -0800632
633 @Override
634 public void connectionServiceFocusLost(Session.Info sessionInfo) throws RemoteException {
635 Log.startSession(sessionInfo, SESSION_CONNECTION_SERVICE_FOCUS_LOST);
636 try {
637 mHandler.obtainMessage(MSG_CONNECTION_SERVICE_FOCUS_LOST).sendToTarget();
638 } finally {
639 Log.endSession();
640 }
641 }
642
643 @Override
644 public void connectionServiceFocusGained(Session.Info sessionInfo) throws RemoteException {
645 Log.startSession(sessionInfo, SESSION_CONNECTION_SERVICE_FOCUS_GAINED);
646 try {
647 mHandler.obtainMessage(MSG_CONNECTION_SERVICE_FOCUS_GAINED).sendToTarget();
648 } finally {
649 Log.endSession();
650 }
651 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700652 };
653
654 private final Handler mHandler = new Handler(Looper.getMainLooper()) {
655 @Override
656 public void handleMessage(Message msg) {
657 switch (msg.what) {
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700658 case MSG_ADD_CONNECTION_SERVICE_ADAPTER: {
659 SomeArgs args = (SomeArgs) msg.obj;
660 try {
661 IConnectionServiceAdapter adapter = (IConnectionServiceAdapter) args.arg1;
662 Log.continueSession((Session) args.arg2,
663 SESSION_HANDLER + SESSION_ADD_CS_ADAPTER);
664 mAdapter.addAdapter(adapter);
665 onAdapterAttached();
666 } finally {
667 args.recycle();
668 Log.endSession();
669 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700670 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700671 }
672 case MSG_REMOVE_CONNECTION_SERVICE_ADAPTER: {
673 SomeArgs args = (SomeArgs) msg.obj;
674 try {
675 Log.continueSession((Session) args.arg2,
676 SESSION_HANDLER + SESSION_REMOVE_CS_ADAPTER);
677 mAdapter.removeAdapter((IConnectionServiceAdapter) args.arg1);
678 } finally {
679 args.recycle();
680 Log.endSession();
681 }
Ihab Awad8aecfed2014-08-08 17:06:11 -0700682 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700683 }
Ihab Awadf8b69882014-07-25 15:14:01 -0700684 case MSG_CREATE_CONNECTION: {
685 SomeArgs args = (SomeArgs) msg.obj;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700686 Log.continueSession((Session) args.arg4, SESSION_HANDLER + SESSION_CREATE_CONN);
Ihab Awadf8b69882014-07-25 15:14:01 -0700687 try {
Ihab Awad5d0410f2014-07-30 10:07:40 -0700688 final PhoneAccountHandle connectionManagerPhoneAccount =
Ihab Awadf8b69882014-07-25 15:14:01 -0700689 (PhoneAccountHandle) args.arg1;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700690 final String id = (String) args.arg2;
691 final ConnectionRequest request = (ConnectionRequest) args.arg3;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700692 final boolean isIncoming = args.argi1 == 1;
Yorke Leec3cf9822014-10-02 09:38:39 -0700693 final boolean isUnknown = args.argi2 == 1;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700694 if (!mAreAccountsInitialized) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700695 Log.d(this, "Enqueueing pre-init request %s", id);
Brad Ebinger0c3541b2016-11-01 14:11:38 -0700696 mPreInitializationConnectionRequests.add(
697 new android.telecom.Logging.Runnable(
698 SESSION_HANDLER + SESSION_CREATE_CONN + ".pICR",
699 null /*lock*/) {
Ihab Awad5d0410f2014-07-30 10:07:40 -0700700 @Override
Brad Ebinger0c3541b2016-11-01 14:11:38 -0700701 public void loggedRun() {
Ihab Awad5d0410f2014-07-30 10:07:40 -0700702 createConnection(
703 connectionManagerPhoneAccount,
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700704 id,
Ihab Awad5d0410f2014-07-30 10:07:40 -0700705 request,
Yorke Leec3cf9822014-10-02 09:38:39 -0700706 isIncoming,
707 isUnknown);
Ihab Awad5d0410f2014-07-30 10:07:40 -0700708 }
Brad Ebinger0c3541b2016-11-01 14:11:38 -0700709 }.prepare());
Ihab Awad5d0410f2014-07-30 10:07:40 -0700710 } else {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700711 createConnection(
712 connectionManagerPhoneAccount,
713 id,
714 request,
Yorke Leec3cf9822014-10-02 09:38:39 -0700715 isIncoming,
716 isUnknown);
Ihab Awad5d0410f2014-07-30 10:07:40 -0700717 }
Ihab Awadf8b69882014-07-25 15:14:01 -0700718 } finally {
719 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700720 Log.endSession();
Ihab Awadf8b69882014-07-25 15:14:01 -0700721 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700722 break;
Ihab Awadf8b69882014-07-25 15:14:01 -0700723 }
Tyler Gunn041a1fe2017-05-12 10:04:49 -0700724 case MSG_CREATE_CONNECTION_COMPLETE: {
725 SomeArgs args = (SomeArgs) msg.obj;
726 Log.continueSession((Session) args.arg2,
727 SESSION_HANDLER + SESSION_CREATE_CONN_COMPLETE);
728 try {
729 final String id = (String) args.arg1;
730 if (!mAreAccountsInitialized) {
731 Log.d(this, "Enqueueing pre-init request %s", id);
732 mPreInitializationConnectionRequests.add(
733 new android.telecom.Logging.Runnable(
734 SESSION_HANDLER + SESSION_CREATE_CONN_COMPLETE
735 + ".pICR",
736 null /*lock*/) {
737 @Override
738 public void loggedRun() {
739 notifyCreateConnectionComplete(id);
740 }
741 }.prepare());
742 } else {
743 notifyCreateConnectionComplete(id);
744 }
745 } finally {
746 args.recycle();
747 Log.endSession();
748 }
749 break;
750 }
Tyler Gunn44e01912017-01-31 10:49:05 -0800751 case MSG_CREATE_CONNECTION_FAILED: {
752 SomeArgs args = (SomeArgs) msg.obj;
753 Log.continueSession((Session) args.arg3, SESSION_HANDLER +
754 SESSION_CREATE_CONN_FAILED);
755 try {
756 final String id = (String) args.arg1;
757 final ConnectionRequest request = (ConnectionRequest) args.arg2;
758 final boolean isIncoming = args.argi1 == 1;
Tyler Gunn159f35c2017-03-02 09:28:37 -0800759 final PhoneAccountHandle connectionMgrPhoneAccount =
760 (PhoneAccountHandle) args.arg4;
Tyler Gunn44e01912017-01-31 10:49:05 -0800761 if (!mAreAccountsInitialized) {
762 Log.d(this, "Enqueueing pre-init request %s", id);
763 mPreInitializationConnectionRequests.add(
764 new android.telecom.Logging.Runnable(
765 SESSION_HANDLER + SESSION_CREATE_CONN_FAILED + ".pICR",
766 null /*lock*/) {
767 @Override
768 public void loggedRun() {
Tyler Gunn159f35c2017-03-02 09:28:37 -0800769 createConnectionFailed(connectionMgrPhoneAccount, id,
770 request, isIncoming);
Tyler Gunn44e01912017-01-31 10:49:05 -0800771 }
772 }.prepare());
773 } else {
774 Log.i(this, "createConnectionFailed %s", id);
Tyler Gunn159f35c2017-03-02 09:28:37 -0800775 createConnectionFailed(connectionMgrPhoneAccount, id, request,
776 isIncoming);
Tyler Gunn44e01912017-01-31 10:49:05 -0800777 }
778 } finally {
779 args.recycle();
780 Log.endSession();
781 }
782 break;
783 }
Sanket Padawe4cc8ed532017-12-04 16:22:20 -0800784 case MSG_HANDOVER_FAILED: {
785 SomeArgs args = (SomeArgs) msg.obj;
786 Log.continueSession((Session) args.arg3, SESSION_HANDLER +
787 SESSION_HANDOVER_FAILED);
788 try {
789 final String id = (String) args.arg1;
790 final ConnectionRequest request = (ConnectionRequest) args.arg2;
791 final int reason = (int) args.arg4;
792 if (!mAreAccountsInitialized) {
793 Log.d(this, "Enqueueing pre-init request %s", id);
794 mPreInitializationConnectionRequests.add(
795 new android.telecom.Logging.Runnable(
796 SESSION_HANDLER
797 + SESSION_HANDOVER_FAILED + ".pICR",
798 null /*lock*/) {
799 @Override
800 public void loggedRun() {
801 handoverFailed(id, request, reason);
802 }
803 }.prepare());
804 } else {
805 Log.i(this, "createConnectionFailed %s", id);
806 handoverFailed(id, request, reason);
807 }
808 } finally {
809 args.recycle();
810 Log.endSession();
811 }
812 break;
813 }
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700814 case MSG_ABORT: {
815 SomeArgs args = (SomeArgs) msg.obj;
816 Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_ABORT);
817 try {
818 abort((String) args.arg1);
819 } finally {
820 args.recycle();
821 Log.endSession();
822 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700823 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700824 }
825 case MSG_ANSWER: {
826 SomeArgs args = (SomeArgs) msg.obj;
827 Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_ANSWER);
828 try {
829 answer((String) args.arg1);
830 } finally {
831 args.recycle();
832 Log.endSession();
833 }
Tyler Gunnbe74de02014-08-29 14:51:48 -0700834 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700835 }
Tyler Gunnbe74de02014-08-29 14:51:48 -0700836 case MSG_ANSWER_VIDEO: {
Andrew Lee8da4c3c2014-07-16 10:11:42 -0700837 SomeArgs args = (SomeArgs) msg.obj;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700838 Log.continueSession((Session) args.arg2,
839 SESSION_HANDLER + SESSION_ANSWER_VIDEO);
Andrew Lee8da4c3c2014-07-16 10:11:42 -0700840 try {
841 String callId = (String) args.arg1;
Evan Charltonbf11f982014-07-20 22:06:28 -0700842 int videoState = args.argi1;
Tyler Gunnbe74de02014-08-29 14:51:48 -0700843 answerVideo(callId, videoState);
Andrew Lee8da4c3c2014-07-16 10:11:42 -0700844 } finally {
845 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700846 Log.endSession();
Andrew Lee8da4c3c2014-07-16 10:11:42 -0700847 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700848 break;
Andrew Lee8da4c3c2014-07-16 10:11:42 -0700849 }
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700850 case MSG_REJECT: {
851 SomeArgs args = (SomeArgs) msg.obj;
852 Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_REJECT);
853 try {
854 reject((String) args.arg1);
855 } finally {
856 args.recycle();
857 Log.endSession();
858 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700859 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700860 }
Bryce Lee81901682015-08-28 16:38:02 -0700861 case MSG_REJECT_WITH_MESSAGE: {
862 SomeArgs args = (SomeArgs) msg.obj;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700863 Log.continueSession((Session) args.arg3,
864 SESSION_HANDLER + SESSION_REJECT_MESSAGE);
Bryce Lee81901682015-08-28 16:38:02 -0700865 try {
866 reject((String) args.arg1, (String) args.arg2);
867 } finally {
868 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700869 Log.endSession();
Bryce Lee81901682015-08-28 16:38:02 -0700870 }
871 break;
872 }
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700873 case MSG_DISCONNECT: {
874 SomeArgs args = (SomeArgs) msg.obj;
875 Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_DISCONNECT);
876 try {
877 disconnect((String) args.arg1);
878 } finally {
879 args.recycle();
880 Log.endSession();
881 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700882 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700883 }
884 case MSG_SILENCE: {
885 SomeArgs args = (SomeArgs) msg.obj;
886 Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_SILENCE);
887 try {
888 silence((String) args.arg1);
889 } finally {
890 args.recycle();
891 Log.endSession();
892 }
Bryce Leecac50772015-11-17 15:13:29 -0800893 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700894 }
895 case MSG_HOLD: {
896 SomeArgs args = (SomeArgs) msg.obj;
897 Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_REJECT);
898 try {
899 hold((String) args.arg1);
900 } finally {
901 args.recycle();
902 Log.endSession();
903 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700904 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700905 }
906 case MSG_UNHOLD: {
907 SomeArgs args = (SomeArgs) msg.obj;
908 Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_UNHOLD);
909 try {
910 unhold((String) args.arg1);
911 } finally {
912 args.recycle();
913 Log.endSession();
914 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700915 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700916 }
Yorke Lee4af59352015-05-13 14:14:54 -0700917 case MSG_ON_CALL_AUDIO_STATE_CHANGED: {
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700918 SomeArgs args = (SomeArgs) msg.obj;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700919 Log.continueSession((Session) args.arg3,
920 SESSION_HANDLER + SESSION_CALL_AUDIO_SC);
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700921 try {
922 String callId = (String) args.arg1;
Yorke Lee4af59352015-05-13 14:14:54 -0700923 CallAudioState audioState = (CallAudioState) args.arg2;
924 onCallAudioStateChanged(callId, new CallAudioState(audioState));
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700925 } finally {
926 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700927 Log.endSession();
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700928 }
929 break;
930 }
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700931 case MSG_PLAY_DTMF_TONE: {
932 SomeArgs args = (SomeArgs) msg.obj;
933 try {
934 Log.continueSession((Session) args.arg3,
935 SESSION_HANDLER + SESSION_PLAY_DTMF);
936 playDtmfTone((String) args.arg2, (char) args.arg1);
937 } finally {
938 args.recycle();
939 Log.endSession();
940 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700941 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700942 }
943 case MSG_STOP_DTMF_TONE: {
944 SomeArgs args = (SomeArgs) msg.obj;
945 try {
946 Log.continueSession((Session) args.arg2,
947 SESSION_HANDLER + SESSION_STOP_DTMF);
948 stopDtmfTone((String) args.arg1);
949 } finally {
950 args.recycle();
951 Log.endSession();
952 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700953 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700954 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700955 case MSG_CONFERENCE: {
956 SomeArgs args = (SomeArgs) msg.obj;
957 try {
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700958 Log.continueSession((Session) args.arg3,
959 SESSION_HANDLER + SESSION_CONFERENCE);
Santos Cordon823fd3c2014-08-07 18:35:18 -0700960 String callId1 = (String) args.arg1;
961 String callId2 = (String) args.arg2;
962 conference(callId1, callId2);
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700963 } finally {
964 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700965 Log.endSession();
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700966 }
967 break;
968 }
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700969 case MSG_SPLIT_FROM_CONFERENCE: {
970 SomeArgs args = (SomeArgs) msg.obj;
971 try {
972 Log.continueSession((Session) args.arg2,
973 SESSION_HANDLER + SESSION_SPLIT_CONFERENCE);
974 splitFromConference((String) args.arg1);
975 } finally {
976 args.recycle();
977 Log.endSession();
978 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700979 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700980 }
981 case MSG_MERGE_CONFERENCE: {
982 SomeArgs args = (SomeArgs) msg.obj;
983 try {
984 Log.continueSession((Session) args.arg2,
985 SESSION_HANDLER + SESSION_MERGE_CONFERENCE);
986 mergeConference((String) args.arg1);
987 } finally {
988 args.recycle();
989 Log.endSession();
990 }
Santos Cordona4868042014-09-04 17:39:22 -0700991 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700992 }
993 case MSG_SWAP_CONFERENCE: {
994 SomeArgs args = (SomeArgs) msg.obj;
995 try {
996 Log.continueSession((Session) args.arg2,
997 SESSION_HANDLER + SESSION_SWAP_CONFERENCE);
998 swapConference((String) args.arg1);
999 } finally {
1000 args.recycle();
1001 Log.endSession();
1002 }
Santos Cordona4868042014-09-04 17:39:22 -07001003 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001004 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001005 case MSG_ON_POST_DIAL_CONTINUE: {
1006 SomeArgs args = (SomeArgs) msg.obj;
1007 try {
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001008 Log.continueSession((Session) args.arg2,
1009 SESSION_HANDLER + SESSION_POST_DIAL_CONT);
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001010 String callId = (String) args.arg1;
1011 boolean proceed = (args.argi1 == 1);
1012 onPostDialContinue(callId, proceed);
1013 } finally {
1014 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001015 Log.endSession();
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001016 }
1017 break;
1018 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001019 case MSG_PULL_EXTERNAL_CALL: {
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001020 SomeArgs args = (SomeArgs) msg.obj;
1021 try {
1022 Log.continueSession((Session) args.arg2,
1023 SESSION_HANDLER + SESSION_PULL_EXTERNAL_CALL);
1024 pullExternalCall((String) args.arg1);
1025 } finally {
1026 args.recycle();
1027 Log.endSession();
1028 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001029 break;
1030 }
1031 case MSG_SEND_CALL_EVENT: {
1032 SomeArgs args = (SomeArgs) msg.obj;
1033 try {
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001034 Log.continueSession((Session) args.arg4,
1035 SESSION_HANDLER + SESSION_SEND_CALL_EVENT);
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001036 String callId = (String) args.arg1;
1037 String event = (String) args.arg2;
1038 Bundle extras = (Bundle) args.arg3;
1039 sendCallEvent(callId, event, extras);
1040 } finally {
1041 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001042 Log.endSession();
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001043 }
1044 break;
1045 }
Tyler Gunn79bc1ec2018-01-22 15:17:54 -08001046 case MSG_HANDOVER_COMPLETE: {
1047 SomeArgs args = (SomeArgs) msg.obj;
1048 try {
1049 Log.continueSession((Session) args.arg2,
1050 SESSION_HANDLER + SESSION_HANDOVER_COMPLETE);
1051 String callId = (String) args.arg1;
1052 notifyHandoverComplete(callId);
1053 } finally {
1054 args.recycle();
1055 Log.endSession();
1056 }
1057 break;
1058 }
Tyler Gunndee56a82016-03-23 16:06:34 -07001059 case MSG_ON_EXTRAS_CHANGED: {
1060 SomeArgs args = (SomeArgs) msg.obj;
1061 try {
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001062 Log.continueSession((Session) args.arg3,
1063 SESSION_HANDLER + SESSION_EXTRAS_CHANGED);
Tyler Gunndee56a82016-03-23 16:06:34 -07001064 String callId = (String) args.arg1;
1065 Bundle extras = (Bundle) args.arg2;
1066 handleExtrasChanged(callId, extras);
1067 } finally {
1068 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001069 Log.endSession();
Tyler Gunndee56a82016-03-23 16:06:34 -07001070 }
1071 break;
1072 }
Hall Liub64ac4c2017-02-06 10:49:48 -08001073 case MSG_ON_START_RTT: {
1074 SomeArgs args = (SomeArgs) msg.obj;
1075 try {
1076 Log.continueSession((Session) args.arg3,
1077 SESSION_HANDLER + SESSION_START_RTT);
1078 String callId = (String) args.arg1;
1079 Connection.RttTextStream rttTextStream =
1080 (Connection.RttTextStream) args.arg2;
1081 startRtt(callId, rttTextStream);
1082 } finally {
1083 args.recycle();
1084 Log.endSession();
1085 }
1086 break;
1087 }
1088 case MSG_ON_STOP_RTT: {
1089 SomeArgs args = (SomeArgs) msg.obj;
1090 try {
1091 Log.continueSession((Session) args.arg2,
1092 SESSION_HANDLER + SESSION_STOP_RTT);
1093 String callId = (String) args.arg1;
1094 stopRtt(callId);
1095 } finally {
1096 args.recycle();
1097 Log.endSession();
1098 }
1099 break;
1100 }
1101 case MSG_RTT_UPGRADE_RESPONSE: {
1102 SomeArgs args = (SomeArgs) msg.obj;
1103 try {
1104 Log.continueSession((Session) args.arg3,
1105 SESSION_HANDLER + SESSION_RTT_UPGRADE_RESPONSE);
1106 String callId = (String) args.arg1;
1107 Connection.RttTextStream rttTextStream =
1108 (Connection.RttTextStream) args.arg2;
1109 handleRttUpgradeResponse(callId, rttTextStream);
1110 } finally {
1111 args.recycle();
1112 Log.endSession();
1113 }
1114 break;
1115 }
Pengquan Meng731c1a32017-11-21 18:01:13 -08001116 case MSG_CONNECTION_SERVICE_FOCUS_GAINED:
1117 onConnectionServiceFocusGained();
1118 break;
1119 case MSG_CONNECTION_SERVICE_FOCUS_LOST:
1120 onConnectionServiceFocusLost();
1121 break;
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001122 default:
1123 break;
1124 }
1125 }
1126 };
1127
Santos Cordon823fd3c2014-08-07 18:35:18 -07001128 private final Conference.Listener mConferenceListener = new Conference.Listener() {
1129 @Override
1130 public void onStateChanged(Conference conference, int oldState, int newState) {
1131 String id = mIdByConference.get(conference);
1132 switch (newState) {
1133 case Connection.STATE_ACTIVE:
1134 mAdapter.setActive(id);
1135 break;
1136 case Connection.STATE_HOLDING:
1137 mAdapter.setOnHold(id);
1138 break;
1139 case Connection.STATE_DISCONNECTED:
1140 // handled by onDisconnected
1141 break;
1142 }
1143 }
1144
1145 @Override
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001146 public void onDisconnected(Conference conference, DisconnectCause disconnectCause) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07001147 String id = mIdByConference.get(conference);
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001148 mAdapter.setDisconnected(id, disconnectCause);
Santos Cordon823fd3c2014-08-07 18:35:18 -07001149 }
1150
1151 @Override
1152 public void onConnectionAdded(Conference conference, Connection connection) {
1153 }
1154
1155 @Override
1156 public void onConnectionRemoved(Conference conference, Connection connection) {
1157 }
1158
1159 @Override
Ihab Awad50e35062014-09-30 09:17:03 -07001160 public void onConferenceableConnectionsChanged(
1161 Conference conference, List<Connection> conferenceableConnections) {
1162 mAdapter.setConferenceableConnections(
1163 mIdByConference.get(conference),
1164 createConnectionIdList(conferenceableConnections));
1165 }
1166
1167 @Override
Santos Cordon823fd3c2014-08-07 18:35:18 -07001168 public void onDestroyed(Conference conference) {
1169 removeConference(conference);
1170 }
1171
1172 @Override
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001173 public void onConnectionCapabilitiesChanged(
1174 Conference conference,
1175 int connectionCapabilities) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07001176 String id = mIdByConference.get(conference);
1177 Log.d(this, "call capabilities: conference: %s",
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001178 Connection.capabilitiesToString(connectionCapabilities));
1179 mAdapter.setConnectionCapabilities(id, connectionCapabilities);
Santos Cordon823fd3c2014-08-07 18:35:18 -07001180 }
Rekha Kumar07366812015-03-24 16:42:31 -07001181
1182 @Override
Tyler Gunn720c6642016-03-22 09:02:47 -07001183 public void onConnectionPropertiesChanged(
1184 Conference conference,
1185 int connectionProperties) {
1186 String id = mIdByConference.get(conference);
1187 Log.d(this, "call capabilities: conference: %s",
1188 Connection.propertiesToString(connectionProperties));
1189 mAdapter.setConnectionProperties(id, connectionProperties);
1190 }
1191
1192 @Override
Rekha Kumar07366812015-03-24 16:42:31 -07001193 public void onVideoStateChanged(Conference c, int videoState) {
1194 String id = mIdByConference.get(c);
1195 Log.d(this, "onVideoStateChanged set video state %d", videoState);
1196 mAdapter.setVideoState(id, videoState);
1197 }
1198
1199 @Override
1200 public void onVideoProviderChanged(Conference c, Connection.VideoProvider videoProvider) {
1201 String id = mIdByConference.get(c);
1202 Log.d(this, "onVideoProviderChanged: Connection: %s, VideoProvider: %s", c,
1203 videoProvider);
1204 mAdapter.setVideoProvider(id, videoProvider);
1205 }
Andrew Lee0f51da32015-04-16 13:11:55 -07001206
1207 @Override
Andrew Leeedc625f2015-04-14 13:38:12 -07001208 public void onStatusHintsChanged(Conference conference, StatusHints statusHints) {
1209 String id = mIdByConference.get(conference);
Tyler Gunndee56a82016-03-23 16:06:34 -07001210 if (id != null) {
1211 mAdapter.setStatusHints(id, statusHints);
1212 }
Andrew Leeedc625f2015-04-14 13:38:12 -07001213 }
Santos Cordon6b7f9552015-05-27 17:21:45 -07001214
1215 @Override
Tyler Gunndee56a82016-03-23 16:06:34 -07001216 public void onExtrasChanged(Conference c, Bundle extras) {
1217 String id = mIdByConference.get(c);
1218 if (id != null) {
1219 mAdapter.putExtras(id, extras);
1220 }
1221 }
1222
1223 @Override
1224 public void onExtrasRemoved(Conference c, List<String> keys) {
1225 String id = mIdByConference.get(c);
1226 if (id != null) {
1227 mAdapter.removeExtras(id, keys);
1228 }
Santos Cordon6b7f9552015-05-27 17:21:45 -07001229 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07001230 };
1231
Ihab Awad542e0ea2014-05-16 10:22:16 -07001232 private final Connection.Listener mConnectionListener = new Connection.Listener() {
1233 @Override
1234 public void onStateChanged(Connection c, int state) {
1235 String id = mIdByConnection.get(c);
Ihab Awad42b30e12014-05-22 09:49:34 -07001236 Log.d(this, "Adapter set state %s %s", id, Connection.stateToString(state));
Ihab Awad542e0ea2014-05-16 10:22:16 -07001237 switch (state) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001238 case Connection.STATE_ACTIVE:
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001239 mAdapter.setActive(id);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001240 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001241 case Connection.STATE_DIALING:
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001242 mAdapter.setDialing(id);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001243 break;
Tyler Gunnc96b5e02016-07-07 22:53:57 -07001244 case Connection.STATE_PULLING_CALL:
1245 mAdapter.setPulling(id);
1246 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001247 case Connection.STATE_DISCONNECTED:
Ihab Awad542e0ea2014-05-16 10:22:16 -07001248 // Handled in onDisconnected()
1249 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001250 case Connection.STATE_HOLDING:
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001251 mAdapter.setOnHold(id);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001252 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001253 case Connection.STATE_NEW:
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001254 // Nothing to tell Telecom
Ihab Awad542e0ea2014-05-16 10:22:16 -07001255 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001256 case Connection.STATE_RINGING:
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001257 mAdapter.setRinging(id);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001258 break;
1259 }
1260 }
1261
1262 @Override
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001263 public void onDisconnected(Connection c, DisconnectCause disconnectCause) {
Ihab Awad542e0ea2014-05-16 10:22:16 -07001264 String id = mIdByConnection.get(c);
Andrew Lee26786392014-09-16 18:14:59 -07001265 Log.d(this, "Adapter set disconnected %s", disconnectCause);
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001266 mAdapter.setDisconnected(id, disconnectCause);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001267 }
1268
1269 @Override
Tyler Gunnaa07df82014-07-17 07:50:22 -07001270 public void onVideoStateChanged(Connection c, int videoState) {
1271 String id = mIdByConnection.get(c);
1272 Log.d(this, "Adapter set video state %d", videoState);
1273 mAdapter.setVideoState(id, videoState);
1274 }
1275
1276 @Override
Andrew Lee100e2932014-09-08 15:34:24 -07001277 public void onAddressChanged(Connection c, Uri address, int presentation) {
Sailesh Nepal61203862014-07-11 14:50:13 -07001278 String id = mIdByConnection.get(c);
Andrew Lee100e2932014-09-08 15:34:24 -07001279 mAdapter.setAddress(id, address, presentation);
Sailesh Nepal61203862014-07-11 14:50:13 -07001280 }
1281
1282 @Override
1283 public void onCallerDisplayNameChanged(
1284 Connection c, String callerDisplayName, int presentation) {
1285 String id = mIdByConnection.get(c);
1286 mAdapter.setCallerDisplayName(id, callerDisplayName, presentation);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001287 }
1288
1289 @Override
Ihab Awad542e0ea2014-05-16 10:22:16 -07001290 public void onDestroyed(Connection c) {
1291 removeConnection(c);
1292 }
Ihab Awadf8358972014-05-28 16:46:42 -07001293
1294 @Override
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001295 public void onPostDialWait(Connection c, String remaining) {
Sailesh Nepal091768c2014-06-30 15:15:23 -07001296 String id = mIdByConnection.get(c);
1297 Log.d(this, "Adapter onPostDialWait %s, %s", c, remaining);
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001298 mAdapter.onPostDialWait(id, remaining);
Sailesh Nepal091768c2014-06-30 15:15:23 -07001299 }
1300
1301 @Override
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001302 public void onPostDialChar(Connection c, char nextChar) {
1303 String id = mIdByConnection.get(c);
1304 Log.d(this, "Adapter onPostDialChar %s, %s", c, nextChar);
1305 mAdapter.onPostDialChar(id, nextChar);
1306 }
1307
1308 @Override
Andrew Lee100e2932014-09-08 15:34:24 -07001309 public void onRingbackRequested(Connection c, boolean ringback) {
Ihab Awadf8358972014-05-28 16:46:42 -07001310 String id = mIdByConnection.get(c);
1311 Log.d(this, "Adapter onRingback %b", ringback);
Andrew Lee100e2932014-09-08 15:34:24 -07001312 mAdapter.setRingbackRequested(id, ringback);
Ihab Awadf8358972014-05-28 16:46:42 -07001313 }
Santos Cordonb6939982014-06-04 20:20:58 -07001314
1315 @Override
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001316 public void onConnectionCapabilitiesChanged(Connection c, int capabilities) {
Santos Cordonb6939982014-06-04 20:20:58 -07001317 String id = mIdByConnection.get(c);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001318 Log.d(this, "capabilities: parcelableconnection: %s",
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001319 Connection.capabilitiesToString(capabilities));
1320 mAdapter.setConnectionCapabilities(id, capabilities);
Santos Cordonb6939982014-06-04 20:20:58 -07001321 }
1322
Santos Cordonb6939982014-06-04 20:20:58 -07001323 @Override
Tyler Gunn720c6642016-03-22 09:02:47 -07001324 public void onConnectionPropertiesChanged(Connection c, int properties) {
1325 String id = mIdByConnection.get(c);
1326 Log.d(this, "properties: parcelableconnection: %s",
1327 Connection.propertiesToString(properties));
1328 mAdapter.setConnectionProperties(id, properties);
1329 }
1330
1331 @Override
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001332 public void onVideoProviderChanged(Connection c, Connection.VideoProvider videoProvider) {
Andrew Lee5ffbe8b2014-06-20 16:29:33 -07001333 String id = mIdByConnection.get(c);
Rekha Kumar07366812015-03-24 16:42:31 -07001334 Log.d(this, "onVideoProviderChanged: Connection: %s, VideoProvider: %s", c,
1335 videoProvider);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001336 mAdapter.setVideoProvider(id, videoProvider);
Andrew Lee5ffbe8b2014-06-20 16:29:33 -07001337 }
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001338
1339 @Override
Sailesh Nepal001bbbb2014-07-15 14:40:39 -07001340 public void onAudioModeIsVoipChanged(Connection c, boolean isVoip) {
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001341 String id = mIdByConnection.get(c);
Andrew Lee100e2932014-09-08 15:34:24 -07001342 mAdapter.setIsVoipAudioMode(id, isVoip);
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001343 }
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001344
1345 @Override
Sailesh Nepal001bbbb2014-07-15 14:40:39 -07001346 public void onStatusHintsChanged(Connection c, StatusHints statusHints) {
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001347 String id = mIdByConnection.get(c);
1348 mAdapter.setStatusHints(id, statusHints);
1349 }
Sailesh Nepal2ab88cc2014-07-18 14:49:18 -07001350
1351 @Override
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001352 public void onConferenceablesChanged(
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001353 Connection connection, List<Conferenceable> conferenceables) {
Ihab Awadb8e85c72014-08-23 20:34:57 -07001354 mAdapter.setConferenceableConnections(
1355 mIdByConnection.get(connection),
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001356 createIdList(conferenceables));
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001357 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07001358
1359 @Override
1360 public void onConferenceChanged(Connection connection, Conference conference) {
1361 String id = mIdByConnection.get(connection);
1362 if (id != null) {
1363 String conferenceId = null;
1364 if (conference != null) {
1365 conferenceId = mIdByConference.get(conference);
1366 }
1367 mAdapter.setIsConferenced(id, conferenceId);
1368 }
1369 }
Anthony Lee17455a32015-04-24 15:25:29 -07001370
1371 @Override
1372 public void onConferenceMergeFailed(Connection connection) {
1373 String id = mIdByConnection.get(connection);
1374 if (id != null) {
1375 mAdapter.onConferenceMergeFailed(id);
1376 }
1377 }
Santos Cordon6b7f9552015-05-27 17:21:45 -07001378
1379 @Override
Tyler Gunndee56a82016-03-23 16:06:34 -07001380 public void onExtrasChanged(Connection c, Bundle extras) {
1381 String id = mIdByConnection.get(c);
Santos Cordon6b7f9552015-05-27 17:21:45 -07001382 if (id != null) {
Tyler Gunndee56a82016-03-23 16:06:34 -07001383 mAdapter.putExtras(id, extras);
Santos Cordon6b7f9552015-05-27 17:21:45 -07001384 }
1385 }
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001386
Tyler Gunnf5035432017-01-09 09:43:12 -08001387 @Override
Tyler Gunndee56a82016-03-23 16:06:34 -07001388 public void onExtrasRemoved(Connection c, List<String> keys) {
1389 String id = mIdByConnection.get(c);
1390 if (id != null) {
1391 mAdapter.removeExtras(id, keys);
1392 }
1393 }
1394
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08001395 @Override
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001396 public void onConnectionEvent(Connection connection, String event, Bundle extras) {
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08001397 String id = mIdByConnection.get(connection);
1398 if (id != null) {
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001399 mAdapter.onConnectionEvent(id, event, extras);
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08001400 }
1401 }
Tyler Gunnf5035432017-01-09 09:43:12 -08001402
1403 @Override
Hall Liua98f58b2017-11-07 17:59:28 -08001404 public void onAudioRouteChanged(Connection c, int audioRoute, String bluetoothAddress) {
Tyler Gunnf5035432017-01-09 09:43:12 -08001405 String id = mIdByConnection.get(c);
1406 if (id != null) {
Hall Liua98f58b2017-11-07 17:59:28 -08001407 mAdapter.setAudioRoute(id, audioRoute, bluetoothAddress);
Tyler Gunnf5035432017-01-09 09:43:12 -08001408 }
1409 }
Hall Liub64ac4c2017-02-06 10:49:48 -08001410
1411 @Override
1412 public void onRttInitiationSuccess(Connection c) {
1413 String id = mIdByConnection.get(c);
1414 if (id != null) {
1415 mAdapter.onRttInitiationSuccess(id);
1416 }
1417 }
1418
1419 @Override
1420 public void onRttInitiationFailure(Connection c, int reason) {
1421 String id = mIdByConnection.get(c);
1422 if (id != null) {
1423 mAdapter.onRttInitiationFailure(id, reason);
1424 }
1425 }
1426
1427 @Override
1428 public void onRttSessionRemotelyTerminated(Connection c) {
1429 String id = mIdByConnection.get(c);
1430 if (id != null) {
1431 mAdapter.onRttSessionRemotelyTerminated(id);
1432 }
1433 }
1434
1435 @Override
1436 public void onRemoteRttRequest(Connection c) {
1437 String id = mIdByConnection.get(c);
1438 if (id != null) {
1439 mAdapter.onRemoteRttRequest(id);
1440 }
1441 }
Srikanth Chintalafcb15012017-05-04 20:58:34 +05301442
1443 @Override
1444 public void onPhoneAccountChanged(Connection c, PhoneAccountHandle pHandle) {
1445 String id = mIdByConnection.get(c);
1446 if (id != null) {
1447 mAdapter.onPhoneAccountChanged(id, pHandle);
1448 }
1449 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001450 };
1451
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001452 /** {@inheritDoc} */
Ihab Awad542e0ea2014-05-16 10:22:16 -07001453 @Override
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001454 public final IBinder onBind(Intent intent) {
1455 return mBinder;
1456 }
1457
Santos Cordon29f2f2e2014-09-11 19:50:24 -07001458 /** {@inheritDoc} */
1459 @Override
1460 public boolean onUnbind(Intent intent) {
1461 endAllConnections();
1462 return super.onUnbind(intent);
1463 }
1464
Sailesh Nepalc5b01572014-07-14 16:29:44 -07001465 /**
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001466 * This can be used by telecom to either create a new outgoing call or attach to an existing
1467 * incoming call. In either case, telecom will cycle through a set of services and call
Sailesh Nepalc5b01572014-07-14 16:29:44 -07001468 * createConnection util a connection service cancels the process or completes it successfully.
1469 */
Ihab Awadf8b69882014-07-25 15:14:01 -07001470 private void createConnection(
1471 final PhoneAccountHandle callManagerAccount,
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001472 final String callId,
Ihab Awadf8b69882014-07-25 15:14:01 -07001473 final ConnectionRequest request,
Yorke Leec3cf9822014-10-02 09:38:39 -07001474 boolean isIncoming,
1475 boolean isUnknown) {
Tyler Gunn79bc1ec2018-01-22 15:17:54 -08001476 boolean isLegacyHandover = request.getExtras() != null &&
1477 request.getExtras().getBoolean(TelecomManager.EXTRA_IS_HANDOVER, false);
1478 boolean isHandover = request.getExtras() != null && request.getExtras().getBoolean(
1479 TelecomManager.EXTRA_IS_HANDOVER_CONNECTION, false);
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001480 Log.d(this, "createConnection, callManagerAccount: %s, callId: %s, request: %s, " +
Tyler Gunn79bc1ec2018-01-22 15:17:54 -08001481 "isIncoming: %b, isUnknown: %b, isLegacyHandover: %b, isHandover: %b",
1482 callManagerAccount, callId, request, isIncoming, isUnknown, isLegacyHandover,
1483 isHandover);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001484
Sanket Padawee29a2662017-12-01 13:59:27 -08001485 Connection connection = null;
Tyler Gunn79bc1ec2018-01-22 15:17:54 -08001486 if (isHandover) {
1487 PhoneAccountHandle fromPhoneAccountHandle = request.getExtras() != null
1488 ? (PhoneAccountHandle) request.getExtras().getParcelable(
1489 TelecomManager.EXTRA_HANDOVER_FROM_PHONE_ACCOUNT) : null;
Sanket Padawee29a2662017-12-01 13:59:27 -08001490 if (!isIncoming) {
Tyler Gunn79bc1ec2018-01-22 15:17:54 -08001491 connection = onCreateOutgoingHandoverConnection(fromPhoneAccountHandle, request);
Sanket Padawee29a2662017-12-01 13:59:27 -08001492 } else {
Tyler Gunn79bc1ec2018-01-22 15:17:54 -08001493 connection = onCreateIncomingHandoverConnection(fromPhoneAccountHandle, request);
Sanket Padawee29a2662017-12-01 13:59:27 -08001494 }
1495 } else {
1496 connection = isUnknown ? onCreateUnknownConnection(callManagerAccount, request)
1497 : isIncoming ? onCreateIncomingConnection(callManagerAccount, request)
1498 : onCreateOutgoingConnection(callManagerAccount, request);
1499 }
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001500 Log.d(this, "createConnection, connection: %s", connection);
1501 if (connection == null) {
Tyler Gunnfba1a8e2017-12-19 15:23:59 -08001502 Log.i(this, "createConnection, implementation returned null connection.");
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001503 connection = Connection.createFailedConnection(
Tyler Gunnfba1a8e2017-12-19 15:23:59 -08001504 new DisconnectCause(DisconnectCause.ERROR, "IMPL_RETURNED_NULL_CONNECTION"));
Sailesh Nepalc5b01572014-07-14 16:29:44 -07001505 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001506
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001507 connection.setTelecomCallId(callId);
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001508 if (connection.getState() != Connection.STATE_DISCONNECTED) {
Pengquan Meng70c9885332017-10-02 18:09:03 -07001509 addConnection(request.getAccountHandle(), callId, connection);
Ihab Awad6107bab2014-08-18 09:23:25 -07001510 }
1511
Andrew Lee100e2932014-09-08 15:34:24 -07001512 Uri address = connection.getAddress();
1513 String number = address == null ? "null" : address.getSchemeSpecificPart();
Tyler Gunn720c6642016-03-22 09:02:47 -07001514 Log.v(this, "createConnection, number: %s, state: %s, capabilities: %s, properties: %s",
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001515 Connection.toLogSafePhoneNumber(number),
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001516 Connection.stateToString(connection.getState()),
Tyler Gunn720c6642016-03-22 09:02:47 -07001517 Connection.capabilitiesToString(connection.getConnectionCapabilities()),
1518 Connection.propertiesToString(connection.getConnectionProperties()));
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001519
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001520 Log.d(this, "createConnection, calling handleCreateConnectionSuccessful %s", callId);
Ihab Awad6107bab2014-08-18 09:23:25 -07001521 mAdapter.handleCreateConnectionComplete(
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001522 callId,
Evan Charltonbf11f982014-07-20 22:06:28 -07001523 request,
1524 new ParcelableConnection(
1525 request.getAccountHandle(),
1526 connection.getState(),
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001527 connection.getConnectionCapabilities(),
Tyler Gunn720c6642016-03-22 09:02:47 -07001528 connection.getConnectionProperties(),
Christine Hallstrom2830ce92016-11-30 16:06:42 -08001529 connection.getSupportedAudioRoutes(),
Andrew Lee100e2932014-09-08 15:34:24 -07001530 connection.getAddress(),
1531 connection.getAddressPresentation(),
Evan Charltonbf11f982014-07-20 22:06:28 -07001532 connection.getCallerDisplayName(),
1533 connection.getCallerDisplayNamePresentation(),
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001534 connection.getVideoProvider() == null ?
1535 null : connection.getVideoProvider().getInterface(),
Sailesh Nepal8b9d3ca2014-08-14 17:39:34 -07001536 connection.getVideoState(),
Andrew Lee100e2932014-09-08 15:34:24 -07001537 connection.isRingbackRequested(),
Sailesh Nepal8b9d3ca2014-08-14 17:39:34 -07001538 connection.getAudioModeIsVoip(),
Roshan Piuse927ec02015-07-15 15:47:21 -07001539 connection.getConnectTimeMillis(),
Tyler Gunn3fa819c2017-08-04 09:27:26 -07001540 connection.getConnectElapsedTimeMillis(),
Ihab Awad6107bab2014-08-18 09:23:25 -07001541 connection.getStatusHints(),
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001542 connection.getDisconnectCause(),
Santos Cordon6b7f9552015-05-27 17:21:45 -07001543 createIdList(connection.getConferenceables()),
1544 connection.getExtras()));
Tyler Gunnf5035432017-01-09 09:43:12 -08001545
1546 if (isIncoming && request.shouldShowIncomingCallUi() &&
1547 (connection.getConnectionProperties() & Connection.PROPERTY_SELF_MANAGED) ==
1548 Connection.PROPERTY_SELF_MANAGED) {
1549 // Tell ConnectionService to show its incoming call UX.
1550 connection.onShowIncomingCallUi();
1551 }
Shriram Ganesh6bf35ac2014-12-11 17:53:38 -08001552 if (isUnknown) {
1553 triggerConferenceRecalculate();
1554 }
Evan Charltonbf11f982014-07-20 22:06:28 -07001555 }
1556
Tyler Gunn159f35c2017-03-02 09:28:37 -08001557 private void createConnectionFailed(final PhoneAccountHandle callManagerAccount,
1558 final String callId, final ConnectionRequest request,
1559 boolean isIncoming) {
Tyler Gunn44e01912017-01-31 10:49:05 -08001560
1561 Log.i(this, "createConnectionFailed %s", callId);
1562 if (isIncoming) {
Tyler Gunn159f35c2017-03-02 09:28:37 -08001563 onCreateIncomingConnectionFailed(callManagerAccount, request);
Tyler Gunn44e01912017-01-31 10:49:05 -08001564 } else {
Tyler Gunn159f35c2017-03-02 09:28:37 -08001565 onCreateOutgoingConnectionFailed(callManagerAccount, request);
Tyler Gunn44e01912017-01-31 10:49:05 -08001566 }
1567 }
1568
Sanket Padawe4cc8ed532017-12-04 16:22:20 -08001569 private void handoverFailed(final String callId, final ConnectionRequest request,
1570 int reason) {
1571
1572 Log.i(this, "handoverFailed %s", callId);
1573 onHandoverFailed(request, reason);
1574 }
1575
Tyler Gunn041a1fe2017-05-12 10:04:49 -07001576 /**
1577 * Called by Telecom when the creation of a new Connection has completed and it is now added
1578 * to Telecom.
1579 * @param callId The ID of the connection.
1580 */
1581 private void notifyCreateConnectionComplete(final String callId) {
1582 Log.i(this, "notifyCreateConnectionComplete %s", callId);
Tyler Gunn0a88f2e2017-06-16 20:20:34 -07001583 if (callId == null) {
1584 // This could happen if the connection fails quickly and is removed from the
1585 // ConnectionService before Telecom sends the create connection complete callback.
1586 Log.w(this, "notifyCreateConnectionComplete: callId is null.");
1587 return;
1588 }
Tyler Gunn041a1fe2017-05-12 10:04:49 -07001589 onCreateConnectionComplete(findConnectionForAction(callId,
1590 "notifyCreateConnectionComplete"));
1591 }
1592
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001593 private void abort(String callId) {
Ihab Awad60ac30b2014-05-20 22:32:12 -07001594 Log.d(this, "abort %s", callId);
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001595 findConnectionForAction(callId, "abort").onAbort();
Ihab Awad542e0ea2014-05-16 10:22:16 -07001596 }
1597
Tyler Gunnbe74de02014-08-29 14:51:48 -07001598 private void answerVideo(String callId, int videoState) {
1599 Log.d(this, "answerVideo %s", callId);
Andrew Lee8da4c3c2014-07-16 10:11:42 -07001600 findConnectionForAction(callId, "answer").onAnswer(videoState);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001601 }
1602
Tyler Gunnbe74de02014-08-29 14:51:48 -07001603 private void answer(String callId) {
1604 Log.d(this, "answer %s", callId);
1605 findConnectionForAction(callId, "answer").onAnswer();
1606 }
1607
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001608 private void reject(String callId) {
Ihab Awad60ac30b2014-05-20 22:32:12 -07001609 Log.d(this, "reject %s", callId);
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001610 findConnectionForAction(callId, "reject").onReject();
Ihab Awad542e0ea2014-05-16 10:22:16 -07001611 }
1612
Bryce Lee81901682015-08-28 16:38:02 -07001613 private void reject(String callId, String rejectWithMessage) {
1614 Log.d(this, "reject %s with message", callId);
1615 findConnectionForAction(callId, "reject").onReject(rejectWithMessage);
1616 }
1617
Bryce Leecac50772015-11-17 15:13:29 -08001618 private void silence(String callId) {
1619 Log.d(this, "silence %s", callId);
1620 findConnectionForAction(callId, "silence").onSilence();
1621 }
1622
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001623 private void disconnect(String callId) {
Ihab Awad60ac30b2014-05-20 22:32:12 -07001624 Log.d(this, "disconnect %s", callId);
Santos Cordon0159ac02014-08-21 14:28:11 -07001625 if (mConnectionById.containsKey(callId)) {
1626 findConnectionForAction(callId, "disconnect").onDisconnect();
1627 } else {
1628 findConferenceForAction(callId, "disconnect").onDisconnect();
1629 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001630 }
1631
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001632 private void hold(String callId) {
Ihab Awad60ac30b2014-05-20 22:32:12 -07001633 Log.d(this, "hold %s", callId);
Santos Cordon0159ac02014-08-21 14:28:11 -07001634 if (mConnectionById.containsKey(callId)) {
1635 findConnectionForAction(callId, "hold").onHold();
1636 } else {
1637 findConferenceForAction(callId, "hold").onHold();
1638 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001639 }
1640
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001641 private void unhold(String callId) {
Ihab Awad60ac30b2014-05-20 22:32:12 -07001642 Log.d(this, "unhold %s", callId);
Santos Cordon0159ac02014-08-21 14:28:11 -07001643 if (mConnectionById.containsKey(callId)) {
1644 findConnectionForAction(callId, "unhold").onUnhold();
1645 } else {
1646 findConferenceForAction(callId, "unhold").onUnhold();
1647 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001648 }
1649
Yorke Lee4af59352015-05-13 14:14:54 -07001650 private void onCallAudioStateChanged(String callId, CallAudioState callAudioState) {
1651 Log.d(this, "onAudioStateChanged %s %s", callId, callAudioState);
Yorke Leea0d3ca92014-09-15 19:18:13 -07001652 if (mConnectionById.containsKey(callId)) {
Yorke Lee4af59352015-05-13 14:14:54 -07001653 findConnectionForAction(callId, "onCallAudioStateChanged").setCallAudioState(
1654 callAudioState);
Yorke Leea0d3ca92014-09-15 19:18:13 -07001655 } else {
Yorke Lee4af59352015-05-13 14:14:54 -07001656 findConferenceForAction(callId, "onCallAudioStateChanged").setCallAudioState(
1657 callAudioState);
Yorke Leea0d3ca92014-09-15 19:18:13 -07001658 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001659 }
1660
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001661 private void playDtmfTone(String callId, char digit) {
1662 Log.d(this, "playDtmfTone %s %c", callId, digit);
Yorke Leea0d3ca92014-09-15 19:18:13 -07001663 if (mConnectionById.containsKey(callId)) {
1664 findConnectionForAction(callId, "playDtmfTone").onPlayDtmfTone(digit);
1665 } else {
1666 findConferenceForAction(callId, "playDtmfTone").onPlayDtmfTone(digit);
1667 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001668 }
1669
1670 private void stopDtmfTone(String callId) {
1671 Log.d(this, "stopDtmfTone %s", callId);
Yorke Leea0d3ca92014-09-15 19:18:13 -07001672 if (mConnectionById.containsKey(callId)) {
1673 findConnectionForAction(callId, "stopDtmfTone").onStopDtmfTone();
1674 } else {
1675 findConferenceForAction(callId, "stopDtmfTone").onStopDtmfTone();
1676 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001677 }
1678
Santos Cordon823fd3c2014-08-07 18:35:18 -07001679 private void conference(String callId1, String callId2) {
1680 Log.d(this, "conference %s, %s", callId1, callId2);
Santos Cordon980acb92014-05-31 10:31:19 -07001681
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001682 // Attempt to get second connection or conference.
Santos Cordon823fd3c2014-08-07 18:35:18 -07001683 Connection connection2 = findConnectionForAction(callId2, "conference");
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001684 Conference conference2 = getNullConference();
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001685 if (connection2 == getNullConnection()) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001686 conference2 = findConferenceForAction(callId2, "conference");
1687 if (conference2 == getNullConference()) {
1688 Log.w(this, "Connection2 or Conference2 missing in conference request %s.",
1689 callId2);
1690 return;
1691 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07001692 }
Santos Cordonb6939982014-06-04 20:20:58 -07001693
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001694 // Attempt to get first connection or conference and perform merge.
Ihab Awad50e35062014-09-30 09:17:03 -07001695 Connection connection1 = findConnectionForAction(callId1, "conference");
1696 if (connection1 == getNullConnection()) {
1697 Conference conference1 = findConferenceForAction(callId1, "addConnection");
1698 if (conference1 == getNullConference()) {
1699 Log.w(this,
1700 "Connection1 or Conference1 missing in conference request %s.",
1701 callId1);
1702 } else {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001703 // Call 1 is a conference.
1704 if (connection2 != getNullConnection()) {
1705 // Call 2 is a connection so merge via call 1 (conference).
1706 conference1.onMerge(connection2);
1707 } else {
1708 // Call 2 is ALSO a conference; this should never happen.
1709 Log.wtf(this, "There can only be one conference and an attempt was made to " +
1710 "merge two conferences.");
1711 return;
1712 }
Ihab Awad50e35062014-09-30 09:17:03 -07001713 }
1714 } else {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001715 // Call 1 is a connection.
1716 if (conference2 != getNullConference()) {
1717 // Call 2 is a conference, so merge via call 2.
1718 conference2.onMerge(connection1);
1719 } else {
1720 // Call 2 is a connection, so merge together.
1721 onConference(connection1, connection2);
1722 }
Ihab Awad50e35062014-09-30 09:17:03 -07001723 }
Santos Cordon980acb92014-05-31 10:31:19 -07001724 }
1725
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001726 private void splitFromConference(String callId) {
Santos Cordonb6939982014-06-04 20:20:58 -07001727 Log.d(this, "splitFromConference(%s)", callId);
Santos Cordon980acb92014-05-31 10:31:19 -07001728
1729 Connection connection = findConnectionForAction(callId, "splitFromConference");
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001730 if (connection == getNullConnection()) {
Santos Cordon980acb92014-05-31 10:31:19 -07001731 Log.w(this, "Connection missing in conference request %s.", callId);
1732 return;
1733 }
1734
Santos Cordon0159ac02014-08-21 14:28:11 -07001735 Conference conference = connection.getConference();
1736 if (conference != null) {
1737 conference.onSeparate(connection);
1738 }
Santos Cordon980acb92014-05-31 10:31:19 -07001739 }
1740
Santos Cordona4868042014-09-04 17:39:22 -07001741 private void mergeConference(String callId) {
1742 Log.d(this, "mergeConference(%s)", callId);
1743 Conference conference = findConferenceForAction(callId, "mergeConference");
1744 if (conference != null) {
1745 conference.onMerge();
1746 }
1747 }
1748
1749 private void swapConference(String callId) {
1750 Log.d(this, "swapConference(%s)", callId);
1751 Conference conference = findConferenceForAction(callId, "swapConference");
1752 if (conference != null) {
1753 conference.onSwap();
1754 }
1755 }
1756
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001757 /**
1758 * Notifies a {@link Connection} of a request to pull an external call.
1759 *
1760 * See {@link Call#pullExternalCall()}.
1761 *
1762 * @param callId The ID of the call to pull.
1763 */
1764 private void pullExternalCall(String callId) {
1765 Log.d(this, "pullExternalCall(%s)", callId);
1766 Connection connection = findConnectionForAction(callId, "pullExternalCall");
1767 if (connection != null) {
1768 connection.onPullExternalCall();
1769 }
1770 }
1771
1772 /**
1773 * Notifies a {@link Connection} of a call event.
1774 *
1775 * See {@link Call#sendCallEvent(String, Bundle)}.
1776 *
1777 * @param callId The ID of the call receiving the event.
1778 * @param event The event.
1779 * @param extras Extras associated with the event.
1780 */
1781 private void sendCallEvent(String callId, String event, Bundle extras) {
1782 Log.d(this, "sendCallEvent(%s, %s)", callId, event);
1783 Connection connection = findConnectionForAction(callId, "sendCallEvent");
1784 if (connection != null) {
1785 connection.onCallEvent(event, extras);
1786 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001787 }
1788
Tyler Gunndee56a82016-03-23 16:06:34 -07001789 /**
Tyler Gunn79bc1ec2018-01-22 15:17:54 -08001790 * Notifies a {@link Connection} that a handover has completed.
1791 *
1792 * @param callId The ID of the call which completed handover.
1793 */
1794 private void notifyHandoverComplete(String callId) {
1795 Log.d(this, "notifyHandoverComplete(%s)", callId);
1796 Connection connection = findConnectionForAction(callId, "notifyHandoverComplete");
1797 if (connection != null) {
1798 connection.onHandoverComplete();
1799 }
1800 }
1801
1802 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001803 * Notifies a {@link Connection} or {@link Conference} of a change to the extras from Telecom.
1804 * <p>
1805 * These extra changes can originate from Telecom itself, or from an {@link InCallService} via
1806 * the {@link android.telecom.Call#putExtra(String, boolean)},
1807 * {@link android.telecom.Call#putExtra(String, int)},
1808 * {@link android.telecom.Call#putExtra(String, String)},
1809 * {@link Call#removeExtras(List)}.
1810 *
1811 * @param callId The ID of the call receiving the event.
1812 * @param extras The new extras bundle.
1813 */
1814 private void handleExtrasChanged(String callId, Bundle extras) {
1815 Log.d(this, "handleExtrasChanged(%s, %s)", callId, extras);
1816 if (mConnectionById.containsKey(callId)) {
1817 findConnectionForAction(callId, "handleExtrasChanged").handleExtrasChanged(extras);
1818 } else if (mConferenceById.containsKey(callId)) {
1819 findConferenceForAction(callId, "handleExtrasChanged").handleExtrasChanged(extras);
1820 }
1821 }
1822
Hall Liub64ac4c2017-02-06 10:49:48 -08001823 private void startRtt(String callId, Connection.RttTextStream rttTextStream) {
1824 Log.d(this, "startRtt(%s)", callId);
1825 if (mConnectionById.containsKey(callId)) {
1826 findConnectionForAction(callId, "startRtt").onStartRtt(rttTextStream);
1827 } else if (mConferenceById.containsKey(callId)) {
1828 Log.w(this, "startRtt called on a conference.");
1829 }
1830 }
1831
1832 private void stopRtt(String callId) {
1833 Log.d(this, "stopRtt(%s)", callId);
1834 if (mConnectionById.containsKey(callId)) {
1835 findConnectionForAction(callId, "stopRtt").onStopRtt();
Hall Liuffa4a812017-03-02 16:11:00 -08001836 findConnectionForAction(callId, "stopRtt").unsetRttProperty();
Hall Liub64ac4c2017-02-06 10:49:48 -08001837 } else if (mConferenceById.containsKey(callId)) {
1838 Log.w(this, "stopRtt called on a conference.");
1839 }
1840 }
1841
1842 private void handleRttUpgradeResponse(String callId, Connection.RttTextStream rttTextStream) {
1843 Log.d(this, "handleRttUpgradeResponse(%s, %s)", callId, rttTextStream == null);
1844 if (mConnectionById.containsKey(callId)) {
1845 findConnectionForAction(callId, "handleRttUpgradeResponse")
1846 .handleRttUpgradeResponse(rttTextStream);
1847 } else if (mConferenceById.containsKey(callId)) {
1848 Log.w(this, "handleRttUpgradeResponse called on a conference.");
1849 }
1850 }
1851
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001852 private void onPostDialContinue(String callId, boolean proceed) {
Evan Charlton6dea4ac2014-06-03 14:07:13 -07001853 Log.d(this, "onPostDialContinue(%s)", callId);
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001854 findConnectionForAction(callId, "stopDtmfTone").onPostDialContinue(proceed);
Evan Charlton6dea4ac2014-06-03 14:07:13 -07001855 }
1856
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001857 private void onAdapterAttached() {
Ihab Awad9c3f1882014-06-30 21:17:13 -07001858 if (mAreAccountsInitialized) {
Santos Cordon52d8a152014-06-17 19:08:45 -07001859 // No need to query again if we already did it.
1860 return;
1861 }
1862
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001863 mAdapter.queryRemoteConnectionServices(new RemoteServiceCallback.Stub() {
Santos Cordon52d8a152014-06-17 19:08:45 -07001864 @Override
1865 public void onResult(
1866 final List<ComponentName> componentNames,
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001867 final List<IBinder> services) {
Brad Ebinger0c3541b2016-11-01 14:11:38 -07001868 mHandler.post(new android.telecom.Logging.Runnable("oAA.qRCS.oR", null /*lock*/) {
Ihab Awad6107bab2014-08-18 09:23:25 -07001869 @Override
Brad Ebinger0c3541b2016-11-01 14:11:38 -07001870 public void loggedRun() {
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001871 for (int i = 0; i < componentNames.size() && i < services.size(); i++) {
Santos Cordon52d8a152014-06-17 19:08:45 -07001872 mRemoteConnectionManager.addConnectionService(
1873 componentNames.get(i),
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001874 IConnectionService.Stub.asInterface(services.get(i)));
Santos Cordon52d8a152014-06-17 19:08:45 -07001875 }
Ihab Awad5d0410f2014-07-30 10:07:40 -07001876 onAccountsInitialized();
Sailesh Nepalc5b01572014-07-14 16:29:44 -07001877 Log.d(this, "remote connection services found: " + services);
Santos Cordon52d8a152014-06-17 19:08:45 -07001878 }
Brad Ebinger0c3541b2016-11-01 14:11:38 -07001879 }.prepare());
Santos Cordon52d8a152014-06-17 19:08:45 -07001880 }
1881
1882 @Override
1883 public void onError() {
Brad Ebinger0c3541b2016-11-01 14:11:38 -07001884 mHandler.post(new android.telecom.Logging.Runnable("oAA.qRCS.oE", null /*lock*/) {
Ihab Awad6107bab2014-08-18 09:23:25 -07001885 @Override
Brad Ebinger0c3541b2016-11-01 14:11:38 -07001886 public void loggedRun() {
Ihab Awad9c3f1882014-06-30 21:17:13 -07001887 mAreAccountsInitialized = true;
Santos Cordon52d8a152014-06-17 19:08:45 -07001888 }
Brad Ebinger0c3541b2016-11-01 14:11:38 -07001889 }.prepare());
Santos Cordon52d8a152014-06-17 19:08:45 -07001890 }
1891 });
1892 }
1893
Ihab Awadf8b69882014-07-25 15:14:01 -07001894 /**
1895 * Ask some other {@code ConnectionService} to create a {@code RemoteConnection} given an
Santos Cordona663f862014-10-29 13:49:58 -07001896 * incoming request. This is used by {@code ConnectionService}s that are registered with
1897 * {@link PhoneAccount#CAPABILITY_CONNECTION_MANAGER} and want to be able to manage
1898 * SIM-based incoming calls.
Ihab Awadf8b69882014-07-25 15:14:01 -07001899 *
1900 * @param connectionManagerPhoneAccount See description at
1901 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
1902 * @param request Details about the incoming call.
1903 * @return The {@code Connection} object to satisfy this call, or {@code null} to
1904 * not handle the call.
1905 */
1906 public final RemoteConnection createRemoteIncomingConnection(
1907 PhoneAccountHandle connectionManagerPhoneAccount,
1908 ConnectionRequest request) {
1909 return mRemoteConnectionManager.createRemoteConnection(
1910 connectionManagerPhoneAccount, request, true);
Santos Cordon52d8a152014-06-17 19:08:45 -07001911 }
1912
1913 /**
Ihab Awadf8b69882014-07-25 15:14:01 -07001914 * Ask some other {@code ConnectionService} to create a {@code RemoteConnection} given an
Santos Cordona663f862014-10-29 13:49:58 -07001915 * outgoing request. This is used by {@code ConnectionService}s that are registered with
1916 * {@link PhoneAccount#CAPABILITY_CONNECTION_MANAGER} and want to be able to use the
1917 * SIM-based {@code ConnectionService} to place its outgoing calls.
Ihab Awadf8b69882014-07-25 15:14:01 -07001918 *
1919 * @param connectionManagerPhoneAccount See description at
1920 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
Cuihtlauac ALVARADO0b3b2a52016-09-13 14:49:41 +02001921 * @param request Details about the outgoing call.
Ihab Awadf8b69882014-07-25 15:14:01 -07001922 * @return The {@code Connection} object to satisfy this call, or {@code null} to
1923 * not handle the call.
1924 */
1925 public final RemoteConnection createRemoteOutgoingConnection(
1926 PhoneAccountHandle connectionManagerPhoneAccount,
1927 ConnectionRequest request) {
1928 return mRemoteConnectionManager.createRemoteConnection(
1929 connectionManagerPhoneAccount, request, false);
1930 }
1931
1932 /**
Santos Cordona663f862014-10-29 13:49:58 -07001933 * Indicates to the relevant {@code RemoteConnectionService} that the specified
1934 * {@link RemoteConnection}s should be merged into a conference call.
1935 * <p>
1936 * If the conference request is successful, the method {@link #onRemoteConferenceAdded} will
1937 * be invoked.
1938 *
1939 * @param remoteConnection1 The first of the remote connections to conference.
1940 * @param remoteConnection2 The second of the remote connections to conference.
Ihab Awadb8e85c72014-08-23 20:34:57 -07001941 */
1942 public final void conferenceRemoteConnections(
Santos Cordona663f862014-10-29 13:49:58 -07001943 RemoteConnection remoteConnection1,
1944 RemoteConnection remoteConnection2) {
1945 mRemoteConnectionManager.conferenceRemoteConnections(remoteConnection1, remoteConnection2);
Ihab Awadb8e85c72014-08-23 20:34:57 -07001946 }
1947
1948 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07001949 * Adds a new conference call. When a conference call is created either as a result of an
1950 * explicit request via {@link #onConference} or otherwise, the connection service should supply
1951 * an instance of {@link Conference} by invoking this method. A conference call provided by this
1952 * method will persist until {@link Conference#destroy} is invoked on the conference instance.
1953 *
1954 * @param conference The new conference object.
1955 */
1956 public final void addConference(Conference conference) {
Rekha Kumar07366812015-03-24 16:42:31 -07001957 Log.d(this, "addConference: conference=%s", conference);
1958
Santos Cordon823fd3c2014-08-07 18:35:18 -07001959 String id = addConferenceInternal(conference);
1960 if (id != null) {
1961 List<String> connectionIds = new ArrayList<>(2);
1962 for (Connection connection : conference.getConnections()) {
1963 if (mIdByConnection.containsKey(connection)) {
1964 connectionIds.add(mIdByConnection.get(connection));
1965 }
1966 }
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001967 conference.setTelecomCallId(id);
Santos Cordon823fd3c2014-08-07 18:35:18 -07001968 ParcelableConference parcelableConference = new ParcelableConference(
Nancy Chenea38cca2014-09-05 16:38:49 -07001969 conference.getPhoneAccountHandle(),
Santos Cordon823fd3c2014-08-07 18:35:18 -07001970 conference.getState(),
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001971 conference.getConnectionCapabilities(),
Tyler Gunn720c6642016-03-22 09:02:47 -07001972 conference.getConnectionProperties(),
Tyler Gunncd5d33c2015-01-12 09:02:01 -08001973 connectionIds,
Rekha Kumar07366812015-03-24 16:42:31 -07001974 conference.getVideoProvider() == null ?
1975 null : conference.getVideoProvider().getInterface(),
1976 conference.getVideoState(),
Andrew Lee3e3e2f22015-04-16 13:48:43 -07001977 conference.getConnectTimeMillis(),
Tyler Gunn3fa819c2017-08-04 09:27:26 -07001978 conference.getConnectElapsedTime(),
Santos Cordon6b7f9552015-05-27 17:21:45 -07001979 conference.getStatusHints(),
1980 conference.getExtras());
Andrew Lee0f51da32015-04-16 13:11:55 -07001981
Santos Cordon823fd3c2014-08-07 18:35:18 -07001982 mAdapter.addConferenceCall(id, parcelableConference);
Rekha Kumar07366812015-03-24 16:42:31 -07001983 mAdapter.setVideoProvider(id, conference.getVideoProvider());
1984 mAdapter.setVideoState(id, conference.getVideoState());
Santos Cordon823fd3c2014-08-07 18:35:18 -07001985
1986 // Go through any child calls and set the parent.
1987 for (Connection connection : conference.getConnections()) {
1988 String connectionId = mIdByConnection.get(connection);
1989 if (connectionId != null) {
1990 mAdapter.setIsConferenced(connectionId, id);
1991 }
1992 }
Pengquan Meng70c9885332017-10-02 18:09:03 -07001993 onConferenceAdded(conference);
Santos Cordon823fd3c2014-08-07 18:35:18 -07001994 }
1995 }
1996
1997 /**
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07001998 * Adds a connection created by the {@link ConnectionService} and informs telecom of the new
1999 * connection.
2000 *
2001 * @param phoneAccountHandle The phone account handle for the connection.
2002 * @param connection The connection to add.
2003 */
2004 public final void addExistingConnection(PhoneAccountHandle phoneAccountHandle,
2005 Connection connection) {
Tyler Gunn78da7812017-05-09 14:34:57 -07002006 addExistingConnection(phoneAccountHandle, connection, null /* conference */);
2007 }
2008
2009 /**
Pengquan Meng731c1a32017-11-21 18:01:13 -08002010 * Call to inform Telecom that your {@link ConnectionService} has released call resources (e.g
2011 * microphone, camera).
2012 *
2013 * @see ConnectionService#onConnectionServiceFocusLost()
2014 */
2015 public final void connectionServiceFocusReleased() {
2016 mAdapter.onConnectionServiceFocusReleased();
2017 }
2018
2019 /**
Tyler Gunn78da7812017-05-09 14:34:57 -07002020 * Adds a connection created by the {@link ConnectionService} and informs telecom of the new
2021 * connection.
2022 *
2023 * @param phoneAccountHandle The phone account handle for the connection.
2024 * @param connection The connection to add.
2025 * @param conference The parent conference of the new connection.
2026 * @hide
2027 */
2028 public final void addExistingConnection(PhoneAccountHandle phoneAccountHandle,
2029 Connection connection, Conference conference) {
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002030
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002031 String id = addExistingConnectionInternal(phoneAccountHandle, connection);
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002032 if (id != null) {
2033 List<String> emptyList = new ArrayList<>(0);
Tyler Gunn78da7812017-05-09 14:34:57 -07002034 String conferenceId = null;
2035 if (conference != null) {
2036 conferenceId = mIdByConference.get(conference);
2037 }
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002038
2039 ParcelableConnection parcelableConnection = new ParcelableConnection(
2040 phoneAccountHandle,
2041 connection.getState(),
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002042 connection.getConnectionCapabilities(),
Tyler Gunn720c6642016-03-22 09:02:47 -07002043 connection.getConnectionProperties(),
Christine Hallstrom2830ce92016-11-30 16:06:42 -08002044 connection.getSupportedAudioRoutes(),
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002045 connection.getAddress(),
2046 connection.getAddressPresentation(),
2047 connection.getCallerDisplayName(),
2048 connection.getCallerDisplayNamePresentation(),
2049 connection.getVideoProvider() == null ?
2050 null : connection.getVideoProvider().getInterface(),
2051 connection.getVideoState(),
2052 connection.isRingbackRequested(),
2053 connection.getAudioModeIsVoip(),
Roshan Piuse927ec02015-07-15 15:47:21 -07002054 connection.getConnectTimeMillis(),
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002055 connection.getConnectElapsedTimeMillis(),
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002056 connection.getStatusHints(),
2057 connection.getDisconnectCause(),
Santos Cordon6b7f9552015-05-27 17:21:45 -07002058 emptyList,
Tyler Gunn78da7812017-05-09 14:34:57 -07002059 connection.getExtras(),
2060 conferenceId);
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002061 mAdapter.addExistingConnection(id, parcelableConnection);
2062 }
2063 }
2064
2065 /**
Ihab Awadf8b69882014-07-25 15:14:01 -07002066 * Returns all the active {@code Connection}s for which this {@code ConnectionService}
2067 * has taken responsibility.
2068 *
2069 * @return A collection of {@code Connection}s created by this {@code ConnectionService}.
Santos Cordonb6939982014-06-04 20:20:58 -07002070 */
Sailesh Nepal091768c2014-06-30 15:15:23 -07002071 public final Collection<Connection> getAllConnections() {
Santos Cordonb6939982014-06-04 20:20:58 -07002072 return mConnectionById.values();
2073 }
2074
2075 /**
Santos Cordona6018b92016-02-16 14:23:12 -08002076 * Returns all the active {@code Conference}s for which this {@code ConnectionService}
2077 * has taken responsibility.
2078 *
2079 * @return A collection of {@code Conference}s created by this {@code ConnectionService}.
2080 */
2081 public final Collection<Conference> getAllConferences() {
2082 return mConferenceById.values();
2083 }
2084
2085 /**
Ihab Awadf8b69882014-07-25 15:14:01 -07002086 * Create a {@code Connection} given an incoming request. This is used to attach to existing
2087 * incoming calls.
Evan Charltonbf11f982014-07-20 22:06:28 -07002088 *
Ihab Awadf8b69882014-07-25 15:14:01 -07002089 * @param connectionManagerPhoneAccount See description at
2090 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
2091 * @param request Details about the incoming call.
2092 * @return The {@code Connection} object to satisfy this call, or {@code null} to
2093 * not handle the call.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002094 */
Ihab Awadf8b69882014-07-25 15:14:01 -07002095 public Connection onCreateIncomingConnection(
2096 PhoneAccountHandle connectionManagerPhoneAccount,
2097 ConnectionRequest request) {
2098 return null;
2099 }
Sailesh Nepalc5b01572014-07-14 16:29:44 -07002100
2101 /**
Tyler Gunn041a1fe2017-05-12 10:04:49 -07002102 * Called after the {@link Connection} returned by
2103 * {@link #onCreateIncomingConnection(PhoneAccountHandle, ConnectionRequest)}
2104 * or {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)} has been
2105 * added to the {@link ConnectionService} and sent to Telecom.
2106 *
2107 * @param connection the {@link Connection}.
2108 * @hide
2109 */
2110 public void onCreateConnectionComplete(Connection connection) {
2111 }
2112
2113 /**
Tyler Gunnf5035432017-01-09 09:43:12 -08002114 * Called by Telecom to inform the {@link ConnectionService} that its request to create a new
2115 * incoming {@link Connection} was denied.
2116 * <p>
2117 * Used when a self-managed {@link ConnectionService} attempts to create a new incoming
2118 * {@link Connection}, but Telecom has determined that the call cannot be allowed at this time.
2119 * The {@link ConnectionService} is responsible for silently rejecting the new incoming
2120 * {@link Connection}.
2121 * <p>
2122 * See {@link TelecomManager#isIncomingCallPermitted(PhoneAccountHandle)} for more information.
2123 *
Tyler Gunn159f35c2017-03-02 09:28:37 -08002124 * @param connectionManagerPhoneAccount See description at
2125 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
Tyler Gunnf5035432017-01-09 09:43:12 -08002126 * @param request The incoming connection request.
2127 */
Tyler Gunn159f35c2017-03-02 09:28:37 -08002128 public void onCreateIncomingConnectionFailed(PhoneAccountHandle connectionManagerPhoneAccount,
2129 ConnectionRequest request) {
Tyler Gunnf5035432017-01-09 09:43:12 -08002130 }
2131
2132 /**
2133 * Called by Telecom to inform the {@link ConnectionService} that its request to create a new
2134 * outgoing {@link Connection} was denied.
2135 * <p>
2136 * Used when a self-managed {@link ConnectionService} attempts to create a new outgoing
2137 * {@link Connection}, but Telecom has determined that the call cannot be placed at this time.
2138 * The {@link ConnectionService} is responisible for informing the user that the
2139 * {@link Connection} cannot be made at this time.
2140 * <p>
2141 * See {@link TelecomManager#isOutgoingCallPermitted(PhoneAccountHandle)} for more information.
2142 *
Tyler Gunn159f35c2017-03-02 09:28:37 -08002143 * @param connectionManagerPhoneAccount See description at
2144 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
Tyler Gunnf5035432017-01-09 09:43:12 -08002145 * @param request The outgoing connection request.
2146 */
Tyler Gunn159f35c2017-03-02 09:28:37 -08002147 public void onCreateOutgoingConnectionFailed(PhoneAccountHandle connectionManagerPhoneAccount,
2148 ConnectionRequest request) {
Tyler Gunnf5035432017-01-09 09:43:12 -08002149 }
2150
2151 /**
Shriram Ganesh6bf35ac2014-12-11 17:53:38 -08002152 * Trigger recalculate functinality for conference calls. This is used when a Telephony
2153 * Connection is part of a conference controller but is not yet added to Connection
2154 * Service and hence cannot be added to the conference call.
2155 *
2156 * @hide
2157 */
2158 public void triggerConferenceRecalculate() {
2159 }
2160
2161 /**
Ihab Awadf8b69882014-07-25 15:14:01 -07002162 * Create a {@code Connection} given an outgoing request. This is used to initiate new
2163 * outgoing calls.
Sailesh Nepalc5b01572014-07-14 16:29:44 -07002164 *
Ihab Awadf8b69882014-07-25 15:14:01 -07002165 * @param connectionManagerPhoneAccount The connection manager account to use for managing
2166 * this call.
2167 * <p>
2168 * If this parameter is not {@code null}, it means that this {@code ConnectionService}
2169 * has registered one or more {@code PhoneAccount}s having
2170 * {@link PhoneAccount#CAPABILITY_CONNECTION_MANAGER}. This parameter will contain
2171 * one of these {@code PhoneAccount}s, while the {@code request} will contain another
2172 * (usually but not always distinct) {@code PhoneAccount} to be used for actually
2173 * making the connection.
2174 * <p>
2175 * If this parameter is {@code null}, it means that this {@code ConnectionService} is
2176 * being asked to make a direct connection. The
2177 * {@link ConnectionRequest#getAccountHandle()} of parameter {@code request} will be
2178 * a {@code PhoneAccount} registered by this {@code ConnectionService} to use for
2179 * making the connection.
2180 * @param request Details about the outgoing call.
2181 * @return The {@code Connection} object to satisfy this call, or the result of an invocation
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002182 * of {@link Connection#createFailedConnection(DisconnectCause)} to not handle the call.
Sailesh Nepalc5b01572014-07-14 16:29:44 -07002183 */
Ihab Awadf8b69882014-07-25 15:14:01 -07002184 public Connection onCreateOutgoingConnection(
2185 PhoneAccountHandle connectionManagerPhoneAccount,
2186 ConnectionRequest request) {
2187 return null;
2188 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002189
2190 /**
Sanket Padawea8eddd42017-11-03 11:07:35 -07002191 * Called by Telecom on the initiating side of the handover to create an instance of a
2192 * handover connection.
2193 * @param fromPhoneAccountHandle {@link PhoneAccountHandle} associated with the
2194 * ConnectionService which needs to handover the call.
2195 * @param request Details about the call which needs to be handover.
2196 * @return Connection object corresponding to the handover call.
2197 */
2198 public Connection onCreateOutgoingHandoverConnection(PhoneAccountHandle fromPhoneAccountHandle,
2199 ConnectionRequest request) {
2200 return null;
2201 }
2202
2203 /**
2204 * Called by Telecom on the receiving side of the handover to request the
2205 * {@link ConnectionService} to create an instance of a handover connection.
2206 * @param fromPhoneAccountHandle {@link PhoneAccountHandle} associated with the
2207 * ConnectionService which needs to handover the call.
2208 * @param request Details about the call which needs to be handover.
2209 * @return {@link Connection} object corresponding to the handover call.
2210 */
2211 public Connection onCreateIncomingHandoverConnection(PhoneAccountHandle fromPhoneAccountHandle,
2212 ConnectionRequest request) {
2213 return null;
2214 }
2215
2216 /**
2217 * Called by Telecom in response to a {@code TelecomManager#acceptHandover()}
2218 * invocation which failed.
2219 * @param request Details about the call which needs to be handover.
2220 * @param error Reason for handover failure as defined in
2221 * {@link android.telecom.Call.Callback#HANDOVER_FAILURE_DEST_INVALID_PERM}
2222 */
2223 public void onHandoverFailed(ConnectionRequest request, int error) {
2224 return;
2225 }
2226
2227 /**
Yorke Leec3cf9822014-10-02 09:38:39 -07002228 * Create a {@code Connection} for a new unknown call. An unknown call is a call originating
2229 * from the ConnectionService that was neither a user-initiated outgoing call, nor an incoming
2230 * call created using
2231 * {@code TelecomManager#addNewIncomingCall(PhoneAccountHandle, android.os.Bundle)}.
2232 *
Yorke Lee770ed6e2014-10-06 18:58:52 -07002233 * @hide
Yorke Leec3cf9822014-10-02 09:38:39 -07002234 */
2235 public Connection onCreateUnknownConnection(PhoneAccountHandle connectionManagerPhoneAccount,
2236 ConnectionRequest request) {
Brad Ebingerb32d4f82016-10-24 16:40:49 -07002237 return null;
Yorke Leec3cf9822014-10-02 09:38:39 -07002238 }
2239
2240 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07002241 * Conference two specified connections. Invoked when the user has made a request to merge the
2242 * specified connections into a conference call. In response, the connection service should
2243 * create an instance of {@link Conference} and pass it into {@link #addConference}.
Santos Cordonb6939982014-06-04 20:20:58 -07002244 *
Santos Cordon823fd3c2014-08-07 18:35:18 -07002245 * @param connection1 A connection to merge into a conference call.
2246 * @param connection2 A connection to merge into a conference call.
Santos Cordonb6939982014-06-04 20:20:58 -07002247 */
Santos Cordon823fd3c2014-08-07 18:35:18 -07002248 public void onConference(Connection connection1, Connection connection2) {}
Santos Cordonb6939982014-06-04 20:20:58 -07002249
Santos Cordona663f862014-10-29 13:49:58 -07002250 /**
Pengquan Meng70c9885332017-10-02 18:09:03 -07002251 * Called when a connection is added.
2252 * @hide
2253 */
2254 public void onConnectionAdded(Connection connection) {}
2255
2256 /**
2257 * Called when a connection is removed.
2258 * @hide
2259 */
2260 public void onConnectionRemoved(Connection connection) {}
2261
2262 /**
2263 * Called when a conference is added.
2264 * @hide
2265 */
2266 public void onConferenceAdded(Conference conference) {}
2267
2268 /**
2269 * Called when a conference is removed.
2270 * @hide
2271 */
2272 public void onConferenceRemoved(Conference conference) {}
2273
2274 /**
Santos Cordona663f862014-10-29 13:49:58 -07002275 * Indicates that a remote conference has been created for existing {@link RemoteConnection}s.
2276 * When this method is invoked, this {@link ConnectionService} should create its own
2277 * representation of the conference call and send it to telecom using {@link #addConference}.
2278 * <p>
2279 * This is only relevant to {@link ConnectionService}s which are registered with
2280 * {@link PhoneAccount#CAPABILITY_CONNECTION_MANAGER}.
2281 *
2282 * @param conference The remote conference call.
2283 */
Ihab Awadb8e85c72014-08-23 20:34:57 -07002284 public void onRemoteConferenceAdded(RemoteConference conference) {}
2285
Santos Cordon823fd3c2014-08-07 18:35:18 -07002286 /**
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002287 * Called when an existing connection is added remotely.
2288 * @param connection The existing connection which was added.
2289 */
2290 public void onRemoteExistingConnectionAdded(RemoteConnection connection) {}
2291
2292 /**
Pengquan Meng731c1a32017-11-21 18:01:13 -08002293 * Called when the {@link ConnectionService} has lost the call focus.
2294 * The {@link ConnectionService} should release the call resources and invokes
2295 * {@link ConnectionService#connectionServiceFocusReleased()} to inform telecom that it has
2296 * released the call resources.
2297 */
2298 public void onConnectionServiceFocusLost() {}
2299
2300 /**
2301 * Called when the {@link ConnectionService} has gained the call focus. The
2302 * {@link ConnectionService} can acquire the call resources at this time.
2303 */
2304 public void onConnectionServiceFocusGained() {}
2305
2306 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07002307 * @hide
2308 */
2309 public boolean containsConference(Conference conference) {
2310 return mIdByConference.containsKey(conference);
2311 }
2312
Ihab Awadb8e85c72014-08-23 20:34:57 -07002313 /** {@hide} */
2314 void addRemoteConference(RemoteConference remoteConference) {
2315 onRemoteConferenceAdded(remoteConference);
2316 }
2317
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002318 /** {@hide} */
2319 void addRemoteExistingConnection(RemoteConnection remoteConnection) {
2320 onRemoteExistingConnectionAdded(remoteConnection);
2321 }
2322
Ihab Awad5d0410f2014-07-30 10:07:40 -07002323 private void onAccountsInitialized() {
2324 mAreAccountsInitialized = true;
2325 for (Runnable r : mPreInitializationConnectionRequests) {
2326 r.run();
2327 }
2328 mPreInitializationConnectionRequests.clear();
2329 }
2330
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002331 /**
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002332 * Adds an existing connection to the list of connections, identified by a new call ID unique
2333 * to this connection service.
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002334 *
2335 * @param connection The connection.
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002336 * @return The ID of the connection (e.g. the call-id).
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002337 */
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002338 private String addExistingConnectionInternal(PhoneAccountHandle handle, Connection connection) {
2339 String id;
Tyler Gunncd6ccfd2016-10-17 15:48:19 -07002340
2341 if (connection.getExtras() != null && connection.getExtras()
2342 .containsKey(Connection.EXTRA_ORIGINAL_CONNECTION_ID)) {
2343 id = connection.getExtras().getString(Connection.EXTRA_ORIGINAL_CONNECTION_ID);
2344 Log.d(this, "addExistingConnectionInternal - conn %s reusing original id %s",
2345 connection.getTelecomCallId(), id);
2346 } else if (handle == null) {
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002347 // If no phone account handle was provided, we cannot be sure the call ID is unique,
2348 // so just use a random UUID.
2349 id = UUID.randomUUID().toString();
2350 } else {
2351 // Phone account handle was provided, so use the ConnectionService class name as a
2352 // prefix for a unique incremental call ID.
2353 id = handle.getComponentName().getClassName() + "@" + getNextCallId();
2354 }
Pengquan Meng70c9885332017-10-02 18:09:03 -07002355 addConnection(handle, id, connection);
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002356 return id;
2357 }
2358
Pengquan Meng70c9885332017-10-02 18:09:03 -07002359 private void addConnection(PhoneAccountHandle handle, String callId, Connection connection) {
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002360 connection.setTelecomCallId(callId);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002361 mConnectionById.put(callId, connection);
2362 mIdByConnection.put(connection, callId);
2363 connection.addConnectionListener(mConnectionListener);
Santos Cordon823fd3c2014-08-07 18:35:18 -07002364 connection.setConnectionService(this);
Pengquan Meng70c9885332017-10-02 18:09:03 -07002365 connection.setPhoneAccountHandle(handle);
2366 onConnectionAdded(connection);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002367 }
2368
Anthony Lee30e65842014-11-06 16:30:53 -08002369 /** {@hide} */
2370 protected void removeConnection(Connection connection) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07002371 connection.unsetConnectionService(this);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002372 connection.removeConnectionListener(mConnectionListener);
Chenjie Luoe370b532016-05-12 16:59:43 -07002373 String id = mIdByConnection.get(connection);
2374 if (id != null) {
2375 mConnectionById.remove(id);
2376 mIdByConnection.remove(connection);
2377 mAdapter.removeCall(id);
Pengquan Meng70c9885332017-10-02 18:09:03 -07002378 onConnectionRemoved(connection);
Chenjie Luoe370b532016-05-12 16:59:43 -07002379 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002380 }
2381
Santos Cordon823fd3c2014-08-07 18:35:18 -07002382 private String addConferenceInternal(Conference conference) {
Tyler Gunncd6ccfd2016-10-17 15:48:19 -07002383 String originalId = null;
2384 if (conference.getExtras() != null && conference.getExtras()
2385 .containsKey(Connection.EXTRA_ORIGINAL_CONNECTION_ID)) {
2386 originalId = conference.getExtras().getString(Connection.EXTRA_ORIGINAL_CONNECTION_ID);
2387 Log.d(this, "addConferenceInternal: conf %s reusing original id %s",
2388 conference.getTelecomCallId(),
2389 originalId);
2390 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07002391 if (mIdByConference.containsKey(conference)) {
2392 Log.w(this, "Re-adding an existing conference: %s.", conference);
2393 } else if (conference != null) {
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002394 // Conferences do not (yet) have a PhoneAccountHandle associated with them, so we
2395 // cannot determine a ConnectionService class name to associate with the ID, so use
2396 // a unique UUID (for now).
Tyler Gunncd6ccfd2016-10-17 15:48:19 -07002397 String id = originalId == null ? UUID.randomUUID().toString() : originalId;
Santos Cordon823fd3c2014-08-07 18:35:18 -07002398 mConferenceById.put(id, conference);
2399 mIdByConference.put(conference, id);
2400 conference.addListener(mConferenceListener);
2401 return id;
2402 }
2403
2404 return null;
2405 }
2406
2407 private void removeConference(Conference conference) {
2408 if (mIdByConference.containsKey(conference)) {
2409 conference.removeListener(mConferenceListener);
2410
2411 String id = mIdByConference.get(conference);
2412 mConferenceById.remove(id);
2413 mIdByConference.remove(conference);
2414 mAdapter.removeCall(id);
Pengquan Meng70c9885332017-10-02 18:09:03 -07002415
2416 onConferenceRemoved(conference);
Santos Cordon823fd3c2014-08-07 18:35:18 -07002417 }
2418 }
2419
Ihab Awad542e0ea2014-05-16 10:22:16 -07002420 private Connection findConnectionForAction(String callId, String action) {
Tyler Gunn0a88f2e2017-06-16 20:20:34 -07002421 if (callId != null && mConnectionById.containsKey(callId)) {
Ihab Awad542e0ea2014-05-16 10:22:16 -07002422 return mConnectionById.get(callId);
2423 }
Ihab Awad60ac30b2014-05-20 22:32:12 -07002424 Log.w(this, "%s - Cannot find Connection %s", action, callId);
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07002425 return getNullConnection();
2426 }
2427
2428 static synchronized Connection getNullConnection() {
2429 if (sNullConnection == null) {
2430 sNullConnection = new Connection() {};
2431 }
2432 return sNullConnection;
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002433 }
Santos Cordon0159ac02014-08-21 14:28:11 -07002434
2435 private Conference findConferenceForAction(String conferenceId, String action) {
2436 if (mConferenceById.containsKey(conferenceId)) {
2437 return mConferenceById.get(conferenceId);
2438 }
2439 Log.w(this, "%s - Cannot find conference %s", action, conferenceId);
2440 return getNullConference();
2441 }
2442
Ihab Awadb8e85c72014-08-23 20:34:57 -07002443 private List<String> createConnectionIdList(List<Connection> connections) {
2444 List<String> ids = new ArrayList<>();
2445 for (Connection c : connections) {
2446 if (mIdByConnection.containsKey(c)) {
2447 ids.add(mIdByConnection.get(c));
2448 }
2449 }
2450 Collections.sort(ids);
2451 return ids;
2452 }
2453
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002454 /**
2455 * Builds a list of {@link Connection} and {@link Conference} IDs based on the list of
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002456 * {@link Conferenceable}s passed in.
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002457 *
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002458 * @param conferenceables The {@link Conferenceable} connections and conferences.
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002459 * @return List of string conference and call Ids.
2460 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002461 private List<String> createIdList(List<Conferenceable> conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002462 List<String> ids = new ArrayList<>();
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002463 for (Conferenceable c : conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002464 // Only allow Connection and Conference conferenceables.
2465 if (c instanceof Connection) {
2466 Connection connection = (Connection) c;
2467 if (mIdByConnection.containsKey(connection)) {
2468 ids.add(mIdByConnection.get(connection));
2469 }
2470 } else if (c instanceof Conference) {
2471 Conference conference = (Conference) c;
2472 if (mIdByConference.containsKey(conference)) {
2473 ids.add(mIdByConference.get(conference));
2474 }
2475 }
2476 }
2477 Collections.sort(ids);
2478 return ids;
2479 }
2480
Santos Cordon0159ac02014-08-21 14:28:11 -07002481 private Conference getNullConference() {
2482 if (sNullConference == null) {
2483 sNullConference = new Conference(null) {};
2484 }
2485 return sNullConference;
2486 }
Santos Cordon29f2f2e2014-09-11 19:50:24 -07002487
2488 private void endAllConnections() {
2489 // Unbound from telecomm. We should end all connections and conferences.
2490 for (Connection connection : mIdByConnection.keySet()) {
2491 // only operate on top-level calls. Conference calls will be removed on their own.
2492 if (connection.getConference() == null) {
2493 connection.onDisconnect();
2494 }
2495 }
2496 for (Conference conference : mIdByConference.keySet()) {
2497 conference.onDisconnect();
2498 }
2499 }
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002500
2501 /**
2502 * Retrieves the next call ID as maintainted by the connection service.
2503 *
2504 * @return The call ID.
2505 */
2506 private int getNextCallId() {
Brad Ebingerb32d4f82016-10-24 16:40:49 -07002507 synchronized (mIdSyncRoot) {
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002508 return ++mId;
2509 }
2510 }
Santos Cordon980acb92014-05-31 10:31:19 -07002511}