Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 1 | /* |
| 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 Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 14 | * limitations under the License. |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 15 | */ |
| 16 | |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame^] | 17 | package android.telecom; |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 18 | |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 19 | import android.net.Uri; |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 20 | import android.os.IBinder; |
Santos Cordon | e8dc4be | 2014-07-21 01:28:28 -0700 | [diff] [blame] | 21 | import android.os.IBinder.DeathRecipient; |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 22 | import android.os.RemoteException; |
| 23 | import android.telephony.DisconnectCause; |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 24 | |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame^] | 25 | import com.android.internal.telecom.IConnectionService; |
| 26 | import com.android.internal.telecom.IConnectionServiceAdapter; |
| 27 | import com.android.internal.telecom.IVideoProvider; |
| 28 | import com.android.internal.telecom.RemoteServiceCallback; |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 29 | |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 30 | import java.util.ArrayList; |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 31 | import java.util.HashMap; |
| 32 | import java.util.HashSet; |
| 33 | import java.util.Map; |
| 34 | import java.util.Set; |
Santos Cordon | 7c7bc7f | 2014-07-28 18:15:48 -0700 | [diff] [blame] | 35 | import java.util.List; |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 36 | import java.util.UUID; |
| 37 | |
| 38 | /** |
| 39 | * Remote connection service which other connection services can use to place calls on their behalf. |
Sailesh Nepal | 091768c | 2014-06-30 15:15:23 -0700 | [diff] [blame] | 40 | * |
| 41 | * @hide |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 42 | */ |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 43 | final class RemoteConnectionService { |
Sailesh Nepal | 4803159 | 2014-07-18 14:21:23 -0700 | [diff] [blame] | 44 | |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 45 | private static final RemoteConnection NULL_CONNECTION = |
| 46 | new RemoteConnection("NULL", null, null); |
| 47 | |
| 48 | private static final RemoteConference NULL_CONFERENCE = |
| 49 | new RemoteConference("NULL", null); |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 50 | |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 51 | private final IConnectionServiceAdapter mServantDelegate = new IConnectionServiceAdapter() { |
Sailesh Nepal | 4803159 | 2014-07-18 14:21:23 -0700 | [diff] [blame] | 52 | @Override |
Ihab Awad | 6107bab | 2014-08-18 09:23:25 -0700 | [diff] [blame] | 53 | public void handleCreateConnectionComplete( |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 54 | String id, |
| 55 | ConnectionRequest request, |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 56 | ParcelableConnection parcel) { |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 57 | RemoteConnection connection = |
| 58 | findConnectionForAction(id, "handleCreateConnectionSuccessful"); |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 59 | if (connection != NULL_CONNECTION && mPendingConnections.contains(connection)) { |
| 60 | mPendingConnections.remove(connection); |
Ihab Awad | 6107bab | 2014-08-18 09:23:25 -0700 | [diff] [blame] | 61 | // Unconditionally initialize the connection ... |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 62 | connection.setCallCapabilities(parcel.getCapabilities()); |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 63 | connection.setAddress( |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 64 | parcel.getHandle(), parcel.getHandlePresentation()); |
| 65 | connection.setCallerDisplayName( |
| 66 | parcel.getCallerDisplayName(), |
| 67 | parcel.getCallerDisplayNamePresentation()); |
Sailesh Nepal | 70638f1 | 2014-09-09 21:49:14 -0700 | [diff] [blame] | 68 | // Set state after handle so that the client can identify the connection. |
| 69 | connection.setState(parcel.getState()); |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 70 | List<RemoteConnection> conferenceable = new ArrayList<>(); |
| 71 | for (String confId : parcel.getConferenceableConnectionIds()) { |
| 72 | if (mConnectionById.containsKey(confId)) { |
| 73 | conferenceable.add(mConnectionById.get(confId)); |
| 74 | } |
| 75 | } |
| 76 | connection.setConferenceableConnections(conferenceable); |
Ihab Awad | a64627c | 2014-08-20 09:36:40 -0700 | [diff] [blame] | 77 | connection.setVideoState(parcel.getVideoState()); |
Ihab Awad | 6107bab | 2014-08-18 09:23:25 -0700 | [diff] [blame] | 78 | if (connection.getState() == Connection.STATE_DISCONNECTED) { |
| 79 | // ... then, if it was created in a disconnected state, that indicates |
| 80 | // failure on the providing end, so immediately mark it destroyed |
| 81 | connection.setDestroyed(); |
| 82 | } |
Sailesh Nepal | 4803159 | 2014-07-18 14:21:23 -0700 | [diff] [blame] | 83 | } |
| 84 | } |
Sailesh Nepal | 2ab88cc | 2014-07-18 14:49:18 -0700 | [diff] [blame] | 85 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 86 | @Override |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 87 | public void setActive(String callId) { |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 88 | if (mConnectionById.containsKey(callId)) { |
| 89 | findConnectionForAction(callId, "setActive") |
| 90 | .setState(Connection.STATE_ACTIVE); |
| 91 | } else { |
| 92 | findConferenceForAction(callId, "setActive") |
| 93 | .setState(Connection.STATE_ACTIVE); |
| 94 | } |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 95 | } |
| 96 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 97 | @Override |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 98 | public void setRinging(String callId) { |
| 99 | findConnectionForAction(callId, "setRinging") |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 100 | .setState(Connection.STATE_RINGING); |
Andrew Lee | 5ffbe8b | 2014-06-20 16:29:33 -0700 | [diff] [blame] | 101 | } |
| 102 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 103 | @Override |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 104 | public void setDialing(String callId) { |
| 105 | findConnectionForAction(callId, "setDialing") |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 106 | .setState(Connection.STATE_DIALING); |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 107 | } |
| 108 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 109 | @Override |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 110 | public void setDisconnected(String callId, int disconnectCause, |
| 111 | String disconnectMessage) { |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 112 | if (mConnectionById.containsKey(callId)) { |
| 113 | findConnectionForAction(callId, "setDisconnected") |
| 114 | .setDisconnected(disconnectCause, disconnectMessage); |
| 115 | } else { |
| 116 | findConferenceForAction(callId, "setDisconnected") |
| 117 | .setDisconnected(disconnectCause, disconnectMessage); |
| 118 | } |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 119 | } |
| 120 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 121 | @Override |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 122 | public void setOnHold(String callId) { |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 123 | if (mConnectionById.containsKey(callId)) { |
| 124 | findConnectionForAction(callId, "setOnHold") |
| 125 | .setState(Connection.STATE_HOLDING); |
| 126 | } else { |
| 127 | findConferenceForAction(callId, "setOnHold") |
| 128 | .setState(Connection.STATE_HOLDING); |
| 129 | } |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 130 | } |
| 131 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 132 | @Override |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 133 | public void setRingbackRequested(String callId, boolean ringing) { |
| 134 | findConnectionForAction(callId, "setRingbackRequested") |
| 135 | .setRingbackRequested(ringing); |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 136 | } |
| 137 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 138 | @Override |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 139 | public void setCallCapabilities(String callId, int callCapabilities) { |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 140 | if (mConnectionById.containsKey(callId)) { |
| 141 | findConnectionForAction(callId, "setCallCapabilities") |
| 142 | .setCallCapabilities(callCapabilities); |
| 143 | } else { |
| 144 | findConferenceForAction(callId, "setCallCapabilities") |
| 145 | .setCallCapabilities(callCapabilities); |
| 146 | } |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 147 | } |
| 148 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 149 | @Override |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 150 | public void setIsConferenced(String callId, String conferenceCallId) { |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 151 | // Note: callId should not be null; conferenceCallId may be null |
| 152 | RemoteConnection connection = |
| 153 | findConnectionForAction(callId, "setIsConferenced"); |
| 154 | if (connection != NULL_CONNECTION) { |
| 155 | if (conferenceCallId == null) { |
| 156 | // 'connection' is being split from its conference |
| 157 | if (connection.getConference() != null) { |
| 158 | connection.getConference().removeConnection(connection); |
| 159 | } |
| 160 | } else { |
| 161 | RemoteConference conference = |
| 162 | findConferenceForAction(conferenceCallId, "setIsConferenced"); |
| 163 | if (conference != NULL_CONFERENCE) { |
| 164 | conference.addConnection(connection); |
| 165 | } |
| 166 | } |
| 167 | } |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 168 | } |
| 169 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 170 | @Override |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 171 | public void addConferenceCall( |
| 172 | final String callId, |
| 173 | ParcelableConference parcel) { |
| 174 | RemoteConference conference = new RemoteConference(callId, |
| 175 | mOutgoingConnectionServiceRpc); |
| 176 | |
| 177 | for (String id : parcel.getConnectionIds()) { |
| 178 | RemoteConnection c = mConnectionById.get(id); |
| 179 | if (c != null) { |
| 180 | conference.addConnection(c); |
| 181 | } |
| 182 | } |
| 183 | |
| 184 | if (conference.getConnections().size() == 0) { |
| 185 | // A conference was created, but none of its connections are ones that have been |
| 186 | // created by, and therefore being tracked by, this remote connection service. It |
| 187 | // is of no interest to us. |
| 188 | return; |
| 189 | } |
| 190 | |
| 191 | conference.setState(parcel.getState()); |
| 192 | conference.setCallCapabilities(parcel.getCapabilities()); |
| 193 | mConferenceById.put(callId, conference); |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 194 | conference.registerCallback(new RemoteConference.Callback() { |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 195 | @Override |
| 196 | public void onDestroyed(RemoteConference c) { |
| 197 | mConferenceById.remove(callId); |
| 198 | maybeDisconnectAdapter(); |
| 199 | } |
| 200 | }); |
| 201 | |
| 202 | mOurConnectionServiceImpl.addRemoteConference(conference); |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 203 | } |
| 204 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 205 | @Override |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 206 | public void removeCall(String callId) { |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 207 | if (mConnectionById.containsKey(callId)) { |
| 208 | findConnectionForAction(callId, "removeCall") |
| 209 | .setDestroyed(); |
| 210 | } else { |
| 211 | findConferenceForAction(callId, "removeCall") |
| 212 | .setDestroyed(); |
| 213 | } |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 214 | } |
| 215 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 216 | @Override |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 217 | public void onPostDialWait(String callId, String remaining) { |
| 218 | findConnectionForAction(callId, "onPostDialWait") |
| 219 | .setPostDialWait(remaining); |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 220 | } |
| 221 | |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 222 | @Override |
| 223 | public void queryRemoteConnectionServices(RemoteServiceCallback callback) { |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 224 | // Not supported from remote connection service. |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 225 | } |
Tyler Gunn | 8d83fa9 | 2014-07-01 11:31:21 -0700 | [diff] [blame] | 226 | |
Sailesh Nepal | 33aaae4 | 2014-07-07 22:49:44 -0700 | [diff] [blame] | 227 | @Override |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 228 | public void setVideoProvider(String callId, IVideoProvider videoProvider) { |
Ihab Awad | a64627c | 2014-08-20 09:36:40 -0700 | [diff] [blame] | 229 | findConnectionForAction(callId, "setVideoProvider") |
| 230 | .setVideoProvider(new RemoteConnection.VideoProvider(videoProvider)); |
Tyler Gunn | aa07df8 | 2014-07-17 07:50:22 -0700 | [diff] [blame] | 231 | } |
| 232 | |
| 233 | @Override |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 234 | public void setVideoState(String callId, int videoState) { |
| 235 | findConnectionForAction(callId, "setVideoState") |
| 236 | .setVideoState(videoState); |
Sailesh Nepal | 33aaae4 | 2014-07-07 22:49:44 -0700 | [diff] [blame] | 237 | } |
Sailesh Nepal | e7ef59a | 2014-07-08 21:48:22 -0700 | [diff] [blame] | 238 | |
Sailesh Nepal | e7ef59a | 2014-07-08 21:48:22 -0700 | [diff] [blame] | 239 | @Override |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 240 | public void setIsVoipAudioMode(String callId, boolean isVoip) { |
| 241 | findConnectionForAction(callId, "setIsVoipAudioMode") |
| 242 | .setIsVoipAudioMode(isVoip); |
Sailesh Nepal | e7ef59a | 2014-07-08 21:48:22 -0700 | [diff] [blame] | 243 | } |
Sailesh Nepal | 6120386 | 2014-07-11 14:50:13 -0700 | [diff] [blame] | 244 | |
| 245 | @Override |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 246 | public void setStatusHints(String callId, StatusHints statusHints) { |
| 247 | findConnectionForAction(callId, "setStatusHints") |
| 248 | .setStatusHints(statusHints); |
Sailesh Nepal | 6120386 | 2014-07-11 14:50:13 -0700 | [diff] [blame] | 249 | } |
| 250 | |
| 251 | @Override |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 252 | public void setAddress(String callId, Uri address, int presentation) { |
| 253 | findConnectionForAction(callId, "setAddress") |
| 254 | .setAddress(address, presentation); |
Sailesh Nepal | 6120386 | 2014-07-11 14:50:13 -0700 | [diff] [blame] | 255 | } |
Sailesh Nepal | 2ab88cc | 2014-07-18 14:49:18 -0700 | [diff] [blame] | 256 | |
| 257 | @Override |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 258 | public void setCallerDisplayName(String callId, String callerDisplayName, |
| 259 | int presentation) { |
| 260 | findConnectionForAction(callId, "setCallerDisplayName") |
| 261 | .setCallerDisplayName(callerDisplayName, presentation); |
| 262 | } |
| 263 | |
| 264 | @Override |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 265 | public IBinder asBinder() { |
| 266 | throw new UnsupportedOperationException(); |
Sailesh Nepal | 2ab88cc | 2014-07-18 14:49:18 -0700 | [diff] [blame] | 267 | } |
Santos Cordon | 7c7bc7f | 2014-07-28 18:15:48 -0700 | [diff] [blame] | 268 | |
| 269 | @Override |
| 270 | public final void setConferenceableConnections( |
| 271 | String callId, List<String> conferenceableConnectionIds) { |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 272 | List<RemoteConnection> conferenceable = new ArrayList<>(); |
| 273 | for (String id : conferenceableConnectionIds) { |
| 274 | if (mConnectionById.containsKey(id)) { |
| 275 | conferenceable.add(mConnectionById.get(id)); |
| 276 | } |
| 277 | } |
Santos Cordon | 7c7bc7f | 2014-07-28 18:15:48 -0700 | [diff] [blame] | 278 | |
Santos Cordon | 7c7bc7f | 2014-07-28 18:15:48 -0700 | [diff] [blame] | 279 | findConnectionForAction(callId, "setConferenceableConnections") |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 280 | .setConferenceableConnections(conferenceable); |
Santos Cordon | 7c7bc7f | 2014-07-28 18:15:48 -0700 | [diff] [blame] | 281 | } |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 282 | }; |
| 283 | |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 284 | private final ConnectionServiceAdapterServant mServant = |
| 285 | new ConnectionServiceAdapterServant(mServantDelegate); |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 286 | |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 287 | private final DeathRecipient mDeathRecipient = new DeathRecipient() { |
| 288 | @Override |
| 289 | public void binderDied() { |
| 290 | for (RemoteConnection c : mConnectionById.values()) { |
| 291 | c.setDestroyed(); |
| 292 | } |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 293 | for (RemoteConference c : mConferenceById.values()) { |
| 294 | c.setDestroyed(); |
| 295 | } |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 296 | mConnectionById.clear(); |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 297 | mConferenceById.clear(); |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 298 | mPendingConnections.clear(); |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 299 | mOutgoingConnectionServiceRpc.asBinder().unlinkToDeath(mDeathRecipient, 0); |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 300 | } |
| 301 | }; |
| 302 | |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 303 | private final IConnectionService mOutgoingConnectionServiceRpc; |
| 304 | private final ConnectionService mOurConnectionServiceImpl; |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 305 | private final Map<String, RemoteConnection> mConnectionById = new HashMap<>(); |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 306 | private final Map<String, RemoteConference> mConferenceById = new HashMap<>(); |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 307 | private final Set<RemoteConnection> mPendingConnections = new HashSet<>(); |
| 308 | |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 309 | RemoteConnectionService( |
| 310 | IConnectionService outgoingConnectionServiceRpc, |
| 311 | ConnectionService ourConnectionServiceImpl) throws RemoteException { |
| 312 | mOutgoingConnectionServiceRpc = outgoingConnectionServiceRpc; |
| 313 | mOutgoingConnectionServiceRpc.asBinder().linkToDeath(mDeathRecipient, 0); |
| 314 | mOurConnectionServiceImpl = ourConnectionServiceImpl; |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 315 | } |
| 316 | |
| 317 | @Override |
| 318 | public String toString() { |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 319 | return "[RemoteCS - " + mOutgoingConnectionServiceRpc.asBinder().toString() + "]"; |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 320 | } |
| 321 | |
Ihab Awad | f8b6988 | 2014-07-25 15:14:01 -0700 | [diff] [blame] | 322 | final RemoteConnection createRemoteConnection( |
| 323 | PhoneAccountHandle connectionManagerPhoneAccount, |
| 324 | ConnectionRequest request, |
| 325 | boolean isIncoming) { |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 326 | final String id = UUID.randomUUID().toString(); |
Ihab Awad | 8aecfed | 2014-08-08 17:06:11 -0700 | [diff] [blame] | 327 | final ConnectionRequest newRequest = new ConnectionRequest( |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 328 | request.getAccountHandle(), |
Nancy Chen | ea38cca | 2014-09-05 16:38:49 -0700 | [diff] [blame] | 329 | request.getAddress(), |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 330 | request.getExtras(), |
| 331 | request.getVideoState()); |
| 332 | try { |
Ihab Awad | 8aecfed | 2014-08-08 17:06:11 -0700 | [diff] [blame] | 333 | if (mConnectionById.isEmpty()) { |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 334 | mOutgoingConnectionServiceRpc.addConnectionServiceAdapter(mServant.getStub()); |
Ihab Awad | 8aecfed | 2014-08-08 17:06:11 -0700 | [diff] [blame] | 335 | } |
| 336 | RemoteConnection connection = |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 337 | new RemoteConnection(id, mOutgoingConnectionServiceRpc, newRequest); |
Ihab Awad | 8aecfed | 2014-08-08 17:06:11 -0700 | [diff] [blame] | 338 | mPendingConnections.add(connection); |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 339 | mConnectionById.put(id, connection); |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 340 | mOutgoingConnectionServiceRpc.createConnection( |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 341 | connectionManagerPhoneAccount, |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 342 | id, |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 343 | newRequest, |
| 344 | isIncoming); |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 345 | connection.registerCallback(new RemoteConnection.Callback() { |
Ihab Awad | 8aecfed | 2014-08-08 17:06:11 -0700 | [diff] [blame] | 346 | @Override |
| 347 | public void onDestroyed(RemoteConnection connection) { |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 348 | mConnectionById.remove(id); |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 349 | maybeDisconnectAdapter(); |
Ihab Awad | 8aecfed | 2014-08-08 17:06:11 -0700 | [diff] [blame] | 350 | } |
| 351 | }); |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 352 | return connection; |
| 353 | } catch (RemoteException e) { |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 354 | return RemoteConnection |
| 355 | .failure(DisconnectCause.ERROR_UNSPECIFIED, e.toString()); |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 356 | } |
| 357 | } |
| 358 | |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 359 | private RemoteConnection findConnectionForAction( |
| 360 | String callId, String action) { |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 361 | if (mConnectionById.containsKey(callId)) { |
| 362 | return mConnectionById.get(callId); |
| 363 | } |
| 364 | Log.w(this, "%s - Cannot find Connection %s", action, callId); |
| 365 | return NULL_CONNECTION; |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 366 | } |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 367 | |
| 368 | private RemoteConference findConferenceForAction( |
| 369 | String callId, String action) { |
| 370 | if (mConferenceById.containsKey(callId)) { |
| 371 | return mConferenceById.get(callId); |
| 372 | } |
| 373 | Log.w(this, "%s - Cannot find Conference %s", action, callId); |
| 374 | return NULL_CONFERENCE; |
| 375 | } |
| 376 | |
| 377 | private void maybeDisconnectAdapter() { |
| 378 | if (mConnectionById.isEmpty() && mConferenceById.isEmpty()) { |
| 379 | try { |
| 380 | mOutgoingConnectionServiceRpc.removeConnectionServiceAdapter(mServant.getStub()); |
| 381 | } catch (RemoteException e) { |
| 382 | } |
| 383 | } |
| 384 | } |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 385 | } |