blob: cb6364660a687e8840fc16535d7959fb375c29d3 [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 Shrauner229e3822014-08-15 09:23:07 -070039 /**
40 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
41 * load factor before resizing, 1 means we only expect a single thread to
42 * access the map so make only a single shard
43 */
Jay Shraunerb0c0e362014-08-08 16:31:48 -070044 private final Set<IConnectionServiceAdapter> mAdapters = Collections.newSetFromMap(
Jay Shrauner229e3822014-08-15 09:23:07 -070045 new ConcurrentHashMap<IConnectionServiceAdapter, Boolean>(8, 0.9f, 1));
Sailesh Nepalab5d2822014-03-08 18:01:06 -080046
Sailesh Nepal2a46b902014-07-04 17:21:07 -070047 ConnectionServiceAdapter() {
Santos Cordon52d8a152014-06-17 19:08:45 -070048 }
49
Sailesh Nepal2a46b902014-07-04 17:21:07 -070050 void addAdapter(IConnectionServiceAdapter adapter) {
Santos Cordon52d8a152014-06-17 19:08:45 -070051 if (mAdapters.add(adapter)) {
52 try {
53 adapter.asBinder().linkToDeath(this, 0);
54 } catch (RemoteException e) {
55 mAdapters.remove(adapter);
56 }
57 }
58 }
59
Sailesh Nepal2a46b902014-07-04 17:21:07 -070060 void removeAdapter(IConnectionServiceAdapter adapter) {
Jay Shrauner229e3822014-08-15 09:23:07 -070061 if (adapter != null && mAdapters.remove(adapter)) {
Santos Cordon52d8a152014-06-17 19:08:45 -070062 adapter.asBinder().unlinkToDeath(this, 0);
63 }
64 }
65
66 /** ${inheritDoc} */
67 @Override
68 public void binderDied() {
Sailesh Nepal4dd9df52014-07-10 18:15:15 -070069 Iterator<IConnectionServiceAdapter> it = mAdapters.iterator();
70 while (it.hasNext()) {
71 IConnectionServiceAdapter adapter = it.next();
Santos Cordon52d8a152014-06-17 19:08:45 -070072 if (!adapter.asBinder().isBinderAlive()) {
Sailesh Nepal4dd9df52014-07-10 18:15:15 -070073 it.remove();
74 adapter.asBinder().unlinkToDeath(this, 0);
Santos Cordon52d8a152014-06-17 19:08:45 -070075 }
76 }
Sailesh Nepalab5d2822014-03-08 18:01:06 -080077 }
Ben Giladbb69b0c2013-12-12 18:32:02 -080078
Ihab Awad6107bab2014-08-18 09:23:25 -070079 void handleCreateConnectionComplete(
Ihab Awadb19a0bc2014-08-07 19:46:01 -070080 String id,
81 ConnectionRequest request,
82 ParcelableConnection connection) {
Sailesh Nepal2a46b902014-07-04 17:21:07 -070083 for (IConnectionServiceAdapter adapter : mAdapters) {
Santos Cordon52d8a152014-06-17 19:08:45 -070084 try {
Ihab Awad6107bab2014-08-18 09:23:25 -070085 adapter.handleCreateConnectionComplete(id, request, connection);
Sailesh Nepal506e3862014-06-25 13:35:14 -070086 } catch (RemoteException e) {
87 }
88 }
89 }
90
91 /**
Ben Giladbb69b0c2013-12-12 18:32:02 -080092 * Sets a call's state to active (e.g., an ongoing call where two parties can actively
93 * communicate).
Santos Cordon37841332013-12-17 13:30:53 -080094 *
95 * @param callId The unique ID of the call whose state is changing to active.
Ben Giladbb69b0c2013-12-12 18:32:02 -080096 */
Sailesh Nepal2a46b902014-07-04 17:21:07 -070097 void setActive(String callId) {
98 for (IConnectionServiceAdapter adapter : mAdapters) {
Santos Cordon52d8a152014-06-17 19:08:45 -070099 try {
100 adapter.setActive(callId);
101 } catch (RemoteException e) {
102 }
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800103 }
104 }
Ben Giladbb69b0c2013-12-12 18:32:02 -0800105
106 /**
107 * Sets a call's state to ringing (e.g., an inbound ringing call).
Santos Cordon37841332013-12-17 13:30:53 -0800108 *
109 * @param callId The unique ID of the call whose state is changing to ringing.
Ben Giladbb69b0c2013-12-12 18:32:02 -0800110 */
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700111 void setRinging(String callId) {
112 for (IConnectionServiceAdapter adapter : mAdapters) {
Santos Cordon52d8a152014-06-17 19:08:45 -0700113 try {
114 adapter.setRinging(callId);
115 } catch (RemoteException e) {
116 }
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800117 }
118 }
Ben Giladbb69b0c2013-12-12 18:32:02 -0800119
120 /**
121 * Sets a call's state to dialing (e.g., dialing an outbound call).
Santos Cordon37841332013-12-17 13:30:53 -0800122 *
123 * @param callId The unique ID of the call whose state is changing to dialing.
Ben Giladbb69b0c2013-12-12 18:32:02 -0800124 */
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700125 void setDialing(String callId) {
126 for (IConnectionServiceAdapter adapter : mAdapters) {
Santos Cordon52d8a152014-06-17 19:08:45 -0700127 try {
128 adapter.setDialing(callId);
129 } catch (RemoteException e) {
130 }
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800131 }
132 }
Ben Giladbb69b0c2013-12-12 18:32:02 -0800133
134 /**
135 * Sets a call's state to disconnected.
Santos Cordon37841332013-12-17 13:30:53 -0800136 *
137 * @param callId The unique ID of the call whose state is changing to disconnected.
Santos Cordon20e3f022014-03-27 12:15:38 -0700138 * @param disconnectCause The reason for the disconnection, any of
Santos Cordon52d8a152014-06-17 19:08:45 -0700139 * {@link android.telephony.DisconnectCause}.
Santos Cordon20e3f022014-03-27 12:15:38 -0700140 * @param disconnectMessage Optional call-service-provided message about the disconnect.
Ben Giladbb69b0c2013-12-12 18:32:02 -0800141 */
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700142 void setDisconnected(String callId, int disconnectCause, String disconnectMessage) {
143 for (IConnectionServiceAdapter adapter : mAdapters) {
Santos Cordon52d8a152014-06-17 19:08:45 -0700144 try {
145 adapter.setDisconnected(callId, disconnectCause, disconnectMessage);
146 } catch (RemoteException e) {
147 }
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800148 }
149 }
Yorke Lee81ccaaa2014-03-12 18:33:19 -0700150
151 /**
152 * Sets a call's state to be on hold.
153 *
154 * @param callId - The unique ID of the call whose state is changing to be on hold.
155 */
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700156 void setOnHold(String callId) {
157 for (IConnectionServiceAdapter adapter : mAdapters) {
Santos Cordon52d8a152014-06-17 19:08:45 -0700158 try {
159 adapter.setOnHold(callId);
160 } catch (RemoteException e) {
161 }
Yorke Lee81ccaaa2014-03-12 18:33:19 -0700162 }
163 }
164
Ihab Awadf8358972014-05-28 16:46:42 -0700165 /**
166 * Asks Telecomm to start or stop a ringback tone for a call.
167 *
168 * @param callId The unique ID of the call whose ringback is being changed.
169 * @param ringback Whether Telecomm should start playing a ringback tone.
170 */
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700171 void setRequestingRingback(String callId, boolean ringback) {
172 for (IConnectionServiceAdapter adapter : mAdapters) {
Santos Cordon52d8a152014-06-17 19:08:45 -0700173 try {
174 adapter.setRequestingRingback(callId, ringback);
175 } catch (RemoteException e) {
176 }
Ihab Awadf8358972014-05-28 16:46:42 -0700177 }
178 }
Yorke Lee81ccaaa2014-03-12 18:33:19 -0700179
Sailesh Nepal1a7061b2014-07-09 21:03:20 -0700180 void setCallCapabilities(String callId, int capabilities) {
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700181 for (IConnectionServiceAdapter adapter : mAdapters) {
Santos Cordon52d8a152014-06-17 19:08:45 -0700182 try {
Sailesh Nepal1a7061b2014-07-09 21:03:20 -0700183 adapter.setCallCapabilities(callId, capabilities);
Santos Cordon52d8a152014-06-17 19:08:45 -0700184 } catch (RemoteException ignored) {
185 }
Santos Cordon980acb92014-05-31 10:31:19 -0700186 }
187 }
188
189 /**
190 * Indicates whether or not the specified call is currently conferenced into the specified
191 * conference call.
192 *
Santos Cordon980acb92014-05-31 10:31:19 -0700193 * @param callId The unique ID of the call being conferenced.
Santos Cordonb6939982014-06-04 20:20:58 -0700194 * @param conferenceCallId The unique ID of the conference call. Null if call is not
Santos Cordon52d8a152014-06-17 19:08:45 -0700195 * conferenced.
Santos Cordon980acb92014-05-31 10:31:19 -0700196 */
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700197 void setIsConferenced(String callId, String conferenceCallId) {
198 for (IConnectionServiceAdapter adapter : mAdapters) {
Santos Cordon52d8a152014-06-17 19:08:45 -0700199 try {
Santos Cordon0159ac02014-08-21 14:28:11 -0700200 Log.d(this, "sending connection %s with conference %s", callId, conferenceCallId);
Santos Cordon52d8a152014-06-17 19:08:45 -0700201 adapter.setIsConferenced(callId, conferenceCallId);
202 } catch (RemoteException ignored) {
203 }
Santos Cordon980acb92014-05-31 10:31:19 -0700204 }
205 }
206
207 /**
208 * Indicates that the call no longer exists. Can be used with either a call or a conference
209 * call.
210 *
211 * @param callId The unique ID of the call.
Santos Cordon980acb92014-05-31 10:31:19 -0700212 */
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700213 void removeCall(String callId) {
214 for (IConnectionServiceAdapter adapter : mAdapters) {
Santos Cordon52d8a152014-06-17 19:08:45 -0700215 try {
216 adapter.removeCall(callId);
217 } catch (RemoteException ignored) {
218 }
Santos Cordon980acb92014-05-31 10:31:19 -0700219 }
220 }
Evan Charlton6dea4ac2014-06-03 14:07:13 -0700221
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700222 void onPostDialWait(String callId, String remaining) {
223 for (IConnectionServiceAdapter adapter : mAdapters) {
Santos Cordon52d8a152014-06-17 19:08:45 -0700224 try {
225 adapter.onPostDialWait(callId, remaining);
226 } catch (RemoteException ignored) {
227 }
Evan Charlton6dea4ac2014-06-03 14:07:13 -0700228 }
229 }
Sailesh Nepal8b4818d2014-06-06 10:54:07 -0700230
231 /**
Santos Cordonb6939982014-06-04 20:20:58 -0700232 * Indicates that a new conference call has been created.
233 *
234 * @param callId The unique ID of the conference call.
235 */
Santos Cordon823fd3c2014-08-07 18:35:18 -0700236 void addConferenceCall(String callId, ParcelableConference parcelableConference) {
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700237 for (IConnectionServiceAdapter adapter : mAdapters) {
Santos Cordon52d8a152014-06-17 19:08:45 -0700238 try {
Santos Cordon823fd3c2014-08-07 18:35:18 -0700239 adapter.addConferenceCall(callId, parcelableConference);
Santos Cordon52d8a152014-06-17 19:08:45 -0700240 } catch (RemoteException ignored) {
241 }
242 }
243 }
244
245 /**
246 * Retrieves a list of remote connection services usable to place calls.
Santos Cordon52d8a152014-06-17 19:08:45 -0700247 */
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700248 void queryRemoteConnectionServices(RemoteServiceCallback callback) {
Santos Cordon52d8a152014-06-17 19:08:45 -0700249 // Only supported when there is only one adapter.
250 if (mAdapters.size() == 1) {
251 try {
252 mAdapters.iterator().next().queryRemoteConnectionServices(callback);
253 } catch (RemoteException e) {
254 Log.e(this, e, "Exception trying to query for remote CSs");
255 }
Santos Cordonb6939982014-06-04 20:20:58 -0700256 }
257 }
Andrew Lee5ffbe8b2014-06-20 16:29:33 -0700258
259 /**
260 * Sets the call video provider for a call.
261 *
262 * @param callId The unique ID of the call to set with the given call video provider.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700263 * @param videoProvider The call video provider instance to set on the call.
Andrew Lee5ffbe8b2014-06-20 16:29:33 -0700264 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700265 void setVideoProvider(
266 String callId, Connection.VideoProvider videoProvider) {
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700267 for (IConnectionServiceAdapter adapter : mAdapters) {
Andrew Lee5ffbe8b2014-06-20 16:29:33 -0700268 try {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700269 adapter.setVideoProvider(
Santos Cordone8dc4be2014-07-21 01:28:28 -0700270 callId,
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700271 videoProvider == null ? null : videoProvider.getInterface());
Andrew Lee5ffbe8b2014-06-20 16:29:33 -0700272 } catch (RemoteException e) {
273 }
274 }
275 }
Tyler Gunn8d83fa92014-07-01 11:31:21 -0700276
277 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -0700278 * Requests that the framework use VOIP audio mode for this connection.
279 *
280 * @param callId The unique ID of the call to set with the given call video provider.
281 * @param isVoip True if the audio mode is VOIP.
282 */
283 void setAudioModeIsVoip(String callId, boolean isVoip) {
284 for (IConnectionServiceAdapter adapter : mAdapters) {
285 try {
286 adapter.setAudioModeIsVoip(callId, isVoip);
287 } catch (RemoteException e) {
288 }
289 }
290 }
291
Sailesh Nepale7ef59a2014-07-08 21:48:22 -0700292 void setStatusHints(String callId, StatusHints statusHints) {
293 for (IConnectionServiceAdapter adapter : mAdapters) {
294 try {
295 adapter.setStatusHints(callId, statusHints);
296 } catch (RemoteException e) {
297 }
298 }
299 }
300
Sailesh Nepal61203862014-07-11 14:50:13 -0700301 void setHandle(String callId, Uri handle, int presentation) {
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700302 for (IConnectionServiceAdapter adapter : mAdapters) {
Tyler Gunn8d83fa92014-07-01 11:31:21 -0700303 try {
Sailesh Nepal61203862014-07-11 14:50:13 -0700304 adapter.setHandle(callId, handle, presentation);
305 } catch (RemoteException e) {
306 }
307 }
308 }
309
310 void setCallerDisplayName(String callId, String callerDisplayName, int presentation) {
311 for (IConnectionServiceAdapter adapter : mAdapters) {
312 try {
313 adapter.setCallerDisplayName(callId, callerDisplayName, presentation);
314 } catch (RemoteException e) {
Tyler Gunn8d83fa92014-07-01 11:31:21 -0700315 }
316 }
317 }
Tyler Gunnaa07df82014-07-17 07:50:22 -0700318
319 /**
320 * Sets the video state associated with a call.
321 *
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700322 * Valid values: {@link VideoProfile.VideoState#AUDIO_ONLY},
323 * {@link VideoProfile.VideoState#BIDIRECTIONAL},
324 * {@link VideoProfile.VideoState#TX_ENABLED},
325 * {@link VideoProfile.VideoState#RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -0700326 *
327 * @param callId The unique ID of the call to set the video state for.
328 * @param videoState The video state.
329 */
330 void setVideoState(String callId, int videoState) {
331 Log.v(this, "setVideoState: %d", videoState);
332 for (IConnectionServiceAdapter adapter : mAdapters) {
333 try {
334 adapter.setVideoState(callId, videoState);
335 } catch (RemoteException ignored) {
336 }
337 }
338 }
Sailesh Nepal2ab88cc2014-07-18 14:49:18 -0700339
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700340 void setConferenceableConnections(String callId, List<String> conferenceableCallIds) {
341 Log.v(this, "setConferenceableConnections: %s, %s", callId, conferenceableCallIds);
342 for (IConnectionServiceAdapter adapter : mAdapters) {
343 try {
344 adapter.setConferenceableConnections(callId, conferenceableCallIds);
345 } catch (RemoteException ignored) {
346 }
347 }
348 }
349
Sailesh Nepal2ab88cc2014-07-18 14:49:18 -0700350 void startActivityFromInCall(String callId, PendingIntent intent) {
351 for (IConnectionServiceAdapter adapter : mAdapters) {
352 try {
353 adapter.startActivityFromInCall(callId, intent);
354 } catch (RemoteException e) {
355 }
356 }
357 }
Ben Giladbb69b0c2013-12-12 18:32:02 -0800358}