blob: 7374a3b022aea6b0814dfbe3b5b0e33664096e72 [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());
Rekha Kumar07366812015-03-24 16:42:31 -070087 connection.setCallSubstate(parcel.getCallSubstate());
Ihab Awad6107bab2014-08-18 09:23:25 -070088 if (connection.getState() == Connection.STATE_DISCONNECTED) {
89 // ... then, if it was created in a disconnected state, that indicates
90 // failure on the providing end, so immediately mark it destroyed
91 connection.setDestroyed();
92 }
Sailesh Nepal48031592014-07-18 14:21:23 -070093 }
94 }
Sailesh Nepal2ab88cc2014-07-18 14:49:18 -070095
Sailesh Nepal2a46b902014-07-04 17:21:07 -070096 @Override
Ihab Awad5d0410f2014-07-30 10:07:40 -070097 public void setActive(String callId) {
Ihab Awadb8e85c72014-08-23 20:34:57 -070098 if (mConnectionById.containsKey(callId)) {
99 findConnectionForAction(callId, "setActive")
100 .setState(Connection.STATE_ACTIVE);
101 } else {
102 findConferenceForAction(callId, "setActive")
103 .setState(Connection.STATE_ACTIVE);
104 }
Santos Cordon52d8a152014-06-17 19:08:45 -0700105 }
106
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700107 @Override
Ihab Awad5d0410f2014-07-30 10:07:40 -0700108 public void setRinging(String callId) {
109 findConnectionForAction(callId, "setRinging")
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700110 .setState(Connection.STATE_RINGING);
Andrew Lee5ffbe8b2014-06-20 16:29:33 -0700111 }
112
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700113 @Override
Ihab Awad5d0410f2014-07-30 10:07:40 -0700114 public void setDialing(String callId) {
115 findConnectionForAction(callId, "setDialing")
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700116 .setState(Connection.STATE_DIALING);
Santos Cordon52d8a152014-06-17 19:08:45 -0700117 }
118
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700119 @Override
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700120 public void setDisconnected(String callId, DisconnectCause disconnectCause) {
Ihab Awadb8e85c72014-08-23 20:34:57 -0700121 if (mConnectionById.containsKey(callId)) {
122 findConnectionForAction(callId, "setDisconnected")
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700123 .setDisconnected(disconnectCause);
Ihab Awadb8e85c72014-08-23 20:34:57 -0700124 } else {
125 findConferenceForAction(callId, "setDisconnected")
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700126 .setDisconnected(disconnectCause);
Ihab Awadb8e85c72014-08-23 20:34:57 -0700127 }
Santos Cordon52d8a152014-06-17 19:08:45 -0700128 }
129
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700130 @Override
Ihab Awad5d0410f2014-07-30 10:07:40 -0700131 public void setOnHold(String callId) {
Ihab Awadb8e85c72014-08-23 20:34:57 -0700132 if (mConnectionById.containsKey(callId)) {
133 findConnectionForAction(callId, "setOnHold")
134 .setState(Connection.STATE_HOLDING);
135 } else {
136 findConferenceForAction(callId, "setOnHold")
137 .setState(Connection.STATE_HOLDING);
138 }
Santos Cordon52d8a152014-06-17 19:08:45 -0700139 }
140
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700141 @Override
Andrew Lee100e2932014-09-08 15:34:24 -0700142 public void setRingbackRequested(String callId, boolean ringing) {
143 findConnectionForAction(callId, "setRingbackRequested")
144 .setRingbackRequested(ringing);
Santos Cordon52d8a152014-06-17 19:08:45 -0700145 }
146
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700147 @Override
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800148 public void setConnectionCapabilities(String callId, int connectionCapabilities) {
Ihab Awadb8e85c72014-08-23 20:34:57 -0700149 if (mConnectionById.containsKey(callId)) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800150 findConnectionForAction(callId, "setConnectionCapabilities")
151 .setConnectionCapabilities(connectionCapabilities);
Ihab Awadb8e85c72014-08-23 20:34:57 -0700152 } else {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800153 findConferenceForAction(callId, "setConnectionCapabilities")
154 .setConnectionCapabilities(connectionCapabilities);
Ihab Awadb8e85c72014-08-23 20:34:57 -0700155 }
Santos Cordon52d8a152014-06-17 19:08:45 -0700156 }
157
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700158 @Override
Ihab Awad5d0410f2014-07-30 10:07:40 -0700159 public void setIsConferenced(String callId, String conferenceCallId) {
Ihab Awadb8e85c72014-08-23 20:34:57 -0700160 // Note: callId should not be null; conferenceCallId may be null
161 RemoteConnection connection =
162 findConnectionForAction(callId, "setIsConferenced");
163 if (connection != NULL_CONNECTION) {
164 if (conferenceCallId == null) {
165 // 'connection' is being split from its conference
166 if (connection.getConference() != null) {
167 connection.getConference().removeConnection(connection);
168 }
169 } else {
170 RemoteConference conference =
171 findConferenceForAction(conferenceCallId, "setIsConferenced");
172 if (conference != NULL_CONFERENCE) {
173 conference.addConnection(connection);
174 }
175 }
176 }
Santos Cordon52d8a152014-06-17 19:08:45 -0700177 }
178
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700179 @Override
Ihab Awadb8e85c72014-08-23 20:34:57 -0700180 public void addConferenceCall(
181 final String callId,
182 ParcelableConference parcel) {
183 RemoteConference conference = new RemoteConference(callId,
184 mOutgoingConnectionServiceRpc);
185
186 for (String id : parcel.getConnectionIds()) {
187 RemoteConnection c = mConnectionById.get(id);
188 if (c != null) {
189 conference.addConnection(c);
190 }
191 }
192
193 if (conference.getConnections().size() == 0) {
194 // A conference was created, but none of its connections are ones that have been
195 // created by, and therefore being tracked by, this remote connection service. It
196 // is of no interest to us.
197 return;
198 }
199
200 conference.setState(parcel.getState());
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800201 conference.setConnectionCapabilities(parcel.getConnectionCapabilities());
Ihab Awadb8e85c72014-08-23 20:34:57 -0700202 mConferenceById.put(callId, conference);
Andrew Lee100e2932014-09-08 15:34:24 -0700203 conference.registerCallback(new RemoteConference.Callback() {
Ihab Awadb8e85c72014-08-23 20:34:57 -0700204 @Override
205 public void onDestroyed(RemoteConference c) {
206 mConferenceById.remove(callId);
207 maybeDisconnectAdapter();
208 }
209 });
210
211 mOurConnectionServiceImpl.addRemoteConference(conference);
Santos Cordon52d8a152014-06-17 19:08:45 -0700212 }
213
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700214 @Override
Ihab Awad5d0410f2014-07-30 10:07:40 -0700215 public void removeCall(String callId) {
Ihab Awadb8e85c72014-08-23 20:34:57 -0700216 if (mConnectionById.containsKey(callId)) {
217 findConnectionForAction(callId, "removeCall")
218 .setDestroyed();
219 } else {
220 findConferenceForAction(callId, "removeCall")
221 .setDestroyed();
222 }
Santos Cordon52d8a152014-06-17 19:08:45 -0700223 }
224
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700225 @Override
Ihab Awad5d0410f2014-07-30 10:07:40 -0700226 public void onPostDialWait(String callId, String remaining) {
227 findConnectionForAction(callId, "onPostDialWait")
228 .setPostDialWait(remaining);
Santos Cordon52d8a152014-06-17 19:08:45 -0700229 }
230
Santos Cordon52d8a152014-06-17 19:08:45 -0700231 @Override
Nancy Chen27d1c2d2014-12-15 16:12:50 -0800232 public void onPostDialChar(String callId, char nextChar) {
233 findConnectionForAction(callId, "onPostDialChar")
234 .onPostDialChar(nextChar);
235 }
236
237 @Override
Santos Cordon52d8a152014-06-17 19:08:45 -0700238 public void queryRemoteConnectionServices(RemoteServiceCallback callback) {
Ihab Awad5d0410f2014-07-30 10:07:40 -0700239 // Not supported from remote connection service.
Santos Cordon52d8a152014-06-17 19:08:45 -0700240 }
Tyler Gunn8d83fa92014-07-01 11:31:21 -0700241
Sailesh Nepal33aaae42014-07-07 22:49:44 -0700242 @Override
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700243 public void setVideoProvider(String callId, IVideoProvider videoProvider) {
Sailesh Nepal11aeae52015-01-28 16:54:09 -0800244 RemoteConnection.VideoProvider remoteVideoProvider = null;
245 if (videoProvider != null) {
246 remoteVideoProvider = new RemoteConnection.VideoProvider(videoProvider);
247 }
Ihab Awada64627c2014-08-20 09:36:40 -0700248 findConnectionForAction(callId, "setVideoProvider")
Sailesh Nepal11aeae52015-01-28 16:54:09 -0800249 .setVideoProvider(remoteVideoProvider);
Tyler Gunnaa07df82014-07-17 07:50:22 -0700250 }
251
252 @Override
Ihab Awad5d0410f2014-07-30 10:07:40 -0700253 public void setVideoState(String callId, int videoState) {
254 findConnectionForAction(callId, "setVideoState")
255 .setVideoState(videoState);
Sailesh Nepal33aaae42014-07-07 22:49:44 -0700256 }
Sailesh Nepale7ef59a2014-07-08 21:48:22 -0700257
Sailesh Nepale7ef59a2014-07-08 21:48:22 -0700258 @Override
Andrew Lee100e2932014-09-08 15:34:24 -0700259 public void setIsVoipAudioMode(String callId, boolean isVoip) {
260 findConnectionForAction(callId, "setIsVoipAudioMode")
261 .setIsVoipAudioMode(isVoip);
Sailesh Nepale7ef59a2014-07-08 21:48:22 -0700262 }
Sailesh Nepal61203862014-07-11 14:50:13 -0700263
264 @Override
Ihab Awad5d0410f2014-07-30 10:07:40 -0700265 public void setStatusHints(String callId, StatusHints statusHints) {
266 findConnectionForAction(callId, "setStatusHints")
267 .setStatusHints(statusHints);
Sailesh Nepal61203862014-07-11 14:50:13 -0700268 }
269
270 @Override
Andrew Lee100e2932014-09-08 15:34:24 -0700271 public void setAddress(String callId, Uri address, int presentation) {
272 findConnectionForAction(callId, "setAddress")
273 .setAddress(address, presentation);
Sailesh Nepal61203862014-07-11 14:50:13 -0700274 }
Sailesh Nepal2ab88cc2014-07-18 14:49:18 -0700275
276 @Override
Ihab Awad5d0410f2014-07-30 10:07:40 -0700277 public void setCallerDisplayName(String callId, String callerDisplayName,
278 int presentation) {
279 findConnectionForAction(callId, "setCallerDisplayName")
280 .setCallerDisplayName(callerDisplayName, presentation);
281 }
282
283 @Override
Ihab Awad5d0410f2014-07-30 10:07:40 -0700284 public IBinder asBinder() {
285 throw new UnsupportedOperationException();
Sailesh Nepal2ab88cc2014-07-18 14:49:18 -0700286 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700287
288 @Override
289 public final void setConferenceableConnections(
290 String callId, List<String> conferenceableConnectionIds) {
Ihab Awadb8e85c72014-08-23 20:34:57 -0700291 List<RemoteConnection> conferenceable = new ArrayList<>();
292 for (String id : conferenceableConnectionIds) {
293 if (mConnectionById.containsKey(id)) {
294 conferenceable.add(mConnectionById.get(id));
295 }
296 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700297
Ihab Awad50e35062014-09-30 09:17:03 -0700298 if (hasConnection(callId)) {
299 findConnectionForAction(callId, "setConferenceableConnections")
300 .setConferenceableConnections(conferenceable);
301 } else {
302 findConferenceForAction(callId, "setConferenceableConnections")
303 .setConferenceableConnections(conferenceable);
304 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700305 }
Tyler Gunn4a57b9b2014-10-30 14:27:48 -0700306
307 @Override
308 public void addExistingConnection(String callId, ParcelableConnection connection) {
309 // TODO: add contents of this method
310 RemoteConnection remoteConnction = new RemoteConnection(callId,
311 mOutgoingConnectionServiceRpc, connection);
312
313 mOurConnectionServiceImpl.addRemoteExistingConnection(remoteConnction);
314 }
Rekha Kumar07366812015-03-24 16:42:31 -0700315
316 @Override
317 public void setCallSubstate(String callId, int callSubstate) {
318 findConnectionForAction(callId, "callSubstate")
319 .setCallSubstate(callSubstate);
320 }
Santos Cordon52d8a152014-06-17 19:08:45 -0700321 };
322
Ihab Awad5d0410f2014-07-30 10:07:40 -0700323 private final ConnectionServiceAdapterServant mServant =
324 new ConnectionServiceAdapterServant(mServantDelegate);
Santos Cordon52d8a152014-06-17 19:08:45 -0700325
Ihab Awad5d0410f2014-07-30 10:07:40 -0700326 private final DeathRecipient mDeathRecipient = new DeathRecipient() {
327 @Override
328 public void binderDied() {
329 for (RemoteConnection c : mConnectionById.values()) {
330 c.setDestroyed();
331 }
Ihab Awadb8e85c72014-08-23 20:34:57 -0700332 for (RemoteConference c : mConferenceById.values()) {
333 c.setDestroyed();
334 }
Ihab Awad5d0410f2014-07-30 10:07:40 -0700335 mConnectionById.clear();
Ihab Awadb8e85c72014-08-23 20:34:57 -0700336 mConferenceById.clear();
Ihab Awad5d0410f2014-07-30 10:07:40 -0700337 mPendingConnections.clear();
Ihab Awadb8e85c72014-08-23 20:34:57 -0700338 mOutgoingConnectionServiceRpc.asBinder().unlinkToDeath(mDeathRecipient, 0);
Ihab Awad5d0410f2014-07-30 10:07:40 -0700339 }
340 };
341
Ihab Awadb8e85c72014-08-23 20:34:57 -0700342 private final IConnectionService mOutgoingConnectionServiceRpc;
343 private final ConnectionService mOurConnectionServiceImpl;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700344 private final Map<String, RemoteConnection> mConnectionById = new HashMap<>();
Ihab Awadb8e85c72014-08-23 20:34:57 -0700345 private final Map<String, RemoteConference> mConferenceById = new HashMap<>();
Ihab Awad5d0410f2014-07-30 10:07:40 -0700346 private final Set<RemoteConnection> mPendingConnections = new HashSet<>();
347
Ihab Awadb8e85c72014-08-23 20:34:57 -0700348 RemoteConnectionService(
349 IConnectionService outgoingConnectionServiceRpc,
350 ConnectionService ourConnectionServiceImpl) throws RemoteException {
351 mOutgoingConnectionServiceRpc = outgoingConnectionServiceRpc;
352 mOutgoingConnectionServiceRpc.asBinder().linkToDeath(mDeathRecipient, 0);
353 mOurConnectionServiceImpl = ourConnectionServiceImpl;
Santos Cordon52d8a152014-06-17 19:08:45 -0700354 }
355
356 @Override
357 public String toString() {
Ihab Awadb8e85c72014-08-23 20:34:57 -0700358 return "[RemoteCS - " + mOutgoingConnectionServiceRpc.asBinder().toString() + "]";
Santos Cordon52d8a152014-06-17 19:08:45 -0700359 }
360
Ihab Awadf8b69882014-07-25 15:14:01 -0700361 final RemoteConnection createRemoteConnection(
362 PhoneAccountHandle connectionManagerPhoneAccount,
363 ConnectionRequest request,
364 boolean isIncoming) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700365 final String id = UUID.randomUUID().toString();
Ihab Awad8aecfed2014-08-08 17:06:11 -0700366 final ConnectionRequest newRequest = new ConnectionRequest(
Ihab Awad5d0410f2014-07-30 10:07:40 -0700367 request.getAccountHandle(),
Nancy Chenea38cca2014-09-05 16:38:49 -0700368 request.getAddress(),
Ihab Awad5d0410f2014-07-30 10:07:40 -0700369 request.getExtras(),
370 request.getVideoState());
371 try {
Ihab Awad8aecfed2014-08-08 17:06:11 -0700372 if (mConnectionById.isEmpty()) {
Ihab Awadb8e85c72014-08-23 20:34:57 -0700373 mOutgoingConnectionServiceRpc.addConnectionServiceAdapter(mServant.getStub());
Ihab Awad8aecfed2014-08-08 17:06:11 -0700374 }
375 RemoteConnection connection =
Ihab Awadb8e85c72014-08-23 20:34:57 -0700376 new RemoteConnection(id, mOutgoingConnectionServiceRpc, newRequest);
Ihab Awad8aecfed2014-08-08 17:06:11 -0700377 mPendingConnections.add(connection);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700378 mConnectionById.put(id, connection);
Ihab Awadb8e85c72014-08-23 20:34:57 -0700379 mOutgoingConnectionServiceRpc.createConnection(
Ihab Awad5d0410f2014-07-30 10:07:40 -0700380 connectionManagerPhoneAccount,
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700381 id,
Ihab Awad5d0410f2014-07-30 10:07:40 -0700382 newRequest,
Yorke Leec3cf9822014-10-02 09:38:39 -0700383 isIncoming,
384 false /* isUnknownCall */);
Andrew Lee100e2932014-09-08 15:34:24 -0700385 connection.registerCallback(new RemoteConnection.Callback() {
Ihab Awad8aecfed2014-08-08 17:06:11 -0700386 @Override
387 public void onDestroyed(RemoteConnection connection) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700388 mConnectionById.remove(id);
Ihab Awadb8e85c72014-08-23 20:34:57 -0700389 maybeDisconnectAdapter();
Ihab Awad8aecfed2014-08-08 17:06:11 -0700390 }
391 });
Ihab Awad5d0410f2014-07-30 10:07:40 -0700392 return connection;
393 } catch (RemoteException e) {
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700394 return RemoteConnection.failure(
395 new DisconnectCause(DisconnectCause.ERROR, e.toString()));
Santos Cordon52d8a152014-06-17 19:08:45 -0700396 }
397 }
398
Ihab Awad50e35062014-09-30 09:17:03 -0700399 private boolean hasConnection(String callId) {
mike dooley879142b2014-10-08 13:39:28 -0700400 return mConnectionById.containsKey(callId);
Ihab Awad50e35062014-09-30 09:17:03 -0700401 }
402
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700403 private RemoteConnection findConnectionForAction(
404 String callId, String action) {
Ihab Awad5d0410f2014-07-30 10:07:40 -0700405 if (mConnectionById.containsKey(callId)) {
406 return mConnectionById.get(callId);
407 }
408 Log.w(this, "%s - Cannot find Connection %s", action, callId);
409 return NULL_CONNECTION;
Santos Cordon52d8a152014-06-17 19:08:45 -0700410 }
Ihab Awadb8e85c72014-08-23 20:34:57 -0700411
412 private RemoteConference findConferenceForAction(
413 String callId, String action) {
414 if (mConferenceById.containsKey(callId)) {
415 return mConferenceById.get(callId);
416 }
417 Log.w(this, "%s - Cannot find Conference %s", action, callId);
418 return NULL_CONFERENCE;
419 }
420
421 private void maybeDisconnectAdapter() {
422 if (mConnectionById.isEmpty() && mConferenceById.isEmpty()) {
423 try {
424 mOutgoingConnectionServiceRpc.removeConnectionServiceAdapter(mServant.getStub());
425 } catch (RemoteException e) {
426 }
427 }
428 }
Santos Cordon52d8a152014-06-17 19:08:45 -0700429}