blob: a9b725be133f7b17180f1bdd1ddfe416268e70cd [file] [log] [blame]
Santos Cordon52d8a152014-06-17 19:08:45 -07001/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
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
Ihab Awadb19a0bc2014-08-07 19:46:01 -070014 * limitations under the License.
Santos Cordon52d8a152014-06-17 19:08:45 -070015 */
16
Tyler Gunnef9f6f92014-09-12 22:16:17 -070017package android.telecom;
Santos Cordon52d8a152014-06-17 19:08:45 -070018
Santos Cordon52d8a152014-06-17 19:08:45 -070019import android.net.Uri;
Ihab Awad5d0410f2014-07-30 10:07:40 -070020import android.os.IBinder;
Santos Cordone8dc4be2014-07-21 01:28:28 -070021import android.os.IBinder.DeathRecipient;
Santos Cordon52d8a152014-06-17 19:08:45 -070022import android.os.RemoteException;
Santos Cordon52d8a152014-06-17 19:08:45 -070023
Tyler Gunnef9f6f92014-09-12 22:16:17 -070024import com.android.internal.telecom.IConnectionService;
25import com.android.internal.telecom.IConnectionServiceAdapter;
26import com.android.internal.telecom.IVideoProvider;
27import com.android.internal.telecom.RemoteServiceCallback;
Santos Cordon52d8a152014-06-17 19:08:45 -070028
Ihab Awadb8e85c72014-08-23 20:34:57 -070029import java.util.ArrayList;
Ihab Awad5d0410f2014-07-30 10:07:40 -070030import java.util.HashMap;
31import java.util.HashSet;
32import java.util.Map;
33import java.util.Set;
Santos Cordon7c7bc7f2014-07-28 18:15:48 -070034import java.util.List;
Santos Cordon52d8a152014-06-17 19:08:45 -070035import java.util.UUID;
36
37/**
38 * Remote connection service which other connection services can use to place calls on their behalf.
Sailesh Nepal091768c2014-06-30 15:15:23 -070039 *
40 * @hide
Santos Cordon52d8a152014-06-17 19:08:45 -070041 */
Ihab Awad5d0410f2014-07-30 10:07:40 -070042final class RemoteConnectionService {
Sailesh Nepal48031592014-07-18 14:21:23 -070043
Tyler Gunn4a57b9b2014-10-30 14:27:48 -070044 // Note: Casting null to avoid ambiguous constructor reference.
Ihab Awadb8e85c72014-08-23 20:34:57 -070045 private static final RemoteConnection NULL_CONNECTION =
Tyler Gunn4a57b9b2014-10-30 14:27:48 -070046 new RemoteConnection("NULL", null, (ConnectionRequest) null);
Ihab Awadb8e85c72014-08-23 20:34:57 -070047
48 private static final RemoteConference NULL_CONFERENCE =
49 new RemoteConference("NULL", null);
Santos Cordon52d8a152014-06-17 19:08:45 -070050
Ihab Awad5d0410f2014-07-30 10:07:40 -070051 private final IConnectionServiceAdapter mServantDelegate = new IConnectionServiceAdapter() {
Sailesh Nepal48031592014-07-18 14:21:23 -070052 @Override
Ihab Awad6107bab2014-08-18 09:23:25 -070053 public void handleCreateConnectionComplete(
Ihab Awadb19a0bc2014-08-07 19:46:01 -070054 String id,
55 ConnectionRequest request,
Ihab Awad5d0410f2014-07-30 10:07:40 -070056 ParcelableConnection parcel) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -070057 RemoteConnection connection =
58 findConnectionForAction(id, "handleCreateConnectionSuccessful");
Ihab Awad5d0410f2014-07-30 10:07:40 -070059 if (connection != NULL_CONNECTION && mPendingConnections.contains(connection)) {
60 mPendingConnections.remove(connection);
Ihab Awad6107bab2014-08-18 09:23:25 -070061 // Unconditionally initialize the connection ...
Ihab Awad5c9c86e2014-11-12 13:41:16 -080062 connection.setConnectionCapabilities(parcel.getConnectionCapabilities());
Sailesh Nepal2d3ced72015-01-31 20:17:35 -080063 if (parcel.getHandle() != null
64 || parcel.getState() != Connection.STATE_DISCONNECTED) {
65 connection.setAddress(parcel.getHandle(), parcel.getHandlePresentation());
66 }
67 if (parcel.getCallerDisplayName() != null
68 || parcel.getState() != Connection.STATE_DISCONNECTED) {
69 connection.setCallerDisplayName(
70 parcel.getCallerDisplayName(),
71 parcel.getCallerDisplayNamePresentation());
72 }
Sailesh Nepal70638f12014-09-09 21:49:14 -070073 // Set state after handle so that the client can identify the connection.
Sailesh Nepalc2a978d2014-09-20 18:23:05 -070074 if (parcel.getState() == Connection.STATE_DISCONNECTED) {
75 connection.setDisconnected(parcel.getDisconnectCause());
76 } else {
77 connection.setState(parcel.getState());
78 }
Ihab Awadb8e85c72014-08-23 20:34:57 -070079 List<RemoteConnection> conferenceable = new ArrayList<>();
80 for (String confId : parcel.getConferenceableConnectionIds()) {
81 if (mConnectionById.containsKey(confId)) {
82 conferenceable.add(mConnectionById.get(confId));
83 }
84 }
85 connection.setConferenceableConnections(conferenceable);
Ihab Awada64627c2014-08-20 09:36:40 -070086 connection.setVideoState(parcel.getVideoState());
Ihab Awad6107bab2014-08-18 09:23:25 -070087 if (connection.getState() == Connection.STATE_DISCONNECTED) {
88 // ... then, if it was created in a disconnected state, that indicates
89 // failure on the providing end, so immediately mark it destroyed
90 connection.setDestroyed();
91 }
Sailesh Nepal48031592014-07-18 14:21:23 -070092 }
93 }
Sailesh Nepal2ab88cc2014-07-18 14:49:18 -070094
Sailesh Nepal2a46b902014-07-04 17:21:07 -070095 @Override
Ihab Awad5d0410f2014-07-30 10:07:40 -070096 public void setActive(String callId) {
Ihab Awadb8e85c72014-08-23 20:34:57 -070097 if (mConnectionById.containsKey(callId)) {
98 findConnectionForAction(callId, "setActive")
99 .setState(Connection.STATE_ACTIVE);
100 } else {
101 findConferenceForAction(callId, "setActive")
102 .setState(Connection.STATE_ACTIVE);
103 }
Santos Cordon52d8a152014-06-17 19:08:45 -0700104 }
105
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700106 @Override
Ihab Awad5d0410f2014-07-30 10:07:40 -0700107 public void setRinging(String callId) {
108 findConnectionForAction(callId, "setRinging")
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700109 .setState(Connection.STATE_RINGING);
Andrew Lee5ffbe8b2014-06-20 16:29:33 -0700110 }
111
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700112 @Override
Ihab Awad5d0410f2014-07-30 10:07:40 -0700113 public void setDialing(String callId) {
114 findConnectionForAction(callId, "setDialing")
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700115 .setState(Connection.STATE_DIALING);
Santos Cordon52d8a152014-06-17 19:08:45 -0700116 }
117
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700118 @Override
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700119 public void setDisconnected(String callId, DisconnectCause disconnectCause) {
Ihab Awadb8e85c72014-08-23 20:34:57 -0700120 if (mConnectionById.containsKey(callId)) {
121 findConnectionForAction(callId, "setDisconnected")
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700122 .setDisconnected(disconnectCause);
Ihab Awadb8e85c72014-08-23 20:34:57 -0700123 } else {
124 findConferenceForAction(callId, "setDisconnected")
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700125 .setDisconnected(disconnectCause);
Ihab Awadb8e85c72014-08-23 20:34:57 -0700126 }
Santos Cordon52d8a152014-06-17 19:08:45 -0700127 }
128
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700129 @Override
Ihab Awad5d0410f2014-07-30 10:07:40 -0700130 public void setOnHold(String callId) {
Ihab Awadb8e85c72014-08-23 20:34:57 -0700131 if (mConnectionById.containsKey(callId)) {
132 findConnectionForAction(callId, "setOnHold")
133 .setState(Connection.STATE_HOLDING);
134 } else {
135 findConferenceForAction(callId, "setOnHold")
136 .setState(Connection.STATE_HOLDING);
137 }
Santos Cordon52d8a152014-06-17 19:08:45 -0700138 }
139
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700140 @Override
Andrew Lee100e2932014-09-08 15:34:24 -0700141 public void setRingbackRequested(String callId, boolean ringing) {
142 findConnectionForAction(callId, "setRingbackRequested")
143 .setRingbackRequested(ringing);
Santos Cordon52d8a152014-06-17 19:08:45 -0700144 }
145
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700146 @Override
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800147 public void setConnectionCapabilities(String callId, int connectionCapabilities) {
Ihab Awadb8e85c72014-08-23 20:34:57 -0700148 if (mConnectionById.containsKey(callId)) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800149 findConnectionForAction(callId, "setConnectionCapabilities")
150 .setConnectionCapabilities(connectionCapabilities);
Ihab Awadb8e85c72014-08-23 20:34:57 -0700151 } else {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800152 findConferenceForAction(callId, "setConnectionCapabilities")
153 .setConnectionCapabilities(connectionCapabilities);
Ihab Awadb8e85c72014-08-23 20:34:57 -0700154 }
Santos Cordon52d8a152014-06-17 19:08:45 -0700155 }
156
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700157 @Override
Ihab Awad5d0410f2014-07-30 10:07:40 -0700158 public void setIsConferenced(String callId, String conferenceCallId) {
Ihab Awadb8e85c72014-08-23 20:34:57 -0700159 // Note: callId should not be null; conferenceCallId may be null
160 RemoteConnection connection =
161 findConnectionForAction(callId, "setIsConferenced");
162 if (connection != NULL_CONNECTION) {
163 if (conferenceCallId == null) {
164 // 'connection' is being split from its conference
165 if (connection.getConference() != null) {
166 connection.getConference().removeConnection(connection);
167 }
168 } else {
169 RemoteConference conference =
170 findConferenceForAction(conferenceCallId, "setIsConferenced");
171 if (conference != NULL_CONFERENCE) {
172 conference.addConnection(connection);
173 }
174 }
175 }
Santos Cordon52d8a152014-06-17 19:08:45 -0700176 }
177
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700178 @Override
Ihab Awadb8e85c72014-08-23 20:34:57 -0700179 public void addConferenceCall(
180 final String callId,
181 ParcelableConference parcel) {
182 RemoteConference conference = new RemoteConference(callId,
183 mOutgoingConnectionServiceRpc);
184
185 for (String id : parcel.getConnectionIds()) {
186 RemoteConnection c = mConnectionById.get(id);
187 if (c != null) {
188 conference.addConnection(c);
189 }
190 }
191
192 if (conference.getConnections().size() == 0) {
193 // A conference was created, but none of its connections are ones that have been
194 // created by, and therefore being tracked by, this remote connection service. It
195 // is of no interest to us.
196 return;
197 }
198
199 conference.setState(parcel.getState());
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800200 conference.setConnectionCapabilities(parcel.getConnectionCapabilities());
Ihab Awadb8e85c72014-08-23 20:34:57 -0700201 mConferenceById.put(callId, conference);
Andrew Lee100e2932014-09-08 15:34:24 -0700202 conference.registerCallback(new RemoteConference.Callback() {
Ihab Awadb8e85c72014-08-23 20:34:57 -0700203 @Override
204 public void onDestroyed(RemoteConference c) {
205 mConferenceById.remove(callId);
206 maybeDisconnectAdapter();
207 }
208 });
209
210 mOurConnectionServiceImpl.addRemoteConference(conference);
Santos Cordon52d8a152014-06-17 19:08:45 -0700211 }
212
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700213 @Override
Ihab Awad5d0410f2014-07-30 10:07:40 -0700214 public void removeCall(String callId) {
Ihab Awadb8e85c72014-08-23 20:34:57 -0700215 if (mConnectionById.containsKey(callId)) {
216 findConnectionForAction(callId, "removeCall")
217 .setDestroyed();
218 } else {
219 findConferenceForAction(callId, "removeCall")
220 .setDestroyed();
221 }
Santos Cordon52d8a152014-06-17 19:08:45 -0700222 }
223
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700224 @Override
Ihab Awad5d0410f2014-07-30 10:07:40 -0700225 public void onPostDialWait(String callId, String remaining) {
226 findConnectionForAction(callId, "onPostDialWait")
227 .setPostDialWait(remaining);
Santos Cordon52d8a152014-06-17 19:08:45 -0700228 }
229
Santos Cordon52d8a152014-06-17 19:08:45 -0700230 @Override
Nancy Chen27d1c2d2014-12-15 16:12:50 -0800231 public void onPostDialChar(String callId, char nextChar) {
232 findConnectionForAction(callId, "onPostDialChar")
233 .onPostDialChar(nextChar);
234 }
235
236 @Override
Santos Cordon52d8a152014-06-17 19:08:45 -0700237 public void queryRemoteConnectionServices(RemoteServiceCallback callback) {
Ihab Awad5d0410f2014-07-30 10:07:40 -0700238 // Not supported from remote connection service.
Santos Cordon52d8a152014-06-17 19:08:45 -0700239 }
Tyler Gunn8d83fa92014-07-01 11:31:21 -0700240
Sailesh Nepal33aaae42014-07-07 22:49:44 -0700241 @Override
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700242 public void setVideoProvider(String callId, IVideoProvider videoProvider) {
Sailesh Nepal11aeae52015-01-28 16:54:09 -0800243 RemoteConnection.VideoProvider remoteVideoProvider = null;
244 if (videoProvider != null) {
245 remoteVideoProvider = new RemoteConnection.VideoProvider(videoProvider);
246 }
Ihab Awada64627c2014-08-20 09:36:40 -0700247 findConnectionForAction(callId, "setVideoProvider")
Sailesh Nepal11aeae52015-01-28 16:54:09 -0800248 .setVideoProvider(remoteVideoProvider);
Tyler Gunnaa07df82014-07-17 07:50:22 -0700249 }
250
251 @Override
Ihab Awad5d0410f2014-07-30 10:07:40 -0700252 public void setVideoState(String callId, int videoState) {
253 findConnectionForAction(callId, "setVideoState")
254 .setVideoState(videoState);
Sailesh Nepal33aaae42014-07-07 22:49:44 -0700255 }
Sailesh Nepale7ef59a2014-07-08 21:48:22 -0700256
Sailesh Nepale7ef59a2014-07-08 21:48:22 -0700257 @Override
Andrew Lee100e2932014-09-08 15:34:24 -0700258 public void setIsVoipAudioMode(String callId, boolean isVoip) {
259 findConnectionForAction(callId, "setIsVoipAudioMode")
260 .setIsVoipAudioMode(isVoip);
Sailesh Nepale7ef59a2014-07-08 21:48:22 -0700261 }
Sailesh Nepal61203862014-07-11 14:50:13 -0700262
263 @Override
Ihab Awad5d0410f2014-07-30 10:07:40 -0700264 public void setStatusHints(String callId, StatusHints statusHints) {
265 findConnectionForAction(callId, "setStatusHints")
266 .setStatusHints(statusHints);
Sailesh Nepal61203862014-07-11 14:50:13 -0700267 }
268
269 @Override
Andrew Lee100e2932014-09-08 15:34:24 -0700270 public void setAddress(String callId, Uri address, int presentation) {
271 findConnectionForAction(callId, "setAddress")
272 .setAddress(address, presentation);
Sailesh Nepal61203862014-07-11 14:50:13 -0700273 }
Sailesh Nepal2ab88cc2014-07-18 14:49:18 -0700274
275 @Override
Ihab Awad5d0410f2014-07-30 10:07:40 -0700276 public void setCallerDisplayName(String callId, String callerDisplayName,
277 int presentation) {
278 findConnectionForAction(callId, "setCallerDisplayName")
279 .setCallerDisplayName(callerDisplayName, presentation);
280 }
281
282 @Override
Ihab Awad5d0410f2014-07-30 10:07:40 -0700283 public IBinder asBinder() {
284 throw new UnsupportedOperationException();
Sailesh Nepal2ab88cc2014-07-18 14:49:18 -0700285 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700286
287 @Override
288 public final void setConferenceableConnections(
289 String callId, List<String> conferenceableConnectionIds) {
Ihab Awadb8e85c72014-08-23 20:34:57 -0700290 List<RemoteConnection> conferenceable = new ArrayList<>();
291 for (String id : conferenceableConnectionIds) {
292 if (mConnectionById.containsKey(id)) {
293 conferenceable.add(mConnectionById.get(id));
294 }
295 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700296
Ihab Awad50e35062014-09-30 09:17:03 -0700297 if (hasConnection(callId)) {
298 findConnectionForAction(callId, "setConferenceableConnections")
299 .setConferenceableConnections(conferenceable);
300 } else {
301 findConferenceForAction(callId, "setConferenceableConnections")
302 .setConferenceableConnections(conferenceable);
303 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700304 }
Tyler Gunn4a57b9b2014-10-30 14:27:48 -0700305
306 @Override
307 public void addExistingConnection(String callId, ParcelableConnection connection) {
308 // TODO: add contents of this method
309 RemoteConnection remoteConnction = new RemoteConnection(callId,
310 mOutgoingConnectionServiceRpc, connection);
311
312 mOurConnectionServiceImpl.addRemoteExistingConnection(remoteConnction);
313 }
Santos Cordon52d8a152014-06-17 19:08:45 -0700314 };
315
Ihab Awad5d0410f2014-07-30 10:07:40 -0700316 private final ConnectionServiceAdapterServant mServant =
317 new ConnectionServiceAdapterServant(mServantDelegate);
Santos Cordon52d8a152014-06-17 19:08:45 -0700318
Ihab Awad5d0410f2014-07-30 10:07:40 -0700319 private final DeathRecipient mDeathRecipient = new DeathRecipient() {
320 @Override
321 public void binderDied() {
322 for (RemoteConnection c : mConnectionById.values()) {
323 c.setDestroyed();
324 }
Ihab Awadb8e85c72014-08-23 20:34:57 -0700325 for (RemoteConference c : mConferenceById.values()) {
326 c.setDestroyed();
327 }
Ihab Awad5d0410f2014-07-30 10:07:40 -0700328 mConnectionById.clear();
Ihab Awadb8e85c72014-08-23 20:34:57 -0700329 mConferenceById.clear();
Ihab Awad5d0410f2014-07-30 10:07:40 -0700330 mPendingConnections.clear();
Ihab Awadb8e85c72014-08-23 20:34:57 -0700331 mOutgoingConnectionServiceRpc.asBinder().unlinkToDeath(mDeathRecipient, 0);
Ihab Awad5d0410f2014-07-30 10:07:40 -0700332 }
333 };
334
Ihab Awadb8e85c72014-08-23 20:34:57 -0700335 private final IConnectionService mOutgoingConnectionServiceRpc;
336 private final ConnectionService mOurConnectionServiceImpl;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700337 private final Map<String, RemoteConnection> mConnectionById = new HashMap<>();
Ihab Awadb8e85c72014-08-23 20:34:57 -0700338 private final Map<String, RemoteConference> mConferenceById = new HashMap<>();
Ihab Awad5d0410f2014-07-30 10:07:40 -0700339 private final Set<RemoteConnection> mPendingConnections = new HashSet<>();
340
Ihab Awadb8e85c72014-08-23 20:34:57 -0700341 RemoteConnectionService(
342 IConnectionService outgoingConnectionServiceRpc,
343 ConnectionService ourConnectionServiceImpl) throws RemoteException {
344 mOutgoingConnectionServiceRpc = outgoingConnectionServiceRpc;
345 mOutgoingConnectionServiceRpc.asBinder().linkToDeath(mDeathRecipient, 0);
346 mOurConnectionServiceImpl = ourConnectionServiceImpl;
Santos Cordon52d8a152014-06-17 19:08:45 -0700347 }
348
349 @Override
350 public String toString() {
Ihab Awadb8e85c72014-08-23 20:34:57 -0700351 return "[RemoteCS - " + mOutgoingConnectionServiceRpc.asBinder().toString() + "]";
Santos Cordon52d8a152014-06-17 19:08:45 -0700352 }
353
Ihab Awadf8b69882014-07-25 15:14:01 -0700354 final RemoteConnection createRemoteConnection(
355 PhoneAccountHandle connectionManagerPhoneAccount,
356 ConnectionRequest request,
357 boolean isIncoming) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700358 final String id = UUID.randomUUID().toString();
Ihab Awad8aecfed2014-08-08 17:06:11 -0700359 final ConnectionRequest newRequest = new ConnectionRequest(
Ihab Awad5d0410f2014-07-30 10:07:40 -0700360 request.getAccountHandle(),
Nancy Chenea38cca2014-09-05 16:38:49 -0700361 request.getAddress(),
Ihab Awad5d0410f2014-07-30 10:07:40 -0700362 request.getExtras(),
363 request.getVideoState());
364 try {
Ihab Awad8aecfed2014-08-08 17:06:11 -0700365 if (mConnectionById.isEmpty()) {
Ihab Awadb8e85c72014-08-23 20:34:57 -0700366 mOutgoingConnectionServiceRpc.addConnectionServiceAdapter(mServant.getStub());
Ihab Awad8aecfed2014-08-08 17:06:11 -0700367 }
368 RemoteConnection connection =
Ihab Awadb8e85c72014-08-23 20:34:57 -0700369 new RemoteConnection(id, mOutgoingConnectionServiceRpc, newRequest);
Ihab Awad8aecfed2014-08-08 17:06:11 -0700370 mPendingConnections.add(connection);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700371 mConnectionById.put(id, connection);
Ihab Awadb8e85c72014-08-23 20:34:57 -0700372 mOutgoingConnectionServiceRpc.createConnection(
Ihab Awad5d0410f2014-07-30 10:07:40 -0700373 connectionManagerPhoneAccount,
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700374 id,
Ihab Awad5d0410f2014-07-30 10:07:40 -0700375 newRequest,
Yorke Leec3cf9822014-10-02 09:38:39 -0700376 isIncoming,
377 false /* isUnknownCall */);
Andrew Lee100e2932014-09-08 15:34:24 -0700378 connection.registerCallback(new RemoteConnection.Callback() {
Ihab Awad8aecfed2014-08-08 17:06:11 -0700379 @Override
380 public void onDestroyed(RemoteConnection connection) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700381 mConnectionById.remove(id);
Ihab Awadb8e85c72014-08-23 20:34:57 -0700382 maybeDisconnectAdapter();
Ihab Awad8aecfed2014-08-08 17:06:11 -0700383 }
384 });
Ihab Awad5d0410f2014-07-30 10:07:40 -0700385 return connection;
386 } catch (RemoteException e) {
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700387 return RemoteConnection.failure(
388 new DisconnectCause(DisconnectCause.ERROR, e.toString()));
Santos Cordon52d8a152014-06-17 19:08:45 -0700389 }
390 }
391
Ihab Awad50e35062014-09-30 09:17:03 -0700392 private boolean hasConnection(String callId) {
mike dooley879142b2014-10-08 13:39:28 -0700393 return mConnectionById.containsKey(callId);
Ihab Awad50e35062014-09-30 09:17:03 -0700394 }
395
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700396 private RemoteConnection findConnectionForAction(
397 String callId, String action) {
Ihab Awad5d0410f2014-07-30 10:07:40 -0700398 if (mConnectionById.containsKey(callId)) {
399 return mConnectionById.get(callId);
400 }
401 Log.w(this, "%s - Cannot find Connection %s", action, callId);
402 return NULL_CONNECTION;
Santos Cordon52d8a152014-06-17 19:08:45 -0700403 }
Ihab Awadb8e85c72014-08-23 20:34:57 -0700404
405 private RemoteConference findConferenceForAction(
406 String callId, String action) {
407 if (mConferenceById.containsKey(callId)) {
408 return mConferenceById.get(callId);
409 }
410 Log.w(this, "%s - Cannot find Conference %s", action, callId);
411 return NULL_CONFERENCE;
412 }
413
414 private void maybeDisconnectAdapter() {
415 if (mConnectionById.isEmpty() && mConferenceById.isEmpty()) {
416 try {
417 mOutgoingConnectionServiceRpc.removeConnectionServiceAdapter(mServant.getStub());
418 } catch (RemoteException e) {
419 }
420 }
421 }
Santos Cordon52d8a152014-06-17 19:08:45 -0700422}