blob: 4d6caf834e89e93353b2273b87b9627f0661c099 [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
Tyler Gunn5567d742019-10-31 13:04:37 -070019import android.annotation.NonNull;
20import android.annotation.Nullable;
Roopa Sattiraju45de470c2022-01-27 21:31:35 -080021import android.annotation.RequiresPermission;
Santos Cordon5c6fa952014-07-20 17:47:12 -070022import android.annotation.SdkConstant;
Tyler Gunn5567d742019-10-31 13:04:37 -070023import android.annotation.SystemApi;
Hall Liueb7c9ea2021-03-09 20:24:50 -080024import android.annotation.TestApi;
Sailesh Nepal2a46b902014-07-04 17:21:07 -070025import android.app.Service;
Santos Cordon52d8a152014-06-17 19:08:45 -070026import android.content.ComponentName;
Santos Cordon5c6fa952014-07-20 17:47:12 -070027import android.content.Intent;
Ihab Awad542e0ea2014-05-16 10:22:16 -070028import android.net.Uri;
Santos Cordon6b7f9552015-05-27 17:21:45 -070029import android.os.Bundle;
Santos Cordon52d8a152014-06-17 19:08:45 -070030import android.os.Handler;
31import android.os.IBinder;
32import android.os.Looper;
Sailesh Nepal2a46b902014-07-04 17:21:07 -070033import android.os.Message;
Junhoedf3d822022-11-24 09:26:37 +000034import android.os.OutcomeReceiver;
Hall Liub64ac4c2017-02-06 10:49:48 -080035import android.os.ParcelFileDescriptor;
36import android.os.RemoteException;
Brad Ebingerb32d4f82016-10-24 16:40:49 -070037import android.telecom.Logging.Session;
Andrew Lee14185762014-07-25 09:41:56 -070038
Brad Ebinger99f17ce2019-09-11 18:06:51 -070039import com.android.internal.annotations.VisibleForTesting;
Sailesh Nepal2a46b902014-07-04 17:21:07 -070040import com.android.internal.os.SomeArgs;
Tyler Gunnef9f6f92014-09-12 22:16:17 -070041import com.android.internal.telecom.IConnectionService;
42import com.android.internal.telecom.IConnectionServiceAdapter;
43import com.android.internal.telecom.RemoteServiceCallback;
Santos Cordon52d8a152014-06-17 19:08:45 -070044
Ihab Awad5d0410f2014-07-30 10:07:40 -070045import java.util.ArrayList;
Santos Cordonb6939982014-06-04 20:20:58 -070046import java.util.Collection;
Santos Cordon7c7bc7f2014-07-28 18:15:48 -070047import java.util.Collections;
Santos Cordon52d8a152014-06-17 19:08:45 -070048import java.util.List;
Ihab Awad542e0ea2014-05-16 10:22:16 -070049import java.util.Map;
Santos Cordon823fd3c2014-08-07 18:35:18 -070050import java.util.UUID;
mike dooley95e80702014-09-18 14:07:52 -070051import java.util.concurrent.ConcurrentHashMap;
Junhoedf3d822022-11-24 09:26:37 +000052import java.util.concurrent.Executor;
Ihab Awad542e0ea2014-05-16 10:22:16 -070053
54/**
Tyler Gunnf5035432017-01-09 09:43:12 -080055 * An abstract service that should be implemented by any apps which either:
56 * <ol>
57 * <li>Can make phone calls (VoIP or otherwise) and want those calls to be integrated into the
58 * built-in phone app. Referred to as a <b>system managed</b> {@link ConnectionService}.</li>
59 * <li>Are a standalone calling app and don't want their calls to be integrated into the
60 * built-in phone app. Referred to as a <b>self managed</b> {@link ConnectionService}.</li>
61 * </ol>
62 * Once implemented, the {@link ConnectionService} needs to take the following steps so that Telecom
63 * will bind to it:
Santos Cordona663f862014-10-29 13:49:58 -070064 * <p>
65 * 1. <i>Registration in AndroidManifest.xml</i>
66 * <br/>
67 * <pre>
68 * &lt;service android:name="com.example.package.MyConnectionService"
69 * android:label="@string/some_label_for_my_connection_service"
Yorke Lee249c12e2015-05-13 15:59:29 -070070 * android:permission="android.permission.BIND_TELECOM_CONNECTION_SERVICE"&gt;
Santos Cordona663f862014-10-29 13:49:58 -070071 * &lt;intent-filter&gt;
72 * &lt;action android:name="android.telecom.ConnectionService" /&gt;
73 * &lt;/intent-filter&gt;
74 * &lt;/service&gt;
75 * </pre>
76 * <p>
77 * 2. <i> Registration of {@link PhoneAccount} with {@link TelecomManager}.</i>
78 * <br/>
79 * See {@link PhoneAccount} and {@link TelecomManager#registerPhoneAccount} for more information.
80 * <p>
Tyler Gunnf5035432017-01-09 09:43:12 -080081 * System managed {@link ConnectionService}s must be enabled by the user in the phone app settings
kopriva82c591b2018-10-08 15:57:00 -070082 * before Telecom will bind to them. Self-managed {@link ConnectionService}s must be granted the
Tyler Gunnf5035432017-01-09 09:43:12 -080083 * appropriate permission before Telecom will bind to them.
84 * <p>
85 * Once registered and enabled by the user in the phone app settings or granted permission, telecom
86 * will bind to a {@link ConnectionService} implementation when it wants that
87 * {@link ConnectionService} to place a call or the service has indicated that is has an incoming
88 * call through {@link TelecomManager#addNewIncomingCall}. The {@link ConnectionService} can then
89 * expect a call to {@link #onCreateIncomingConnection} or {@link #onCreateOutgoingConnection}
90 * wherein it should provide a new instance of a {@link Connection} object. It is through this
91 * {@link Connection} object that telecom receives state updates and the {@link ConnectionService}
Santos Cordona663f862014-10-29 13:49:58 -070092 * receives call-commands such as answer, reject, hold and disconnect.
93 * <p>
Tyler Gunnf5035432017-01-09 09:43:12 -080094 * When there are no more live calls, telecom will unbind from the {@link ConnectionService}.
Ihab Awad542e0ea2014-05-16 10:22:16 -070095 */
Sailesh Nepal2a46b902014-07-04 17:21:07 -070096public abstract class ConnectionService extends Service {
Santos Cordon5c6fa952014-07-20 17:47:12 -070097 /**
98 * The {@link Intent} that must be declared as handled by the service.
99 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700100 @SdkConstant(SdkConstant.SdkConstantType.SERVICE_ACTION)
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700101 public static final String SERVICE_INTERFACE = "android.telecom.ConnectionService";
Santos Cordon5c6fa952014-07-20 17:47:12 -0700102
Tyler Gunn8bf76572017-04-06 15:30:08 -0700103 /**
104 * Boolean extra used by Telecom to inform a {@link ConnectionService} that the purpose of it
105 * being asked to create a new outgoing {@link Connection} is to perform a handover of an
106 * ongoing call on the device from another {@link PhoneAccount}/{@link ConnectionService}. Will
107 * be specified in the {@link ConnectionRequest#getExtras()} passed by Telecom when
108 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)} is called.
109 * <p>
Tyler Gunn727c6bd2017-04-11 09:51:40 -0700110 * When your {@link ConnectionService} receives this extra, it should communicate the fact that
111 * this is a handover to the other device's matching {@link ConnectionService}. That
Tyler Gunn8bf76572017-04-06 15:30:08 -0700112 * {@link ConnectionService} will continue the handover using
113 * {@link TelecomManager#addNewIncomingCall(PhoneAccountHandle, Bundle)}, specifying
Tyler Gunn727c6bd2017-04-11 09:51:40 -0700114 * {@link TelecomManager#EXTRA_IS_HANDOVER}. Telecom will match the phone numbers of the
115 * handover call on the other device with ongoing calls for {@link ConnectionService}s which
116 * support {@link PhoneAccount#EXTRA_SUPPORTS_HANDOVER_FROM}.
Tyler Gunn8bf76572017-04-06 15:30:08 -0700117 * @hide
118 */
119 public static final String EXTRA_IS_HANDOVER = TelecomManager.EXTRA_IS_HANDOVER;
120
Ihab Awad542e0ea2014-05-16 10:22:16 -0700121 // Flag controlling whether PII is emitted into the logs
Ihab Awad60ac30b2014-05-20 22:32:12 -0700122 private static final boolean PII_DEBUG = Log.isLoggable(android.util.Log.DEBUG);
Ihab Awad542e0ea2014-05-16 10:22:16 -0700123
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700124 // Session Definitions
125 private static final String SESSION_HANDLER = "H.";
126 private static final String SESSION_ADD_CS_ADAPTER = "CS.aCSA";
127 private static final String SESSION_REMOVE_CS_ADAPTER = "CS.rCSA";
128 private static final String SESSION_CREATE_CONN = "CS.crCo";
Tyler Gunn041a1fe2017-05-12 10:04:49 -0700129 private static final String SESSION_CREATE_CONN_COMPLETE = "CS.crCoC";
Tyler Gunn44e01912017-01-31 10:49:05 -0800130 private static final String SESSION_CREATE_CONN_FAILED = "CS.crCoF";
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700131 private static final String SESSION_ABORT = "CS.ab";
132 private static final String SESSION_ANSWER = "CS.an";
133 private static final String SESSION_ANSWER_VIDEO = "CS.anV";
Pooja Jaind34698d2017-12-28 14:15:31 +0530134 private static final String SESSION_DEFLECT = "CS.def";
Ravi Palurif4b38e72020-02-05 12:35:41 +0530135 private static final String SESSION_TRANSFER = "CS.trans";
136 private static final String SESSION_CONSULTATIVE_TRANSFER = "CS.cTrans";
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700137 private static final String SESSION_REJECT = "CS.r";
138 private static final String SESSION_REJECT_MESSAGE = "CS.rWM";
139 private static final String SESSION_SILENCE = "CS.s";
140 private static final String SESSION_DISCONNECT = "CS.d";
141 private static final String SESSION_HOLD = "CS.h";
142 private static final String SESSION_UNHOLD = "CS.u";
143 private static final String SESSION_CALL_AUDIO_SC = "CS.cASC";
Grace Jiae99fde92021-01-19 14:58:01 -0800144 private static final String SESSION_USING_ALTERNATIVE_UI = "CS.uAU";
145 private static final String SESSION_TRACKED_BY_NON_UI_SERVICE = "CS.tBNUS";
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700146 private static final String SESSION_PLAY_DTMF = "CS.pDT";
147 private static final String SESSION_STOP_DTMF = "CS.sDT";
148 private static final String SESSION_CONFERENCE = "CS.c";
149 private static final String SESSION_SPLIT_CONFERENCE = "CS.sFC";
150 private static final String SESSION_MERGE_CONFERENCE = "CS.mC";
151 private static final String SESSION_SWAP_CONFERENCE = "CS.sC";
Ravi Paluri404babb2020-01-23 19:02:44 +0530152 private static final String SESSION_ADD_PARTICIPANT = "CS.aP";
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700153 private static final String SESSION_POST_DIAL_CONT = "CS.oPDC";
154 private static final String SESSION_PULL_EXTERNAL_CALL = "CS.pEC";
155 private static final String SESSION_SEND_CALL_EVENT = "CS.sCE";
Hall Liu49cabcc2021-01-15 11:41:48 -0800156 private static final String SESSION_CALL_FILTERING_COMPLETED = "CS.oCFC";
Tyler Gunn79bc1ec2018-01-22 15:17:54 -0800157 private static final String SESSION_HANDOVER_COMPLETE = "CS.hC";
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700158 private static final String SESSION_EXTRAS_CHANGED = "CS.oEC";
Hall Liub64ac4c2017-02-06 10:49:48 -0800159 private static final String SESSION_START_RTT = "CS.+RTT";
Hall Liua549fed2018-02-09 16:40:03 -0800160 private static final String SESSION_UPDATE_RTT_PIPES = "CS.uRTT";
Hall Liub64ac4c2017-02-06 10:49:48 -0800161 private static final String SESSION_STOP_RTT = "CS.-RTT";
162 private static final String SESSION_RTT_UPGRADE_RESPONSE = "CS.rTRUR";
Pengquan Meng731c1a32017-11-21 18:01:13 -0800163 private static final String SESSION_CONNECTION_SERVICE_FOCUS_LOST = "CS.cSFL";
164 private static final String SESSION_CONNECTION_SERVICE_FOCUS_GAINED = "CS.cSFG";
Sanket Padawe4cc8ed52017-12-04 16:22:20 -0800165 private static final String SESSION_HANDOVER_FAILED = "CS.haF";
Ravi Paluri80aa2142019-12-02 11:57:37 +0530166 private static final String SESSION_CREATE_CONF = "CS.crConf";
167 private static final String SESSION_CREATE_CONF_COMPLETE = "CS.crConfC";
168 private static final String SESSION_CREATE_CONF_FAILED = "CS.crConfF";
Junhoedf3d822022-11-24 09:26:37 +0000169 private static final String SESSION_CALL_ENDPOINT_CHANGED = "CS.oCEC";
170 private static final String SESSION_AVAILABLE_CALL_ENDPOINTS_CHANGED = "CS.oACEC";
171 private static final String SESSION_MUTE_STATE_CHANGED = "CS.oMSC";
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700172
Ihab Awad8aecfed2014-08-08 17:06:11 -0700173 private static final int MSG_ADD_CONNECTION_SERVICE_ADAPTER = 1;
Sailesh Nepalc5b01572014-07-14 16:29:44 -0700174 private static final int MSG_CREATE_CONNECTION = 2;
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700175 private static final int MSG_ABORT = 3;
Sailesh Nepalc5b01572014-07-14 16:29:44 -0700176 private static final int MSG_ANSWER = 4;
177 private static final int MSG_REJECT = 5;
178 private static final int MSG_DISCONNECT = 6;
179 private static final int MSG_HOLD = 7;
180 private static final int MSG_UNHOLD = 8;
Yorke Lee4af59352015-05-13 14:14:54 -0700181 private static final int MSG_ON_CALL_AUDIO_STATE_CHANGED = 9;
Sailesh Nepalc5b01572014-07-14 16:29:44 -0700182 private static final int MSG_PLAY_DTMF_TONE = 10;
183 private static final int MSG_STOP_DTMF_TONE = 11;
184 private static final int MSG_CONFERENCE = 12;
185 private static final int MSG_SPLIT_FROM_CONFERENCE = 13;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700186 private static final int MSG_ON_POST_DIAL_CONTINUE = 14;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700187 private static final int MSG_REMOVE_CONNECTION_SERVICE_ADAPTER = 16;
Tyler Gunnbe74de02014-08-29 14:51:48 -0700188 private static final int MSG_ANSWER_VIDEO = 17;
Santos Cordona4868042014-09-04 17:39:22 -0700189 private static final int MSG_MERGE_CONFERENCE = 18;
190 private static final int MSG_SWAP_CONFERENCE = 19;
Bryce Lee81901682015-08-28 16:38:02 -0700191 private static final int MSG_REJECT_WITH_MESSAGE = 20;
Bryce Leecac50772015-11-17 15:13:29 -0800192 private static final int MSG_SILENCE = 21;
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700193 private static final int MSG_PULL_EXTERNAL_CALL = 22;
194 private static final int MSG_SEND_CALL_EVENT = 23;
Tyler Gunndee56a82016-03-23 16:06:34 -0700195 private static final int MSG_ON_EXTRAS_CHANGED = 24;
Tyler Gunn44e01912017-01-31 10:49:05 -0800196 private static final int MSG_CREATE_CONNECTION_FAILED = 25;
Hall Liub64ac4c2017-02-06 10:49:48 -0800197 private static final int MSG_ON_START_RTT = 26;
198 private static final int MSG_ON_STOP_RTT = 27;
199 private static final int MSG_RTT_UPGRADE_RESPONSE = 28;
Tyler Gunn041a1fe2017-05-12 10:04:49 -0700200 private static final int MSG_CREATE_CONNECTION_COMPLETE = 29;
Pengquan Meng731c1a32017-11-21 18:01:13 -0800201 private static final int MSG_CONNECTION_SERVICE_FOCUS_LOST = 30;
202 private static final int MSG_CONNECTION_SERVICE_FOCUS_GAINED = 31;
Sanket Padawe4cc8ed52017-12-04 16:22:20 -0800203 private static final int MSG_HANDOVER_FAILED = 32;
Tyler Gunn79bc1ec2018-01-22 15:17:54 -0800204 private static final int MSG_HANDOVER_COMPLETE = 33;
Pooja Jaind34698d2017-12-28 14:15:31 +0530205 private static final int MSG_DEFLECT = 34;
Ravi Paluri80aa2142019-12-02 11:57:37 +0530206 private static final int MSG_CREATE_CONFERENCE = 35;
207 private static final int MSG_CREATE_CONFERENCE_COMPLETE = 36;
208 private static final int MSG_CREATE_CONFERENCE_FAILED = 37;
Tyler Gunnfacfdee2020-01-23 13:10:37 -0800209 private static final int MSG_REJECT_WITH_REASON = 38;
Ravi Paluri404babb2020-01-23 19:02:44 +0530210 private static final int MSG_ADD_PARTICIPANT = 39;
Ravi Palurif4b38e72020-02-05 12:35:41 +0530211 private static final int MSG_EXPLICIT_CALL_TRANSFER = 40;
212 private static final int MSG_EXPLICIT_CALL_TRANSFER_CONSULTATIVE = 41;
Hall Liu49cabcc2021-01-15 11:41:48 -0800213 private static final int MSG_ON_CALL_FILTERING_COMPLETED = 42;
Grace Jiae99fde92021-01-19 14:58:01 -0800214 private static final int MSG_ON_USING_ALTERNATIVE_UI = 43;
215 private static final int MSG_ON_TRACKED_BY_NON_UI_SERVICE = 44;
Junhoedf3d822022-11-24 09:26:37 +0000216 private static final int MSG_ON_CALL_ENDPOINT_CHANGED = 45;
217 private static final int MSG_ON_AVAILABLE_CALL_ENDPOINTS_CHANGED = 46;
218 private static final int MSG_ON_MUTE_STATE_CHANGED = 47;
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700219
Sailesh Nepalcf7020b2014-08-20 10:07:19 -0700220 private static Connection sNullConnection;
221
mike dooley95e80702014-09-18 14:07:52 -0700222 private final Map<String, Connection> mConnectionById = new ConcurrentHashMap<>();
223 private final Map<Connection, String> mIdByConnection = new ConcurrentHashMap<>();
224 private final Map<String, Conference> mConferenceById = new ConcurrentHashMap<>();
225 private final Map<Conference, String> mIdByConference = new ConcurrentHashMap<>();
Ihab Awadb8e85c72014-08-23 20:34:57 -0700226 private final RemoteConnectionManager mRemoteConnectionManager =
227 new RemoteConnectionManager(this);
Ihab Awad5d0410f2014-07-30 10:07:40 -0700228 private final List<Runnable> mPreInitializationConnectionRequests = new ArrayList<>();
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700229 private final ConnectionServiceAdapter mAdapter = new ConnectionServiceAdapter();
Ihab Awad542e0ea2014-05-16 10:22:16 -0700230
Santos Cordon823fd3c2014-08-07 18:35:18 -0700231 private boolean mAreAccountsInitialized = false;
Santos Cordon0159ac02014-08-21 14:28:11 -0700232 private Conference sNullConference;
Tyler Gunnf0500bd2015-09-01 10:59:48 -0700233 private Object mIdSyncRoot = new Object();
234 private int mId = 0;
Santos Cordon823fd3c2014-08-07 18:35:18 -0700235
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700236 private final IBinder mBinder = new IConnectionService.Stub() {
237 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700238 public void addConnectionServiceAdapter(IConnectionServiceAdapter adapter,
239 Session.Info sessionInfo) {
240 Log.startSession(sessionInfo, SESSION_ADD_CS_ADAPTER);
241 try {
242 SomeArgs args = SomeArgs.obtain();
243 args.arg1 = adapter;
244 args.arg2 = Log.createSubsession();
245 mHandler.obtainMessage(MSG_ADD_CONNECTION_SERVICE_ADAPTER, args).sendToTarget();
246 } finally {
247 Log.endSession();
248 }
Ihab Awad8aecfed2014-08-08 17:06:11 -0700249 }
250
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700251 public void removeConnectionServiceAdapter(IConnectionServiceAdapter adapter,
252 Session.Info sessionInfo) {
253 Log.startSession(sessionInfo, SESSION_REMOVE_CS_ADAPTER);
254 try {
255 SomeArgs args = SomeArgs.obtain();
256 args.arg1 = adapter;
257 args.arg2 = Log.createSubsession();
258 mHandler.obtainMessage(MSG_REMOVE_CONNECTION_SERVICE_ADAPTER, args).sendToTarget();
259 } finally {
260 Log.endSession();
261 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700262 }
263
264 @Override
Ihab Awadf8b69882014-07-25 15:14:01 -0700265 public void createConnection(
266 PhoneAccountHandle connectionManagerPhoneAccount,
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700267 String id,
Ihab Awadf8b69882014-07-25 15:14:01 -0700268 ConnectionRequest request,
Yorke Leec3cf9822014-10-02 09:38:39 -0700269 boolean isIncoming,
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700270 boolean isUnknown,
271 Session.Info sessionInfo) {
272 Log.startSession(sessionInfo, SESSION_CREATE_CONN);
273 try {
274 SomeArgs args = SomeArgs.obtain();
275 args.arg1 = connectionManagerPhoneAccount;
276 args.arg2 = id;
277 args.arg3 = request;
278 args.arg4 = Log.createSubsession();
279 args.argi1 = isIncoming ? 1 : 0;
280 args.argi2 = isUnknown ? 1 : 0;
281 mHandler.obtainMessage(MSG_CREATE_CONNECTION, args).sendToTarget();
282 } finally {
283 Log.endSession();
284 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700285 }
286
287 @Override
Tyler Gunn041a1fe2017-05-12 10:04:49 -0700288 public void createConnectionComplete(String id, Session.Info sessionInfo) {
289 Log.startSession(sessionInfo, SESSION_CREATE_CONN_COMPLETE);
290 try {
291 SomeArgs args = SomeArgs.obtain();
292 args.arg1 = id;
293 args.arg2 = Log.createSubsession();
294 mHandler.obtainMessage(MSG_CREATE_CONNECTION_COMPLETE, args).sendToTarget();
295 } finally {
296 Log.endSession();
297 }
298 }
299
300 @Override
Tyler Gunn44e01912017-01-31 10:49:05 -0800301 public void createConnectionFailed(
Tyler Gunn159f35c2017-03-02 09:28:37 -0800302 PhoneAccountHandle connectionManagerPhoneAccount,
Tyler Gunn44e01912017-01-31 10:49:05 -0800303 String callId,
304 ConnectionRequest request,
305 boolean isIncoming,
306 Session.Info sessionInfo) {
307 Log.startSession(sessionInfo, SESSION_CREATE_CONN_FAILED);
308 try {
309 SomeArgs args = SomeArgs.obtain();
310 args.arg1 = callId;
311 args.arg2 = request;
312 args.arg3 = Log.createSubsession();
Tyler Gunn159f35c2017-03-02 09:28:37 -0800313 args.arg4 = connectionManagerPhoneAccount;
Tyler Gunn44e01912017-01-31 10:49:05 -0800314 args.argi1 = isIncoming ? 1 : 0;
315 mHandler.obtainMessage(MSG_CREATE_CONNECTION_FAILED, args).sendToTarget();
316 } finally {
317 Log.endSession();
318 }
319 }
320
321 @Override
Ravi Paluri80aa2142019-12-02 11:57:37 +0530322 public void createConference(
323 PhoneAccountHandle connectionManagerPhoneAccount,
324 String id,
325 ConnectionRequest request,
326 boolean isIncoming,
327 boolean isUnknown,
328 Session.Info sessionInfo) {
329 Log.startSession(sessionInfo, SESSION_CREATE_CONF);
330 try {
331 SomeArgs args = SomeArgs.obtain();
332 args.arg1 = connectionManagerPhoneAccount;
333 args.arg2 = id;
334 args.arg3 = request;
335 args.arg4 = Log.createSubsession();
336 args.argi1 = isIncoming ? 1 : 0;
337 args.argi2 = isUnknown ? 1 : 0;
338 mHandler.obtainMessage(MSG_CREATE_CONFERENCE, args).sendToTarget();
339 } finally {
340 Log.endSession();
341 }
342 }
343
344 @Override
345 public void createConferenceComplete(String id, Session.Info sessionInfo) {
346 Log.startSession(sessionInfo, SESSION_CREATE_CONF_COMPLETE);
347 try {
348 SomeArgs args = SomeArgs.obtain();
349 args.arg1 = id;
350 args.arg2 = Log.createSubsession();
351 mHandler.obtainMessage(MSG_CREATE_CONFERENCE_COMPLETE, args).sendToTarget();
352 } finally {
353 Log.endSession();
354 }
355 }
356
357 @Override
358 public void createConferenceFailed(
359 PhoneAccountHandle connectionManagerPhoneAccount,
360 String callId,
361 ConnectionRequest request,
362 boolean isIncoming,
363 Session.Info sessionInfo) {
364 Log.startSession(sessionInfo, SESSION_CREATE_CONF_FAILED);
365 try {
366 SomeArgs args = SomeArgs.obtain();
367 args.arg1 = callId;
368 args.arg2 = request;
369 args.arg3 = Log.createSubsession();
370 args.arg4 = connectionManagerPhoneAccount;
371 args.argi1 = isIncoming ? 1 : 0;
372 mHandler.obtainMessage(MSG_CREATE_CONFERENCE_FAILED, args).sendToTarget();
373 } finally {
374 Log.endSession();
375 }
376 }
377
378 @Override
Sanket Padawe4cc8ed52017-12-04 16:22:20 -0800379 public void handoverFailed(String callId, ConnectionRequest request, int reason,
380 Session.Info sessionInfo) {
381 Log.startSession(sessionInfo, SESSION_HANDOVER_FAILED);
382 try {
383 SomeArgs args = SomeArgs.obtain();
384 args.arg1 = callId;
385 args.arg2 = request;
386 args.arg3 = Log.createSubsession();
387 args.arg4 = reason;
388 mHandler.obtainMessage(MSG_HANDOVER_FAILED, args).sendToTarget();
389 } finally {
390 Log.endSession();
391 }
392 }
393
394 @Override
Tyler Gunn79bc1ec2018-01-22 15:17:54 -0800395 public void handoverComplete(String callId, Session.Info sessionInfo) {
396 Log.startSession(sessionInfo, SESSION_HANDOVER_COMPLETE);
397 try {
398 SomeArgs args = SomeArgs.obtain();
399 args.arg1 = callId;
400 args.arg2 = Log.createSubsession();
401 mHandler.obtainMessage(MSG_HANDOVER_COMPLETE, args).sendToTarget();
402 } finally {
403 Log.endSession();
404 }
405 }
406
407 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700408 public void abort(String callId, Session.Info sessionInfo) {
409 Log.startSession(sessionInfo, SESSION_ABORT);
410 try {
411 SomeArgs args = SomeArgs.obtain();
412 args.arg1 = callId;
413 args.arg2 = Log.createSubsession();
414 mHandler.obtainMessage(MSG_ABORT, args).sendToTarget();
415 } finally {
416 Log.endSession();
417 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700418 }
419
420 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700421 public void answerVideo(String callId, int videoState, Session.Info sessionInfo) {
422 Log.startSession(sessionInfo, SESSION_ANSWER_VIDEO);
423 try {
424 SomeArgs args = SomeArgs.obtain();
425 args.arg1 = callId;
426 args.arg2 = Log.createSubsession();
427 args.argi1 = videoState;
428 mHandler.obtainMessage(MSG_ANSWER_VIDEO, args).sendToTarget();
429 } finally {
430 Log.endSession();
431 }
Tyler Gunnbe74de02014-08-29 14:51:48 -0700432 }
433
434 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700435 public void answer(String callId, Session.Info sessionInfo) {
436 Log.startSession(sessionInfo, SESSION_ANSWER);
437 try {
438 SomeArgs args = SomeArgs.obtain();
439 args.arg1 = callId;
440 args.arg2 = Log.createSubsession();
441 mHandler.obtainMessage(MSG_ANSWER, args).sendToTarget();
442 } finally {
443 Log.endSession();
444 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700445 }
446
447 @Override
Pooja Jaind34698d2017-12-28 14:15:31 +0530448 public void deflect(String callId, Uri address, Session.Info sessionInfo) {
449 Log.startSession(sessionInfo, SESSION_DEFLECT);
450 try {
451 SomeArgs args = SomeArgs.obtain();
452 args.arg1 = callId;
453 args.arg2 = address;
454 args.arg3 = Log.createSubsession();
455 mHandler.obtainMessage(MSG_DEFLECT, args).sendToTarget();
456 } finally {
457 Log.endSession();
458 }
459 }
460
461 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700462 public void reject(String callId, Session.Info sessionInfo) {
463 Log.startSession(sessionInfo, SESSION_REJECT);
464 try {
465 SomeArgs args = SomeArgs.obtain();
466 args.arg1 = callId;
467 args.arg2 = Log.createSubsession();
468 mHandler.obtainMessage(MSG_REJECT, args).sendToTarget();
469 } finally {
470 Log.endSession();
471 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700472 }
473
474 @Override
Tyler Gunnfacfdee2020-01-23 13:10:37 -0800475 public void rejectWithReason(String callId,
476 @android.telecom.Call.RejectReason int rejectReason, Session.Info sessionInfo) {
477 Log.startSession(sessionInfo, SESSION_REJECT);
478 try {
479 SomeArgs args = SomeArgs.obtain();
480 args.arg1 = callId;
481 args.argi1 = rejectReason;
482 args.arg2 = Log.createSubsession();
483 mHandler.obtainMessage(MSG_REJECT_WITH_REASON, args).sendToTarget();
484 } finally {
485 Log.endSession();
486 }
487 }
488
489 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700490 public void rejectWithMessage(String callId, String message, Session.Info sessionInfo) {
491 Log.startSession(sessionInfo, SESSION_REJECT_MESSAGE);
492 try {
493 SomeArgs args = SomeArgs.obtain();
494 args.arg1 = callId;
495 args.arg2 = message;
496 args.arg3 = Log.createSubsession();
497 mHandler.obtainMessage(MSG_REJECT_WITH_MESSAGE, args).sendToTarget();
498 } finally {
499 Log.endSession();
500 }
Bryce Lee81901682015-08-28 16:38:02 -0700501 }
502
503 @Override
Ravi Palurif4b38e72020-02-05 12:35:41 +0530504 public void transfer(@NonNull String callId, @NonNull Uri number,
505 boolean isConfirmationRequired, Session.Info sessionInfo) {
506 Log.startSession(sessionInfo, SESSION_TRANSFER);
507 try {
508 SomeArgs args = SomeArgs.obtain();
509 args.arg1 = callId;
510 args.arg2 = number;
511 args.argi1 = isConfirmationRequired ? 1 : 0;
512 args.arg3 = Log.createSubsession();
513 mHandler.obtainMessage(MSG_EXPLICIT_CALL_TRANSFER, args).sendToTarget();
514 } finally {
515 Log.endSession();
516 }
517 }
518
519 @Override
520 public void consultativeTransfer(@NonNull String callId, @NonNull String otherCallId,
521 Session.Info sessionInfo) {
522 Log.startSession(sessionInfo, SESSION_CONSULTATIVE_TRANSFER);
523 try {
524 SomeArgs args = SomeArgs.obtain();
525 args.arg1 = callId;
526 args.arg2 = otherCallId;
527 args.arg3 = Log.createSubsession();
528 mHandler.obtainMessage(
529 MSG_EXPLICIT_CALL_TRANSFER_CONSULTATIVE, args).sendToTarget();
530 } finally {
531 Log.endSession();
532 }
533 }
534
535 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700536 public void silence(String callId, Session.Info sessionInfo) {
537 Log.startSession(sessionInfo, SESSION_SILENCE);
538 try {
539 SomeArgs args = SomeArgs.obtain();
540 args.arg1 = callId;
541 args.arg2 = Log.createSubsession();
542 mHandler.obtainMessage(MSG_SILENCE, args).sendToTarget();
543 } finally {
544 Log.endSession();
545 }
Bryce Leecac50772015-11-17 15:13:29 -0800546 }
547
548 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700549 public void disconnect(String callId, Session.Info sessionInfo) {
550 Log.startSession(sessionInfo, SESSION_DISCONNECT);
551 try {
552 SomeArgs args = SomeArgs.obtain();
553 args.arg1 = callId;
554 args.arg2 = Log.createSubsession();
555 mHandler.obtainMessage(MSG_DISCONNECT, args).sendToTarget();
556 } finally {
557 Log.endSession();
558 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700559 }
560
561 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700562 public void hold(String callId, Session.Info sessionInfo) {
563 Log.startSession(sessionInfo, SESSION_HOLD);
564 try {
565 SomeArgs args = SomeArgs.obtain();
566 args.arg1 = callId;
567 args.arg2 = Log.createSubsession();
568 mHandler.obtainMessage(MSG_HOLD, args).sendToTarget();
569 } finally {
570 Log.endSession();
571 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700572 }
573
574 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700575 public void unhold(String callId, Session.Info sessionInfo) {
576 Log.startSession(sessionInfo, SESSION_UNHOLD);
577 try {
578 SomeArgs args = SomeArgs.obtain();
579 args.arg1 = callId;
580 args.arg2 = Log.createSubsession();
581 mHandler.obtainMessage(MSG_UNHOLD, args).sendToTarget();
582 } finally {
583 Log.endSession();
584 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700585 }
586
587 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700588 public void onCallAudioStateChanged(String callId, CallAudioState callAudioState,
589 Session.Info sessionInfo) {
590 Log.startSession(sessionInfo, SESSION_CALL_AUDIO_SC);
591 try {
592 SomeArgs args = SomeArgs.obtain();
593 args.arg1 = callId;
594 args.arg2 = callAudioState;
595 args.arg3 = Log.createSubsession();
596 mHandler.obtainMessage(MSG_ON_CALL_AUDIO_STATE_CHANGED, args).sendToTarget();
597 } finally {
598 Log.endSession();
599 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700600 }
601
602 @Override
Junhoedf3d822022-11-24 09:26:37 +0000603 public void onCallEndpointChanged(String callId, CallEndpoint callEndpoint,
604 Session.Info sessionInfo) {
605 Log.startSession(sessionInfo, SESSION_CALL_ENDPOINT_CHANGED);
606 try {
607 SomeArgs args = SomeArgs.obtain();
608 args.arg1 = callId;
609 args.arg2 = callEndpoint;
610 args.arg3 = Log.createSubsession();
611 mHandler.obtainMessage(MSG_ON_CALL_ENDPOINT_CHANGED, args).sendToTarget();
612 } finally {
613 Log.endSession();
614 }
615 }
616
617 @Override
618 public void onAvailableCallEndpointsChanged(String callId,
619 List<CallEndpoint> availableCallEndpoints, Session.Info sessionInfo) {
620 Log.startSession(sessionInfo, SESSION_AVAILABLE_CALL_ENDPOINTS_CHANGED);
621 try {
622 SomeArgs args = SomeArgs.obtain();
623 args.arg1 = callId;
624 args.arg2 = availableCallEndpoints;
625 args.arg3 = Log.createSubsession();
626 mHandler.obtainMessage(MSG_ON_AVAILABLE_CALL_ENDPOINTS_CHANGED, args)
627 .sendToTarget();
628 } finally {
629 Log.endSession();
630 }
631 }
632
633 @Override
634 public void onMuteStateChanged(String callId, boolean isMuted, Session.Info sessionInfo) {
635 Log.startSession(sessionInfo, SESSION_MUTE_STATE_CHANGED);
636 try {
637 SomeArgs args = SomeArgs.obtain();
638 args.arg1 = callId;
639 args.arg2 = isMuted;
640 args.arg3 = Log.createSubsession();
641 mHandler.obtainMessage(MSG_ON_MUTE_STATE_CHANGED, args).sendToTarget();
642 } finally {
643 Log.endSession();
644 }
645 }
646
647 @Override
Grace Jiae99fde92021-01-19 14:58:01 -0800648 public void onUsingAlternativeUi(String callId, boolean usingAlternativeUiShowing,
649 Session.Info sessionInfo) {
650 Log.startSession(sessionInfo, SESSION_USING_ALTERNATIVE_UI);
651 try {
652 SomeArgs args = SomeArgs.obtain();
653 args.arg1 = callId;
654 args.arg2 = usingAlternativeUiShowing;
655 args.arg3 = Log.createSubsession();
656 mHandler.obtainMessage(MSG_ON_USING_ALTERNATIVE_UI, args).sendToTarget();
657 } finally {
658 Log.endSession();
659 }
660 }
661
662 @Override
663 public void onTrackedByNonUiService(String callId, boolean isTracked,
664 Session.Info sessionInfo) {
665 Log.startSession(sessionInfo, SESSION_TRACKED_BY_NON_UI_SERVICE);
666 try {
667 SomeArgs args = SomeArgs.obtain();
668 args.arg1 = callId;
669 args.arg2 = isTracked;
670 args.arg3 = Log.createSubsession();
671 mHandler.obtainMessage(MSG_ON_TRACKED_BY_NON_UI_SERVICE, args).sendToTarget();
672 } finally {
673 Log.endSession();
674 }
675 }
676
677 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700678 public void playDtmfTone(String callId, char digit, Session.Info sessionInfo) {
679 Log.startSession(sessionInfo, SESSION_PLAY_DTMF);
680 try {
681 SomeArgs args = SomeArgs.obtain();
682 args.arg1 = digit;
683 args.arg2 = callId;
684 args.arg3 = Log.createSubsession();
685 mHandler.obtainMessage(MSG_PLAY_DTMF_TONE, args).sendToTarget();
686 } finally {
687 Log.endSession();
688 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700689 }
690
691 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700692 public void stopDtmfTone(String callId, Session.Info sessionInfo) {
693 Log.startSession(sessionInfo, SESSION_STOP_DTMF);
694 try {
695 SomeArgs args = SomeArgs.obtain();
696 args.arg1 = callId;
697 args.arg2 = Log.createSubsession();
698 mHandler.obtainMessage(MSG_STOP_DTMF_TONE, args).sendToTarget();
699 } finally {
700 Log.endSession();
701 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700702 }
703
704 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700705 public void conference(String callId1, String callId2, Session.Info sessionInfo) {
706 Log.startSession(sessionInfo, SESSION_CONFERENCE);
707 try {
708 SomeArgs args = SomeArgs.obtain();
709 args.arg1 = callId1;
710 args.arg2 = callId2;
711 args.arg3 = Log.createSubsession();
712 mHandler.obtainMessage(MSG_CONFERENCE, args).sendToTarget();
713 } finally {
714 Log.endSession();
715 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700716 }
717
718 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700719 public void splitFromConference(String callId, Session.Info sessionInfo) {
720 Log.startSession(sessionInfo, SESSION_SPLIT_CONFERENCE);
721 try {
722 SomeArgs args = SomeArgs.obtain();
723 args.arg1 = callId;
724 args.arg2 = Log.createSubsession();
725 mHandler.obtainMessage(MSG_SPLIT_FROM_CONFERENCE, args).sendToTarget();
726 } finally {
727 Log.endSession();
728 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700729 }
730
731 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700732 public void mergeConference(String callId, Session.Info sessionInfo) {
733 Log.startSession(sessionInfo, SESSION_MERGE_CONFERENCE);
734 try {
735 SomeArgs args = SomeArgs.obtain();
736 args.arg1 = callId;
737 args.arg2 = Log.createSubsession();
738 mHandler.obtainMessage(MSG_MERGE_CONFERENCE, args).sendToTarget();
739 } finally {
740 Log.endSession();
741 }
Santos Cordona4868042014-09-04 17:39:22 -0700742 }
743
744 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700745 public void swapConference(String callId, Session.Info sessionInfo) {
746 Log.startSession(sessionInfo, SESSION_SWAP_CONFERENCE);
747 try {
748 SomeArgs args = SomeArgs.obtain();
749 args.arg1 = callId;
750 args.arg2 = Log.createSubsession();
751 mHandler.obtainMessage(MSG_SWAP_CONFERENCE, args).sendToTarget();
752 } finally {
753 Log.endSession();
754 }
Santos Cordona4868042014-09-04 17:39:22 -0700755 }
756
757 @Override
Ravi Paluri404babb2020-01-23 19:02:44 +0530758 public void addConferenceParticipants(String callId, List<Uri> participants,
759 Session.Info sessionInfo) {
760 Log.startSession(sessionInfo, SESSION_ADD_PARTICIPANT);
761 try {
762 SomeArgs args = SomeArgs.obtain();
763 args.arg1 = callId;
764 args.arg2 = participants;
765 args.arg3 = Log.createSubsession();
766 mHandler.obtainMessage(MSG_ADD_PARTICIPANT, args).sendToTarget();
767 } finally {
768 Log.endSession();
769 }
770 }
771
772 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700773 public void onPostDialContinue(String callId, boolean proceed, Session.Info sessionInfo) {
774 Log.startSession(sessionInfo, SESSION_POST_DIAL_CONT);
775 try {
776 SomeArgs args = SomeArgs.obtain();
777 args.arg1 = callId;
778 args.arg2 = Log.createSubsession();
779 args.argi1 = proceed ? 1 : 0;
780 mHandler.obtainMessage(MSG_ON_POST_DIAL_CONTINUE, args).sendToTarget();
781 } finally {
782 Log.endSession();
783 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700784 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700785
786 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700787 public void pullExternalCall(String callId, Session.Info sessionInfo) {
788 Log.startSession(sessionInfo, SESSION_PULL_EXTERNAL_CALL);
789 try {
790 SomeArgs args = SomeArgs.obtain();
791 args.arg1 = callId;
792 args.arg2 = Log.createSubsession();
793 mHandler.obtainMessage(MSG_PULL_EXTERNAL_CALL, args).sendToTarget();
794 } finally {
795 Log.endSession();
796 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700797 }
798
799 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700800 public void sendCallEvent(String callId, String event, Bundle extras,
801 Session.Info sessionInfo) {
802 Log.startSession(sessionInfo, SESSION_SEND_CALL_EVENT);
803 try {
804 SomeArgs args = SomeArgs.obtain();
805 args.arg1 = callId;
806 args.arg2 = event;
807 args.arg3 = extras;
808 args.arg4 = Log.createSubsession();
809 mHandler.obtainMessage(MSG_SEND_CALL_EVENT, args).sendToTarget();
810 } finally {
811 Log.endSession();
812 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700813 }
Tyler Gunndee56a82016-03-23 16:06:34 -0700814
815 @Override
Hall Liu73903142021-02-18 18:41:41 -0800816 public void onCallFilteringCompleted(String callId,
817 Connection.CallFilteringCompletionInfo completionInfo,
Hall Liu49cabcc2021-01-15 11:41:48 -0800818 Session.Info sessionInfo) {
819 Log.startSession(sessionInfo, SESSION_CALL_FILTERING_COMPLETED);
820 try {
821 SomeArgs args = SomeArgs.obtain();
822 args.arg1 = callId;
Hall Liu73903142021-02-18 18:41:41 -0800823 args.arg2 = completionInfo;
824 args.arg3 = Log.createSubsession();
Hall Liu49cabcc2021-01-15 11:41:48 -0800825 mHandler.obtainMessage(MSG_ON_CALL_FILTERING_COMPLETED, args).sendToTarget();
826 } finally {
827 Log.endSession();
828 }
829 }
830
831 @Override
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700832 public void onExtrasChanged(String callId, Bundle extras, Session.Info sessionInfo) {
833 Log.startSession(sessionInfo, SESSION_EXTRAS_CHANGED);
834 try {
835 SomeArgs args = SomeArgs.obtain();
836 args.arg1 = callId;
837 args.arg2 = extras;
838 args.arg3 = Log.createSubsession();
839 mHandler.obtainMessage(MSG_ON_EXTRAS_CHANGED, args).sendToTarget();
840 } finally {
841 Log.endSession();
842 }
Tyler Gunndee56a82016-03-23 16:06:34 -0700843 }
Hall Liub64ac4c2017-02-06 10:49:48 -0800844
845 @Override
846 public void startRtt(String callId, ParcelFileDescriptor fromInCall,
847 ParcelFileDescriptor toInCall, Session.Info sessionInfo) throws RemoteException {
848 Log.startSession(sessionInfo, SESSION_START_RTT);
849 try {
850 SomeArgs args = SomeArgs.obtain();
851 args.arg1 = callId;
852 args.arg2 = new Connection.RttTextStream(toInCall, fromInCall);
853 args.arg3 = Log.createSubsession();
854 mHandler.obtainMessage(MSG_ON_START_RTT, args).sendToTarget();
855 } finally {
856 Log.endSession();
857 }
858 }
859
860 @Override
861 public void stopRtt(String callId, Session.Info sessionInfo) throws RemoteException {
862 Log.startSession(sessionInfo, SESSION_STOP_RTT);
863 try {
864 SomeArgs args = SomeArgs.obtain();
865 args.arg1 = callId;
866 args.arg2 = Log.createSubsession();
867 mHandler.obtainMessage(MSG_ON_STOP_RTT, args).sendToTarget();
868 } finally {
869 Log.endSession();
870 }
871 }
872
873 @Override
874 public void respondToRttUpgradeRequest(String callId, ParcelFileDescriptor fromInCall,
875 ParcelFileDescriptor toInCall, Session.Info sessionInfo) throws RemoteException {
876 Log.startSession(sessionInfo, SESSION_RTT_UPGRADE_RESPONSE);
877 try {
878 SomeArgs args = SomeArgs.obtain();
879 args.arg1 = callId;
880 if (toInCall == null || fromInCall == null) {
881 args.arg2 = null;
882 } else {
883 args.arg2 = new Connection.RttTextStream(toInCall, fromInCall);
884 }
885 args.arg3 = Log.createSubsession();
886 mHandler.obtainMessage(MSG_RTT_UPGRADE_RESPONSE, args).sendToTarget();
887 } finally {
888 Log.endSession();
889 }
890 }
Pengquan Meng731c1a32017-11-21 18:01:13 -0800891
892 @Override
893 public void connectionServiceFocusLost(Session.Info sessionInfo) throws RemoteException {
894 Log.startSession(sessionInfo, SESSION_CONNECTION_SERVICE_FOCUS_LOST);
895 try {
896 mHandler.obtainMessage(MSG_CONNECTION_SERVICE_FOCUS_LOST).sendToTarget();
897 } finally {
898 Log.endSession();
899 }
900 }
901
902 @Override
903 public void connectionServiceFocusGained(Session.Info sessionInfo) throws RemoteException {
904 Log.startSession(sessionInfo, SESSION_CONNECTION_SERVICE_FOCUS_GAINED);
905 try {
906 mHandler.obtainMessage(MSG_CONNECTION_SERVICE_FOCUS_GAINED).sendToTarget();
907 } finally {
908 Log.endSession();
909 }
910 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700911 };
912
913 private final Handler mHandler = new Handler(Looper.getMainLooper()) {
914 @Override
915 public void handleMessage(Message msg) {
916 switch (msg.what) {
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700917 case MSG_ADD_CONNECTION_SERVICE_ADAPTER: {
918 SomeArgs args = (SomeArgs) msg.obj;
919 try {
920 IConnectionServiceAdapter adapter = (IConnectionServiceAdapter) args.arg1;
921 Log.continueSession((Session) args.arg2,
922 SESSION_HANDLER + SESSION_ADD_CS_ADAPTER);
923 mAdapter.addAdapter(adapter);
924 onAdapterAttached();
925 } finally {
926 args.recycle();
927 Log.endSession();
928 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700929 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700930 }
931 case MSG_REMOVE_CONNECTION_SERVICE_ADAPTER: {
932 SomeArgs args = (SomeArgs) msg.obj;
933 try {
934 Log.continueSession((Session) args.arg2,
935 SESSION_HANDLER + SESSION_REMOVE_CS_ADAPTER);
936 mAdapter.removeAdapter((IConnectionServiceAdapter) args.arg1);
937 } finally {
938 args.recycle();
939 Log.endSession();
940 }
Ihab Awad8aecfed2014-08-08 17:06:11 -0700941 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700942 }
Ihab Awadf8b69882014-07-25 15:14:01 -0700943 case MSG_CREATE_CONNECTION: {
944 SomeArgs args = (SomeArgs) msg.obj;
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700945 Log.continueSession((Session) args.arg4, SESSION_HANDLER + SESSION_CREATE_CONN);
Ihab Awadf8b69882014-07-25 15:14:01 -0700946 try {
Ihab Awad5d0410f2014-07-30 10:07:40 -0700947 final PhoneAccountHandle connectionManagerPhoneAccount =
Ihab Awadf8b69882014-07-25 15:14:01 -0700948 (PhoneAccountHandle) args.arg1;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700949 final String id = (String) args.arg2;
950 final ConnectionRequest request = (ConnectionRequest) args.arg3;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700951 final boolean isIncoming = args.argi1 == 1;
Yorke Leec3cf9822014-10-02 09:38:39 -0700952 final boolean isUnknown = args.argi2 == 1;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700953 if (!mAreAccountsInitialized) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700954 Log.d(this, "Enqueueing pre-init request %s", id);
Brad Ebinger0c3541b2016-11-01 14:11:38 -0700955 mPreInitializationConnectionRequests.add(
956 new android.telecom.Logging.Runnable(
957 SESSION_HANDLER + SESSION_CREATE_CONN + ".pICR",
958 null /*lock*/) {
Ihab Awad5d0410f2014-07-30 10:07:40 -0700959 @Override
Brad Ebinger0c3541b2016-11-01 14:11:38 -0700960 public void loggedRun() {
Ihab Awad5d0410f2014-07-30 10:07:40 -0700961 createConnection(
962 connectionManagerPhoneAccount,
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700963 id,
Ihab Awad5d0410f2014-07-30 10:07:40 -0700964 request,
Yorke Leec3cf9822014-10-02 09:38:39 -0700965 isIncoming,
966 isUnknown);
Ihab Awad5d0410f2014-07-30 10:07:40 -0700967 }
Brad Ebinger0c3541b2016-11-01 14:11:38 -0700968 }.prepare());
Ihab Awad5d0410f2014-07-30 10:07:40 -0700969 } else {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700970 createConnection(
971 connectionManagerPhoneAccount,
972 id,
973 request,
Yorke Leec3cf9822014-10-02 09:38:39 -0700974 isIncoming,
975 isUnknown);
Ihab Awad5d0410f2014-07-30 10:07:40 -0700976 }
Ihab Awadf8b69882014-07-25 15:14:01 -0700977 } finally {
978 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700979 Log.endSession();
Ihab Awadf8b69882014-07-25 15:14:01 -0700980 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700981 break;
Ihab Awadf8b69882014-07-25 15:14:01 -0700982 }
Tyler Gunn041a1fe2017-05-12 10:04:49 -0700983 case MSG_CREATE_CONNECTION_COMPLETE: {
984 SomeArgs args = (SomeArgs) msg.obj;
985 Log.continueSession((Session) args.arg2,
986 SESSION_HANDLER + SESSION_CREATE_CONN_COMPLETE);
987 try {
988 final String id = (String) args.arg1;
989 if (!mAreAccountsInitialized) {
990 Log.d(this, "Enqueueing pre-init request %s", id);
991 mPreInitializationConnectionRequests.add(
992 new android.telecom.Logging.Runnable(
993 SESSION_HANDLER + SESSION_CREATE_CONN_COMPLETE
994 + ".pICR",
995 null /*lock*/) {
996 @Override
997 public void loggedRun() {
998 notifyCreateConnectionComplete(id);
999 }
1000 }.prepare());
1001 } else {
1002 notifyCreateConnectionComplete(id);
1003 }
1004 } finally {
1005 args.recycle();
1006 Log.endSession();
1007 }
1008 break;
1009 }
Tyler Gunn44e01912017-01-31 10:49:05 -08001010 case MSG_CREATE_CONNECTION_FAILED: {
1011 SomeArgs args = (SomeArgs) msg.obj;
1012 Log.continueSession((Session) args.arg3, SESSION_HANDLER +
1013 SESSION_CREATE_CONN_FAILED);
1014 try {
1015 final String id = (String) args.arg1;
1016 final ConnectionRequest request = (ConnectionRequest) args.arg2;
1017 final boolean isIncoming = args.argi1 == 1;
Tyler Gunn159f35c2017-03-02 09:28:37 -08001018 final PhoneAccountHandle connectionMgrPhoneAccount =
1019 (PhoneAccountHandle) args.arg4;
Tyler Gunn44e01912017-01-31 10:49:05 -08001020 if (!mAreAccountsInitialized) {
1021 Log.d(this, "Enqueueing pre-init request %s", id);
1022 mPreInitializationConnectionRequests.add(
1023 new android.telecom.Logging.Runnable(
1024 SESSION_HANDLER + SESSION_CREATE_CONN_FAILED + ".pICR",
1025 null /*lock*/) {
1026 @Override
1027 public void loggedRun() {
Tyler Gunn159f35c2017-03-02 09:28:37 -08001028 createConnectionFailed(connectionMgrPhoneAccount, id,
1029 request, isIncoming);
Tyler Gunn44e01912017-01-31 10:49:05 -08001030 }
1031 }.prepare());
1032 } else {
1033 Log.i(this, "createConnectionFailed %s", id);
Tyler Gunn159f35c2017-03-02 09:28:37 -08001034 createConnectionFailed(connectionMgrPhoneAccount, id, request,
1035 isIncoming);
Tyler Gunn44e01912017-01-31 10:49:05 -08001036 }
1037 } finally {
1038 args.recycle();
1039 Log.endSession();
1040 }
1041 break;
1042 }
Ravi Paluri80aa2142019-12-02 11:57:37 +05301043 case MSG_CREATE_CONFERENCE: {
1044 SomeArgs args = (SomeArgs) msg.obj;
1045 Log.continueSession((Session) args.arg4, SESSION_HANDLER + SESSION_CREATE_CONN);
1046 try {
1047 final PhoneAccountHandle connectionManagerPhoneAccount =
1048 (PhoneAccountHandle) args.arg1;
1049 final String id = (String) args.arg2;
1050 final ConnectionRequest request = (ConnectionRequest) args.arg3;
1051 final boolean isIncoming = args.argi1 == 1;
1052 final boolean isUnknown = args.argi2 == 1;
1053 if (!mAreAccountsInitialized) {
1054 Log.d(this, "Enqueueing pre-initconference request %s", id);
1055 mPreInitializationConnectionRequests.add(
1056 new android.telecom.Logging.Runnable(
1057 SESSION_HANDLER + SESSION_CREATE_CONF + ".pIConfR",
1058 null /*lock*/) {
1059 @Override
1060 public void loggedRun() {
1061 createConference(connectionManagerPhoneAccount,
1062 id,
1063 request,
1064 isIncoming,
1065 isUnknown);
1066 }
1067 }.prepare());
1068 } else {
1069 createConference(connectionManagerPhoneAccount,
1070 id,
1071 request,
1072 isIncoming,
1073 isUnknown);
1074 }
1075 } finally {
1076 args.recycle();
1077 Log.endSession();
1078 }
1079 break;
1080 }
1081 case MSG_CREATE_CONFERENCE_COMPLETE: {
1082 SomeArgs args = (SomeArgs) msg.obj;
1083 Log.continueSession((Session) args.arg2,
1084 SESSION_HANDLER + SESSION_CREATE_CONN_COMPLETE);
1085 try {
1086 final String id = (String) args.arg1;
1087 if (!mAreAccountsInitialized) {
1088 Log.d(this, "Enqueueing pre-init conference request %s", id);
1089 mPreInitializationConnectionRequests.add(
1090 new android.telecom.Logging.Runnable(
1091 SESSION_HANDLER + SESSION_CREATE_CONF_COMPLETE
1092 + ".pIConfR",
1093 null /*lock*/) {
1094 @Override
1095 public void loggedRun() {
1096 notifyCreateConferenceComplete(id);
1097 }
1098 }.prepare());
1099 } else {
1100 notifyCreateConferenceComplete(id);
1101 }
1102 } finally {
1103 args.recycle();
1104 Log.endSession();
1105 }
1106 break;
1107 }
1108 case MSG_CREATE_CONFERENCE_FAILED: {
1109 SomeArgs args = (SomeArgs) msg.obj;
1110 Log.continueSession((Session) args.arg3, SESSION_HANDLER +
1111 SESSION_CREATE_CONN_FAILED);
1112 try {
1113 final String id = (String) args.arg1;
1114 final ConnectionRequest request = (ConnectionRequest) args.arg2;
1115 final boolean isIncoming = args.argi1 == 1;
1116 final PhoneAccountHandle connectionMgrPhoneAccount =
1117 (PhoneAccountHandle) args.arg4;
1118 if (!mAreAccountsInitialized) {
1119 Log.d(this, "Enqueueing pre-init conference request %s", id);
1120 mPreInitializationConnectionRequests.add(
1121 new android.telecom.Logging.Runnable(
1122 SESSION_HANDLER + SESSION_CREATE_CONF_FAILED
1123 + ".pIConfR",
1124 null /*lock*/) {
1125 @Override
1126 public void loggedRun() {
1127 createConferenceFailed(connectionMgrPhoneAccount, id,
1128 request, isIncoming);
1129 }
1130 }.prepare());
1131 } else {
1132 Log.i(this, "createConferenceFailed %s", id);
1133 createConferenceFailed(connectionMgrPhoneAccount, id, request,
1134 isIncoming);
1135 }
1136 } finally {
1137 args.recycle();
1138 Log.endSession();
1139 }
1140 break;
1141 }
1142
Sanket Padawe4cc8ed52017-12-04 16:22:20 -08001143 case MSG_HANDOVER_FAILED: {
1144 SomeArgs args = (SomeArgs) msg.obj;
1145 Log.continueSession((Session) args.arg3, SESSION_HANDLER +
1146 SESSION_HANDOVER_FAILED);
1147 try {
1148 final String id = (String) args.arg1;
1149 final ConnectionRequest request = (ConnectionRequest) args.arg2;
1150 final int reason = (int) args.arg4;
1151 if (!mAreAccountsInitialized) {
1152 Log.d(this, "Enqueueing pre-init request %s", id);
1153 mPreInitializationConnectionRequests.add(
1154 new android.telecom.Logging.Runnable(
1155 SESSION_HANDLER
1156 + SESSION_HANDOVER_FAILED + ".pICR",
1157 null /*lock*/) {
1158 @Override
1159 public void loggedRun() {
1160 handoverFailed(id, request, reason);
1161 }
1162 }.prepare());
1163 } else {
1164 Log.i(this, "createConnectionFailed %s", id);
1165 handoverFailed(id, request, reason);
1166 }
1167 } finally {
1168 args.recycle();
1169 Log.endSession();
1170 }
1171 break;
1172 }
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001173 case MSG_ABORT: {
1174 SomeArgs args = (SomeArgs) msg.obj;
1175 Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_ABORT);
1176 try {
1177 abort((String) args.arg1);
1178 } finally {
1179 args.recycle();
1180 Log.endSession();
1181 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001182 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001183 }
1184 case MSG_ANSWER: {
1185 SomeArgs args = (SomeArgs) msg.obj;
1186 Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_ANSWER);
1187 try {
1188 answer((String) args.arg1);
1189 } finally {
1190 args.recycle();
1191 Log.endSession();
1192 }
Tyler Gunnbe74de02014-08-29 14:51:48 -07001193 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001194 }
Tyler Gunnbe74de02014-08-29 14:51:48 -07001195 case MSG_ANSWER_VIDEO: {
Andrew Lee8da4c3c2014-07-16 10:11:42 -07001196 SomeArgs args = (SomeArgs) msg.obj;
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001197 Log.continueSession((Session) args.arg2,
1198 SESSION_HANDLER + SESSION_ANSWER_VIDEO);
Andrew Lee8da4c3c2014-07-16 10:11:42 -07001199 try {
1200 String callId = (String) args.arg1;
Evan Charltonbf11f982014-07-20 22:06:28 -07001201 int videoState = args.argi1;
Tyler Gunnbe74de02014-08-29 14:51:48 -07001202 answerVideo(callId, videoState);
Andrew Lee8da4c3c2014-07-16 10:11:42 -07001203 } finally {
1204 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001205 Log.endSession();
Andrew Lee8da4c3c2014-07-16 10:11:42 -07001206 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001207 break;
Andrew Lee8da4c3c2014-07-16 10:11:42 -07001208 }
Pooja Jaind34698d2017-12-28 14:15:31 +05301209 case MSG_DEFLECT: {
1210 SomeArgs args = (SomeArgs) msg.obj;
1211 Log.continueSession((Session) args.arg3, SESSION_HANDLER + SESSION_DEFLECT);
1212 try {
1213 deflect((String) args.arg1, (Uri) args.arg2);
1214 } finally {
1215 args.recycle();
1216 Log.endSession();
1217 }
1218 break;
1219 }
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001220 case MSG_REJECT: {
1221 SomeArgs args = (SomeArgs) msg.obj;
1222 Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_REJECT);
1223 try {
1224 reject((String) args.arg1);
1225 } finally {
1226 args.recycle();
1227 Log.endSession();
1228 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001229 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001230 }
Tyler Gunnfacfdee2020-01-23 13:10:37 -08001231 case MSG_REJECT_WITH_REASON: {
1232 SomeArgs args = (SomeArgs) msg.obj;
1233 Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_REJECT);
1234 try {
1235 reject((String) args.arg1, args.argi1);
1236 } finally {
1237 args.recycle();
1238 Log.endSession();
1239 }
1240 break;
1241 }
Bryce Lee81901682015-08-28 16:38:02 -07001242 case MSG_REJECT_WITH_MESSAGE: {
1243 SomeArgs args = (SomeArgs) msg.obj;
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001244 Log.continueSession((Session) args.arg3,
1245 SESSION_HANDLER + SESSION_REJECT_MESSAGE);
Bryce Lee81901682015-08-28 16:38:02 -07001246 try {
1247 reject((String) args.arg1, (String) args.arg2);
1248 } finally {
1249 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001250 Log.endSession();
Bryce Lee81901682015-08-28 16:38:02 -07001251 }
1252 break;
1253 }
Ravi Palurif4b38e72020-02-05 12:35:41 +05301254 case MSG_EXPLICIT_CALL_TRANSFER: {
1255 SomeArgs args = (SomeArgs) msg.obj;
1256 Log.continueSession((Session) args.arg3, SESSION_HANDLER + SESSION_TRANSFER);
1257 try {
1258 final boolean isConfirmationRequired = args.argi1 == 1;
1259 transfer((String) args.arg1, (Uri) args.arg2, isConfirmationRequired);
1260 } finally {
1261 args.recycle();
1262 Log.endSession();
1263 }
1264 break;
1265 }
1266 case MSG_EXPLICIT_CALL_TRANSFER_CONSULTATIVE: {
1267 SomeArgs args = (SomeArgs) msg.obj;
1268 Log.continueSession(
1269 (Session) args.arg3, SESSION_HANDLER + SESSION_CONSULTATIVE_TRANSFER);
1270 try {
1271 consultativeTransfer((String) args.arg1, (String) args.arg2);
1272 } finally {
1273 args.recycle();
1274 Log.endSession();
1275 }
1276 break;
1277 }
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001278 case MSG_DISCONNECT: {
1279 SomeArgs args = (SomeArgs) msg.obj;
1280 Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_DISCONNECT);
1281 try {
1282 disconnect((String) args.arg1);
1283 } finally {
1284 args.recycle();
1285 Log.endSession();
1286 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001287 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001288 }
1289 case MSG_SILENCE: {
1290 SomeArgs args = (SomeArgs) msg.obj;
1291 Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_SILENCE);
1292 try {
1293 silence((String) args.arg1);
1294 } finally {
1295 args.recycle();
1296 Log.endSession();
1297 }
Bryce Leecac50772015-11-17 15:13:29 -08001298 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001299 }
1300 case MSG_HOLD: {
1301 SomeArgs args = (SomeArgs) msg.obj;
1302 Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_REJECT);
1303 try {
1304 hold((String) args.arg1);
1305 } finally {
1306 args.recycle();
1307 Log.endSession();
1308 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001309 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001310 }
1311 case MSG_UNHOLD: {
1312 SomeArgs args = (SomeArgs) msg.obj;
1313 Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_UNHOLD);
1314 try {
1315 unhold((String) args.arg1);
1316 } finally {
1317 args.recycle();
1318 Log.endSession();
1319 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001320 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001321 }
Yorke Lee4af59352015-05-13 14:14:54 -07001322 case MSG_ON_CALL_AUDIO_STATE_CHANGED: {
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001323 SomeArgs args = (SomeArgs) msg.obj;
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001324 Log.continueSession((Session) args.arg3,
1325 SESSION_HANDLER + SESSION_CALL_AUDIO_SC);
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001326 try {
1327 String callId = (String) args.arg1;
Yorke Lee4af59352015-05-13 14:14:54 -07001328 CallAudioState audioState = (CallAudioState) args.arg2;
1329 onCallAudioStateChanged(callId, new CallAudioState(audioState));
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001330 } finally {
1331 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001332 Log.endSession();
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001333 }
1334 break;
1335 }
Grace Jiae99fde92021-01-19 14:58:01 -08001336 case MSG_ON_USING_ALTERNATIVE_UI: {
1337 SomeArgs args = (SomeArgs) msg.obj;
1338 Log.continueSession((Session) args.arg3,
1339 SESSION_HANDLER + SESSION_USING_ALTERNATIVE_UI);
1340 try {
1341 String callId = (String) args.arg1;
1342 boolean isUsingAlternativeUi = (boolean) args.arg2;
1343 onUsingAlternativeUi(callId, isUsingAlternativeUi);
1344 } finally {
1345 args.recycle();
1346 Log.endSession();
1347 }
1348 break;
1349 }
1350 case MSG_ON_TRACKED_BY_NON_UI_SERVICE: {
1351 SomeArgs args = (SomeArgs) msg.obj;
1352 Log.continueSession((Session) args.arg3,
1353 SESSION_HANDLER + SESSION_TRACKED_BY_NON_UI_SERVICE);
1354 try {
1355 String callId = (String) args.arg1;
1356 boolean isTracked = (boolean) args.arg2;
1357 onTrackedByNonUiService(callId, isTracked);
1358 } finally {
1359 args.recycle();
1360 Log.endSession();
1361 }
1362 break;
1363 }
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001364 case MSG_PLAY_DTMF_TONE: {
1365 SomeArgs args = (SomeArgs) msg.obj;
1366 try {
1367 Log.continueSession((Session) args.arg3,
1368 SESSION_HANDLER + SESSION_PLAY_DTMF);
1369 playDtmfTone((String) args.arg2, (char) args.arg1);
1370 } finally {
1371 args.recycle();
1372 Log.endSession();
1373 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001374 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001375 }
1376 case MSG_STOP_DTMF_TONE: {
1377 SomeArgs args = (SomeArgs) msg.obj;
1378 try {
1379 Log.continueSession((Session) args.arg2,
1380 SESSION_HANDLER + SESSION_STOP_DTMF);
1381 stopDtmfTone((String) args.arg1);
1382 } finally {
1383 args.recycle();
1384 Log.endSession();
1385 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001386 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001387 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001388 case MSG_CONFERENCE: {
1389 SomeArgs args = (SomeArgs) msg.obj;
1390 try {
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001391 Log.continueSession((Session) args.arg3,
1392 SESSION_HANDLER + SESSION_CONFERENCE);
Santos Cordon823fd3c2014-08-07 18:35:18 -07001393 String callId1 = (String) args.arg1;
1394 String callId2 = (String) args.arg2;
1395 conference(callId1, callId2);
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001396 } finally {
1397 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001398 Log.endSession();
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001399 }
1400 break;
1401 }
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001402 case MSG_SPLIT_FROM_CONFERENCE: {
1403 SomeArgs args = (SomeArgs) msg.obj;
1404 try {
1405 Log.continueSession((Session) args.arg2,
1406 SESSION_HANDLER + SESSION_SPLIT_CONFERENCE);
1407 splitFromConference((String) args.arg1);
1408 } finally {
1409 args.recycle();
1410 Log.endSession();
1411 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001412 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001413 }
1414 case MSG_MERGE_CONFERENCE: {
1415 SomeArgs args = (SomeArgs) msg.obj;
1416 try {
1417 Log.continueSession((Session) args.arg2,
1418 SESSION_HANDLER + SESSION_MERGE_CONFERENCE);
1419 mergeConference((String) args.arg1);
1420 } finally {
1421 args.recycle();
1422 Log.endSession();
1423 }
Santos Cordona4868042014-09-04 17:39:22 -07001424 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001425 }
1426 case MSG_SWAP_CONFERENCE: {
1427 SomeArgs args = (SomeArgs) msg.obj;
1428 try {
1429 Log.continueSession((Session) args.arg2,
1430 SESSION_HANDLER + SESSION_SWAP_CONFERENCE);
1431 swapConference((String) args.arg1);
1432 } finally {
1433 args.recycle();
1434 Log.endSession();
1435 }
Santos Cordona4868042014-09-04 17:39:22 -07001436 break;
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001437 }
Ravi Paluri404babb2020-01-23 19:02:44 +05301438 case MSG_ADD_PARTICIPANT: {
1439 SomeArgs args = (SomeArgs) msg.obj;
1440 try {
1441 Log.continueSession((Session) args.arg3,
1442 SESSION_HANDLER + SESSION_ADD_PARTICIPANT);
1443 addConferenceParticipants((String) args.arg1, (List<Uri>)args.arg2);
1444 } finally {
1445 args.recycle();
1446 Log.endSession();
1447 }
1448 break;
1449 }
1450
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001451 case MSG_ON_POST_DIAL_CONTINUE: {
1452 SomeArgs args = (SomeArgs) msg.obj;
1453 try {
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001454 Log.continueSession((Session) args.arg2,
1455 SESSION_HANDLER + SESSION_POST_DIAL_CONT);
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001456 String callId = (String) args.arg1;
1457 boolean proceed = (args.argi1 == 1);
1458 onPostDialContinue(callId, proceed);
1459 } finally {
1460 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001461 Log.endSession();
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001462 }
1463 break;
1464 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001465 case MSG_PULL_EXTERNAL_CALL: {
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001466 SomeArgs args = (SomeArgs) msg.obj;
1467 try {
1468 Log.continueSession((Session) args.arg2,
1469 SESSION_HANDLER + SESSION_PULL_EXTERNAL_CALL);
1470 pullExternalCall((String) args.arg1);
1471 } finally {
1472 args.recycle();
1473 Log.endSession();
1474 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001475 break;
1476 }
1477 case MSG_SEND_CALL_EVENT: {
1478 SomeArgs args = (SomeArgs) msg.obj;
1479 try {
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001480 Log.continueSession((Session) args.arg4,
1481 SESSION_HANDLER + SESSION_SEND_CALL_EVENT);
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001482 String callId = (String) args.arg1;
1483 String event = (String) args.arg2;
1484 Bundle extras = (Bundle) args.arg3;
1485 sendCallEvent(callId, event, extras);
1486 } finally {
1487 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001488 Log.endSession();
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001489 }
1490 break;
1491 }
Hall Liu49cabcc2021-01-15 11:41:48 -08001492 case MSG_ON_CALL_FILTERING_COMPLETED: {
1493 SomeArgs args = (SomeArgs) msg.obj;
1494 try {
Hall Liu73903142021-02-18 18:41:41 -08001495 Log.continueSession((Session) args.arg3,
Hall Liu49cabcc2021-01-15 11:41:48 -08001496 SESSION_HANDLER + SESSION_CALL_FILTERING_COMPLETED);
1497 String callId = (String) args.arg1;
Hall Liu73903142021-02-18 18:41:41 -08001498 Connection.CallFilteringCompletionInfo completionInfo =
1499 (Connection.CallFilteringCompletionInfo) args.arg2;
1500 onCallFilteringCompleted(callId, completionInfo);
Hall Liu49cabcc2021-01-15 11:41:48 -08001501 } finally {
1502 args.recycle();
1503 Log.endSession();
1504 }
1505 break;
1506 }
Tyler Gunn79bc1ec2018-01-22 15:17:54 -08001507 case MSG_HANDOVER_COMPLETE: {
1508 SomeArgs args = (SomeArgs) msg.obj;
1509 try {
1510 Log.continueSession((Session) args.arg2,
1511 SESSION_HANDLER + SESSION_HANDOVER_COMPLETE);
1512 String callId = (String) args.arg1;
1513 notifyHandoverComplete(callId);
1514 } finally {
1515 args.recycle();
1516 Log.endSession();
1517 }
1518 break;
1519 }
Tyler Gunndee56a82016-03-23 16:06:34 -07001520 case MSG_ON_EXTRAS_CHANGED: {
1521 SomeArgs args = (SomeArgs) msg.obj;
1522 try {
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001523 Log.continueSession((Session) args.arg3,
1524 SESSION_HANDLER + SESSION_EXTRAS_CHANGED);
Tyler Gunndee56a82016-03-23 16:06:34 -07001525 String callId = (String) args.arg1;
1526 Bundle extras = (Bundle) args.arg2;
1527 handleExtrasChanged(callId, extras);
1528 } finally {
1529 args.recycle();
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001530 Log.endSession();
Tyler Gunndee56a82016-03-23 16:06:34 -07001531 }
1532 break;
1533 }
Hall Liub64ac4c2017-02-06 10:49:48 -08001534 case MSG_ON_START_RTT: {
1535 SomeArgs args = (SomeArgs) msg.obj;
1536 try {
1537 Log.continueSession((Session) args.arg3,
1538 SESSION_HANDLER + SESSION_START_RTT);
1539 String callId = (String) args.arg1;
1540 Connection.RttTextStream rttTextStream =
1541 (Connection.RttTextStream) args.arg2;
1542 startRtt(callId, rttTextStream);
1543 } finally {
1544 args.recycle();
1545 Log.endSession();
1546 }
1547 break;
1548 }
1549 case MSG_ON_STOP_RTT: {
1550 SomeArgs args = (SomeArgs) msg.obj;
1551 try {
1552 Log.continueSession((Session) args.arg2,
1553 SESSION_HANDLER + SESSION_STOP_RTT);
1554 String callId = (String) args.arg1;
1555 stopRtt(callId);
1556 } finally {
1557 args.recycle();
1558 Log.endSession();
1559 }
1560 break;
1561 }
1562 case MSG_RTT_UPGRADE_RESPONSE: {
1563 SomeArgs args = (SomeArgs) msg.obj;
1564 try {
1565 Log.continueSession((Session) args.arg3,
1566 SESSION_HANDLER + SESSION_RTT_UPGRADE_RESPONSE);
1567 String callId = (String) args.arg1;
1568 Connection.RttTextStream rttTextStream =
1569 (Connection.RttTextStream) args.arg2;
1570 handleRttUpgradeResponse(callId, rttTextStream);
1571 } finally {
1572 args.recycle();
1573 Log.endSession();
1574 }
1575 break;
1576 }
Pengquan Meng731c1a32017-11-21 18:01:13 -08001577 case MSG_CONNECTION_SERVICE_FOCUS_GAINED:
1578 onConnectionServiceFocusGained();
1579 break;
1580 case MSG_CONNECTION_SERVICE_FOCUS_LOST:
1581 onConnectionServiceFocusLost();
1582 break;
Junhoedf3d822022-11-24 09:26:37 +00001583 case MSG_ON_CALL_ENDPOINT_CHANGED: {
1584 SomeArgs args = (SomeArgs) msg.obj;
1585 Log.continueSession((Session) args.arg3,
1586 SESSION_HANDLER + SESSION_CALL_AUDIO_SC);
1587 try {
1588 String callId = (String) args.arg1;
1589 CallEndpoint callEndpoint = (CallEndpoint) args.arg2;
1590 onCallEndpointChanged(callId, callEndpoint);
1591 } finally {
1592 args.recycle();
1593 Log.endSession();
1594 }
1595 break;
1596 }
1597 case MSG_ON_AVAILABLE_CALL_ENDPOINTS_CHANGED: {
1598 SomeArgs args = (SomeArgs) msg.obj;
1599 Log.continueSession((Session) args.arg3,
1600 SESSION_HANDLER + SESSION_CALL_AUDIO_SC);
1601 try {
1602 String callId = (String) args.arg1;
1603 List<CallEndpoint> availableCallEndpoints = (List<CallEndpoint>) args.arg2;
1604 onAvailableCallEndpointsChanged(callId, availableCallEndpoints);
1605 } finally {
1606 args.recycle();
1607 Log.endSession();
1608 }
1609 break;
1610 }
1611 case MSG_ON_MUTE_STATE_CHANGED: {
1612 SomeArgs args = (SomeArgs) msg.obj;
1613 Log.continueSession((Session) args.arg3,
1614 SESSION_HANDLER + SESSION_CALL_AUDIO_SC);
1615 try {
1616 String callId = (String) args.arg1;
1617 boolean isMuted = (boolean) args.arg2;
1618 onMuteStateChanged(callId, isMuted);
1619 } finally {
1620 args.recycle();
1621 Log.endSession();
1622 }
1623 break;
1624 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001625 default:
1626 break;
1627 }
1628 }
1629 };
1630
Santos Cordon823fd3c2014-08-07 18:35:18 -07001631 private final Conference.Listener mConferenceListener = new Conference.Listener() {
1632 @Override
1633 public void onStateChanged(Conference conference, int oldState, int newState) {
1634 String id = mIdByConference.get(conference);
1635 switch (newState) {
Ravi Paluri80aa2142019-12-02 11:57:37 +05301636 case Connection.STATE_RINGING:
1637 mAdapter.setRinging(id);
1638 break;
1639 case Connection.STATE_DIALING:
1640 mAdapter.setDialing(id);
1641 break;
Santos Cordon823fd3c2014-08-07 18:35:18 -07001642 case Connection.STATE_ACTIVE:
1643 mAdapter.setActive(id);
1644 break;
1645 case Connection.STATE_HOLDING:
1646 mAdapter.setOnHold(id);
1647 break;
1648 case Connection.STATE_DISCONNECTED:
1649 // handled by onDisconnected
1650 break;
1651 }
1652 }
1653
1654 @Override
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001655 public void onDisconnected(Conference conference, DisconnectCause disconnectCause) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07001656 String id = mIdByConference.get(conference);
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001657 mAdapter.setDisconnected(id, disconnectCause);
Santos Cordon823fd3c2014-08-07 18:35:18 -07001658 }
1659
1660 @Override
1661 public void onConnectionAdded(Conference conference, Connection connection) {
1662 }
1663
1664 @Override
1665 public void onConnectionRemoved(Conference conference, Connection connection) {
1666 }
1667
1668 @Override
Ihab Awad50e35062014-09-30 09:17:03 -07001669 public void onConferenceableConnectionsChanged(
1670 Conference conference, List<Connection> conferenceableConnections) {
1671 mAdapter.setConferenceableConnections(
1672 mIdByConference.get(conference),
1673 createConnectionIdList(conferenceableConnections));
1674 }
1675
1676 @Override
Santos Cordon823fd3c2014-08-07 18:35:18 -07001677 public void onDestroyed(Conference conference) {
1678 removeConference(conference);
1679 }
1680
1681 @Override
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001682 public void onConnectionCapabilitiesChanged(
1683 Conference conference,
1684 int connectionCapabilities) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07001685 String id = mIdByConference.get(conference);
1686 Log.d(this, "call capabilities: conference: %s",
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001687 Connection.capabilitiesToString(connectionCapabilities));
1688 mAdapter.setConnectionCapabilities(id, connectionCapabilities);
Santos Cordon823fd3c2014-08-07 18:35:18 -07001689 }
Rekha Kumar07366812015-03-24 16:42:31 -07001690
1691 @Override
Tyler Gunn720c6642016-03-22 09:02:47 -07001692 public void onConnectionPropertiesChanged(
1693 Conference conference,
1694 int connectionProperties) {
1695 String id = mIdByConference.get(conference);
1696 Log.d(this, "call capabilities: conference: %s",
1697 Connection.propertiesToString(connectionProperties));
1698 mAdapter.setConnectionProperties(id, connectionProperties);
1699 }
1700
1701 @Override
Rekha Kumar07366812015-03-24 16:42:31 -07001702 public void onVideoStateChanged(Conference c, int videoState) {
1703 String id = mIdByConference.get(c);
1704 Log.d(this, "onVideoStateChanged set video state %d", videoState);
1705 mAdapter.setVideoState(id, videoState);
1706 }
1707
1708 @Override
1709 public void onVideoProviderChanged(Conference c, Connection.VideoProvider videoProvider) {
1710 String id = mIdByConference.get(c);
1711 Log.d(this, "onVideoProviderChanged: Connection: %s, VideoProvider: %s", c,
1712 videoProvider);
1713 mAdapter.setVideoProvider(id, videoProvider);
1714 }
Andrew Lee0f51da32015-04-16 13:11:55 -07001715
1716 @Override
Andrew Leeedc625f2015-04-14 13:38:12 -07001717 public void onStatusHintsChanged(Conference conference, StatusHints statusHints) {
1718 String id = mIdByConference.get(conference);
Tyler Gunndee56a82016-03-23 16:06:34 -07001719 if (id != null) {
1720 mAdapter.setStatusHints(id, statusHints);
1721 }
Andrew Leeedc625f2015-04-14 13:38:12 -07001722 }
Santos Cordon6b7f9552015-05-27 17:21:45 -07001723
1724 @Override
Tyler Gunndee56a82016-03-23 16:06:34 -07001725 public void onExtrasChanged(Conference c, Bundle extras) {
1726 String id = mIdByConference.get(c);
1727 if (id != null) {
1728 mAdapter.putExtras(id, extras);
1729 }
1730 }
1731
1732 @Override
1733 public void onExtrasRemoved(Conference c, List<String> keys) {
1734 String id = mIdByConference.get(c);
1735 if (id != null) {
1736 mAdapter.removeExtras(id, keys);
1737 }
Santos Cordon6b7f9552015-05-27 17:21:45 -07001738 }
Tyler Gunn68a73a42018-10-03 15:38:57 -07001739
1740 @Override
1741 public void onConferenceStateChanged(Conference c, boolean isConference) {
1742 String id = mIdByConference.get(c);
1743 if (id != null) {
1744 mAdapter.setConferenceState(id, isConference);
1745 }
1746 }
1747
1748 @Override
Brad Ebingere0c12f42020-04-08 16:25:12 -07001749 public void onCallDirectionChanged(Conference c, int direction) {
1750 String id = mIdByConference.get(c);
1751 if (id != null) {
1752 mAdapter.setCallDirection(id, direction);
1753 }
1754 }
1755
1756 @Override
Tyler Gunn68a73a42018-10-03 15:38:57 -07001757 public void onAddressChanged(Conference c, Uri newAddress, int presentation) {
1758 String id = mIdByConference.get(c);
1759 if (id != null) {
1760 mAdapter.setAddress(id, newAddress, presentation);
1761 }
1762 }
1763
1764 @Override
1765 public void onCallerDisplayNameChanged(Conference c, String callerDisplayName,
1766 int presentation) {
1767 String id = mIdByConference.get(c);
1768 if (id != null) {
1769 mAdapter.setCallerDisplayName(id, callerDisplayName, presentation);
1770 }
1771 }
Hall Liuc9bc1c62019-04-16 14:00:55 -07001772
1773 @Override
1774 public void onConnectionEvent(Conference c, String event, Bundle extras) {
1775 String id = mIdByConference.get(c);
1776 if (id != null) {
1777 mAdapter.onConnectionEvent(id, event, extras);
1778 }
1779 }
Ravi Paluri80aa2142019-12-02 11:57:37 +05301780
1781 @Override
1782 public void onRingbackRequested(Conference c, boolean ringback) {
1783 String id = mIdByConference.get(c);
1784 Log.d(this, "Adapter conference onRingback %b", ringback);
1785 mAdapter.setRingbackRequested(id, ringback);
1786 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07001787 };
1788
Ihab Awad542e0ea2014-05-16 10:22:16 -07001789 private final Connection.Listener mConnectionListener = new Connection.Listener() {
1790 @Override
1791 public void onStateChanged(Connection c, int state) {
1792 String id = mIdByConnection.get(c);
Ihab Awad42b30e12014-05-22 09:49:34 -07001793 Log.d(this, "Adapter set state %s %s", id, Connection.stateToString(state));
Ihab Awad542e0ea2014-05-16 10:22:16 -07001794 switch (state) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001795 case Connection.STATE_ACTIVE:
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001796 mAdapter.setActive(id);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001797 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001798 case Connection.STATE_DIALING:
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001799 mAdapter.setDialing(id);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001800 break;
Tyler Gunnc96b5e02016-07-07 22:53:57 -07001801 case Connection.STATE_PULLING_CALL:
1802 mAdapter.setPulling(id);
1803 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001804 case Connection.STATE_DISCONNECTED:
Ihab Awad542e0ea2014-05-16 10:22:16 -07001805 // Handled in onDisconnected()
1806 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001807 case Connection.STATE_HOLDING:
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001808 mAdapter.setOnHold(id);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001809 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001810 case Connection.STATE_NEW:
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001811 // Nothing to tell Telecom
Ihab Awad542e0ea2014-05-16 10:22:16 -07001812 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001813 case Connection.STATE_RINGING:
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001814 mAdapter.setRinging(id);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001815 break;
1816 }
1817 }
1818
1819 @Override
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001820 public void onDisconnected(Connection c, DisconnectCause disconnectCause) {
Ihab Awad542e0ea2014-05-16 10:22:16 -07001821 String id = mIdByConnection.get(c);
Andrew Lee26786392014-09-16 18:14:59 -07001822 Log.d(this, "Adapter set disconnected %s", disconnectCause);
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001823 mAdapter.setDisconnected(id, disconnectCause);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001824 }
1825
1826 @Override
Tyler Gunnaa07df82014-07-17 07:50:22 -07001827 public void onVideoStateChanged(Connection c, int videoState) {
1828 String id = mIdByConnection.get(c);
1829 Log.d(this, "Adapter set video state %d", videoState);
1830 mAdapter.setVideoState(id, videoState);
1831 }
1832
1833 @Override
Andrew Lee100e2932014-09-08 15:34:24 -07001834 public void onAddressChanged(Connection c, Uri address, int presentation) {
Sailesh Nepal61203862014-07-11 14:50:13 -07001835 String id = mIdByConnection.get(c);
Andrew Lee100e2932014-09-08 15:34:24 -07001836 mAdapter.setAddress(id, address, presentation);
Sailesh Nepal61203862014-07-11 14:50:13 -07001837 }
1838
1839 @Override
1840 public void onCallerDisplayNameChanged(
1841 Connection c, String callerDisplayName, int presentation) {
1842 String id = mIdByConnection.get(c);
1843 mAdapter.setCallerDisplayName(id, callerDisplayName, presentation);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001844 }
1845
1846 @Override
Ihab Awad542e0ea2014-05-16 10:22:16 -07001847 public void onDestroyed(Connection c) {
1848 removeConnection(c);
1849 }
Ihab Awadf8358972014-05-28 16:46:42 -07001850
1851 @Override
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001852 public void onPostDialWait(Connection c, String remaining) {
Sailesh Nepal091768c2014-06-30 15:15:23 -07001853 String id = mIdByConnection.get(c);
1854 Log.d(this, "Adapter onPostDialWait %s, %s", c, remaining);
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001855 mAdapter.onPostDialWait(id, remaining);
Sailesh Nepal091768c2014-06-30 15:15:23 -07001856 }
1857
1858 @Override
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001859 public void onPostDialChar(Connection c, char nextChar) {
1860 String id = mIdByConnection.get(c);
1861 Log.d(this, "Adapter onPostDialChar %s, %s", c, nextChar);
1862 mAdapter.onPostDialChar(id, nextChar);
1863 }
1864
1865 @Override
Andrew Lee100e2932014-09-08 15:34:24 -07001866 public void onRingbackRequested(Connection c, boolean ringback) {
Ihab Awadf8358972014-05-28 16:46:42 -07001867 String id = mIdByConnection.get(c);
1868 Log.d(this, "Adapter onRingback %b", ringback);
Andrew Lee100e2932014-09-08 15:34:24 -07001869 mAdapter.setRingbackRequested(id, ringback);
Ihab Awadf8358972014-05-28 16:46:42 -07001870 }
Santos Cordonb6939982014-06-04 20:20:58 -07001871
1872 @Override
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001873 public void onConnectionCapabilitiesChanged(Connection c, int capabilities) {
Santos Cordonb6939982014-06-04 20:20:58 -07001874 String id = mIdByConnection.get(c);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001875 Log.d(this, "capabilities: parcelableconnection: %s",
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001876 Connection.capabilitiesToString(capabilities));
1877 mAdapter.setConnectionCapabilities(id, capabilities);
Santos Cordonb6939982014-06-04 20:20:58 -07001878 }
1879
Santos Cordonb6939982014-06-04 20:20:58 -07001880 @Override
Tyler Gunn720c6642016-03-22 09:02:47 -07001881 public void onConnectionPropertiesChanged(Connection c, int properties) {
1882 String id = mIdByConnection.get(c);
1883 Log.d(this, "properties: parcelableconnection: %s",
1884 Connection.propertiesToString(properties));
1885 mAdapter.setConnectionProperties(id, properties);
1886 }
1887
1888 @Override
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001889 public void onVideoProviderChanged(Connection c, Connection.VideoProvider videoProvider) {
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07001890 String id = mIdByConnection.get(c);
Rekha Kumar07366812015-03-24 16:42:31 -07001891 Log.d(this, "onVideoProviderChanged: Connection: %s, VideoProvider: %s", c,
1892 videoProvider);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001893 mAdapter.setVideoProvider(id, videoProvider);
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07001894 }
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001895
1896 @Override
Sailesh Nepal001bbbb2014-07-15 14:40:39 -07001897 public void onAudioModeIsVoipChanged(Connection c, boolean isVoip) {
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001898 String id = mIdByConnection.get(c);
Andrew Lee100e2932014-09-08 15:34:24 -07001899 mAdapter.setIsVoipAudioMode(id, isVoip);
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001900 }
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001901
1902 @Override
Sailesh Nepal001bbbb2014-07-15 14:40:39 -07001903 public void onStatusHintsChanged(Connection c, StatusHints statusHints) {
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001904 String id = mIdByConnection.get(c);
1905 mAdapter.setStatusHints(id, statusHints);
1906 }
Sailesh Nepal2ab88cc2014-07-18 14:49:18 -07001907
1908 @Override
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001909 public void onConferenceablesChanged(
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001910 Connection connection, List<Conferenceable> conferenceables) {
Ihab Awadb8e85c72014-08-23 20:34:57 -07001911 mAdapter.setConferenceableConnections(
1912 mIdByConnection.get(connection),
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001913 createIdList(conferenceables));
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001914 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07001915
1916 @Override
1917 public void onConferenceChanged(Connection connection, Conference conference) {
1918 String id = mIdByConnection.get(connection);
1919 if (id != null) {
1920 String conferenceId = null;
1921 if (conference != null) {
1922 conferenceId = mIdByConference.get(conference);
1923 }
1924 mAdapter.setIsConferenced(id, conferenceId);
1925 }
1926 }
Anthony Lee17455a32015-04-24 15:25:29 -07001927
1928 @Override
1929 public void onConferenceMergeFailed(Connection connection) {
1930 String id = mIdByConnection.get(connection);
1931 if (id != null) {
1932 mAdapter.onConferenceMergeFailed(id);
1933 }
1934 }
Santos Cordon6b7f9552015-05-27 17:21:45 -07001935
1936 @Override
Tyler Gunndee56a82016-03-23 16:06:34 -07001937 public void onExtrasChanged(Connection c, Bundle extras) {
1938 String id = mIdByConnection.get(c);
Santos Cordon6b7f9552015-05-27 17:21:45 -07001939 if (id != null) {
Tyler Gunndee56a82016-03-23 16:06:34 -07001940 mAdapter.putExtras(id, extras);
Santos Cordon6b7f9552015-05-27 17:21:45 -07001941 }
1942 }
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001943
Tyler Gunnf5035432017-01-09 09:43:12 -08001944 @Override
Tyler Gunndee56a82016-03-23 16:06:34 -07001945 public void onExtrasRemoved(Connection c, List<String> keys) {
1946 String id = mIdByConnection.get(c);
1947 if (id != null) {
1948 mAdapter.removeExtras(id, keys);
1949 }
1950 }
1951
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08001952 @Override
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001953 public void onConnectionEvent(Connection connection, String event, Bundle extras) {
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08001954 String id = mIdByConnection.get(connection);
1955 if (id != null) {
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001956 mAdapter.onConnectionEvent(id, event, extras);
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08001957 }
1958 }
Tyler Gunnf5035432017-01-09 09:43:12 -08001959
1960 @Override
Hall Liua98f58b52017-11-07 17:59:28 -08001961 public void onAudioRouteChanged(Connection c, int audioRoute, String bluetoothAddress) {
Tyler Gunnf5035432017-01-09 09:43:12 -08001962 String id = mIdByConnection.get(c);
1963 if (id != null) {
Hall Liua98f58b52017-11-07 17:59:28 -08001964 mAdapter.setAudioRoute(id, audioRoute, bluetoothAddress);
Tyler Gunnf5035432017-01-09 09:43:12 -08001965 }
1966 }
Hall Liub64ac4c2017-02-06 10:49:48 -08001967
1968 @Override
1969 public void onRttInitiationSuccess(Connection c) {
1970 String id = mIdByConnection.get(c);
1971 if (id != null) {
1972 mAdapter.onRttInitiationSuccess(id);
1973 }
1974 }
1975
1976 @Override
1977 public void onRttInitiationFailure(Connection c, int reason) {
1978 String id = mIdByConnection.get(c);
1979 if (id != null) {
1980 mAdapter.onRttInitiationFailure(id, reason);
1981 }
1982 }
1983
1984 @Override
1985 public void onRttSessionRemotelyTerminated(Connection c) {
1986 String id = mIdByConnection.get(c);
1987 if (id != null) {
1988 mAdapter.onRttSessionRemotelyTerminated(id);
1989 }
1990 }
1991
1992 @Override
1993 public void onRemoteRttRequest(Connection c) {
1994 String id = mIdByConnection.get(c);
1995 if (id != null) {
1996 mAdapter.onRemoteRttRequest(id);
1997 }
1998 }
Srikanth Chintalafcb15012017-05-04 20:58:34 +05301999
2000 @Override
2001 public void onPhoneAccountChanged(Connection c, PhoneAccountHandle pHandle) {
2002 String id = mIdByConnection.get(c);
2003 if (id != null) {
2004 mAdapter.onPhoneAccountChanged(id, pHandle);
2005 }
2006 }
Mengjun Leng25707742017-07-04 11:10:37 +08002007
2008 public void onConnectionTimeReset(Connection c) {
2009 String id = mIdByConnection.get(c);
2010 if (id != null) {
2011 mAdapter.resetConnectionTime(id);
2012 }
2013 }
Junhoedf3d822022-11-24 09:26:37 +00002014
2015 @Override
2016 public void onEndpointChanged(Connection c, CallEndpoint endpoint, Executor executor,
2017 OutcomeReceiver<Void, CallEndpointException> callback) {
2018 String id = mIdByConnection.get(c);
2019 if (id != null) {
2020 mAdapter.requestCallEndpointChange(id, endpoint, executor, callback);
2021 }
2022 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002023 };
2024
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002025 /** {@inheritDoc} */
Ihab Awad542e0ea2014-05-16 10:22:16 -07002026 @Override
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002027 public final IBinder onBind(Intent intent) {
Hall Liueb7c9ea2021-03-09 20:24:50 -08002028 onBindClient(intent);
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002029 return mBinder;
2030 }
2031
Santos Cordon29f2f2e2014-09-11 19:50:24 -07002032 /** {@inheritDoc} */
2033 @Override
2034 public boolean onUnbind(Intent intent) {
2035 endAllConnections();
2036 return super.onUnbind(intent);
2037 }
2038
Hall Liueb7c9ea2021-03-09 20:24:50 -08002039 /**
2040 * Used for testing to let the test suite know when the connection service has been bound.
2041 * @hide
2042 */
2043 @TestApi
2044 public void onBindClient(@Nullable Intent intent) {
2045 }
Ravi Paluri80aa2142019-12-02 11:57:37 +05302046
2047 /**
2048 * This can be used by telecom to either create a new outgoing conference call or attach
2049 * to an existing incoming conference call. In either case, telecom will cycle through a
2050 * set of services and call createConference until a connection service cancels the process
2051 * or completes it successfully.
2052 */
2053 private void createConference(
2054 final PhoneAccountHandle callManagerAccount,
2055 final String callId,
2056 final ConnectionRequest request,
2057 boolean isIncoming,
2058 boolean isUnknown) {
2059
2060 Conference conference = null;
2061 conference = isIncoming ? onCreateIncomingConference(callManagerAccount, request)
2062 : onCreateOutgoingConference(callManagerAccount, request);
2063
2064 Log.d(this, "createConference, conference: %s", conference);
2065 if (conference == null) {
2066 Log.i(this, "createConference, implementation returned null conference.");
2067 conference = Conference.createFailedConference(
2068 new DisconnectCause(DisconnectCause.ERROR, "IMPL_RETURNED_NULL_CONFERENCE"),
2069 request.getAccountHandle());
2070 }
Tyler Gunnc59fd0c2020-04-17 14:03:35 -07002071
2072 Bundle extras = request.getExtras();
2073 Bundle newExtras = new Bundle();
2074 newExtras.putString(Connection.EXTRA_ORIGINAL_CONNECTION_ID, callId);
2075 if (extras != null) {
2076 // If the request originated from a remote connection service, we will add some
2077 // tracking information that Telecom can use to keep informed of which package
2078 // made the remote request, and which remote connection service was used.
2079 if (extras.containsKey(Connection.EXTRA_REMOTE_CONNECTION_ORIGINATING_PACKAGE_NAME)) {
2080 newExtras.putString(
2081 Connection.EXTRA_REMOTE_CONNECTION_ORIGINATING_PACKAGE_NAME,
2082 extras.getString(
2083 Connection.EXTRA_REMOTE_CONNECTION_ORIGINATING_PACKAGE_NAME));
2084 newExtras.putParcelable(Connection.EXTRA_REMOTE_PHONE_ACCOUNT_HANDLE,
2085 request.getAccountHandle());
2086 }
Ravi Paluri80aa2142019-12-02 11:57:37 +05302087 }
Tyler Gunnc59fd0c2020-04-17 14:03:35 -07002088 conference.putExtras(newExtras);
2089
Ravi Paluri80aa2142019-12-02 11:57:37 +05302090 mConferenceById.put(callId, conference);
2091 mIdByConference.put(conference, callId);
Tyler Gunn460360d2020-07-29 10:21:45 -07002092
Ravi Paluri80aa2142019-12-02 11:57:37 +05302093 conference.addListener(mConferenceListener);
Brad Ebinger0ae44ed2020-04-09 15:30:57 -07002094 ParcelableConference parcelableConference = new ParcelableConference.Builder(
2095 request.getAccountHandle(), conference.getState())
2096 .setConnectionCapabilities(conference.getConnectionCapabilities())
2097 .setConnectionProperties(conference.getConnectionProperties())
2098 .setVideoAttributes(conference.getVideoProvider() == null
2099 ? null : conference.getVideoProvider().getInterface(),
2100 conference.getVideoState())
2101 .setConnectTimeMillis(conference.getConnectTimeMillis(),
2102 conference.getConnectionStartElapsedRealtimeMillis())
2103 .setStatusHints(conference.getStatusHints())
2104 .setExtras(conference.getExtras())
2105 .setAddress(conference.getAddress(), conference.getAddressPresentation())
2106 .setCallerDisplayName(conference.getCallerDisplayName(),
2107 conference.getCallerDisplayNamePresentation())
2108 .setDisconnectCause(conference.getDisconnectCause())
2109 .setRingbackRequested(conference.isRingbackRequested())
2110 .build();
Ravi Paluri80aa2142019-12-02 11:57:37 +05302111 if (conference.getState() != Connection.STATE_DISCONNECTED) {
2112 conference.setTelecomCallId(callId);
2113 mAdapter.setVideoProvider(callId, conference.getVideoProvider());
2114 mAdapter.setVideoState(callId, conference.getVideoState());
2115 onConferenceAdded(conference);
2116 }
2117
2118 Log.d(this, "createConference, calling handleCreateConferenceSuccessful %s", callId);
2119 mAdapter.handleCreateConferenceComplete(
2120 callId,
2121 request,
2122 parcelableConference);
2123 }
2124
Sailesh Nepalc5b01572014-07-14 16:29:44 -07002125 /**
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002126 * This can be used by telecom to either create a new outgoing call or attach to an existing
2127 * incoming call. In either case, telecom will cycle through a set of services and call
Sailesh Nepalc5b01572014-07-14 16:29:44 -07002128 * createConnection util a connection service cancels the process or completes it successfully.
2129 */
Ihab Awadf8b69882014-07-25 15:14:01 -07002130 private void createConnection(
2131 final PhoneAccountHandle callManagerAccount,
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002132 final String callId,
Ihab Awadf8b69882014-07-25 15:14:01 -07002133 final ConnectionRequest request,
Yorke Leec3cf9822014-10-02 09:38:39 -07002134 boolean isIncoming,
2135 boolean isUnknown) {
Tyler Gunn79bc1ec2018-01-22 15:17:54 -08002136 boolean isLegacyHandover = request.getExtras() != null &&
2137 request.getExtras().getBoolean(TelecomManager.EXTRA_IS_HANDOVER, false);
2138 boolean isHandover = request.getExtras() != null && request.getExtras().getBoolean(
2139 TelecomManager.EXTRA_IS_HANDOVER_CONNECTION, false);
Grace Jiae99fde92021-01-19 14:58:01 -08002140 boolean addSelfManaged = request.getExtras() != null && request.getExtras().getBoolean(
Grace Jia8b22bb42021-02-02 15:37:32 -08002141 PhoneAccount.EXTRA_ADD_SELF_MANAGED_CALLS_TO_INCALLSERVICE, true);
Grace Jiae99fde92021-01-19 14:58:01 -08002142 Log.i(this, "createConnection, callManagerAccount: %s, callId: %s, request: %s, "
2143 + "isIncoming: %b, isUnknown: %b, isLegacyHandover: %b, isHandover: %b, "
2144 + " addSelfManaged: %b", callManagerAccount, callId, request, isIncoming,
2145 isUnknown, isLegacyHandover, isHandover, addSelfManaged);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002146
Sanket Padawee29a2662017-12-01 13:59:27 -08002147 Connection connection = null;
Tyler Gunn79bc1ec2018-01-22 15:17:54 -08002148 if (isHandover) {
2149 PhoneAccountHandle fromPhoneAccountHandle = request.getExtras() != null
2150 ? (PhoneAccountHandle) request.getExtras().getParcelable(
Hani Kazmi4f221e52022-06-20 09:38:26 +00002151 TelecomManager.EXTRA_HANDOVER_FROM_PHONE_ACCOUNT, android.telecom.PhoneAccountHandle.class) : null;
Sanket Padawee29a2662017-12-01 13:59:27 -08002152 if (!isIncoming) {
Tyler Gunn79bc1ec2018-01-22 15:17:54 -08002153 connection = onCreateOutgoingHandoverConnection(fromPhoneAccountHandle, request);
Sanket Padawee29a2662017-12-01 13:59:27 -08002154 } else {
Tyler Gunn79bc1ec2018-01-22 15:17:54 -08002155 connection = onCreateIncomingHandoverConnection(fromPhoneAccountHandle, request);
Sanket Padawee29a2662017-12-01 13:59:27 -08002156 }
2157 } else {
2158 connection = isUnknown ? onCreateUnknownConnection(callManagerAccount, request)
2159 : isIncoming ? onCreateIncomingConnection(callManagerAccount, request)
2160 : onCreateOutgoingConnection(callManagerAccount, request);
2161 }
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07002162 Log.d(this, "createConnection, connection: %s", connection);
2163 if (connection == null) {
Tyler Gunnfba1a8e2017-12-19 15:23:59 -08002164 Log.i(this, "createConnection, implementation returned null connection.");
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002165 connection = Connection.createFailedConnection(
Tyler Gunnfba1a8e2017-12-19 15:23:59 -08002166 new DisconnectCause(DisconnectCause.ERROR, "IMPL_RETURNED_NULL_CONNECTION"));
Tyler Gunnc59fd0c2020-04-17 14:03:35 -07002167 } else {
2168 try {
2169 Bundle extras = request.getExtras();
2170 if (extras != null) {
2171 // If the request originated from a remote connection service, we will add some
2172 // tracking information that Telecom can use to keep informed of which package
2173 // made the remote request, and which remote connection service was used.
2174 if (extras.containsKey(
2175 Connection.EXTRA_REMOTE_CONNECTION_ORIGINATING_PACKAGE_NAME)) {
2176 Bundle newExtras = new Bundle();
2177 newExtras.putString(
2178 Connection.EXTRA_REMOTE_CONNECTION_ORIGINATING_PACKAGE_NAME,
2179 extras.getString(
2180 Connection.EXTRA_REMOTE_CONNECTION_ORIGINATING_PACKAGE_NAME
2181 ));
2182 newExtras.putParcelable(Connection.EXTRA_REMOTE_PHONE_ACCOUNT_HANDLE,
2183 request.getAccountHandle());
2184 connection.putExtras(newExtras);
2185 }
2186 }
2187 } catch (UnsupportedOperationException ose) {
2188 // Do nothing; if the ConnectionService reported a failure it will be an instance
2189 // of an immutable Connection which we cannot edit, so we're out of luck.
2190 }
Sailesh Nepalc5b01572014-07-14 16:29:44 -07002191 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002192
Tyler Gunnf2e08b42018-05-24 10:44:44 -07002193 boolean isSelfManaged =
2194 (connection.getConnectionProperties() & Connection.PROPERTY_SELF_MANAGED)
2195 == Connection.PROPERTY_SELF_MANAGED;
2196 // Self-managed Connections should always use voip audio mode; we default here so that the
2197 // local state within the ConnectionService matches the default we assume in Telecom.
2198 if (isSelfManaged) {
2199 connection.setAudioModeIsVoip(true);
2200 }
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002201 connection.setTelecomCallId(callId);
Sungjae7f4137452020-09-16 17:01:54 +09002202 PhoneAccountHandle phoneAccountHandle = connection.getPhoneAccountHandle() == null
2203 ? request.getAccountHandle() : connection.getPhoneAccountHandle();
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07002204 if (connection.getState() != Connection.STATE_DISCONNECTED) {
Sungjae7f4137452020-09-16 17:01:54 +09002205 addConnection(phoneAccountHandle, callId, connection);
Ihab Awad6107bab2014-08-18 09:23:25 -07002206 }
2207
Andrew Lee100e2932014-09-08 15:34:24 -07002208 Uri address = connection.getAddress();
2209 String number = address == null ? "null" : address.getSchemeSpecificPart();
Tyler Gunn720c6642016-03-22 09:02:47 -07002210 Log.v(this, "createConnection, number: %s, state: %s, capabilities: %s, properties: %s",
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002211 Connection.toLogSafePhoneNumber(number),
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07002212 Connection.stateToString(connection.getState()),
Tyler Gunn720c6642016-03-22 09:02:47 -07002213 Connection.capabilitiesToString(connection.getConnectionCapabilities()),
2214 Connection.propertiesToString(connection.getConnectionProperties()));
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002215
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07002216 Log.d(this, "createConnection, calling handleCreateConnectionSuccessful %s", callId);
Ihab Awad6107bab2014-08-18 09:23:25 -07002217 mAdapter.handleCreateConnectionComplete(
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002218 callId,
Evan Charltonbf11f982014-07-20 22:06:28 -07002219 request,
2220 new ParcelableConnection(
Sungjae7f4137452020-09-16 17:01:54 +09002221 phoneAccountHandle,
Evan Charltonbf11f982014-07-20 22:06:28 -07002222 connection.getState(),
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002223 connection.getConnectionCapabilities(),
Tyler Gunn720c6642016-03-22 09:02:47 -07002224 connection.getConnectionProperties(),
Christine Hallstrom2830ce92016-11-30 16:06:42 -08002225 connection.getSupportedAudioRoutes(),
Andrew Lee100e2932014-09-08 15:34:24 -07002226 connection.getAddress(),
2227 connection.getAddressPresentation(),
Evan Charltonbf11f982014-07-20 22:06:28 -07002228 connection.getCallerDisplayName(),
2229 connection.getCallerDisplayNamePresentation(),
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002230 connection.getVideoProvider() == null ?
2231 null : connection.getVideoProvider().getInterface(),
Sailesh Nepal8b9d3ca2014-08-14 17:39:34 -07002232 connection.getVideoState(),
Andrew Lee100e2932014-09-08 15:34:24 -07002233 connection.isRingbackRequested(),
Sailesh Nepal8b9d3ca2014-08-14 17:39:34 -07002234 connection.getAudioModeIsVoip(),
Roshan Piuse927ec02015-07-15 15:47:21 -07002235 connection.getConnectTimeMillis(),
Tyler Gunnc9503d62020-01-27 10:30:51 -08002236 connection.getConnectionStartElapsedRealtimeMillis(),
Ihab Awad6107bab2014-08-18 09:23:25 -07002237 connection.getStatusHints(),
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07002238 connection.getDisconnectCause(),
Santos Cordon6b7f9552015-05-27 17:21:45 -07002239 createIdList(connection.getConferenceables()),
Tyler Gunnd57d76c2019-09-24 14:53:23 -07002240 connection.getExtras(),
2241 connection.getCallerNumberVerificationStatus()));
Tyler Gunnf5035432017-01-09 09:43:12 -08002242
Tyler Gunnf2e08b42018-05-24 10:44:44 -07002243 if (isIncoming && request.shouldShowIncomingCallUi() && isSelfManaged) {
Tyler Gunnf5035432017-01-09 09:43:12 -08002244 // Tell ConnectionService to show its incoming call UX.
2245 connection.onShowIncomingCallUi();
2246 }
Shriram Ganesh6bf35ac2014-12-11 17:53:38 -08002247 if (isUnknown) {
2248 triggerConferenceRecalculate();
2249 }
Evan Charltonbf11f982014-07-20 22:06:28 -07002250 }
2251
Tyler Gunn159f35c2017-03-02 09:28:37 -08002252 private void createConnectionFailed(final PhoneAccountHandle callManagerAccount,
2253 final String callId, final ConnectionRequest request,
2254 boolean isIncoming) {
Tyler Gunn44e01912017-01-31 10:49:05 -08002255
2256 Log.i(this, "createConnectionFailed %s", callId);
2257 if (isIncoming) {
Tyler Gunn159f35c2017-03-02 09:28:37 -08002258 onCreateIncomingConnectionFailed(callManagerAccount, request);
Tyler Gunn44e01912017-01-31 10:49:05 -08002259 } else {
Tyler Gunn159f35c2017-03-02 09:28:37 -08002260 onCreateOutgoingConnectionFailed(callManagerAccount, request);
Tyler Gunn44e01912017-01-31 10:49:05 -08002261 }
2262 }
2263
Ravi Paluri80aa2142019-12-02 11:57:37 +05302264 private void createConferenceFailed(final PhoneAccountHandle callManagerAccount,
2265 final String callId, final ConnectionRequest request,
2266 boolean isIncoming) {
2267
2268 Log.i(this, "createConferenceFailed %s", callId);
2269 if (isIncoming) {
2270 onCreateIncomingConferenceFailed(callManagerAccount, request);
2271 } else {
2272 onCreateOutgoingConferenceFailed(callManagerAccount, request);
2273 }
2274 }
2275
Sanket Padawe4cc8ed52017-12-04 16:22:20 -08002276 private void handoverFailed(final String callId, final ConnectionRequest request,
2277 int reason) {
2278
2279 Log.i(this, "handoverFailed %s", callId);
2280 onHandoverFailed(request, reason);
2281 }
2282
Tyler Gunn041a1fe2017-05-12 10:04:49 -07002283 /**
2284 * Called by Telecom when the creation of a new Connection has completed and it is now added
2285 * to Telecom.
2286 * @param callId The ID of the connection.
2287 */
2288 private void notifyCreateConnectionComplete(final String callId) {
2289 Log.i(this, "notifyCreateConnectionComplete %s", callId);
Tyler Gunn0a88f2e2017-06-16 20:20:34 -07002290 if (callId == null) {
2291 // This could happen if the connection fails quickly and is removed from the
2292 // ConnectionService before Telecom sends the create connection complete callback.
2293 Log.w(this, "notifyCreateConnectionComplete: callId is null.");
2294 return;
2295 }
Tyler Gunn041a1fe2017-05-12 10:04:49 -07002296 onCreateConnectionComplete(findConnectionForAction(callId,
2297 "notifyCreateConnectionComplete"));
2298 }
2299
Ravi Paluri80aa2142019-12-02 11:57:37 +05302300 /**
2301 * Called by Telecom when the creation of a new Conference has completed and it is now added
2302 * to Telecom.
2303 * @param callId The ID of the connection.
2304 */
2305 private void notifyCreateConferenceComplete(final String callId) {
2306 Log.i(this, "notifyCreateConferenceComplete %s", callId);
2307 if (callId == null) {
2308 // This could happen if the conference fails quickly and is removed from the
2309 // ConnectionService before Telecom sends the create conference complete callback.
2310 Log.w(this, "notifyCreateConferenceComplete: callId is null.");
2311 return;
2312 }
2313 onCreateConferenceComplete(findConferenceForAction(callId,
2314 "notifyCreateConferenceComplete"));
2315 }
2316
2317
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002318 private void abort(String callId) {
Tyler Gunnffbcd892020-05-04 15:01:59 -07002319 Log.i(this, "abort %s", callId);
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002320 findConnectionForAction(callId, "abort").onAbort();
Ihab Awad542e0ea2014-05-16 10:22:16 -07002321 }
2322
Tyler Gunnbe74de02014-08-29 14:51:48 -07002323 private void answerVideo(String callId, int videoState) {
Tyler Gunnffbcd892020-05-04 15:01:59 -07002324 Log.i(this, "answerVideo %s", callId);
Ravi Paluri80aa2142019-12-02 11:57:37 +05302325 if (mConnectionById.containsKey(callId)) {
2326 findConnectionForAction(callId, "answer").onAnswer(videoState);
2327 } else {
2328 findConferenceForAction(callId, "answer").onAnswer(videoState);
2329 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002330 }
2331
Tyler Gunnbe74de02014-08-29 14:51:48 -07002332 private void answer(String callId) {
Tyler Gunnffbcd892020-05-04 15:01:59 -07002333 Log.i(this, "answer %s", callId);
Ravi Paluri80aa2142019-12-02 11:57:37 +05302334 if (mConnectionById.containsKey(callId)) {
2335 findConnectionForAction(callId, "answer").onAnswer();
2336 } else {
2337 findConferenceForAction(callId, "answer").onAnswer();
2338 }
Tyler Gunnbe74de02014-08-29 14:51:48 -07002339 }
2340
Pooja Jaind34698d2017-12-28 14:15:31 +05302341 private void deflect(String callId, Uri address) {
Tyler Gunnffbcd892020-05-04 15:01:59 -07002342 Log.i(this, "deflect %s", callId);
Pooja Jaind34698d2017-12-28 14:15:31 +05302343 findConnectionForAction(callId, "deflect").onDeflect(address);
2344 }
2345
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002346 private void reject(String callId) {
Tyler Gunnffbcd892020-05-04 15:01:59 -07002347 Log.i(this, "reject %s", callId);
Ravi Paluri80aa2142019-12-02 11:57:37 +05302348 if (mConnectionById.containsKey(callId)) {
2349 findConnectionForAction(callId, "reject").onReject();
2350 } else {
2351 findConferenceForAction(callId, "reject").onReject();
2352 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002353 }
2354
Bryce Lee81901682015-08-28 16:38:02 -07002355 private void reject(String callId, String rejectWithMessage) {
Tyler Gunnffbcd892020-05-04 15:01:59 -07002356 Log.i(this, "reject %s with message", callId);
Bryce Lee81901682015-08-28 16:38:02 -07002357 findConnectionForAction(callId, "reject").onReject(rejectWithMessage);
2358 }
2359
Tyler Gunnfacfdee2020-01-23 13:10:37 -08002360 private void reject(String callId, @android.telecom.Call.RejectReason int rejectReason) {
Tyler Gunnffbcd892020-05-04 15:01:59 -07002361 Log.i(this, "reject %s with reason %d", callId, rejectReason);
Tyler Gunnfacfdee2020-01-23 13:10:37 -08002362 findConnectionForAction(callId, "reject").onReject(rejectReason);
2363 }
2364
Ravi Palurif4b38e72020-02-05 12:35:41 +05302365 private void transfer(String callId, Uri number, boolean isConfirmationRequired) {
Tyler Gunnffbcd892020-05-04 15:01:59 -07002366 Log.i(this, "transfer %s", callId);
Ravi Palurif4b38e72020-02-05 12:35:41 +05302367 findConnectionForAction(callId, "transfer").onTransfer(number, isConfirmationRequired);
2368 }
2369
2370 private void consultativeTransfer(String callId, String otherCallId) {
Tyler Gunnffbcd892020-05-04 15:01:59 -07002371 Log.i(this, "consultativeTransfer %s", callId);
Ravi Palurif4b38e72020-02-05 12:35:41 +05302372 Connection connection1 = findConnectionForAction(callId, "consultativeTransfer");
2373 Connection connection2 = findConnectionForAction(otherCallId, " consultativeTransfer");
2374 connection1.onTransfer(connection2);
2375 }
2376
Bryce Leecac50772015-11-17 15:13:29 -08002377 private void silence(String callId) {
Tyler Gunnffbcd892020-05-04 15:01:59 -07002378 Log.i(this, "silence %s", callId);
Bryce Leecac50772015-11-17 15:13:29 -08002379 findConnectionForAction(callId, "silence").onSilence();
2380 }
2381
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002382 private void disconnect(String callId) {
Tyler Gunnffbcd892020-05-04 15:01:59 -07002383 Log.i(this, "disconnect %s", callId);
Santos Cordon0159ac02014-08-21 14:28:11 -07002384 if (mConnectionById.containsKey(callId)) {
2385 findConnectionForAction(callId, "disconnect").onDisconnect();
2386 } else {
2387 findConferenceForAction(callId, "disconnect").onDisconnect();
2388 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002389 }
2390
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002391 private void hold(String callId) {
Tyler Gunnffbcd892020-05-04 15:01:59 -07002392 Log.i(this, "hold %s", callId);
Santos Cordon0159ac02014-08-21 14:28:11 -07002393 if (mConnectionById.containsKey(callId)) {
2394 findConnectionForAction(callId, "hold").onHold();
2395 } else {
2396 findConferenceForAction(callId, "hold").onHold();
2397 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002398 }
2399
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002400 private void unhold(String callId) {
Tyler Gunnffbcd892020-05-04 15:01:59 -07002401 Log.i(this, "unhold %s", callId);
Santos Cordon0159ac02014-08-21 14:28:11 -07002402 if (mConnectionById.containsKey(callId)) {
2403 findConnectionForAction(callId, "unhold").onUnhold();
2404 } else {
2405 findConferenceForAction(callId, "unhold").onUnhold();
2406 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002407 }
2408
Yorke Lee4af59352015-05-13 14:14:54 -07002409 private void onCallAudioStateChanged(String callId, CallAudioState callAudioState) {
Tyler Gunnffbcd892020-05-04 15:01:59 -07002410 Log.i(this, "onAudioStateChanged %s %s", callId, callAudioState);
Yorke Leea0d3ca92014-09-15 19:18:13 -07002411 if (mConnectionById.containsKey(callId)) {
Yorke Lee4af59352015-05-13 14:14:54 -07002412 findConnectionForAction(callId, "onCallAudioStateChanged").setCallAudioState(
2413 callAudioState);
Yorke Leea0d3ca92014-09-15 19:18:13 -07002414 } else {
Yorke Lee4af59352015-05-13 14:14:54 -07002415 findConferenceForAction(callId, "onCallAudioStateChanged").setCallAudioState(
2416 callAudioState);
Yorke Leea0d3ca92014-09-15 19:18:13 -07002417 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002418 }
2419
Junhoedf3d822022-11-24 09:26:37 +00002420 private void onCallEndpointChanged(String callId, CallEndpoint callEndpoint) {
2421 Log.i(this, "onCallEndpointChanged %s %s", callId, callEndpoint);
2422 if (mConnectionById.containsKey(callId)) {
2423 findConnectionForAction(callId, "onCallEndpointChanged").setCallEndpoint(callEndpoint);
2424 } else {
2425 findConferenceForAction(callId, "onCallEndpointChanged").setCallEndpoint(callEndpoint);
2426 }
2427 }
2428
2429 private void onAvailableCallEndpointsChanged(String callId,
2430 List<CallEndpoint> availableCallEndpoints) {
2431 Log.i(this, "onAvailableCallEndpointsChanged %s", callId);
2432 if (mConnectionById.containsKey(callId)) {
2433 findConnectionForAction(callId, "onAvailableCallEndpointsChanged")
2434 .setAvailableCallEndpoints(availableCallEndpoints);
2435 } else {
2436 findConferenceForAction(callId, "onAvailableCallEndpointsChanged")
2437 .setAvailableCallEndpoints(availableCallEndpoints);
2438 }
2439 }
2440
2441 private void onMuteStateChanged(String callId, boolean isMuted) {
2442 Log.i(this, "onMuteStateChanged %s %s", callId, isMuted);
2443 if (mConnectionById.containsKey(callId)) {
2444 findConnectionForAction(callId, "onMuteStateChanged").setMuteState(isMuted);
2445 } else {
2446 findConferenceForAction(callId, "onMuteStateChanged").setMuteState(isMuted);
2447 }
2448 }
2449
Grace Jiae99fde92021-01-19 14:58:01 -08002450 private void onUsingAlternativeUi(String callId, boolean isUsingAlternativeUi) {
2451 Log.i(this, "onUsingAlternativeUi %s %s", callId, isUsingAlternativeUi);
2452 if (mConnectionById.containsKey(callId)) {
2453 findConnectionForAction(callId, "onUsingAlternativeUi")
2454 .onUsingAlternativeUi(isUsingAlternativeUi);
2455 }
2456 }
2457
2458 private void onTrackedByNonUiService(String callId, boolean isTracked) {
2459 Log.i(this, "onTrackedByNonUiService %s %s", callId, isTracked);
2460 if (mConnectionById.containsKey(callId)) {
2461 findConnectionForAction(callId, "onTrackedByNonUiService")
2462 .onTrackedByNonUiService(isTracked);
2463 }
2464 }
2465
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002466 private void playDtmfTone(String callId, char digit) {
Tyler Gunnffbcd892020-05-04 15:01:59 -07002467 Log.i(this, "playDtmfTone %s %c", callId, digit);
Yorke Leea0d3ca92014-09-15 19:18:13 -07002468 if (mConnectionById.containsKey(callId)) {
2469 findConnectionForAction(callId, "playDtmfTone").onPlayDtmfTone(digit);
2470 } else {
2471 findConferenceForAction(callId, "playDtmfTone").onPlayDtmfTone(digit);
2472 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002473 }
2474
2475 private void stopDtmfTone(String callId) {
Tyler Gunnffbcd892020-05-04 15:01:59 -07002476 Log.i(this, "stopDtmfTone %s", callId);
Yorke Leea0d3ca92014-09-15 19:18:13 -07002477 if (mConnectionById.containsKey(callId)) {
2478 findConnectionForAction(callId, "stopDtmfTone").onStopDtmfTone();
2479 } else {
2480 findConferenceForAction(callId, "stopDtmfTone").onStopDtmfTone();
2481 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002482 }
2483
Santos Cordon823fd3c2014-08-07 18:35:18 -07002484 private void conference(String callId1, String callId2) {
Tyler Gunnffbcd892020-05-04 15:01:59 -07002485 Log.i(this, "conference %s, %s", callId1, callId2);
Santos Cordon980acb92014-05-31 10:31:19 -07002486
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002487 // Attempt to get second connection or conference.
Santos Cordon823fd3c2014-08-07 18:35:18 -07002488 Connection connection2 = findConnectionForAction(callId2, "conference");
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002489 Conference conference2 = getNullConference();
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07002490 if (connection2 == getNullConnection()) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002491 conference2 = findConferenceForAction(callId2, "conference");
2492 if (conference2 == getNullConference()) {
2493 Log.w(this, "Connection2 or Conference2 missing in conference request %s.",
2494 callId2);
2495 return;
2496 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07002497 }
Santos Cordonb6939982014-06-04 20:20:58 -07002498
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002499 // Attempt to get first connection or conference and perform merge.
Ihab Awad50e35062014-09-30 09:17:03 -07002500 Connection connection1 = findConnectionForAction(callId1, "conference");
2501 if (connection1 == getNullConnection()) {
2502 Conference conference1 = findConferenceForAction(callId1, "addConnection");
2503 if (conference1 == getNullConference()) {
2504 Log.w(this,
2505 "Connection1 or Conference1 missing in conference request %s.",
2506 callId1);
2507 } else {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002508 // Call 1 is a conference.
2509 if (connection2 != getNullConnection()) {
2510 // Call 2 is a connection so merge via call 1 (conference).
2511 conference1.onMerge(connection2);
2512 } else {
2513 // Call 2 is ALSO a conference; this should never happen.
2514 Log.wtf(this, "There can only be one conference and an attempt was made to " +
2515 "merge two conferences.");
2516 return;
2517 }
Ihab Awad50e35062014-09-30 09:17:03 -07002518 }
2519 } else {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002520 // Call 1 is a connection.
2521 if (conference2 != getNullConference()) {
2522 // Call 2 is a conference, so merge via call 2.
2523 conference2.onMerge(connection1);
2524 } else {
2525 // Call 2 is a connection, so merge together.
2526 onConference(connection1, connection2);
2527 }
Ihab Awad50e35062014-09-30 09:17:03 -07002528 }
Santos Cordon980acb92014-05-31 10:31:19 -07002529 }
2530
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002531 private void splitFromConference(String callId) {
Tyler Gunnffbcd892020-05-04 15:01:59 -07002532 Log.i(this, "splitFromConference(%s)", callId);
Santos Cordon980acb92014-05-31 10:31:19 -07002533
2534 Connection connection = findConnectionForAction(callId, "splitFromConference");
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07002535 if (connection == getNullConnection()) {
Santos Cordon980acb92014-05-31 10:31:19 -07002536 Log.w(this, "Connection missing in conference request %s.", callId);
2537 return;
2538 }
2539
Santos Cordon0159ac02014-08-21 14:28:11 -07002540 Conference conference = connection.getConference();
2541 if (conference != null) {
2542 conference.onSeparate(connection);
2543 }
Santos Cordon980acb92014-05-31 10:31:19 -07002544 }
2545
Santos Cordona4868042014-09-04 17:39:22 -07002546 private void mergeConference(String callId) {
Tyler Gunnffbcd892020-05-04 15:01:59 -07002547 Log.i(this, "mergeConference(%s)", callId);
Santos Cordona4868042014-09-04 17:39:22 -07002548 Conference conference = findConferenceForAction(callId, "mergeConference");
2549 if (conference != null) {
2550 conference.onMerge();
2551 }
2552 }
2553
2554 private void swapConference(String callId) {
Tyler Gunnffbcd892020-05-04 15:01:59 -07002555 Log.i(this, "swapConference(%s)", callId);
Santos Cordona4868042014-09-04 17:39:22 -07002556 Conference conference = findConferenceForAction(callId, "swapConference");
2557 if (conference != null) {
2558 conference.onSwap();
2559 }
2560 }
2561
Ravi Paluri404babb2020-01-23 19:02:44 +05302562 private void addConferenceParticipants(String callId, List<Uri> participants) {
Tyler Gunnffbcd892020-05-04 15:01:59 -07002563 Log.i(this, "addConferenceParticipants(%s)", callId);
Ravi Paluri404babb2020-01-23 19:02:44 +05302564 if (mConnectionById.containsKey(callId)) {
2565 findConnectionForAction(callId, "addConferenceParticipants")
2566 .onAddConferenceParticipants(participants);
2567 } else {
2568 findConferenceForAction(callId, "addConferenceParticipants")
2569 .onAddConferenceParticipants(participants);
2570 }
2571 }
2572
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002573 /**
2574 * Notifies a {@link Connection} of a request to pull an external call.
2575 *
2576 * See {@link Call#pullExternalCall()}.
2577 *
2578 * @param callId The ID of the call to pull.
2579 */
2580 private void pullExternalCall(String callId) {
Tyler Gunnffbcd892020-05-04 15:01:59 -07002581 Log.i(this, "pullExternalCall(%s)", callId);
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002582 Connection connection = findConnectionForAction(callId, "pullExternalCall");
2583 if (connection != null) {
2584 connection.onPullExternalCall();
2585 }
2586 }
2587
2588 /**
2589 * Notifies a {@link Connection} of a call event.
2590 *
2591 * See {@link Call#sendCallEvent(String, Bundle)}.
2592 *
2593 * @param callId The ID of the call receiving the event.
2594 * @param event The event.
2595 * @param extras Extras associated with the event.
2596 */
2597 private void sendCallEvent(String callId, String event, Bundle extras) {
Tyler Gunnffbcd892020-05-04 15:01:59 -07002598 Log.i(this, "sendCallEvent(%s, %s)", callId, event);
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002599 Connection connection = findConnectionForAction(callId, "sendCallEvent");
2600 if (connection != null) {
2601 connection.onCallEvent(event, extras);
2602 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002603 }
2604
Hall Liu73903142021-02-18 18:41:41 -08002605 private void onCallFilteringCompleted(String callId, Connection.CallFilteringCompletionInfo
2606 callFilteringCompletionInfo) {
2607 Log.i(this, "onCallFilteringCompleted(%s, %s)", callId, callFilteringCompletionInfo);
Hall Liu49cabcc2021-01-15 11:41:48 -08002608 Connection connection = findConnectionForAction(callId, "onCallFilteringCompleted");
2609 if (connection != null) {
Hall Liu73903142021-02-18 18:41:41 -08002610 connection.onCallFilteringCompleted(callFilteringCompletionInfo);
Hall Liu49cabcc2021-01-15 11:41:48 -08002611 }
2612 }
2613
Tyler Gunndee56a82016-03-23 16:06:34 -07002614 /**
Tyler Gunn79bc1ec2018-01-22 15:17:54 -08002615 * Notifies a {@link Connection} that a handover has completed.
2616 *
2617 * @param callId The ID of the call which completed handover.
2618 */
2619 private void notifyHandoverComplete(String callId) {
Tyler Gunnffbcd892020-05-04 15:01:59 -07002620 Log.i(this, "notifyHandoverComplete(%s)", callId);
Tyler Gunn79bc1ec2018-01-22 15:17:54 -08002621 Connection connection = findConnectionForAction(callId, "notifyHandoverComplete");
2622 if (connection != null) {
2623 connection.onHandoverComplete();
2624 }
2625 }
2626
2627 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07002628 * Notifies a {@link Connection} or {@link Conference} of a change to the extras from Telecom.
2629 * <p>
2630 * These extra changes can originate from Telecom itself, or from an {@link InCallService} via
2631 * the {@link android.telecom.Call#putExtra(String, boolean)},
2632 * {@link android.telecom.Call#putExtra(String, int)},
2633 * {@link android.telecom.Call#putExtra(String, String)},
2634 * {@link Call#removeExtras(List)}.
2635 *
2636 * @param callId The ID of the call receiving the event.
2637 * @param extras The new extras bundle.
2638 */
2639 private void handleExtrasChanged(String callId, Bundle extras) {
Tyler Gunnffbcd892020-05-04 15:01:59 -07002640 Log.i(this, "handleExtrasChanged(%s, %s)", callId, extras);
Tyler Gunndee56a82016-03-23 16:06:34 -07002641 if (mConnectionById.containsKey(callId)) {
2642 findConnectionForAction(callId, "handleExtrasChanged").handleExtrasChanged(extras);
2643 } else if (mConferenceById.containsKey(callId)) {
2644 findConferenceForAction(callId, "handleExtrasChanged").handleExtrasChanged(extras);
2645 }
2646 }
2647
Hall Liub64ac4c2017-02-06 10:49:48 -08002648 private void startRtt(String callId, Connection.RttTextStream rttTextStream) {
Tyler Gunnffbcd892020-05-04 15:01:59 -07002649 Log.i(this, "startRtt(%s)", callId);
Hall Liub64ac4c2017-02-06 10:49:48 -08002650 if (mConnectionById.containsKey(callId)) {
2651 findConnectionForAction(callId, "startRtt").onStartRtt(rttTextStream);
2652 } else if (mConferenceById.containsKey(callId)) {
2653 Log.w(this, "startRtt called on a conference.");
2654 }
2655 }
2656
2657 private void stopRtt(String callId) {
Tyler Gunnffbcd892020-05-04 15:01:59 -07002658 Log.i(this, "stopRtt(%s)", callId);
Hall Liub64ac4c2017-02-06 10:49:48 -08002659 if (mConnectionById.containsKey(callId)) {
2660 findConnectionForAction(callId, "stopRtt").onStopRtt();
2661 } else if (mConferenceById.containsKey(callId)) {
2662 Log.w(this, "stopRtt called on a conference.");
2663 }
2664 }
2665
2666 private void handleRttUpgradeResponse(String callId, Connection.RttTextStream rttTextStream) {
Tyler Gunnffbcd892020-05-04 15:01:59 -07002667 Log.i(this, "handleRttUpgradeResponse(%s, %s)", callId, rttTextStream == null);
Hall Liub64ac4c2017-02-06 10:49:48 -08002668 if (mConnectionById.containsKey(callId)) {
2669 findConnectionForAction(callId, "handleRttUpgradeResponse")
2670 .handleRttUpgradeResponse(rttTextStream);
2671 } else if (mConferenceById.containsKey(callId)) {
2672 Log.w(this, "handleRttUpgradeResponse called on a conference.");
2673 }
2674 }
2675
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002676 private void onPostDialContinue(String callId, boolean proceed) {
Tyler Gunnffbcd892020-05-04 15:01:59 -07002677 Log.i(this, "onPostDialContinue(%s)", callId);
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002678 findConnectionForAction(callId, "stopDtmfTone").onPostDialContinue(proceed);
Evan Charlton6dea4ac2014-06-03 14:07:13 -07002679 }
2680
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002681 private void onAdapterAttached() {
Ihab Awad9c3f1882014-06-30 21:17:13 -07002682 if (mAreAccountsInitialized) {
Santos Cordon52d8a152014-06-17 19:08:45 -07002683 // No need to query again if we already did it.
2684 return;
2685 }
2686
Tyler Gunn4c69fb32019-05-17 10:49:16 -07002687 String callingPackage = getOpPackageName();
2688
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002689 mAdapter.queryRemoteConnectionServices(new RemoteServiceCallback.Stub() {
Santos Cordon52d8a152014-06-17 19:08:45 -07002690 @Override
2691 public void onResult(
2692 final List<ComponentName> componentNames,
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002693 final List<IBinder> services) {
Brad Ebinger0c3541b2016-11-01 14:11:38 -07002694 mHandler.post(new android.telecom.Logging.Runnable("oAA.qRCS.oR", null /*lock*/) {
Ihab Awad6107bab2014-08-18 09:23:25 -07002695 @Override
Brad Ebinger0c3541b2016-11-01 14:11:38 -07002696 public void loggedRun() {
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002697 for (int i = 0; i < componentNames.size() && i < services.size(); i++) {
Santos Cordon52d8a152014-06-17 19:08:45 -07002698 mRemoteConnectionManager.addConnectionService(
2699 componentNames.get(i),
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002700 IConnectionService.Stub.asInterface(services.get(i)));
Santos Cordon52d8a152014-06-17 19:08:45 -07002701 }
Ihab Awad5d0410f2014-07-30 10:07:40 -07002702 onAccountsInitialized();
Sailesh Nepalc5b01572014-07-14 16:29:44 -07002703 Log.d(this, "remote connection services found: " + services);
Santos Cordon52d8a152014-06-17 19:08:45 -07002704 }
Brad Ebinger0c3541b2016-11-01 14:11:38 -07002705 }.prepare());
Santos Cordon52d8a152014-06-17 19:08:45 -07002706 }
2707
2708 @Override
2709 public void onError() {
Brad Ebinger0c3541b2016-11-01 14:11:38 -07002710 mHandler.post(new android.telecom.Logging.Runnable("oAA.qRCS.oE", null /*lock*/) {
Ihab Awad6107bab2014-08-18 09:23:25 -07002711 @Override
Brad Ebinger0c3541b2016-11-01 14:11:38 -07002712 public void loggedRun() {
Ihab Awad9c3f1882014-06-30 21:17:13 -07002713 mAreAccountsInitialized = true;
Santos Cordon52d8a152014-06-17 19:08:45 -07002714 }
Brad Ebinger0c3541b2016-11-01 14:11:38 -07002715 }.prepare());
Santos Cordon52d8a152014-06-17 19:08:45 -07002716 }
Tyler Gunn4c69fb32019-05-17 10:49:16 -07002717 }, callingPackage);
Santos Cordon52d8a152014-06-17 19:08:45 -07002718 }
2719
Ihab Awadf8b69882014-07-25 15:14:01 -07002720 /**
2721 * Ask some other {@code ConnectionService} to create a {@code RemoteConnection} given an
Santos Cordona663f862014-10-29 13:49:58 -07002722 * incoming request. This is used by {@code ConnectionService}s that are registered with
2723 * {@link PhoneAccount#CAPABILITY_CONNECTION_MANAGER} and want to be able to manage
2724 * SIM-based incoming calls.
Ihab Awadf8b69882014-07-25 15:14:01 -07002725 *
2726 * @param connectionManagerPhoneAccount See description at
2727 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
2728 * @param request Details about the incoming call.
2729 * @return The {@code Connection} object to satisfy this call, or {@code null} to
2730 * not handle the call.
2731 */
Grace Jia41895152021-01-19 13:57:51 -08002732 public final @Nullable RemoteConnection createRemoteIncomingConnection(
2733 @NonNull PhoneAccountHandle connectionManagerPhoneAccount,
2734 @NonNull ConnectionRequest request) {
Ihab Awadf8b69882014-07-25 15:14:01 -07002735 return mRemoteConnectionManager.createRemoteConnection(
2736 connectionManagerPhoneAccount, request, true);
Santos Cordon52d8a152014-06-17 19:08:45 -07002737 }
2738
2739 /**
Ihab Awadf8b69882014-07-25 15:14:01 -07002740 * Ask some other {@code ConnectionService} to create a {@code RemoteConnection} given an
Santos Cordona663f862014-10-29 13:49:58 -07002741 * outgoing request. This is used by {@code ConnectionService}s that are registered with
2742 * {@link PhoneAccount#CAPABILITY_CONNECTION_MANAGER} and want to be able to use the
2743 * SIM-based {@code ConnectionService} to place its outgoing calls.
Ihab Awadf8b69882014-07-25 15:14:01 -07002744 *
2745 * @param connectionManagerPhoneAccount See description at
2746 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
Cuihtlauac ALVARADO0b3b2a52016-09-13 14:49:41 +02002747 * @param request Details about the outgoing call.
Ihab Awadf8b69882014-07-25 15:14:01 -07002748 * @return The {@code Connection} object to satisfy this call, or {@code null} to
2749 * not handle the call.
2750 */
Grace Jia41895152021-01-19 13:57:51 -08002751 public final @Nullable RemoteConnection createRemoteOutgoingConnection(
2752 @NonNull PhoneAccountHandle connectionManagerPhoneAccount,
2753 @NonNull ConnectionRequest request) {
Ihab Awadf8b69882014-07-25 15:14:01 -07002754 return mRemoteConnectionManager.createRemoteConnection(
2755 connectionManagerPhoneAccount, request, false);
2756 }
2757
2758 /**
Grace Jia9a09c672020-08-04 12:52:09 -07002759 * Ask some other {@code ConnectionService} to create a {@code RemoteConference} given an
2760 * incoming request. This is used by {@code ConnectionService}s that are registered with
2761 * {@link PhoneAccount#CAPABILITY_ADHOC_CONFERENCE_CALLING}.
2762 *
2763 * @param connectionManagerPhoneAccount See description at
2764 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
2765 * @param request Details about the incoming conference call.
2766 * @return The {@code RemoteConference} object to satisfy this call, or {@code null} to not
2767 * handle the call.
2768 */
2769 public final @Nullable RemoteConference createRemoteIncomingConference(
2770 @Nullable PhoneAccountHandle connectionManagerPhoneAccount,
2771 @Nullable ConnectionRequest request) {
2772 return mRemoteConnectionManager.createRemoteConference(connectionManagerPhoneAccount,
2773 request, true);
2774 }
2775
2776 /**
2777 * Ask some other {@code ConnectionService} to create a {@code RemoteConference} given an
2778 * outgoing request. This is used by {@code ConnectionService}s that are registered with
2779 * {@link PhoneAccount#CAPABILITY_ADHOC_CONFERENCE_CALLING}.
2780 *
2781 * @param connectionManagerPhoneAccount See description at
2782 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
2783 * @param request Details about the outgoing conference call.
2784 * @return The {@code RemoteConference} object to satisfy this call, or {@code null} to not
2785 * handle the call.
2786 */
2787 public final @Nullable RemoteConference createRemoteOutgoingConference(
2788 @Nullable PhoneAccountHandle connectionManagerPhoneAccount,
2789 @Nullable ConnectionRequest request) {
2790 return mRemoteConnectionManager.createRemoteConference(connectionManagerPhoneAccount,
2791 request, false);
2792 }
2793
2794 /**
Santos Cordona663f862014-10-29 13:49:58 -07002795 * Indicates to the relevant {@code RemoteConnectionService} that the specified
2796 * {@link RemoteConnection}s should be merged into a conference call.
2797 * <p>
2798 * If the conference request is successful, the method {@link #onRemoteConferenceAdded} will
2799 * be invoked.
2800 *
2801 * @param remoteConnection1 The first of the remote connections to conference.
2802 * @param remoteConnection2 The second of the remote connections to conference.
Ihab Awadb8e85c72014-08-23 20:34:57 -07002803 */
2804 public final void conferenceRemoteConnections(
Santos Cordona663f862014-10-29 13:49:58 -07002805 RemoteConnection remoteConnection1,
2806 RemoteConnection remoteConnection2) {
2807 mRemoteConnectionManager.conferenceRemoteConnections(remoteConnection1, remoteConnection2);
Ihab Awadb8e85c72014-08-23 20:34:57 -07002808 }
2809
2810 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07002811 * Adds a new conference call. When a conference call is created either as a result of an
2812 * explicit request via {@link #onConference} or otherwise, the connection service should supply
2813 * an instance of {@link Conference} by invoking this method. A conference call provided by this
2814 * method will persist until {@link Conference#destroy} is invoked on the conference instance.
2815 *
2816 * @param conference The new conference object.
2817 */
2818 public final void addConference(Conference conference) {
Rekha Kumar07366812015-03-24 16:42:31 -07002819 Log.d(this, "addConference: conference=%s", conference);
2820
Santos Cordon823fd3c2014-08-07 18:35:18 -07002821 String id = addConferenceInternal(conference);
2822 if (id != null) {
2823 List<String> connectionIds = new ArrayList<>(2);
2824 for (Connection connection : conference.getConnections()) {
2825 if (mIdByConnection.containsKey(connection)) {
2826 connectionIds.add(mIdByConnection.get(connection));
2827 }
2828 }
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002829 conference.setTelecomCallId(id);
Brad Ebinger0ae44ed2020-04-09 15:30:57 -07002830 ParcelableConference parcelableConference = new ParcelableConference.Builder(
2831 conference.getPhoneAccountHandle(), conference.getState())
2832 .setConnectionCapabilities(conference.getConnectionCapabilities())
2833 .setConnectionProperties(conference.getConnectionProperties())
2834 .setConnectionIds(connectionIds)
2835 .setVideoAttributes(conference.getVideoProvider() == null
2836 ? null : conference.getVideoProvider().getInterface(),
2837 conference.getVideoState())
2838 .setConnectTimeMillis(conference.getConnectTimeMillis(),
2839 conference.getConnectionStartElapsedRealtimeMillis())
2840 .setStatusHints(conference.getStatusHints())
2841 .setExtras(conference.getExtras())
2842 .setAddress(conference.getAddress(), conference.getAddressPresentation())
2843 .setCallerDisplayName(conference.getCallerDisplayName(),
2844 conference.getCallerDisplayNamePresentation())
2845 .setDisconnectCause(conference.getDisconnectCause())
2846 .setRingbackRequested(conference.isRingbackRequested())
2847 .setCallDirection(conference.getCallDirection())
2848 .build();
Andrew Lee0f51da32015-04-16 13:11:55 -07002849
Santos Cordon823fd3c2014-08-07 18:35:18 -07002850 mAdapter.addConferenceCall(id, parcelableConference);
Rekha Kumar07366812015-03-24 16:42:31 -07002851 mAdapter.setVideoProvider(id, conference.getVideoProvider());
2852 mAdapter.setVideoState(id, conference.getVideoState());
Tyler Gunn10362372020-04-08 13:12:30 -07002853 // In some instances a conference can start its life as a standalone call with just a
2854 // single participant; ensure we signal to Telecom in this case.
2855 if (!conference.isMultiparty()) {
2856 mAdapter.setConferenceState(id, conference.isMultiparty());
2857 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07002858
2859 // Go through any child calls and set the parent.
2860 for (Connection connection : conference.getConnections()) {
2861 String connectionId = mIdByConnection.get(connection);
2862 if (connectionId != null) {
2863 mAdapter.setIsConferenced(connectionId, id);
2864 }
2865 }
Pengquan Meng70c9885332017-10-02 18:09:03 -07002866 onConferenceAdded(conference);
Santos Cordon823fd3c2014-08-07 18:35:18 -07002867 }
2868 }
2869
2870 /**
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002871 * Adds a connection created by the {@link ConnectionService} and informs telecom of the new
2872 * connection.
2873 *
2874 * @param phoneAccountHandle The phone account handle for the connection.
2875 * @param connection The connection to add.
2876 */
2877 public final void addExistingConnection(PhoneAccountHandle phoneAccountHandle,
2878 Connection connection) {
Tyler Gunn78da7812017-05-09 14:34:57 -07002879 addExistingConnection(phoneAccountHandle, connection, null /* conference */);
2880 }
2881
2882 /**
Pengquan Meng731c1a32017-11-21 18:01:13 -08002883 * Call to inform Telecom that your {@link ConnectionService} has released call resources (e.g
2884 * microphone, camera).
2885 *
Pengquan Menge3bf7e22018-02-22 17:30:04 -08002886 * <p>
2887 * The {@link ConnectionService} will be disconnected when it failed to call this method within
2888 * 5 seconds after {@link #onConnectionServiceFocusLost()} is called.
2889 *
Pengquan Meng731c1a32017-11-21 18:01:13 -08002890 * @see ConnectionService#onConnectionServiceFocusLost()
2891 */
2892 public final void connectionServiceFocusReleased() {
2893 mAdapter.onConnectionServiceFocusReleased();
2894 }
2895
2896 /**
Tyler Gunn78da7812017-05-09 14:34:57 -07002897 * Adds a connection created by the {@link ConnectionService} and informs telecom of the new
Tyler Gunn5567d742019-10-31 13:04:37 -07002898 * connection, as well as adding that connection to the specified conference.
2899 * <p>
2900 * Note: This API is intended ONLY for use by the Telephony stack to provide an easy way to add
2901 * IMS conference participants to be added to a conference in a single step; this helps ensure
2902 * UI updates happen atomically, rather than adding the connection and then adding it to
2903 * the conference in another step.
Tyler Gunn78da7812017-05-09 14:34:57 -07002904 *
2905 * @param phoneAccountHandle The phone account handle for the connection.
2906 * @param connection The connection to add.
2907 * @param conference The parent conference of the new connection.
2908 * @hide
2909 */
Tyler Gunn5567d742019-10-31 13:04:37 -07002910 @SystemApi
2911 public final void addExistingConnection(@NonNull PhoneAccountHandle phoneAccountHandle,
2912 @NonNull Connection connection, @NonNull Conference conference) {
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002913
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002914 String id = addExistingConnectionInternal(phoneAccountHandle, connection);
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002915 if (id != null) {
2916 List<String> emptyList = new ArrayList<>(0);
Tyler Gunn78da7812017-05-09 14:34:57 -07002917 String conferenceId = null;
2918 if (conference != null) {
2919 conferenceId = mIdByConference.get(conference);
2920 }
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002921
2922 ParcelableConnection parcelableConnection = new ParcelableConnection(
2923 phoneAccountHandle,
2924 connection.getState(),
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002925 connection.getConnectionCapabilities(),
Tyler Gunn720c6642016-03-22 09:02:47 -07002926 connection.getConnectionProperties(),
Christine Hallstrom2830ce92016-11-30 16:06:42 -08002927 connection.getSupportedAudioRoutes(),
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002928 connection.getAddress(),
2929 connection.getAddressPresentation(),
2930 connection.getCallerDisplayName(),
2931 connection.getCallerDisplayNamePresentation(),
2932 connection.getVideoProvider() == null ?
2933 null : connection.getVideoProvider().getInterface(),
2934 connection.getVideoState(),
2935 connection.isRingbackRequested(),
2936 connection.getAudioModeIsVoip(),
Roshan Piuse927ec02015-07-15 15:47:21 -07002937 connection.getConnectTimeMillis(),
Tyler Gunnc9503d62020-01-27 10:30:51 -08002938 connection.getConnectionStartElapsedRealtimeMillis(),
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002939 connection.getStatusHints(),
2940 connection.getDisconnectCause(),
Santos Cordon6b7f9552015-05-27 17:21:45 -07002941 emptyList,
Tyler Gunn78da7812017-05-09 14:34:57 -07002942 connection.getExtras(),
Tyler Gunn6986a632019-06-25 13:45:32 -07002943 conferenceId,
Tyler Gunnd57d76c2019-09-24 14:53:23 -07002944 connection.getCallDirection(),
2945 Connection.VERIFICATION_STATUS_NOT_VERIFIED);
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07002946 mAdapter.addExistingConnection(id, parcelableConnection);
2947 }
2948 }
2949
2950 /**
Ihab Awadf8b69882014-07-25 15:14:01 -07002951 * Returns all the active {@code Connection}s for which this {@code ConnectionService}
2952 * has taken responsibility.
2953 *
2954 * @return A collection of {@code Connection}s created by this {@code ConnectionService}.
Santos Cordonb6939982014-06-04 20:20:58 -07002955 */
Sailesh Nepal091768c2014-06-30 15:15:23 -07002956 public final Collection<Connection> getAllConnections() {
Santos Cordonb6939982014-06-04 20:20:58 -07002957 return mConnectionById.values();
2958 }
2959
2960 /**
Santos Cordona6018b92016-02-16 14:23:12 -08002961 * Returns all the active {@code Conference}s for which this {@code ConnectionService}
2962 * has taken responsibility.
2963 *
2964 * @return A collection of {@code Conference}s created by this {@code ConnectionService}.
2965 */
2966 public final Collection<Conference> getAllConferences() {
2967 return mConferenceById.values();
2968 }
2969
2970 /**
Ihab Awadf8b69882014-07-25 15:14:01 -07002971 * Create a {@code Connection} given an incoming request. This is used to attach to existing
2972 * incoming calls.
Evan Charltonbf11f982014-07-20 22:06:28 -07002973 *
Ihab Awadf8b69882014-07-25 15:14:01 -07002974 * @param connectionManagerPhoneAccount See description at
2975 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
2976 * @param request Details about the incoming call.
2977 * @return The {@code Connection} object to satisfy this call, or {@code null} to
2978 * not handle the call.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002979 */
Ihab Awadf8b69882014-07-25 15:14:01 -07002980 public Connection onCreateIncomingConnection(
2981 PhoneAccountHandle connectionManagerPhoneAccount,
2982 ConnectionRequest request) {
2983 return null;
2984 }
Ravi Paluri80aa2142019-12-02 11:57:37 +05302985 /**
Grace Jia8587ee52020-07-10 15:42:32 -07002986 * Create a {@code Conference} given an incoming request. This is used to attach to an incoming
2987 * conference call initiated via
2988 * {@link TelecomManager#addNewIncomingConference(PhoneAccountHandle, Bundle)}.
Ravi Paluri80aa2142019-12-02 11:57:37 +05302989 *
2990 * @param connectionManagerPhoneAccount See description at
2991 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
Grace Jia8587ee52020-07-10 15:42:32 -07002992 * @param request Details about the incoming conference call.
Grace Jia41895152021-01-19 13:57:51 -08002993 * @return The {@code Conference} object to satisfy this call. If the conference attempt is
2994 * failed, the return value will be a result of an invocation of
2995 * {@link Connection#createFailedConnection(DisconnectCause)}.
2996 * Return {@code null} if the {@link ConnectionService} cannot handle the call.
Ravi Paluri80aa2142019-12-02 11:57:37 +05302997 */
2998 public @Nullable Conference onCreateIncomingConference(
Grace Jia41895152021-01-19 13:57:51 -08002999 @NonNull PhoneAccountHandle connectionManagerPhoneAccount,
3000 @NonNull ConnectionRequest request) {
Ravi Paluri80aa2142019-12-02 11:57:37 +05303001 return null;
3002 }
Sailesh Nepalc5b01572014-07-14 16:29:44 -07003003
3004 /**
Tyler Gunn041a1fe2017-05-12 10:04:49 -07003005 * Called after the {@link Connection} returned by
3006 * {@link #onCreateIncomingConnection(PhoneAccountHandle, ConnectionRequest)}
3007 * or {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)} has been
3008 * added to the {@link ConnectionService} and sent to Telecom.
3009 *
3010 * @param connection the {@link Connection}.
3011 * @hide
3012 */
3013 public void onCreateConnectionComplete(Connection connection) {
3014 }
3015
3016 /**
Ravi Paluri80aa2142019-12-02 11:57:37 +05303017 * Called after the {@link Conference} returned by
3018 * {@link #onCreateIncomingConference(PhoneAccountHandle, ConnectionRequest)}
3019 * or {@link #onCreateOutgoingConference(PhoneAccountHandle, ConnectionRequest)} has been
3020 * added to the {@link ConnectionService} and sent to Telecom.
3021 *
3022 * @param conference the {@link Conference}.
3023 * @hide
3024 */
3025 public void onCreateConferenceComplete(Conference conference) {
3026 }
3027
3028
3029 /**
Tyler Gunnf5035432017-01-09 09:43:12 -08003030 * Called by Telecom to inform the {@link ConnectionService} that its request to create a new
3031 * incoming {@link Connection} was denied.
3032 * <p>
3033 * Used when a self-managed {@link ConnectionService} attempts to create a new incoming
3034 * {@link Connection}, but Telecom has determined that the call cannot be allowed at this time.
3035 * The {@link ConnectionService} is responsible for silently rejecting the new incoming
3036 * {@link Connection}.
3037 * <p>
3038 * See {@link TelecomManager#isIncomingCallPermitted(PhoneAccountHandle)} for more information.
3039 *
Tyler Gunn159f35c2017-03-02 09:28:37 -08003040 * @param connectionManagerPhoneAccount See description at
3041 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
Tyler Gunnf5035432017-01-09 09:43:12 -08003042 * @param request The incoming connection request.
3043 */
Tyler Gunn159f35c2017-03-02 09:28:37 -08003044 public void onCreateIncomingConnectionFailed(PhoneAccountHandle connectionManagerPhoneAccount,
3045 ConnectionRequest request) {
Tyler Gunnf5035432017-01-09 09:43:12 -08003046 }
3047
3048 /**
3049 * Called by Telecom to inform the {@link ConnectionService} that its request to create a new
3050 * outgoing {@link Connection} was denied.
3051 * <p>
3052 * Used when a self-managed {@link ConnectionService} attempts to create a new outgoing
3053 * {@link Connection}, but Telecom has determined that the call cannot be placed at this time.
3054 * The {@link ConnectionService} is responisible for informing the user that the
3055 * {@link Connection} cannot be made at this time.
3056 * <p>
3057 * See {@link TelecomManager#isOutgoingCallPermitted(PhoneAccountHandle)} for more information.
3058 *
Tyler Gunn159f35c2017-03-02 09:28:37 -08003059 * @param connectionManagerPhoneAccount See description at
3060 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
Tyler Gunnf5035432017-01-09 09:43:12 -08003061 * @param request The outgoing connection request.
3062 */
Tyler Gunn159f35c2017-03-02 09:28:37 -08003063 public void onCreateOutgoingConnectionFailed(PhoneAccountHandle connectionManagerPhoneAccount,
3064 ConnectionRequest request) {
Tyler Gunnf5035432017-01-09 09:43:12 -08003065 }
3066
3067 /**
Ravi Paluri80aa2142019-12-02 11:57:37 +05303068 * Called by Telecom to inform the {@link ConnectionService} that its request to create a new
3069 * incoming {@link Conference} was denied.
3070 * <p>
3071 * Used when a self-managed {@link ConnectionService} attempts to create a new incoming
3072 * {@link Conference}, but Telecom has determined that the call cannot be allowed at this time.
3073 * The {@link ConnectionService} is responsible for silently rejecting the new incoming
3074 * {@link Conference}.
3075 * <p>
3076 * See {@link TelecomManager#isIncomingCallPermitted(PhoneAccountHandle)} for more information.
3077 *
3078 * @param connectionManagerPhoneAccount See description at
3079 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
3080 * @param request The incoming connection request.
3081 */
3082 public void onCreateIncomingConferenceFailed(
3083 @Nullable PhoneAccountHandle connectionManagerPhoneAccount,
3084 @Nullable ConnectionRequest request) {
3085 }
3086
3087 /**
3088 * Called by Telecom to inform the {@link ConnectionService} that its request to create a new
3089 * outgoing {@link Conference} was denied.
3090 * <p>
3091 * Used when a self-managed {@link ConnectionService} attempts to create a new outgoing
3092 * {@link Conference}, but Telecom has determined that the call cannot be placed at this time.
3093 * The {@link ConnectionService} is responisible for informing the user that the
3094 * {@link Conference} cannot be made at this time.
3095 * <p>
3096 * See {@link TelecomManager#isOutgoingCallPermitted(PhoneAccountHandle)} for more information.
3097 *
3098 * @param connectionManagerPhoneAccount See description at
3099 * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
3100 * @param request The outgoing connection request.
3101 */
3102 public void onCreateOutgoingConferenceFailed(
Grace Jia41895152021-01-19 13:57:51 -08003103 @NonNull PhoneAccountHandle connectionManagerPhoneAccount,
3104 @NonNull ConnectionRequest request) {
Ravi Paluri80aa2142019-12-02 11:57:37 +05303105 }
3106
3107
3108 /**
Shriram Ganesh6bf35ac2014-12-11 17:53:38 -08003109 * Trigger recalculate functinality for conference calls. This is used when a Telephony
3110 * Connection is part of a conference controller but is not yet added to Connection
3111 * Service and hence cannot be added to the conference call.
3112 *
3113 * @hide
3114 */
3115 public void triggerConferenceRecalculate() {
3116 }
3117
3118 /**
Ihab Awadf8b69882014-07-25 15:14:01 -07003119 * Create a {@code Connection} given an outgoing request. This is used to initiate new
3120 * outgoing calls.
Sailesh Nepalc5b01572014-07-14 16:29:44 -07003121 *
Ihab Awadf8b69882014-07-25 15:14:01 -07003122 * @param connectionManagerPhoneAccount The connection manager account to use for managing
3123 * this call.
3124 * <p>
3125 * If this parameter is not {@code null}, it means that this {@code ConnectionService}
3126 * has registered one or more {@code PhoneAccount}s having
3127 * {@link PhoneAccount#CAPABILITY_CONNECTION_MANAGER}. This parameter will contain
3128 * one of these {@code PhoneAccount}s, while the {@code request} will contain another
3129 * (usually but not always distinct) {@code PhoneAccount} to be used for actually
3130 * making the connection.
3131 * <p>
3132 * If this parameter is {@code null}, it means that this {@code ConnectionService} is
3133 * being asked to make a direct connection. The
3134 * {@link ConnectionRequest#getAccountHandle()} of parameter {@code request} will be
3135 * a {@code PhoneAccount} registered by this {@code ConnectionService} to use for
3136 * making the connection.
3137 * @param request Details about the outgoing call.
3138 * @return The {@code Connection} object to satisfy this call, or the result of an invocation
Andrew Lee7f3d41f2014-09-11 17:33:16 -07003139 * of {@link Connection#createFailedConnection(DisconnectCause)} to not handle the call.
Sailesh Nepalc5b01572014-07-14 16:29:44 -07003140 */
Ihab Awadf8b69882014-07-25 15:14:01 -07003141 public Connection onCreateOutgoingConnection(
3142 PhoneAccountHandle connectionManagerPhoneAccount,
3143 ConnectionRequest request) {
3144 return null;
3145 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07003146
3147 /**
Ravi Paluri80aa2142019-12-02 11:57:37 +05303148 * Create a {@code Conference} given an outgoing request. This is used to initiate new
Grace Jia8587ee52020-07-10 15:42:32 -07003149 * outgoing conference call requested via
3150 * {@link TelecomManager#startConference(List, Bundle)}.
Ravi Paluri80aa2142019-12-02 11:57:37 +05303151 *
3152 * @param connectionManagerPhoneAccount The connection manager account to use for managing
3153 * this call.
3154 * <p>
3155 * If this parameter is not {@code null}, it means that this {@code ConnectionService}
3156 * has registered one or more {@code PhoneAccount}s having
3157 * {@link PhoneAccount#CAPABILITY_CONNECTION_MANAGER}. This parameter will contain
3158 * one of these {@code PhoneAccount}s, while the {@code request} will contain another
3159 * (usually but not always distinct) {@code PhoneAccount} to be used for actually
3160 * making the connection.
3161 * <p>
3162 * If this parameter is {@code null}, it means that this {@code ConnectionService} is
3163 * being asked to make a direct connection. The
3164 * {@link ConnectionRequest#getAccountHandle()} of parameter {@code request} will be
3165 * a {@code PhoneAccount} registered by this {@code ConnectionService} to use for
3166 * making the connection.
3167 * @param request Details about the outgoing call.
Grace Jia41895152021-01-19 13:57:51 -08003168 * @return The {@code Conference} object to satisfy this call. If the conference attempt is
3169 * failed, the return value will be a result of an invocation of
3170 * {@link Connection#createFailedConnection(DisconnectCause)}.
3171 * Return {@code null} if the {@link ConnectionService} cannot handle the call.
Ravi Paluri80aa2142019-12-02 11:57:37 +05303172 */
3173 public @Nullable Conference onCreateOutgoingConference(
Grace Jia41895152021-01-19 13:57:51 -08003174 @NonNull PhoneAccountHandle connectionManagerPhoneAccount,
3175 @NonNull ConnectionRequest request) {
Ravi Paluri80aa2142019-12-02 11:57:37 +05303176 return null;
3177 }
3178
3179
3180 /**
Tyler Gunn9d127732018-03-02 15:45:51 -08003181 * Called by Telecom to request that a {@link ConnectionService} creates an instance of an
3182 * outgoing handover {@link Connection}.
3183 * <p>
3184 * A call handover is the process where an ongoing call is transferred from one app (i.e.
3185 * {@link ConnectionService} to another app. The user could, for example, choose to continue a
3186 * mobile network call in a video calling app. The mobile network call via the Telephony stack
3187 * is referred to as the source of the handover, and the video calling app is referred to as the
3188 * destination.
3189 * <p>
3190 * When considering a handover scenario the <em>initiating</em> device is where a user initiated
3191 * the handover process (e.g. by calling {@link android.telecom.Call#handoverTo(
3192 * PhoneAccountHandle, int, Bundle)}, and the other device is considered the <em>receiving</em>
3193 * device.
3194 * <p>
3195 * This method is called on the destination {@link ConnectionService} on <em>initiating</em>
3196 * device when the user initiates a handover request from one app to another. The user request
3197 * originates in the {@link InCallService} via
3198 * {@link android.telecom.Call#handoverTo(PhoneAccountHandle, int, Bundle)}.
3199 * <p>
3200 * For a full discussion of the handover process and the APIs involved, see
3201 * {@link android.telecom.Call#handoverTo(PhoneAccountHandle, int, Bundle)}.
3202 * <p>
3203 * Implementations of this method should return an instance of {@link Connection} which
3204 * represents the handover. If your app does not wish to accept a handover to it at this time,
3205 * you can return {@code null}. The code below shows an example of how this is done.
3206 * <pre>
3207 * {@code
3208 * public Connection onCreateIncomingHandoverConnection(PhoneAccountHandle
3209 * fromPhoneAccountHandle, ConnectionRequest request) {
3210 * if (!isHandoverAvailable()) {
3211 * return null;
3212 * }
3213 * MyConnection connection = new MyConnection();
3214 * connection.setAddress(request.getAddress(), TelecomManager.PRESENTATION_ALLOWED);
3215 * connection.setVideoState(request.getVideoState());
3216 * return connection;
3217 * }
3218 * }
3219 * </pre>
3220 *
Sanket Padawea8eddd42017-11-03 11:07:35 -07003221 * @param fromPhoneAccountHandle {@link PhoneAccountHandle} associated with the
3222 * ConnectionService which needs to handover the call.
Tyler Gunn9d127732018-03-02 15:45:51 -08003223 * @param request Details about the call to handover.
3224 * @return {@link Connection} instance corresponding to the handover call.
Sanket Padawea8eddd42017-11-03 11:07:35 -07003225 */
3226 public Connection onCreateOutgoingHandoverConnection(PhoneAccountHandle fromPhoneAccountHandle,
3227 ConnectionRequest request) {
3228 return null;
3229 }
3230
3231 /**
Tyler Gunn9d127732018-03-02 15:45:51 -08003232 * Called by Telecom to request that a {@link ConnectionService} creates an instance of an
3233 * incoming handover {@link Connection}.
3234 * <p>
3235 * A call handover is the process where an ongoing call is transferred from one app (i.e.
3236 * {@link ConnectionService} to another app. The user could, for example, choose to continue a
3237 * mobile network call in a video calling app. The mobile network call via the Telephony stack
3238 * is referred to as the source of the handover, and the video calling app is referred to as the
3239 * destination.
3240 * <p>
3241 * When considering a handover scenario the <em>initiating</em> device is where a user initiated
3242 * the handover process (e.g. by calling {@link android.telecom.Call#handoverTo(
3243 * PhoneAccountHandle, int, Bundle)}, and the other device is considered the <em>receiving</em>
3244 * device.
3245 * <p>
3246 * This method is called on the destination app on the <em>receiving</em> device when the
3247 * destination app calls {@link TelecomManager#acceptHandover(Uri, int, PhoneAccountHandle)} to
3248 * accept an incoming handover from the <em>initiating</em> device.
3249 * <p>
3250 * For a full discussion of the handover process and the APIs involved, see
3251 * {@link android.telecom.Call#handoverTo(PhoneAccountHandle, int, Bundle)}.
3252 * <p>
3253 * Implementations of this method should return an instance of {@link Connection} which
3254 * represents the handover. The code below shows an example of how this is done.
3255 * <pre>
3256 * {@code
3257 * public Connection onCreateIncomingHandoverConnection(PhoneAccountHandle
3258 * fromPhoneAccountHandle, ConnectionRequest request) {
3259 * // Given that your app requested to accept the handover, you should not return null here.
3260 * MyConnection connection = new MyConnection();
3261 * connection.setAddress(request.getAddress(), TelecomManager.PRESENTATION_ALLOWED);
3262 * connection.setVideoState(request.getVideoState());
3263 * return connection;
3264 * }
3265 * }
3266 * </pre>
3267 *
Sanket Padawea8eddd42017-11-03 11:07:35 -07003268 * @param fromPhoneAccountHandle {@link PhoneAccountHandle} associated with the
3269 * ConnectionService which needs to handover the call.
3270 * @param request Details about the call which needs to be handover.
Tyler Gunn9d127732018-03-02 15:45:51 -08003271 * @return {@link Connection} instance corresponding to the handover call.
Sanket Padawea8eddd42017-11-03 11:07:35 -07003272 */
3273 public Connection onCreateIncomingHandoverConnection(PhoneAccountHandle fromPhoneAccountHandle,
3274 ConnectionRequest request) {
3275 return null;
3276 }
3277
3278 /**
3279 * Called by Telecom in response to a {@code TelecomManager#acceptHandover()}
3280 * invocation which failed.
Tyler Gunn9d127732018-03-02 15:45:51 -08003281 * <p>
3282 * For a full discussion of the handover process and the APIs involved, see
3283 * {@link android.telecom.Call#handoverTo(PhoneAccountHandle, int, Bundle)}
3284 *
3285 * @param request Details about the call which failed to handover.
3286 * @param error Reason for handover failure. Will be one of the
Sanket Padawea8eddd42017-11-03 11:07:35 -07003287 */
Tyler Gunn9d127732018-03-02 15:45:51 -08003288 public void onHandoverFailed(ConnectionRequest request,
3289 @Call.Callback.HandoverFailureErrors int error) {
Sanket Padawea8eddd42017-11-03 11:07:35 -07003290 return;
3291 }
3292
3293 /**
Roopa Sattiraju45de470c2022-01-27 21:31:35 -08003294 * Calls of this type are created using
3295 * {@link TelecomManager#addNewUnknownCall(PhoneAccountHandle, Bundle)}. Unknown calls
3296 * are used for representing calls which become known to the {@link ConnectionService}
3297 * midway through the call.
3298 *
3299 * For example, a call transferred from one device to answer would surface as an active
3300 * call in Telecom instead of going through a typical Ringing to Active transition, or
3301 * Dialing to Active transition.
3302 *
3303 * A {@link ConnectionService} can return {@code null} (the default behavior)
3304 * if it is not able to handle a request for the requested unknown connection.
3305 *
3306 * {@link TelecomManager#addNewIncomingCall(PhoneAccountHandle, android.os.Bundle)}.
Yorke Leec3cf9822014-10-02 09:38:39 -07003307 *
Etienne Ruffieuxb99333d2022-02-25 16:11:01 +00003308 * @param connectionManagerPhoneAccount The connection manager account to use for managing
3309 * this call
3310 * @param request Details about the outgoing call
3311 * @return The {@code Connection} object to satisfy this call, or the result of an invocation
3312 * of {@link Connection#createFailedConnection(DisconnectCause)} to not handle the call
Yorke Lee770ed6e2014-10-06 18:58:52 -07003313 * @hide
Yorke Leec3cf9822014-10-02 09:38:39 -07003314 */
Etienne Ruffieuxb99333d2022-02-25 16:11:01 +00003315 @SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
Roopa Sattiraju45de470c2022-01-27 21:31:35 -08003316 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3317 public @Nullable Connection onCreateUnknownConnection(
3318 @NonNull PhoneAccountHandle connectionManagerPhoneAccount,
3319 @NonNull ConnectionRequest request) {
Brad Ebingerb32d4f82016-10-24 16:40:49 -07003320 return null;
Yorke Leec3cf9822014-10-02 09:38:39 -07003321 }
3322
3323 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07003324 * Conference two specified connections. Invoked when the user has made a request to merge the
3325 * specified connections into a conference call. In response, the connection service should
3326 * create an instance of {@link Conference} and pass it into {@link #addConference}.
Santos Cordonb6939982014-06-04 20:20:58 -07003327 *
Santos Cordon823fd3c2014-08-07 18:35:18 -07003328 * @param connection1 A connection to merge into a conference call.
3329 * @param connection2 A connection to merge into a conference call.
Santos Cordonb6939982014-06-04 20:20:58 -07003330 */
Santos Cordon823fd3c2014-08-07 18:35:18 -07003331 public void onConference(Connection connection1, Connection connection2) {}
Santos Cordonb6939982014-06-04 20:20:58 -07003332
Santos Cordona663f862014-10-29 13:49:58 -07003333 /**
Pengquan Meng70c9885332017-10-02 18:09:03 -07003334 * Called when a connection is added.
3335 * @hide
3336 */
3337 public void onConnectionAdded(Connection connection) {}
3338
3339 /**
3340 * Called when a connection is removed.
3341 * @hide
3342 */
3343 public void onConnectionRemoved(Connection connection) {}
3344
3345 /**
3346 * Called when a conference is added.
3347 * @hide
3348 */
3349 public void onConferenceAdded(Conference conference) {}
3350
3351 /**
3352 * Called when a conference is removed.
3353 * @hide
3354 */
3355 public void onConferenceRemoved(Conference conference) {}
3356
3357 /**
Santos Cordona663f862014-10-29 13:49:58 -07003358 * Indicates that a remote conference has been created for existing {@link RemoteConnection}s.
3359 * When this method is invoked, this {@link ConnectionService} should create its own
3360 * representation of the conference call and send it to telecom using {@link #addConference}.
3361 * <p>
3362 * This is only relevant to {@link ConnectionService}s which are registered with
3363 * {@link PhoneAccount#CAPABILITY_CONNECTION_MANAGER}.
3364 *
3365 * @param conference The remote conference call.
3366 */
Ihab Awadb8e85c72014-08-23 20:34:57 -07003367 public void onRemoteConferenceAdded(RemoteConference conference) {}
3368
Santos Cordon823fd3c2014-08-07 18:35:18 -07003369 /**
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07003370 * Called when an existing connection is added remotely.
3371 * @param connection The existing connection which was added.
3372 */
3373 public void onRemoteExistingConnectionAdded(RemoteConnection connection) {}
3374
3375 /**
Pengquan Meng731c1a32017-11-21 18:01:13 -08003376 * Called when the {@link ConnectionService} has lost the call focus.
3377 * The {@link ConnectionService} should release the call resources and invokes
3378 * {@link ConnectionService#connectionServiceFocusReleased()} to inform telecom that it has
3379 * released the call resources.
3380 */
3381 public void onConnectionServiceFocusLost() {}
3382
3383 /**
3384 * Called when the {@link ConnectionService} has gained the call focus. The
3385 * {@link ConnectionService} can acquire the call resources at this time.
3386 */
3387 public void onConnectionServiceFocusGained() {}
3388
3389 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07003390 * @hide
3391 */
3392 public boolean containsConference(Conference conference) {
3393 return mIdByConference.containsKey(conference);
3394 }
3395
Ihab Awadb8e85c72014-08-23 20:34:57 -07003396 /** {@hide} */
3397 void addRemoteConference(RemoteConference remoteConference) {
3398 onRemoteConferenceAdded(remoteConference);
3399 }
3400
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07003401 /** {@hide} */
3402 void addRemoteExistingConnection(RemoteConnection remoteConnection) {
3403 onRemoteExistingConnectionAdded(remoteConnection);
3404 }
3405
Ihab Awad5d0410f2014-07-30 10:07:40 -07003406 private void onAccountsInitialized() {
3407 mAreAccountsInitialized = true;
3408 for (Runnable r : mPreInitializationConnectionRequests) {
3409 r.run();
3410 }
3411 mPreInitializationConnectionRequests.clear();
3412 }
3413
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07003414 /**
Tyler Gunnf0500bd2015-09-01 10:59:48 -07003415 * Adds an existing connection to the list of connections, identified by a new call ID unique
3416 * to this connection service.
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07003417 *
3418 * @param connection The connection.
Tyler Gunnf0500bd2015-09-01 10:59:48 -07003419 * @return The ID of the connection (e.g. the call-id).
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07003420 */
Tyler Gunnf0500bd2015-09-01 10:59:48 -07003421 private String addExistingConnectionInternal(PhoneAccountHandle handle, Connection connection) {
3422 String id;
Tyler Gunncd6ccfd2016-10-17 15:48:19 -07003423
3424 if (connection.getExtras() != null && connection.getExtras()
3425 .containsKey(Connection.EXTRA_ORIGINAL_CONNECTION_ID)) {
3426 id = connection.getExtras().getString(Connection.EXTRA_ORIGINAL_CONNECTION_ID);
3427 Log.d(this, "addExistingConnectionInternal - conn %s reusing original id %s",
3428 connection.getTelecomCallId(), id);
3429 } else if (handle == null) {
Tyler Gunnf0500bd2015-09-01 10:59:48 -07003430 // If no phone account handle was provided, we cannot be sure the call ID is unique,
3431 // so just use a random UUID.
3432 id = UUID.randomUUID().toString();
3433 } else {
3434 // Phone account handle was provided, so use the ConnectionService class name as a
3435 // prefix for a unique incremental call ID.
3436 id = handle.getComponentName().getClassName() + "@" + getNextCallId();
3437 }
Pengquan Meng70c9885332017-10-02 18:09:03 -07003438 addConnection(handle, id, connection);
Tyler Gunn4a57b9b2014-10-30 14:27:48 -07003439 return id;
3440 }
3441
Pengquan Meng70c9885332017-10-02 18:09:03 -07003442 private void addConnection(PhoneAccountHandle handle, String callId, Connection connection) {
Tyler Gunnf0500bd2015-09-01 10:59:48 -07003443 connection.setTelecomCallId(callId);
Ihab Awad542e0ea2014-05-16 10:22:16 -07003444 mConnectionById.put(callId, connection);
3445 mIdByConnection.put(connection, callId);
3446 connection.addConnectionListener(mConnectionListener);
Santos Cordon823fd3c2014-08-07 18:35:18 -07003447 connection.setConnectionService(this);
Pengquan Meng70c9885332017-10-02 18:09:03 -07003448 connection.setPhoneAccountHandle(handle);
3449 onConnectionAdded(connection);
Ihab Awad542e0ea2014-05-16 10:22:16 -07003450 }
3451
Anthony Lee30e65842014-11-06 16:30:53 -08003452 /** {@hide} */
3453 protected void removeConnection(Connection connection) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07003454 connection.unsetConnectionService(this);
Ihab Awad542e0ea2014-05-16 10:22:16 -07003455 connection.removeConnectionListener(mConnectionListener);
Chenjie Luoe370b532016-05-12 16:59:43 -07003456 String id = mIdByConnection.get(connection);
3457 if (id != null) {
3458 mConnectionById.remove(id);
3459 mIdByConnection.remove(connection);
3460 mAdapter.removeCall(id);
Pengquan Meng70c9885332017-10-02 18:09:03 -07003461 onConnectionRemoved(connection);
Chenjie Luoe370b532016-05-12 16:59:43 -07003462 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07003463 }
3464
Santos Cordon823fd3c2014-08-07 18:35:18 -07003465 private String addConferenceInternal(Conference conference) {
Tyler Gunncd6ccfd2016-10-17 15:48:19 -07003466 String originalId = null;
3467 if (conference.getExtras() != null && conference.getExtras()
3468 .containsKey(Connection.EXTRA_ORIGINAL_CONNECTION_ID)) {
3469 originalId = conference.getExtras().getString(Connection.EXTRA_ORIGINAL_CONNECTION_ID);
3470 Log.d(this, "addConferenceInternal: conf %s reusing original id %s",
3471 conference.getTelecomCallId(),
3472 originalId);
3473 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07003474 if (mIdByConference.containsKey(conference)) {
3475 Log.w(this, "Re-adding an existing conference: %s.", conference);
3476 } else if (conference != null) {
Tyler Gunnf0500bd2015-09-01 10:59:48 -07003477 // Conferences do not (yet) have a PhoneAccountHandle associated with them, so we
3478 // cannot determine a ConnectionService class name to associate with the ID, so use
3479 // a unique UUID (for now).
Tyler Gunncd6ccfd2016-10-17 15:48:19 -07003480 String id = originalId == null ? UUID.randomUUID().toString() : originalId;
Santos Cordon823fd3c2014-08-07 18:35:18 -07003481 mConferenceById.put(id, conference);
3482 mIdByConference.put(conference, id);
3483 conference.addListener(mConferenceListener);
3484 return id;
3485 }
3486
3487 return null;
3488 }
3489
3490 private void removeConference(Conference conference) {
3491 if (mIdByConference.containsKey(conference)) {
3492 conference.removeListener(mConferenceListener);
3493
3494 String id = mIdByConference.get(conference);
3495 mConferenceById.remove(id);
3496 mIdByConference.remove(conference);
3497 mAdapter.removeCall(id);
Pengquan Meng70c9885332017-10-02 18:09:03 -07003498
3499 onConferenceRemoved(conference);
Santos Cordon823fd3c2014-08-07 18:35:18 -07003500 }
3501 }
3502
Ihab Awad542e0ea2014-05-16 10:22:16 -07003503 private Connection findConnectionForAction(String callId, String action) {
Tyler Gunn0a88f2e2017-06-16 20:20:34 -07003504 if (callId != null && mConnectionById.containsKey(callId)) {
Ihab Awad542e0ea2014-05-16 10:22:16 -07003505 return mConnectionById.get(callId);
3506 }
Ihab Awad60ac30b2014-05-20 22:32:12 -07003507 Log.w(this, "%s - Cannot find Connection %s", action, callId);
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07003508 return getNullConnection();
3509 }
3510
3511 static synchronized Connection getNullConnection() {
3512 if (sNullConnection == null) {
3513 sNullConnection = new Connection() {};
3514 }
3515 return sNullConnection;
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003516 }
Santos Cordon0159ac02014-08-21 14:28:11 -07003517
3518 private Conference findConferenceForAction(String conferenceId, String action) {
3519 if (mConferenceById.containsKey(conferenceId)) {
3520 return mConferenceById.get(conferenceId);
3521 }
3522 Log.w(this, "%s - Cannot find conference %s", action, conferenceId);
3523 return getNullConference();
3524 }
3525
Ihab Awadb8e85c72014-08-23 20:34:57 -07003526 private List<String> createConnectionIdList(List<Connection> connections) {
3527 List<String> ids = new ArrayList<>();
3528 for (Connection c : connections) {
3529 if (mIdByConnection.containsKey(c)) {
3530 ids.add(mIdByConnection.get(c));
3531 }
3532 }
3533 Collections.sort(ids);
3534 return ids;
3535 }
3536
Tyler Gunn6d76ca02014-11-17 15:49:51 -08003537 /**
3538 * Builds a list of {@link Connection} and {@link Conference} IDs based on the list of
Tyler Gunndf2cbc82015-04-20 09:13:01 -07003539 * {@link Conferenceable}s passed in.
Tyler Gunn6d76ca02014-11-17 15:49:51 -08003540 *
Tyler Gunndf2cbc82015-04-20 09:13:01 -07003541 * @param conferenceables The {@link Conferenceable} connections and conferences.
Tyler Gunn6d76ca02014-11-17 15:49:51 -08003542 * @return List of string conference and call Ids.
3543 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07003544 private List<String> createIdList(List<Conferenceable> conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08003545 List<String> ids = new ArrayList<>();
Tyler Gunndf2cbc82015-04-20 09:13:01 -07003546 for (Conferenceable c : conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08003547 // Only allow Connection and Conference conferenceables.
3548 if (c instanceof Connection) {
3549 Connection connection = (Connection) c;
3550 if (mIdByConnection.containsKey(connection)) {
3551 ids.add(mIdByConnection.get(connection));
3552 }
3553 } else if (c instanceof Conference) {
3554 Conference conference = (Conference) c;
3555 if (mIdByConference.containsKey(conference)) {
3556 ids.add(mIdByConference.get(conference));
3557 }
3558 }
3559 }
3560 Collections.sort(ids);
3561 return ids;
3562 }
3563
Santos Cordon0159ac02014-08-21 14:28:11 -07003564 private Conference getNullConference() {
3565 if (sNullConference == null) {
3566 sNullConference = new Conference(null) {};
3567 }
3568 return sNullConference;
3569 }
Santos Cordon29f2f2e2014-09-11 19:50:24 -07003570
3571 private void endAllConnections() {
3572 // Unbound from telecomm. We should end all connections and conferences.
3573 for (Connection connection : mIdByConnection.keySet()) {
3574 // only operate on top-level calls. Conference calls will be removed on their own.
3575 if (connection.getConference() == null) {
3576 connection.onDisconnect();
3577 }
3578 }
3579 for (Conference conference : mIdByConference.keySet()) {
3580 conference.onDisconnect();
3581 }
3582 }
Tyler Gunnf0500bd2015-09-01 10:59:48 -07003583
3584 /**
3585 * Retrieves the next call ID as maintainted by the connection service.
3586 *
3587 * @return The call ID.
3588 */
3589 private int getNextCallId() {
Brad Ebingerb32d4f82016-10-24 16:40:49 -07003590 synchronized (mIdSyncRoot) {
Tyler Gunnf0500bd2015-09-01 10:59:48 -07003591 return ++mId;
3592 }
3593 }
Brad Ebinger99f17ce2019-09-11 18:06:51 -07003594
3595 /**
3596 * Returns this handler, ONLY FOR TESTING.
3597 * @hide
3598 */
3599 @VisibleForTesting
3600 public Handler getHandler() {
3601 return mHandler;
3602 }
Tyler Gunnc7e07b92021-04-06 11:40:57 -07003603
3604 /**
3605 * Sets this {@link ConnectionService} ready for testing purposes.
3606 * @hide
3607 */
3608 @VisibleForTesting
3609 public void setReadyForTest() {
3610 mAreAccountsInitialized = true;
3611 }
Santos Cordon980acb92014-05-31 10:31:19 -07003612}