blob: 773ed705a9991600c7cfb87f463b531dd4053f33 [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
yongnamcha8ec56242022-11-28 06:23:02 +000019import android.annotation.CallbackExecutor;
Tyler Gunn5567d742019-10-31 13:04:37 -070020import android.annotation.NonNull;
21import android.annotation.Nullable;
Roopa Sattiraju45de470c2022-01-27 21:31:35 -080022import android.annotation.RequiresPermission;
Santos Cordon5c6fa952014-07-20 17:47:12 -070023import android.annotation.SdkConstant;
Tyler Gunn5567d742019-10-31 13:04:37 -070024import android.annotation.SystemApi;
Hall Liueb7c9ea2021-03-09 20:24:50 -080025import android.annotation.TestApi;
Sailesh Nepal2a46b902014-07-04 17:21:07 -070026import android.app.Service;
Santos Cordon52d8a152014-06-17 19:08:45 -070027import android.content.ComponentName;
Santos Cordon5c6fa952014-07-20 17:47:12 -070028import android.content.Intent;
yongnamcha8ec56242022-11-28 06:23:02 +000029import android.location.Location;
Ihab Awad542e0ea2014-05-16 10:22:16 -070030import android.net.Uri;
Santos Cordon6b7f9552015-05-27 17:21:45 -070031import android.os.Bundle;
Santos Cordon52d8a152014-06-17 19:08:45 -070032import android.os.Handler;
33import android.os.IBinder;
34import android.os.Looper;
Sailesh Nepal2a46b902014-07-04 17:21:07 -070035import android.os.Message;
Junhoedf3d822022-11-24 09:26:37 +000036import android.os.OutcomeReceiver;
Hall Liub64ac4c2017-02-06 10:49:48 -080037import android.os.ParcelFileDescriptor;
38import android.os.RemoteException;
Brad Ebingerb32d4f82016-10-24 16:40:49 -070039import android.telecom.Logging.Session;
Andrew Lee14185762014-07-25 09:41:56 -070040
Brad Ebinger99f17ce2019-09-11 18:06:51 -070041import com.android.internal.annotations.VisibleForTesting;
Sailesh Nepal2a46b902014-07-04 17:21:07 -070042import com.android.internal.os.SomeArgs;
Tyler Gunnef9f6f92014-09-12 22:16:17 -070043import com.android.internal.telecom.IConnectionService;
44import com.android.internal.telecom.IConnectionServiceAdapter;
45import com.android.internal.telecom.RemoteServiceCallback;
Santos Cordon52d8a152014-06-17 19:08:45 -070046
Ihab Awad5d0410f2014-07-30 10:07:40 -070047import java.util.ArrayList;
Santos Cordonb6939982014-06-04 20:20:58 -070048import java.util.Collection;
Santos Cordon7c7bc7f2014-07-28 18:15:48 -070049import java.util.Collections;
Santos Cordon52d8a152014-06-17 19:08:45 -070050import java.util.List;
Ihab Awad542e0ea2014-05-16 10:22:16 -070051import java.util.Map;
Santos Cordon823fd3c2014-08-07 18:35:18 -070052import java.util.UUID;
mike dooley95e80702014-09-18 14:07:52 -070053import java.util.concurrent.ConcurrentHashMap;
Junhoedf3d822022-11-24 09:26:37 +000054import java.util.concurrent.Executor;
Ihab Awad542e0ea2014-05-16 10:22:16 -070055
56/**
Tyler Gunnf5035432017-01-09 09:43:12 -080057 * An abstract service that should be implemented by any apps which either:
58 * <ol>
59 * <li>Can make phone calls (VoIP or otherwise) and want those calls to be integrated into the
60 * built-in phone app. Referred to as a <b>system managed</b> {@link ConnectionService}.</li>
61 * <li>Are a standalone calling app and don't want their calls to be integrated into the
62 * built-in phone app. Referred to as a <b>self managed</b> {@link ConnectionService}.</li>
63 * </ol>
64 * Once implemented, the {@link ConnectionService} needs to take the following steps so that Telecom
65 * will bind to it:
Santos Cordona663f862014-10-29 13:49:58 -070066 * <p>
67 * 1. <i>Registration in AndroidManifest.xml</i>
68 * <br/>
69 * <pre>
70 * &lt;service android:name="com.example.package.MyConnectionService"
71 * android:label="@string/some_label_for_my_connection_service"
Yorke Lee249c12e2015-05-13 15:59:29 -070072 * android:permission="android.permission.BIND_TELECOM_CONNECTION_SERVICE"&gt;
Santos Cordona663f862014-10-29 13:49:58 -070073 * &lt;intent-filter&gt;
74 * &lt;action android:name="android.telecom.ConnectionService" /&gt;
75 * &lt;/intent-filter&gt;
76 * &lt;/service&gt;
77 * </pre>
78 * <p>
79 * 2. <i> Registration of {@link PhoneAccount} with {@link TelecomManager}.</i>
80 * <br/>
81 * See {@link PhoneAccount} and {@link TelecomManager#registerPhoneAccount} for more information.
82 * <p>
Tyler Gunnf5035432017-01-09 09:43:12 -080083 * System managed {@link ConnectionService}s must be enabled by the user in the phone app settings
kopriva82c591b2018-10-08 15:57:00 -070084 * before Telecom will bind to them. Self-managed {@link ConnectionService}s must be granted the
Tyler Gunnf5035432017-01-09 09:43:12 -080085 * appropriate permission before Telecom will bind to them.
86 * <p>
87 * Once registered and enabled by the user in the phone app settings or granted permission, telecom
88 * will bind to a {@link ConnectionService} implementation when it wants that
89 * {@link ConnectionService} to place a call or the service has indicated that is has an incoming
90 * call through {@link TelecomManager#addNewIncomingCall}. The {@link ConnectionService} can then
91 * expect a call to {@link #onCreateIncomingConnection} or {@link #onCreateOutgoingConnection}
92 * wherein it should provide a new instance of a {@link Connection} object. It is through this
93 * {@link Connection} object that telecom receives state updates and the {@link ConnectionService}
Santos Cordona663f862014-10-29 13:49:58 -070094 * receives call-commands such as answer, reject, hold and disconnect.
95 * <p>
Tyler Gunnf5035432017-01-09 09:43:12 -080096 * When there are no more live calls, telecom will unbind from the {@link ConnectionService}.
Ihab Awad542e0ea2014-05-16 10:22:16 -070097 */
Sailesh Nepal2a46b902014-07-04 17:21:07 -070098public abstract class ConnectionService extends Service {
Santos Cordon5c6fa952014-07-20 17:47:12 -070099 /**
100 * The {@link Intent} that must be declared as handled by the service.
101 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700102 @SdkConstant(SdkConstant.SdkConstantType.SERVICE_ACTION)
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700103 public static final String SERVICE_INTERFACE = "android.telecom.ConnectionService";
Santos Cordon5c6fa952014-07-20 17:47:12 -0700104
Tyler Gunn8bf76572017-04-06 15:30:08 -0700105 /**
106 * Boolean extra used by Telecom to inform a {@link ConnectionService} that the purpose of it
107 * being asked to create a new outgoing {@link Connection} is to perform a handover of an
108 * ongoing call on the device from another {@link PhoneAccount}/{@link ConnectionService}. Will
109 * be specified in the {@link ConnectionRequest#getExtras()} passed by Telecom when
110 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)} is called.
111 * <p>
Tyler Gunn727c6bd2017-04-11 09:51:40 -0700112 * When your {@link ConnectionService} receives this extra, it should communicate the fact that
113 * this is a handover to the other device's matching {@link ConnectionService}. That
Tyler Gunn8bf76572017-04-06 15:30:08 -0700114 * {@link ConnectionService} will continue the handover using
115 * {@link TelecomManager#addNewIncomingCall(PhoneAccountHandle, Bundle)}, specifying
Tyler Gunn727c6bd2017-04-11 09:51:40 -0700116 * {@link TelecomManager#EXTRA_IS_HANDOVER}. Telecom will match the phone numbers of the
117 * handover call on the other device with ongoing calls for {@link ConnectionService}s which
118 * support {@link PhoneAccount#EXTRA_SUPPORTS_HANDOVER_FROM}.
Tyler Gunn8bf76572017-04-06 15:30:08 -0700119 * @hide
120 */
121 public static final String EXTRA_IS_HANDOVER = TelecomManager.EXTRA_IS_HANDOVER;
122
Ihab Awad542e0ea2014-05-16 10:22:16 -0700123 // Flag controlling whether PII is emitted into the logs
Ihab Awad60ac30b2014-05-20 22:32:12 -0700124 private static final boolean PII_DEBUG = Log.isLoggable(android.util.Log.DEBUG);
Ihab Awad542e0ea2014-05-16 10:22:16 -0700125
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700126 // Session Definitions
127 private static final String SESSION_HANDLER = "H.";
128 private static final String SESSION_ADD_CS_ADAPTER = "CS.aCSA";
129 private static final String SESSION_REMOVE_CS_ADAPTER = "CS.rCSA";
130 private static final String SESSION_CREATE_CONN = "CS.crCo";
Tyler Gunn041a1fe2017-05-12 10:04:49 -0700131 private static final String SESSION_CREATE_CONN_COMPLETE = "CS.crCoC";
Tyler Gunn44e01912017-01-31 10:49:05 -0800132 private static final String SESSION_CREATE_CONN_FAILED = "CS.crCoF";
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700133 private static final String SESSION_ABORT = "CS.ab";
134 private static final String SESSION_ANSWER = "CS.an";
135 private static final String SESSION_ANSWER_VIDEO = "CS.anV";
Pooja Jaind34698d2017-12-28 14:15:31 +0530136 private static final String SESSION_DEFLECT = "CS.def";
Ravi Palurif4b38e72020-02-05 12:35:41 +0530137 private static final String SESSION_TRANSFER = "CS.trans";
138 private static final String SESSION_CONSULTATIVE_TRANSFER = "CS.cTrans";
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700139 private static final String SESSION_REJECT = "CS.r";
140 private static final String SESSION_REJECT_MESSAGE = "CS.rWM";
141 private static final String SESSION_SILENCE = "CS.s";
142 private static final String SESSION_DISCONNECT = "CS.d";
143 private static final String SESSION_HOLD = "CS.h";
144 private static final String SESSION_UNHOLD = "CS.u";
145 private static final String SESSION_CALL_AUDIO_SC = "CS.cASC";
Grace Jiae99fde92021-01-19 14:58:01 -0800146 private static final String SESSION_USING_ALTERNATIVE_UI = "CS.uAU";
147 private static final String SESSION_TRACKED_BY_NON_UI_SERVICE = "CS.tBNUS";
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700148 private static final String SESSION_PLAY_DTMF = "CS.pDT";
149 private static final String SESSION_STOP_DTMF = "CS.sDT";
150 private static final String SESSION_CONFERENCE = "CS.c";
151 private static final String SESSION_SPLIT_CONFERENCE = "CS.sFC";
152 private static final String SESSION_MERGE_CONFERENCE = "CS.mC";
153 private static final String SESSION_SWAP_CONFERENCE = "CS.sC";
Ravi Paluri404babb2020-01-23 19:02:44 +0530154 private static final String SESSION_ADD_PARTICIPANT = "CS.aP";
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700155 private static final String SESSION_POST_DIAL_CONT = "CS.oPDC";
156 private static final String SESSION_PULL_EXTERNAL_CALL = "CS.pEC";
157 private static final String SESSION_SEND_CALL_EVENT = "CS.sCE";
Hall Liu49cabcc2021-01-15 11:41:48 -0800158 private static final String SESSION_CALL_FILTERING_COMPLETED = "CS.oCFC";
Tyler Gunn79bc1ec2018-01-22 15:17:54 -0800159 private static final String SESSION_HANDOVER_COMPLETE = "CS.hC";
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700160 private static final String SESSION_EXTRAS_CHANGED = "CS.oEC";
Hall Liub64ac4c2017-02-06 10:49:48 -0800161 private static final String SESSION_START_RTT = "CS.+RTT";
Hall Liua549fed2018-02-09 16:40:03 -0800162 private static final String SESSION_UPDATE_RTT_PIPES = "CS.uRTT";
Hall Liub64ac4c2017-02-06 10:49:48 -0800163 private static final String SESSION_STOP_RTT = "CS.-RTT";
164 private static final String SESSION_RTT_UPGRADE_RESPONSE = "CS.rTRUR";
Pengquan Meng731c1a32017-11-21 18:01:13 -0800165 private static final String SESSION_CONNECTION_SERVICE_FOCUS_LOST = "CS.cSFL";
166 private static final String SESSION_CONNECTION_SERVICE_FOCUS_GAINED = "CS.cSFG";
Sanket Padawe4cc8ed52017-12-04 16:22:20 -0800167 private static final String SESSION_HANDOVER_FAILED = "CS.haF";
Ravi Paluri80aa2142019-12-02 11:57:37 +0530168 private static final String SESSION_CREATE_CONF = "CS.crConf";
169 private static final String SESSION_CREATE_CONF_COMPLETE = "CS.crConfC";
170 private static final String SESSION_CREATE_CONF_FAILED = "CS.crConfF";
Junhoedf3d822022-11-24 09:26:37 +0000171 private static final String SESSION_CALL_ENDPOINT_CHANGED = "CS.oCEC";
172 private static final String SESSION_AVAILABLE_CALL_ENDPOINTS_CHANGED = "CS.oACEC";
173 private static final String SESSION_MUTE_STATE_CHANGED = "CS.oMSC";
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700174
Ihab Awad8aecfed2014-08-08 17:06:11 -0700175 private static final int MSG_ADD_CONNECTION_SERVICE_ADAPTER = 1;
Sailesh Nepalc5b01572014-07-14 16:29:44 -0700176 private static final int MSG_CREATE_CONNECTION = 2;
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700177 private static final int MSG_ABORT = 3;
Sailesh Nepalc5b01572014-07-14 16:29:44 -0700178 private static final int MSG_ANSWER = 4;
179 private static final int MSG_REJECT = 5;
180 private static final int MSG_DISCONNECT = 6;
181 private static final int MSG_HOLD = 7;
182 private static final int MSG_UNHOLD = 8;
Yorke Lee4af59352015-05-13 14:14:54 -0700183 private static final int MSG_ON_CALL_AUDIO_STATE_CHANGED = 9;
Sailesh Nepalc5b01572014-07-14 16:29:44 -0700184 private static final int MSG_PLAY_DTMF_TONE = 10;
185 private static final int MSG_STOP_DTMF_TONE = 11;
186 private static final int MSG_CONFERENCE = 12;
187 private static final int MSG_SPLIT_FROM_CONFERENCE = 13;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700188 private static final int MSG_ON_POST_DIAL_CONTINUE = 14;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700189 private static final int MSG_REMOVE_CONNECTION_SERVICE_ADAPTER = 16;
Tyler Gunnbe74de02014-08-29 14:51:48 -0700190 private static final int MSG_ANSWER_VIDEO = 17;
Santos Cordona4868042014-09-04 17:39:22 -0700191 private static final int MSG_MERGE_CONFERENCE = 18;
192 private static final int MSG_SWAP_CONFERENCE = 19;
Bryce Lee81901682015-08-28 16:38:02 -0700193 private static final int MSG_REJECT_WITH_MESSAGE = 20;
Bryce Leecac50772015-11-17 15:13:29 -0800194 private static final int MSG_SILENCE = 21;
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700195 private static final int MSG_PULL_EXTERNAL_CALL = 22;
196 private static final int MSG_SEND_CALL_EVENT = 23;
Tyler Gunndee56a82016-03-23 16:06:34 -0700197 private static final int MSG_ON_EXTRAS_CHANGED = 24;
Tyler Gunn44e01912017-01-31 10:49:05 -0800198 private static final int MSG_CREATE_CONNECTION_FAILED = 25;
Hall Liub64ac4c2017-02-06 10:49:48 -0800199 private static final int MSG_ON_START_RTT = 26;
200 private static final int MSG_ON_STOP_RTT = 27;
201 private static final int MSG_RTT_UPGRADE_RESPONSE = 28;
Tyler Gunn041a1fe2017-05-12 10:04:49 -0700202 private static final int MSG_CREATE_CONNECTION_COMPLETE = 29;
Pengquan Meng731c1a32017-11-21 18:01:13 -0800203 private static final int MSG_CONNECTION_SERVICE_FOCUS_LOST = 30;
204 private static final int MSG_CONNECTION_SERVICE_FOCUS_GAINED = 31;
Sanket Padawe4cc8ed52017-12-04 16:22:20 -0800205 private static final int MSG_HANDOVER_FAILED = 32;
Tyler Gunn79bc1ec2018-01-22 15:17:54 -0800206 private static final int MSG_HANDOVER_COMPLETE = 33;
Pooja Jaind34698d2017-12-28 14:15:31 +0530207 private static final int MSG_DEFLECT = 34;
Ravi Paluri80aa2142019-12-02 11:57:37 +0530208 private static final int MSG_CREATE_CONFERENCE = 35;
209 private static final int MSG_CREATE_CONFERENCE_COMPLETE = 36;
210 private static final int MSG_CREATE_CONFERENCE_FAILED = 37;
Tyler Gunnfacfdee2020-01-23 13:10:37 -0800211 private static final int MSG_REJECT_WITH_REASON = 38;
Ravi Paluri404babb2020-01-23 19:02:44 +0530212 private static final int MSG_ADD_PARTICIPANT = 39;
Ravi Palurif4b38e72020-02-05 12:35:41 +0530213 private static final int MSG_EXPLICIT_CALL_TRANSFER = 40;
214 private static final int MSG_EXPLICIT_CALL_TRANSFER_CONSULTATIVE = 41;
Hall Liu49cabcc2021-01-15 11:41:48 -0800215 private static final int MSG_ON_CALL_FILTERING_COMPLETED = 42;
Grace Jiae99fde92021-01-19 14:58:01 -0800216 private static final int MSG_ON_USING_ALTERNATIVE_UI = 43;
217 private static final int MSG_ON_TRACKED_BY_NON_UI_SERVICE = 44;
Junhoedf3d822022-11-24 09:26:37 +0000218 private static final int MSG_ON_CALL_ENDPOINT_CHANGED = 45;
219 private static final int MSG_ON_AVAILABLE_CALL_ENDPOINTS_CHANGED = 46;
220 private static final int MSG_ON_MUTE_STATE_CHANGED = 47;
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700221
Sailesh Nepalcf7020b2014-08-20 10:07:19 -0700222 private static Connection sNullConnection;
223
mike dooley95e80702014-09-18 14:07:52 -0700224 private final Map<String, Connection> mConnectionById = new ConcurrentHashMap<>();
225 private final Map<Connection, String> mIdByConnection = new ConcurrentHashMap<>();
226 private final Map<String, Conference> mConferenceById = new ConcurrentHashMap<>();
227 private final Map<Conference, String> mIdByConference = new ConcurrentHashMap<>();
Ihab Awadb8e85c72014-08-23 20:34:57 -0700228 private final RemoteConnectionManager mRemoteConnectionManager =
229 new RemoteConnectionManager(this);
Ihab Awad5d0410f2014-07-30 10:07:40 -0700230 private final List<Runnable> mPreInitializationConnectionRequests = new ArrayList<>();
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700231 private final ConnectionServiceAdapter mAdapter = new ConnectionServiceAdapter();
Ihab Awad542e0ea2014-05-16 10:22:16 -0700232
Santos Cordon823fd3c2014-08-07 18:35:18 -0700233 private boolean mAreAccountsInitialized = false;
Santos Cordon0159ac02014-08-21 14:28:11 -0700234 private Conference sNullConference;
Tyler Gunnf0500bd2015-09-01 10:59:48 -0700235 private Object mIdSyncRoot = new Object();
236 private int mId = 0;
Santos Cordon823fd3c2014-08-07 18:35:18 -0700237
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700238 private final IBinder mBinder = new IConnectionService.Stub() {
239 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700240 public void addConnectionServiceAdapter(IConnectionServiceAdapter adapter,
241 Session.Info sessionInfo) {
242 Log.startSession(sessionInfo, SESSION_ADD_CS_ADAPTER);
243 try {
244 SomeArgs args = SomeArgs.obtain();
245 args.arg1 = adapter;
246 args.arg2 = Log.createSubsession();
247 mHandler.obtainMessage(MSG_ADD_CONNECTION_SERVICE_ADAPTER, args).sendToTarget();
248 } finally {
249 Log.endSession();
250 }
Ihab Awad8aecfed2014-08-08 17:06:11 -0700251 }
252
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700253 public void removeConnectionServiceAdapter(IConnectionServiceAdapter adapter,
254 Session.Info sessionInfo) {
255 Log.startSession(sessionInfo, SESSION_REMOVE_CS_ADAPTER);
256 try {
257 SomeArgs args = SomeArgs.obtain();
258 args.arg1 = adapter;
259 args.arg2 = Log.createSubsession();
260 mHandler.obtainMessage(MSG_REMOVE_CONNECTION_SERVICE_ADAPTER, args).sendToTarget();
261 } finally {
262 Log.endSession();
263 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700264 }
265
266 @Override
Ihab Awadf8b69882014-07-25 15:14:01 -0700267 public void createConnection(
268 PhoneAccountHandle connectionManagerPhoneAccount,
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700269 String id,
Ihab Awadf8b69882014-07-25 15:14:01 -0700270 ConnectionRequest request,
Yorke Leec3cf9822014-10-02 09:38:39 -0700271 boolean isIncoming,
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700272 boolean isUnknown,
273 Session.Info sessionInfo) {
274 Log.startSession(sessionInfo, SESSION_CREATE_CONN);
275 try {
276 SomeArgs args = SomeArgs.obtain();
277 args.arg1 = connectionManagerPhoneAccount;
278 args.arg2 = id;
279 args.arg3 = request;
280 args.arg4 = Log.createSubsession();
281 args.argi1 = isIncoming ? 1 : 0;
282 args.argi2 = isUnknown ? 1 : 0;
283 mHandler.obtainMessage(MSG_CREATE_CONNECTION, args).sendToTarget();
284 } finally {
285 Log.endSession();
286 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700287 }
288
289 @Override
Tyler Gunn041a1fe2017-05-12 10:04:49 -0700290 public void createConnectionComplete(String id, Session.Info sessionInfo) {
291 Log.startSession(sessionInfo, SESSION_CREATE_CONN_COMPLETE);
292 try {
293 SomeArgs args = SomeArgs.obtain();
294 args.arg1 = id;
295 args.arg2 = Log.createSubsession();
296 mHandler.obtainMessage(MSG_CREATE_CONNECTION_COMPLETE, args).sendToTarget();
297 } finally {
298 Log.endSession();
299 }
300 }
301
302 @Override
Tyler Gunn44e01912017-01-31 10:49:05 -0800303 public void createConnectionFailed(
Tyler Gunn159f35c2017-03-02 09:28:37 -0800304 PhoneAccountHandle connectionManagerPhoneAccount,
Tyler Gunn44e01912017-01-31 10:49:05 -0800305 String callId,
306 ConnectionRequest request,
307 boolean isIncoming,
308 Session.Info sessionInfo) {
309 Log.startSession(sessionInfo, SESSION_CREATE_CONN_FAILED);
310 try {
311 SomeArgs args = SomeArgs.obtain();
312 args.arg1 = callId;
313 args.arg2 = request;
314 args.arg3 = Log.createSubsession();
Tyler Gunn159f35c2017-03-02 09:28:37 -0800315 args.arg4 = connectionManagerPhoneAccount;
Tyler Gunn44e01912017-01-31 10:49:05 -0800316 args.argi1 = isIncoming ? 1 : 0;
317 mHandler.obtainMessage(MSG_CREATE_CONNECTION_FAILED, args).sendToTarget();
318 } finally {
319 Log.endSession();
320 }
321 }
322
323 @Override
Ravi Paluri80aa2142019-12-02 11:57:37 +0530324 public void createConference(
325 PhoneAccountHandle connectionManagerPhoneAccount,
326 String id,
327 ConnectionRequest request,
328 boolean isIncoming,
329 boolean isUnknown,
330 Session.Info sessionInfo) {
331 Log.startSession(sessionInfo, SESSION_CREATE_CONF);
332 try {
333 SomeArgs args = SomeArgs.obtain();
334 args.arg1 = connectionManagerPhoneAccount;
335 args.arg2 = id;
336 args.arg3 = request;
337 args.arg4 = Log.createSubsession();
338 args.argi1 = isIncoming ? 1 : 0;
339 args.argi2 = isUnknown ? 1 : 0;
340 mHandler.obtainMessage(MSG_CREATE_CONFERENCE, args).sendToTarget();
341 } finally {
342 Log.endSession();
343 }
344 }
345
346 @Override
347 public void createConferenceComplete(String id, Session.Info sessionInfo) {
348 Log.startSession(sessionInfo, SESSION_CREATE_CONF_COMPLETE);
349 try {
350 SomeArgs args = SomeArgs.obtain();
351 args.arg1 = id;
352 args.arg2 = Log.createSubsession();
353 mHandler.obtainMessage(MSG_CREATE_CONFERENCE_COMPLETE, args).sendToTarget();
354 } finally {
355 Log.endSession();
356 }
357 }
358
359 @Override
360 public void createConferenceFailed(
361 PhoneAccountHandle connectionManagerPhoneAccount,
362 String callId,
363 ConnectionRequest request,
364 boolean isIncoming,
365 Session.Info sessionInfo) {
366 Log.startSession(sessionInfo, SESSION_CREATE_CONF_FAILED);
367 try {
368 SomeArgs args = SomeArgs.obtain();
369 args.arg1 = callId;
370 args.arg2 = request;
371 args.arg3 = Log.createSubsession();
372 args.arg4 = connectionManagerPhoneAccount;
373 args.argi1 = isIncoming ? 1 : 0;
374 mHandler.obtainMessage(MSG_CREATE_CONFERENCE_FAILED, args).sendToTarget();
375 } finally {
376 Log.endSession();
377 }
378 }
379
380 @Override
Sanket Padawe4cc8ed52017-12-04 16:22:20 -0800381 public void handoverFailed(String callId, ConnectionRequest request, int reason,
382 Session.Info sessionInfo) {
383 Log.startSession(sessionInfo, SESSION_HANDOVER_FAILED);
384 try {
385 SomeArgs args = SomeArgs.obtain();
386 args.arg1 = callId;
387 args.arg2 = request;
388 args.arg3 = Log.createSubsession();
389 args.arg4 = reason;
390 mHandler.obtainMessage(MSG_HANDOVER_FAILED, args).sendToTarget();
391 } finally {
392 Log.endSession();
393 }
394 }
395
396 @Override
Tyler Gunn79bc1ec2018-01-22 15:17:54 -0800397 public void handoverComplete(String callId, Session.Info sessionInfo) {
398 Log.startSession(sessionInfo, SESSION_HANDOVER_COMPLETE);
399 try {
400 SomeArgs args = SomeArgs.obtain();
401 args.arg1 = callId;
402 args.arg2 = Log.createSubsession();
403 mHandler.obtainMessage(MSG_HANDOVER_COMPLETE, args).sendToTarget();
404 } finally {
405 Log.endSession();
406 }
407 }
408
409 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700410 public void abort(String callId, Session.Info sessionInfo) {
411 Log.startSession(sessionInfo, SESSION_ABORT);
412 try {
413 SomeArgs args = SomeArgs.obtain();
414 args.arg1 = callId;
415 args.arg2 = Log.createSubsession();
416 mHandler.obtainMessage(MSG_ABORT, args).sendToTarget();
417 } finally {
418 Log.endSession();
419 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700420 }
421
422 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700423 public void answerVideo(String callId, int videoState, Session.Info sessionInfo) {
424 Log.startSession(sessionInfo, SESSION_ANSWER_VIDEO);
425 try {
426 SomeArgs args = SomeArgs.obtain();
427 args.arg1 = callId;
428 args.arg2 = Log.createSubsession();
429 args.argi1 = videoState;
430 mHandler.obtainMessage(MSG_ANSWER_VIDEO, args).sendToTarget();
431 } finally {
432 Log.endSession();
433 }
Tyler Gunnbe74de02014-08-29 14:51:48 -0700434 }
435
436 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700437 public void answer(String callId, Session.Info sessionInfo) {
438 Log.startSession(sessionInfo, SESSION_ANSWER);
439 try {
440 SomeArgs args = SomeArgs.obtain();
441 args.arg1 = callId;
442 args.arg2 = Log.createSubsession();
443 mHandler.obtainMessage(MSG_ANSWER, args).sendToTarget();
444 } finally {
445 Log.endSession();
446 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700447 }
448
449 @Override
Pooja Jaind34698d2017-12-28 14:15:31 +0530450 public void deflect(String callId, Uri address, Session.Info sessionInfo) {
451 Log.startSession(sessionInfo, SESSION_DEFLECT);
452 try {
453 SomeArgs args = SomeArgs.obtain();
454 args.arg1 = callId;
455 args.arg2 = address;
456 args.arg3 = Log.createSubsession();
457 mHandler.obtainMessage(MSG_DEFLECT, args).sendToTarget();
458 } finally {
459 Log.endSession();
460 }
461 }
462
463 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700464 public void reject(String callId, Session.Info sessionInfo) {
465 Log.startSession(sessionInfo, SESSION_REJECT);
466 try {
467 SomeArgs args = SomeArgs.obtain();
468 args.arg1 = callId;
469 args.arg2 = Log.createSubsession();
470 mHandler.obtainMessage(MSG_REJECT, args).sendToTarget();
471 } finally {
472 Log.endSession();
473 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700474 }
475
476 @Override
Tyler Gunnfacfdee2020-01-23 13:10:37 -0800477 public void rejectWithReason(String callId,
478 @android.telecom.Call.RejectReason int rejectReason, Session.Info sessionInfo) {
479 Log.startSession(sessionInfo, SESSION_REJECT);
480 try {
481 SomeArgs args = SomeArgs.obtain();
482 args.arg1 = callId;
483 args.argi1 = rejectReason;
484 args.arg2 = Log.createSubsession();
485 mHandler.obtainMessage(MSG_REJECT_WITH_REASON, args).sendToTarget();
486 } finally {
487 Log.endSession();
488 }
489 }
490
491 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700492 public void rejectWithMessage(String callId, String message, Session.Info sessionInfo) {
493 Log.startSession(sessionInfo, SESSION_REJECT_MESSAGE);
494 try {
495 SomeArgs args = SomeArgs.obtain();
496 args.arg1 = callId;
497 args.arg2 = message;
498 args.arg3 = Log.createSubsession();
499 mHandler.obtainMessage(MSG_REJECT_WITH_MESSAGE, args).sendToTarget();
500 } finally {
501 Log.endSession();
502 }
Bryce Lee81901682015-08-28 16:38:02 -0700503 }
504
505 @Override
Ravi Palurif4b38e72020-02-05 12:35:41 +0530506 public void transfer(@NonNull String callId, @NonNull Uri number,
507 boolean isConfirmationRequired, Session.Info sessionInfo) {
508 Log.startSession(sessionInfo, SESSION_TRANSFER);
509 try {
510 SomeArgs args = SomeArgs.obtain();
511 args.arg1 = callId;
512 args.arg2 = number;
513 args.argi1 = isConfirmationRequired ? 1 : 0;
514 args.arg3 = Log.createSubsession();
515 mHandler.obtainMessage(MSG_EXPLICIT_CALL_TRANSFER, args).sendToTarget();
516 } finally {
517 Log.endSession();
518 }
519 }
520
521 @Override
522 public void consultativeTransfer(@NonNull String callId, @NonNull String otherCallId,
523 Session.Info sessionInfo) {
524 Log.startSession(sessionInfo, SESSION_CONSULTATIVE_TRANSFER);
525 try {
526 SomeArgs args = SomeArgs.obtain();
527 args.arg1 = callId;
528 args.arg2 = otherCallId;
529 args.arg3 = Log.createSubsession();
530 mHandler.obtainMessage(
531 MSG_EXPLICIT_CALL_TRANSFER_CONSULTATIVE, args).sendToTarget();
532 } finally {
533 Log.endSession();
534 }
535 }
536
537 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700538 public void silence(String callId, Session.Info sessionInfo) {
539 Log.startSession(sessionInfo, SESSION_SILENCE);
540 try {
541 SomeArgs args = SomeArgs.obtain();
542 args.arg1 = callId;
543 args.arg2 = Log.createSubsession();
544 mHandler.obtainMessage(MSG_SILENCE, args).sendToTarget();
545 } finally {
546 Log.endSession();
547 }
Bryce Leecac50772015-11-17 15:13:29 -0800548 }
549
550 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700551 public void disconnect(String callId, Session.Info sessionInfo) {
552 Log.startSession(sessionInfo, SESSION_DISCONNECT);
553 try {
554 SomeArgs args = SomeArgs.obtain();
555 args.arg1 = callId;
556 args.arg2 = Log.createSubsession();
557 mHandler.obtainMessage(MSG_DISCONNECT, args).sendToTarget();
558 } finally {
559 Log.endSession();
560 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700561 }
562
563 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700564 public void hold(String callId, Session.Info sessionInfo) {
565 Log.startSession(sessionInfo, SESSION_HOLD);
566 try {
567 SomeArgs args = SomeArgs.obtain();
568 args.arg1 = callId;
569 args.arg2 = Log.createSubsession();
570 mHandler.obtainMessage(MSG_HOLD, args).sendToTarget();
571 } finally {
572 Log.endSession();
573 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700574 }
575
576 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700577 public void unhold(String callId, Session.Info sessionInfo) {
578 Log.startSession(sessionInfo, SESSION_UNHOLD);
579 try {
580 SomeArgs args = SomeArgs.obtain();
581 args.arg1 = callId;
582 args.arg2 = Log.createSubsession();
583 mHandler.obtainMessage(MSG_UNHOLD, args).sendToTarget();
584 } finally {
585 Log.endSession();
586 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700587 }
588
589 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700590 public void onCallAudioStateChanged(String callId, CallAudioState callAudioState,
591 Session.Info sessionInfo) {
592 Log.startSession(sessionInfo, SESSION_CALL_AUDIO_SC);
593 try {
594 SomeArgs args = SomeArgs.obtain();
595 args.arg1 = callId;
596 args.arg2 = callAudioState;
597 args.arg3 = Log.createSubsession();
598 mHandler.obtainMessage(MSG_ON_CALL_AUDIO_STATE_CHANGED, args).sendToTarget();
599 } finally {
600 Log.endSession();
601 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700602 }
603
604 @Override
Junhoedf3d822022-11-24 09:26:37 +0000605 public void onCallEndpointChanged(String callId, CallEndpoint callEndpoint,
606 Session.Info sessionInfo) {
607 Log.startSession(sessionInfo, SESSION_CALL_ENDPOINT_CHANGED);
608 try {
609 SomeArgs args = SomeArgs.obtain();
610 args.arg1 = callId;
611 args.arg2 = callEndpoint;
612 args.arg3 = Log.createSubsession();
613 mHandler.obtainMessage(MSG_ON_CALL_ENDPOINT_CHANGED, args).sendToTarget();
614 } finally {
615 Log.endSession();
616 }
617 }
618
619 @Override
620 public void onAvailableCallEndpointsChanged(String callId,
621 List<CallEndpoint> availableCallEndpoints, Session.Info sessionInfo) {
622 Log.startSession(sessionInfo, SESSION_AVAILABLE_CALL_ENDPOINTS_CHANGED);
623 try {
624 SomeArgs args = SomeArgs.obtain();
625 args.arg1 = callId;
626 args.arg2 = availableCallEndpoints;
627 args.arg3 = Log.createSubsession();
628 mHandler.obtainMessage(MSG_ON_AVAILABLE_CALL_ENDPOINTS_CHANGED, args)
629 .sendToTarget();
630 } finally {
631 Log.endSession();
632 }
633 }
634
635 @Override
636 public void onMuteStateChanged(String callId, boolean isMuted, Session.Info sessionInfo) {
637 Log.startSession(sessionInfo, SESSION_MUTE_STATE_CHANGED);
638 try {
639 SomeArgs args = SomeArgs.obtain();
640 args.arg1 = callId;
641 args.arg2 = isMuted;
642 args.arg3 = Log.createSubsession();
643 mHandler.obtainMessage(MSG_ON_MUTE_STATE_CHANGED, args).sendToTarget();
644 } finally {
645 Log.endSession();
646 }
647 }
648
649 @Override
Grace Jiae99fde92021-01-19 14:58:01 -0800650 public void onUsingAlternativeUi(String callId, boolean usingAlternativeUiShowing,
651 Session.Info sessionInfo) {
652 Log.startSession(sessionInfo, SESSION_USING_ALTERNATIVE_UI);
653 try {
654 SomeArgs args = SomeArgs.obtain();
655 args.arg1 = callId;
656 args.arg2 = usingAlternativeUiShowing;
657 args.arg3 = Log.createSubsession();
658 mHandler.obtainMessage(MSG_ON_USING_ALTERNATIVE_UI, args).sendToTarget();
659 } finally {
660 Log.endSession();
661 }
662 }
663
664 @Override
665 public void onTrackedByNonUiService(String callId, boolean isTracked,
666 Session.Info sessionInfo) {
667 Log.startSession(sessionInfo, SESSION_TRACKED_BY_NON_UI_SERVICE);
668 try {
669 SomeArgs args = SomeArgs.obtain();
670 args.arg1 = callId;
671 args.arg2 = isTracked;
672 args.arg3 = Log.createSubsession();
673 mHandler.obtainMessage(MSG_ON_TRACKED_BY_NON_UI_SERVICE, args).sendToTarget();
674 } finally {
675 Log.endSession();
676 }
677 }
678
679 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700680 public void playDtmfTone(String callId, char digit, Session.Info sessionInfo) {
681 Log.startSession(sessionInfo, SESSION_PLAY_DTMF);
682 try {
683 SomeArgs args = SomeArgs.obtain();
684 args.arg1 = digit;
685 args.arg2 = callId;
686 args.arg3 = Log.createSubsession();
687 mHandler.obtainMessage(MSG_PLAY_DTMF_TONE, args).sendToTarget();
688 } finally {
689 Log.endSession();
690 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700691 }
692
693 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700694 public void stopDtmfTone(String callId, Session.Info sessionInfo) {
695 Log.startSession(sessionInfo, SESSION_STOP_DTMF);
696 try {
697 SomeArgs args = SomeArgs.obtain();
698 args.arg1 = callId;
699 args.arg2 = Log.createSubsession();
700 mHandler.obtainMessage(MSG_STOP_DTMF_TONE, args).sendToTarget();
701 } finally {
702 Log.endSession();
703 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700704 }
705
706 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700707 public void conference(String callId1, String callId2, Session.Info sessionInfo) {
708 Log.startSession(sessionInfo, SESSION_CONFERENCE);
709 try {
710 SomeArgs args = SomeArgs.obtain();
711 args.arg1 = callId1;
712 args.arg2 = callId2;
713 args.arg3 = Log.createSubsession();
714 mHandler.obtainMessage(MSG_CONFERENCE, args).sendToTarget();
715 } finally {
716 Log.endSession();
717 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700718 }
719
720 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700721 public void splitFromConference(String callId, Session.Info sessionInfo) {
722 Log.startSession(sessionInfo, SESSION_SPLIT_CONFERENCE);
723 try {
724 SomeArgs args = SomeArgs.obtain();
725 args.arg1 = callId;
726 args.arg2 = Log.createSubsession();
727 mHandler.obtainMessage(MSG_SPLIT_FROM_CONFERENCE, args).sendToTarget();
728 } finally {
729 Log.endSession();
730 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700731 }
732
733 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700734 public void mergeConference(String callId, Session.Info sessionInfo) {
735 Log.startSession(sessionInfo, SESSION_MERGE_CONFERENCE);
736 try {
737 SomeArgs args = SomeArgs.obtain();
738 args.arg1 = callId;
739 args.arg2 = Log.createSubsession();
740 mHandler.obtainMessage(MSG_MERGE_CONFERENCE, args).sendToTarget();
741 } finally {
742 Log.endSession();
743 }
Santos Cordona4868042014-09-04 17:39:22 -0700744 }
745
746 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700747 public void swapConference(String callId, Session.Info sessionInfo) {
748 Log.startSession(sessionInfo, SESSION_SWAP_CONFERENCE);
749 try {
750 SomeArgs args = SomeArgs.obtain();
751 args.arg1 = callId;
752 args.arg2 = Log.createSubsession();
753 mHandler.obtainMessage(MSG_SWAP_CONFERENCE, args).sendToTarget();
754 } finally {
755 Log.endSession();
756 }
Santos Cordona4868042014-09-04 17:39:22 -0700757 }
758
759 @Override
Ravi Paluri404babb2020-01-23 19:02:44 +0530760 public void addConferenceParticipants(String callId, List<Uri> participants,
761 Session.Info sessionInfo) {
762 Log.startSession(sessionInfo, SESSION_ADD_PARTICIPANT);
763 try {
764 SomeArgs args = SomeArgs.obtain();
765 args.arg1 = callId;
766 args.arg2 = participants;
767 args.arg3 = Log.createSubsession();
768 mHandler.obtainMessage(MSG_ADD_PARTICIPANT, args).sendToTarget();
769 } finally {
770 Log.endSession();
771 }
772 }
773
774 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700775 public void onPostDialContinue(String callId, boolean proceed, Session.Info sessionInfo) {
776 Log.startSession(sessionInfo, SESSION_POST_DIAL_CONT);
777 try {
778 SomeArgs args = SomeArgs.obtain();
779 args.arg1 = callId;
780 args.arg2 = Log.createSubsession();
781 args.argi1 = proceed ? 1 : 0;
782 mHandler.obtainMessage(MSG_ON_POST_DIAL_CONTINUE, args).sendToTarget();
783 } finally {
784 Log.endSession();
785 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700786 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700787
788 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700789 public void pullExternalCall(String callId, Session.Info sessionInfo) {
790 Log.startSession(sessionInfo, SESSION_PULL_EXTERNAL_CALL);
791 try {
792 SomeArgs args = SomeArgs.obtain();
793 args.arg1 = callId;
794 args.arg2 = Log.createSubsession();
795 mHandler.obtainMessage(MSG_PULL_EXTERNAL_CALL, args).sendToTarget();
796 } finally {
797 Log.endSession();
798 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700799 }
800
801 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700802 public void sendCallEvent(String callId, String event, Bundle extras,
803 Session.Info sessionInfo) {
804 Log.startSession(sessionInfo, SESSION_SEND_CALL_EVENT);
805 try {
806 SomeArgs args = SomeArgs.obtain();
807 args.arg1 = callId;
808 args.arg2 = event;
809 args.arg3 = extras;
810 args.arg4 = Log.createSubsession();
811 mHandler.obtainMessage(MSG_SEND_CALL_EVENT, args).sendToTarget();
812 } finally {
813 Log.endSession();
814 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700815 }
Tyler Gunndee56a82016-03-23 16:06:34 -0700816
817 @Override
Hall Liu73903142021-02-18 18:41:41 -0800818 public void onCallFilteringCompleted(String callId,
819 Connection.CallFilteringCompletionInfo completionInfo,
Hall Liu49cabcc2021-01-15 11:41:48 -0800820 Session.Info sessionInfo) {
821 Log.startSession(sessionInfo, SESSION_CALL_FILTERING_COMPLETED);
822 try {
823 SomeArgs args = SomeArgs.obtain();
824 args.arg1 = callId;
Hall Liu73903142021-02-18 18:41:41 -0800825 args.arg2 = completionInfo;
826 args.arg3 = Log.createSubsession();
Hall Liu49cabcc2021-01-15 11:41:48 -0800827 mHandler.obtainMessage(MSG_ON_CALL_FILTERING_COMPLETED, args).sendToTarget();
828 } finally {
829 Log.endSession();
830 }
831 }
832
833 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700834 public void onExtrasChanged(String callId, Bundle extras, Session.Info sessionInfo) {
835 Log.startSession(sessionInfo, SESSION_EXTRAS_CHANGED);
836 try {
837 SomeArgs args = SomeArgs.obtain();
838 args.arg1 = callId;
839 args.arg2 = extras;
840 args.arg3 = Log.createSubsession();
841 mHandler.obtainMessage(MSG_ON_EXTRAS_CHANGED, args).sendToTarget();
842 } finally {
843 Log.endSession();
844 }
Tyler Gunndee56a82016-03-23 16:06:34 -0700845 }
Hall Liub64ac4c2017-02-06 10:49:48 -0800846
847 @Override
848 public void startRtt(String callId, ParcelFileDescriptor fromInCall,
849 ParcelFileDescriptor toInCall, Session.Info sessionInfo) throws RemoteException {
850 Log.startSession(sessionInfo, SESSION_START_RTT);
851 try {
852 SomeArgs args = SomeArgs.obtain();
853 args.arg1 = callId;
854 args.arg2 = new Connection.RttTextStream(toInCall, fromInCall);
855 args.arg3 = Log.createSubsession();
856 mHandler.obtainMessage(MSG_ON_START_RTT, args).sendToTarget();
857 } finally {
858 Log.endSession();
859 }
860 }
861
862 @Override
863 public void stopRtt(String callId, Session.Info sessionInfo) throws RemoteException {
864 Log.startSession(sessionInfo, SESSION_STOP_RTT);
865 try {
866 SomeArgs args = SomeArgs.obtain();
867 args.arg1 = callId;
868 args.arg2 = Log.createSubsession();
869 mHandler.obtainMessage(MSG_ON_STOP_RTT, args).sendToTarget();
870 } finally {
871 Log.endSession();
872 }
873 }
874
875 @Override
876 public void respondToRttUpgradeRequest(String callId, ParcelFileDescriptor fromInCall,
877 ParcelFileDescriptor toInCall, Session.Info sessionInfo) throws RemoteException {
878 Log.startSession(sessionInfo, SESSION_RTT_UPGRADE_RESPONSE);
879 try {
880 SomeArgs args = SomeArgs.obtain();
881 args.arg1 = callId;
882 if (toInCall == null || fromInCall == null) {
883 args.arg2 = null;
884 } else {
885 args.arg2 = new Connection.RttTextStream(toInCall, fromInCall);
886 }
887 args.arg3 = Log.createSubsession();
888 mHandler.obtainMessage(MSG_RTT_UPGRADE_RESPONSE, args).sendToTarget();
889 } finally {
890 Log.endSession();
891 }
892 }
Pengquan Meng731c1a32017-11-21 18:01:13 -0800893
894 @Override
895 public void connectionServiceFocusLost(Session.Info sessionInfo) throws RemoteException {
896 Log.startSession(sessionInfo, SESSION_CONNECTION_SERVICE_FOCUS_LOST);
897 try {
898 mHandler.obtainMessage(MSG_CONNECTION_SERVICE_FOCUS_LOST).sendToTarget();
899 } finally {
900 Log.endSession();
901 }
902 }
903
904 @Override
905 public void connectionServiceFocusGained(Session.Info sessionInfo) throws RemoteException {
906 Log.startSession(sessionInfo, SESSION_CONNECTION_SERVICE_FOCUS_GAINED);
907 try {
908 mHandler.obtainMessage(MSG_CONNECTION_SERVICE_FOCUS_GAINED).sendToTarget();
909 } finally {
910 Log.endSession();
911 }
912 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700913 };
914
915 private final Handler mHandler = new Handler(Looper.getMainLooper()) {
916 @Override
917 public void handleMessage(Message msg) {
918 switch (msg.what) {
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700919 case MSG_ADD_CONNECTION_SERVICE_ADAPTER: {
920 SomeArgs args = (SomeArgs) msg.obj;
921 try {
922 IConnectionServiceAdapter adapter = (IConnectionServiceAdapter) args.arg1;
923 Log.continueSession((Session) args.arg2,
924 SESSION_HANDLER + SESSION_ADD_CS_ADAPTER);
925 mAdapter.addAdapter(adapter);
926 onAdapterAttached();
927 } finally {
928 args.recycle();
929 Log.endSession();
930 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700931 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700932 }
933 case MSG_REMOVE_CONNECTION_SERVICE_ADAPTER: {
934 SomeArgs args = (SomeArgs) msg.obj;
935 try {
936 Log.continueSession((Session) args.arg2,
937 SESSION_HANDLER + SESSION_REMOVE_CS_ADAPTER);
938 mAdapter.removeAdapter((IConnectionServiceAdapter) args.arg1);
939 } finally {
940 args.recycle();
941 Log.endSession();
942 }
Ihab Awad8aecfed2014-08-08 17:06:11 -0700943 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700944 }
Ihab Awadf8b69882014-07-25 15:14:01 -0700945 case MSG_CREATE_CONNECTION: {
946 SomeArgs args = (SomeArgs) msg.obj;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700947 Log.continueSession((Session) args.arg4, SESSION_HANDLER + SESSION_CREATE_CONN);
Ihab Awadf8b69882014-07-25 15:14:01 -0700948 try {
Ihab Awad5d0410f2014-07-30 10:07:40 -0700949 final PhoneAccountHandle connectionManagerPhoneAccount =
Ihab Awadf8b69882014-07-25 15:14:01 -0700950 (PhoneAccountHandle) args.arg1;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700951 final String id = (String) args.arg2;
952 final ConnectionRequest request = (ConnectionRequest) args.arg3;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700953 final boolean isIncoming = args.argi1 == 1;
Yorke Leec3cf9822014-10-02 09:38:39 -0700954 final boolean isUnknown = args.argi2 == 1;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700955 if (!mAreAccountsInitialized) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700956 Log.d(this, "Enqueueing pre-init request %s", id);
Brad Ebinger0c3541b2016-11-01 14:11:38 -0700957 mPreInitializationConnectionRequests.add(
958 new android.telecom.Logging.Runnable(
959 SESSION_HANDLER + SESSION_CREATE_CONN + ".pICR",
960 null /*lock*/) {
Ihab Awad5d0410f2014-07-30 10:07:40 -0700961 @Override
Brad Ebinger0c3541b2016-11-01 14:11:38 -0700962 public void loggedRun() {
Ihab Awad5d0410f2014-07-30 10:07:40 -0700963 createConnection(
964 connectionManagerPhoneAccount,
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700965 id,
Ihab Awad5d0410f2014-07-30 10:07:40 -0700966 request,
Yorke Leec3cf9822014-10-02 09:38:39 -0700967 isIncoming,
968 isUnknown);
Ihab Awad5d0410f2014-07-30 10:07:40 -0700969 }
Brad Ebinger0c3541b2016-11-01 14:11:38 -0700970 }.prepare());
Ihab Awad5d0410f2014-07-30 10:07:40 -0700971 } else {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700972 createConnection(
973 connectionManagerPhoneAccount,
974 id,
975 request,
Yorke Leec3cf9822014-10-02 09:38:39 -0700976 isIncoming,
977 isUnknown);
Ihab Awad5d0410f2014-07-30 10:07:40 -0700978 }
Ihab Awadf8b69882014-07-25 15:14:01 -0700979 } finally {
980 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700981 Log.endSession();
Ihab Awadf8b69882014-07-25 15:14:01 -0700982 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700983 break;
Ihab Awadf8b69882014-07-25 15:14:01 -0700984 }
Tyler Gunn041a1fe2017-05-12 10:04:49 -0700985 case MSG_CREATE_CONNECTION_COMPLETE: {
986 SomeArgs args = (SomeArgs) msg.obj;
987 Log.continueSession((Session) args.arg2,
988 SESSION_HANDLER + SESSION_CREATE_CONN_COMPLETE);
989 try {
990 final String id = (String) args.arg1;
991 if (!mAreAccountsInitialized) {
992 Log.d(this, "Enqueueing pre-init request %s", id);
993 mPreInitializationConnectionRequests.add(
994 new android.telecom.Logging.Runnable(
995 SESSION_HANDLER + SESSION_CREATE_CONN_COMPLETE
996 + ".pICR",
997 null /*lock*/) {
998 @Override
999 public void loggedRun() {
1000 notifyCreateConnectionComplete(id);
1001 }
1002 }.prepare());
1003 } else {
1004 notifyCreateConnectionComplete(id);
1005 }
1006 } finally {
1007 args.recycle();
1008 Log.endSession();
1009 }
1010 break;
1011 }
Tyler Gunn44e01912017-01-31 10:49:05 -08001012 case MSG_CREATE_CONNECTION_FAILED: {
1013 SomeArgs args = (SomeArgs) msg.obj;
1014 Log.continueSession((Session) args.arg3, SESSION_HANDLER +
1015 SESSION_CREATE_CONN_FAILED);
1016 try {
1017 final String id = (String) args.arg1;
1018 final ConnectionRequest request = (ConnectionRequest) args.arg2;
1019 final boolean isIncoming = args.argi1 == 1;
Tyler Gunn159f35c2017-03-02 09:28:37 -08001020 final PhoneAccountHandle connectionMgrPhoneAccount =
1021 (PhoneAccountHandle) args.arg4;
Tyler Gunn44e01912017-01-31 10:49:05 -08001022 if (!mAreAccountsInitialized) {
1023 Log.d(this, "Enqueueing pre-init request %s", id);
1024 mPreInitializationConnectionRequests.add(
1025 new android.telecom.Logging.Runnable(
1026 SESSION_HANDLER + SESSION_CREATE_CONN_FAILED + ".pICR",
1027 null /*lock*/) {
1028 @Override
1029 public void loggedRun() {
Tyler Gunn159f35c2017-03-02 09:28:37 -08001030 createConnectionFailed(connectionMgrPhoneAccount, id,
1031 request, isIncoming);
Tyler Gunn44e01912017-01-31 10:49:05 -08001032 }
1033 }.prepare());
1034 } else {
1035 Log.i(this, "createConnectionFailed %s", id);
Tyler Gunn159f35c2017-03-02 09:28:37 -08001036 createConnectionFailed(connectionMgrPhoneAccount, id, request,
1037 isIncoming);
Tyler Gunn44e01912017-01-31 10:49:05 -08001038 }
1039 } finally {
1040 args.recycle();
1041 Log.endSession();
1042 }
1043 break;
1044 }
Ravi Paluri80aa2142019-12-02 11:57:37 +05301045 case MSG_CREATE_CONFERENCE: {
1046 SomeArgs args = (SomeArgs) msg.obj;
1047 Log.continueSession((Session) args.arg4, SESSION_HANDLER + SESSION_CREATE_CONN);
1048 try {
1049 final PhoneAccountHandle connectionManagerPhoneAccount =
1050 (PhoneAccountHandle) args.arg1;
1051 final String id = (String) args.arg2;
1052 final ConnectionRequest request = (ConnectionRequest) args.arg3;
1053 final boolean isIncoming = args.argi1 == 1;
1054 final boolean isUnknown = args.argi2 == 1;
1055 if (!mAreAccountsInitialized) {
1056 Log.d(this, "Enqueueing pre-initconference request %s", id);
1057 mPreInitializationConnectionRequests.add(
1058 new android.telecom.Logging.Runnable(
1059 SESSION_HANDLER + SESSION_CREATE_CONF + ".pIConfR",
1060 null /*lock*/) {
1061 @Override
1062 public void loggedRun() {
1063 createConference(connectionManagerPhoneAccount,
1064 id,
1065 request,
1066 isIncoming,
1067 isUnknown);
1068 }
1069 }.prepare());
1070 } else {
1071 createConference(connectionManagerPhoneAccount,
1072 id,
1073 request,
1074 isIncoming,
1075 isUnknown);
1076 }
1077 } finally {
1078 args.recycle();
1079 Log.endSession();
1080 }
1081 break;
1082 }
1083 case MSG_CREATE_CONFERENCE_COMPLETE: {
1084 SomeArgs args = (SomeArgs) msg.obj;
1085 Log.continueSession((Session) args.arg2,
1086 SESSION_HANDLER + SESSION_CREATE_CONN_COMPLETE);
1087 try {
1088 final String id = (String) args.arg1;
1089 if (!mAreAccountsInitialized) {
1090 Log.d(this, "Enqueueing pre-init conference request %s", id);
1091 mPreInitializationConnectionRequests.add(
1092 new android.telecom.Logging.Runnable(
1093 SESSION_HANDLER + SESSION_CREATE_CONF_COMPLETE
1094 + ".pIConfR",
1095 null /*lock*/) {
1096 @Override
1097 public void loggedRun() {
1098 notifyCreateConferenceComplete(id);
1099 }
1100 }.prepare());
1101 } else {
1102 notifyCreateConferenceComplete(id);
1103 }
1104 } finally {
1105 args.recycle();
1106 Log.endSession();
1107 }
1108 break;
1109 }
1110 case MSG_CREATE_CONFERENCE_FAILED: {
1111 SomeArgs args = (SomeArgs) msg.obj;
1112 Log.continueSession((Session) args.arg3, SESSION_HANDLER +
1113 SESSION_CREATE_CONN_FAILED);
1114 try {
1115 final String id = (String) args.arg1;
1116 final ConnectionRequest request = (ConnectionRequest) args.arg2;
1117 final boolean isIncoming = args.argi1 == 1;
1118 final PhoneAccountHandle connectionMgrPhoneAccount =
1119 (PhoneAccountHandle) args.arg4;
1120 if (!mAreAccountsInitialized) {
1121 Log.d(this, "Enqueueing pre-init conference request %s", id);
1122 mPreInitializationConnectionRequests.add(
1123 new android.telecom.Logging.Runnable(
1124 SESSION_HANDLER + SESSION_CREATE_CONF_FAILED
1125 + ".pIConfR",
1126 null /*lock*/) {
1127 @Override
1128 public void loggedRun() {
1129 createConferenceFailed(connectionMgrPhoneAccount, id,
1130 request, isIncoming);
1131 }
1132 }.prepare());
1133 } else {
1134 Log.i(this, "createConferenceFailed %s", id);
1135 createConferenceFailed(connectionMgrPhoneAccount, id, request,
1136 isIncoming);
1137 }
1138 } finally {
1139 args.recycle();
1140 Log.endSession();
1141 }
1142 break;
1143 }
1144
Sanket Padawe4cc8ed52017-12-04 16:22:20 -08001145 case MSG_HANDOVER_FAILED: {
1146 SomeArgs args = (SomeArgs) msg.obj;
1147 Log.continueSession((Session) args.arg3, SESSION_HANDLER +
1148 SESSION_HANDOVER_FAILED);
1149 try {
1150 final String id = (String) args.arg1;
1151 final ConnectionRequest request = (ConnectionRequest) args.arg2;
1152 final int reason = (int) args.arg4;
1153 if (!mAreAccountsInitialized) {
1154 Log.d(this, "Enqueueing pre-init request %s", id);
1155 mPreInitializationConnectionRequests.add(
1156 new android.telecom.Logging.Runnable(
1157 SESSION_HANDLER
1158 + SESSION_HANDOVER_FAILED + ".pICR",
1159 null /*lock*/) {
1160 @Override
1161 public void loggedRun() {
1162 handoverFailed(id, request, reason);
1163 }
1164 }.prepare());
1165 } else {
1166 Log.i(this, "createConnectionFailed %s", id);
1167 handoverFailed(id, request, reason);
1168 }
1169 } finally {
1170 args.recycle();
1171 Log.endSession();
1172 }
1173 break;
1174 }
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001175 case MSG_ABORT: {
1176 SomeArgs args = (SomeArgs) msg.obj;
1177 Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_ABORT);
1178 try {
1179 abort((String) args.arg1);
1180 } finally {
1181 args.recycle();
1182 Log.endSession();
1183 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001184 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001185 }
1186 case MSG_ANSWER: {
1187 SomeArgs args = (SomeArgs) msg.obj;
1188 Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_ANSWER);
1189 try {
1190 answer((String) args.arg1);
1191 } finally {
1192 args.recycle();
1193 Log.endSession();
1194 }
Tyler Gunnbe74de02014-08-29 14:51:48 -07001195 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001196 }
Tyler Gunnbe74de02014-08-29 14:51:48 -07001197 case MSG_ANSWER_VIDEO: {
Andrew Lee8da4c3c2014-07-16 10:11:42 -07001198 SomeArgs args = (SomeArgs) msg.obj;
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001199 Log.continueSession((Session) args.arg2,
1200 SESSION_HANDLER + SESSION_ANSWER_VIDEO);
Andrew Lee8da4c3c2014-07-16 10:11:42 -07001201 try {
1202 String callId = (String) args.arg1;
Evan Charltonbf11f982014-07-20 22:06:28 -07001203 int videoState = args.argi1;
Tyler Gunnbe74de02014-08-29 14:51:48 -07001204 answerVideo(callId, videoState);
Andrew Lee8da4c3c2014-07-16 10:11:42 -07001205 } finally {
1206 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001207 Log.endSession();
Andrew Lee8da4c3c2014-07-16 10:11:42 -07001208 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001209 break;
Andrew Lee8da4c3c2014-07-16 10:11:42 -07001210 }
Pooja Jaind34698d2017-12-28 14:15:31 +05301211 case MSG_DEFLECT: {
1212 SomeArgs args = (SomeArgs) msg.obj;
1213 Log.continueSession((Session) args.arg3, SESSION_HANDLER + SESSION_DEFLECT);
1214 try {
1215 deflect((String) args.arg1, (Uri) args.arg2);
1216 } finally {
1217 args.recycle();
1218 Log.endSession();
1219 }
1220 break;
1221 }
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001222 case MSG_REJECT: {
1223 SomeArgs args = (SomeArgs) msg.obj;
1224 Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_REJECT);
1225 try {
1226 reject((String) args.arg1);
1227 } finally {
1228 args.recycle();
1229 Log.endSession();
1230 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001231 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001232 }
Tyler Gunnfacfdee2020-01-23 13:10:37 -08001233 case MSG_REJECT_WITH_REASON: {
1234 SomeArgs args = (SomeArgs) msg.obj;
1235 Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_REJECT);
1236 try {
1237 reject((String) args.arg1, args.argi1);
1238 } finally {
1239 args.recycle();
1240 Log.endSession();
1241 }
1242 break;
1243 }
Bryce Lee81901682015-08-28 16:38:02 -07001244 case MSG_REJECT_WITH_MESSAGE: {
1245 SomeArgs args = (SomeArgs) msg.obj;
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001246 Log.continueSession((Session) args.arg3,
1247 SESSION_HANDLER + SESSION_REJECT_MESSAGE);
Bryce Lee81901682015-08-28 16:38:02 -07001248 try {
1249 reject((String) args.arg1, (String) args.arg2);
1250 } finally {
1251 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001252 Log.endSession();
Bryce Lee81901682015-08-28 16:38:02 -07001253 }
1254 break;
1255 }
Ravi Palurif4b38e72020-02-05 12:35:41 +05301256 case MSG_EXPLICIT_CALL_TRANSFER: {
1257 SomeArgs args = (SomeArgs) msg.obj;
1258 Log.continueSession((Session) args.arg3, SESSION_HANDLER + SESSION_TRANSFER);
1259 try {
1260 final boolean isConfirmationRequired = args.argi1 == 1;
1261 transfer((String) args.arg1, (Uri) args.arg2, isConfirmationRequired);
1262 } finally {
1263 args.recycle();
1264 Log.endSession();
1265 }
1266 break;
1267 }
1268 case MSG_EXPLICIT_CALL_TRANSFER_CONSULTATIVE: {
1269 SomeArgs args = (SomeArgs) msg.obj;
1270 Log.continueSession(
1271 (Session) args.arg3, SESSION_HANDLER + SESSION_CONSULTATIVE_TRANSFER);
1272 try {
1273 consultativeTransfer((String) args.arg1, (String) args.arg2);
1274 } finally {
1275 args.recycle();
1276 Log.endSession();
1277 }
1278 break;
1279 }
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001280 case MSG_DISCONNECT: {
1281 SomeArgs args = (SomeArgs) msg.obj;
1282 Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_DISCONNECT);
1283 try {
1284 disconnect((String) args.arg1);
1285 } finally {
1286 args.recycle();
1287 Log.endSession();
1288 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001289 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001290 }
1291 case MSG_SILENCE: {
1292 SomeArgs args = (SomeArgs) msg.obj;
1293 Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_SILENCE);
1294 try {
1295 silence((String) args.arg1);
1296 } finally {
1297 args.recycle();
1298 Log.endSession();
1299 }
Bryce Leecac50772015-11-17 15:13:29 -08001300 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001301 }
1302 case MSG_HOLD: {
1303 SomeArgs args = (SomeArgs) msg.obj;
1304 Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_REJECT);
1305 try {
1306 hold((String) args.arg1);
1307 } finally {
1308 args.recycle();
1309 Log.endSession();
1310 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001311 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001312 }
1313 case MSG_UNHOLD: {
1314 SomeArgs args = (SomeArgs) msg.obj;
1315 Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_UNHOLD);
1316 try {
1317 unhold((String) args.arg1);
1318 } finally {
1319 args.recycle();
1320 Log.endSession();
1321 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001322 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001323 }
Yorke Lee4af59352015-05-13 14:14:54 -07001324 case MSG_ON_CALL_AUDIO_STATE_CHANGED: {
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001325 SomeArgs args = (SomeArgs) msg.obj;
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001326 Log.continueSession((Session) args.arg3,
1327 SESSION_HANDLER + SESSION_CALL_AUDIO_SC);
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001328 try {
1329 String callId = (String) args.arg1;
Yorke Lee4af59352015-05-13 14:14:54 -07001330 CallAudioState audioState = (CallAudioState) args.arg2;
1331 onCallAudioStateChanged(callId, new CallAudioState(audioState));
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001332 } finally {
1333 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001334 Log.endSession();
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001335 }
1336 break;
1337 }
Grace Jiae99fde92021-01-19 14:58:01 -08001338 case MSG_ON_USING_ALTERNATIVE_UI: {
1339 SomeArgs args = (SomeArgs) msg.obj;
1340 Log.continueSession((Session) args.arg3,
1341 SESSION_HANDLER + SESSION_USING_ALTERNATIVE_UI);
1342 try {
1343 String callId = (String) args.arg1;
1344 boolean isUsingAlternativeUi = (boolean) args.arg2;
1345 onUsingAlternativeUi(callId, isUsingAlternativeUi);
1346 } finally {
1347 args.recycle();
1348 Log.endSession();
1349 }
1350 break;
1351 }
1352 case MSG_ON_TRACKED_BY_NON_UI_SERVICE: {
1353 SomeArgs args = (SomeArgs) msg.obj;
1354 Log.continueSession((Session) args.arg3,
1355 SESSION_HANDLER + SESSION_TRACKED_BY_NON_UI_SERVICE);
1356 try {
1357 String callId = (String) args.arg1;
1358 boolean isTracked = (boolean) args.arg2;
1359 onTrackedByNonUiService(callId, isTracked);
1360 } finally {
1361 args.recycle();
1362 Log.endSession();
1363 }
1364 break;
1365 }
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001366 case MSG_PLAY_DTMF_TONE: {
1367 SomeArgs args = (SomeArgs) msg.obj;
1368 try {
1369 Log.continueSession((Session) args.arg3,
1370 SESSION_HANDLER + SESSION_PLAY_DTMF);
1371 playDtmfTone((String) args.arg2, (char) args.arg1);
1372 } finally {
1373 args.recycle();
1374 Log.endSession();
1375 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001376 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001377 }
1378 case MSG_STOP_DTMF_TONE: {
1379 SomeArgs args = (SomeArgs) msg.obj;
1380 try {
1381 Log.continueSession((Session) args.arg2,
1382 SESSION_HANDLER + SESSION_STOP_DTMF);
1383 stopDtmfTone((String) args.arg1);
1384 } finally {
1385 args.recycle();
1386 Log.endSession();
1387 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001388 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001389 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001390 case MSG_CONFERENCE: {
1391 SomeArgs args = (SomeArgs) msg.obj;
1392 try {
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001393 Log.continueSession((Session) args.arg3,
1394 SESSION_HANDLER + SESSION_CONFERENCE);
Santos Cordon823fd3c2014-08-07 18:35:18 -07001395 String callId1 = (String) args.arg1;
1396 String callId2 = (String) args.arg2;
1397 conference(callId1, callId2);
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001398 } finally {
1399 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001400 Log.endSession();
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001401 }
1402 break;
1403 }
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001404 case MSG_SPLIT_FROM_CONFERENCE: {
1405 SomeArgs args = (SomeArgs) msg.obj;
1406 try {
1407 Log.continueSession((Session) args.arg2,
1408 SESSION_HANDLER + SESSION_SPLIT_CONFERENCE);
1409 splitFromConference((String) args.arg1);
1410 } finally {
1411 args.recycle();
1412 Log.endSession();
1413 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001414 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001415 }
1416 case MSG_MERGE_CONFERENCE: {
1417 SomeArgs args = (SomeArgs) msg.obj;
1418 try {
1419 Log.continueSession((Session) args.arg2,
1420 SESSION_HANDLER + SESSION_MERGE_CONFERENCE);
1421 mergeConference((String) args.arg1);
1422 } finally {
1423 args.recycle();
1424 Log.endSession();
1425 }
Santos Cordona4868042014-09-04 17:39:22 -07001426 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001427 }
1428 case MSG_SWAP_CONFERENCE: {
1429 SomeArgs args = (SomeArgs) msg.obj;
1430 try {
1431 Log.continueSession((Session) args.arg2,
1432 SESSION_HANDLER + SESSION_SWAP_CONFERENCE);
1433 swapConference((String) args.arg1);
1434 } finally {
1435 args.recycle();
1436 Log.endSession();
1437 }
Santos Cordona4868042014-09-04 17:39:22 -07001438 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001439 }
Ravi Paluri404babb2020-01-23 19:02:44 +05301440 case MSG_ADD_PARTICIPANT: {
1441 SomeArgs args = (SomeArgs) msg.obj;
1442 try {
1443 Log.continueSession((Session) args.arg3,
1444 SESSION_HANDLER + SESSION_ADD_PARTICIPANT);
1445 addConferenceParticipants((String) args.arg1, (List<Uri>)args.arg2);
1446 } finally {
1447 args.recycle();
1448 Log.endSession();
1449 }
1450 break;
1451 }
1452
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001453 case MSG_ON_POST_DIAL_CONTINUE: {
1454 SomeArgs args = (SomeArgs) msg.obj;
1455 try {
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001456 Log.continueSession((Session) args.arg2,
1457 SESSION_HANDLER + SESSION_POST_DIAL_CONT);
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001458 String callId = (String) args.arg1;
1459 boolean proceed = (args.argi1 == 1);
1460 onPostDialContinue(callId, proceed);
1461 } finally {
1462 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001463 Log.endSession();
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001464 }
1465 break;
1466 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001467 case MSG_PULL_EXTERNAL_CALL: {
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001468 SomeArgs args = (SomeArgs) msg.obj;
1469 try {
1470 Log.continueSession((Session) args.arg2,
1471 SESSION_HANDLER + SESSION_PULL_EXTERNAL_CALL);
1472 pullExternalCall((String) args.arg1);
1473 } finally {
1474 args.recycle();
1475 Log.endSession();
1476 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001477 break;
1478 }
1479 case MSG_SEND_CALL_EVENT: {
1480 SomeArgs args = (SomeArgs) msg.obj;
1481 try {
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001482 Log.continueSession((Session) args.arg4,
1483 SESSION_HANDLER + SESSION_SEND_CALL_EVENT);
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001484 String callId = (String) args.arg1;
1485 String event = (String) args.arg2;
1486 Bundle extras = (Bundle) args.arg3;
1487 sendCallEvent(callId, event, extras);
1488 } finally {
1489 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001490 Log.endSession();
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001491 }
1492 break;
1493 }
Hall Liu49cabcc2021-01-15 11:41:48 -08001494 case MSG_ON_CALL_FILTERING_COMPLETED: {
1495 SomeArgs args = (SomeArgs) msg.obj;
1496 try {
Hall Liu73903142021-02-18 18:41:41 -08001497 Log.continueSession((Session) args.arg3,
Hall Liu49cabcc2021-01-15 11:41:48 -08001498 SESSION_HANDLER + SESSION_CALL_FILTERING_COMPLETED);
1499 String callId = (String) args.arg1;
Hall Liu73903142021-02-18 18:41:41 -08001500 Connection.CallFilteringCompletionInfo completionInfo =
1501 (Connection.CallFilteringCompletionInfo) args.arg2;
1502 onCallFilteringCompleted(callId, completionInfo);
Hall Liu49cabcc2021-01-15 11:41:48 -08001503 } finally {
1504 args.recycle();
1505 Log.endSession();
1506 }
1507 break;
1508 }
Tyler Gunn79bc1ec2018-01-22 15:17:54 -08001509 case MSG_HANDOVER_COMPLETE: {
1510 SomeArgs args = (SomeArgs) msg.obj;
1511 try {
1512 Log.continueSession((Session) args.arg2,
1513 SESSION_HANDLER + SESSION_HANDOVER_COMPLETE);
1514 String callId = (String) args.arg1;
1515 notifyHandoverComplete(callId);
1516 } finally {
1517 args.recycle();
1518 Log.endSession();
1519 }
1520 break;
1521 }
Tyler Gunndee56a82016-03-23 16:06:34 -07001522 case MSG_ON_EXTRAS_CHANGED: {
1523 SomeArgs args = (SomeArgs) msg.obj;
1524 try {
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001525 Log.continueSession((Session) args.arg3,
1526 SESSION_HANDLER + SESSION_EXTRAS_CHANGED);
Tyler Gunndee56a82016-03-23 16:06:34 -07001527 String callId = (String) args.arg1;
1528 Bundle extras = (Bundle) args.arg2;
1529 handleExtrasChanged(callId, extras);
1530 } finally {
1531 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001532 Log.endSession();
Tyler Gunndee56a82016-03-23 16:06:34 -07001533 }
1534 break;
1535 }
Hall Liub64ac4c2017-02-06 10:49:48 -08001536 case MSG_ON_START_RTT: {
1537 SomeArgs args = (SomeArgs) msg.obj;
1538 try {
1539 Log.continueSession((Session) args.arg3,
1540 SESSION_HANDLER + SESSION_START_RTT);
1541 String callId = (String) args.arg1;
1542 Connection.RttTextStream rttTextStream =
1543 (Connection.RttTextStream) args.arg2;
1544 startRtt(callId, rttTextStream);
1545 } finally {
1546 args.recycle();
1547 Log.endSession();
1548 }
1549 break;
1550 }
1551 case MSG_ON_STOP_RTT: {
1552 SomeArgs args = (SomeArgs) msg.obj;
1553 try {
1554 Log.continueSession((Session) args.arg2,
1555 SESSION_HANDLER + SESSION_STOP_RTT);
1556 String callId = (String) args.arg1;
1557 stopRtt(callId);
1558 } finally {
1559 args.recycle();
1560 Log.endSession();
1561 }
1562 break;
1563 }
1564 case MSG_RTT_UPGRADE_RESPONSE: {
1565 SomeArgs args = (SomeArgs) msg.obj;
1566 try {
1567 Log.continueSession((Session) args.arg3,
1568 SESSION_HANDLER + SESSION_RTT_UPGRADE_RESPONSE);
1569 String callId = (String) args.arg1;
1570 Connection.RttTextStream rttTextStream =
1571 (Connection.RttTextStream) args.arg2;
1572 handleRttUpgradeResponse(callId, rttTextStream);
1573 } finally {
1574 args.recycle();
1575 Log.endSession();
1576 }
1577 break;
1578 }
Pengquan Meng731c1a32017-11-21 18:01:13 -08001579 case MSG_CONNECTION_SERVICE_FOCUS_GAINED:
1580 onConnectionServiceFocusGained();
1581 break;
1582 case MSG_CONNECTION_SERVICE_FOCUS_LOST:
1583 onConnectionServiceFocusLost();
1584 break;
Junhoedf3d822022-11-24 09:26:37 +00001585 case MSG_ON_CALL_ENDPOINT_CHANGED: {
1586 SomeArgs args = (SomeArgs) msg.obj;
1587 Log.continueSession((Session) args.arg3,
1588 SESSION_HANDLER + SESSION_CALL_AUDIO_SC);
1589 try {
1590 String callId = (String) args.arg1;
1591 CallEndpoint callEndpoint = (CallEndpoint) args.arg2;
1592 onCallEndpointChanged(callId, callEndpoint);
1593 } finally {
1594 args.recycle();
1595 Log.endSession();
1596 }
1597 break;
1598 }
1599 case MSG_ON_AVAILABLE_CALL_ENDPOINTS_CHANGED: {
1600 SomeArgs args = (SomeArgs) msg.obj;
1601 Log.continueSession((Session) args.arg3,
1602 SESSION_HANDLER + SESSION_CALL_AUDIO_SC);
1603 try {
1604 String callId = (String) args.arg1;
1605 List<CallEndpoint> availableCallEndpoints = (List<CallEndpoint>) args.arg2;
1606 onAvailableCallEndpointsChanged(callId, availableCallEndpoints);
1607 } finally {
1608 args.recycle();
1609 Log.endSession();
1610 }
1611 break;
1612 }
1613 case MSG_ON_MUTE_STATE_CHANGED: {
1614 SomeArgs args = (SomeArgs) msg.obj;
1615 Log.continueSession((Session) args.arg3,
1616 SESSION_HANDLER + SESSION_CALL_AUDIO_SC);
1617 try {
1618 String callId = (String) args.arg1;
1619 boolean isMuted = (boolean) args.arg2;
1620 onMuteStateChanged(callId, isMuted);
1621 } finally {
1622 args.recycle();
1623 Log.endSession();
1624 }
1625 break;
1626 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001627 default:
1628 break;
1629 }
1630 }
1631 };
1632
Santos Cordon823fd3c2014-08-07 18:35:18 -07001633 private final Conference.Listener mConferenceListener = new Conference.Listener() {
1634 @Override
1635 public void onStateChanged(Conference conference, int oldState, int newState) {
1636 String id = mIdByConference.get(conference);
1637 switch (newState) {
Ravi Paluri80aa2142019-12-02 11:57:37 +05301638 case Connection.STATE_RINGING:
1639 mAdapter.setRinging(id);
1640 break;
1641 case Connection.STATE_DIALING:
1642 mAdapter.setDialing(id);
1643 break;
Santos Cordon823fd3c2014-08-07 18:35:18 -07001644 case Connection.STATE_ACTIVE:
1645 mAdapter.setActive(id);
1646 break;
1647 case Connection.STATE_HOLDING:
1648 mAdapter.setOnHold(id);
1649 break;
1650 case Connection.STATE_DISCONNECTED:
1651 // handled by onDisconnected
1652 break;
1653 }
1654 }
1655
1656 @Override
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001657 public void onDisconnected(Conference conference, DisconnectCause disconnectCause) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07001658 String id = mIdByConference.get(conference);
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001659 mAdapter.setDisconnected(id, disconnectCause);
Santos Cordon823fd3c2014-08-07 18:35:18 -07001660 }
1661
1662 @Override
1663 public void onConnectionAdded(Conference conference, Connection connection) {
1664 }
1665
1666 @Override
1667 public void onConnectionRemoved(Conference conference, Connection connection) {
1668 }
1669
1670 @Override
Ihab Awad50e35062014-09-30 09:17:03 -07001671 public void onConferenceableConnectionsChanged(
1672 Conference conference, List<Connection> conferenceableConnections) {
1673 mAdapter.setConferenceableConnections(
1674 mIdByConference.get(conference),
1675 createConnectionIdList(conferenceableConnections));
1676 }
1677
1678 @Override
Santos Cordon823fd3c2014-08-07 18:35:18 -07001679 public void onDestroyed(Conference conference) {
1680 removeConference(conference);
1681 }
1682
1683 @Override
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001684 public void onConnectionCapabilitiesChanged(
1685 Conference conference,
1686 int connectionCapabilities) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07001687 String id = mIdByConference.get(conference);
1688 Log.d(this, "call capabilities: conference: %s",
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001689 Connection.capabilitiesToString(connectionCapabilities));
1690 mAdapter.setConnectionCapabilities(id, connectionCapabilities);
Santos Cordon823fd3c2014-08-07 18:35:18 -07001691 }
Rekha Kumar07366812015-03-24 16:42:31 -07001692
1693 @Override
Tyler Gunn720c6642016-03-22 09:02:47 -07001694 public void onConnectionPropertiesChanged(
1695 Conference conference,
1696 int connectionProperties) {
1697 String id = mIdByConference.get(conference);
1698 Log.d(this, "call capabilities: conference: %s",
1699 Connection.propertiesToString(connectionProperties));
1700 mAdapter.setConnectionProperties(id, connectionProperties);
1701 }
1702
1703 @Override
Rekha Kumar07366812015-03-24 16:42:31 -07001704 public void onVideoStateChanged(Conference c, int videoState) {
1705 String id = mIdByConference.get(c);
1706 Log.d(this, "onVideoStateChanged set video state %d", videoState);
1707 mAdapter.setVideoState(id, videoState);
1708 }
1709
1710 @Override
1711 public void onVideoProviderChanged(Conference c, Connection.VideoProvider videoProvider) {
1712 String id = mIdByConference.get(c);
1713 Log.d(this, "onVideoProviderChanged: Connection: %s, VideoProvider: %s", c,
1714 videoProvider);
1715 mAdapter.setVideoProvider(id, videoProvider);
1716 }
Andrew Lee0f51da32015-04-16 13:11:55 -07001717
1718 @Override
Andrew Leeedc625f2015-04-14 13:38:12 -07001719 public void onStatusHintsChanged(Conference conference, StatusHints statusHints) {
1720 String id = mIdByConference.get(conference);
Tyler Gunndee56a82016-03-23 16:06:34 -07001721 if (id != null) {
1722 mAdapter.setStatusHints(id, statusHints);
1723 }
Andrew Leeedc625f2015-04-14 13:38:12 -07001724 }
Santos Cordon6b7f9552015-05-27 17:21:45 -07001725
1726 @Override
Tyler Gunndee56a82016-03-23 16:06:34 -07001727 public void onExtrasChanged(Conference c, Bundle extras) {
1728 String id = mIdByConference.get(c);
1729 if (id != null) {
1730 mAdapter.putExtras(id, extras);
1731 }
1732 }
1733
1734 @Override
1735 public void onExtrasRemoved(Conference c, List<String> keys) {
1736 String id = mIdByConference.get(c);
1737 if (id != null) {
1738 mAdapter.removeExtras(id, keys);
1739 }
Santos Cordon6b7f9552015-05-27 17:21:45 -07001740 }
Tyler Gunn68a73a42018-10-03 15:38:57 -07001741
1742 @Override
1743 public void onConferenceStateChanged(Conference c, boolean isConference) {
1744 String id = mIdByConference.get(c);
1745 if (id != null) {
1746 mAdapter.setConferenceState(id, isConference);
1747 }
1748 }
1749
1750 @Override
Brad Ebingere0c12f42020-04-08 16:25:12 -07001751 public void onCallDirectionChanged(Conference c, int direction) {
1752 String id = mIdByConference.get(c);
1753 if (id != null) {
1754 mAdapter.setCallDirection(id, direction);
1755 }
1756 }
1757
1758 @Override
Tyler Gunn68a73a42018-10-03 15:38:57 -07001759 public void onAddressChanged(Conference c, Uri newAddress, int presentation) {
1760 String id = mIdByConference.get(c);
1761 if (id != null) {
1762 mAdapter.setAddress(id, newAddress, presentation);
1763 }
1764 }
1765
1766 @Override
1767 public void onCallerDisplayNameChanged(Conference c, String callerDisplayName,
1768 int presentation) {
1769 String id = mIdByConference.get(c);
1770 if (id != null) {
1771 mAdapter.setCallerDisplayName(id, callerDisplayName, presentation);
1772 }
1773 }
Hall Liuc9bc1c62019-04-16 14:00:55 -07001774
1775 @Override
1776 public void onConnectionEvent(Conference c, String event, Bundle extras) {
1777 String id = mIdByConference.get(c);
1778 if (id != null) {
1779 mAdapter.onConnectionEvent(id, event, extras);
1780 }
1781 }
Ravi Paluri80aa2142019-12-02 11:57:37 +05301782
1783 @Override
1784 public void onRingbackRequested(Conference c, boolean ringback) {
1785 String id = mIdByConference.get(c);
1786 Log.d(this, "Adapter conference onRingback %b", ringback);
1787 mAdapter.setRingbackRequested(id, ringback);
1788 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07001789 };
1790
Ihab Awad542e0ea2014-05-16 10:22:16 -07001791 private final Connection.Listener mConnectionListener = new Connection.Listener() {
1792 @Override
1793 public void onStateChanged(Connection c, int state) {
1794 String id = mIdByConnection.get(c);
Ihab Awad42b30e12014-05-22 09:49:34 -07001795 Log.d(this, "Adapter set state %s %s", id, Connection.stateToString(state));
Ihab Awad542e0ea2014-05-16 10:22:16 -07001796 switch (state) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001797 case Connection.STATE_ACTIVE:
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001798 mAdapter.setActive(id);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001799 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001800 case Connection.STATE_DIALING:
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001801 mAdapter.setDialing(id);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001802 break;
Tyler Gunnc96b5e02016-07-07 22:53:57 -07001803 case Connection.STATE_PULLING_CALL:
1804 mAdapter.setPulling(id);
1805 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001806 case Connection.STATE_DISCONNECTED:
Ihab Awad542e0ea2014-05-16 10:22:16 -07001807 // Handled in onDisconnected()
1808 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001809 case Connection.STATE_HOLDING:
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001810 mAdapter.setOnHold(id);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001811 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001812 case Connection.STATE_NEW:
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001813 // Nothing to tell Telecom
Ihab Awad542e0ea2014-05-16 10:22:16 -07001814 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001815 case Connection.STATE_RINGING:
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001816 mAdapter.setRinging(id);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001817 break;
1818 }
1819 }
1820
1821 @Override
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001822 public void onDisconnected(Connection c, DisconnectCause disconnectCause) {
Ihab Awad542e0ea2014-05-16 10:22:16 -07001823 String id = mIdByConnection.get(c);
Andrew Lee26786392014-09-16 18:14:59 -07001824 Log.d(this, "Adapter set disconnected %s", disconnectCause);
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001825 mAdapter.setDisconnected(id, disconnectCause);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001826 }
1827
1828 @Override
Tyler Gunnaa07df82014-07-17 07:50:22 -07001829 public void onVideoStateChanged(Connection c, int videoState) {
1830 String id = mIdByConnection.get(c);
1831 Log.d(this, "Adapter set video state %d", videoState);
1832 mAdapter.setVideoState(id, videoState);
1833 }
1834
1835 @Override
Andrew Lee100e2932014-09-08 15:34:24 -07001836 public void onAddressChanged(Connection c, Uri address, int presentation) {
Sailesh Nepal61203862014-07-11 14:50:13 -07001837 String id = mIdByConnection.get(c);
Andrew Lee100e2932014-09-08 15:34:24 -07001838 mAdapter.setAddress(id, address, presentation);
Sailesh Nepal61203862014-07-11 14:50:13 -07001839 }
1840
1841 @Override
1842 public void onCallerDisplayNameChanged(
1843 Connection c, String callerDisplayName, int presentation) {
1844 String id = mIdByConnection.get(c);
1845 mAdapter.setCallerDisplayName(id, callerDisplayName, presentation);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001846 }
1847
1848 @Override
Ihab Awad542e0ea2014-05-16 10:22:16 -07001849 public void onDestroyed(Connection c) {
1850 removeConnection(c);
1851 }
Ihab Awadf8358972014-05-28 16:46:42 -07001852
1853 @Override
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001854 public void onPostDialWait(Connection c, String remaining) {
Sailesh Nepal091768c2014-06-30 15:15:23 -07001855 String id = mIdByConnection.get(c);
1856 Log.d(this, "Adapter onPostDialWait %s, %s", c, remaining);
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001857 mAdapter.onPostDialWait(id, remaining);
Sailesh Nepal091768c2014-06-30 15:15:23 -07001858 }
1859
1860 @Override
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001861 public void onPostDialChar(Connection c, char nextChar) {
1862 String id = mIdByConnection.get(c);
1863 Log.d(this, "Adapter onPostDialChar %s, %s", c, nextChar);
1864 mAdapter.onPostDialChar(id, nextChar);
1865 }
1866
1867 @Override
Andrew Lee100e2932014-09-08 15:34:24 -07001868 public void onRingbackRequested(Connection c, boolean ringback) {
Ihab Awadf8358972014-05-28 16:46:42 -07001869 String id = mIdByConnection.get(c);
1870 Log.d(this, "Adapter onRingback %b", ringback);
Andrew Lee100e2932014-09-08 15:34:24 -07001871 mAdapter.setRingbackRequested(id, ringback);
Ihab Awadf8358972014-05-28 16:46:42 -07001872 }
Santos Cordonb6939982014-06-04 20:20:58 -07001873
1874 @Override
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001875 public void onConnectionCapabilitiesChanged(Connection c, int capabilities) {
Santos Cordonb6939982014-06-04 20:20:58 -07001876 String id = mIdByConnection.get(c);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001877 Log.d(this, "capabilities: parcelableconnection: %s",
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001878 Connection.capabilitiesToString(capabilities));
1879 mAdapter.setConnectionCapabilities(id, capabilities);
Santos Cordonb6939982014-06-04 20:20:58 -07001880 }
1881
Santos Cordonb6939982014-06-04 20:20:58 -07001882 @Override
Tyler Gunn720c6642016-03-22 09:02:47 -07001883 public void onConnectionPropertiesChanged(Connection c, int properties) {
1884 String id = mIdByConnection.get(c);
1885 Log.d(this, "properties: parcelableconnection: %s",
1886 Connection.propertiesToString(properties));
1887 mAdapter.setConnectionProperties(id, properties);
1888 }
1889
1890 @Override
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001891 public void onVideoProviderChanged(Connection c, Connection.VideoProvider videoProvider) {
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07001892 String id = mIdByConnection.get(c);
Rekha Kumar07366812015-03-24 16:42:31 -07001893 Log.d(this, "onVideoProviderChanged: Connection: %s, VideoProvider: %s", c,
1894 videoProvider);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001895 mAdapter.setVideoProvider(id, videoProvider);
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07001896 }
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001897
1898 @Override
Sailesh Nepal001bbbb2014-07-15 14:40:39 -07001899 public void onAudioModeIsVoipChanged(Connection c, boolean isVoip) {
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001900 String id = mIdByConnection.get(c);
Andrew Lee100e2932014-09-08 15:34:24 -07001901 mAdapter.setIsVoipAudioMode(id, isVoip);
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001902 }
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001903
1904 @Override
Sailesh Nepal001bbbb2014-07-15 14:40:39 -07001905 public void onStatusHintsChanged(Connection c, StatusHints statusHints) {
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001906 String id = mIdByConnection.get(c);
1907 mAdapter.setStatusHints(id, statusHints);
1908 }
Sailesh Nepal2ab88cc2014-07-18 14:49:18 -07001909
1910 @Override
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001911 public void onConferenceablesChanged(
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001912 Connection connection, List<Conferenceable> conferenceables) {
Ihab Awadb8e85c72014-08-23 20:34:57 -07001913 mAdapter.setConferenceableConnections(
1914 mIdByConnection.get(connection),
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001915 createIdList(conferenceables));
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001916 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07001917
1918 @Override
1919 public void onConferenceChanged(Connection connection, Conference conference) {
1920 String id = mIdByConnection.get(connection);
1921 if (id != null) {
1922 String conferenceId = null;
1923 if (conference != null) {
1924 conferenceId = mIdByConference.get(conference);
1925 }
1926 mAdapter.setIsConferenced(id, conferenceId);
1927 }
1928 }
Anthony Lee17455a32015-04-24 15:25:29 -07001929
1930 @Override
1931 public void onConferenceMergeFailed(Connection connection) {
1932 String id = mIdByConnection.get(connection);
1933 if (id != null) {
1934 mAdapter.onConferenceMergeFailed(id);
1935 }
1936 }
Santos Cordon6b7f9552015-05-27 17:21:45 -07001937
1938 @Override
Tyler Gunndee56a82016-03-23 16:06:34 -07001939 public void onExtrasChanged(Connection c, Bundle extras) {
1940 String id = mIdByConnection.get(c);
Santos Cordon6b7f9552015-05-27 17:21:45 -07001941 if (id != null) {
Tyler Gunndee56a82016-03-23 16:06:34 -07001942 mAdapter.putExtras(id, extras);
Santos Cordon6b7f9552015-05-27 17:21:45 -07001943 }
1944 }
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001945
Tyler Gunnf5035432017-01-09 09:43:12 -08001946 @Override
Tyler Gunndee56a82016-03-23 16:06:34 -07001947 public void onExtrasRemoved(Connection c, List<String> keys) {
1948 String id = mIdByConnection.get(c);
1949 if (id != null) {
1950 mAdapter.removeExtras(id, keys);
1951 }
1952 }
1953
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08001954 @Override
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001955 public void onConnectionEvent(Connection connection, String event, Bundle extras) {
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08001956 String id = mIdByConnection.get(connection);
1957 if (id != null) {
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001958 mAdapter.onConnectionEvent(id, event, extras);
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08001959 }
1960 }
Tyler Gunnf5035432017-01-09 09:43:12 -08001961
1962 @Override
Hall Liua98f58b52017-11-07 17:59:28 -08001963 public void onAudioRouteChanged(Connection c, int audioRoute, String bluetoothAddress) {
Tyler Gunnf5035432017-01-09 09:43:12 -08001964 String id = mIdByConnection.get(c);
1965 if (id != null) {
Hall Liua98f58b52017-11-07 17:59:28 -08001966 mAdapter.setAudioRoute(id, audioRoute, bluetoothAddress);
Tyler Gunnf5035432017-01-09 09:43:12 -08001967 }
1968 }
Hall Liub64ac4c2017-02-06 10:49:48 -08001969
1970 @Override
1971 public void onRttInitiationSuccess(Connection c) {
1972 String id = mIdByConnection.get(c);
1973 if (id != null) {
1974 mAdapter.onRttInitiationSuccess(id);
1975 }
1976 }
1977
1978 @Override
1979 public void onRttInitiationFailure(Connection c, int reason) {
1980 String id = mIdByConnection.get(c);
1981 if (id != null) {
1982 mAdapter.onRttInitiationFailure(id, reason);
1983 }
1984 }
1985
1986 @Override
1987 public void onRttSessionRemotelyTerminated(Connection c) {
1988 String id = mIdByConnection.get(c);
1989 if (id != null) {
1990 mAdapter.onRttSessionRemotelyTerminated(id);
1991 }
1992 }
1993
1994 @Override
1995 public void onRemoteRttRequest(Connection c) {
1996 String id = mIdByConnection.get(c);
1997 if (id != null) {
1998 mAdapter.onRemoteRttRequest(id);
1999 }
2000 }
Srikanth Chintalafcb15012017-05-04 20:58:34 +05302001
2002 @Override
2003 public void onPhoneAccountChanged(Connection c, PhoneAccountHandle pHandle) {
2004 String id = mIdByConnection.get(c);
2005 if (id != null) {
2006 mAdapter.onPhoneAccountChanged(id, pHandle);
2007 }
2008 }
Mengjun Leng25707742017-07-04 11:10:37 +08002009
2010 public void onConnectionTimeReset(Connection c) {
2011 String id = mIdByConnection.get(c);
2012 if (id != null) {
2013 mAdapter.resetConnectionTime(id);
2014 }
2015 }
Junhoedf3d822022-11-24 09:26:37 +00002016
2017 @Override
2018 public void onEndpointChanged(Connection c, CallEndpoint endpoint, Executor executor,
2019 OutcomeReceiver<Void, CallEndpointException> callback) {
2020 String id = mIdByConnection.get(c);
2021 if (id != null) {
2022 mAdapter.requestCallEndpointChange(id, endpoint, executor, callback);
2023 }
2024 }
yongnamcha8ec56242022-11-28 06:23:02 +00002025
2026 @Override
2027 public void onQueryLocation(Connection c, long timeoutMillis, @NonNull String provider,
2028 @NonNull @CallbackExecutor Executor executor,
2029 @NonNull OutcomeReceiver<Location, QueryLocationException> callback) {
2030 String id = mIdByConnection.get(c);
2031 if (id != null) {
2032 mAdapter.queryLocation(id, timeoutMillis, provider, executor, callback);
2033 }
2034 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002035 };
2036
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002037 /** {@inheritDoc} */
Ihab Awad542e0ea2014-05-16 10:22:16 -07002038 @Override
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002039 public final IBinder onBind(Intent intent) {
Hall Liueb7c9ea2021-03-09 20:24:50 -08002040 onBindClient(intent);
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002041 return mBinder;
2042 }
2043
Santos Cordon29f2f2e2014-09-11 19:50:24 -07002044 /** {@inheritDoc} */
2045 @Override
2046 public boolean onUnbind(Intent intent) {
2047 endAllConnections();
2048 return super.onUnbind(intent);
2049 }
2050
Hall Liueb7c9ea2021-03-09 20:24:50 -08002051 /**
2052 * Used for testing to let the test suite know when the connection service has been bound.
2053 * @hide
2054 */
2055 @TestApi
2056 public void onBindClient(@Nullable Intent intent) {
2057 }
Ravi Paluri80aa2142019-12-02 11:57:37 +05302058
2059 /**
2060 * This can be used by telecom to either create a new outgoing conference call or attach
2061 * to an existing incoming conference call. In either case, telecom will cycle through a
2062 * set of services and call createConference until a connection service cancels the process
2063 * or completes it successfully.
2064 */
2065 private void createConference(
2066 final PhoneAccountHandle callManagerAccount,
2067 final String callId,
2068 final ConnectionRequest request,
2069 boolean isIncoming,
2070 boolean isUnknown) {
2071
2072 Conference conference = null;
2073 conference = isIncoming ? onCreateIncomingConference(callManagerAccount, request)
2074 : onCreateOutgoingConference(callManagerAccount, request);
2075
2076 Log.d(this, "createConference, conference: %s", conference);
2077 if (conference == null) {
2078 Log.i(this, "createConference, implementation returned null conference.");
2079 conference = Conference.createFailedConference(
2080 new DisconnectCause(DisconnectCause.ERROR, "IMPL_RETURNED_NULL_CONFERENCE"),
2081 request.getAccountHandle());
2082 }
Tyler Gunnc59fd0c2020-04-17 14:03:35 -07002083
2084 Bundle extras = request.getExtras();
2085 Bundle newExtras = new Bundle();
2086 newExtras.putString(Connection.EXTRA_ORIGINAL_CONNECTION_ID, callId);
2087 if (extras != null) {
2088 // If the request originated from a remote connection service, we will add some
2089 // tracking information that Telecom can use to keep informed of which package
2090 // made the remote request, and which remote connection service was used.
2091 if (extras.containsKey(Connection.EXTRA_REMOTE_CONNECTION_ORIGINATING_PACKAGE_NAME)) {
2092 newExtras.putString(
2093 Connection.EXTRA_REMOTE_CONNECTION_ORIGINATING_PACKAGE_NAME,
2094 extras.getString(
2095 Connection.EXTRA_REMOTE_CONNECTION_ORIGINATING_PACKAGE_NAME));
2096 newExtras.putParcelable(Connection.EXTRA_REMOTE_PHONE_ACCOUNT_HANDLE,
2097 request.getAccountHandle());
2098 }
Ravi Paluri80aa2142019-12-02 11:57:37 +05302099 }
Tyler Gunnc59fd0c2020-04-17 14:03:35 -07002100 conference.putExtras(newExtras);
2101
Ravi Paluri80aa2142019-12-02 11:57:37 +05302102 mConferenceById.put(callId, conference);
2103 mIdByConference.put(conference, callId);
Tyler Gunn460360d2020-07-29 10:21:45 -07002104
Ravi Paluri80aa2142019-12-02 11:57:37 +05302105 conference.addListener(mConferenceListener);
Brad Ebinger0ae44ed2020-04-09 15:30:57 -07002106 ParcelableConference parcelableConference = new ParcelableConference.Builder(
2107 request.getAccountHandle(), conference.getState())
2108 .setConnectionCapabilities(conference.getConnectionCapabilities())
2109 .setConnectionProperties(conference.getConnectionProperties())
2110 .setVideoAttributes(conference.getVideoProvider() == null
2111 ? null : conference.getVideoProvider().getInterface(),
2112 conference.getVideoState())
2113 .setConnectTimeMillis(conference.getConnectTimeMillis(),
2114 conference.getConnectionStartElapsedRealtimeMillis())
2115 .setStatusHints(conference.getStatusHints())
2116 .setExtras(conference.getExtras())
2117 .setAddress(conference.getAddress(), conference.getAddressPresentation())
2118 .setCallerDisplayName(conference.getCallerDisplayName(),
2119 conference.getCallerDisplayNamePresentation())
2120 .setDisconnectCause(conference.getDisconnectCause())
2121 .setRingbackRequested(conference.isRingbackRequested())
2122 .build();
Ravi Paluri80aa2142019-12-02 11:57:37 +05302123 if (conference.getState() != Connection.STATE_DISCONNECTED) {
2124 conference.setTelecomCallId(callId);
2125 mAdapter.setVideoProvider(callId, conference.getVideoProvider());
2126 mAdapter.setVideoState(callId, conference.getVideoState());
2127 onConferenceAdded(conference);
2128 }
2129
2130 Log.d(this, "createConference, calling handleCreateConferenceSuccessful %s", callId);
2131 mAdapter.handleCreateConferenceComplete(
2132 callId,
2133 request,
2134 parcelableConference);
2135 }
2136
Sailesh Nepalc5b01572014-07-14 16:29:44 -07002137 /**
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002138 * This can be used by telecom to either create a new outgoing call or attach to an existing
2139 * incoming call. In either case, telecom will cycle through a set of services and call
Sailesh Nepalc5b01572014-07-14 16:29:44 -07002140 * createConnection util a connection service cancels the process or completes it successfully.
2141 */
Ihab Awadf8b69882014-07-25 15:14:01 -07002142 private void createConnection(
2143 final PhoneAccountHandle callManagerAccount,
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002144 final String callId,
Ihab Awadf8b69882014-07-25 15:14:01 -07002145 final ConnectionRequest request,
Yorke Leec3cf9822014-10-02 09:38:39 -07002146 boolean isIncoming,
2147 boolean isUnknown) {
Tyler Gunn79bc1ec2018-01-22 15:17:54 -08002148 boolean isLegacyHandover = request.getExtras() != null &&
2149 request.getExtras().getBoolean(TelecomManager.EXTRA_IS_HANDOVER, false);
2150 boolean isHandover = request.getExtras() != null && request.getExtras().getBoolean(
2151 TelecomManager.EXTRA_IS_HANDOVER_CONNECTION, false);
Grace Jiae99fde92021-01-19 14:58:01 -08002152 boolean addSelfManaged = request.getExtras() != null && request.getExtras().getBoolean(
Grace Jia8b22bb42021-02-02 15:37:32 -08002153 PhoneAccount.EXTRA_ADD_SELF_MANAGED_CALLS_TO_INCALLSERVICE, true);
Grace Jiae99fde92021-01-19 14:58:01 -08002154 Log.i(this, "createConnection, callManagerAccount: %s, callId: %s, request: %s, "
2155 + "isIncoming: %b, isUnknown: %b, isLegacyHandover: %b, isHandover: %b, "
2156 + " addSelfManaged: %b", callManagerAccount, callId, request, isIncoming,
2157 isUnknown, isLegacyHandover, isHandover, addSelfManaged);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002158
Sanket Padawee29a2662017-12-01 13:59:27 -08002159 Connection connection = null;
Tyler Gunn79bc1ec2018-01-22 15:17:54 -08002160 if (isHandover) {
2161 PhoneAccountHandle fromPhoneAccountHandle = request.getExtras() != null
2162 ? (PhoneAccountHandle) request.getExtras().getParcelable(
Hani Kazmi4f221e52022-06-20 09:38:26 +00002163 TelecomManager.EXTRA_HANDOVER_FROM_PHONE_ACCOUNT, android.telecom.PhoneAccountHandle.class) : null;
Sanket Padawee29a2662017-12-01 13:59:27 -08002164 if (!isIncoming) {
Tyler Gunn79bc1ec2018-01-22 15:17:54 -08002165 connection = onCreateOutgoingHandoverConnection(fromPhoneAccountHandle, request);
Sanket Padawee29a2662017-12-01 13:59:27 -08002166 } else {
Tyler Gunn79bc1ec2018-01-22 15:17:54 -08002167 connection = onCreateIncomingHandoverConnection(fromPhoneAccountHandle, request);
Sanket Padawee29a2662017-12-01 13:59:27 -08002168 }
2169 } else {
2170 connection = isUnknown ? onCreateUnknownConnection(callManagerAccount, request)
2171 : isIncoming ? onCreateIncomingConnection(callManagerAccount, request)
2172 : onCreateOutgoingConnection(callManagerAccount, request);
2173 }
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07002174 Log.d(this, "createConnection, connection: %s", connection);
2175 if (connection == null) {
Tyler Gunnfba1a8e2017-12-19 15:23:59 -08002176 Log.i(this, "createConnection, implementation returned null connection.");
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002177 connection = Connection.createFailedConnection(
Tyler Gunnfba1a8e2017-12-19 15:23:59 -08002178 new DisconnectCause(DisconnectCause.ERROR, "IMPL_RETURNED_NULL_CONNECTION"));
Tyler Gunnc59fd0c2020-04-17 14:03:35 -07002179 } else {
2180 try {
2181 Bundle extras = request.getExtras();
2182 if (extras != null) {
2183 // If the request originated from a remote connection service, we will add some
2184 // tracking information that Telecom can use to keep informed of which package
2185 // made the remote request, and which remote connection service was used.
2186 if (extras.containsKey(
2187 Connection.EXTRA_REMOTE_CONNECTION_ORIGINATING_PACKAGE_NAME)) {
2188 Bundle newExtras = new Bundle();
2189 newExtras.putString(
2190 Connection.EXTRA_REMOTE_CONNECTION_ORIGINATING_PACKAGE_NAME,
2191 extras.getString(
2192 Connection.EXTRA_REMOTE_CONNECTION_ORIGINATING_PACKAGE_NAME
2193 ));
2194 newExtras.putParcelable(Connection.EXTRA_REMOTE_PHONE_ACCOUNT_HANDLE,
2195 request.getAccountHandle());
2196 connection.putExtras(newExtras);
2197 }
2198 }
2199 } catch (UnsupportedOperationException ose) {
2200 // Do nothing; if the ConnectionService reported a failure it will be an instance
2201 // of an immutable Connection which we cannot edit, so we're out of luck.
2202 }
Sailesh Nepalc5b01572014-07-14 16:29:44 -07002203 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002204
Tyler Gunnf2e08b42018-05-24 10:44:44 -07002205 boolean isSelfManaged =
2206 (connection.getConnectionProperties() & Connection.PROPERTY_SELF_MANAGED)
2207 == Connection.PROPERTY_SELF_MANAGED;
2208 // Self-managed Connections should always use voip audio mode; we default here so that the
2209 // local state within the ConnectionService matches the default we assume in Telecom.
2210 if (isSelfManaged) {
2211 connection.setAudioModeIsVoip(true);
2212 }
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002213 connection.setTelecomCallId(callId);
Sungjae7f4137452020-09-16 17:01:54 +09002214 PhoneAccountHandle phoneAccountHandle = connection.getPhoneAccountHandle() == null
2215 ? request.getAccountHandle() : connection.getPhoneAccountHandle();
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07002216 if (connection.getState() != Connection.STATE_DISCONNECTED) {
Sungjae7f4137452020-09-16 17:01:54 +09002217 addConnection(phoneAccountHandle, callId, connection);
Ihab Awad6107bab2014-08-18 09:23:25 -07002218 }
2219
Andrew Lee100e2932014-09-08 15:34:24 -07002220 Uri address = connection.getAddress();
2221 String number = address == null ? "null" : address.getSchemeSpecificPart();
Tyler Gunn720c6642016-03-22 09:02:47 -07002222 Log.v(this, "createConnection, number: %s, state: %s, capabilities: %s, properties: %s",
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002223 Connection.toLogSafePhoneNumber(number),
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07002224 Connection.stateToString(connection.getState()),
Tyler Gunn720c6642016-03-22 09:02:47 -07002225 Connection.capabilitiesToString(connection.getConnectionCapabilities()),
2226 Connection.propertiesToString(connection.getConnectionProperties()));
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002227
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07002228 Log.d(this, "createConnection, calling handleCreateConnectionSuccessful %s", callId);
Ihab Awad6107bab2014-08-18 09:23:25 -07002229 mAdapter.handleCreateConnectionComplete(
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002230 callId,
Evan Charltonbf11f982014-07-20 22:06:28 -07002231 request,
2232 new ParcelableConnection(
Sungjae7f4137452020-09-16 17:01:54 +09002233 phoneAccountHandle,
Evan Charltonbf11f982014-07-20 22:06:28 -07002234 connection.getState(),
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002235 connection.getConnectionCapabilities(),
Tyler Gunn720c6642016-03-22 09:02:47 -07002236 connection.getConnectionProperties(),
Christine Hallstrom2830ce92016-11-30 16:06:42 -08002237 connection.getSupportedAudioRoutes(),
Andrew Lee100e2932014-09-08 15:34:24 -07002238 connection.getAddress(),
2239 connection.getAddressPresentation(),
Evan Charltonbf11f982014-07-20 22:06:28 -07002240 connection.getCallerDisplayName(),
2241 connection.getCallerDisplayNamePresentation(),
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002242 connection.getVideoProvider() == null ?
2243 null : connection.getVideoProvider().getInterface(),
Sailesh Nepal8b9d3ca2014-08-14 17:39:34 -07002244 connection.getVideoState(),
Andrew Lee100e2932014-09-08 15:34:24 -07002245 connection.isRingbackRequested(),
Sailesh Nepal8b9d3ca2014-08-14 17:39:34 -07002246 connection.getAudioModeIsVoip(),
Roshan Piuse927ec02015-07-15 15:47:21 -07002247 connection.getConnectTimeMillis(),
Tyler Gunnc9503d62020-01-27 10:30:51 -08002248 connection.getConnectionStartElapsedRealtimeMillis(),
Ihab Awad6107bab2014-08-18 09:23:25 -07002249 connection.getStatusHints(),
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07002250 connection.getDisconnectCause(),
Santos Cordon6b7f9552015-05-27 17:21:45 -07002251 createIdList(connection.getConferenceables()),
Tyler Gunnd57d76c2019-09-24 14:53:23 -07002252 connection.getExtras(),
2253 connection.getCallerNumberVerificationStatus()));
Tyler Gunnf5035432017-01-09 09:43:12 -08002254
Tyler Gunnf2e08b42018-05-24 10:44:44 -07002255 if (isIncoming && request.shouldShowIncomingCallUi() && isSelfManaged) {
Tyler Gunnf5035432017-01-09 09:43:12 -08002256 // Tell ConnectionService to show its incoming call UX.
2257 connection.onShowIncomingCallUi();
2258 }
Shriram Ganesh6bf35ac2014-12-11 17:53:38 -08002259 if (isUnknown) {
2260 triggerConferenceRecalculate();
2261 }
Evan Charltonbf11f982014-07-20 22:06:28 -07002262 }
2263
Tyler Gunn159f35c2017-03-02 09:28:37 -08002264 private void createConnectionFailed(final PhoneAccountHandle callManagerAccount,
2265 final String callId, final ConnectionRequest request,
2266 boolean isIncoming) {
Tyler Gunn44e01912017-01-31 10:49:05 -08002267
2268 Log.i(this, "createConnectionFailed %s", callId);
2269 if (isIncoming) {
Tyler Gunn159f35c2017-03-02 09:28:37 -08002270 onCreateIncomingConnectionFailed(callManagerAccount, request);
Tyler Gunn44e01912017-01-31 10:49:05 -08002271 } else {
Tyler Gunn159f35c2017-03-02 09:28:37 -08002272 onCreateOutgoingConnectionFailed(callManagerAccount, request);
Tyler Gunn44e01912017-01-31 10:49:05 -08002273 }
2274 }
2275
Ravi Paluri80aa2142019-12-02 11:57:37 +05302276 private void createConferenceFailed(final PhoneAccountHandle callManagerAccount,
2277 final String callId, final ConnectionRequest request,
2278 boolean isIncoming) {
2279
2280 Log.i(this, "createConferenceFailed %s", callId);
2281 if (isIncoming) {
2282 onCreateIncomingConferenceFailed(callManagerAccount, request);
2283 } else {
2284 onCreateOutgoingConferenceFailed(callManagerAccount, request);
2285 }
2286 }
2287
Sanket Padawe4cc8ed52017-12-04 16:22:20 -08002288 private void handoverFailed(final String callId, final ConnectionRequest request,
2289 int reason) {
2290
2291 Log.i(this, "handoverFailed %s", callId);
2292 onHandoverFailed(request, reason);
2293 }
2294
Tyler Gunn041a1fe2017-05-12 10:04:49 -07002295 /**
2296 * Called by Telecom when the creation of a new Connection has completed and it is now added
2297 * to Telecom.
2298 * @param callId The ID of the connection.
2299 */
2300 private void notifyCreateConnectionComplete(final String callId) {
2301 Log.i(this, "notifyCreateConnectionComplete %s", callId);
Tyler Gunn0a88f2e2017-06-16 20:20:34 -07002302 if (callId == null) {
2303 // This could happen if the connection fails quickly and is removed from the
2304 // ConnectionService before Telecom sends the create connection complete callback.
2305 Log.w(this, "notifyCreateConnectionComplete: callId is null.");
2306 return;
2307 }
Tyler Gunn041a1fe2017-05-12 10:04:49 -07002308 onCreateConnectionComplete(findConnectionForAction(callId,
2309 "notifyCreateConnectionComplete"));
2310 }
2311
Ravi Paluri80aa2142019-12-02 11:57:37 +05302312 /**
2313 * Called by Telecom when the creation of a new Conference has completed and it is now added
2314 * to Telecom.
2315 * @param callId The ID of the connection.
2316 */
2317 private void notifyCreateConferenceComplete(final String callId) {
2318 Log.i(this, "notifyCreateConferenceComplete %s", callId);
2319 if (callId == null) {
2320 // This could happen if the conference fails quickly and is removed from the
2321 // ConnectionService before Telecom sends the create conference complete callback.
2322 Log.w(this, "notifyCreateConferenceComplete: callId is null.");
2323 return;
2324 }
2325 onCreateConferenceComplete(findConferenceForAction(callId,
2326 "notifyCreateConferenceComplete"));
2327 }
2328
2329
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002330 private void abort(String callId) {
Tyler Gunnffbcd892020-05-04 15:01:59 -07002331 Log.i(this, "abort %s", callId);
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002332 findConnectionForAction(callId, "abort").onAbort();
Ihab Awad542e0ea2014-05-16 10:22:16 -07002333 }
2334
Tyler Gunnbe74de02014-08-29 14:51:48 -07002335 private void answerVideo(String callId, int videoState) {
Tyler Gunnffbcd892020-05-04 15:01:59 -07002336 Log.i(this, "answerVideo %s", callId);
Ravi Paluri80aa2142019-12-02 11:57:37 +05302337 if (mConnectionById.containsKey(callId)) {
2338 findConnectionForAction(callId, "answer").onAnswer(videoState);
2339 } else {
2340 findConferenceForAction(callId, "answer").onAnswer(videoState);
2341 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002342 }
2343
Tyler Gunnbe74de02014-08-29 14:51:48 -07002344 private void answer(String callId) {
Tyler Gunnffbcd892020-05-04 15:01:59 -07002345 Log.i(this, "answer %s", callId);
Ravi Paluri80aa2142019-12-02 11:57:37 +05302346 if (mConnectionById.containsKey(callId)) {
2347 findConnectionForAction(callId, "answer").onAnswer();
2348 } else {
2349 findConferenceForAction(callId, "answer").onAnswer();
2350 }
Tyler Gunnbe74de02014-08-29 14:51:48 -07002351 }
2352
Pooja Jaind34698d2017-12-28 14:15:31 +05302353 private void deflect(String callId, Uri address) {
Tyler Gunnffbcd892020-05-04 15:01:59 -07002354 Log.i(this, "deflect %s", callId);
Pooja Jaind34698d2017-12-28 14:15:31 +05302355 findConnectionForAction(callId, "deflect").onDeflect(address);
2356 }
2357
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002358 private void reject(String callId) {
Tyler Gunnffbcd892020-05-04 15:01:59 -07002359 Log.i(this, "reject %s", callId);
Ravi Paluri80aa2142019-12-02 11:57:37 +05302360 if (mConnectionById.containsKey(callId)) {
2361 findConnectionForAction(callId, "reject").onReject();
2362 } else {
2363 findConferenceForAction(callId, "reject").onReject();
2364 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002365 }
2366
Bryce Lee81901682015-08-28 16:38:02 -07002367 private void reject(String callId, String rejectWithMessage) {
Tyler Gunnffbcd892020-05-04 15:01:59 -07002368 Log.i(this, "reject %s with message", callId);
Bryce Lee81901682015-08-28 16:38:02 -07002369 findConnectionForAction(callId, "reject").onReject(rejectWithMessage);
2370 }
2371
Tyler Gunnfacfdee2020-01-23 13:10:37 -08002372 private void reject(String callId, @android.telecom.Call.RejectReason int rejectReason) {
Tyler Gunnffbcd892020-05-04 15:01:59 -07002373 Log.i(this, "reject %s with reason %d", callId, rejectReason);
Tyler Gunnfacfdee2020-01-23 13:10:37 -08002374 findConnectionForAction(callId, "reject").onReject(rejectReason);
2375 }
2376
Ravi Palurif4b38e72020-02-05 12:35:41 +05302377 private void transfer(String callId, Uri number, boolean isConfirmationRequired) {
Tyler Gunnffbcd892020-05-04 15:01:59 -07002378 Log.i(this, "transfer %s", callId);
Ravi Palurif4b38e72020-02-05 12:35:41 +05302379 findConnectionForAction(callId, "transfer").onTransfer(number, isConfirmationRequired);
2380 }
2381
2382 private void consultativeTransfer(String callId, String otherCallId) {
Tyler Gunnffbcd892020-05-04 15:01:59 -07002383 Log.i(this, "consultativeTransfer %s", callId);
Ravi Palurif4b38e72020-02-05 12:35:41 +05302384 Connection connection1 = findConnectionForAction(callId, "consultativeTransfer");
2385 Connection connection2 = findConnectionForAction(otherCallId, " consultativeTransfer");
2386 connection1.onTransfer(connection2);
2387 }
2388
Bryce Leecac50772015-11-17 15:13:29 -08002389 private void silence(String callId) {
Tyler Gunnffbcd892020-05-04 15:01:59 -07002390 Log.i(this, "silence %s", callId);
Bryce Leecac50772015-11-17 15:13:29 -08002391 findConnectionForAction(callId, "silence").onSilence();
2392 }
2393
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002394 private void disconnect(String callId) {
Tyler Gunnffbcd892020-05-04 15:01:59 -07002395 Log.i(this, "disconnect %s", callId);
Santos Cordon0159ac02014-08-21 14:28:11 -07002396 if (mConnectionById.containsKey(callId)) {
2397 findConnectionForAction(callId, "disconnect").onDisconnect();
2398 } else {
2399 findConferenceForAction(callId, "disconnect").onDisconnect();
2400 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002401 }
2402
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002403 private void hold(String callId) {
Tyler Gunnffbcd892020-05-04 15:01:59 -07002404 Log.i(this, "hold %s", callId);
Santos Cordon0159ac02014-08-21 14:28:11 -07002405 if (mConnectionById.containsKey(callId)) {
2406 findConnectionForAction(callId, "hold").onHold();
2407 } else {
2408 findConferenceForAction(callId, "hold").onHold();
2409 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002410 }
2411
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002412 private void unhold(String callId) {
Tyler Gunnffbcd892020-05-04 15:01:59 -07002413 Log.i(this, "unhold %s", callId);
Santos Cordon0159ac02014-08-21 14:28:11 -07002414 if (mConnectionById.containsKey(callId)) {
2415 findConnectionForAction(callId, "unhold").onUnhold();
2416 } else {
2417 findConferenceForAction(callId, "unhold").onUnhold();
2418 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002419 }
2420
Yorke Lee4af59352015-05-13 14:14:54 -07002421 private void onCallAudioStateChanged(String callId, CallAudioState callAudioState) {
Tyler Gunnffbcd892020-05-04 15:01:59 -07002422 Log.i(this, "onAudioStateChanged %s %s", callId, callAudioState);
Yorke Leea0d3ca92014-09-15 19:18:13 -07002423 if (mConnectionById.containsKey(callId)) {
Yorke Lee4af59352015-05-13 14:14:54 -07002424 findConnectionForAction(callId, "onCallAudioStateChanged").setCallAudioState(
2425 callAudioState);
Yorke Leea0d3ca92014-09-15 19:18:13 -07002426 } else {
Yorke Lee4af59352015-05-13 14:14:54 -07002427 findConferenceForAction(callId, "onCallAudioStateChanged").setCallAudioState(
2428 callAudioState);
Yorke Leea0d3ca92014-09-15 19:18:13 -07002429 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002430 }
2431
Junhoedf3d822022-11-24 09:26:37 +00002432 private void onCallEndpointChanged(String callId, CallEndpoint callEndpoint) {
2433 Log.i(this, "onCallEndpointChanged %s %s", callId, callEndpoint);
2434 if (mConnectionById.containsKey(callId)) {
2435 findConnectionForAction(callId, "onCallEndpointChanged").setCallEndpoint(callEndpoint);
2436 } else {
2437 findConferenceForAction(callId, "onCallEndpointChanged").setCallEndpoint(callEndpoint);
2438 }
2439 }
2440
2441 private void onAvailableCallEndpointsChanged(String callId,
2442 List<CallEndpoint> availableCallEndpoints) {
2443 Log.i(this, "onAvailableCallEndpointsChanged %s", callId);
2444 if (mConnectionById.containsKey(callId)) {
2445 findConnectionForAction(callId, "onAvailableCallEndpointsChanged")
2446 .setAvailableCallEndpoints(availableCallEndpoints);
2447 } else {
2448 findConferenceForAction(callId, "onAvailableCallEndpointsChanged")
2449 .setAvailableCallEndpoints(availableCallEndpoints);
2450 }
2451 }
2452
2453 private void onMuteStateChanged(String callId, boolean isMuted) {
2454 Log.i(this, "onMuteStateChanged %s %s", callId, isMuted);
2455 if (mConnectionById.containsKey(callId)) {
2456 findConnectionForAction(callId, "onMuteStateChanged").setMuteState(isMuted);
2457 } else {
2458 findConferenceForAction(callId, "onMuteStateChanged").setMuteState(isMuted);
2459 }
2460 }
2461
Grace Jiae99fde92021-01-19 14:58:01 -08002462 private void onUsingAlternativeUi(String callId, boolean isUsingAlternativeUi) {
2463 Log.i(this, "onUsingAlternativeUi %s %s", callId, isUsingAlternativeUi);
2464 if (mConnectionById.containsKey(callId)) {
2465 findConnectionForAction(callId, "onUsingAlternativeUi")
2466 .onUsingAlternativeUi(isUsingAlternativeUi);
2467 }
2468 }
2469
2470 private void onTrackedByNonUiService(String callId, boolean isTracked) {
2471 Log.i(this, "onTrackedByNonUiService %s %s", callId, isTracked);
2472 if (mConnectionById.containsKey(callId)) {
2473 findConnectionForAction(callId, "onTrackedByNonUiService")
2474 .onTrackedByNonUiService(isTracked);
2475 }
2476 }
2477
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002478 private void playDtmfTone(String callId, char digit) {
Tyler Gunnffbcd892020-05-04 15:01:59 -07002479 Log.i(this, "playDtmfTone %s %c", callId, digit);
Yorke Leea0d3ca92014-09-15 19:18:13 -07002480 if (mConnectionById.containsKey(callId)) {
2481 findConnectionForAction(callId, "playDtmfTone").onPlayDtmfTone(digit);
2482 } else {
2483 findConferenceForAction(callId, "playDtmfTone").onPlayDtmfTone(digit);
2484 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002485 }
2486
2487 private void stopDtmfTone(String callId) {
Tyler Gunnffbcd892020-05-04 15:01:59 -07002488 Log.i(this, "stopDtmfTone %s", callId);
Yorke Leea0d3ca92014-09-15 19:18:13 -07002489 if (mConnectionById.containsKey(callId)) {
2490 findConnectionForAction(callId, "stopDtmfTone").onStopDtmfTone();
2491 } else {
2492 findConferenceForAction(callId, "stopDtmfTone").onStopDtmfTone();
2493 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002494 }
2495
Santos Cordon823fd3c2014-08-07 18:35:18 -07002496 private void conference(String callId1, String callId2) {
Tyler Gunnffbcd892020-05-04 15:01:59 -07002497 Log.i(this, "conference %s, %s", callId1, callId2);
Santos Cordon980acb92014-05-31 10:31:19 -07002498
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002499 // Attempt to get second connection or conference.
Santos Cordon823fd3c2014-08-07 18:35:18 -07002500 Connection connection2 = findConnectionForAction(callId2, "conference");
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002501 Conference conference2 = getNullConference();
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07002502 if (connection2 == getNullConnection()) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002503 conference2 = findConferenceForAction(callId2, "conference");
2504 if (conference2 == getNullConference()) {
2505 Log.w(this, "Connection2 or Conference2 missing in conference request %s.",
2506 callId2);
2507 return;
2508 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07002509 }
Santos Cordonb6939982014-06-04 20:20:58 -07002510
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002511 // Attempt to get first connection or conference and perform merge.
Ihab Awad50e35062014-09-30 09:17:03 -07002512 Connection connection1 = findConnectionForAction(callId1, "conference");
2513 if (connection1 == getNullConnection()) {
2514 Conference conference1 = findConferenceForAction(callId1, "addConnection");
2515 if (conference1 == getNullConference()) {
2516 Log.w(this,
2517 "Connection1 or Conference1 missing in conference request %s.",
2518 callId1);
2519 } else {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002520 // Call 1 is a conference.
2521 if (connection2 != getNullConnection()) {
2522 // Call 2 is a connection so merge via call 1 (conference).
2523 conference1.onMerge(connection2);
2524 } else {
2525 // Call 2 is ALSO a conference; this should never happen.
2526 Log.wtf(this, "There can only be one conference and an attempt was made to " +
2527 "merge two conferences.");
2528 return;
2529 }
Ihab Awad50e35062014-09-30 09:17:03 -07002530 }
2531 } else {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002532 // Call 1 is a connection.
2533 if (conference2 != getNullConference()) {
2534 // Call 2 is a conference, so merge via call 2.
2535 conference2.onMerge(connection1);
2536 } else {
2537 // Call 2 is a connection, so merge together.
2538 onConference(connection1, connection2);
2539 }
Ihab Awad50e35062014-09-30 09:17:03 -07002540 }
Santos Cordon980acb92014-05-31 10:31:19 -07002541 }
2542
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002543 private void splitFromConference(String callId) {
Tyler Gunnffbcd892020-05-04 15:01:59 -07002544 Log.i(this, "splitFromConference(%s)", callId);
Santos Cordon980acb92014-05-31 10:31:19 -07002545
2546 Connection connection = findConnectionForAction(callId, "splitFromConference");
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07002547 if (connection == getNullConnection()) {
Santos Cordon980acb92014-05-31 10:31:19 -07002548 Log.w(this, "Connection missing in conference request %s.", callId);
2549 return;
2550 }
2551
Santos Cordon0159ac02014-08-21 14:28:11 -07002552 Conference conference = connection.getConference();
2553 if (conference != null) {
2554 conference.onSeparate(connection);
2555 }
Santos Cordon980acb92014-05-31 10:31:19 -07002556 }
2557
Santos Cordona4868042014-09-04 17:39:22 -07002558 private void mergeConference(String callId) {
Tyler Gunnffbcd892020-05-04 15:01:59 -07002559 Log.i(this, "mergeConference(%s)", callId);
Santos Cordona4868042014-09-04 17:39:22 -07002560 Conference conference = findConferenceForAction(callId, "mergeConference");
2561 if (conference != null) {
2562 conference.onMerge();
2563 }
2564 }
2565
2566 private void swapConference(String callId) {
Tyler Gunnffbcd892020-05-04 15:01:59 -07002567 Log.i(this, "swapConference(%s)", callId);
Santos Cordona4868042014-09-04 17:39:22 -07002568 Conference conference = findConferenceForAction(callId, "swapConference");
2569 if (conference != null) {
2570 conference.onSwap();
2571 }
2572 }
2573
Ravi Paluri404babb2020-01-23 19:02:44 +05302574 private void addConferenceParticipants(String callId, List<Uri> participants) {
Tyler Gunnffbcd892020-05-04 15:01:59 -07002575 Log.i(this, "addConferenceParticipants(%s)", callId);
Ravi Paluri404babb2020-01-23 19:02:44 +05302576 if (mConnectionById.containsKey(callId)) {
2577 findConnectionForAction(callId, "addConferenceParticipants")
2578 .onAddConferenceParticipants(participants);
2579 } else {
2580 findConferenceForAction(callId, "addConferenceParticipants")
2581 .onAddConferenceParticipants(participants);
2582 }
2583 }
2584
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002585 /**
2586 * Notifies a {@link Connection} of a request to pull an external call.
2587 *
2588 * See {@link Call#pullExternalCall()}.
2589 *
2590 * @param callId The ID of the call to pull.
2591 */
2592 private void pullExternalCall(String callId) {
Tyler Gunnffbcd892020-05-04 15:01:59 -07002593 Log.i(this, "pullExternalCall(%s)", callId);
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002594 Connection connection = findConnectionForAction(callId, "pullExternalCall");
2595 if (connection != null) {
2596 connection.onPullExternalCall();
2597 }
2598 }
2599
2600 /**
2601 * Notifies a {@link Connection} of a call event.
2602 *
2603 * See {@link Call#sendCallEvent(String, Bundle)}.
2604 *
2605 * @param callId The ID of the call receiving the event.
2606 * @param event The event.
2607 * @param extras Extras associated with the event.
2608 */
2609 private void sendCallEvent(String callId, String event, Bundle extras) {
Tyler Gunnffbcd892020-05-04 15:01:59 -07002610 Log.i(this, "sendCallEvent(%s, %s)", callId, event);
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002611 Connection connection = findConnectionForAction(callId, "sendCallEvent");
2612 if (connection != null) {
2613 connection.onCallEvent(event, extras);
2614 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002615 }
2616
Hall Liu73903142021-02-18 18:41:41 -08002617 private void onCallFilteringCompleted(String callId, Connection.CallFilteringCompletionInfo
2618 callFilteringCompletionInfo) {
2619 Log.i(this, "onCallFilteringCompleted(%s, %s)", callId, callFilteringCompletionInfo);
Hall Liu49cabcc2021-01-15 11:41:48 -08002620 Connection connection = findConnectionForAction(callId, "onCallFilteringCompleted");
2621 if (connection != null) {
Hall Liu73903142021-02-18 18:41:41 -08002622 connection.onCallFilteringCompleted(callFilteringCompletionInfo);
Hall Liu49cabcc2021-01-15 11:41:48 -08002623 }
2624 }
2625
Tyler Gunndee56a82016-03-23 16:06:34 -07002626 /**
Tyler Gunn79bc1ec2018-01-22 15:17:54 -08002627 * Notifies a {@link Connection} that a handover has completed.
2628 *
2629 * @param callId The ID of the call which completed handover.
2630 */
2631 private void notifyHandoverComplete(String callId) {
Tyler Gunnffbcd892020-05-04 15:01:59 -07002632 Log.i(this, "notifyHandoverComplete(%s)", callId);
Tyler Gunn79bc1ec2018-01-22 15:17:54 -08002633 Connection connection = findConnectionForAction(callId, "notifyHandoverComplete");
2634 if (connection != null) {
2635 connection.onHandoverComplete();
2636 }
2637 }
2638
2639 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07002640 * Notifies a {@link Connection} or {@link Conference} of a change to the extras from Telecom.
2641 * <p>
2642 * These extra changes can originate from Telecom itself, or from an {@link InCallService} via
2643 * the {@link android.telecom.Call#putExtra(String, boolean)},
2644 * {@link android.telecom.Call#putExtra(String, int)},
2645 * {@link android.telecom.Call#putExtra(String, String)},
2646 * {@link Call#removeExtras(List)}.
2647 *
2648 * @param callId The ID of the call receiving the event.
2649 * @param extras The new extras bundle.
2650 */
2651 private void handleExtrasChanged(String callId, Bundle extras) {
Tyler Gunnffbcd892020-05-04 15:01:59 -07002652 Log.i(this, "handleExtrasChanged(%s, %s)", callId, extras);
Tyler Gunndee56a82016-03-23 16:06:34 -07002653 if (mConnectionById.containsKey(callId)) {
2654 findConnectionForAction(callId, "handleExtrasChanged").handleExtrasChanged(extras);
2655 } else if (mConferenceById.containsKey(callId)) {
2656 findConferenceForAction(callId, "handleExtrasChanged").handleExtrasChanged(extras);
2657 }
2658 }
2659
Hall Liub64ac4c2017-02-06 10:49:48 -08002660 private void startRtt(String callId, Connection.RttTextStream rttTextStream) {
Tyler Gunnffbcd892020-05-04 15:01:59 -07002661 Log.i(this, "startRtt(%s)", callId);
Hall Liub64ac4c2017-02-06 10:49:48 -08002662 if (mConnectionById.containsKey(callId)) {
2663 findConnectionForAction(callId, "startRtt").onStartRtt(rttTextStream);
2664 } else if (mConferenceById.containsKey(callId)) {
2665 Log.w(this, "startRtt called on a conference.");
2666 }
2667 }
2668
2669 private void stopRtt(String callId) {
Tyler Gunnffbcd892020-05-04 15:01:59 -07002670 Log.i(this, "stopRtt(%s)", callId);
Hall Liub64ac4c2017-02-06 10:49:48 -08002671 if (mConnectionById.containsKey(callId)) {
2672 findConnectionForAction(callId, "stopRtt").onStopRtt();
2673 } else if (mConferenceById.containsKey(callId)) {
2674 Log.w(this, "stopRtt called on a conference.");
2675 }
2676 }
2677
2678 private void handleRttUpgradeResponse(String callId, Connection.RttTextStream rttTextStream) {
Tyler Gunnffbcd892020-05-04 15:01:59 -07002679 Log.i(this, "handleRttUpgradeResponse(%s, %s)", callId, rttTextStream == null);
Hall Liub64ac4c2017-02-06 10:49:48 -08002680 if (mConnectionById.containsKey(callId)) {
2681 findConnectionForAction(callId, "handleRttUpgradeResponse")
2682 .handleRttUpgradeResponse(rttTextStream);
2683 } else if (mConferenceById.containsKey(callId)) {
2684 Log.w(this, "handleRttUpgradeResponse called on a conference.");
2685 }
2686 }
2687
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002688 private void onPostDialContinue(String callId, boolean proceed) {
Tyler Gunnffbcd892020-05-04 15:01:59 -07002689 Log.i(this, "onPostDialContinue(%s)", callId);
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002690 findConnectionForAction(callId, "stopDtmfTone").onPostDialContinue(proceed);
Evan Charlton6dea4ac2014-06-03 14:07:13 -07002691 }
2692
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002693 private void onAdapterAttached() {
Ihab Awad9c3f1882014-06-30 21:17:13 -07002694 if (mAreAccountsInitialized) {
Santos Cordon52d8a152014-06-17 19:08:45 -07002695 // No need to query again if we already did it.
2696 return;
2697 }
2698
Tyler Gunn4c69fb32019-05-17 10:49:16 -07002699 String callingPackage = getOpPackageName();
2700
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002701 mAdapter.queryRemoteConnectionServices(new RemoteServiceCallback.Stub() {
Santos Cordon52d8a152014-06-17 19:08:45 -07002702 @Override
2703 public void onResult(
2704 final List<ComponentName> componentNames,
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002705 final List<IBinder> services) {
Brad Ebinger0c3541b2016-11-01 14:11:38 -07002706 mHandler.post(new android.telecom.Logging.Runnable("oAA.qRCS.oR", null /*lock*/) {
Ihab Awad6107bab2014-08-18 09:23:25 -07002707 @Override
Brad Ebinger0c3541b2016-11-01 14:11:38 -07002708 public void loggedRun() {
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002709 for (int i = 0; i < componentNames.size() && i < services.size(); i++) {
Santos Cordon52d8a152014-06-17 19:08:45 -07002710 mRemoteConnectionManager.addConnectionService(
2711 componentNames.get(i),
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002712 IConnectionService.Stub.asInterface(services.get(i)));
Santos Cordon52d8a152014-06-17 19:08:45 -07002713 }
Ihab Awad5d0410f2014-07-30 10:07:40 -07002714 onAccountsInitialized();
Sailesh Nepalc5b01572014-07-14 16:29:44 -07002715 Log.d(this, "remote connection services found: " + services);
Santos Cordon52d8a152014-06-17 19:08:45 -07002716 }
Brad Ebinger0c3541b2016-11-01 14:11:38 -07002717 }.prepare());
Santos Cordon52d8a152014-06-17 19:08:45 -07002718 }
2719
2720 @Override
2721 public void onError() {
Brad Ebinger0c3541b2016-11-01 14:11:38 -07002722 mHandler.post(new android.telecom.Logging.Runnable("oAA.qRCS.oE", null /*lock*/) {
Ihab Awad6107bab2014-08-18 09:23:25 -07002723 @Override
Brad Ebinger0c3541b2016-11-01 14:11:38 -07002724 public void loggedRun() {
Ihab Awad9c3f1882014-06-30 21:17:13 -07002725 mAreAccountsInitialized = true;
Santos Cordon52d8a152014-06-17 19:08:45 -07002726 }
Brad Ebinger0c3541b2016-11-01 14:11:38 -07002727 }.prepare());
Santos Cordon52d8a152014-06-17 19:08:45 -07002728 }
Tyler Gunn4c69fb32019-05-17 10:49:16 -07002729 }, callingPackage);
Santos Cordon52d8a152014-06-17 19:08:45 -07002730 }
2731
Ihab Awadf8b69882014-07-25 15:14:01 -07002732 /**
2733 * Ask some other {@code ConnectionService} to create a {@code RemoteConnection} given an
Santos Cordona663f862014-10-29 13:49:58 -07002734 * incoming request. This is used by {@code ConnectionService}s that are registered with
2735 * {@link PhoneAccount#CAPABILITY_CONNECTION_MANAGER} and want to be able to manage
2736 * SIM-based incoming calls.
Ihab Awadf8b69882014-07-25 15:14:01 -07002737 *
2738 * @param connectionManagerPhoneAccount See description at
2739 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
2740 * @param request Details about the incoming call.
2741 * @return The {@code Connection} object to satisfy this call, or {@code null} to
2742 * not handle the call.
2743 */
Grace Jia41895152021-01-19 13:57:51 -08002744 public final @Nullable RemoteConnection createRemoteIncomingConnection(
2745 @NonNull PhoneAccountHandle connectionManagerPhoneAccount,
2746 @NonNull ConnectionRequest request) {
Ihab Awadf8b69882014-07-25 15:14:01 -07002747 return mRemoteConnectionManager.createRemoteConnection(
2748 connectionManagerPhoneAccount, request, true);
Santos Cordon52d8a152014-06-17 19:08:45 -07002749 }
2750
2751 /**
Ihab Awadf8b69882014-07-25 15:14:01 -07002752 * Ask some other {@code ConnectionService} to create a {@code RemoteConnection} given an
Santos Cordona663f862014-10-29 13:49:58 -07002753 * outgoing request. This is used by {@code ConnectionService}s that are registered with
2754 * {@link PhoneAccount#CAPABILITY_CONNECTION_MANAGER} and want to be able to use the
2755 * SIM-based {@code ConnectionService} to place its outgoing calls.
Ihab Awadf8b69882014-07-25 15:14:01 -07002756 *
2757 * @param connectionManagerPhoneAccount See description at
2758 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
Cuihtlauac ALVARADO0b3b2a52016-09-13 14:49:41 +02002759 * @param request Details about the outgoing call.
Ihab Awadf8b69882014-07-25 15:14:01 -07002760 * @return The {@code Connection} object to satisfy this call, or {@code null} to
2761 * not handle the call.
2762 */
Grace Jia41895152021-01-19 13:57:51 -08002763 public final @Nullable RemoteConnection createRemoteOutgoingConnection(
2764 @NonNull PhoneAccountHandle connectionManagerPhoneAccount,
2765 @NonNull ConnectionRequest request) {
Ihab Awadf8b69882014-07-25 15:14:01 -07002766 return mRemoteConnectionManager.createRemoteConnection(
2767 connectionManagerPhoneAccount, request, false);
2768 }
2769
2770 /**
Grace Jia9a09c672020-08-04 12:52:09 -07002771 * Ask some other {@code ConnectionService} to create a {@code RemoteConference} given an
2772 * incoming request. This is used by {@code ConnectionService}s that are registered with
2773 * {@link PhoneAccount#CAPABILITY_ADHOC_CONFERENCE_CALLING}.
2774 *
2775 * @param connectionManagerPhoneAccount See description at
2776 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
2777 * @param request Details about the incoming conference call.
2778 * @return The {@code RemoteConference} object to satisfy this call, or {@code null} to not
2779 * handle the call.
2780 */
2781 public final @Nullable RemoteConference createRemoteIncomingConference(
2782 @Nullable PhoneAccountHandle connectionManagerPhoneAccount,
2783 @Nullable ConnectionRequest request) {
2784 return mRemoteConnectionManager.createRemoteConference(connectionManagerPhoneAccount,
2785 request, true);
2786 }
2787
2788 /**
2789 * Ask some other {@code ConnectionService} to create a {@code RemoteConference} given an
2790 * outgoing request. This is used by {@code ConnectionService}s that are registered with
2791 * {@link PhoneAccount#CAPABILITY_ADHOC_CONFERENCE_CALLING}.
2792 *
2793 * @param connectionManagerPhoneAccount See description at
2794 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
2795 * @param request Details about the outgoing conference call.
2796 * @return The {@code RemoteConference} object to satisfy this call, or {@code null} to not
2797 * handle the call.
2798 */
2799 public final @Nullable RemoteConference createRemoteOutgoingConference(
2800 @Nullable PhoneAccountHandle connectionManagerPhoneAccount,
2801 @Nullable ConnectionRequest request) {
2802 return mRemoteConnectionManager.createRemoteConference(connectionManagerPhoneAccount,
2803 request, false);
2804 }
2805
2806 /**
Santos Cordona663f862014-10-29 13:49:58 -07002807 * Indicates to the relevant {@code RemoteConnectionService} that the specified
2808 * {@link RemoteConnection}s should be merged into a conference call.
2809 * <p>
2810 * If the conference request is successful, the method {@link #onRemoteConferenceAdded} will
2811 * be invoked.
2812 *
2813 * @param remoteConnection1 The first of the remote connections to conference.
2814 * @param remoteConnection2 The second of the remote connections to conference.
Ihab Awadb8e85c72014-08-23 20:34:57 -07002815 */
2816 public final void conferenceRemoteConnections(
Santos Cordona663f862014-10-29 13:49:58 -07002817 RemoteConnection remoteConnection1,
2818 RemoteConnection remoteConnection2) {
2819 mRemoteConnectionManager.conferenceRemoteConnections(remoteConnection1, remoteConnection2);
Ihab Awadb8e85c72014-08-23 20:34:57 -07002820 }
2821
2822 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07002823 * Adds a new conference call. When a conference call is created either as a result of an
2824 * explicit request via {@link #onConference} or otherwise, the connection service should supply
2825 * an instance of {@link Conference} by invoking this method. A conference call provided by this
2826 * method will persist until {@link Conference#destroy} is invoked on the conference instance.
2827 *
2828 * @param conference The new conference object.
2829 */
2830 public final void addConference(Conference conference) {
Rekha Kumar07366812015-03-24 16:42:31 -07002831 Log.d(this, "addConference: conference=%s", conference);
2832
Santos Cordon823fd3c2014-08-07 18:35:18 -07002833 String id = addConferenceInternal(conference);
2834 if (id != null) {
2835 List<String> connectionIds = new ArrayList<>(2);
2836 for (Connection connection : conference.getConnections()) {
2837 if (mIdByConnection.containsKey(connection)) {
2838 connectionIds.add(mIdByConnection.get(connection));
2839 }
2840 }
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002841 conference.setTelecomCallId(id);
Brad Ebinger0ae44ed2020-04-09 15:30:57 -07002842 ParcelableConference parcelableConference = new ParcelableConference.Builder(
2843 conference.getPhoneAccountHandle(), conference.getState())
2844 .setConnectionCapabilities(conference.getConnectionCapabilities())
2845 .setConnectionProperties(conference.getConnectionProperties())
2846 .setConnectionIds(connectionIds)
2847 .setVideoAttributes(conference.getVideoProvider() == null
2848 ? null : conference.getVideoProvider().getInterface(),
2849 conference.getVideoState())
2850 .setConnectTimeMillis(conference.getConnectTimeMillis(),
2851 conference.getConnectionStartElapsedRealtimeMillis())
2852 .setStatusHints(conference.getStatusHints())
2853 .setExtras(conference.getExtras())
2854 .setAddress(conference.getAddress(), conference.getAddressPresentation())
2855 .setCallerDisplayName(conference.getCallerDisplayName(),
2856 conference.getCallerDisplayNamePresentation())
2857 .setDisconnectCause(conference.getDisconnectCause())
2858 .setRingbackRequested(conference.isRingbackRequested())
2859 .setCallDirection(conference.getCallDirection())
2860 .build();
Andrew Lee0f51da32015-04-16 13:11:55 -07002861
Santos Cordon823fd3c2014-08-07 18:35:18 -07002862 mAdapter.addConferenceCall(id, parcelableConference);
Rekha Kumar07366812015-03-24 16:42:31 -07002863 mAdapter.setVideoProvider(id, conference.getVideoProvider());
2864 mAdapter.setVideoState(id, conference.getVideoState());
Tyler Gunn10362372020-04-08 13:12:30 -07002865 // In some instances a conference can start its life as a standalone call with just a
2866 // single participant; ensure we signal to Telecom in this case.
2867 if (!conference.isMultiparty()) {
2868 mAdapter.setConferenceState(id, conference.isMultiparty());
2869 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07002870
2871 // Go through any child calls and set the parent.
2872 for (Connection connection : conference.getConnections()) {
2873 String connectionId = mIdByConnection.get(connection);
2874 if (connectionId != null) {
2875 mAdapter.setIsConferenced(connectionId, id);
2876 }
2877 }
Pengquan Meng70c9885332017-10-02 18:09:03 -07002878 onConferenceAdded(conference);
Santos Cordon823fd3c2014-08-07 18:35:18 -07002879 }
2880 }
2881
2882 /**
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002883 * Adds a connection created by the {@link ConnectionService} and informs telecom of the new
2884 * connection.
2885 *
2886 * @param phoneAccountHandle The phone account handle for the connection.
2887 * @param connection The connection to add.
2888 */
2889 public final void addExistingConnection(PhoneAccountHandle phoneAccountHandle,
2890 Connection connection) {
Tyler Gunn78da7812017-05-09 14:34:57 -07002891 addExistingConnection(phoneAccountHandle, connection, null /* conference */);
2892 }
2893
2894 /**
Pengquan Meng731c1a32017-11-21 18:01:13 -08002895 * Call to inform Telecom that your {@link ConnectionService} has released call resources (e.g
2896 * microphone, camera).
2897 *
Pengquan Menge3bf7e22018-02-22 17:30:04 -08002898 * <p>
2899 * The {@link ConnectionService} will be disconnected when it failed to call this method within
2900 * 5 seconds after {@link #onConnectionServiceFocusLost()} is called.
2901 *
Pengquan Meng731c1a32017-11-21 18:01:13 -08002902 * @see ConnectionService#onConnectionServiceFocusLost()
2903 */
2904 public final void connectionServiceFocusReleased() {
2905 mAdapter.onConnectionServiceFocusReleased();
2906 }
2907
2908 /**
Tyler Gunn78da7812017-05-09 14:34:57 -07002909 * Adds a connection created by the {@link ConnectionService} and informs telecom of the new
Tyler Gunn5567d742019-10-31 13:04:37 -07002910 * connection, as well as adding that connection to the specified conference.
2911 * <p>
2912 * Note: This API is intended ONLY for use by the Telephony stack to provide an easy way to add
2913 * IMS conference participants to be added to a conference in a single step; this helps ensure
2914 * UI updates happen atomically, rather than adding the connection and then adding it to
2915 * the conference in another step.
Tyler Gunn78da7812017-05-09 14:34:57 -07002916 *
2917 * @param phoneAccountHandle The phone account handle for the connection.
2918 * @param connection The connection to add.
2919 * @param conference The parent conference of the new connection.
2920 * @hide
2921 */
Tyler Gunn5567d742019-10-31 13:04:37 -07002922 @SystemApi
2923 public final void addExistingConnection(@NonNull PhoneAccountHandle phoneAccountHandle,
2924 @NonNull Connection connection, @NonNull Conference conference) {
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002925
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002926 String id = addExistingConnectionInternal(phoneAccountHandle, connection);
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002927 if (id != null) {
2928 List<String> emptyList = new ArrayList<>(0);
Tyler Gunn78da7812017-05-09 14:34:57 -07002929 String conferenceId = null;
2930 if (conference != null) {
2931 conferenceId = mIdByConference.get(conference);
2932 }
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002933
2934 ParcelableConnection parcelableConnection = new ParcelableConnection(
2935 phoneAccountHandle,
2936 connection.getState(),
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002937 connection.getConnectionCapabilities(),
Tyler Gunn720c6642016-03-22 09:02:47 -07002938 connection.getConnectionProperties(),
Christine Hallstrom2830ce92016-11-30 16:06:42 -08002939 connection.getSupportedAudioRoutes(),
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002940 connection.getAddress(),
2941 connection.getAddressPresentation(),
2942 connection.getCallerDisplayName(),
2943 connection.getCallerDisplayNamePresentation(),
2944 connection.getVideoProvider() == null ?
2945 null : connection.getVideoProvider().getInterface(),
2946 connection.getVideoState(),
2947 connection.isRingbackRequested(),
2948 connection.getAudioModeIsVoip(),
Roshan Piuse927ec02015-07-15 15:47:21 -07002949 connection.getConnectTimeMillis(),
Tyler Gunnc9503d62020-01-27 10:30:51 -08002950 connection.getConnectionStartElapsedRealtimeMillis(),
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002951 connection.getStatusHints(),
2952 connection.getDisconnectCause(),
Santos Cordon6b7f9552015-05-27 17:21:45 -07002953 emptyList,
Tyler Gunn78da7812017-05-09 14:34:57 -07002954 connection.getExtras(),
Tyler Gunn6986a632019-06-25 13:45:32 -07002955 conferenceId,
Tyler Gunnd57d76c2019-09-24 14:53:23 -07002956 connection.getCallDirection(),
2957 Connection.VERIFICATION_STATUS_NOT_VERIFIED);
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002958 mAdapter.addExistingConnection(id, parcelableConnection);
2959 }
2960 }
2961
2962 /**
Ihab Awadf8b69882014-07-25 15:14:01 -07002963 * Returns all the active {@code Connection}s for which this {@code ConnectionService}
2964 * has taken responsibility.
2965 *
2966 * @return A collection of {@code Connection}s created by this {@code ConnectionService}.
Santos Cordonb6939982014-06-04 20:20:58 -07002967 */
Sailesh Nepal091768c2014-06-30 15:15:23 -07002968 public final Collection<Connection> getAllConnections() {
Santos Cordonb6939982014-06-04 20:20:58 -07002969 return mConnectionById.values();
2970 }
2971
2972 /**
Santos Cordona6018b92016-02-16 14:23:12 -08002973 * Returns all the active {@code Conference}s for which this {@code ConnectionService}
2974 * has taken responsibility.
2975 *
2976 * @return A collection of {@code Conference}s created by this {@code ConnectionService}.
2977 */
2978 public final Collection<Conference> getAllConferences() {
2979 return mConferenceById.values();
2980 }
2981
2982 /**
Ihab Awadf8b69882014-07-25 15:14:01 -07002983 * Create a {@code Connection} given an incoming request. This is used to attach to existing
2984 * incoming calls.
Evan Charltonbf11f982014-07-20 22:06:28 -07002985 *
Ihab Awadf8b69882014-07-25 15:14:01 -07002986 * @param connectionManagerPhoneAccount See description at
2987 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
2988 * @param request Details about the incoming call.
2989 * @return The {@code Connection} object to satisfy this call, or {@code null} to
2990 * not handle the call.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002991 */
Ihab Awadf8b69882014-07-25 15:14:01 -07002992 public Connection onCreateIncomingConnection(
2993 PhoneAccountHandle connectionManagerPhoneAccount,
2994 ConnectionRequest request) {
2995 return null;
2996 }
Ravi Paluri80aa2142019-12-02 11:57:37 +05302997 /**
Grace Jia8587ee52020-07-10 15:42:32 -07002998 * Create a {@code Conference} given an incoming request. This is used to attach to an incoming
2999 * conference call initiated via
3000 * {@link TelecomManager#addNewIncomingConference(PhoneAccountHandle, Bundle)}.
Ravi Paluri80aa2142019-12-02 11:57:37 +05303001 *
3002 * @param connectionManagerPhoneAccount See description at
3003 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
Grace Jia8587ee52020-07-10 15:42:32 -07003004 * @param request Details about the incoming conference call.
Grace Jia41895152021-01-19 13:57:51 -08003005 * @return The {@code Conference} object to satisfy this call. If the conference attempt is
3006 * failed, the return value will be a result of an invocation of
3007 * {@link Connection#createFailedConnection(DisconnectCause)}.
3008 * Return {@code null} if the {@link ConnectionService} cannot handle the call.
Ravi Paluri80aa2142019-12-02 11:57:37 +05303009 */
3010 public @Nullable Conference onCreateIncomingConference(
Grace Jia41895152021-01-19 13:57:51 -08003011 @NonNull PhoneAccountHandle connectionManagerPhoneAccount,
3012 @NonNull ConnectionRequest request) {
Ravi Paluri80aa2142019-12-02 11:57:37 +05303013 return null;
3014 }
Sailesh Nepalc5b01572014-07-14 16:29:44 -07003015
3016 /**
Tyler Gunn041a1fe2017-05-12 10:04:49 -07003017 * Called after the {@link Connection} returned by
3018 * {@link #onCreateIncomingConnection(PhoneAccountHandle, ConnectionRequest)}
3019 * or {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)} has been
3020 * added to the {@link ConnectionService} and sent to Telecom.
3021 *
3022 * @param connection the {@link Connection}.
3023 * @hide
3024 */
3025 public void onCreateConnectionComplete(Connection connection) {
3026 }
3027
3028 /**
Ravi Paluri80aa2142019-12-02 11:57:37 +05303029 * Called after the {@link Conference} returned by
3030 * {@link #onCreateIncomingConference(PhoneAccountHandle, ConnectionRequest)}
3031 * or {@link #onCreateOutgoingConference(PhoneAccountHandle, ConnectionRequest)} has been
3032 * added to the {@link ConnectionService} and sent to Telecom.
3033 *
3034 * @param conference the {@link Conference}.
3035 * @hide
3036 */
3037 public void onCreateConferenceComplete(Conference conference) {
3038 }
3039
3040
3041 /**
Tyler Gunnf5035432017-01-09 09:43:12 -08003042 * Called by Telecom to inform the {@link ConnectionService} that its request to create a new
3043 * incoming {@link Connection} was denied.
3044 * <p>
3045 * Used when a self-managed {@link ConnectionService} attempts to create a new incoming
3046 * {@link Connection}, but Telecom has determined that the call cannot be allowed at this time.
3047 * The {@link ConnectionService} is responsible for silently rejecting the new incoming
3048 * {@link Connection}.
3049 * <p>
3050 * See {@link TelecomManager#isIncomingCallPermitted(PhoneAccountHandle)} for more information.
3051 *
Tyler Gunn159f35c2017-03-02 09:28:37 -08003052 * @param connectionManagerPhoneAccount See description at
3053 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
Tyler Gunnf5035432017-01-09 09:43:12 -08003054 * @param request The incoming connection request.
3055 */
Tyler Gunn159f35c2017-03-02 09:28:37 -08003056 public void onCreateIncomingConnectionFailed(PhoneAccountHandle connectionManagerPhoneAccount,
3057 ConnectionRequest request) {
Tyler Gunnf5035432017-01-09 09:43:12 -08003058 }
3059
3060 /**
3061 * Called by Telecom to inform the {@link ConnectionService} that its request to create a new
3062 * outgoing {@link Connection} was denied.
3063 * <p>
3064 * Used when a self-managed {@link ConnectionService} attempts to create a new outgoing
3065 * {@link Connection}, but Telecom has determined that the call cannot be placed at this time.
3066 * The {@link ConnectionService} is responisible for informing the user that the
3067 * {@link Connection} cannot be made at this time.
3068 * <p>
3069 * See {@link TelecomManager#isOutgoingCallPermitted(PhoneAccountHandle)} for more information.
3070 *
Tyler Gunn159f35c2017-03-02 09:28:37 -08003071 * @param connectionManagerPhoneAccount See description at
3072 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
Tyler Gunnf5035432017-01-09 09:43:12 -08003073 * @param request The outgoing connection request.
3074 */
Tyler Gunn159f35c2017-03-02 09:28:37 -08003075 public void onCreateOutgoingConnectionFailed(PhoneAccountHandle connectionManagerPhoneAccount,
3076 ConnectionRequest request) {
Tyler Gunnf5035432017-01-09 09:43:12 -08003077 }
3078
3079 /**
Ravi Paluri80aa2142019-12-02 11:57:37 +05303080 * Called by Telecom to inform the {@link ConnectionService} that its request to create a new
3081 * incoming {@link Conference} was denied.
3082 * <p>
3083 * Used when a self-managed {@link ConnectionService} attempts to create a new incoming
3084 * {@link Conference}, but Telecom has determined that the call cannot be allowed at this time.
3085 * The {@link ConnectionService} is responsible for silently rejecting the new incoming
3086 * {@link Conference}.
3087 * <p>
3088 * See {@link TelecomManager#isIncomingCallPermitted(PhoneAccountHandle)} for more information.
3089 *
3090 * @param connectionManagerPhoneAccount See description at
3091 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
3092 * @param request The incoming connection request.
3093 */
3094 public void onCreateIncomingConferenceFailed(
3095 @Nullable PhoneAccountHandle connectionManagerPhoneAccount,
3096 @Nullable ConnectionRequest request) {
3097 }
3098
3099 /**
3100 * Called by Telecom to inform the {@link ConnectionService} that its request to create a new
3101 * outgoing {@link Conference} was denied.
3102 * <p>
3103 * Used when a self-managed {@link ConnectionService} attempts to create a new outgoing
3104 * {@link Conference}, but Telecom has determined that the call cannot be placed at this time.
3105 * The {@link ConnectionService} is responisible for informing the user that the
3106 * {@link Conference} cannot be made at this time.
3107 * <p>
3108 * See {@link TelecomManager#isOutgoingCallPermitted(PhoneAccountHandle)} for more information.
3109 *
3110 * @param connectionManagerPhoneAccount See description at
3111 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
3112 * @param request The outgoing connection request.
3113 */
3114 public void onCreateOutgoingConferenceFailed(
Grace Jia41895152021-01-19 13:57:51 -08003115 @NonNull PhoneAccountHandle connectionManagerPhoneAccount,
3116 @NonNull ConnectionRequest request) {
Ravi Paluri80aa2142019-12-02 11:57:37 +05303117 }
3118
3119
3120 /**
Shriram Ganesh6bf35ac2014-12-11 17:53:38 -08003121 * Trigger recalculate functinality for conference calls. This is used when a Telephony
3122 * Connection is part of a conference controller but is not yet added to Connection
3123 * Service and hence cannot be added to the conference call.
3124 *
3125 * @hide
3126 */
3127 public void triggerConferenceRecalculate() {
3128 }
3129
3130 /**
Ihab Awadf8b69882014-07-25 15:14:01 -07003131 * Create a {@code Connection} given an outgoing request. This is used to initiate new
3132 * outgoing calls.
Sailesh Nepalc5b01572014-07-14 16:29:44 -07003133 *
Ihab Awadf8b69882014-07-25 15:14:01 -07003134 * @param connectionManagerPhoneAccount The connection manager account to use for managing
3135 * this call.
3136 * <p>
3137 * If this parameter is not {@code null}, it means that this {@code ConnectionService}
3138 * has registered one or more {@code PhoneAccount}s having
3139 * {@link PhoneAccount#CAPABILITY_CONNECTION_MANAGER}. This parameter will contain
3140 * one of these {@code PhoneAccount}s, while the {@code request} will contain another
3141 * (usually but not always distinct) {@code PhoneAccount} to be used for actually
3142 * making the connection.
3143 * <p>
3144 * If this parameter is {@code null}, it means that this {@code ConnectionService} is
3145 * being asked to make a direct connection. The
3146 * {@link ConnectionRequest#getAccountHandle()} of parameter {@code request} will be
3147 * a {@code PhoneAccount} registered by this {@code ConnectionService} to use for
3148 * making the connection.
3149 * @param request Details about the outgoing call.
3150 * @return The {@code Connection} object to satisfy this call, or the result of an invocation
Andrew Lee7f3d41f2014-09-11 17:33:16 -07003151 * of {@link Connection#createFailedConnection(DisconnectCause)} to not handle the call.
Sailesh Nepalc5b01572014-07-14 16:29:44 -07003152 */
Ihab Awadf8b69882014-07-25 15:14:01 -07003153 public Connection onCreateOutgoingConnection(
3154 PhoneAccountHandle connectionManagerPhoneAccount,
3155 ConnectionRequest request) {
3156 return null;
3157 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07003158
3159 /**
Ravi Paluri80aa2142019-12-02 11:57:37 +05303160 * Create a {@code Conference} given an outgoing request. This is used to initiate new
Grace Jia8587ee52020-07-10 15:42:32 -07003161 * outgoing conference call requested via
3162 * {@link TelecomManager#startConference(List, Bundle)}.
Ravi Paluri80aa2142019-12-02 11:57:37 +05303163 *
3164 * @param connectionManagerPhoneAccount The connection manager account to use for managing
3165 * this call.
3166 * <p>
3167 * If this parameter is not {@code null}, it means that this {@code ConnectionService}
3168 * has registered one or more {@code PhoneAccount}s having
3169 * {@link PhoneAccount#CAPABILITY_CONNECTION_MANAGER}. This parameter will contain
3170 * one of these {@code PhoneAccount}s, while the {@code request} will contain another
3171 * (usually but not always distinct) {@code PhoneAccount} to be used for actually
3172 * making the connection.
3173 * <p>
3174 * If this parameter is {@code null}, it means that this {@code ConnectionService} is
3175 * being asked to make a direct connection. The
3176 * {@link ConnectionRequest#getAccountHandle()} of parameter {@code request} will be
3177 * a {@code PhoneAccount} registered by this {@code ConnectionService} to use for
3178 * making the connection.
3179 * @param request Details about the outgoing call.
Grace Jia41895152021-01-19 13:57:51 -08003180 * @return The {@code Conference} object to satisfy this call. If the conference attempt is
3181 * failed, the return value will be a result of an invocation of
3182 * {@link Connection#createFailedConnection(DisconnectCause)}.
3183 * Return {@code null} if the {@link ConnectionService} cannot handle the call.
Ravi Paluri80aa2142019-12-02 11:57:37 +05303184 */
3185 public @Nullable Conference onCreateOutgoingConference(
Grace Jia41895152021-01-19 13:57:51 -08003186 @NonNull PhoneAccountHandle connectionManagerPhoneAccount,
3187 @NonNull ConnectionRequest request) {
Ravi Paluri80aa2142019-12-02 11:57:37 +05303188 return null;
3189 }
3190
3191
3192 /**
Tyler Gunn9d127732018-03-02 15:45:51 -08003193 * Called by Telecom to request that a {@link ConnectionService} creates an instance of an
3194 * outgoing handover {@link Connection}.
3195 * <p>
3196 * A call handover is the process where an ongoing call is transferred from one app (i.e.
3197 * {@link ConnectionService} to another app. The user could, for example, choose to continue a
3198 * mobile network call in a video calling app. The mobile network call via the Telephony stack
3199 * is referred to as the source of the handover, and the video calling app is referred to as the
3200 * destination.
3201 * <p>
3202 * When considering a handover scenario the <em>initiating</em> device is where a user initiated
3203 * the handover process (e.g. by calling {@link android.telecom.Call#handoverTo(
3204 * PhoneAccountHandle, int, Bundle)}, and the other device is considered the <em>receiving</em>
3205 * device.
3206 * <p>
3207 * This method is called on the destination {@link ConnectionService} on <em>initiating</em>
3208 * device when the user initiates a handover request from one app to another. The user request
3209 * originates in the {@link InCallService} via
3210 * {@link android.telecom.Call#handoverTo(PhoneAccountHandle, int, Bundle)}.
3211 * <p>
3212 * For a full discussion of the handover process and the APIs involved, see
3213 * {@link android.telecom.Call#handoverTo(PhoneAccountHandle, int, Bundle)}.
3214 * <p>
3215 * Implementations of this method should return an instance of {@link Connection} which
3216 * represents the handover. If your app does not wish to accept a handover to it at this time,
3217 * you can return {@code null}. The code below shows an example of how this is done.
3218 * <pre>
3219 * {@code
3220 * public Connection onCreateIncomingHandoverConnection(PhoneAccountHandle
3221 * fromPhoneAccountHandle, ConnectionRequest request) {
3222 * if (!isHandoverAvailable()) {
3223 * return null;
3224 * }
3225 * MyConnection connection = new MyConnection();
3226 * connection.setAddress(request.getAddress(), TelecomManager.PRESENTATION_ALLOWED);
3227 * connection.setVideoState(request.getVideoState());
3228 * return connection;
3229 * }
3230 * }
3231 * </pre>
3232 *
Sanket Padawea8eddd42017-11-03 11:07:35 -07003233 * @param fromPhoneAccountHandle {@link PhoneAccountHandle} associated with the
3234 * ConnectionService which needs to handover the call.
Tyler Gunn9d127732018-03-02 15:45:51 -08003235 * @param request Details about the call to handover.
3236 * @return {@link Connection} instance corresponding to the handover call.
Sanket Padawea8eddd42017-11-03 11:07:35 -07003237 */
3238 public Connection onCreateOutgoingHandoverConnection(PhoneAccountHandle fromPhoneAccountHandle,
3239 ConnectionRequest request) {
3240 return null;
3241 }
3242
3243 /**
Tyler Gunn9d127732018-03-02 15:45:51 -08003244 * Called by Telecom to request that a {@link ConnectionService} creates an instance of an
3245 * incoming handover {@link Connection}.
3246 * <p>
3247 * A call handover is the process where an ongoing call is transferred from one app (i.e.
3248 * {@link ConnectionService} to another app. The user could, for example, choose to continue a
3249 * mobile network call in a video calling app. The mobile network call via the Telephony stack
3250 * is referred to as the source of the handover, and the video calling app is referred to as the
3251 * destination.
3252 * <p>
3253 * When considering a handover scenario the <em>initiating</em> device is where a user initiated
3254 * the handover process (e.g. by calling {@link android.telecom.Call#handoverTo(
3255 * PhoneAccountHandle, int, Bundle)}, and the other device is considered the <em>receiving</em>
3256 * device.
3257 * <p>
3258 * This method is called on the destination app on the <em>receiving</em> device when the
3259 * destination app calls {@link TelecomManager#acceptHandover(Uri, int, PhoneAccountHandle)} to
3260 * accept an incoming handover from the <em>initiating</em> device.
3261 * <p>
3262 * For a full discussion of the handover process and the APIs involved, see
3263 * {@link android.telecom.Call#handoverTo(PhoneAccountHandle, int, Bundle)}.
3264 * <p>
3265 * Implementations of this method should return an instance of {@link Connection} which
3266 * represents the handover. The code below shows an example of how this is done.
3267 * <pre>
3268 * {@code
3269 * public Connection onCreateIncomingHandoverConnection(PhoneAccountHandle
3270 * fromPhoneAccountHandle, ConnectionRequest request) {
3271 * // Given that your app requested to accept the handover, you should not return null here.
3272 * MyConnection connection = new MyConnection();
3273 * connection.setAddress(request.getAddress(), TelecomManager.PRESENTATION_ALLOWED);
3274 * connection.setVideoState(request.getVideoState());
3275 * return connection;
3276 * }
3277 * }
3278 * </pre>
3279 *
Sanket Padawea8eddd42017-11-03 11:07:35 -07003280 * @param fromPhoneAccountHandle {@link PhoneAccountHandle} associated with the
3281 * ConnectionService which needs to handover the call.
3282 * @param request Details about the call which needs to be handover.
Tyler Gunn9d127732018-03-02 15:45:51 -08003283 * @return {@link Connection} instance corresponding to the handover call.
Sanket Padawea8eddd42017-11-03 11:07:35 -07003284 */
3285 public Connection onCreateIncomingHandoverConnection(PhoneAccountHandle fromPhoneAccountHandle,
3286 ConnectionRequest request) {
3287 return null;
3288 }
3289
3290 /**
3291 * Called by Telecom in response to a {@code TelecomManager#acceptHandover()}
3292 * invocation which failed.
Tyler Gunn9d127732018-03-02 15:45:51 -08003293 * <p>
3294 * For a full discussion of the handover process and the APIs involved, see
3295 * {@link android.telecom.Call#handoverTo(PhoneAccountHandle, int, Bundle)}
3296 *
3297 * @param request Details about the call which failed to handover.
3298 * @param error Reason for handover failure. Will be one of the
Sanket Padawea8eddd42017-11-03 11:07:35 -07003299 */
Tyler Gunn9d127732018-03-02 15:45:51 -08003300 public void onHandoverFailed(ConnectionRequest request,
3301 @Call.Callback.HandoverFailureErrors int error) {
Sanket Padawea8eddd42017-11-03 11:07:35 -07003302 return;
3303 }
3304
3305 /**
Roopa Sattiraju45de470c2022-01-27 21:31:35 -08003306 * Calls of this type are created using
3307 * {@link TelecomManager#addNewUnknownCall(PhoneAccountHandle, Bundle)}. Unknown calls
3308 * are used for representing calls which become known to the {@link ConnectionService}
3309 * midway through the call.
3310 *
3311 * For example, a call transferred from one device to answer would surface as an active
3312 * call in Telecom instead of going through a typical Ringing to Active transition, or
3313 * Dialing to Active transition.
3314 *
3315 * A {@link ConnectionService} can return {@code null} (the default behavior)
3316 * if it is not able to handle a request for the requested unknown connection.
3317 *
3318 * {@link TelecomManager#addNewIncomingCall(PhoneAccountHandle, android.os.Bundle)}.
Yorke Leec3cf9822014-10-02 09:38:39 -07003319 *
Etienne Ruffieuxb99333d2022-02-25 16:11:01 +00003320 * @param connectionManagerPhoneAccount The connection manager account to use for managing
3321 * this call
3322 * @param request Details about the outgoing call
3323 * @return The {@code Connection} object to satisfy this call, or the result of an invocation
3324 * of {@link Connection#createFailedConnection(DisconnectCause)} to not handle the call
Yorke Lee770ed6e2014-10-06 18:58:52 -07003325 * @hide
Yorke Leec3cf9822014-10-02 09:38:39 -07003326 */
Etienne Ruffieuxb99333d2022-02-25 16:11:01 +00003327 @SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
Roopa Sattiraju45de470c2022-01-27 21:31:35 -08003328 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3329 public @Nullable Connection onCreateUnknownConnection(
3330 @NonNull PhoneAccountHandle connectionManagerPhoneAccount,
3331 @NonNull ConnectionRequest request) {
Brad Ebingerb32d4f82016-10-24 16:40:49 -07003332 return null;
Yorke Leec3cf9822014-10-02 09:38:39 -07003333 }
3334
3335 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07003336 * Conference two specified connections. Invoked when the user has made a request to merge the
3337 * specified connections into a conference call. In response, the connection service should
3338 * create an instance of {@link Conference} and pass it into {@link #addConference}.
Santos Cordonb6939982014-06-04 20:20:58 -07003339 *
Santos Cordon823fd3c2014-08-07 18:35:18 -07003340 * @param connection1 A connection to merge into a conference call.
3341 * @param connection2 A connection to merge into a conference call.
Santos Cordonb6939982014-06-04 20:20:58 -07003342 */
Santos Cordon823fd3c2014-08-07 18:35:18 -07003343 public void onConference(Connection connection1, Connection connection2) {}
Santos Cordonb6939982014-06-04 20:20:58 -07003344
Santos Cordona663f862014-10-29 13:49:58 -07003345 /**
Pengquan Meng70c9885332017-10-02 18:09:03 -07003346 * Called when a connection is added.
3347 * @hide
3348 */
3349 public void onConnectionAdded(Connection connection) {}
3350
3351 /**
3352 * Called when a connection is removed.
3353 * @hide
3354 */
3355 public void onConnectionRemoved(Connection connection) {}
3356
3357 /**
3358 * Called when a conference is added.
3359 * @hide
3360 */
3361 public void onConferenceAdded(Conference conference) {}
3362
3363 /**
3364 * Called when a conference is removed.
3365 * @hide
3366 */
3367 public void onConferenceRemoved(Conference conference) {}
3368
3369 /**
Santos Cordona663f862014-10-29 13:49:58 -07003370 * Indicates that a remote conference has been created for existing {@link RemoteConnection}s.
3371 * When this method is invoked, this {@link ConnectionService} should create its own
3372 * representation of the conference call and send it to telecom using {@link #addConference}.
3373 * <p>
3374 * This is only relevant to {@link ConnectionService}s which are registered with
3375 * {@link PhoneAccount#CAPABILITY_CONNECTION_MANAGER}.
3376 *
3377 * @param conference The remote conference call.
3378 */
Ihab Awadb8e85c72014-08-23 20:34:57 -07003379 public void onRemoteConferenceAdded(RemoteConference conference) {}
3380
Santos Cordon823fd3c2014-08-07 18:35:18 -07003381 /**
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07003382 * Called when an existing connection is added remotely.
3383 * @param connection The existing connection which was added.
3384 */
3385 public void onRemoteExistingConnectionAdded(RemoteConnection connection) {}
3386
3387 /**
Pengquan Meng731c1a32017-11-21 18:01:13 -08003388 * Called when the {@link ConnectionService} has lost the call focus.
3389 * The {@link ConnectionService} should release the call resources and invokes
3390 * {@link ConnectionService#connectionServiceFocusReleased()} to inform telecom that it has
3391 * released the call resources.
3392 */
3393 public void onConnectionServiceFocusLost() {}
3394
3395 /**
3396 * Called when the {@link ConnectionService} has gained the call focus. The
3397 * {@link ConnectionService} can acquire the call resources at this time.
3398 */
3399 public void onConnectionServiceFocusGained() {}
3400
3401 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07003402 * @hide
3403 */
3404 public boolean containsConference(Conference conference) {
3405 return mIdByConference.containsKey(conference);
3406 }
3407
Ihab Awadb8e85c72014-08-23 20:34:57 -07003408 /** {@hide} */
3409 void addRemoteConference(RemoteConference remoteConference) {
3410 onRemoteConferenceAdded(remoteConference);
3411 }
3412
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07003413 /** {@hide} */
3414 void addRemoteExistingConnection(RemoteConnection remoteConnection) {
3415 onRemoteExistingConnectionAdded(remoteConnection);
3416 }
3417
Ihab Awad5d0410f2014-07-30 10:07:40 -07003418 private void onAccountsInitialized() {
3419 mAreAccountsInitialized = true;
3420 for (Runnable r : mPreInitializationConnectionRequests) {
3421 r.run();
3422 }
3423 mPreInitializationConnectionRequests.clear();
3424 }
3425
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07003426 /**
Tyler Gunnf0500bd2015-09-01 10:59:48 -07003427 * Adds an existing connection to the list of connections, identified by a new call ID unique
3428 * to this connection service.
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07003429 *
3430 * @param connection The connection.
Tyler Gunnf0500bd2015-09-01 10:59:48 -07003431 * @return The ID of the connection (e.g. the call-id).
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07003432 */
Tyler Gunnf0500bd2015-09-01 10:59:48 -07003433 private String addExistingConnectionInternal(PhoneAccountHandle handle, Connection connection) {
3434 String id;
Tyler Gunncd6ccfd2016-10-17 15:48:19 -07003435
3436 if (connection.getExtras() != null && connection.getExtras()
3437 .containsKey(Connection.EXTRA_ORIGINAL_CONNECTION_ID)) {
3438 id = connection.getExtras().getString(Connection.EXTRA_ORIGINAL_CONNECTION_ID);
3439 Log.d(this, "addExistingConnectionInternal - conn %s reusing original id %s",
3440 connection.getTelecomCallId(), id);
3441 } else if (handle == null) {
Tyler Gunnf0500bd2015-09-01 10:59:48 -07003442 // If no phone account handle was provided, we cannot be sure the call ID is unique,
3443 // so just use a random UUID.
3444 id = UUID.randomUUID().toString();
3445 } else {
3446 // Phone account handle was provided, so use the ConnectionService class name as a
3447 // prefix for a unique incremental call ID.
3448 id = handle.getComponentName().getClassName() + "@" + getNextCallId();
3449 }
Pengquan Meng70c9885332017-10-02 18:09:03 -07003450 addConnection(handle, id, connection);
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07003451 return id;
3452 }
3453
Pengquan Meng70c9885332017-10-02 18:09:03 -07003454 private void addConnection(PhoneAccountHandle handle, String callId, Connection connection) {
Tyler Gunnf0500bd2015-09-01 10:59:48 -07003455 connection.setTelecomCallId(callId);
Ihab Awad542e0ea2014-05-16 10:22:16 -07003456 mConnectionById.put(callId, connection);
3457 mIdByConnection.put(connection, callId);
3458 connection.addConnectionListener(mConnectionListener);
Santos Cordon823fd3c2014-08-07 18:35:18 -07003459 connection.setConnectionService(this);
Pengquan Meng70c9885332017-10-02 18:09:03 -07003460 connection.setPhoneAccountHandle(handle);
3461 onConnectionAdded(connection);
Ihab Awad542e0ea2014-05-16 10:22:16 -07003462 }
3463
Anthony Lee30e65842014-11-06 16:30:53 -08003464 /** {@hide} */
3465 protected void removeConnection(Connection connection) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07003466 connection.unsetConnectionService(this);
Ihab Awad542e0ea2014-05-16 10:22:16 -07003467 connection.removeConnectionListener(mConnectionListener);
Chenjie Luoe370b532016-05-12 16:59:43 -07003468 String id = mIdByConnection.get(connection);
3469 if (id != null) {
3470 mConnectionById.remove(id);
3471 mIdByConnection.remove(connection);
3472 mAdapter.removeCall(id);
Pengquan Meng70c9885332017-10-02 18:09:03 -07003473 onConnectionRemoved(connection);
Chenjie Luoe370b532016-05-12 16:59:43 -07003474 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07003475 }
3476
Santos Cordon823fd3c2014-08-07 18:35:18 -07003477 private String addConferenceInternal(Conference conference) {
Tyler Gunncd6ccfd2016-10-17 15:48:19 -07003478 String originalId = null;
3479 if (conference.getExtras() != null && conference.getExtras()
3480 .containsKey(Connection.EXTRA_ORIGINAL_CONNECTION_ID)) {
3481 originalId = conference.getExtras().getString(Connection.EXTRA_ORIGINAL_CONNECTION_ID);
3482 Log.d(this, "addConferenceInternal: conf %s reusing original id %s",
3483 conference.getTelecomCallId(),
3484 originalId);
3485 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07003486 if (mIdByConference.containsKey(conference)) {
3487 Log.w(this, "Re-adding an existing conference: %s.", conference);
3488 } else if (conference != null) {
Tyler Gunnf0500bd2015-09-01 10:59:48 -07003489 // Conferences do not (yet) have a PhoneAccountHandle associated with them, so we
3490 // cannot determine a ConnectionService class name to associate with the ID, so use
3491 // a unique UUID (for now).
Tyler Gunncd6ccfd2016-10-17 15:48:19 -07003492 String id = originalId == null ? UUID.randomUUID().toString() : originalId;
Santos Cordon823fd3c2014-08-07 18:35:18 -07003493 mConferenceById.put(id, conference);
3494 mIdByConference.put(conference, id);
3495 conference.addListener(mConferenceListener);
3496 return id;
3497 }
3498
3499 return null;
3500 }
3501
3502 private void removeConference(Conference conference) {
3503 if (mIdByConference.containsKey(conference)) {
3504 conference.removeListener(mConferenceListener);
3505
3506 String id = mIdByConference.get(conference);
3507 mConferenceById.remove(id);
3508 mIdByConference.remove(conference);
3509 mAdapter.removeCall(id);
Pengquan Meng70c9885332017-10-02 18:09:03 -07003510
3511 onConferenceRemoved(conference);
Santos Cordon823fd3c2014-08-07 18:35:18 -07003512 }
3513 }
3514
Ihab Awad542e0ea2014-05-16 10:22:16 -07003515 private Connection findConnectionForAction(String callId, String action) {
Tyler Gunn0a88f2e2017-06-16 20:20:34 -07003516 if (callId != null && mConnectionById.containsKey(callId)) {
Ihab Awad542e0ea2014-05-16 10:22:16 -07003517 return mConnectionById.get(callId);
3518 }
Ihab Awad60ac30b2014-05-20 22:32:12 -07003519 Log.w(this, "%s - Cannot find Connection %s", action, callId);
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07003520 return getNullConnection();
3521 }
3522
3523 static synchronized Connection getNullConnection() {
3524 if (sNullConnection == null) {
3525 sNullConnection = new Connection() {};
3526 }
3527 return sNullConnection;
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003528 }
Santos Cordon0159ac02014-08-21 14:28:11 -07003529
3530 private Conference findConferenceForAction(String conferenceId, String action) {
3531 if (mConferenceById.containsKey(conferenceId)) {
3532 return mConferenceById.get(conferenceId);
3533 }
3534 Log.w(this, "%s - Cannot find conference %s", action, conferenceId);
3535 return getNullConference();
3536 }
3537
Ihab Awadb8e85c72014-08-23 20:34:57 -07003538 private List<String> createConnectionIdList(List<Connection> connections) {
3539 List<String> ids = new ArrayList<>();
3540 for (Connection c : connections) {
3541 if (mIdByConnection.containsKey(c)) {
3542 ids.add(mIdByConnection.get(c));
3543 }
3544 }
3545 Collections.sort(ids);
3546 return ids;
3547 }
3548
Tyler Gunn6d76ca02014-11-17 15:49:51 -08003549 /**
3550 * Builds a list of {@link Connection} and {@link Conference} IDs based on the list of
Tyler Gunndf2cbc82015-04-20 09:13:01 -07003551 * {@link Conferenceable}s passed in.
Tyler Gunn6d76ca02014-11-17 15:49:51 -08003552 *
Tyler Gunndf2cbc82015-04-20 09:13:01 -07003553 * @param conferenceables The {@link Conferenceable} connections and conferences.
Tyler Gunn6d76ca02014-11-17 15:49:51 -08003554 * @return List of string conference and call Ids.
3555 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07003556 private List<String> createIdList(List<Conferenceable> conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08003557 List<String> ids = new ArrayList<>();
Tyler Gunndf2cbc82015-04-20 09:13:01 -07003558 for (Conferenceable c : conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08003559 // Only allow Connection and Conference conferenceables.
3560 if (c instanceof Connection) {
3561 Connection connection = (Connection) c;
3562 if (mIdByConnection.containsKey(connection)) {
3563 ids.add(mIdByConnection.get(connection));
3564 }
3565 } else if (c instanceof Conference) {
3566 Conference conference = (Conference) c;
3567 if (mIdByConference.containsKey(conference)) {
3568 ids.add(mIdByConference.get(conference));
3569 }
3570 }
3571 }
3572 Collections.sort(ids);
3573 return ids;
3574 }
3575
Santos Cordon0159ac02014-08-21 14:28:11 -07003576 private Conference getNullConference() {
3577 if (sNullConference == null) {
3578 sNullConference = new Conference(null) {};
3579 }
3580 return sNullConference;
3581 }
Santos Cordon29f2f2e2014-09-11 19:50:24 -07003582
3583 private void endAllConnections() {
3584 // Unbound from telecomm. We should end all connections and conferences.
3585 for (Connection connection : mIdByConnection.keySet()) {
3586 // only operate on top-level calls. Conference calls will be removed on their own.
3587 if (connection.getConference() == null) {
3588 connection.onDisconnect();
3589 }
3590 }
3591 for (Conference conference : mIdByConference.keySet()) {
3592 conference.onDisconnect();
3593 }
3594 }
Tyler Gunnf0500bd2015-09-01 10:59:48 -07003595
3596 /**
3597 * Retrieves the next call ID as maintainted by the connection service.
3598 *
3599 * @return The call ID.
3600 */
3601 private int getNextCallId() {
Brad Ebingerb32d4f82016-10-24 16:40:49 -07003602 synchronized (mIdSyncRoot) {
Tyler Gunnf0500bd2015-09-01 10:59:48 -07003603 return ++mId;
3604 }
3605 }
Brad Ebinger99f17ce2019-09-11 18:06:51 -07003606
3607 /**
3608 * Returns this handler, ONLY FOR TESTING.
3609 * @hide
3610 */
3611 @VisibleForTesting
3612 public Handler getHandler() {
3613 return mHandler;
3614 }
Tyler Gunnc7e07b92021-04-06 11:40:57 -07003615
3616 /**
3617 * Sets this {@link ConnectionService} ready for testing purposes.
3618 * @hide
3619 */
3620 @VisibleForTesting
3621 public void setReadyForTest() {
3622 mAreAccountsInitialized = true;
3623 }
Santos Cordon980acb92014-05-31 10:31:19 -07003624}