blob: 0b8d93d29c6a6716be89bc30298aca05faf18a0e [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
Sailesh Nepal2ab88cc2014-07-18 14:49:18 -070019import android.app.PendingIntent;
Santos Cordon52d8a152014-06-17 19:08:45 -070020import android.content.ComponentName;
Sailesh Nepal61203862014-07-11 14:50:13 -070021import android.net.Uri;
Santos Cordon52d8a152014-06-17 19:08:45 -070022import android.os.IBinder;
23import android.os.IBinder.DeathRecipient;
Sailesh Nepalab5d2822014-03-08 18:01:06 -080024import android.os.RemoteException;
25
Sailesh Nepal2a46b902014-07-04 17:21:07 -070026import com.android.internal.telecomm.IConnectionService;
27import com.android.internal.telecomm.IConnectionServiceAdapter;
Andrew Lee5ffbe8b2014-06-20 16:29:33 -070028import com.android.internal.telecomm.ICallVideoProvider;
Santos Cordon52d8a152014-06-17 19:08:45 -070029import com.android.internal.telecomm.RemoteServiceCallback;
Ben Giladbb69b0c2013-12-12 18:32:02 -080030
Santos Cordon52d8a152014-06-17 19:08:45 -070031import java.util.ArrayList;
32import java.util.HashSet;
Sailesh Nepal4dd9df52014-07-10 18:15:15 -070033import java.util.Iterator;
Santos Cordon980acb92014-05-31 10:31:19 -070034import java.util.List;
Santos Cordon52d8a152014-06-17 19:08:45 -070035import java.util.Set;
Santos Cordon980acb92014-05-31 10:31:19 -070036
Ben Giladbb69b0c2013-12-12 18:32:02 -080037/**
Sailesh Nepal2a46b902014-07-04 17:21:07 -070038 * Provides methods for IConnectionService implementations to interact with the system phone app.
Sailesh Nepal2bed9562014-07-02 21:26:12 -070039 *
40 * @hide
Ben Giladbb69b0c2013-12-12 18:32:02 -080041 */
Sailesh Nepal2a46b902014-07-04 17:21:07 -070042final class ConnectionServiceAdapter implements DeathRecipient {
43 private final Set<IConnectionServiceAdapter> mAdapters = new HashSet<>();
Sailesh Nepalab5d2822014-03-08 18:01:06 -080044
Sailesh Nepal2a46b902014-07-04 17:21:07 -070045 ConnectionServiceAdapter() {
Santos Cordon52d8a152014-06-17 19:08:45 -070046 }
47
Sailesh Nepal2a46b902014-07-04 17:21:07 -070048 void addAdapter(IConnectionServiceAdapter adapter) {
Santos Cordon52d8a152014-06-17 19:08:45 -070049 if (mAdapters.add(adapter)) {
50 try {
51 adapter.asBinder().linkToDeath(this, 0);
52 } catch (RemoteException e) {
53 mAdapters.remove(adapter);
54 }
55 }
56 }
57
Sailesh Nepal2a46b902014-07-04 17:21:07 -070058 void removeAdapter(IConnectionServiceAdapter adapter) {
Santos Cordon52d8a152014-06-17 19:08:45 -070059 if (mAdapters.remove(adapter)) {
60 adapter.asBinder().unlinkToDeath(this, 0);
61 }
62 }
63
64 /** ${inheritDoc} */
65 @Override
66 public void binderDied() {
Sailesh Nepal4dd9df52014-07-10 18:15:15 -070067 Iterator<IConnectionServiceAdapter> it = mAdapters.iterator();
68 while (it.hasNext()) {
69 IConnectionServiceAdapter adapter = it.next();
Santos Cordon52d8a152014-06-17 19:08:45 -070070 if (!adapter.asBinder().isBinderAlive()) {
Sailesh Nepal4dd9df52014-07-10 18:15:15 -070071 it.remove();
72 adapter.asBinder().unlinkToDeath(this, 0);
Santos Cordon52d8a152014-06-17 19:08:45 -070073 }
74 }
Sailesh Nepalab5d2822014-03-08 18:01:06 -080075 }
Ben Giladbb69b0c2013-12-12 18:32:02 -080076
Sailesh Nepalc5b01572014-07-14 16:29:44 -070077 void handleCreateConnectionSuccessful(ConnectionRequest request) {
Sailesh Nepal2a46b902014-07-04 17:21:07 -070078 for (IConnectionServiceAdapter adapter : mAdapters) {
Santos Cordon52d8a152014-06-17 19:08:45 -070079 try {
Sailesh Nepalc5b01572014-07-14 16:29:44 -070080 adapter.handleCreateConnectionSuccessful(request);
Santos Cordon52d8a152014-06-17 19:08:45 -070081 } catch (RemoteException e) {
82 }
Sailesh Nepalab5d2822014-03-08 18:01:06 -080083 }
84 }
Ben Giladbb69b0c2013-12-12 18:32:02 -080085
Sailesh Nepalc5b01572014-07-14 16:29:44 -070086 void handleCreateConnectionFailed(ConnectionRequest request, int errorCode, String errorMsg) {
Sailesh Nepal2a46b902014-07-04 17:21:07 -070087 for (IConnectionServiceAdapter adapter : mAdapters) {
Santos Cordon52d8a152014-06-17 19:08:45 -070088 try {
Sailesh Nepalc5b01572014-07-14 16:29:44 -070089 adapter.handleCreateConnectionFailed(request, errorCode, errorMsg);
Santos Cordon52d8a152014-06-17 19:08:45 -070090 } catch (RemoteException e) {
91 }
Sailesh Nepalab5d2822014-03-08 18:01:06 -080092 }
93 }
Santos Cordonf6d868b2014-02-05 13:04:15 -080094
Sailesh Nepalc5b01572014-07-14 16:29:44 -070095 void handleCreateConnectionCancelled(ConnectionRequest request) {
Sailesh Nepal2a46b902014-07-04 17:21:07 -070096 for (IConnectionServiceAdapter adapter : mAdapters) {
Santos Cordon52d8a152014-06-17 19:08:45 -070097 try {
Sailesh Nepalc5b01572014-07-14 16:29:44 -070098 adapter.handleCreateConnectionCancelled(request);
Sailesh Nepal506e3862014-06-25 13:35:14 -070099 } catch (RemoteException e) {
100 }
101 }
102 }
103
104 /**
Ben Giladbb69b0c2013-12-12 18:32:02 -0800105 * Sets a call's state to active (e.g., an ongoing call where two parties can actively
106 * communicate).
Santos Cordon37841332013-12-17 13:30:53 -0800107 *
108 * @param callId The unique ID of the call whose state is changing to active.
Ben Giladbb69b0c2013-12-12 18:32:02 -0800109 */
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700110 void setActive(String callId) {
111 for (IConnectionServiceAdapter adapter : mAdapters) {
Santos Cordon52d8a152014-06-17 19:08:45 -0700112 try {
113 adapter.setActive(callId);
114 } catch (RemoteException e) {
115 }
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800116 }
117 }
Ben Giladbb69b0c2013-12-12 18:32:02 -0800118
119 /**
120 * Sets a call's state to ringing (e.g., an inbound ringing call).
Santos Cordon37841332013-12-17 13:30:53 -0800121 *
122 * @param callId The unique ID of the call whose state is changing to ringing.
Ben Giladbb69b0c2013-12-12 18:32:02 -0800123 */
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700124 void setRinging(String callId) {
125 for (IConnectionServiceAdapter adapter : mAdapters) {
Santos Cordon52d8a152014-06-17 19:08:45 -0700126 try {
127 adapter.setRinging(callId);
128 } catch (RemoteException e) {
129 }
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800130 }
131 }
Ben Giladbb69b0c2013-12-12 18:32:02 -0800132
133 /**
134 * Sets a call's state to dialing (e.g., dialing an outbound call).
Santos Cordon37841332013-12-17 13:30:53 -0800135 *
136 * @param callId The unique ID of the call whose state is changing to dialing.
Ben Giladbb69b0c2013-12-12 18:32:02 -0800137 */
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700138 void setDialing(String callId) {
139 for (IConnectionServiceAdapter adapter : mAdapters) {
Santos Cordon52d8a152014-06-17 19:08:45 -0700140 try {
141 adapter.setDialing(callId);
142 } catch (RemoteException e) {
143 }
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800144 }
145 }
Ben Giladbb69b0c2013-12-12 18:32:02 -0800146
147 /**
148 * Sets a call's state to disconnected.
Santos Cordon37841332013-12-17 13:30:53 -0800149 *
150 * @param callId The unique ID of the call whose state is changing to disconnected.
Santos Cordon20e3f022014-03-27 12:15:38 -0700151 * @param disconnectCause The reason for the disconnection, any of
Santos Cordon52d8a152014-06-17 19:08:45 -0700152 * {@link android.telephony.DisconnectCause}.
Santos Cordon20e3f022014-03-27 12:15:38 -0700153 * @param disconnectMessage Optional call-service-provided message about the disconnect.
Ben Giladbb69b0c2013-12-12 18:32:02 -0800154 */
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700155 void setDisconnected(String callId, int disconnectCause, String disconnectMessage) {
156 for (IConnectionServiceAdapter adapter : mAdapters) {
Santos Cordon52d8a152014-06-17 19:08:45 -0700157 try {
158 adapter.setDisconnected(callId, disconnectCause, disconnectMessage);
159 } catch (RemoteException e) {
160 }
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800161 }
162 }
Yorke Lee81ccaaa2014-03-12 18:33:19 -0700163
164 /**
165 * Sets a call's state to be on hold.
166 *
167 * @param callId - The unique ID of the call whose state is changing to be on hold.
168 */
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700169 void setOnHold(String callId) {
170 for (IConnectionServiceAdapter adapter : mAdapters) {
Santos Cordon52d8a152014-06-17 19:08:45 -0700171 try {
172 adapter.setOnHold(callId);
173 } catch (RemoteException e) {
174 }
Yorke Lee81ccaaa2014-03-12 18:33:19 -0700175 }
176 }
177
Ihab Awadf8358972014-05-28 16:46:42 -0700178 /**
179 * Asks Telecomm to start or stop a ringback tone for a call.
180 *
181 * @param callId The unique ID of the call whose ringback is being changed.
182 * @param ringback Whether Telecomm should start playing a ringback tone.
183 */
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700184 void setRequestingRingback(String callId, boolean ringback) {
185 for (IConnectionServiceAdapter adapter : mAdapters) {
Santos Cordon52d8a152014-06-17 19:08:45 -0700186 try {
187 adapter.setRequestingRingback(callId, ringback);
188 } catch (RemoteException e) {
189 }
Ihab Awadf8358972014-05-28 16:46:42 -0700190 }
191 }
Yorke Lee81ccaaa2014-03-12 18:33:19 -0700192
Sailesh Nepal1a7061b2014-07-09 21:03:20 -0700193 void setCallCapabilities(String callId, int capabilities) {
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700194 for (IConnectionServiceAdapter adapter : mAdapters) {
Santos Cordon52d8a152014-06-17 19:08:45 -0700195 try {
Sailesh Nepal1a7061b2014-07-09 21:03:20 -0700196 adapter.setCallCapabilities(callId, capabilities);
Santos Cordon52d8a152014-06-17 19:08:45 -0700197 } catch (RemoteException ignored) {
198 }
Santos Cordon980acb92014-05-31 10:31:19 -0700199 }
200 }
201
202 /**
203 * Indicates whether or not the specified call is currently conferenced into the specified
204 * conference call.
205 *
Santos Cordon980acb92014-05-31 10:31:19 -0700206 * @param callId The unique ID of the call being conferenced.
Santos Cordonb6939982014-06-04 20:20:58 -0700207 * @param conferenceCallId The unique ID of the conference call. Null if call is not
Santos Cordon52d8a152014-06-17 19:08:45 -0700208 * conferenced.
Santos Cordon980acb92014-05-31 10:31:19 -0700209 */
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700210 void setIsConferenced(String callId, String conferenceCallId) {
211 for (IConnectionServiceAdapter adapter : mAdapters) {
Santos Cordon52d8a152014-06-17 19:08:45 -0700212 try {
213 adapter.setIsConferenced(callId, conferenceCallId);
214 } catch (RemoteException ignored) {
215 }
Santos Cordon980acb92014-05-31 10:31:19 -0700216 }
217 }
218
219 /**
220 * Indicates that the call no longer exists. Can be used with either a call or a conference
221 * call.
222 *
223 * @param callId The unique ID of the call.
Santos Cordon980acb92014-05-31 10:31:19 -0700224 */
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700225 void removeCall(String callId) {
226 for (IConnectionServiceAdapter adapter : mAdapters) {
Santos Cordon52d8a152014-06-17 19:08:45 -0700227 try {
228 adapter.removeCall(callId);
229 } catch (RemoteException ignored) {
230 }
Santos Cordon980acb92014-05-31 10:31:19 -0700231 }
232 }
Evan Charlton6dea4ac2014-06-03 14:07:13 -0700233
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700234 void onPostDialWait(String callId, String remaining) {
235 for (IConnectionServiceAdapter adapter : mAdapters) {
Santos Cordon52d8a152014-06-17 19:08:45 -0700236 try {
237 adapter.onPostDialWait(callId, remaining);
238 } catch (RemoteException ignored) {
239 }
Evan Charlton6dea4ac2014-06-03 14:07:13 -0700240 }
241 }
Sailesh Nepal8b4818d2014-06-06 10:54:07 -0700242
243 /**
Santos Cordonb6939982014-06-04 20:20:58 -0700244 * Indicates that a new conference call has been created.
245 *
246 * @param callId The unique ID of the conference call.
247 */
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700248 void addConferenceCall(String callId) {
249 for (IConnectionServiceAdapter adapter : mAdapters) {
Santos Cordon52d8a152014-06-17 19:08:45 -0700250 try {
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700251 adapter.addConferenceCall(callId);
Santos Cordon52d8a152014-06-17 19:08:45 -0700252 } catch (RemoteException ignored) {
253 }
254 }
255 }
256
257 /**
258 * Retrieves a list of remote connection services usable to place calls.
Santos Cordon52d8a152014-06-17 19:08:45 -0700259 */
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700260 void queryRemoteConnectionServices(RemoteServiceCallback callback) {
Santos Cordon52d8a152014-06-17 19:08:45 -0700261 // Only supported when there is only one adapter.
262 if (mAdapters.size() == 1) {
263 try {
264 mAdapters.iterator().next().queryRemoteConnectionServices(callback);
265 } catch (RemoteException e) {
266 Log.e(this, e, "Exception trying to query for remote CSs");
267 }
Santos Cordonb6939982014-06-04 20:20:58 -0700268 }
269 }
Andrew Lee5ffbe8b2014-06-20 16:29:33 -0700270
271 /**
272 * Sets the call video provider for a call.
273 *
274 * @param callId The unique ID of the call to set with the given call video provider.
275 * @param callVideoProvider The call video provider instance to set on the call.
276 */
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700277 void setCallVideoProvider(String callId, CallVideoProvider callVideoProvider) {
278 for (IConnectionServiceAdapter adapter : mAdapters) {
Andrew Lee5ffbe8b2014-06-20 16:29:33 -0700279 try {
280 adapter.setCallVideoProvider(callId, callVideoProvider.getInterface());
281 } catch (RemoteException e) {
282 }
283 }
284 }
Tyler Gunn8d83fa92014-07-01 11:31:21 -0700285
286 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -0700287 * Requests that the framework use VOIP audio mode for this connection.
288 *
289 * @param callId The unique ID of the call to set with the given call video provider.
290 * @param isVoip True if the audio mode is VOIP.
291 */
292 void setAudioModeIsVoip(String callId, boolean isVoip) {
293 for (IConnectionServiceAdapter adapter : mAdapters) {
294 try {
295 adapter.setAudioModeIsVoip(callId, isVoip);
296 } catch (RemoteException e) {
297 }
298 }
299 }
300
Sailesh Nepale7ef59a2014-07-08 21:48:22 -0700301 void setStatusHints(String callId, StatusHints statusHints) {
302 for (IConnectionServiceAdapter adapter : mAdapters) {
303 try {
304 adapter.setStatusHints(callId, statusHints);
305 } catch (RemoteException e) {
306 }
307 }
308 }
309
Sailesh Nepal61203862014-07-11 14:50:13 -0700310 void setHandle(String callId, Uri handle, int presentation) {
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700311 for (IConnectionServiceAdapter adapter : mAdapters) {
Tyler Gunn8d83fa92014-07-01 11:31:21 -0700312 try {
Sailesh Nepal61203862014-07-11 14:50:13 -0700313 adapter.setHandle(callId, handle, presentation);
314 } catch (RemoteException e) {
315 }
316 }
317 }
318
319 void setCallerDisplayName(String callId, String callerDisplayName, int presentation) {
320 for (IConnectionServiceAdapter adapter : mAdapters) {
321 try {
322 adapter.setCallerDisplayName(callId, callerDisplayName, presentation);
323 } catch (RemoteException e) {
Tyler Gunn8d83fa92014-07-01 11:31:21 -0700324 }
325 }
326 }
Tyler Gunnaa07df82014-07-17 07:50:22 -0700327
328 /**
329 * Sets the video state associated with a call.
330 *
331 * Valid values: {@link android.telecomm.VideoCallProfile#VIDEO_STATE_AUDIO_ONLY},
332 * {@link android.telecomm.VideoCallProfile#VIDEO_STATE_BIDIRECTIONAL},
333 * {@link android.telecomm.VideoCallProfile#VIDEO_STATE_TX_ENABLED},
334 * {@link android.telecomm.VideoCallProfile#VIDEO_STATE_RX_ENABLED}.
335 *
336 * @param callId The unique ID of the call to set the video state for.
337 * @param videoState The video state.
338 */
339 void setVideoState(String callId, int videoState) {
340 Log.v(this, "setVideoState: %d", videoState);
341 for (IConnectionServiceAdapter adapter : mAdapters) {
342 try {
343 adapter.setVideoState(callId, videoState);
344 } catch (RemoteException ignored) {
345 }
346 }
347 }
Sailesh Nepal2ab88cc2014-07-18 14:49:18 -0700348
349 void startActivityFromInCall(String callId, PendingIntent intent) {
350 for (IConnectionServiceAdapter adapter : mAdapters) {
351 try {
352 adapter.startActivityFromInCall(callId, intent);
353 } catch (RemoteException e) {
354 }
355 }
356 }
Ben Giladbb69b0c2013-12-12 18:32:02 -0800357}