blob: bfcb5c3218be8bba5ab5468d1aab681749747261 [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;
Sailesh Nepal61203862014-07-11 14:50:13 -070020import android.net.Uri;
Santos Cordon52d8a152014-06-17 19:08:45 -070021import 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.IConnectionServiceAdapter;
Santos Cordon52d8a152014-06-17 19:08:45 -070025import com.android.internal.telecomm.RemoteServiceCallback;
Ben Giladbb69b0c2013-12-12 18:32:02 -080026
Jay Shraunerb0c0e362014-08-08 16:31:48 -070027import java.util.Collections;
Sailesh Nepal4dd9df52014-07-10 18:15:15 -070028import java.util.Iterator;
Santos Cordon980acb92014-05-31 10:31:19 -070029import java.util.List;
Santos Cordon52d8a152014-06-17 19:08:45 -070030import java.util.Set;
Jay Shraunerb0c0e362014-08-08 16:31:48 -070031import java.util.concurrent.ConcurrentHashMap;
Santos Cordon980acb92014-05-31 10:31:19 -070032
Ben Giladbb69b0c2013-12-12 18:32:02 -080033/**
Sailesh Nepal2a46b902014-07-04 17:21:07 -070034 * Provides methods for IConnectionService implementations to interact with the system phone app.
Sailesh Nepal2bed9562014-07-02 21:26:12 -070035 *
36 * @hide
Ben Giladbb69b0c2013-12-12 18:32:02 -080037 */
Sailesh Nepal2a46b902014-07-04 17:21:07 -070038final class ConnectionServiceAdapter implements DeathRecipient {
Jay Shraunerb0c0e362014-08-08 16:31:48 -070039 private final Set<IConnectionServiceAdapter> mAdapters = Collections.newSetFromMap(
40 new ConcurrentHashMap<IConnectionServiceAdapter, Boolean>(2));
Sailesh Nepalab5d2822014-03-08 18:01:06 -080041
Sailesh Nepal2a46b902014-07-04 17:21:07 -070042 ConnectionServiceAdapter() {
Santos Cordon52d8a152014-06-17 19:08:45 -070043 }
44
Sailesh Nepal2a46b902014-07-04 17:21:07 -070045 void addAdapter(IConnectionServiceAdapter adapter) {
Santos Cordon52d8a152014-06-17 19:08:45 -070046 if (mAdapters.add(adapter)) {
47 try {
48 adapter.asBinder().linkToDeath(this, 0);
49 } catch (RemoteException e) {
50 mAdapters.remove(adapter);
51 }
52 }
53 }
54
Sailesh Nepal2a46b902014-07-04 17:21:07 -070055 void removeAdapter(IConnectionServiceAdapter adapter) {
Santos Cordon52d8a152014-06-17 19:08:45 -070056 if (mAdapters.remove(adapter)) {
57 adapter.asBinder().unlinkToDeath(this, 0);
58 }
59 }
60
61 /** ${inheritDoc} */
62 @Override
63 public void binderDied() {
Sailesh Nepal4dd9df52014-07-10 18:15:15 -070064 Iterator<IConnectionServiceAdapter> it = mAdapters.iterator();
65 while (it.hasNext()) {
66 IConnectionServiceAdapter adapter = it.next();
Santos Cordon52d8a152014-06-17 19:08:45 -070067 if (!adapter.asBinder().isBinderAlive()) {
Sailesh Nepal4dd9df52014-07-10 18:15:15 -070068 it.remove();
69 adapter.asBinder().unlinkToDeath(this, 0);
Santos Cordon52d8a152014-06-17 19:08:45 -070070 }
71 }
Sailesh Nepalab5d2822014-03-08 18:01:06 -080072 }
Ben Giladbb69b0c2013-12-12 18:32:02 -080073
Santos Cordone8dc4be2014-07-21 01:28:28 -070074 void handleCreateConnectionSuccessful(
Ihab Awadb19a0bc2014-08-07 19:46:01 -070075 String id,
76 ConnectionRequest request,
77 ParcelableConnection connection) {
Sailesh Nepal2a46b902014-07-04 17:21:07 -070078 for (IConnectionServiceAdapter adapter : mAdapters) {
Santos Cordon52d8a152014-06-17 19:08:45 -070079 try {
Ihab Awadb19a0bc2014-08-07 19:46:01 -070080 adapter.handleCreateConnectionSuccessful(id, request, connection);
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
Ihab Awadb19a0bc2014-08-07 19:46:01 -070086 void handleCreateConnectionFailed(
87 String id,
88 ConnectionRequest request,
89 int errorCode,
90 String errorMsg) {
Sailesh Nepal2a46b902014-07-04 17:21:07 -070091 for (IConnectionServiceAdapter adapter : mAdapters) {
Santos Cordon52d8a152014-06-17 19:08:45 -070092 try {
Ihab Awadb19a0bc2014-08-07 19:46:01 -070093 adapter.handleCreateConnectionFailed(id, request, errorCode, errorMsg);
Santos Cordon52d8a152014-06-17 19:08:45 -070094 } catch (RemoteException e) {
95 }
Sailesh Nepalab5d2822014-03-08 18:01:06 -080096 }
97 }
Santos Cordonf6d868b2014-02-05 13:04:15 -080098
Ihab Awadb19a0bc2014-08-07 19:46:01 -070099 void handleCreateConnectionCancelled(
100 String id,
101 ConnectionRequest request) {
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700102 for (IConnectionServiceAdapter adapter : mAdapters) {
Santos Cordon52d8a152014-06-17 19:08:45 -0700103 try {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700104 adapter.handleCreateConnectionCancelled(id, request);
Sailesh Nepal506e3862014-06-25 13:35:14 -0700105 } catch (RemoteException e) {
106 }
107 }
108 }
109
110 /**
Ben Giladbb69b0c2013-12-12 18:32:02 -0800111 * Sets a call's state to active (e.g., an ongoing call where two parties can actively
112 * communicate).
Santos Cordon37841332013-12-17 13:30:53 -0800113 *
114 * @param callId The unique ID of the call whose state is changing to active.
Ben Giladbb69b0c2013-12-12 18:32:02 -0800115 */
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700116 void setActive(String callId) {
117 for (IConnectionServiceAdapter adapter : mAdapters) {
Santos Cordon52d8a152014-06-17 19:08:45 -0700118 try {
119 adapter.setActive(callId);
120 } catch (RemoteException e) {
121 }
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800122 }
123 }
Ben Giladbb69b0c2013-12-12 18:32:02 -0800124
125 /**
126 * Sets a call's state to ringing (e.g., an inbound ringing call).
Santos Cordon37841332013-12-17 13:30:53 -0800127 *
128 * @param callId The unique ID of the call whose state is changing to ringing.
Ben Giladbb69b0c2013-12-12 18:32:02 -0800129 */
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700130 void setRinging(String callId) {
131 for (IConnectionServiceAdapter adapter : mAdapters) {
Santos Cordon52d8a152014-06-17 19:08:45 -0700132 try {
133 adapter.setRinging(callId);
134 } catch (RemoteException e) {
135 }
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800136 }
137 }
Ben Giladbb69b0c2013-12-12 18:32:02 -0800138
139 /**
140 * Sets a call's state to dialing (e.g., dialing an outbound call).
Santos Cordon37841332013-12-17 13:30:53 -0800141 *
142 * @param callId The unique ID of the call whose state is changing to dialing.
Ben Giladbb69b0c2013-12-12 18:32:02 -0800143 */
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700144 void setDialing(String callId) {
145 for (IConnectionServiceAdapter adapter : mAdapters) {
Santos Cordon52d8a152014-06-17 19:08:45 -0700146 try {
147 adapter.setDialing(callId);
148 } catch (RemoteException e) {
149 }
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800150 }
151 }
Ben Giladbb69b0c2013-12-12 18:32:02 -0800152
153 /**
154 * Sets a call's state to disconnected.
Santos Cordon37841332013-12-17 13:30:53 -0800155 *
156 * @param callId The unique ID of the call whose state is changing to disconnected.
Santos Cordon20e3f022014-03-27 12:15:38 -0700157 * @param disconnectCause The reason for the disconnection, any of
Santos Cordon52d8a152014-06-17 19:08:45 -0700158 * {@link android.telephony.DisconnectCause}.
Santos Cordon20e3f022014-03-27 12:15:38 -0700159 * @param disconnectMessage Optional call-service-provided message about the disconnect.
Ben Giladbb69b0c2013-12-12 18:32:02 -0800160 */
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700161 void setDisconnected(String callId, int disconnectCause, String disconnectMessage) {
162 for (IConnectionServiceAdapter adapter : mAdapters) {
Santos Cordon52d8a152014-06-17 19:08:45 -0700163 try {
164 adapter.setDisconnected(callId, disconnectCause, disconnectMessage);
165 } catch (RemoteException e) {
166 }
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800167 }
168 }
Yorke Lee81ccaaa2014-03-12 18:33:19 -0700169
170 /**
171 * Sets a call's state to be on hold.
172 *
173 * @param callId - The unique ID of the call whose state is changing to be on hold.
174 */
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700175 void setOnHold(String callId) {
176 for (IConnectionServiceAdapter adapter : mAdapters) {
Santos Cordon52d8a152014-06-17 19:08:45 -0700177 try {
178 adapter.setOnHold(callId);
179 } catch (RemoteException e) {
180 }
Yorke Lee81ccaaa2014-03-12 18:33:19 -0700181 }
182 }
183
Ihab Awadf8358972014-05-28 16:46:42 -0700184 /**
185 * Asks Telecomm to start or stop a ringback tone for a call.
186 *
187 * @param callId The unique ID of the call whose ringback is being changed.
188 * @param ringback Whether Telecomm should start playing a ringback tone.
189 */
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700190 void setRequestingRingback(String callId, boolean ringback) {
191 for (IConnectionServiceAdapter adapter : mAdapters) {
Santos Cordon52d8a152014-06-17 19:08:45 -0700192 try {
193 adapter.setRequestingRingback(callId, ringback);
194 } catch (RemoteException e) {
195 }
Ihab Awadf8358972014-05-28 16:46:42 -0700196 }
197 }
Yorke Lee81ccaaa2014-03-12 18:33:19 -0700198
Sailesh Nepal1a7061b2014-07-09 21:03:20 -0700199 void setCallCapabilities(String callId, int capabilities) {
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700200 for (IConnectionServiceAdapter adapter : mAdapters) {
Santos Cordon52d8a152014-06-17 19:08:45 -0700201 try {
Sailesh Nepal1a7061b2014-07-09 21:03:20 -0700202 adapter.setCallCapabilities(callId, capabilities);
Santos Cordon52d8a152014-06-17 19:08:45 -0700203 } catch (RemoteException ignored) {
204 }
Santos Cordon980acb92014-05-31 10:31:19 -0700205 }
206 }
207
208 /**
209 * Indicates whether or not the specified call is currently conferenced into the specified
210 * conference call.
211 *
Santos Cordon980acb92014-05-31 10:31:19 -0700212 * @param callId The unique ID of the call being conferenced.
Santos Cordonb6939982014-06-04 20:20:58 -0700213 * @param conferenceCallId The unique ID of the conference call. Null if call is not
Santos Cordon52d8a152014-06-17 19:08:45 -0700214 * conferenced.
Santos Cordon980acb92014-05-31 10:31:19 -0700215 */
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700216 void setIsConferenced(String callId, String conferenceCallId) {
217 for (IConnectionServiceAdapter adapter : mAdapters) {
Santos Cordon52d8a152014-06-17 19:08:45 -0700218 try {
219 adapter.setIsConferenced(callId, conferenceCallId);
220 } catch (RemoteException ignored) {
221 }
Santos Cordon980acb92014-05-31 10:31:19 -0700222 }
223 }
224
225 /**
226 * Indicates that the call no longer exists. Can be used with either a call or a conference
227 * call.
228 *
229 * @param callId The unique ID of the call.
Santos Cordon980acb92014-05-31 10:31:19 -0700230 */
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700231 void removeCall(String callId) {
232 for (IConnectionServiceAdapter adapter : mAdapters) {
Santos Cordon52d8a152014-06-17 19:08:45 -0700233 try {
234 adapter.removeCall(callId);
235 } catch (RemoteException ignored) {
236 }
Santos Cordon980acb92014-05-31 10:31:19 -0700237 }
238 }
Evan Charlton6dea4ac2014-06-03 14:07:13 -0700239
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700240 void onPostDialWait(String callId, String remaining) {
241 for (IConnectionServiceAdapter adapter : mAdapters) {
Santos Cordon52d8a152014-06-17 19:08:45 -0700242 try {
243 adapter.onPostDialWait(callId, remaining);
244 } catch (RemoteException ignored) {
245 }
Evan Charlton6dea4ac2014-06-03 14:07:13 -0700246 }
247 }
Sailesh Nepal8b4818d2014-06-06 10:54:07 -0700248
249 /**
Santos Cordonb6939982014-06-04 20:20:58 -0700250 * Indicates that a new conference call has been created.
251 *
252 * @param callId The unique ID of the conference call.
253 */
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700254 void addConferenceCall(String callId) {
255 for (IConnectionServiceAdapter adapter : mAdapters) {
Santos Cordon52d8a152014-06-17 19:08:45 -0700256 try {
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700257 adapter.addConferenceCall(callId);
Santos Cordon52d8a152014-06-17 19:08:45 -0700258 } catch (RemoteException ignored) {
259 }
260 }
261 }
262
263 /**
264 * Retrieves a list of remote connection services usable to place calls.
Santos Cordon52d8a152014-06-17 19:08:45 -0700265 */
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700266 void queryRemoteConnectionServices(RemoteServiceCallback callback) {
Santos Cordon52d8a152014-06-17 19:08:45 -0700267 // Only supported when there is only one adapter.
268 if (mAdapters.size() == 1) {
269 try {
270 mAdapters.iterator().next().queryRemoteConnectionServices(callback);
271 } catch (RemoteException e) {
272 Log.e(this, e, "Exception trying to query for remote CSs");
273 }
Santos Cordonb6939982014-06-04 20:20:58 -0700274 }
275 }
Andrew Lee5ffbe8b2014-06-20 16:29:33 -0700276
277 /**
278 * Sets the call video provider for a call.
279 *
280 * @param callId The unique ID of the call to set with the given call video provider.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700281 * @param videoProvider The call video provider instance to set on the call.
Andrew Lee5ffbe8b2014-06-20 16:29:33 -0700282 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700283 void setVideoProvider(
284 String callId, Connection.VideoProvider videoProvider) {
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700285 for (IConnectionServiceAdapter adapter : mAdapters) {
Andrew Lee5ffbe8b2014-06-20 16:29:33 -0700286 try {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700287 adapter.setVideoProvider(
Santos Cordone8dc4be2014-07-21 01:28:28 -0700288 callId,
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700289 videoProvider == null ? null : videoProvider.getInterface());
Andrew Lee5ffbe8b2014-06-20 16:29:33 -0700290 } catch (RemoteException e) {
291 }
292 }
293 }
Tyler Gunn8d83fa92014-07-01 11:31:21 -0700294
295 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -0700296 * Requests that the framework use VOIP audio mode for this connection.
297 *
298 * @param callId The unique ID of the call to set with the given call video provider.
299 * @param isVoip True if the audio mode is VOIP.
300 */
301 void setAudioModeIsVoip(String callId, boolean isVoip) {
302 for (IConnectionServiceAdapter adapter : mAdapters) {
303 try {
304 adapter.setAudioModeIsVoip(callId, isVoip);
305 } catch (RemoteException e) {
306 }
307 }
308 }
309
Sailesh Nepale7ef59a2014-07-08 21:48:22 -0700310 void setStatusHints(String callId, StatusHints statusHints) {
311 for (IConnectionServiceAdapter adapter : mAdapters) {
312 try {
313 adapter.setStatusHints(callId, statusHints);
314 } catch (RemoteException e) {
315 }
316 }
317 }
318
Sailesh Nepal61203862014-07-11 14:50:13 -0700319 void setHandle(String callId, Uri handle, int presentation) {
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700320 for (IConnectionServiceAdapter adapter : mAdapters) {
Tyler Gunn8d83fa92014-07-01 11:31:21 -0700321 try {
Sailesh Nepal61203862014-07-11 14:50:13 -0700322 adapter.setHandle(callId, handle, presentation);
323 } catch (RemoteException e) {
324 }
325 }
326 }
327
328 void setCallerDisplayName(String callId, String callerDisplayName, int presentation) {
329 for (IConnectionServiceAdapter adapter : mAdapters) {
330 try {
331 adapter.setCallerDisplayName(callId, callerDisplayName, presentation);
332 } catch (RemoteException e) {
Tyler Gunn8d83fa92014-07-01 11:31:21 -0700333 }
334 }
335 }
Tyler Gunnaa07df82014-07-17 07:50:22 -0700336
337 /**
338 * Sets the video state associated with a call.
339 *
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700340 * Valid values: {@link VideoProfile.VideoState#AUDIO_ONLY},
341 * {@link VideoProfile.VideoState#BIDIRECTIONAL},
342 * {@link VideoProfile.VideoState#TX_ENABLED},
343 * {@link VideoProfile.VideoState#RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -0700344 *
345 * @param callId The unique ID of the call to set the video state for.
346 * @param videoState The video state.
347 */
348 void setVideoState(String callId, int videoState) {
349 Log.v(this, "setVideoState: %d", videoState);
350 for (IConnectionServiceAdapter adapter : mAdapters) {
351 try {
352 adapter.setVideoState(callId, videoState);
353 } catch (RemoteException ignored) {
354 }
355 }
356 }
Sailesh Nepal2ab88cc2014-07-18 14:49:18 -0700357
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700358 void setConferenceableConnections(String callId, List<String> conferenceableCallIds) {
359 Log.v(this, "setConferenceableConnections: %s, %s", callId, conferenceableCallIds);
360 for (IConnectionServiceAdapter adapter : mAdapters) {
361 try {
362 adapter.setConferenceableConnections(callId, conferenceableCallIds);
363 } catch (RemoteException ignored) {
364 }
365 }
366 }
367
Sailesh Nepal2ab88cc2014-07-18 14:49:18 -0700368 void startActivityFromInCall(String callId, PendingIntent intent) {
369 for (IConnectionServiceAdapter adapter : mAdapters) {
370 try {
371 adapter.startActivityFromInCall(callId, intent);
372 } catch (RemoteException e) {
373 }
374 }
375 }
Ben Giladbb69b0c2013-12-12 18:32:02 -0800376}