blob: f71544bb8f1ad99b42cc81ff55214b30cb14a987 [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
Sailesh Nepal2a46b902014-07-04 17:21:07 -070024import com.android.internal.telecomm.IConnectionService;
25import com.android.internal.telecomm.IConnectionServiceAdapter;
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;
Sailesh Nepal4dd9df52014-07-10 18:15:15 -070031import java.util.Iterator;
Santos Cordon980acb92014-05-31 10:31:19 -070032import java.util.List;
Santos Cordon52d8a152014-06-17 19:08:45 -070033import java.util.Set;
Santos Cordon980acb92014-05-31 10:31:19 -070034
Ben Giladbb69b0c2013-12-12 18:32:02 -080035/**
Sailesh Nepal2a46b902014-07-04 17:21:07 -070036 * Provides methods for IConnectionService implementations to interact with the system phone app.
Sailesh Nepal2bed9562014-07-02 21:26:12 -070037 *
38 * @hide
Ben Giladbb69b0c2013-12-12 18:32:02 -080039 */
Sailesh Nepal2a46b902014-07-04 17:21:07 -070040final class ConnectionServiceAdapter implements DeathRecipient {
41 private final Set<IConnectionServiceAdapter> mAdapters = new HashSet<>();
Sailesh Nepalab5d2822014-03-08 18:01:06 -080042
Sailesh Nepal2a46b902014-07-04 17:21:07 -070043 ConnectionServiceAdapter() {
Santos Cordon52d8a152014-06-17 19:08:45 -070044 }
45
Sailesh Nepal2a46b902014-07-04 17:21:07 -070046 void addAdapter(IConnectionServiceAdapter adapter) {
Santos Cordon52d8a152014-06-17 19:08:45 -070047 if (mAdapters.add(adapter)) {
48 try {
49 adapter.asBinder().linkToDeath(this, 0);
50 } catch (RemoteException e) {
51 mAdapters.remove(adapter);
52 }
53 }
54 }
55
Sailesh Nepal2a46b902014-07-04 17:21:07 -070056 void removeAdapter(IConnectionServiceAdapter adapter) {
Santos Cordon52d8a152014-06-17 19:08:45 -070057 if (mAdapters.remove(adapter)) {
58 adapter.asBinder().unlinkToDeath(this, 0);
59 }
60 }
61
62 /** ${inheritDoc} */
63 @Override
64 public void binderDied() {
Sailesh Nepal4dd9df52014-07-10 18:15:15 -070065 Iterator<IConnectionServiceAdapter> it = mAdapters.iterator();
66 while (it.hasNext()) {
67 IConnectionServiceAdapter adapter = it.next();
Santos Cordon52d8a152014-06-17 19:08:45 -070068 if (!adapter.asBinder().isBinderAlive()) {
Sailesh Nepal4dd9df52014-07-10 18:15:15 -070069 it.remove();
70 adapter.asBinder().unlinkToDeath(this, 0);
Santos Cordon52d8a152014-06-17 19:08:45 -070071 }
72 }
Sailesh Nepalab5d2822014-03-08 18:01:06 -080073 }
Ben Giladbb69b0c2013-12-12 18:32:02 -080074
75 /**
Santos Cordonb340c332014-02-19 01:59:32 -080076 * Provides Telecomm with the details of an incoming call. An invocation of this method must
Sailesh Nepal2a46b902014-07-04 17:21:07 -070077 * follow {@link ConnectionService#setIncomingCallId} and use the call ID specified therein.
78 * Upon the invocation of this method, Telecomm will bring up the incoming-call interface where
79 * the user can elect to answer or reject a call.
Santos Cordon37841332013-12-17 13:30:53 -080080 *
Sailesh Nepal2a46b902014-07-04 17:21:07 -070081 * @param request The connection request.
Ben Giladbb69b0c2013-12-12 18:32:02 -080082 */
Sailesh Nepal2a46b902014-07-04 17:21:07 -070083 void notifyIncomingCall(ConnectionRequest request) {
84 for (IConnectionServiceAdapter adapter : mAdapters) {
Santos Cordon52d8a152014-06-17 19:08:45 -070085 try {
Sailesh Nepal2a46b902014-07-04 17:21:07 -070086 adapter.notifyIncomingCall(request);
Santos Cordon52d8a152014-06-17 19:08:45 -070087 } catch (RemoteException e) {
88 }
Sailesh Nepalab5d2822014-03-08 18:01:06 -080089 }
90 }
Ben Giladbb69b0c2013-12-12 18:32:02 -080091
92 /**
Santos Cordonf6d868b2014-02-05 13:04:15 -080093 * Tells Telecomm that an attempt to place the specified outgoing call succeeded.
Santos Cordon37841332013-12-17 13:30:53 -080094 *
Sailesh Nepal2a46b902014-07-04 17:21:07 -070095 * @param request The originating request for a connection.
Ben Giladbb69b0c2013-12-12 18:32:02 -080096 */
Sailesh Nepal2a46b902014-07-04 17:21:07 -070097 void handleSuccessfulOutgoingCall(ConnectionRequest request) {
98 for (IConnectionServiceAdapter adapter : mAdapters) {
Santos Cordon52d8a152014-06-17 19:08:45 -070099 try {
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700100 adapter.handleSuccessfulOutgoingCall(request);
Santos Cordon52d8a152014-06-17 19:08:45 -0700101 } catch (RemoteException e) {
102 }
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800103 }
104 }
Santos Cordonf6d868b2014-02-05 13:04:15 -0800105
106 /**
107 * Tells Telecomm that an attempt to place the specified outgoing call failed.
108 *
Ihab Awadfc91b7d2014-06-03 18:40:45 -0700109 * @param request The originating request for a connection.
110 * @param errorCode The error code associated with the failed call attempt.
111 * @param errorMsg The error message associated with the failed call attempt.
Santos Cordonf6d868b2014-02-05 13:04:15 -0800112 */
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700113 void handleFailedOutgoingCall(
Ihab Awadfc91b7d2014-06-03 18:40:45 -0700114 ConnectionRequest request,
115 int errorCode,
116 String errorMsg) {
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700117 for (IConnectionServiceAdapter adapter : mAdapters) {
Santos Cordon52d8a152014-06-17 19:08:45 -0700118 try {
119 adapter.handleFailedOutgoingCall(request, errorCode, errorMsg);
120 } catch (RemoteException e) {
121 }
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800122 }
123 }
Ben Giladbb69b0c2013-12-12 18:32:02 -0800124
125 /**
Sailesh Nepal506e3862014-06-25 13:35:14 -0700126 * Tells Telecomm to cancel the call.
127 *
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700128 * @param request The originating request for a connection.
Sailesh Nepal506e3862014-06-25 13:35:14 -0700129 */
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700130 void cancelOutgoingCall(ConnectionRequest request) {
131 for (IConnectionServiceAdapter adapter : mAdapters) {
Sailesh Nepal506e3862014-06-25 13:35:14 -0700132 try {
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700133 adapter.cancelOutgoingCall(request);
Sailesh Nepal506e3862014-06-25 13:35:14 -0700134 } catch (RemoteException e) {
135 }
136 }
137 }
138
139 /**
Ben Giladbb69b0c2013-12-12 18:32:02 -0800140 * Sets a call's state to active (e.g., an ongoing call where two parties can actively
141 * communicate).
Santos Cordon37841332013-12-17 13:30:53 -0800142 *
143 * @param callId The unique ID of the call whose state is changing to active.
Ben Giladbb69b0c2013-12-12 18:32:02 -0800144 */
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700145 void setActive(String callId) {
146 for (IConnectionServiceAdapter adapter : mAdapters) {
Santos Cordon52d8a152014-06-17 19:08:45 -0700147 try {
148 adapter.setActive(callId);
149 } catch (RemoteException e) {
150 }
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800151 }
152 }
Ben Giladbb69b0c2013-12-12 18:32:02 -0800153
154 /**
155 * Sets a call's state to ringing (e.g., an inbound ringing call).
Santos Cordon37841332013-12-17 13:30:53 -0800156 *
157 * @param callId The unique ID of the call whose state is changing to ringing.
Ben Giladbb69b0c2013-12-12 18:32:02 -0800158 */
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700159 void setRinging(String callId) {
160 for (IConnectionServiceAdapter adapter : mAdapters) {
Santos Cordon52d8a152014-06-17 19:08:45 -0700161 try {
162 adapter.setRinging(callId);
163 } catch (RemoteException e) {
164 }
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800165 }
166 }
Ben Giladbb69b0c2013-12-12 18:32:02 -0800167
168 /**
169 * Sets a call's state to dialing (e.g., dialing an outbound call).
Santos Cordon37841332013-12-17 13:30:53 -0800170 *
171 * @param callId The unique ID of the call whose state is changing to dialing.
Ben Giladbb69b0c2013-12-12 18:32:02 -0800172 */
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700173 void setDialing(String callId) {
174 for (IConnectionServiceAdapter adapter : mAdapters) {
Santos Cordon52d8a152014-06-17 19:08:45 -0700175 try {
176 adapter.setDialing(callId);
177 } catch (RemoteException e) {
178 }
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800179 }
180 }
Ben Giladbb69b0c2013-12-12 18:32:02 -0800181
182 /**
183 * Sets a call's state to disconnected.
Santos Cordon37841332013-12-17 13:30:53 -0800184 *
185 * @param callId The unique ID of the call whose state is changing to disconnected.
Santos Cordon20e3f022014-03-27 12:15:38 -0700186 * @param disconnectCause The reason for the disconnection, any of
Santos Cordon52d8a152014-06-17 19:08:45 -0700187 * {@link android.telephony.DisconnectCause}.
Santos Cordon20e3f022014-03-27 12:15:38 -0700188 * @param disconnectMessage Optional call-service-provided message about the disconnect.
Ben Giladbb69b0c2013-12-12 18:32:02 -0800189 */
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700190 void setDisconnected(String callId, int disconnectCause, String disconnectMessage) {
191 for (IConnectionServiceAdapter adapter : mAdapters) {
Santos Cordon52d8a152014-06-17 19:08:45 -0700192 try {
193 adapter.setDisconnected(callId, disconnectCause, disconnectMessage);
194 } catch (RemoteException e) {
195 }
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800196 }
197 }
Yorke Lee81ccaaa2014-03-12 18:33:19 -0700198
199 /**
200 * Sets a call's state to be on hold.
201 *
202 * @param callId - The unique ID of the call whose state is changing to be on hold.
203 */
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700204 void setOnHold(String callId) {
205 for (IConnectionServiceAdapter adapter : mAdapters) {
Santos Cordon52d8a152014-06-17 19:08:45 -0700206 try {
207 adapter.setOnHold(callId);
208 } catch (RemoteException e) {
209 }
Yorke Lee81ccaaa2014-03-12 18:33:19 -0700210 }
211 }
212
Ihab Awadf8358972014-05-28 16:46:42 -0700213 /**
214 * Asks Telecomm to start or stop a ringback tone for a call.
215 *
216 * @param callId The unique ID of the call whose ringback is being changed.
217 * @param ringback Whether Telecomm should start playing a ringback tone.
218 */
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700219 void setRequestingRingback(String callId, boolean ringback) {
220 for (IConnectionServiceAdapter adapter : mAdapters) {
Santos Cordon52d8a152014-06-17 19:08:45 -0700221 try {
222 adapter.setRequestingRingback(callId, ringback);
223 } catch (RemoteException e) {
224 }
Ihab Awadf8358972014-05-28 16:46:42 -0700225 }
226 }
Yorke Lee81ccaaa2014-03-12 18:33:19 -0700227
Sailesh Nepal1a7061b2014-07-09 21:03:20 -0700228 void setCallCapabilities(String callId, int capabilities) {
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700229 for (IConnectionServiceAdapter adapter : mAdapters) {
Santos Cordon52d8a152014-06-17 19:08:45 -0700230 try {
Sailesh Nepal1a7061b2014-07-09 21:03:20 -0700231 adapter.setCallCapabilities(callId, capabilities);
Santos Cordon52d8a152014-06-17 19:08:45 -0700232 } catch (RemoteException ignored) {
233 }
Santos Cordon980acb92014-05-31 10:31:19 -0700234 }
235 }
236
237 /**
238 * Indicates whether or not the specified call is currently conferenced into the specified
239 * conference call.
240 *
Santos Cordon980acb92014-05-31 10:31:19 -0700241 * @param callId The unique ID of the call being conferenced.
Santos Cordonb6939982014-06-04 20:20:58 -0700242 * @param conferenceCallId The unique ID of the conference call. Null if call is not
Santos Cordon52d8a152014-06-17 19:08:45 -0700243 * conferenced.
Santos Cordon980acb92014-05-31 10:31:19 -0700244 */
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700245 void setIsConferenced(String callId, String conferenceCallId) {
246 for (IConnectionServiceAdapter adapter : mAdapters) {
Santos Cordon52d8a152014-06-17 19:08:45 -0700247 try {
248 adapter.setIsConferenced(callId, conferenceCallId);
249 } catch (RemoteException ignored) {
250 }
Santos Cordon980acb92014-05-31 10:31:19 -0700251 }
252 }
253
254 /**
255 * Indicates that the call no longer exists. Can be used with either a call or a conference
256 * call.
257 *
258 * @param callId The unique ID of the call.
Santos Cordon980acb92014-05-31 10:31:19 -0700259 */
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700260 void removeCall(String callId) {
261 for (IConnectionServiceAdapter adapter : mAdapters) {
Santos Cordon52d8a152014-06-17 19:08:45 -0700262 try {
263 adapter.removeCall(callId);
264 } catch (RemoteException ignored) {
265 }
Santos Cordon980acb92014-05-31 10:31:19 -0700266 }
267 }
Evan Charlton6dea4ac2014-06-03 14:07:13 -0700268
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700269 void onPostDialWait(String callId, String remaining) {
270 for (IConnectionServiceAdapter adapter : mAdapters) {
Santos Cordon52d8a152014-06-17 19:08:45 -0700271 try {
272 adapter.onPostDialWait(callId, remaining);
273 } catch (RemoteException ignored) {
274 }
Evan Charlton6dea4ac2014-06-03 14:07:13 -0700275 }
276 }
Sailesh Nepal8b4818d2014-06-06 10:54:07 -0700277
278 /**
Santos Cordonb6939982014-06-04 20:20:58 -0700279 * Indicates that a new conference call has been created.
280 *
281 * @param callId The unique ID of the conference call.
282 */
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700283 void addConferenceCall(String callId) {
284 for (IConnectionServiceAdapter adapter : mAdapters) {
Santos Cordon52d8a152014-06-17 19:08:45 -0700285 try {
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700286 adapter.addConferenceCall(callId);
Santos Cordon52d8a152014-06-17 19:08:45 -0700287 } catch (RemoteException ignored) {
288 }
289 }
290 }
291
292 /**
293 * Retrieves a list of remote connection services usable to place calls.
Santos Cordon52d8a152014-06-17 19:08:45 -0700294 */
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700295 void queryRemoteConnectionServices(RemoteServiceCallback callback) {
Santos Cordon52d8a152014-06-17 19:08:45 -0700296 // Only supported when there is only one adapter.
297 if (mAdapters.size() == 1) {
298 try {
299 mAdapters.iterator().next().queryRemoteConnectionServices(callback);
300 } catch (RemoteException e) {
301 Log.e(this, e, "Exception trying to query for remote CSs");
302 }
Santos Cordonb6939982014-06-04 20:20:58 -0700303 }
304 }
Andrew Lee5ffbe8b2014-06-20 16:29:33 -0700305
306 /**
307 * Sets the call video provider for a call.
308 *
309 * @param callId The unique ID of the call to set with the given call video provider.
310 * @param callVideoProvider The call video provider instance to set on the call.
311 */
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700312 void setCallVideoProvider(String callId, CallVideoProvider callVideoProvider) {
313 for (IConnectionServiceAdapter adapter : mAdapters) {
Andrew Lee5ffbe8b2014-06-20 16:29:33 -0700314 try {
315 adapter.setCallVideoProvider(callId, callVideoProvider.getInterface());
316 } catch (RemoteException e) {
317 }
318 }
319 }
Tyler Gunn8d83fa92014-07-01 11:31:21 -0700320
321 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -0700322 * Requests that the framework use VOIP audio mode for this connection.
323 *
324 * @param callId The unique ID of the call to set with the given call video provider.
325 * @param isVoip True if the audio mode is VOIP.
326 */
327 void setAudioModeIsVoip(String callId, boolean isVoip) {
328 for (IConnectionServiceAdapter adapter : mAdapters) {
329 try {
330 adapter.setAudioModeIsVoip(callId, isVoip);
331 } catch (RemoteException e) {
332 }
333 }
334 }
335
Sailesh Nepale7ef59a2014-07-08 21:48:22 -0700336 void setStatusHints(String callId, StatusHints statusHints) {
337 for (IConnectionServiceAdapter adapter : mAdapters) {
338 try {
339 adapter.setStatusHints(callId, statusHints);
340 } catch (RemoteException e) {
341 }
342 }
343 }
344
Sailesh Nepal33aaae42014-07-07 22:49:44 -0700345 /**
Tyler Gunn8d83fa92014-07-01 11:31:21 -0700346 * Set the features associated with the given call.
347 * Features are defined in {@link android.telecomm.CallFeatures} and are passed in as a
348 * bit-mask.
349 *
350 * @param callId The unique ID of the call to set features for.
351 * @param features The features.
352 */
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700353 void setFeatures(String callId, int features) {
Tyler Gunn8d83fa92014-07-01 11:31:21 -0700354 Log.v(this, "setFeatures: %d", features);
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700355 for (IConnectionServiceAdapter adapter : mAdapters) {
Tyler Gunn8d83fa92014-07-01 11:31:21 -0700356 try {
357 adapter.setFeatures(callId, features);
358 } catch (RemoteException ignored) {
359 }
360 }
361 }
Ben Giladbb69b0c2013-12-12 18:32:02 -0800362}