blob: f6bcdc66a84fd237e61672b27c9c9ad430cdd926 [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
Tyler Gunnef9f6f92014-09-12 22:16:17 -070017package android.telecom;
Ben Giladbb69b0c2013-12-12 18:32:02 -080018
Sailesh Nepal61203862014-07-11 14:50:13 -070019import android.net.Uri;
Santos Cordon52d8a152014-06-17 19:08:45 -070020import android.os.IBinder.DeathRecipient;
Sailesh Nepalab5d2822014-03-08 18:01:06 -080021import android.os.RemoteException;
22
Tyler Gunnef9f6f92014-09-12 22:16:17 -070023import com.android.internal.telecom.IConnectionServiceAdapter;
24import com.android.internal.telecom.RemoteServiceCallback;
Ben Giladbb69b0c2013-12-12 18:32:02 -080025
Jay Shraunerb0c0e362014-08-08 16:31:48 -070026import java.util.Collections;
Sailesh Nepal4dd9df52014-07-10 18:15:15 -070027import java.util.Iterator;
Santos Cordon980acb92014-05-31 10:31:19 -070028import java.util.List;
Santos Cordon52d8a152014-06-17 19:08:45 -070029import java.util.Set;
Jay Shraunerb0c0e362014-08-08 16:31:48 -070030import java.util.concurrent.ConcurrentHashMap;
Santos Cordon980acb92014-05-31 10:31:19 -070031
Ben Giladbb69b0c2013-12-12 18:32:02 -080032/**
Sailesh Nepal2a46b902014-07-04 17:21:07 -070033 * Provides methods for IConnectionService implementations to interact with the system phone app.
Sailesh Nepal2bed9562014-07-02 21:26:12 -070034 *
35 * @hide
Ben Giladbb69b0c2013-12-12 18:32:02 -080036 */
Sailesh Nepal2a46b902014-07-04 17:21:07 -070037final class ConnectionServiceAdapter implements DeathRecipient {
Jay Shrauner229e3822014-08-15 09:23:07 -070038 /**
39 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
40 * load factor before resizing, 1 means we only expect a single thread to
41 * access the map so make only a single shard
42 */
Jay Shraunerb0c0e362014-08-08 16:31:48 -070043 private final Set<IConnectionServiceAdapter> mAdapters = Collections.newSetFromMap(
Jay Shrauner229e3822014-08-15 09:23:07 -070044 new ConcurrentHashMap<IConnectionServiceAdapter, Boolean>(8, 0.9f, 1));
Sailesh Nepalab5d2822014-03-08 18:01:06 -080045
Sailesh Nepal2a46b902014-07-04 17:21:07 -070046 ConnectionServiceAdapter() {
Santos Cordon52d8a152014-06-17 19:08:45 -070047 }
48
Sailesh Nepal2a46b902014-07-04 17:21:07 -070049 void addAdapter(IConnectionServiceAdapter adapter) {
Santos Cordon52d8a152014-06-17 19:08:45 -070050 if (mAdapters.add(adapter)) {
51 try {
52 adapter.asBinder().linkToDeath(this, 0);
53 } catch (RemoteException e) {
54 mAdapters.remove(adapter);
55 }
56 }
57 }
58
Sailesh Nepal2a46b902014-07-04 17:21:07 -070059 void removeAdapter(IConnectionServiceAdapter adapter) {
Jay Shrauner229e3822014-08-15 09:23:07 -070060 if (adapter != null && mAdapters.remove(adapter)) {
Santos Cordon52d8a152014-06-17 19:08:45 -070061 adapter.asBinder().unlinkToDeath(this, 0);
62 }
63 }
64
65 /** ${inheritDoc} */
66 @Override
67 public void binderDied() {
Sailesh Nepal4dd9df52014-07-10 18:15:15 -070068 Iterator<IConnectionServiceAdapter> it = mAdapters.iterator();
69 while (it.hasNext()) {
70 IConnectionServiceAdapter adapter = it.next();
Santos Cordon52d8a152014-06-17 19:08:45 -070071 if (!adapter.asBinder().isBinderAlive()) {
Sailesh Nepal4dd9df52014-07-10 18:15:15 -070072 it.remove();
73 adapter.asBinder().unlinkToDeath(this, 0);
Santos Cordon52d8a152014-06-17 19:08:45 -070074 }
75 }
Sailesh Nepalab5d2822014-03-08 18:01:06 -080076 }
Ben Giladbb69b0c2013-12-12 18:32:02 -080077
Ihab Awad6107bab2014-08-18 09:23:25 -070078 void handleCreateConnectionComplete(
Ihab Awadb19a0bc2014-08-07 19:46:01 -070079 String id,
80 ConnectionRequest request,
81 ParcelableConnection connection) {
Sailesh Nepal2a46b902014-07-04 17:21:07 -070082 for (IConnectionServiceAdapter adapter : mAdapters) {
Santos Cordon52d8a152014-06-17 19:08:45 -070083 try {
Ihab Awad6107bab2014-08-18 09:23:25 -070084 adapter.handleCreateConnectionComplete(id, request, connection);
Sailesh Nepal506e3862014-06-25 13:35:14 -070085 } catch (RemoteException e) {
86 }
87 }
88 }
89
90 /**
Ben Giladbb69b0c2013-12-12 18:32:02 -080091 * Sets a call's state to active (e.g., an ongoing call where two parties can actively
92 * communicate).
Santos Cordon37841332013-12-17 13:30:53 -080093 *
94 * @param callId The unique ID of the call whose state is changing to active.
Ben Giladbb69b0c2013-12-12 18:32:02 -080095 */
Sailesh Nepal2a46b902014-07-04 17:21:07 -070096 void setActive(String callId) {
97 for (IConnectionServiceAdapter adapter : mAdapters) {
Santos Cordon52d8a152014-06-17 19:08:45 -070098 try {
99 adapter.setActive(callId);
100 } catch (RemoteException e) {
101 }
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800102 }
103 }
Ben Giladbb69b0c2013-12-12 18:32:02 -0800104
105 /**
106 * Sets a call's state to ringing (e.g., an inbound ringing call).
Santos Cordon37841332013-12-17 13:30:53 -0800107 *
108 * @param callId The unique ID of the call whose state is changing to ringing.
Ben Giladbb69b0c2013-12-12 18:32:02 -0800109 */
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700110 void setRinging(String callId) {
111 for (IConnectionServiceAdapter adapter : mAdapters) {
Santos Cordon52d8a152014-06-17 19:08:45 -0700112 try {
113 adapter.setRinging(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 dialing (e.g., dialing an outbound call).
Santos Cordon37841332013-12-17 13:30:53 -0800121 *
122 * @param callId The unique ID of the call whose state is changing to dialing.
Ben Giladbb69b0c2013-12-12 18:32:02 -0800123 */
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700124 void setDialing(String callId) {
125 for (IConnectionServiceAdapter adapter : mAdapters) {
Santos Cordon52d8a152014-06-17 19:08:45 -0700126 try {
127 adapter.setDialing(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 disconnected.
Santos Cordon37841332013-12-17 13:30:53 -0800135 *
136 * @param callId The unique ID of the call whose state is changing to disconnected.
Santos Cordon20e3f022014-03-27 12:15:38 -0700137 * @param disconnectCause The reason for the disconnection, any of
Santos Cordon52d8a152014-06-17 19:08:45 -0700138 * {@link android.telephony.DisconnectCause}.
Santos Cordon20e3f022014-03-27 12:15:38 -0700139 * @param disconnectMessage Optional call-service-provided message about the disconnect.
Ben Giladbb69b0c2013-12-12 18:32:02 -0800140 */
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700141 void setDisconnected(String callId, int disconnectCause, String disconnectMessage) {
142 for (IConnectionServiceAdapter adapter : mAdapters) {
Santos Cordon52d8a152014-06-17 19:08:45 -0700143 try {
144 adapter.setDisconnected(callId, disconnectCause, disconnectMessage);
145 } catch (RemoteException e) {
146 }
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800147 }
148 }
Yorke Lee81ccaaa2014-03-12 18:33:19 -0700149
150 /**
151 * Sets a call's state to be on hold.
152 *
153 * @param callId - The unique ID of the call whose state is changing to be on hold.
154 */
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700155 void setOnHold(String callId) {
156 for (IConnectionServiceAdapter adapter : mAdapters) {
Santos Cordon52d8a152014-06-17 19:08:45 -0700157 try {
158 adapter.setOnHold(callId);
159 } catch (RemoteException e) {
160 }
Yorke Lee81ccaaa2014-03-12 18:33:19 -0700161 }
162 }
163
Ihab Awadf8358972014-05-28 16:46:42 -0700164 /**
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700165 * Asks Telecom to start or stop a ringback tone for a call.
Ihab Awadf8358972014-05-28 16:46:42 -0700166 *
167 * @param callId The unique ID of the call whose ringback is being changed.
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700168 * @param ringback Whether Telecom should start playing a ringback tone.
Ihab Awadf8358972014-05-28 16:46:42 -0700169 */
Andrew Lee100e2932014-09-08 15:34:24 -0700170 void setRingbackRequested(String callId, boolean ringback) {
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700171 for (IConnectionServiceAdapter adapter : mAdapters) {
Santos Cordon52d8a152014-06-17 19:08:45 -0700172 try {
Andrew Lee100e2932014-09-08 15:34:24 -0700173 adapter.setRingbackRequested(callId, ringback);
Santos Cordon52d8a152014-06-17 19:08:45 -0700174 } catch (RemoteException e) {
175 }
Ihab Awadf8358972014-05-28 16:46:42 -0700176 }
177 }
Yorke Lee81ccaaa2014-03-12 18:33:19 -0700178
Sailesh Nepal1a7061b2014-07-09 21:03:20 -0700179 void setCallCapabilities(String callId, int capabilities) {
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700180 for (IConnectionServiceAdapter adapter : mAdapters) {
Santos Cordon52d8a152014-06-17 19:08:45 -0700181 try {
Sailesh Nepal1a7061b2014-07-09 21:03:20 -0700182 adapter.setCallCapabilities(callId, capabilities);
Santos Cordon52d8a152014-06-17 19:08:45 -0700183 } catch (RemoteException ignored) {
184 }
Santos Cordon980acb92014-05-31 10:31:19 -0700185 }
186 }
187
188 /**
189 * Indicates whether or not the specified call is currently conferenced into the specified
190 * conference call.
191 *
Santos Cordon980acb92014-05-31 10:31:19 -0700192 * @param callId The unique ID of the call being conferenced.
Santos Cordonb6939982014-06-04 20:20:58 -0700193 * @param conferenceCallId The unique ID of the conference call. Null if call is not
Santos Cordon52d8a152014-06-17 19:08:45 -0700194 * conferenced.
Santos Cordon980acb92014-05-31 10:31:19 -0700195 */
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700196 void setIsConferenced(String callId, String conferenceCallId) {
197 for (IConnectionServiceAdapter adapter : mAdapters) {
Santos Cordon52d8a152014-06-17 19:08:45 -0700198 try {
Santos Cordon0159ac02014-08-21 14:28:11 -0700199 Log.d(this, "sending connection %s with conference %s", callId, conferenceCallId);
Santos Cordon52d8a152014-06-17 19:08:45 -0700200 adapter.setIsConferenced(callId, conferenceCallId);
201 } catch (RemoteException ignored) {
202 }
Santos Cordon980acb92014-05-31 10:31:19 -0700203 }
204 }
205
206 /**
207 * Indicates that the call no longer exists. Can be used with either a call or a conference
208 * call.
209 *
210 * @param callId The unique ID of the call.
Santos Cordon980acb92014-05-31 10:31:19 -0700211 */
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700212 void removeCall(String callId) {
213 for (IConnectionServiceAdapter adapter : mAdapters) {
Santos Cordon52d8a152014-06-17 19:08:45 -0700214 try {
215 adapter.removeCall(callId);
216 } catch (RemoteException ignored) {
217 }
Santos Cordon980acb92014-05-31 10:31:19 -0700218 }
219 }
Evan Charlton6dea4ac2014-06-03 14:07:13 -0700220
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700221 void onPostDialWait(String callId, String remaining) {
222 for (IConnectionServiceAdapter adapter : mAdapters) {
Santos Cordon52d8a152014-06-17 19:08:45 -0700223 try {
224 adapter.onPostDialWait(callId, remaining);
225 } catch (RemoteException ignored) {
226 }
Evan Charlton6dea4ac2014-06-03 14:07:13 -0700227 }
228 }
Sailesh Nepal8b4818d2014-06-06 10:54:07 -0700229
230 /**
Santos Cordonb6939982014-06-04 20:20:58 -0700231 * Indicates that a new conference call has been created.
232 *
233 * @param callId The unique ID of the conference call.
234 */
Santos Cordon823fd3c2014-08-07 18:35:18 -0700235 void addConferenceCall(String callId, ParcelableConference parcelableConference) {
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700236 for (IConnectionServiceAdapter adapter : mAdapters) {
Santos Cordon52d8a152014-06-17 19:08:45 -0700237 try {
Santos Cordon823fd3c2014-08-07 18:35:18 -0700238 adapter.addConferenceCall(callId, parcelableConference);
Santos Cordon52d8a152014-06-17 19:08:45 -0700239 } catch (RemoteException ignored) {
240 }
241 }
242 }
243
244 /**
245 * Retrieves a list of remote connection services usable to place calls.
Santos Cordon52d8a152014-06-17 19:08:45 -0700246 */
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700247 void queryRemoteConnectionServices(RemoteServiceCallback callback) {
Santos Cordon52d8a152014-06-17 19:08:45 -0700248 // Only supported when there is only one adapter.
249 if (mAdapters.size() == 1) {
250 try {
251 mAdapters.iterator().next().queryRemoteConnectionServices(callback);
252 } catch (RemoteException e) {
253 Log.e(this, e, "Exception trying to query for remote CSs");
254 }
Santos Cordonb6939982014-06-04 20:20:58 -0700255 }
256 }
Andrew Lee5ffbe8b82014-06-20 16:29:33 -0700257
258 /**
259 * Sets the call video provider for a call.
260 *
261 * @param callId The unique ID of the call to set with the given call video provider.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700262 * @param videoProvider The call video provider instance to set on the call.
Andrew Lee5ffbe8b82014-06-20 16:29:33 -0700263 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700264 void setVideoProvider(
265 String callId, Connection.VideoProvider videoProvider) {
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700266 for (IConnectionServiceAdapter adapter : mAdapters) {
Andrew Lee5ffbe8b82014-06-20 16:29:33 -0700267 try {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700268 adapter.setVideoProvider(
Santos Cordone8dc4be2014-07-21 01:28:28 -0700269 callId,
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700270 videoProvider == null ? null : videoProvider.getInterface());
Andrew Lee5ffbe8b82014-06-20 16:29:33 -0700271 } catch (RemoteException e) {
272 }
273 }
274 }
Tyler Gunn8d83fa92014-07-01 11:31:21 -0700275
276 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -0700277 * Requests that the framework use VOIP audio mode for this connection.
278 *
279 * @param callId The unique ID of the call to set with the given call video provider.
280 * @param isVoip True if the audio mode is VOIP.
281 */
Andrew Lee100e2932014-09-08 15:34:24 -0700282 void setIsVoipAudioMode(String callId, boolean isVoip) {
Sailesh Nepal33aaae42014-07-07 22:49:44 -0700283 for (IConnectionServiceAdapter adapter : mAdapters) {
284 try {
Andrew Lee100e2932014-09-08 15:34:24 -0700285 adapter.setIsVoipAudioMode(callId, isVoip);
Sailesh Nepal33aaae42014-07-07 22:49:44 -0700286 } catch (RemoteException e) {
287 }
288 }
289 }
290
Sailesh Nepale7ef59a2014-07-08 21:48:22 -0700291 void setStatusHints(String callId, StatusHints statusHints) {
292 for (IConnectionServiceAdapter adapter : mAdapters) {
293 try {
294 adapter.setStatusHints(callId, statusHints);
295 } catch (RemoteException e) {
296 }
297 }
298 }
299
Andrew Lee100e2932014-09-08 15:34:24 -0700300 void setAddress(String callId, Uri address, int presentation) {
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700301 for (IConnectionServiceAdapter adapter : mAdapters) {
Tyler Gunn8d83fa92014-07-01 11:31:21 -0700302 try {
Andrew Lee100e2932014-09-08 15:34:24 -0700303 adapter.setAddress(callId, address, presentation);
Sailesh Nepal61203862014-07-11 14:50:13 -0700304 } catch (RemoteException e) {
305 }
306 }
307 }
308
309 void setCallerDisplayName(String callId, String callerDisplayName, int presentation) {
310 for (IConnectionServiceAdapter adapter : mAdapters) {
311 try {
312 adapter.setCallerDisplayName(callId, callerDisplayName, presentation);
313 } catch (RemoteException e) {
Tyler Gunn8d83fa92014-07-01 11:31:21 -0700314 }
315 }
316 }
Tyler Gunnaa07df82014-07-17 07:50:22 -0700317
318 /**
319 * Sets the video state associated with a call.
320 *
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700321 * Valid values: {@link VideoProfile.VideoState#AUDIO_ONLY},
322 * {@link VideoProfile.VideoState#BIDIRECTIONAL},
323 * {@link VideoProfile.VideoState#TX_ENABLED},
324 * {@link VideoProfile.VideoState#RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -0700325 *
326 * @param callId The unique ID of the call to set the video state for.
327 * @param videoState The video state.
328 */
329 void setVideoState(String callId, int videoState) {
330 Log.v(this, "setVideoState: %d", videoState);
331 for (IConnectionServiceAdapter adapter : mAdapters) {
332 try {
333 adapter.setVideoState(callId, videoState);
334 } catch (RemoteException ignored) {
335 }
336 }
337 }
Sailesh Nepal2ab88cc2014-07-18 14:49:18 -0700338
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700339 void setConferenceableConnections(String callId, List<String> conferenceableCallIds) {
340 Log.v(this, "setConferenceableConnections: %s, %s", callId, conferenceableCallIds);
341 for (IConnectionServiceAdapter adapter : mAdapters) {
342 try {
343 adapter.setConferenceableConnections(callId, conferenceableCallIds);
344 } catch (RemoteException ignored) {
345 }
346 }
347 }
Ben Giladbb69b0c2013-12-12 18:32:02 -0800348}