blob: b90dec306da5a55ec46bd8007b60e4c55181083c [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
17package android.telecomm;
18
Santos Cordon52d8a152014-06-17 19:08:45 -070019import android.content.ComponentName;
Sailesh Nepal61203862014-07-11 14:50:13 -070020import android.net.Uri;
Santos Cordon52d8a152014-06-17 19:08:45 -070021import android.os.IBinder;
22import android.os.IBinder.DeathRecipient;
Sailesh Nepalab5d2822014-03-08 18:01:06 -080023import android.os.RemoteException;
24
Sailesh Nepal2a46b902014-07-04 17:21:07 -070025import com.android.internal.telecomm.IConnectionService;
26import com.android.internal.telecomm.IConnectionServiceAdapter;
Andrew Lee5ffbe8b2014-06-20 16:29:33 -070027import com.android.internal.telecomm.ICallVideoProvider;
Santos Cordon52d8a152014-06-17 19:08:45 -070028import com.android.internal.telecomm.RemoteServiceCallback;
Ben Giladbb69b0c2013-12-12 18:32:02 -080029
Santos Cordon52d8a152014-06-17 19:08:45 -070030import java.util.ArrayList;
31import java.util.HashSet;
Sailesh Nepal4dd9df52014-07-10 18:15:15 -070032import java.util.Iterator;
Santos Cordon980acb92014-05-31 10:31:19 -070033import java.util.List;
Santos Cordon52d8a152014-06-17 19:08:45 -070034import java.util.Set;
Santos Cordon980acb92014-05-31 10:31:19 -070035
Ben Giladbb69b0c2013-12-12 18:32:02 -080036/**
Sailesh Nepal2a46b902014-07-04 17:21:07 -070037 * Provides methods for IConnectionService implementations to interact with the system phone app.
Sailesh Nepal2bed9562014-07-02 21:26:12 -070038 *
39 * @hide
Ben Giladbb69b0c2013-12-12 18:32:02 -080040 */
Sailesh Nepal2a46b902014-07-04 17:21:07 -070041final class ConnectionServiceAdapter implements DeathRecipient {
42 private final Set<IConnectionServiceAdapter> mAdapters = new HashSet<>();
Sailesh Nepalab5d2822014-03-08 18:01:06 -080043
Sailesh Nepal2a46b902014-07-04 17:21:07 -070044 ConnectionServiceAdapter() {
Santos Cordon52d8a152014-06-17 19:08:45 -070045 }
46
Sailesh Nepal2a46b902014-07-04 17:21:07 -070047 void addAdapter(IConnectionServiceAdapter adapter) {
Santos Cordon52d8a152014-06-17 19:08:45 -070048 if (mAdapters.add(adapter)) {
49 try {
50 adapter.asBinder().linkToDeath(this, 0);
51 } catch (RemoteException e) {
52 mAdapters.remove(adapter);
53 }
54 }
55 }
56
Sailesh Nepal2a46b902014-07-04 17:21:07 -070057 void removeAdapter(IConnectionServiceAdapter adapter) {
Santos Cordon52d8a152014-06-17 19:08:45 -070058 if (mAdapters.remove(adapter)) {
59 adapter.asBinder().unlinkToDeath(this, 0);
60 }
61 }
62
63 /** ${inheritDoc} */
64 @Override
65 public void binderDied() {
Sailesh Nepal4dd9df52014-07-10 18:15:15 -070066 Iterator<IConnectionServiceAdapter> it = mAdapters.iterator();
67 while (it.hasNext()) {
68 IConnectionServiceAdapter adapter = it.next();
Santos Cordon52d8a152014-06-17 19:08:45 -070069 if (!adapter.asBinder().isBinderAlive()) {
Sailesh Nepal4dd9df52014-07-10 18:15:15 -070070 it.remove();
71 adapter.asBinder().unlinkToDeath(this, 0);
Santos Cordon52d8a152014-06-17 19:08:45 -070072 }
73 }
Sailesh Nepalab5d2822014-03-08 18:01:06 -080074 }
Ben Giladbb69b0c2013-12-12 18:32:02 -080075
76 /**
Santos Cordonb340c332014-02-19 01:59:32 -080077 * Provides Telecomm with the details of an incoming call. An invocation of this method must
Sailesh Nepal2a46b902014-07-04 17:21:07 -070078 * follow {@link ConnectionService#setIncomingCallId} and use the call ID specified therein.
79 * Upon the invocation of this method, Telecomm will bring up the incoming-call interface where
80 * the user can elect to answer or reject a call.
Santos Cordon37841332013-12-17 13:30:53 -080081 *
Sailesh Nepal2a46b902014-07-04 17:21:07 -070082 * @param request The connection request.
Ben Giladbb69b0c2013-12-12 18:32:02 -080083 */
Sailesh Nepal2a46b902014-07-04 17:21:07 -070084 void notifyIncomingCall(ConnectionRequest request) {
85 for (IConnectionServiceAdapter adapter : mAdapters) {
Santos Cordon52d8a152014-06-17 19:08:45 -070086 try {
Sailesh Nepal2a46b902014-07-04 17:21:07 -070087 adapter.notifyIncomingCall(request);
Santos Cordon52d8a152014-06-17 19:08:45 -070088 } catch (RemoteException e) {
89 }
Sailesh Nepalab5d2822014-03-08 18:01:06 -080090 }
91 }
Ben Giladbb69b0c2013-12-12 18:32:02 -080092
93 /**
Santos Cordonf6d868b2014-02-05 13:04:15 -080094 * Tells Telecomm that an attempt to place the specified outgoing call succeeded.
Santos Cordon37841332013-12-17 13:30:53 -080095 *
Sailesh Nepal2a46b902014-07-04 17:21:07 -070096 * @param request The originating request for a connection.
Ben Giladbb69b0c2013-12-12 18:32:02 -080097 */
Sailesh Nepal2a46b902014-07-04 17:21:07 -070098 void handleSuccessfulOutgoingCall(ConnectionRequest request) {
99 for (IConnectionServiceAdapter adapter : mAdapters) {
Santos Cordon52d8a152014-06-17 19:08:45 -0700100 try {
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700101 adapter.handleSuccessfulOutgoingCall(request);
Santos Cordon52d8a152014-06-17 19:08:45 -0700102 } catch (RemoteException e) {
103 }
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800104 }
105 }
Santos Cordonf6d868b2014-02-05 13:04:15 -0800106
107 /**
108 * Tells Telecomm that an attempt to place the specified outgoing call failed.
109 *
Ihab Awadfc91b7d2014-06-03 18:40:45 -0700110 * @param request The originating request for a connection.
111 * @param errorCode The error code associated with the failed call attempt.
112 * @param errorMsg The error message associated with the failed call attempt.
Santos Cordonf6d868b2014-02-05 13:04:15 -0800113 */
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700114 void handleFailedOutgoingCall(
Ihab Awadfc91b7d2014-06-03 18:40:45 -0700115 ConnectionRequest request,
116 int errorCode,
117 String errorMsg) {
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700118 for (IConnectionServiceAdapter adapter : mAdapters) {
Santos Cordon52d8a152014-06-17 19:08:45 -0700119 try {
120 adapter.handleFailedOutgoingCall(request, errorCode, errorMsg);
121 } catch (RemoteException e) {
122 }
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800123 }
124 }
Ben Giladbb69b0c2013-12-12 18:32:02 -0800125
126 /**
Sailesh Nepal506e3862014-06-25 13:35:14 -0700127 * Tells Telecomm to cancel the call.
128 *
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700129 * @param request The originating request for a connection.
Sailesh Nepal506e3862014-06-25 13:35:14 -0700130 */
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700131 void cancelOutgoingCall(ConnectionRequest request) {
132 for (IConnectionServiceAdapter adapter : mAdapters) {
Sailesh Nepal506e3862014-06-25 13:35:14 -0700133 try {
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700134 adapter.cancelOutgoingCall(request);
Sailesh Nepal506e3862014-06-25 13:35:14 -0700135 } catch (RemoteException e) {
136 }
137 }
138 }
139
140 /**
Ben Giladbb69b0c2013-12-12 18:32:02 -0800141 * Sets a call's state to active (e.g., an ongoing call where two parties can actively
142 * communicate).
Santos Cordon37841332013-12-17 13:30:53 -0800143 *
144 * @param callId The unique ID of the call whose state is changing to active.
Ben Giladbb69b0c2013-12-12 18:32:02 -0800145 */
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700146 void setActive(String callId) {
147 for (IConnectionServiceAdapter adapter : mAdapters) {
Santos Cordon52d8a152014-06-17 19:08:45 -0700148 try {
149 adapter.setActive(callId);
150 } catch (RemoteException e) {
151 }
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800152 }
153 }
Ben Giladbb69b0c2013-12-12 18:32:02 -0800154
155 /**
156 * Sets a call's state to ringing (e.g., an inbound ringing call).
Santos Cordon37841332013-12-17 13:30:53 -0800157 *
158 * @param callId The unique ID of the call whose state is changing to ringing.
Ben Giladbb69b0c2013-12-12 18:32:02 -0800159 */
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700160 void setRinging(String callId) {
161 for (IConnectionServiceAdapter adapter : mAdapters) {
Santos Cordon52d8a152014-06-17 19:08:45 -0700162 try {
163 adapter.setRinging(callId);
164 } catch (RemoteException e) {
165 }
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800166 }
167 }
Ben Giladbb69b0c2013-12-12 18:32:02 -0800168
169 /**
170 * Sets a call's state to dialing (e.g., dialing an outbound call).
Santos Cordon37841332013-12-17 13:30:53 -0800171 *
172 * @param callId The unique ID of the call whose state is changing to dialing.
Ben Giladbb69b0c2013-12-12 18:32:02 -0800173 */
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700174 void setDialing(String callId) {
175 for (IConnectionServiceAdapter adapter : mAdapters) {
Santos Cordon52d8a152014-06-17 19:08:45 -0700176 try {
177 adapter.setDialing(callId);
178 } catch (RemoteException e) {
179 }
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800180 }
181 }
Ben Giladbb69b0c2013-12-12 18:32:02 -0800182
183 /**
184 * Sets a call's state to disconnected.
Santos Cordon37841332013-12-17 13:30:53 -0800185 *
186 * @param callId The unique ID of the call whose state is changing to disconnected.
Santos Cordon20e3f022014-03-27 12:15:38 -0700187 * @param disconnectCause The reason for the disconnection, any of
Santos Cordon52d8a152014-06-17 19:08:45 -0700188 * {@link android.telephony.DisconnectCause}.
Santos Cordon20e3f022014-03-27 12:15:38 -0700189 * @param disconnectMessage Optional call-service-provided message about the disconnect.
Ben Giladbb69b0c2013-12-12 18:32:02 -0800190 */
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700191 void setDisconnected(String callId, int disconnectCause, String disconnectMessage) {
192 for (IConnectionServiceAdapter adapter : mAdapters) {
Santos Cordon52d8a152014-06-17 19:08:45 -0700193 try {
194 adapter.setDisconnected(callId, disconnectCause, disconnectMessage);
195 } catch (RemoteException e) {
196 }
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800197 }
198 }
Yorke Lee81ccaaa2014-03-12 18:33:19 -0700199
200 /**
201 * Sets a call's state to be on hold.
202 *
203 * @param callId - The unique ID of the call whose state is changing to be on hold.
204 */
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700205 void setOnHold(String callId) {
206 for (IConnectionServiceAdapter adapter : mAdapters) {
Santos Cordon52d8a152014-06-17 19:08:45 -0700207 try {
208 adapter.setOnHold(callId);
209 } catch (RemoteException e) {
210 }
Yorke Lee81ccaaa2014-03-12 18:33:19 -0700211 }
212 }
213
Ihab Awadf8358972014-05-28 16:46:42 -0700214 /**
215 * Asks Telecomm to start or stop a ringback tone for a call.
216 *
217 * @param callId The unique ID of the call whose ringback is being changed.
218 * @param ringback Whether Telecomm should start playing a ringback tone.
219 */
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700220 void setRequestingRingback(String callId, boolean ringback) {
221 for (IConnectionServiceAdapter adapter : mAdapters) {
Santos Cordon52d8a152014-06-17 19:08:45 -0700222 try {
223 adapter.setRequestingRingback(callId, ringback);
224 } catch (RemoteException e) {
225 }
Ihab Awadf8358972014-05-28 16:46:42 -0700226 }
227 }
Yorke Lee81ccaaa2014-03-12 18:33:19 -0700228
Sailesh Nepal1a7061b2014-07-09 21:03:20 -0700229 void setCallCapabilities(String callId, int capabilities) {
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700230 for (IConnectionServiceAdapter adapter : mAdapters) {
Santos Cordon52d8a152014-06-17 19:08:45 -0700231 try {
Sailesh Nepal1a7061b2014-07-09 21:03:20 -0700232 adapter.setCallCapabilities(callId, capabilities);
Santos Cordon52d8a152014-06-17 19:08:45 -0700233 } catch (RemoteException ignored) {
234 }
Santos Cordon980acb92014-05-31 10:31:19 -0700235 }
236 }
237
238 /**
239 * Indicates whether or not the specified call is currently conferenced into the specified
240 * conference call.
241 *
Santos Cordon980acb92014-05-31 10:31:19 -0700242 * @param callId The unique ID of the call being conferenced.
Santos Cordonb6939982014-06-04 20:20:58 -0700243 * @param conferenceCallId The unique ID of the conference call. Null if call is not
Santos Cordon52d8a152014-06-17 19:08:45 -0700244 * conferenced.
Santos Cordon980acb92014-05-31 10:31:19 -0700245 */
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700246 void setIsConferenced(String callId, String conferenceCallId) {
247 for (IConnectionServiceAdapter adapter : mAdapters) {
Santos Cordon52d8a152014-06-17 19:08:45 -0700248 try {
249 adapter.setIsConferenced(callId, conferenceCallId);
250 } catch (RemoteException ignored) {
251 }
Santos Cordon980acb92014-05-31 10:31:19 -0700252 }
253 }
254
255 /**
256 * Indicates that the call no longer exists. Can be used with either a call or a conference
257 * call.
258 *
259 * @param callId The unique ID of the call.
Santos Cordon980acb92014-05-31 10:31:19 -0700260 */
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700261 void removeCall(String callId) {
262 for (IConnectionServiceAdapter adapter : mAdapters) {
Santos Cordon52d8a152014-06-17 19:08:45 -0700263 try {
264 adapter.removeCall(callId);
265 } catch (RemoteException ignored) {
266 }
Santos Cordon980acb92014-05-31 10:31:19 -0700267 }
268 }
Evan Charlton6dea4ac2014-06-03 14:07:13 -0700269
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700270 void onPostDialWait(String callId, String remaining) {
271 for (IConnectionServiceAdapter adapter : mAdapters) {
Santos Cordon52d8a152014-06-17 19:08:45 -0700272 try {
273 adapter.onPostDialWait(callId, remaining);
274 } catch (RemoteException ignored) {
275 }
Evan Charlton6dea4ac2014-06-03 14:07:13 -0700276 }
277 }
Sailesh Nepal8b4818d2014-06-06 10:54:07 -0700278
279 /**
Santos Cordonb6939982014-06-04 20:20:58 -0700280 * Indicates that a new conference call has been created.
281 *
282 * @param callId The unique ID of the conference call.
283 */
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700284 void addConferenceCall(String callId) {
285 for (IConnectionServiceAdapter adapter : mAdapters) {
Santos Cordon52d8a152014-06-17 19:08:45 -0700286 try {
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700287 adapter.addConferenceCall(callId);
Santos Cordon52d8a152014-06-17 19:08:45 -0700288 } catch (RemoteException ignored) {
289 }
290 }
291 }
292
293 /**
294 * Retrieves a list of remote connection services usable to place calls.
Santos Cordon52d8a152014-06-17 19:08:45 -0700295 */
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700296 void queryRemoteConnectionServices(RemoteServiceCallback callback) {
Santos Cordon52d8a152014-06-17 19:08:45 -0700297 // Only supported when there is only one adapter.
298 if (mAdapters.size() == 1) {
299 try {
300 mAdapters.iterator().next().queryRemoteConnectionServices(callback);
301 } catch (RemoteException e) {
302 Log.e(this, e, "Exception trying to query for remote CSs");
303 }
Santos Cordonb6939982014-06-04 20:20:58 -0700304 }
305 }
Andrew Lee5ffbe8b2014-06-20 16:29:33 -0700306
307 /**
308 * Sets the call video provider for a call.
309 *
310 * @param callId The unique ID of the call to set with the given call video provider.
311 * @param callVideoProvider The call video provider instance to set on the call.
312 */
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700313 void setCallVideoProvider(String callId, CallVideoProvider callVideoProvider) {
314 for (IConnectionServiceAdapter adapter : mAdapters) {
Andrew Lee5ffbe8b2014-06-20 16:29:33 -0700315 try {
316 adapter.setCallVideoProvider(callId, callVideoProvider.getInterface());
317 } catch (RemoteException e) {
318 }
319 }
320 }
Tyler Gunn8d83fa92014-07-01 11:31:21 -0700321
322 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -0700323 * Requests that the framework use VOIP audio mode for this connection.
324 *
325 * @param callId The unique ID of the call to set with the given call video provider.
326 * @param isVoip True if the audio mode is VOIP.
327 */
328 void setAudioModeIsVoip(String callId, boolean isVoip) {
329 for (IConnectionServiceAdapter adapter : mAdapters) {
330 try {
331 adapter.setAudioModeIsVoip(callId, isVoip);
332 } catch (RemoteException e) {
333 }
334 }
335 }
336
Sailesh Nepale7ef59a2014-07-08 21:48:22 -0700337 void setStatusHints(String callId, StatusHints statusHints) {
338 for (IConnectionServiceAdapter adapter : mAdapters) {
339 try {
340 adapter.setStatusHints(callId, statusHints);
341 } catch (RemoteException e) {
342 }
343 }
344 }
345
Sailesh Nepal61203862014-07-11 14:50:13 -0700346 void setHandle(String callId, Uri handle, int presentation) {
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700347 for (IConnectionServiceAdapter adapter : mAdapters) {
Tyler Gunn8d83fa92014-07-01 11:31:21 -0700348 try {
Sailesh Nepal61203862014-07-11 14:50:13 -0700349 adapter.setHandle(callId, handle, presentation);
350 } catch (RemoteException e) {
351 }
352 }
353 }
354
355 void setCallerDisplayName(String callId, String callerDisplayName, int presentation) {
356 for (IConnectionServiceAdapter adapter : mAdapters) {
357 try {
358 adapter.setCallerDisplayName(callId, callerDisplayName, presentation);
359 } catch (RemoteException e) {
Tyler Gunn8d83fa92014-07-01 11:31:21 -0700360 }
361 }
362 }
Ben Giladbb69b0c2013-12-12 18:32:02 -0800363}