blob: 5319793f396db57a16bb40b4692cec851af7a50d [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());
Andrew Lee100e2932014-09-08 15:34:24 -070063 connection.setAddress(
Ihab Awad5d0410f2014-07-30 10:07:40 -070064 parcel.getHandle(), parcel.getHandlePresentation());
65 connection.setCallerDisplayName(
66 parcel.getCallerDisplayName(),
67 parcel.getCallerDisplayNamePresentation());
Sailesh Nepal70638f12014-09-09 21:49:14 -070068 // Set state after handle so that the client can identify the connection.
Sailesh Nepalc2a978d2014-09-20 18:23:05 -070069 if (parcel.getState() == Connection.STATE_DISCONNECTED) {
70 connection.setDisconnected(parcel.getDisconnectCause());
71 } else {
72 connection.setState(parcel.getState());
73 }
Ihab Awadb8e85c72014-08-23 20:34:57 -070074 List<RemoteConnection> conferenceable = new ArrayList<>();
75 for (String confId : parcel.getConferenceableConnectionIds()) {
76 if (mConnectionById.containsKey(confId)) {
77 conferenceable.add(mConnectionById.get(confId));
78 }
79 }
80 connection.setConferenceableConnections(conferenceable);
Ihab Awada64627c2014-08-20 09:36:40 -070081 connection.setVideoState(parcel.getVideoState());
Ihab Awad6107bab2014-08-18 09:23:25 -070082 if (connection.getState() == Connection.STATE_DISCONNECTED) {
83 // ... then, if it was created in a disconnected state, that indicates
84 // failure on the providing end, so immediately mark it destroyed
85 connection.setDestroyed();
86 }
Sailesh Nepal48031592014-07-18 14:21:23 -070087 }
88 }
Sailesh Nepal2ab88cc2014-07-18 14:49:18 -070089
Sailesh Nepal2a46b902014-07-04 17:21:07 -070090 @Override
Ihab Awad5d0410f2014-07-30 10:07:40 -070091 public void setActive(String callId) {
Ihab Awadb8e85c72014-08-23 20:34:57 -070092 if (mConnectionById.containsKey(callId)) {
93 findConnectionForAction(callId, "setActive")
94 .setState(Connection.STATE_ACTIVE);
95 } else {
96 findConferenceForAction(callId, "setActive")
97 .setState(Connection.STATE_ACTIVE);
98 }
Santos Cordon52d8a152014-06-17 19:08:45 -070099 }
100
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700101 @Override
Ihab Awad5d0410f2014-07-30 10:07:40 -0700102 public void setRinging(String callId) {
103 findConnectionForAction(callId, "setRinging")
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700104 .setState(Connection.STATE_RINGING);
Andrew Lee5ffbe8b2014-06-20 16:29:33 -0700105 }
106
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700107 @Override
Ihab Awad5d0410f2014-07-30 10:07:40 -0700108 public void setDialing(String callId) {
109 findConnectionForAction(callId, "setDialing")
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700110 .setState(Connection.STATE_DIALING);
Santos Cordon52d8a152014-06-17 19:08:45 -0700111 }
112
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700113 @Override
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700114 public void setDisconnected(String callId, DisconnectCause disconnectCause) {
Ihab Awadb8e85c72014-08-23 20:34:57 -0700115 if (mConnectionById.containsKey(callId)) {
116 findConnectionForAction(callId, "setDisconnected")
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700117 .setDisconnected(disconnectCause);
Ihab Awadb8e85c72014-08-23 20:34:57 -0700118 } else {
119 findConferenceForAction(callId, "setDisconnected")
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700120 .setDisconnected(disconnectCause);
Ihab Awadb8e85c72014-08-23 20:34:57 -0700121 }
Santos Cordon52d8a152014-06-17 19:08:45 -0700122 }
123
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700124 @Override
Ihab Awad5d0410f2014-07-30 10:07:40 -0700125 public void setOnHold(String callId) {
Ihab Awadb8e85c72014-08-23 20:34:57 -0700126 if (mConnectionById.containsKey(callId)) {
127 findConnectionForAction(callId, "setOnHold")
128 .setState(Connection.STATE_HOLDING);
129 } else {
130 findConferenceForAction(callId, "setOnHold")
131 .setState(Connection.STATE_HOLDING);
132 }
Santos Cordon52d8a152014-06-17 19:08:45 -0700133 }
134
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700135 @Override
Andrew Lee100e2932014-09-08 15:34:24 -0700136 public void setRingbackRequested(String callId, boolean ringing) {
137 findConnectionForAction(callId, "setRingbackRequested")
138 .setRingbackRequested(ringing);
Santos Cordon52d8a152014-06-17 19:08:45 -0700139 }
140
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700141 @Override
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800142 public void setConnectionCapabilities(String callId, int connectionCapabilities) {
Ihab Awadb8e85c72014-08-23 20:34:57 -0700143 if (mConnectionById.containsKey(callId)) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800144 findConnectionForAction(callId, "setConnectionCapabilities")
145 .setConnectionCapabilities(connectionCapabilities);
Ihab Awadb8e85c72014-08-23 20:34:57 -0700146 } else {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800147 findConferenceForAction(callId, "setConnectionCapabilities")
148 .setConnectionCapabilities(connectionCapabilities);
Ihab Awadb8e85c72014-08-23 20:34:57 -0700149 }
Santos Cordon52d8a152014-06-17 19:08:45 -0700150 }
151
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700152 @Override
Ihab Awad5d0410f2014-07-30 10:07:40 -0700153 public void setIsConferenced(String callId, String conferenceCallId) {
Ihab Awadb8e85c72014-08-23 20:34:57 -0700154 // Note: callId should not be null; conferenceCallId may be null
155 RemoteConnection connection =
156 findConnectionForAction(callId, "setIsConferenced");
157 if (connection != NULL_CONNECTION) {
158 if (conferenceCallId == null) {
159 // 'connection' is being split from its conference
160 if (connection.getConference() != null) {
161 connection.getConference().removeConnection(connection);
162 }
163 } else {
164 RemoteConference conference =
165 findConferenceForAction(conferenceCallId, "setIsConferenced");
166 if (conference != NULL_CONFERENCE) {
167 conference.addConnection(connection);
168 }
169 }
170 }
Santos Cordon52d8a152014-06-17 19:08:45 -0700171 }
172
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700173 @Override
Anthony Lee17455a32015-04-24 15:25:29 -0700174 public void setConferenceMergeFailed(String callId) {
175 // Nothing to do here.
176 // The event has already been handled and there is no state to update
177 // in the underlying connection or conference objects
178 }
179
180 @Override
Ihab Awadb8e85c72014-08-23 20:34:57 -0700181 public void addConferenceCall(
182 final String callId,
183 ParcelableConference parcel) {
184 RemoteConference conference = new RemoteConference(callId,
185 mOutgoingConnectionServiceRpc);
186
187 for (String id : parcel.getConnectionIds()) {
188 RemoteConnection c = mConnectionById.get(id);
189 if (c != null) {
190 conference.addConnection(c);
191 }
192 }
193
194 if (conference.getConnections().size() == 0) {
195 // A conference was created, but none of its connections are ones that have been
196 // created by, and therefore being tracked by, this remote connection service. It
197 // is of no interest to us.
198 return;
199 }
200
201 conference.setState(parcel.getState());
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800202 conference.setConnectionCapabilities(parcel.getConnectionCapabilities());
Ihab Awadb8e85c72014-08-23 20:34:57 -0700203 mConferenceById.put(callId, conference);
Andrew Lee100e2932014-09-08 15:34:24 -0700204 conference.registerCallback(new RemoteConference.Callback() {
Ihab Awadb8e85c72014-08-23 20:34:57 -0700205 @Override
206 public void onDestroyed(RemoteConference c) {
207 mConferenceById.remove(callId);
208 maybeDisconnectAdapter();
209 }
210 });
211
212 mOurConnectionServiceImpl.addRemoteConference(conference);
Santos Cordon52d8a152014-06-17 19:08:45 -0700213 }
214
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700215 @Override
Ihab Awad5d0410f2014-07-30 10:07:40 -0700216 public void removeCall(String callId) {
Ihab Awadb8e85c72014-08-23 20:34:57 -0700217 if (mConnectionById.containsKey(callId)) {
218 findConnectionForAction(callId, "removeCall")
219 .setDestroyed();
220 } else {
221 findConferenceForAction(callId, "removeCall")
222 .setDestroyed();
223 }
Santos Cordon52d8a152014-06-17 19:08:45 -0700224 }
225
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700226 @Override
Ihab Awad5d0410f2014-07-30 10:07:40 -0700227 public void onPostDialWait(String callId, String remaining) {
228 findConnectionForAction(callId, "onPostDialWait")
229 .setPostDialWait(remaining);
Santos Cordon52d8a152014-06-17 19:08:45 -0700230 }
231
Santos Cordon52d8a152014-06-17 19:08:45 -0700232 @Override
Nancy Chen27d1c2d2014-12-15 16:12:50 -0800233 public void onPostDialChar(String callId, char nextChar) {
234 findConnectionForAction(callId, "onPostDialChar")
235 .onPostDialChar(nextChar);
236 }
237
238 @Override
Santos Cordon52d8a152014-06-17 19:08:45 -0700239 public void queryRemoteConnectionServices(RemoteServiceCallback callback) {
Ihab Awad5d0410f2014-07-30 10:07:40 -0700240 // Not supported from remote connection service.
Santos Cordon52d8a152014-06-17 19:08:45 -0700241 }
Tyler Gunn8d83fa92014-07-01 11:31:21 -0700242
Sailesh Nepal33aaae42014-07-07 22:49:44 -0700243 @Override
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700244 public void setVideoProvider(String callId, IVideoProvider videoProvider) {
Sailesh Nepal11aeae52015-01-28 16:54:09 -0800245 RemoteConnection.VideoProvider remoteVideoProvider = null;
246 if (videoProvider != null) {
247 remoteVideoProvider = new RemoteConnection.VideoProvider(videoProvider);
248 }
Ihab Awada64627c2014-08-20 09:36:40 -0700249 findConnectionForAction(callId, "setVideoProvider")
Sailesh Nepal11aeae52015-01-28 16:54:09 -0800250 .setVideoProvider(remoteVideoProvider);
Tyler Gunnaa07df82014-07-17 07:50:22 -0700251 }
252
253 @Override
Ihab Awad5d0410f2014-07-30 10:07:40 -0700254 public void setVideoState(String callId, int videoState) {
255 findConnectionForAction(callId, "setVideoState")
256 .setVideoState(videoState);
Sailesh Nepal33aaae42014-07-07 22:49:44 -0700257 }
Sailesh Nepale7ef59a2014-07-08 21:48:22 -0700258
Sailesh Nepale7ef59a2014-07-08 21:48:22 -0700259 @Override
Andrew Lee100e2932014-09-08 15:34:24 -0700260 public void setIsVoipAudioMode(String callId, boolean isVoip) {
261 findConnectionForAction(callId, "setIsVoipAudioMode")
262 .setIsVoipAudioMode(isVoip);
Sailesh Nepale7ef59a2014-07-08 21:48:22 -0700263 }
Sailesh Nepal61203862014-07-11 14:50:13 -0700264
265 @Override
Ihab Awad5d0410f2014-07-30 10:07:40 -0700266 public void setStatusHints(String callId, StatusHints statusHints) {
267 findConnectionForAction(callId, "setStatusHints")
268 .setStatusHints(statusHints);
Sailesh Nepal61203862014-07-11 14:50:13 -0700269 }
270
271 @Override
Andrew Lee100e2932014-09-08 15:34:24 -0700272 public void setAddress(String callId, Uri address, int presentation) {
273 findConnectionForAction(callId, "setAddress")
274 .setAddress(address, presentation);
Sailesh Nepal61203862014-07-11 14:50:13 -0700275 }
Sailesh Nepal2ab88cc2014-07-18 14:49:18 -0700276
277 @Override
Ihab Awad5d0410f2014-07-30 10:07:40 -0700278 public void setCallerDisplayName(String callId, String callerDisplayName,
279 int presentation) {
280 findConnectionForAction(callId, "setCallerDisplayName")
281 .setCallerDisplayName(callerDisplayName, presentation);
282 }
283
284 @Override
Ihab Awad5d0410f2014-07-30 10:07:40 -0700285 public IBinder asBinder() {
286 throw new UnsupportedOperationException();
Sailesh Nepal2ab88cc2014-07-18 14:49:18 -0700287 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700288
289 @Override
290 public final void setConferenceableConnections(
291 String callId, List<String> conferenceableConnectionIds) {
Ihab Awadb8e85c72014-08-23 20:34:57 -0700292 List<RemoteConnection> conferenceable = new ArrayList<>();
293 for (String id : conferenceableConnectionIds) {
294 if (mConnectionById.containsKey(id)) {
295 conferenceable.add(mConnectionById.get(id));
296 }
297 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700298
Ihab Awad50e35062014-09-30 09:17:03 -0700299 if (hasConnection(callId)) {
300 findConnectionForAction(callId, "setConferenceableConnections")
301 .setConferenceableConnections(conferenceable);
302 } else {
303 findConferenceForAction(callId, "setConferenceableConnections")
304 .setConferenceableConnections(conferenceable);
305 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700306 }
Tyler Gunn4a57b9b2014-10-30 14:27:48 -0700307
308 @Override
309 public void addExistingConnection(String callId, ParcelableConnection connection) {
310 // TODO: add contents of this method
311 RemoteConnection remoteConnction = new RemoteConnection(callId,
312 mOutgoingConnectionServiceRpc, connection);
313
314 mOurConnectionServiceImpl.addRemoteExistingConnection(remoteConnction);
315 }
Santos Cordon52d8a152014-06-17 19:08:45 -0700316 };
317
Ihab Awad5d0410f2014-07-30 10:07:40 -0700318 private final ConnectionServiceAdapterServant mServant =
319 new ConnectionServiceAdapterServant(mServantDelegate);
Santos Cordon52d8a152014-06-17 19:08:45 -0700320
Ihab Awad5d0410f2014-07-30 10:07:40 -0700321 private final DeathRecipient mDeathRecipient = new DeathRecipient() {
322 @Override
323 public void binderDied() {
324 for (RemoteConnection c : mConnectionById.values()) {
325 c.setDestroyed();
326 }
Ihab Awadb8e85c72014-08-23 20:34:57 -0700327 for (RemoteConference c : mConferenceById.values()) {
328 c.setDestroyed();
329 }
Ihab Awad5d0410f2014-07-30 10:07:40 -0700330 mConnectionById.clear();
Ihab Awadb8e85c72014-08-23 20:34:57 -0700331 mConferenceById.clear();
Ihab Awad5d0410f2014-07-30 10:07:40 -0700332 mPendingConnections.clear();
Ihab Awadb8e85c72014-08-23 20:34:57 -0700333 mOutgoingConnectionServiceRpc.asBinder().unlinkToDeath(mDeathRecipient, 0);
Ihab Awad5d0410f2014-07-30 10:07:40 -0700334 }
335 };
336
Ihab Awadb8e85c72014-08-23 20:34:57 -0700337 private final IConnectionService mOutgoingConnectionServiceRpc;
338 private final ConnectionService mOurConnectionServiceImpl;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700339 private final Map<String, RemoteConnection> mConnectionById = new HashMap<>();
Ihab Awadb8e85c72014-08-23 20:34:57 -0700340 private final Map<String, RemoteConference> mConferenceById = new HashMap<>();
Ihab Awad5d0410f2014-07-30 10:07:40 -0700341 private final Set<RemoteConnection> mPendingConnections = new HashSet<>();
342
Ihab Awadb8e85c72014-08-23 20:34:57 -0700343 RemoteConnectionService(
344 IConnectionService outgoingConnectionServiceRpc,
345 ConnectionService ourConnectionServiceImpl) throws RemoteException {
346 mOutgoingConnectionServiceRpc = outgoingConnectionServiceRpc;
347 mOutgoingConnectionServiceRpc.asBinder().linkToDeath(mDeathRecipient, 0);
348 mOurConnectionServiceImpl = ourConnectionServiceImpl;
Santos Cordon52d8a152014-06-17 19:08:45 -0700349 }
350
351 @Override
352 public String toString() {
Ihab Awadb8e85c72014-08-23 20:34:57 -0700353 return "[RemoteCS - " + mOutgoingConnectionServiceRpc.asBinder().toString() + "]";
Santos Cordon52d8a152014-06-17 19:08:45 -0700354 }
355
Ihab Awadf8b69882014-07-25 15:14:01 -0700356 final RemoteConnection createRemoteConnection(
357 PhoneAccountHandle connectionManagerPhoneAccount,
358 ConnectionRequest request,
359 boolean isIncoming) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700360 final String id = UUID.randomUUID().toString();
Ihab Awad8aecfed2014-08-08 17:06:11 -0700361 final ConnectionRequest newRequest = new ConnectionRequest(
Ihab Awad5d0410f2014-07-30 10:07:40 -0700362 request.getAccountHandle(),
Nancy Chenea38cca2014-09-05 16:38:49 -0700363 request.getAddress(),
Ihab Awad5d0410f2014-07-30 10:07:40 -0700364 request.getExtras(),
365 request.getVideoState());
366 try {
Ihab Awad8aecfed2014-08-08 17:06:11 -0700367 if (mConnectionById.isEmpty()) {
Ihab Awadb8e85c72014-08-23 20:34:57 -0700368 mOutgoingConnectionServiceRpc.addConnectionServiceAdapter(mServant.getStub());
Ihab Awad8aecfed2014-08-08 17:06:11 -0700369 }
370 RemoteConnection connection =
Ihab Awadb8e85c72014-08-23 20:34:57 -0700371 new RemoteConnection(id, mOutgoingConnectionServiceRpc, newRequest);
Ihab Awad8aecfed2014-08-08 17:06:11 -0700372 mPendingConnections.add(connection);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700373 mConnectionById.put(id, connection);
Ihab Awadb8e85c72014-08-23 20:34:57 -0700374 mOutgoingConnectionServiceRpc.createConnection(
Ihab Awad5d0410f2014-07-30 10:07:40 -0700375 connectionManagerPhoneAccount,
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700376 id,
Ihab Awad5d0410f2014-07-30 10:07:40 -0700377 newRequest,
Yorke Leec3cf9822014-10-02 09:38:39 -0700378 isIncoming,
379 false /* isUnknownCall */);
Andrew Lee100e2932014-09-08 15:34:24 -0700380 connection.registerCallback(new RemoteConnection.Callback() {
Ihab Awad8aecfed2014-08-08 17:06:11 -0700381 @Override
382 public void onDestroyed(RemoteConnection connection) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700383 mConnectionById.remove(id);
Ihab Awadb8e85c72014-08-23 20:34:57 -0700384 maybeDisconnectAdapter();
Ihab Awad8aecfed2014-08-08 17:06:11 -0700385 }
386 });
Ihab Awad5d0410f2014-07-30 10:07:40 -0700387 return connection;
388 } catch (RemoteException e) {
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700389 return RemoteConnection.failure(
390 new DisconnectCause(DisconnectCause.ERROR, e.toString()));
Santos Cordon52d8a152014-06-17 19:08:45 -0700391 }
392 }
393
Ihab Awad50e35062014-09-30 09:17:03 -0700394 private boolean hasConnection(String callId) {
mike dooley879142b2014-10-08 13:39:28 -0700395 return mConnectionById.containsKey(callId);
Ihab Awad50e35062014-09-30 09:17:03 -0700396 }
397
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700398 private RemoteConnection findConnectionForAction(
399 String callId, String action) {
Ihab Awad5d0410f2014-07-30 10:07:40 -0700400 if (mConnectionById.containsKey(callId)) {
401 return mConnectionById.get(callId);
402 }
403 Log.w(this, "%s - Cannot find Connection %s", action, callId);
404 return NULL_CONNECTION;
Santos Cordon52d8a152014-06-17 19:08:45 -0700405 }
Ihab Awadb8e85c72014-08-23 20:34:57 -0700406
407 private RemoteConference findConferenceForAction(
408 String callId, String action) {
409 if (mConferenceById.containsKey(callId)) {
410 return mConferenceById.get(callId);
411 }
412 Log.w(this, "%s - Cannot find Conference %s", action, callId);
413 return NULL_CONFERENCE;
414 }
415
416 private void maybeDisconnectAdapter() {
417 if (mConnectionById.isEmpty() && mConferenceById.isEmpty()) {
418 try {
419 mOutgoingConnectionServiceRpc.removeConnectionServiceAdapter(mServant.getStub());
420 } catch (RemoteException e) {
421 }
422 }
423 }
Santos Cordon52d8a152014-06-17 19:08:45 -0700424}