blob: 43a92cb576e72420dda15f8b02da333dd8eaee7d [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
Ihab Awadb8e85c72014-08-23 20:34:57 -0700174 public void addConferenceCall(
175 final String callId,
176 ParcelableConference parcel) {
177 RemoteConference conference = new RemoteConference(callId,
178 mOutgoingConnectionServiceRpc);
179
180 for (String id : parcel.getConnectionIds()) {
181 RemoteConnection c = mConnectionById.get(id);
182 if (c != null) {
183 conference.addConnection(c);
184 }
185 }
186
187 if (conference.getConnections().size() == 0) {
188 // A conference was created, but none of its connections are ones that have been
189 // created by, and therefore being tracked by, this remote connection service. It
190 // is of no interest to us.
191 return;
192 }
193
194 conference.setState(parcel.getState());
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800195 conference.setConnectionCapabilities(parcel.getConnectionCapabilities());
Ihab Awadb8e85c72014-08-23 20:34:57 -0700196 mConferenceById.put(callId, conference);
Andrew Lee100e2932014-09-08 15:34:24 -0700197 conference.registerCallback(new RemoteConference.Callback() {
Ihab Awadb8e85c72014-08-23 20:34:57 -0700198 @Override
199 public void onDestroyed(RemoteConference c) {
200 mConferenceById.remove(callId);
201 maybeDisconnectAdapter();
202 }
203 });
204
205 mOurConnectionServiceImpl.addRemoteConference(conference);
Santos Cordon52d8a152014-06-17 19:08:45 -0700206 }
207
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700208 @Override
Ihab Awad5d0410f2014-07-30 10:07:40 -0700209 public void removeCall(String callId) {
Ihab Awadb8e85c72014-08-23 20:34:57 -0700210 if (mConnectionById.containsKey(callId)) {
211 findConnectionForAction(callId, "removeCall")
212 .setDestroyed();
213 } else {
214 findConferenceForAction(callId, "removeCall")
215 .setDestroyed();
216 }
Santos Cordon52d8a152014-06-17 19:08:45 -0700217 }
218
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700219 @Override
Ihab Awad5d0410f2014-07-30 10:07:40 -0700220 public void onPostDialWait(String callId, String remaining) {
221 findConnectionForAction(callId, "onPostDialWait")
222 .setPostDialWait(remaining);
Santos Cordon52d8a152014-06-17 19:08:45 -0700223 }
224
Santos Cordon52d8a152014-06-17 19:08:45 -0700225 @Override
Nancy Chen27d1c2d2014-12-15 16:12:50 -0800226 public void onPostDialChar(String callId, char nextChar) {
227 findConnectionForAction(callId, "onPostDialChar")
228 .onPostDialChar(nextChar);
229 }
230
231 @Override
Santos Cordon52d8a152014-06-17 19:08:45 -0700232 public void queryRemoteConnectionServices(RemoteServiceCallback callback) {
Ihab Awad5d0410f2014-07-30 10:07:40 -0700233 // Not supported from remote connection service.
Santos Cordon52d8a152014-06-17 19:08:45 -0700234 }
Tyler Gunn8d83fa92014-07-01 11:31:21 -0700235
Sailesh Nepal33aaae42014-07-07 22:49:44 -0700236 @Override
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700237 public void setVideoProvider(String callId, IVideoProvider videoProvider) {
Sailesh Nepal11aeae52015-01-28 16:54:09 -0800238 RemoteConnection.VideoProvider remoteVideoProvider = null;
239 if (videoProvider != null) {
240 remoteVideoProvider = new RemoteConnection.VideoProvider(videoProvider);
241 }
Ihab Awada64627c2014-08-20 09:36:40 -0700242 findConnectionForAction(callId, "setVideoProvider")
Sailesh Nepal11aeae52015-01-28 16:54:09 -0800243 .setVideoProvider(remoteVideoProvider);
Tyler Gunnaa07df82014-07-17 07:50:22 -0700244 }
245
246 @Override
Ihab Awad5d0410f2014-07-30 10:07:40 -0700247 public void setVideoState(String callId, int videoState) {
248 findConnectionForAction(callId, "setVideoState")
249 .setVideoState(videoState);
Sailesh Nepal33aaae42014-07-07 22:49:44 -0700250 }
Sailesh Nepale7ef59a2014-07-08 21:48:22 -0700251
Sailesh Nepale7ef59a2014-07-08 21:48:22 -0700252 @Override
Andrew Lee100e2932014-09-08 15:34:24 -0700253 public void setIsVoipAudioMode(String callId, boolean isVoip) {
254 findConnectionForAction(callId, "setIsVoipAudioMode")
255 .setIsVoipAudioMode(isVoip);
Sailesh Nepale7ef59a2014-07-08 21:48:22 -0700256 }
Sailesh Nepal61203862014-07-11 14:50:13 -0700257
258 @Override
Ihab Awad5d0410f2014-07-30 10:07:40 -0700259 public void setStatusHints(String callId, StatusHints statusHints) {
260 findConnectionForAction(callId, "setStatusHints")
261 .setStatusHints(statusHints);
Sailesh Nepal61203862014-07-11 14:50:13 -0700262 }
263
264 @Override
Andrew Lee100e2932014-09-08 15:34:24 -0700265 public void setAddress(String callId, Uri address, int presentation) {
266 findConnectionForAction(callId, "setAddress")
267 .setAddress(address, presentation);
Sailesh Nepal61203862014-07-11 14:50:13 -0700268 }
Sailesh Nepal2ab88cc2014-07-18 14:49:18 -0700269
270 @Override
Ihab Awad5d0410f2014-07-30 10:07:40 -0700271 public void setCallerDisplayName(String callId, String callerDisplayName,
272 int presentation) {
273 findConnectionForAction(callId, "setCallerDisplayName")
274 .setCallerDisplayName(callerDisplayName, presentation);
275 }
276
277 @Override
Ihab Awad5d0410f2014-07-30 10:07:40 -0700278 public IBinder asBinder() {
279 throw new UnsupportedOperationException();
Sailesh Nepal2ab88cc2014-07-18 14:49:18 -0700280 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700281
282 @Override
283 public final void setConferenceableConnections(
284 String callId, List<String> conferenceableConnectionIds) {
Ihab Awadb8e85c72014-08-23 20:34:57 -0700285 List<RemoteConnection> conferenceable = new ArrayList<>();
286 for (String id : conferenceableConnectionIds) {
287 if (mConnectionById.containsKey(id)) {
288 conferenceable.add(mConnectionById.get(id));
289 }
290 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700291
Ihab Awad50e35062014-09-30 09:17:03 -0700292 if (hasConnection(callId)) {
293 findConnectionForAction(callId, "setConferenceableConnections")
294 .setConferenceableConnections(conferenceable);
295 } else {
296 findConferenceForAction(callId, "setConferenceableConnections")
297 .setConferenceableConnections(conferenceable);
298 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700299 }
Tyler Gunn4a57b9b2014-10-30 14:27:48 -0700300
301 @Override
302 public void addExistingConnection(String callId, ParcelableConnection connection) {
303 // TODO: add contents of this method
304 RemoteConnection remoteConnction = new RemoteConnection(callId,
305 mOutgoingConnectionServiceRpc, connection);
306
307 mOurConnectionServiceImpl.addRemoteExistingConnection(remoteConnction);
308 }
Santos Cordon52d8a152014-06-17 19:08:45 -0700309 };
310
Ihab Awad5d0410f2014-07-30 10:07:40 -0700311 private final ConnectionServiceAdapterServant mServant =
312 new ConnectionServiceAdapterServant(mServantDelegate);
Santos Cordon52d8a152014-06-17 19:08:45 -0700313
Ihab Awad5d0410f2014-07-30 10:07:40 -0700314 private final DeathRecipient mDeathRecipient = new DeathRecipient() {
315 @Override
316 public void binderDied() {
317 for (RemoteConnection c : mConnectionById.values()) {
318 c.setDestroyed();
319 }
Ihab Awadb8e85c72014-08-23 20:34:57 -0700320 for (RemoteConference c : mConferenceById.values()) {
321 c.setDestroyed();
322 }
Ihab Awad5d0410f2014-07-30 10:07:40 -0700323 mConnectionById.clear();
Ihab Awadb8e85c72014-08-23 20:34:57 -0700324 mConferenceById.clear();
Ihab Awad5d0410f2014-07-30 10:07:40 -0700325 mPendingConnections.clear();
Ihab Awadb8e85c72014-08-23 20:34:57 -0700326 mOutgoingConnectionServiceRpc.asBinder().unlinkToDeath(mDeathRecipient, 0);
Ihab Awad5d0410f2014-07-30 10:07:40 -0700327 }
328 };
329
Ihab Awadb8e85c72014-08-23 20:34:57 -0700330 private final IConnectionService mOutgoingConnectionServiceRpc;
331 private final ConnectionService mOurConnectionServiceImpl;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700332 private final Map<String, RemoteConnection> mConnectionById = new HashMap<>();
Ihab Awadb8e85c72014-08-23 20:34:57 -0700333 private final Map<String, RemoteConference> mConferenceById = new HashMap<>();
Ihab Awad5d0410f2014-07-30 10:07:40 -0700334 private final Set<RemoteConnection> mPendingConnections = new HashSet<>();
335
Ihab Awadb8e85c72014-08-23 20:34:57 -0700336 RemoteConnectionService(
337 IConnectionService outgoingConnectionServiceRpc,
338 ConnectionService ourConnectionServiceImpl) throws RemoteException {
339 mOutgoingConnectionServiceRpc = outgoingConnectionServiceRpc;
340 mOutgoingConnectionServiceRpc.asBinder().linkToDeath(mDeathRecipient, 0);
341 mOurConnectionServiceImpl = ourConnectionServiceImpl;
Santos Cordon52d8a152014-06-17 19:08:45 -0700342 }
343
344 @Override
345 public String toString() {
Ihab Awadb8e85c72014-08-23 20:34:57 -0700346 return "[RemoteCS - " + mOutgoingConnectionServiceRpc.asBinder().toString() + "]";
Santos Cordon52d8a152014-06-17 19:08:45 -0700347 }
348
Ihab Awadf8b69882014-07-25 15:14:01 -0700349 final RemoteConnection createRemoteConnection(
350 PhoneAccountHandle connectionManagerPhoneAccount,
351 ConnectionRequest request,
352 boolean isIncoming) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700353 final String id = UUID.randomUUID().toString();
Ihab Awad8aecfed2014-08-08 17:06:11 -0700354 final ConnectionRequest newRequest = new ConnectionRequest(
Ihab Awad5d0410f2014-07-30 10:07:40 -0700355 request.getAccountHandle(),
Nancy Chenea38cca2014-09-05 16:38:49 -0700356 request.getAddress(),
Ihab Awad5d0410f2014-07-30 10:07:40 -0700357 request.getExtras(),
358 request.getVideoState());
359 try {
Ihab Awad8aecfed2014-08-08 17:06:11 -0700360 if (mConnectionById.isEmpty()) {
Ihab Awadb8e85c72014-08-23 20:34:57 -0700361 mOutgoingConnectionServiceRpc.addConnectionServiceAdapter(mServant.getStub());
Ihab Awad8aecfed2014-08-08 17:06:11 -0700362 }
363 RemoteConnection connection =
Ihab Awadb8e85c72014-08-23 20:34:57 -0700364 new RemoteConnection(id, mOutgoingConnectionServiceRpc, newRequest);
Ihab Awad8aecfed2014-08-08 17:06:11 -0700365 mPendingConnections.add(connection);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700366 mConnectionById.put(id, connection);
Ihab Awadb8e85c72014-08-23 20:34:57 -0700367 mOutgoingConnectionServiceRpc.createConnection(
Ihab Awad5d0410f2014-07-30 10:07:40 -0700368 connectionManagerPhoneAccount,
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700369 id,
Ihab Awad5d0410f2014-07-30 10:07:40 -0700370 newRequest,
Yorke Leec3cf9822014-10-02 09:38:39 -0700371 isIncoming,
372 false /* isUnknownCall */);
Andrew Lee100e2932014-09-08 15:34:24 -0700373 connection.registerCallback(new RemoteConnection.Callback() {
Ihab Awad8aecfed2014-08-08 17:06:11 -0700374 @Override
375 public void onDestroyed(RemoteConnection connection) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700376 mConnectionById.remove(id);
Ihab Awadb8e85c72014-08-23 20:34:57 -0700377 maybeDisconnectAdapter();
Ihab Awad8aecfed2014-08-08 17:06:11 -0700378 }
379 });
Ihab Awad5d0410f2014-07-30 10:07:40 -0700380 return connection;
381 } catch (RemoteException e) {
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700382 return RemoteConnection.failure(
383 new DisconnectCause(DisconnectCause.ERROR, e.toString()));
Santos Cordon52d8a152014-06-17 19:08:45 -0700384 }
385 }
386
Ihab Awad50e35062014-09-30 09:17:03 -0700387 private boolean hasConnection(String callId) {
mike dooley879142b2014-10-08 13:39:28 -0700388 return mConnectionById.containsKey(callId);
Ihab Awad50e35062014-09-30 09:17:03 -0700389 }
390
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700391 private RemoteConnection findConnectionForAction(
392 String callId, String action) {
Ihab Awad5d0410f2014-07-30 10:07:40 -0700393 if (mConnectionById.containsKey(callId)) {
394 return mConnectionById.get(callId);
395 }
396 Log.w(this, "%s - Cannot find Connection %s", action, callId);
397 return NULL_CONNECTION;
Santos Cordon52d8a152014-06-17 19:08:45 -0700398 }
Ihab Awadb8e85c72014-08-23 20:34:57 -0700399
400 private RemoteConference findConferenceForAction(
401 String callId, String action) {
402 if (mConferenceById.containsKey(callId)) {
403 return mConferenceById.get(callId);
404 }
405 Log.w(this, "%s - Cannot find Conference %s", action, callId);
406 return NULL_CONFERENCE;
407 }
408
409 private void maybeDisconnectAdapter() {
410 if (mConnectionById.isEmpty() && mConferenceById.isEmpty()) {
411 try {
412 mOutgoingConnectionServiceRpc.removeConnectionServiceAdapter(mServant.getStub());
413 } catch (RemoteException e) {
414 }
415 }
416 }
Santos Cordon52d8a152014-06-17 19:08:45 -0700417}