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; |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 23 | |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 24 | import com.android.internal.telecom.IConnectionService; |
| 25 | import com.android.internal.telecom.IConnectionServiceAdapter; |
| 26 | import com.android.internal.telecom.IVideoProvider; |
| 27 | import com.android.internal.telecom.RemoteServiceCallback; |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 28 | |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 29 | import java.util.ArrayList; |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 30 | import java.util.HashMap; |
| 31 | import java.util.HashSet; |
| 32 | import java.util.Map; |
| 33 | import java.util.Set; |
Santos Cordon | 7c7bc7f | 2014-07-28 18:15:48 -0700 | [diff] [blame] | 34 | import java.util.List; |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 35 | import java.util.UUID; |
| 36 | |
| 37 | /** |
| 38 | * 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] | 39 | * |
| 40 | * @hide |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 41 | */ |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 42 | final class RemoteConnectionService { |
Sailesh Nepal | 4803159 | 2014-07-18 14:21:23 -0700 | [diff] [blame] | 43 | |
Tyler Gunn | 4a57b9b | 2014-10-30 14:27:48 -0700 | [diff] [blame^] | 44 | // Note: Casting null to avoid ambiguous constructor reference. |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 45 | private static final RemoteConnection NULL_CONNECTION = |
Tyler Gunn | 4a57b9b | 2014-10-30 14:27:48 -0700 | [diff] [blame^] | 46 | new RemoteConnection("NULL", null, (ConnectionRequest) null); |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 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. |
Sailesh Nepal | c2a978d | 2014-09-20 18:23:05 -0700 | [diff] [blame] | 69 | if (parcel.getState() == Connection.STATE_DISCONNECTED) { |
| 70 | connection.setDisconnected(parcel.getDisconnectCause()); |
| 71 | } else { |
| 72 | connection.setState(parcel.getState()); |
| 73 | } |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 74 | 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 Awad | a64627c | 2014-08-20 09:36:40 -0700 | [diff] [blame] | 81 | connection.setVideoState(parcel.getVideoState()); |
Ihab Awad | 6107bab | 2014-08-18 09:23:25 -0700 | [diff] [blame] | 82 | 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 Nepal | 4803159 | 2014-07-18 14:21:23 -0700 | [diff] [blame] | 87 | } |
| 88 | } |
Sailesh Nepal | 2ab88cc | 2014-07-18 14:49:18 -0700 | [diff] [blame] | 89 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 90 | @Override |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 91 | public void setActive(String callId) { |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 92 | 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 Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 99 | } |
| 100 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 101 | @Override |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 102 | public void setRinging(String callId) { |
| 103 | findConnectionForAction(callId, "setRinging") |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 104 | .setState(Connection.STATE_RINGING); |
Andrew Lee | 5ffbe8b | 2014-06-20 16:29:33 -0700 | [diff] [blame] | 105 | } |
| 106 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 107 | @Override |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 108 | public void setDialing(String callId) { |
| 109 | findConnectionForAction(callId, "setDialing") |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 110 | .setState(Connection.STATE_DIALING); |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 111 | } |
| 112 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 113 | @Override |
Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame] | 114 | public void setDisconnected(String callId, DisconnectCause disconnectCause) { |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 115 | if (mConnectionById.containsKey(callId)) { |
| 116 | findConnectionForAction(callId, "setDisconnected") |
Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame] | 117 | .setDisconnected(disconnectCause); |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 118 | } else { |
| 119 | findConferenceForAction(callId, "setDisconnected") |
Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame] | 120 | .setDisconnected(disconnectCause); |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 121 | } |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 122 | } |
| 123 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 124 | @Override |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 125 | public void setOnHold(String callId) { |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 126 | 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 Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 133 | } |
| 134 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 135 | @Override |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 136 | public void setRingbackRequested(String callId, boolean ringing) { |
| 137 | findConnectionForAction(callId, "setRingbackRequested") |
| 138 | .setRingbackRequested(ringing); |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 139 | } |
| 140 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 141 | @Override |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 142 | public void setCallCapabilities(String callId, int callCapabilities) { |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 143 | if (mConnectionById.containsKey(callId)) { |
| 144 | findConnectionForAction(callId, "setCallCapabilities") |
| 145 | .setCallCapabilities(callCapabilities); |
| 146 | } else { |
| 147 | findConferenceForAction(callId, "setCallCapabilities") |
| 148 | .setCallCapabilities(callCapabilities); |
| 149 | } |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 150 | } |
| 151 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 152 | @Override |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 153 | public void setIsConferenced(String callId, String conferenceCallId) { |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 154 | // 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 Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 171 | } |
| 172 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 173 | @Override |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 174 | 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()); |
| 195 | conference.setCallCapabilities(parcel.getCapabilities()); |
| 196 | mConferenceById.put(callId, conference); |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 197 | conference.registerCallback(new RemoteConference.Callback() { |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 198 | @Override |
| 199 | public void onDestroyed(RemoteConference c) { |
| 200 | mConferenceById.remove(callId); |
| 201 | maybeDisconnectAdapter(); |
| 202 | } |
| 203 | }); |
| 204 | |
| 205 | mOurConnectionServiceImpl.addRemoteConference(conference); |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 206 | } |
| 207 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 208 | @Override |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 209 | public void removeCall(String callId) { |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 210 | if (mConnectionById.containsKey(callId)) { |
| 211 | findConnectionForAction(callId, "removeCall") |
| 212 | .setDestroyed(); |
| 213 | } else { |
| 214 | findConferenceForAction(callId, "removeCall") |
| 215 | .setDestroyed(); |
| 216 | } |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 217 | } |
| 218 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 219 | @Override |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 220 | public void onPostDialWait(String callId, String remaining) { |
| 221 | findConnectionForAction(callId, "onPostDialWait") |
| 222 | .setPostDialWait(remaining); |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 223 | } |
| 224 | |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 225 | @Override |
| 226 | public void queryRemoteConnectionServices(RemoteServiceCallback callback) { |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 227 | // Not supported from remote connection service. |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 228 | } |
Tyler Gunn | 8d83fa9 | 2014-07-01 11:31:21 -0700 | [diff] [blame] | 229 | |
Sailesh Nepal | 33aaae4 | 2014-07-07 22:49:44 -0700 | [diff] [blame] | 230 | @Override |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 231 | public void setVideoProvider(String callId, IVideoProvider videoProvider) { |
Ihab Awad | a64627c | 2014-08-20 09:36:40 -0700 | [diff] [blame] | 232 | findConnectionForAction(callId, "setVideoProvider") |
| 233 | .setVideoProvider(new RemoteConnection.VideoProvider(videoProvider)); |
Tyler Gunn | aa07df8 | 2014-07-17 07:50:22 -0700 | [diff] [blame] | 234 | } |
| 235 | |
| 236 | @Override |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 237 | public void setVideoState(String callId, int videoState) { |
| 238 | findConnectionForAction(callId, "setVideoState") |
| 239 | .setVideoState(videoState); |
Sailesh Nepal | 33aaae4 | 2014-07-07 22:49:44 -0700 | [diff] [blame] | 240 | } |
Sailesh Nepal | e7ef59a | 2014-07-08 21:48:22 -0700 | [diff] [blame] | 241 | |
Sailesh Nepal | e7ef59a | 2014-07-08 21:48:22 -0700 | [diff] [blame] | 242 | @Override |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 243 | public void setIsVoipAudioMode(String callId, boolean isVoip) { |
| 244 | findConnectionForAction(callId, "setIsVoipAudioMode") |
| 245 | .setIsVoipAudioMode(isVoip); |
Sailesh Nepal | e7ef59a | 2014-07-08 21:48:22 -0700 | [diff] [blame] | 246 | } |
Sailesh Nepal | 6120386 | 2014-07-11 14:50:13 -0700 | [diff] [blame] | 247 | |
| 248 | @Override |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 249 | public void setStatusHints(String callId, StatusHints statusHints) { |
| 250 | findConnectionForAction(callId, "setStatusHints") |
| 251 | .setStatusHints(statusHints); |
Sailesh Nepal | 6120386 | 2014-07-11 14:50:13 -0700 | [diff] [blame] | 252 | } |
| 253 | |
| 254 | @Override |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 255 | public void setAddress(String callId, Uri address, int presentation) { |
| 256 | findConnectionForAction(callId, "setAddress") |
| 257 | .setAddress(address, presentation); |
Sailesh Nepal | 6120386 | 2014-07-11 14:50:13 -0700 | [diff] [blame] | 258 | } |
Sailesh Nepal | 2ab88cc | 2014-07-18 14:49:18 -0700 | [diff] [blame] | 259 | |
| 260 | @Override |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 261 | public void setCallerDisplayName(String callId, String callerDisplayName, |
| 262 | int presentation) { |
| 263 | findConnectionForAction(callId, "setCallerDisplayName") |
| 264 | .setCallerDisplayName(callerDisplayName, presentation); |
| 265 | } |
| 266 | |
| 267 | @Override |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 268 | public IBinder asBinder() { |
| 269 | throw new UnsupportedOperationException(); |
Sailesh Nepal | 2ab88cc | 2014-07-18 14:49:18 -0700 | [diff] [blame] | 270 | } |
Santos Cordon | 7c7bc7f | 2014-07-28 18:15:48 -0700 | [diff] [blame] | 271 | |
| 272 | @Override |
| 273 | public final void setConferenceableConnections( |
| 274 | String callId, List<String> conferenceableConnectionIds) { |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 275 | List<RemoteConnection> conferenceable = new ArrayList<>(); |
| 276 | for (String id : conferenceableConnectionIds) { |
| 277 | if (mConnectionById.containsKey(id)) { |
| 278 | conferenceable.add(mConnectionById.get(id)); |
| 279 | } |
| 280 | } |
Santos Cordon | 7c7bc7f | 2014-07-28 18:15:48 -0700 | [diff] [blame] | 281 | |
Ihab Awad | 50e3506 | 2014-09-30 09:17:03 -0700 | [diff] [blame] | 282 | if (hasConnection(callId)) { |
| 283 | findConnectionForAction(callId, "setConferenceableConnections") |
| 284 | .setConferenceableConnections(conferenceable); |
| 285 | } else { |
| 286 | findConferenceForAction(callId, "setConferenceableConnections") |
| 287 | .setConferenceableConnections(conferenceable); |
| 288 | } |
Santos Cordon | 7c7bc7f | 2014-07-28 18:15:48 -0700 | [diff] [blame] | 289 | } |
Tyler Gunn | 4a57b9b | 2014-10-30 14:27:48 -0700 | [diff] [blame^] | 290 | |
| 291 | @Override |
| 292 | public void addExistingConnection(String callId, ParcelableConnection connection) { |
| 293 | // TODO: add contents of this method |
| 294 | RemoteConnection remoteConnction = new RemoteConnection(callId, |
| 295 | mOutgoingConnectionServiceRpc, connection); |
| 296 | |
| 297 | mOurConnectionServiceImpl.addRemoteExistingConnection(remoteConnction); |
| 298 | } |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 299 | }; |
| 300 | |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 301 | private final ConnectionServiceAdapterServant mServant = |
| 302 | new ConnectionServiceAdapterServant(mServantDelegate); |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 303 | |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 304 | private final DeathRecipient mDeathRecipient = new DeathRecipient() { |
| 305 | @Override |
| 306 | public void binderDied() { |
| 307 | for (RemoteConnection c : mConnectionById.values()) { |
| 308 | c.setDestroyed(); |
| 309 | } |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 310 | for (RemoteConference c : mConferenceById.values()) { |
| 311 | c.setDestroyed(); |
| 312 | } |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 313 | mConnectionById.clear(); |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 314 | mConferenceById.clear(); |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 315 | mPendingConnections.clear(); |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 316 | mOutgoingConnectionServiceRpc.asBinder().unlinkToDeath(mDeathRecipient, 0); |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 317 | } |
| 318 | }; |
| 319 | |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 320 | private final IConnectionService mOutgoingConnectionServiceRpc; |
| 321 | private final ConnectionService mOurConnectionServiceImpl; |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 322 | private final Map<String, RemoteConnection> mConnectionById = new HashMap<>(); |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 323 | private final Map<String, RemoteConference> mConferenceById = new HashMap<>(); |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 324 | private final Set<RemoteConnection> mPendingConnections = new HashSet<>(); |
| 325 | |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 326 | RemoteConnectionService( |
| 327 | IConnectionService outgoingConnectionServiceRpc, |
| 328 | ConnectionService ourConnectionServiceImpl) throws RemoteException { |
| 329 | mOutgoingConnectionServiceRpc = outgoingConnectionServiceRpc; |
| 330 | mOutgoingConnectionServiceRpc.asBinder().linkToDeath(mDeathRecipient, 0); |
| 331 | mOurConnectionServiceImpl = ourConnectionServiceImpl; |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 332 | } |
| 333 | |
| 334 | @Override |
| 335 | public String toString() { |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 336 | return "[RemoteCS - " + mOutgoingConnectionServiceRpc.asBinder().toString() + "]"; |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 337 | } |
| 338 | |
Ihab Awad | f8b6988 | 2014-07-25 15:14:01 -0700 | [diff] [blame] | 339 | final RemoteConnection createRemoteConnection( |
| 340 | PhoneAccountHandle connectionManagerPhoneAccount, |
| 341 | ConnectionRequest request, |
| 342 | boolean isIncoming) { |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 343 | final String id = UUID.randomUUID().toString(); |
Ihab Awad | 8aecfed | 2014-08-08 17:06:11 -0700 | [diff] [blame] | 344 | final ConnectionRequest newRequest = new ConnectionRequest( |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 345 | request.getAccountHandle(), |
Nancy Chen | ea38cca | 2014-09-05 16:38:49 -0700 | [diff] [blame] | 346 | request.getAddress(), |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 347 | request.getExtras(), |
| 348 | request.getVideoState()); |
| 349 | try { |
Ihab Awad | 8aecfed | 2014-08-08 17:06:11 -0700 | [diff] [blame] | 350 | if (mConnectionById.isEmpty()) { |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 351 | mOutgoingConnectionServiceRpc.addConnectionServiceAdapter(mServant.getStub()); |
Ihab Awad | 8aecfed | 2014-08-08 17:06:11 -0700 | [diff] [blame] | 352 | } |
| 353 | RemoteConnection connection = |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 354 | new RemoteConnection(id, mOutgoingConnectionServiceRpc, newRequest); |
Ihab Awad | 8aecfed | 2014-08-08 17:06:11 -0700 | [diff] [blame] | 355 | mPendingConnections.add(connection); |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 356 | mConnectionById.put(id, connection); |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 357 | mOutgoingConnectionServiceRpc.createConnection( |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 358 | connectionManagerPhoneAccount, |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 359 | id, |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 360 | newRequest, |
Yorke Lee | c3cf982 | 2014-10-02 09:38:39 -0700 | [diff] [blame] | 361 | isIncoming, |
| 362 | false /* isUnknownCall */); |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 363 | connection.registerCallback(new RemoteConnection.Callback() { |
Ihab Awad | 8aecfed | 2014-08-08 17:06:11 -0700 | [diff] [blame] | 364 | @Override |
| 365 | public void onDestroyed(RemoteConnection connection) { |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 366 | mConnectionById.remove(id); |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 367 | maybeDisconnectAdapter(); |
Ihab Awad | 8aecfed | 2014-08-08 17:06:11 -0700 | [diff] [blame] | 368 | } |
| 369 | }); |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 370 | return connection; |
| 371 | } catch (RemoteException e) { |
Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame] | 372 | return RemoteConnection.failure( |
| 373 | new DisconnectCause(DisconnectCause.ERROR, e.toString())); |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 374 | } |
| 375 | } |
| 376 | |
Ihab Awad | 50e3506 | 2014-09-30 09:17:03 -0700 | [diff] [blame] | 377 | private boolean hasConnection(String callId) { |
mike dooley | 879142b | 2014-10-08 13:39:28 -0700 | [diff] [blame] | 378 | return mConnectionById.containsKey(callId); |
Ihab Awad | 50e3506 | 2014-09-30 09:17:03 -0700 | [diff] [blame] | 379 | } |
| 380 | |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 381 | private RemoteConnection findConnectionForAction( |
| 382 | String callId, String action) { |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 383 | if (mConnectionById.containsKey(callId)) { |
| 384 | return mConnectionById.get(callId); |
| 385 | } |
| 386 | Log.w(this, "%s - Cannot find Connection %s", action, callId); |
| 387 | return NULL_CONNECTION; |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 388 | } |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 389 | |
| 390 | private RemoteConference findConferenceForAction( |
| 391 | String callId, String action) { |
| 392 | if (mConferenceById.containsKey(callId)) { |
| 393 | return mConferenceById.get(callId); |
| 394 | } |
| 395 | Log.w(this, "%s - Cannot find Conference %s", action, callId); |
| 396 | return NULL_CONFERENCE; |
| 397 | } |
| 398 | |
| 399 | private void maybeDisconnectAdapter() { |
| 400 | if (mConnectionById.isEmpty() && mConferenceById.isEmpty()) { |
| 401 | try { |
| 402 | mOutgoingConnectionServiceRpc.removeConnectionServiceAdapter(mServant.getStub()); |
| 403 | } catch (RemoteException e) { |
| 404 | } |
| 405 | } |
| 406 | } |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 407 | } |