blob: a7105d349f26af3a23c1897c74fdeb67aef7ed0b [file] [log] [blame]
Ben Giladbb69b0c2013-12-12 18:32:02 -08001/*
Sailesh Nepalab5d2822014-03-08 18:01:06 -08002 * Copyright (C) 2014 The Android Open Source Project
Ben Giladbb69b0c2013-12-12 18:32:02 -08003 *
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;
Ben Giladbb69b0c2013-12-12 18:32:02 -080018
yongnamcha8ec56242022-11-28 06:23:02 +000019import android.annotation.CallbackExecutor;
20import android.annotation.NonNull;
21import android.location.Location;
Sailesh Nepal61203862014-07-11 14:50:13 -070022import android.net.Uri;
Junhoedf3d822022-11-24 09:26:37 +000023import android.os.Binder;
Santos Cordon6b7f9552015-05-27 17:21:45 -070024import android.os.Bundle;
Santos Cordon52d8a152014-06-17 19:08:45 -070025import android.os.IBinder.DeathRecipient;
Junhoedf3d822022-11-24 09:26:37 +000026import android.os.OutcomeReceiver;
Sailesh Nepalab5d2822014-03-08 18:01:06 -080027import android.os.RemoteException;
Junhoedf3d822022-11-24 09:26:37 +000028import android.os.ResultReceiver;
Sailesh Nepalab5d2822014-03-08 18:01:06 -080029
Tyler Gunnef9f6f92014-09-12 22:16:17 -070030import com.android.internal.telecom.IConnectionServiceAdapter;
31import com.android.internal.telecom.RemoteServiceCallback;
Ben Giladbb69b0c2013-12-12 18:32:02 -080032
Jay Shraunerb0c0e362014-08-08 16:31:48 -070033import java.util.Collections;
Sailesh Nepal4dd9df52014-07-10 18:15:15 -070034import java.util.Iterator;
Santos Cordon980acb92014-05-31 10:31:19 -070035import java.util.List;
Santos Cordon52d8a152014-06-17 19:08:45 -070036import java.util.Set;
Jay Shraunerb0c0e362014-08-08 16:31:48 -070037import java.util.concurrent.ConcurrentHashMap;
Junhoedf3d822022-11-24 09:26:37 +000038import java.util.concurrent.Executor;
Santos Cordon980acb92014-05-31 10:31:19 -070039
Ben Giladbb69b0c2013-12-12 18:32:02 -080040/**
Sailesh Nepal2a46b902014-07-04 17:21:07 -070041 * Provides methods for IConnectionService implementations to interact with the system phone app.
Sailesh Nepal2bed9562014-07-02 21:26:12 -070042 *
43 * @hide
Ben Giladbb69b0c2013-12-12 18:32:02 -080044 */
Sailesh Nepal2a46b902014-07-04 17:21:07 -070045final class ConnectionServiceAdapter implements DeathRecipient {
Jay Shrauner229e3822014-08-15 09:23:07 -070046 /**
47 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
48 * load factor before resizing, 1 means we only expect a single thread to
49 * access the map so make only a single shard
50 */
Jay Shraunerb0c0e362014-08-08 16:31:48 -070051 private final Set<IConnectionServiceAdapter> mAdapters = Collections.newSetFromMap(
Jay Shrauner229e3822014-08-15 09:23:07 -070052 new ConcurrentHashMap<IConnectionServiceAdapter, Boolean>(8, 0.9f, 1));
Sailesh Nepalab5d2822014-03-08 18:01:06 -080053
Sailesh Nepal2a46b902014-07-04 17:21:07 -070054 ConnectionServiceAdapter() {
Santos Cordon52d8a152014-06-17 19:08:45 -070055 }
56
Sailesh Nepal2a46b902014-07-04 17:21:07 -070057 void addAdapter(IConnectionServiceAdapter adapter) {
Roshan Pius75c36b62015-07-08 16:52:37 -070058 for (IConnectionServiceAdapter it : mAdapters) {
59 if (it.asBinder() == adapter.asBinder()) {
60 Log.w(this, "Ignoring duplicate adapter addition.");
61 return;
62 }
63 }
Santos Cordon52d8a152014-06-17 19:08:45 -070064 if (mAdapters.add(adapter)) {
65 try {
66 adapter.asBinder().linkToDeath(this, 0);
67 } catch (RemoteException e) {
68 mAdapters.remove(adapter);
69 }
70 }
71 }
72
Sailesh Nepal2a46b902014-07-04 17:21:07 -070073 void removeAdapter(IConnectionServiceAdapter adapter) {
Roshan Pius75c36b62015-07-08 16:52:37 -070074 if (adapter != null) {
75 for (IConnectionServiceAdapter it : mAdapters) {
76 if (it.asBinder() == adapter.asBinder() && mAdapters.remove(it)) {
77 adapter.asBinder().unlinkToDeath(this, 0);
78 break;
79 }
80 }
Santos Cordon52d8a152014-06-17 19:08:45 -070081 }
82 }
83
84 /** ${inheritDoc} */
85 @Override
86 public void binderDied() {
Sailesh Nepal4dd9df52014-07-10 18:15:15 -070087 Iterator<IConnectionServiceAdapter> it = mAdapters.iterator();
88 while (it.hasNext()) {
89 IConnectionServiceAdapter adapter = it.next();
Santos Cordon52d8a152014-06-17 19:08:45 -070090 if (!adapter.asBinder().isBinderAlive()) {
Sailesh Nepal4dd9df52014-07-10 18:15:15 -070091 it.remove();
92 adapter.asBinder().unlinkToDeath(this, 0);
Santos Cordon52d8a152014-06-17 19:08:45 -070093 }
94 }
Sailesh Nepalab5d2822014-03-08 18:01:06 -080095 }
Ben Giladbb69b0c2013-12-12 18:32:02 -080096
Ihab Awad6107bab2014-08-18 09:23:25 -070097 void handleCreateConnectionComplete(
Ihab Awadb19a0bc2014-08-07 19:46:01 -070098 String id,
99 ConnectionRequest request,
100 ParcelableConnection connection) {
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700101 for (IConnectionServiceAdapter adapter : mAdapters) {
Santos Cordon52d8a152014-06-17 19:08:45 -0700102 try {
Brad Ebinger4d75bee2016-10-28 12:29:55 -0700103 adapter.handleCreateConnectionComplete(id, request, connection,
104 Log.getExternalSession());
Sailesh Nepal506e3862014-06-25 13:35:14 -0700105 } catch (RemoteException e) {
106 }
107 }
108 }
109
Ravi Paluri80aa2142019-12-02 11:57:37 +0530110 void handleCreateConferenceComplete(
111 String id,
112 ConnectionRequest request,
113 ParcelableConference conference) {
114 for (IConnectionServiceAdapter adapter : mAdapters) {
115 try {
116 adapter.handleCreateConferenceComplete(id, request, conference,
117 Log.getExternalSession());
118 } catch (RemoteException e) {
119 }
120 }
121 }
122
Sailesh Nepal506e3862014-06-25 13:35:14 -0700123 /**
Ben Giladbb69b0c2013-12-12 18:32:02 -0800124 * Sets a call's state to active (e.g., an ongoing call where two parties can actively
125 * communicate).
Santos Cordon37841332013-12-17 13:30:53 -0800126 *
127 * @param callId The unique ID of the call whose state is changing to active.
Ben Giladbb69b0c2013-12-12 18:32:02 -0800128 */
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700129 void setActive(String callId) {
130 for (IConnectionServiceAdapter adapter : mAdapters) {
Santos Cordon52d8a152014-06-17 19:08:45 -0700131 try {
Brad Ebinger4d75bee2016-10-28 12:29:55 -0700132 adapter.setActive(callId, Log.getExternalSession());
Santos Cordon52d8a152014-06-17 19:08:45 -0700133 } catch (RemoteException e) {
134 }
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800135 }
136 }
Ben Giladbb69b0c2013-12-12 18:32:02 -0800137
138 /**
139 * Sets a call's state to ringing (e.g., an inbound ringing call).
Santos Cordon37841332013-12-17 13:30:53 -0800140 *
141 * @param callId The unique ID of the call whose state is changing to ringing.
Ben Giladbb69b0c2013-12-12 18:32:02 -0800142 */
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700143 void setRinging(String callId) {
144 for (IConnectionServiceAdapter adapter : mAdapters) {
Santos Cordon52d8a152014-06-17 19:08:45 -0700145 try {
Brad Ebinger4d75bee2016-10-28 12:29:55 -0700146 adapter.setRinging(callId, Log.getExternalSession());
Santos Cordon52d8a152014-06-17 19:08:45 -0700147 } catch (RemoteException e) {
148 }
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800149 }
150 }
Ben Giladbb69b0c2013-12-12 18:32:02 -0800151
152 /**
153 * Sets a call's state to dialing (e.g., dialing an outbound call).
Santos Cordon37841332013-12-17 13:30:53 -0800154 *
155 * @param callId The unique ID of the call whose state is changing to dialing.
Ben Giladbb69b0c2013-12-12 18:32:02 -0800156 */
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700157 void setDialing(String callId) {
158 for (IConnectionServiceAdapter adapter : mAdapters) {
Santos Cordon52d8a152014-06-17 19:08:45 -0700159 try {
Brad Ebinger4d75bee2016-10-28 12:29:55 -0700160 adapter.setDialing(callId, Log.getExternalSession());
Santos Cordon52d8a152014-06-17 19:08:45 -0700161 } catch (RemoteException e) {
162 }
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800163 }
164 }
Ben Giladbb69b0c2013-12-12 18:32:02 -0800165
166 /**
Tyler Gunnc96b5e02016-07-07 22:53:57 -0700167 * Sets a call's state to pulling (e.g. a call with {@link Connection#PROPERTY_IS_EXTERNAL_CALL}
168 * is being pulled to the local device.
169 *
170 * @param callId The unique ID of the call whose state is changing to dialing.
171 */
172 void setPulling(String callId) {
173 for (IConnectionServiceAdapter adapter : mAdapters) {
174 try {
Brad Ebinger4d75bee2016-10-28 12:29:55 -0700175 adapter.setPulling(callId, Log.getExternalSession());
Tyler Gunnc96b5e02016-07-07 22:53:57 -0700176 } catch (RemoteException e) {
177 }
178 }
179 }
180
181 /**
Ben Giladbb69b0c2013-12-12 18:32:02 -0800182 * Sets a call's state to disconnected.
Santos Cordon37841332013-12-17 13:30:53 -0800183 *
184 * @param callId The unique ID of the call whose state is changing to disconnected.
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700185 * @param disconnectCause The reason for the disconnection, as described by
186 * {@link android.telecomm.DisconnectCause}.
Ben Giladbb69b0c2013-12-12 18:32:02 -0800187 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700188 void setDisconnected(String callId, DisconnectCause disconnectCause) {
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700189 for (IConnectionServiceAdapter adapter : mAdapters) {
Santos Cordon52d8a152014-06-17 19:08:45 -0700190 try {
Brad Ebinger4d75bee2016-10-28 12:29:55 -0700191 adapter.setDisconnected(callId, disconnectCause, Log.getExternalSession());
Santos Cordon52d8a152014-06-17 19:08:45 -0700192 } catch (RemoteException e) {
193 }
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800194 }
195 }
Yorke Lee81ccaaa2014-03-12 18:33:19 -0700196
197 /**
198 * Sets a call's state to be on hold.
199 *
200 * @param callId - The unique ID of the call whose state is changing to be on hold.
201 */
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700202 void setOnHold(String callId) {
203 for (IConnectionServiceAdapter adapter : mAdapters) {
Santos Cordon52d8a152014-06-17 19:08:45 -0700204 try {
Brad Ebinger4d75bee2016-10-28 12:29:55 -0700205 adapter.setOnHold(callId, Log.getExternalSession());
Santos Cordon52d8a152014-06-17 19:08:45 -0700206 } catch (RemoteException e) {
207 }
Yorke Lee81ccaaa2014-03-12 18:33:19 -0700208 }
209 }
210
Ihab Awadf8358972014-05-28 16:46:42 -0700211 /**
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700212 * Asks Telecom to start or stop a ringback tone for a call.
Ihab Awadf8358972014-05-28 16:46:42 -0700213 *
214 * @param callId The unique ID of the call whose ringback is being changed.
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700215 * @param ringback Whether Telecom should start playing a ringback tone.
Ihab Awadf8358972014-05-28 16:46:42 -0700216 */
Andrew Lee100e2932014-09-08 15:34:24 -0700217 void setRingbackRequested(String callId, boolean ringback) {
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700218 for (IConnectionServiceAdapter adapter : mAdapters) {
Santos Cordon52d8a152014-06-17 19:08:45 -0700219 try {
Brad Ebinger4d75bee2016-10-28 12:29:55 -0700220 adapter.setRingbackRequested(callId, ringback, Log.getExternalSession());
Santos Cordon52d8a152014-06-17 19:08:45 -0700221 } catch (RemoteException e) {
222 }
Ihab Awadf8358972014-05-28 16:46:42 -0700223 }
224 }
Yorke Lee81ccaaa2014-03-12 18:33:19 -0700225
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800226 void setConnectionCapabilities(String callId, int capabilities) {
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700227 for (IConnectionServiceAdapter adapter : mAdapters) {
Santos Cordon52d8a152014-06-17 19:08:45 -0700228 try {
Brad Ebinger4d75bee2016-10-28 12:29:55 -0700229 adapter.setConnectionCapabilities(callId, capabilities, Log.getExternalSession());
Santos Cordon52d8a152014-06-17 19:08:45 -0700230 } catch (RemoteException ignored) {
231 }
Santos Cordon980acb92014-05-31 10:31:19 -0700232 }
233 }
234
Tyler Gunn720c6642016-03-22 09:02:47 -0700235 void setConnectionProperties(String callId, int properties) {
236 for (IConnectionServiceAdapter adapter : mAdapters) {
237 try {
Brad Ebinger4d75bee2016-10-28 12:29:55 -0700238 adapter.setConnectionProperties(callId, properties, Log.getExternalSession());
Tyler Gunn720c6642016-03-22 09:02:47 -0700239 } catch (RemoteException ignored) {
240 }
241 }
242 }
243
Santos Cordon980acb92014-05-31 10:31:19 -0700244 /**
245 * Indicates whether or not the specified call is currently conferenced into the specified
246 * conference call.
247 *
Santos Cordon980acb92014-05-31 10:31:19 -0700248 * @param callId The unique ID of the call being conferenced.
Santos Cordonb6939982014-06-04 20:20:58 -0700249 * @param conferenceCallId The unique ID of the conference call. Null if call is not
Santos Cordon52d8a152014-06-17 19:08:45 -0700250 * conferenced.
Santos Cordon980acb92014-05-31 10:31:19 -0700251 */
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700252 void setIsConferenced(String callId, String conferenceCallId) {
253 for (IConnectionServiceAdapter adapter : mAdapters) {
Santos Cordon52d8a152014-06-17 19:08:45 -0700254 try {
Santos Cordon0159ac02014-08-21 14:28:11 -0700255 Log.d(this, "sending connection %s with conference %s", callId, conferenceCallId);
Brad Ebinger4d75bee2016-10-28 12:29:55 -0700256 adapter.setIsConferenced(callId, conferenceCallId, Log.getExternalSession());
Santos Cordon52d8a152014-06-17 19:08:45 -0700257 } catch (RemoteException ignored) {
258 }
Santos Cordon980acb92014-05-31 10:31:19 -0700259 }
260 }
261
262 /**
Anthony Lee17455a32015-04-24 15:25:29 -0700263 * Indicates that the merge request on this call has failed.
264 *
265 * @param callId The unique ID of the call being conferenced.
266 */
267 void onConferenceMergeFailed(String callId) {
268 for (IConnectionServiceAdapter adapter : mAdapters) {
269 try {
270 Log.d(this, "merge failed for call %s", callId);
Brad Ebinger4d75bee2016-10-28 12:29:55 -0700271 adapter.setConferenceMergeFailed(callId, Log.getExternalSession());
Anthony Lee17455a32015-04-24 15:25:29 -0700272 } catch (RemoteException ignored) {
273 }
274 }
275 }
276
277 /**
Mengjun Leng25707742017-07-04 11:10:37 +0800278 * Resets the cdma connection time.
279 */
280 void resetConnectionTime(String callId) {
281 for (IConnectionServiceAdapter adapter : mAdapters) {
282 try {
283 adapter.resetConnectionTime(callId, Log.getExternalSession());
284 } catch (RemoteException e) {
285 }
286 }
287 }
288
289 /**
Santos Cordon980acb92014-05-31 10:31:19 -0700290 * Indicates that the call no longer exists. Can be used with either a call or a conference
291 * call.
292 *
293 * @param callId The unique ID of the call.
Santos Cordon980acb92014-05-31 10:31:19 -0700294 */
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700295 void removeCall(String callId) {
296 for (IConnectionServiceAdapter adapter : mAdapters) {
Santos Cordon52d8a152014-06-17 19:08:45 -0700297 try {
Brad Ebinger4d75bee2016-10-28 12:29:55 -0700298 adapter.removeCall(callId, Log.getExternalSession());
Santos Cordon52d8a152014-06-17 19:08:45 -0700299 } catch (RemoteException ignored) {
300 }
Santos Cordon980acb92014-05-31 10:31:19 -0700301 }
302 }
Evan Charlton6dea4ac2014-06-03 14:07:13 -0700303
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700304 void onPostDialWait(String callId, String remaining) {
305 for (IConnectionServiceAdapter adapter : mAdapters) {
Santos Cordon52d8a152014-06-17 19:08:45 -0700306 try {
Brad Ebinger4d75bee2016-10-28 12:29:55 -0700307 adapter.onPostDialWait(callId, remaining, Log.getExternalSession());
Santos Cordon52d8a152014-06-17 19:08:45 -0700308 } catch (RemoteException ignored) {
309 }
Evan Charlton6dea4ac2014-06-03 14:07:13 -0700310 }
311 }
Sailesh Nepal8b4818d2014-06-06 10:54:07 -0700312
Nancy Chen27d1c2d2014-12-15 16:12:50 -0800313 void onPostDialChar(String callId, char nextChar) {
314 for (IConnectionServiceAdapter adapter : mAdapters) {
315 try {
Brad Ebinger4d75bee2016-10-28 12:29:55 -0700316 adapter.onPostDialChar(callId, nextChar, Log.getExternalSession());
Nancy Chen27d1c2d2014-12-15 16:12:50 -0800317 } catch (RemoteException ignored) {
318 }
319 }
320 }
321
Sailesh Nepal8b4818d2014-06-06 10:54:07 -0700322 /**
Santos Cordonb6939982014-06-04 20:20:58 -0700323 * Indicates that a new conference call has been created.
324 *
325 * @param callId The unique ID of the conference call.
326 */
Santos Cordon823fd3c2014-08-07 18:35:18 -0700327 void addConferenceCall(String callId, ParcelableConference parcelableConference) {
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700328 for (IConnectionServiceAdapter adapter : mAdapters) {
Santos Cordon52d8a152014-06-17 19:08:45 -0700329 try {
Brad Ebinger4d75bee2016-10-28 12:29:55 -0700330 adapter.addConferenceCall(callId, parcelableConference, Log.getExternalSession());
Santos Cordon52d8a152014-06-17 19:08:45 -0700331 } catch (RemoteException ignored) {
332 }
333 }
334 }
335
336 /**
337 * Retrieves a list of remote connection services usable to place calls.
Santos Cordon52d8a152014-06-17 19:08:45 -0700338 */
Tyler Gunn4c69fb32019-05-17 10:49:16 -0700339 void queryRemoteConnectionServices(RemoteServiceCallback callback, String callingPackage) {
Santos Cordon52d8a152014-06-17 19:08:45 -0700340 // Only supported when there is only one adapter.
341 if (mAdapters.size() == 1) {
342 try {
Tyler Gunn4c69fb32019-05-17 10:49:16 -0700343 mAdapters.iterator().next().queryRemoteConnectionServices(callback, callingPackage,
Brad Ebinger4d75bee2016-10-28 12:29:55 -0700344 Log.getExternalSession());
Santos Cordon52d8a152014-06-17 19:08:45 -0700345 } catch (RemoteException e) {
346 Log.e(this, e, "Exception trying to query for remote CSs");
347 }
Tyler Gunn156a33b2019-05-30 16:52:28 -0700348 } else {
349 try {
350 // This is not an error condition, so just pass back an empty list.
351 // This happens when querying from a remote connection service, not the connection
352 // manager itself.
353 callback.onResult(Collections.EMPTY_LIST, Collections.EMPTY_LIST);
354 } catch (RemoteException e) {
355 Log.e(this, e, "Exception trying to query for remote CSs");
356 }
Santos Cordonb6939982014-06-04 20:20:58 -0700357 }
358 }
Andrew Lee5ffbe8b82014-06-20 16:29:33 -0700359
360 /**
361 * Sets the call video provider for a call.
362 *
363 * @param callId The unique ID of the call to set with the given call video provider.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700364 * @param videoProvider The call video provider instance to set on the call.
Andrew Lee5ffbe8b82014-06-20 16:29:33 -0700365 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700366 void setVideoProvider(
367 String callId, Connection.VideoProvider videoProvider) {
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700368 for (IConnectionServiceAdapter adapter : mAdapters) {
Andrew Lee5ffbe8b82014-06-20 16:29:33 -0700369 try {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700370 adapter.setVideoProvider(
Santos Cordone8dc4be2014-07-21 01:28:28 -0700371 callId,
Brad Ebinger4d75bee2016-10-28 12:29:55 -0700372 videoProvider == null ? null : videoProvider.getInterface(),
373 Log.getExternalSession());
Andrew Lee5ffbe8b82014-06-20 16:29:33 -0700374 } catch (RemoteException e) {
375 }
376 }
377 }
Tyler Gunn8d83fa92014-07-01 11:31:21 -0700378
379 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -0700380 * Requests that the framework use VOIP audio mode for this connection.
381 *
382 * @param callId The unique ID of the call to set with the given call video provider.
383 * @param isVoip True if the audio mode is VOIP.
384 */
Andrew Lee100e2932014-09-08 15:34:24 -0700385 void setIsVoipAudioMode(String callId, boolean isVoip) {
Sailesh Nepal33aaae42014-07-07 22:49:44 -0700386 for (IConnectionServiceAdapter adapter : mAdapters) {
387 try {
Brad Ebinger4d75bee2016-10-28 12:29:55 -0700388 adapter.setIsVoipAudioMode(callId, isVoip, Log.getExternalSession());
Sailesh Nepal33aaae42014-07-07 22:49:44 -0700389 } catch (RemoteException e) {
390 }
391 }
392 }
393
Sailesh Nepale7ef59a2014-07-08 21:48:22 -0700394 void setStatusHints(String callId, StatusHints statusHints) {
395 for (IConnectionServiceAdapter adapter : mAdapters) {
396 try {
Brad Ebinger4d75bee2016-10-28 12:29:55 -0700397 adapter.setStatusHints(callId, statusHints, Log.getExternalSession());
Sailesh Nepale7ef59a2014-07-08 21:48:22 -0700398 } catch (RemoteException e) {
399 }
400 }
401 }
402
Andrew Lee100e2932014-09-08 15:34:24 -0700403 void setAddress(String callId, Uri address, int presentation) {
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700404 for (IConnectionServiceAdapter adapter : mAdapters) {
Tyler Gunn8d83fa92014-07-01 11:31:21 -0700405 try {
Brad Ebinger4d75bee2016-10-28 12:29:55 -0700406 adapter.setAddress(callId, address, presentation, Log.getExternalSession());
Sailesh Nepal61203862014-07-11 14:50:13 -0700407 } catch (RemoteException e) {
408 }
409 }
410 }
411
412 void setCallerDisplayName(String callId, String callerDisplayName, int presentation) {
413 for (IConnectionServiceAdapter adapter : mAdapters) {
414 try {
Brad Ebinger4d75bee2016-10-28 12:29:55 -0700415 adapter.setCallerDisplayName(callId, callerDisplayName, presentation,
416 Log.getExternalSession());
Sailesh Nepal61203862014-07-11 14:50:13 -0700417 } catch (RemoteException e) {
Tyler Gunn8d83fa92014-07-01 11:31:21 -0700418 }
419 }
420 }
Tyler Gunnaa07df82014-07-17 07:50:22 -0700421
422 /**
423 * Sets the video state associated with a call.
424 *
Tyler Gunn87b73f32015-06-03 10:09:59 -0700425 * Valid values: {@link VideoProfile#STATE_BIDIRECTIONAL},
426 * {@link VideoProfile#STATE_AUDIO_ONLY},
427 * {@link VideoProfile#STATE_TX_ENABLED},
428 * {@link VideoProfile#STATE_RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -0700429 *
430 * @param callId The unique ID of the call to set the video state for.
431 * @param videoState The video state.
432 */
433 void setVideoState(String callId, int videoState) {
434 Log.v(this, "setVideoState: %d", videoState);
435 for (IConnectionServiceAdapter adapter : mAdapters) {
436 try {
Brad Ebinger4d75bee2016-10-28 12:29:55 -0700437 adapter.setVideoState(callId, videoState, Log.getExternalSession());
Tyler Gunnaa07df82014-07-17 07:50:22 -0700438 } catch (RemoteException ignored) {
439 }
440 }
441 }
Sailesh Nepal2ab88cc2014-07-18 14:49:18 -0700442
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700443 void setConferenceableConnections(String callId, List<String> conferenceableCallIds) {
444 Log.v(this, "setConferenceableConnections: %s, %s", callId, conferenceableCallIds);
445 for (IConnectionServiceAdapter adapter : mAdapters) {
446 try {
Brad Ebinger4d75bee2016-10-28 12:29:55 -0700447 adapter.setConferenceableConnections(callId, conferenceableCallIds,
448 Log.getExternalSession());
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700449 } catch (RemoteException ignored) {
450 }
451 }
452 }
Tyler Gunn4a57b9b2014-10-30 14:27:48 -0700453
454 /**
455 * Informs telecom of an existing connection which was added by the {@link ConnectionService}.
456 *
457 * @param callId The unique ID of the call being added.
458 * @param connection The connection.
459 */
460 void addExistingConnection(String callId, ParcelableConnection connection) {
461 Log.v(this, "addExistingConnection: %s", callId);
462 for (IConnectionServiceAdapter adapter : mAdapters) {
463 try {
Brad Ebinger4d75bee2016-10-28 12:29:55 -0700464 adapter.addExistingConnection(callId, connection, Log.getExternalSession());
Tyler Gunn4a57b9b2014-10-30 14:27:48 -0700465 } catch (RemoteException ignored) {
466 }
467 }
468 }
Santos Cordon6b7f9552015-05-27 17:21:45 -0700469
470 /**
Tyler Gunndee56a82016-03-23 16:06:34 -0700471 * Adds some extras associated with a {@code Connection}.
Santos Cordon6b7f9552015-05-27 17:21:45 -0700472 *
473 * @param callId The unique ID of the call.
Tyler Gunndee56a82016-03-23 16:06:34 -0700474 * @param extras The extras to add.
Santos Cordon6b7f9552015-05-27 17:21:45 -0700475 */
Tyler Gunndee56a82016-03-23 16:06:34 -0700476 void putExtras(String callId, Bundle extras) {
477 Log.v(this, "putExtras: %s", callId);
Santos Cordon6b7f9552015-05-27 17:21:45 -0700478 for (IConnectionServiceAdapter adapter : mAdapters) {
479 try {
Brad Ebinger4d75bee2016-10-28 12:29:55 -0700480 adapter.putExtras(callId, extras, Log.getExternalSession());
Tyler Gunndee56a82016-03-23 16:06:34 -0700481 } catch (RemoteException ignored) {
482 }
483 }
484 }
485
486 /**
487 * Adds an extra associated with a {@code Connection}.
488 *
489 * @param callId The unique ID of the call.
490 * @param key The extra key.
491 * @param value The extra value.
492 */
493 void putExtra(String callId, String key, boolean value) {
494 Log.v(this, "putExtra: %s %s=%b", callId, key, value);
495 for (IConnectionServiceAdapter adapter : mAdapters) {
496 try {
497 Bundle bundle = new Bundle();
498 bundle.putBoolean(key, value);
Brad Ebinger4d75bee2016-10-28 12:29:55 -0700499 adapter.putExtras(callId, bundle, Log.getExternalSession());
Tyler Gunndee56a82016-03-23 16:06:34 -0700500 } catch (RemoteException ignored) {
501 }
502 }
503 }
504
505 /**
506 * Adds an extra associated with a {@code Connection}.
507 *
508 * @param callId The unique ID of the call.
509 * @param key The extra key.
510 * @param value The extra value.
511 */
512 void putExtra(String callId, String key, int value) {
513 Log.v(this, "putExtra: %s %s=%d", callId, key, value);
514 for (IConnectionServiceAdapter adapter : mAdapters) {
515 try {
516 Bundle bundle = new Bundle();
517 bundle.putInt(key, value);
Brad Ebinger4d75bee2016-10-28 12:29:55 -0700518 adapter.putExtras(callId, bundle, Log.getExternalSession());
Tyler Gunndee56a82016-03-23 16:06:34 -0700519 } catch (RemoteException ignored) {
520 }
521 }
522 }
523
524 /**
525 * Adds an extra associated with a {@code Connection}.
526 *
527 * @param callId The unique ID of the call.
528 * @param key The extra key.
529 * @param value The extra value.
530 */
531 void putExtra(String callId, String key, String value) {
532 Log.v(this, "putExtra: %s %s=%s", callId, key, value);
533 for (IConnectionServiceAdapter adapter : mAdapters) {
534 try {
535 Bundle bundle = new Bundle();
536 bundle.putString(key, value);
Brad Ebinger4d75bee2016-10-28 12:29:55 -0700537 adapter.putExtras(callId, bundle, Log.getExternalSession());
Tyler Gunndee56a82016-03-23 16:06:34 -0700538 } catch (RemoteException ignored) {
539 }
540 }
541 }
542
543 /**
544 * Removes extras associated with a {@code Connection}.
545 * @param callId The unique ID of the call.
546 * @param keys The extra keys to remove.
547 */
548 void removeExtras(String callId, List<String> keys) {
549 Log.v(this, "removeExtras: %s %s", callId, keys);
550 for (IConnectionServiceAdapter adapter : mAdapters) {
551 try {
Brad Ebinger4d75bee2016-10-28 12:29:55 -0700552 adapter.removeExtras(callId, keys, Log.getExternalSession());
Santos Cordon6b7f9552015-05-27 17:21:45 -0700553 } catch (RemoteException ignored) {
554 }
555 }
556 }
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800557
558 /**
Tyler Gunnf5035432017-01-09 09:43:12 -0800559 * Sets the audio route associated with a {@link Connection}.
560 *
561 * @param callId The unique ID of the call.
562 * @param audioRoute The new audio route (see {@code CallAudioState#ROUTE_*}).
563 */
Hall Liua98f58b52017-11-07 17:59:28 -0800564 void setAudioRoute(String callId, int audioRoute, String bluetoothAddress) {
565 Log.v(this, "setAudioRoute: %s %s %s", callId,
566 CallAudioState.audioRouteToString(audioRoute),
567 bluetoothAddress);
Tyler Gunnf5035432017-01-09 09:43:12 -0800568 for (IConnectionServiceAdapter adapter : mAdapters) {
569 try {
Hall Liua98f58b52017-11-07 17:59:28 -0800570 adapter.setAudioRoute(callId, audioRoute,
571 bluetoothAddress, Log.getExternalSession());
Tyler Gunnf5035432017-01-09 09:43:12 -0800572 } catch (RemoteException ignored) {
573 }
574 }
575 }
576
Junhoedf3d822022-11-24 09:26:37 +0000577 /**
578 * Sets the call endpoint associated with a {@link Connection}.
579 *
580 * @param callId The unique ID of the call.
581 * @param endpoint The new call endpoint (see {@link CallEndpoint}).
582 * @param executor The executor of where the callback will execute.
583 * @param callback The callback to notify the result of the endpoint change.
584 */
585 void requestCallEndpointChange(String callId, CallEndpoint endpoint, Executor executor,
586 OutcomeReceiver<Void, CallEndpointException> callback) {
587 Log.v(this, "requestCallEndpointChange");
588 for (IConnectionServiceAdapter adapter : mAdapters) {
589 try {
590 adapter.requestCallEndpointChange(callId, endpoint, new ResultReceiver(null) {
591 @Override
592 protected void onReceiveResult(int resultCode, Bundle result) {
593 super.onReceiveResult(resultCode, result);
594 final long identity = Binder.clearCallingIdentity();
595 try {
596 if (resultCode == CallEndpoint.ENDPOINT_OPERATION_SUCCESS) {
597 executor.execute(() -> callback.onResult(null));
598 } else {
599 executor.execute(() -> callback.onError(result.getParcelable(
600 CallEndpointException.CHANGE_ERROR,
601 CallEndpointException.class)));
602 }
603 } finally {
604 Binder.restoreCallingIdentity(identity);
605 }
606 }}, Log.getExternalSession());
607 } catch (RemoteException ignored) {
608 Log.d(this, "Remote exception calling requestCallEndpointChange");
609 }
610 }
611 }
Tyler Gunnf5035432017-01-09 09:43:12 -0800612
613 /**
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800614 * Informs Telecom of a connection level event.
615 *
616 * @param callId The unique ID of the call.
617 * @param event The event.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700618 * @param extras Extras associated with the event.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800619 */
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700620 void onConnectionEvent(String callId, String event, Bundle extras) {
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800621 Log.v(this, "onConnectionEvent: %s", event);
622 for (IConnectionServiceAdapter adapter : mAdapters) {
623 try {
Brad Ebinger4d75bee2016-10-28 12:29:55 -0700624 adapter.onConnectionEvent(callId, event, extras, Log.getExternalSession());
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800625 } catch (RemoteException ignored) {
626 }
627 }
628 }
Hall Liu57006aa2017-02-06 10:49:48 -0800629
630 /**
631 * Notifies Telecom that an RTT session was successfully established.
632 *
633 * @param callId The unique ID of the call.
634 */
635 void onRttInitiationSuccess(String callId) {
636 Log.v(this, "onRttInitiationSuccess: %s", callId);
637 for (IConnectionServiceAdapter adapter : mAdapters) {
638 try {
639 adapter.onRttInitiationSuccess(callId, Log.getExternalSession());
640 } catch (RemoteException ignored) {
641 }
642 }
643 }
644
645 /**
646 * Notifies Telecom that a requested RTT session failed to be established.
647 *
648 * @param callId The unique ID of the call.
649 */
650 void onRttInitiationFailure(String callId, int reason) {
651 Log.v(this, "onRttInitiationFailure: %s", callId);
652 for (IConnectionServiceAdapter adapter : mAdapters) {
653 try {
654 adapter.onRttInitiationFailure(callId, reason, Log.getExternalSession());
655 } catch (RemoteException ignored) {
656 }
657 }
658 }
659
660 /**
661 * Notifies Telecom that an established RTT session was terminated by the remote user on
662 * the call.
663 *
664 * @param callId The unique ID of the call.
665 */
666 void onRttSessionRemotelyTerminated(String callId) {
667 Log.v(this, "onRttSessionRemotelyTerminated: %s", callId);
668 for (IConnectionServiceAdapter adapter : mAdapters) {
669 try {
670 adapter.onRttSessionRemotelyTerminated(callId, Log.getExternalSession());
671 } catch (RemoteException ignored) {
672 }
673 }
674 }
675
676 /**
677 * Notifies Telecom that the remote user on the call has requested an upgrade to an RTT
678 * session for this call.
679 *
680 * @param callId The unique ID of the call.
681 */
682 void onRemoteRttRequest(String callId) {
683 Log.v(this, "onRemoteRttRequest: %s", callId);
684 for (IConnectionServiceAdapter adapter : mAdapters) {
685 try {
686 adapter.onRemoteRttRequest(callId, Log.getExternalSession());
687 } catch (RemoteException ignored) {
688 }
689 }
690 }
Srikanth Chintalafcb15012017-05-04 20:58:34 +0530691
692 /**
693 * Notifies Telecom that a call's PhoneAccountHandle has changed.
694 *
695 * @param callId The unique ID of the call.
696 * @param pHandle The new PhoneAccountHandle associated with the call.
697 */
698 void onPhoneAccountChanged(String callId, PhoneAccountHandle pHandle) {
699 for (IConnectionServiceAdapter adapter : mAdapters) {
700 try {
701 Log.d(this, "onPhoneAccountChanged %s", callId);
702 adapter.onPhoneAccountChanged(callId, pHandle, Log.getExternalSession());
703 } catch (RemoteException ignored) {
704 }
705 }
706 }
Pengquan Meng63d25a52017-11-21 18:01:13 -0800707
708 /**
709 * Notifies Telecom that the {@link ConnectionService} has released the call resource.
710 */
711 void onConnectionServiceFocusReleased() {
712 for (IConnectionServiceAdapter adapter : mAdapters) {
713 try {
714 Log.d(this, "onConnectionServiceFocusReleased");
715 adapter.onConnectionServiceFocusReleased(Log.getExternalSession());
716 } catch (RemoteException ignored) {
717 }
718 }
719 }
Tyler Gunn68a73a42018-10-03 15:38:57 -0700720
721 /**
722 * Sets whether a conference is treated as a conference or a single party call.
723 * See {@link Conference#setConferenceState(boolean)} for more information.
724 *
725 * @param callId The ID of the telecom call.
726 * @param isConference {@code true} if this call should be treated as a conference,
727 * {@code false} otherwise.
728 */
729 void setConferenceState(String callId, boolean isConference) {
730 Log.v(this, "setConferenceState: %s %b", callId, isConference);
731 for (IConnectionServiceAdapter adapter : mAdapters) {
732 try {
733 adapter.setConferenceState(callId, isConference, Log.getExternalSession());
734 } catch (RemoteException ignored) {
735 }
736 }
737 }
Brad Ebinger31774ae2020-04-08 16:25:12 -0700738
739 /**
740 * Sets the direction of a call. Setting a new direction of an existing call is usually only
741 * applicable during single caller emulation during conferencing, see
742 * {@link Conference#setConferenceState(boolean)} for more information.
743 * @param callId The identifier of the call.
744 * @param direction The new direction of the call.
745 */
746 void setCallDirection(String callId, @Call.Details.CallDirection int direction) {
747 for (IConnectionServiceAdapter a : mAdapters) {
748 try {
749 a.setCallDirection(callId, direction, Log.getExternalSession());
750 } catch (RemoteException e) {
751 }
752 }
753 }
yongnamcha8ec56242022-11-28 06:23:02 +0000754
755 /**
756 * Query location information.
757 * Only SIM call managers can call this method for Connections representing Emergency calls.
758 * If the previous request is not completed, the new request will be rejected.
759 *
760 * @param timeoutMillis long: Timeout in millis waiting for query response.
761 * @param provider String: the location provider name, This value cannot be null.
762 * @param executor The executor of where the callback will execute.
763 * @param callback The callback to notify the result of queryLocation.
764 */
765 void queryLocation(String callId, long timeoutMillis, @NonNull String provider,
766 @NonNull @CallbackExecutor Executor executor,
767 @NonNull OutcomeReceiver<Location, QueryLocationException> callback) {
768 Log.v(this, "queryLocation: %s %d", callId, timeoutMillis);
769 for (IConnectionServiceAdapter adapter : mAdapters) {
770 try {
771 adapter.queryLocation(callId, timeoutMillis, provider,
772 new ResultReceiver(null) {
773 @Override
774 protected void onReceiveResult(int resultCode, Bundle result) {
775 super.onReceiveResult(resultCode, result);
776
777 if (resultCode == 1 /* success */) {
778 executor.execute(() -> callback.onResult(result.getParcelable(
779 Connection.EXTRA_KEY_QUERY_LOCATION, Location.class)));
780 } else {
781 executor.execute(() -> callback.onError(result.getParcelable(
782 QueryLocationException.QUERY_LOCATION_ERROR,
783 QueryLocationException.class)));
784 }
785 }
786 },
787 Log.getExternalSession());
788 } catch (RemoteException e) {
789 Log.d(this, "queryLocation: Exception e : " + e);
790 executor.execute(() -> callback.onError(new QueryLocationException(
791 e.getMessage(), QueryLocationException.ERROR_SERVICE_UNAVAILABLE)));
792 }
793 }
794 }
Ben Giladbb69b0c2013-12-12 18:32:02 -0800795}