blob: 8412e806d6d1816ede766bb1fcf2aeb66939530b [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;
20import android.os.IBinder;
21import android.os.IBinder.DeathRecipient;
Sailesh Nepalab5d2822014-03-08 18:01:06 -080022import android.os.RemoteException;
23
Santos Cordon52d8a152014-06-17 19:08:45 -070024import com.android.internal.telecomm.ICallService;
Sailesh Nepalab5d2822014-03-08 18:01:06 -080025import com.android.internal.telecomm.ICallServiceAdapter;
Andrew Lee5ffbe8b2014-06-20 16:29:33 -070026import com.android.internal.telecomm.ICallVideoProvider;
Santos Cordon52d8a152014-06-17 19:08:45 -070027import com.android.internal.telecomm.RemoteServiceCallback;
Ben Giladbb69b0c2013-12-12 18:32:02 -080028
Santos Cordon52d8a152014-06-17 19:08:45 -070029import java.util.ArrayList;
30import java.util.HashSet;
Santos Cordon980acb92014-05-31 10:31:19 -070031import java.util.List;
Santos Cordon52d8a152014-06-17 19:08:45 -070032import java.util.Set;
Santos Cordon980acb92014-05-31 10:31:19 -070033
Ben Giladbb69b0c2013-12-12 18:32:02 -080034/**
35 * Provides methods for ICallService implementations to interact with the system phone app.
36 * TODO(santoscordon): Need final public-facing comments in this file.
Santos Cordon52d8a152014-06-17 19:08:45 -070037 * TODO(santoscordon): Rename this to CallServiceAdapterDemultiplexer (or something).
Ben Giladbb69b0c2013-12-12 18:32:02 -080038 */
Santos Cordon52d8a152014-06-17 19:08:45 -070039public final class CallServiceAdapter implements DeathRecipient {
40 private final Set<ICallServiceAdapter> mAdapters = new HashSet<>();
Sailesh Nepalab5d2822014-03-08 18:01:06 -080041
42 /**
Santos Cordon52d8a152014-06-17 19:08:45 -070043 * @hide
Sailesh Nepalab5d2822014-03-08 18:01:06 -080044 */
Santos Cordon52d8a152014-06-17 19:08:45 -070045 public CallServiceAdapter() {
46 }
47
48 /**
49 * @hide
50 */
51 public void addAdapter(ICallServiceAdapter adapter) {
52 if (mAdapters.add(adapter)) {
53 try {
54 adapter.asBinder().linkToDeath(this, 0);
55 } catch (RemoteException e) {
56 mAdapters.remove(adapter);
57 }
58 }
59 }
60
61 /**
62 * @hide
63 */
64 public void removeAdapter(ICallServiceAdapter adapter) {
65 if (mAdapters.remove(adapter)) {
66 adapter.asBinder().unlinkToDeath(this, 0);
67 }
68 }
69
70 /** ${inheritDoc} */
71 @Override
72 public void binderDied() {
73 ICallServiceAdapter adapterToRemove = null;
74 for (ICallServiceAdapter adapter : mAdapters) {
75 if (!adapter.asBinder().isBinderAlive()) {
76 adapterToRemove = adapter;
77 break;
78 }
79 }
80
81 if (adapterToRemove != null) {
82 removeAdapter(adapterToRemove);
83 }
Sailesh Nepalab5d2822014-03-08 18:01:06 -080084 }
Ben Giladbb69b0c2013-12-12 18:32:02 -080085
86 /**
Santos Cordonb340c332014-02-19 01:59:32 -080087 * Provides Telecomm with the details of an incoming call. An invocation of this method must
Santos Cordon52d8a152014-06-17 19:08:45 -070088 * follow {@link CallService#setIncomingCallId} and use the call ID specified therein. Upon the
89 * invocation of this method, Telecomm will bring up the incoming-call interface where the user
90 * can elect to answer or reject a call.
Santos Cordon37841332013-12-17 13:30:53 -080091 *
Santos Cordon805afaa2014-01-29 11:58:36 -080092 * @param callInfo The details of the relevant call.
Ben Giladbb69b0c2013-12-12 18:32:02 -080093 */
Sailesh Nepalab5d2822014-03-08 18:01:06 -080094 public void notifyIncomingCall(CallInfo callInfo) {
Santos Cordon52d8a152014-06-17 19:08:45 -070095 for (ICallServiceAdapter adapter : mAdapters) {
96 try {
97 adapter.notifyIncomingCall(callInfo);
98 } catch (RemoteException e) {
99 }
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800100 }
101 }
Ben Giladbb69b0c2013-12-12 18:32:02 -0800102
103 /**
Santos Cordonf6d868b2014-02-05 13:04:15 -0800104 * Tells Telecomm that an attempt to place the specified outgoing call succeeded.
105 * TODO(santoscordon): Consider adding a CallState parameter in case this outgoing call is
106 * somehow no longer in the DIALING state.
Santos Cordon37841332013-12-17 13:30:53 -0800107 *
Santos Cordonf6d868b2014-02-05 13:04:15 -0800108 * @param callId The ID of the outgoing call.
Ben Giladbb69b0c2013-12-12 18:32:02 -0800109 */
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800110 public void handleSuccessfulOutgoingCall(String callId) {
Santos Cordon52d8a152014-06-17 19:08:45 -0700111 for (ICallServiceAdapter adapter : mAdapters) {
112 try {
113 adapter.handleSuccessfulOutgoingCall(callId);
114 } catch (RemoteException e) {
115 }
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800116 }
117 }
Santos Cordonf6d868b2014-02-05 13:04:15 -0800118
119 /**
120 * Tells Telecomm that an attempt to place the specified outgoing call failed.
121 *
Ihab Awadfc91b7d2014-06-03 18:40:45 -0700122 * @param request The originating request for a connection.
123 * @param errorCode The error code associated with the failed call attempt.
124 * @param errorMsg The error message associated with the failed call attempt.
Santos Cordonf6d868b2014-02-05 13:04:15 -0800125 */
Ihab Awadfc91b7d2014-06-03 18:40:45 -0700126 public void handleFailedOutgoingCall(
127 ConnectionRequest request,
128 int errorCode,
129 String errorMsg) {
Santos Cordon52d8a152014-06-17 19:08:45 -0700130 for (ICallServiceAdapter adapter : mAdapters) {
131 try {
132 adapter.handleFailedOutgoingCall(request, errorCode, errorMsg);
133 } catch (RemoteException e) {
134 }
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800135 }
136 }
Ben Giladbb69b0c2013-12-12 18:32:02 -0800137
138 /**
Sailesh Nepal506e3862014-06-25 13:35:14 -0700139 * Tells Telecomm to cancel the call.
140 *
141 * @param callId The ID of the outgoing call.
142 */
143 public void cancelOutgoingCall(String callId) {
144 for (ICallServiceAdapter adapter : mAdapters) {
145 try {
146 adapter.cancelOutgoingCall(callId);
147 } catch (RemoteException e) {
148 }
149 }
150 }
151
152 /**
Ben Giladbb69b0c2013-12-12 18:32:02 -0800153 * Sets a call's state to active (e.g., an ongoing call where two parties can actively
154 * communicate).
Santos Cordon37841332013-12-17 13:30:53 -0800155 *
156 * @param callId The unique ID of the call whose state is changing to active.
Ben Giladbb69b0c2013-12-12 18:32:02 -0800157 */
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800158 public void setActive(String callId) {
Santos Cordon52d8a152014-06-17 19:08:45 -0700159 for (ICallServiceAdapter adapter : mAdapters) {
160 try {
161 adapter.setActive(callId);
162 } catch (RemoteException e) {
163 }
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800164 }
165 }
Ben Giladbb69b0c2013-12-12 18:32:02 -0800166
167 /**
168 * Sets a call's state to ringing (e.g., an inbound ringing call).
Santos Cordon37841332013-12-17 13:30:53 -0800169 *
170 * @param callId The unique ID of the call whose state is changing to ringing.
Ben Giladbb69b0c2013-12-12 18:32:02 -0800171 */
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800172 public void setRinging(String callId) {
Santos Cordon52d8a152014-06-17 19:08:45 -0700173 for (ICallServiceAdapter adapter : mAdapters) {
174 try {
175 adapter.setRinging(callId);
176 } catch (RemoteException e) {
177 }
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800178 }
179 }
Ben Giladbb69b0c2013-12-12 18:32:02 -0800180
181 /**
182 * Sets a call's state to dialing (e.g., dialing an outbound call).
Santos Cordon37841332013-12-17 13:30:53 -0800183 *
184 * @param callId The unique ID of the call whose state is changing to dialing.
Ben Giladbb69b0c2013-12-12 18:32:02 -0800185 */
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800186 public void setDialing(String callId) {
Santos Cordon52d8a152014-06-17 19:08:45 -0700187 for (ICallServiceAdapter adapter : mAdapters) {
188 try {
189 adapter.setDialing(callId);
190 } catch (RemoteException e) {
191 }
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800192 }
193 }
Ben Giladbb69b0c2013-12-12 18:32:02 -0800194
195 /**
196 * Sets a call's state to disconnected.
Santos Cordon37841332013-12-17 13:30:53 -0800197 *
198 * @param callId The unique ID of the call whose state is changing to disconnected.
Santos Cordon20e3f022014-03-27 12:15:38 -0700199 * @param disconnectCause The reason for the disconnection, any of
Santos Cordon52d8a152014-06-17 19:08:45 -0700200 * {@link android.telephony.DisconnectCause}.
Santos Cordon20e3f022014-03-27 12:15:38 -0700201 * @param disconnectMessage Optional call-service-provided message about the disconnect.
Ben Giladbb69b0c2013-12-12 18:32:02 -0800202 */
Santos Cordon20e3f022014-03-27 12:15:38 -0700203 public void setDisconnected(String callId, int disconnectCause, String disconnectMessage) {
Santos Cordon52d8a152014-06-17 19:08:45 -0700204 for (ICallServiceAdapter adapter : mAdapters) {
205 try {
206 adapter.setDisconnected(callId, disconnectCause, disconnectMessage);
207 } catch (RemoteException e) {
208 }
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800209 }
210 }
Yorke Lee81ccaaa2014-03-12 18:33:19 -0700211
212 /**
213 * Sets a call's state to be on hold.
214 *
215 * @param callId - The unique ID of the call whose state is changing to be on hold.
216 */
217 public void setOnHold(String callId) {
Santos Cordon52d8a152014-06-17 19:08:45 -0700218 for (ICallServiceAdapter adapter : mAdapters) {
219 try {
220 adapter.setOnHold(callId);
221 } catch (RemoteException e) {
222 }
Yorke Lee81ccaaa2014-03-12 18:33:19 -0700223 }
224 }
225
Ihab Awadf8358972014-05-28 16:46:42 -0700226 /**
227 * Asks Telecomm to start or stop a ringback tone for a call.
228 *
229 * @param callId The unique ID of the call whose ringback is being changed.
230 * @param ringback Whether Telecomm should start playing a ringback tone.
231 */
232 public void setRequestingRingback(String callId, boolean ringback) {
Santos Cordon52d8a152014-06-17 19:08:45 -0700233 for (ICallServiceAdapter adapter : mAdapters) {
234 try {
235 adapter.setRequestingRingback(callId, ringback);
236 } catch (RemoteException e) {
237 }
Ihab Awadf8358972014-05-28 16:46:42 -0700238 }
239 }
Yorke Lee81ccaaa2014-03-12 18:33:19 -0700240
Santos Cordon980acb92014-05-31 10:31:19 -0700241 /**
242 * Indicates that the specified call can conference with any of the specified list of calls.
243 *
244 * @param callId The unique ID of the call.
Santos Cordonb6939982014-06-04 20:20:58 -0700245 * @param canConference Specified whether or not the call can be conferenced.
Santos Cordon980acb92014-05-31 10:31:19 -0700246 * @hide
247 */
Santos Cordonb6939982014-06-04 20:20:58 -0700248 public void setCanConference(String callId, boolean canConference) {
Santos Cordon52d8a152014-06-17 19:08:45 -0700249 for (ICallServiceAdapter adapter : mAdapters) {
250 try {
251 adapter.setCanConference(callId, canConference);
252 } catch (RemoteException ignored) {
253 }
Santos Cordon980acb92014-05-31 10:31:19 -0700254 }
255 }
256
257 /**
258 * Indicates whether or not the specified call is currently conferenced into the specified
259 * conference call.
260 *
Santos Cordon980acb92014-05-31 10:31:19 -0700261 * @param callId The unique ID of the call being conferenced.
Santos Cordonb6939982014-06-04 20:20:58 -0700262 * @param conferenceCallId The unique ID of the conference call. Null if call is not
Santos Cordon52d8a152014-06-17 19:08:45 -0700263 * conferenced.
Santos Cordon980acb92014-05-31 10:31:19 -0700264 * @hide
265 */
Santos Cordonb6939982014-06-04 20:20:58 -0700266 public void setIsConferenced(String callId, String conferenceCallId) {
Santos Cordon52d8a152014-06-17 19:08:45 -0700267 for (ICallServiceAdapter adapter : mAdapters) {
268 try {
269 adapter.setIsConferenced(callId, conferenceCallId);
270 } catch (RemoteException ignored) {
271 }
Santos Cordon980acb92014-05-31 10:31:19 -0700272 }
273 }
274
275 /**
276 * Indicates that the call no longer exists. Can be used with either a call or a conference
277 * call.
278 *
279 * @param callId The unique ID of the call.
280 * @hide
281 */
282 public void removeCall(String callId) {
Santos Cordon52d8a152014-06-17 19:08:45 -0700283 for (ICallServiceAdapter adapter : mAdapters) {
284 try {
285 adapter.removeCall(callId);
286 } catch (RemoteException ignored) {
287 }
Santos Cordon980acb92014-05-31 10:31:19 -0700288 }
289 }
Evan Charlton6dea4ac2014-06-03 14:07:13 -0700290
291 public void onPostDialWait(String callId, String remaining) {
Santos Cordon52d8a152014-06-17 19:08:45 -0700292 for (ICallServiceAdapter adapter : mAdapters) {
293 try {
294 adapter.onPostDialWait(callId, remaining);
295 } catch (RemoteException ignored) {
296 }
Evan Charlton6dea4ac2014-06-03 14:07:13 -0700297 }
298 }
Sailesh Nepal8b4818d2014-06-06 10:54:07 -0700299
300 /**
301 * Instructs Telecomm to handoff the call to another call service.
302 *
303 * @param callId The identifier of the call to handoff.
304 */
305 public void handoffCall(String callId) {
Santos Cordon52d8a152014-06-17 19:08:45 -0700306 for (ICallServiceAdapter adapter : mAdapters) {
307 try {
308 adapter.handoffCall(callId);
309 } catch (RemoteException e) {
310 }
Sailesh Nepal8b4818d2014-06-06 10:54:07 -0700311 }
312 }
Santos Cordonb6939982014-06-04 20:20:58 -0700313
314 /**
315 * Indicates that a new conference call has been created.
316 *
317 * @param callId The unique ID of the conference call.
318 */
319 public void addConferenceCall(String callId) {
Santos Cordon52d8a152014-06-17 19:08:45 -0700320 for (ICallServiceAdapter adapter : mAdapters) {
321 try {
322 adapter.addConferenceCall(callId, null);
323 } catch (RemoteException ignored) {
324 }
325 }
326 }
327
328 /**
329 * Retrieves a list of remote connection services usable to place calls.
330 * @hide
331 */
332 public void queryRemoteConnectionServices(RemoteServiceCallback callback) {
333 // Only supported when there is only one adapter.
334 if (mAdapters.size() == 1) {
335 try {
336 mAdapters.iterator().next().queryRemoteConnectionServices(callback);
337 } catch (RemoteException e) {
338 Log.e(this, e, "Exception trying to query for remote CSs");
339 }
Santos Cordonb6939982014-06-04 20:20:58 -0700340 }
341 }
Andrew Lee5ffbe8b2014-06-20 16:29:33 -0700342
343 /**
344 * Sets the call video provider for a call.
345 *
346 * @param callId The unique ID of the call to set with the given call video provider.
347 * @param callVideoProvider The call video provider instance to set on the call.
348 */
349 public void setCallVideoProvider(String callId, CallVideoProvider callVideoProvider) {
350 for (ICallServiceAdapter adapter : mAdapters) {
351 try {
352 adapter.setCallVideoProvider(callId, callVideoProvider.getInterface());
353 } catch (RemoteException e) {
354 }
355 }
356 }
Ben Giladbb69b0c2013-12-12 18:32:02 -0800357}