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 | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 62 | connection.setConnectionCapabilities(parcel.getConnectionCapabilities()); |
Sailesh Nepal | 2d3ced7 | 2015-01-31 20:17:35 -0800 | [diff] [blame] | 63 | 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 Nepal | 70638f1 | 2014-09-09 21:49:14 -0700 | [diff] [blame] | 73 | // Set state after handle so that the client can identify the connection. |
Sailesh Nepal | c2a978d | 2014-09-20 18:23:05 -0700 | [diff] [blame] | 74 | if (parcel.getState() == Connection.STATE_DISCONNECTED) { |
| 75 | connection.setDisconnected(parcel.getDisconnectCause()); |
| 76 | } else { |
| 77 | connection.setState(parcel.getState()); |
| 78 | } |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 79 | 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 Awad | a64627c | 2014-08-20 09:36:40 -0700 | [diff] [blame] | 86 | connection.setVideoState(parcel.getVideoState()); |
Rekha Kumar | 0736681 | 2015-03-24 16:42:31 -0700 | [diff] [blame] | 87 | connection.setCallSubstate(parcel.getCallSubstate()); |
Ihab Awad | 6107bab | 2014-08-18 09:23:25 -0700 | [diff] [blame] | 88 | 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 Nepal | 4803159 | 2014-07-18 14:21:23 -0700 | [diff] [blame] | 93 | } |
| 94 | } |
Sailesh Nepal | 2ab88cc | 2014-07-18 14:49:18 -0700 | [diff] [blame] | 95 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 96 | @Override |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 97 | public void setActive(String callId) { |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 98 | 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 Cordon | 52d8a15 | 2014-06-17 19:08:45 -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 setRinging(String callId) { |
| 109 | findConnectionForAction(callId, "setRinging") |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 110 | .setState(Connection.STATE_RINGING); |
Andrew Lee | 5ffbe8b | 2014-06-20 16:29:33 -0700 | [diff] [blame] | 111 | } |
| 112 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 113 | @Override |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 114 | public void setDialing(String callId) { |
| 115 | findConnectionForAction(callId, "setDialing") |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 116 | .setState(Connection.STATE_DIALING); |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 117 | } |
| 118 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 119 | @Override |
Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame] | 120 | public void setDisconnected(String callId, DisconnectCause disconnectCause) { |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 121 | if (mConnectionById.containsKey(callId)) { |
| 122 | findConnectionForAction(callId, "setDisconnected") |
Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame] | 123 | .setDisconnected(disconnectCause); |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 124 | } else { |
| 125 | findConferenceForAction(callId, "setDisconnected") |
Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame] | 126 | .setDisconnected(disconnectCause); |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 127 | } |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 128 | } |
| 129 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 130 | @Override |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 131 | public void setOnHold(String callId) { |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 132 | 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 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 |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 142 | public void setRingbackRequested(String callId, boolean ringing) { |
| 143 | findConnectionForAction(callId, "setRingbackRequested") |
| 144 | .setRingbackRequested(ringing); |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 145 | } |
| 146 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 147 | @Override |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 148 | public void setConnectionCapabilities(String callId, int connectionCapabilities) { |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 149 | if (mConnectionById.containsKey(callId)) { |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 150 | findConnectionForAction(callId, "setConnectionCapabilities") |
| 151 | .setConnectionCapabilities(connectionCapabilities); |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 152 | } else { |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 153 | findConferenceForAction(callId, "setConnectionCapabilities") |
| 154 | .setConnectionCapabilities(connectionCapabilities); |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 155 | } |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 156 | } |
| 157 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 158 | @Override |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 159 | public void setIsConferenced(String callId, String conferenceCallId) { |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 160 | // 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 Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 177 | } |
| 178 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 179 | @Override |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 180 | 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 Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 201 | conference.setConnectionCapabilities(parcel.getConnectionCapabilities()); |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 202 | mConferenceById.put(callId, conference); |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 203 | conference.registerCallback(new RemoteConference.Callback() { |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 204 | @Override |
| 205 | public void onDestroyed(RemoteConference c) { |
| 206 | mConferenceById.remove(callId); |
| 207 | maybeDisconnectAdapter(); |
| 208 | } |
| 209 | }); |
| 210 | |
| 211 | mOurConnectionServiceImpl.addRemoteConference(conference); |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 212 | } |
| 213 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 214 | @Override |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 215 | public void removeCall(String callId) { |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 216 | if (mConnectionById.containsKey(callId)) { |
| 217 | findConnectionForAction(callId, "removeCall") |
| 218 | .setDestroyed(); |
| 219 | } else { |
| 220 | findConferenceForAction(callId, "removeCall") |
| 221 | .setDestroyed(); |
| 222 | } |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 223 | } |
| 224 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 225 | @Override |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 226 | public void onPostDialWait(String callId, String remaining) { |
| 227 | findConnectionForAction(callId, "onPostDialWait") |
| 228 | .setPostDialWait(remaining); |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 229 | } |
| 230 | |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 231 | @Override |
Nancy Chen | 27d1c2d | 2014-12-15 16:12:50 -0800 | [diff] [blame] | 232 | public void onPostDialChar(String callId, char nextChar) { |
| 233 | findConnectionForAction(callId, "onPostDialChar") |
| 234 | .onPostDialChar(nextChar); |
| 235 | } |
| 236 | |
| 237 | @Override |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 238 | public void queryRemoteConnectionServices(RemoteServiceCallback callback) { |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 239 | // Not supported from remote connection service. |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 240 | } |
Tyler Gunn | 8d83fa9 | 2014-07-01 11:31:21 -0700 | [diff] [blame] | 241 | |
Sailesh Nepal | 33aaae4 | 2014-07-07 22:49:44 -0700 | [diff] [blame] | 242 | @Override |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 243 | public void setVideoProvider(String callId, IVideoProvider videoProvider) { |
Sailesh Nepal | 11aeae5 | 2015-01-28 16:54:09 -0800 | [diff] [blame] | 244 | RemoteConnection.VideoProvider remoteVideoProvider = null; |
| 245 | if (videoProvider != null) { |
| 246 | remoteVideoProvider = new RemoteConnection.VideoProvider(videoProvider); |
| 247 | } |
Ihab Awad | a64627c | 2014-08-20 09:36:40 -0700 | [diff] [blame] | 248 | findConnectionForAction(callId, "setVideoProvider") |
Sailesh Nepal | 11aeae5 | 2015-01-28 16:54:09 -0800 | [diff] [blame] | 249 | .setVideoProvider(remoteVideoProvider); |
Tyler Gunn | aa07df8 | 2014-07-17 07:50:22 -0700 | [diff] [blame] | 250 | } |
| 251 | |
| 252 | @Override |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 253 | public void setVideoState(String callId, int videoState) { |
| 254 | findConnectionForAction(callId, "setVideoState") |
| 255 | .setVideoState(videoState); |
Sailesh Nepal | 33aaae4 | 2014-07-07 22:49:44 -0700 | [diff] [blame] | 256 | } |
Sailesh Nepal | e7ef59a | 2014-07-08 21:48:22 -0700 | [diff] [blame] | 257 | |
Sailesh Nepal | e7ef59a | 2014-07-08 21:48:22 -0700 | [diff] [blame] | 258 | @Override |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 259 | public void setIsVoipAudioMode(String callId, boolean isVoip) { |
| 260 | findConnectionForAction(callId, "setIsVoipAudioMode") |
| 261 | .setIsVoipAudioMode(isVoip); |
Sailesh Nepal | e7ef59a | 2014-07-08 21:48:22 -0700 | [diff] [blame] | 262 | } |
Sailesh Nepal | 6120386 | 2014-07-11 14:50:13 -0700 | [diff] [blame] | 263 | |
| 264 | @Override |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 265 | public void setStatusHints(String callId, StatusHints statusHints) { |
| 266 | findConnectionForAction(callId, "setStatusHints") |
| 267 | .setStatusHints(statusHints); |
Sailesh Nepal | 6120386 | 2014-07-11 14:50:13 -0700 | [diff] [blame] | 268 | } |
| 269 | |
| 270 | @Override |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 271 | public void setAddress(String callId, Uri address, int presentation) { |
| 272 | findConnectionForAction(callId, "setAddress") |
| 273 | .setAddress(address, presentation); |
Sailesh Nepal | 6120386 | 2014-07-11 14:50:13 -0700 | [diff] [blame] | 274 | } |
Sailesh Nepal | 2ab88cc | 2014-07-18 14:49:18 -0700 | [diff] [blame] | 275 | |
| 276 | @Override |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 277 | public void setCallerDisplayName(String callId, String callerDisplayName, |
| 278 | int presentation) { |
| 279 | findConnectionForAction(callId, "setCallerDisplayName") |
| 280 | .setCallerDisplayName(callerDisplayName, presentation); |
| 281 | } |
| 282 | |
| 283 | @Override |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 284 | public IBinder asBinder() { |
| 285 | throw new UnsupportedOperationException(); |
Sailesh Nepal | 2ab88cc | 2014-07-18 14:49:18 -0700 | [diff] [blame] | 286 | } |
Santos Cordon | 7c7bc7f | 2014-07-28 18:15:48 -0700 | [diff] [blame] | 287 | |
| 288 | @Override |
| 289 | public final void setConferenceableConnections( |
| 290 | String callId, List<String> conferenceableConnectionIds) { |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 291 | List<RemoteConnection> conferenceable = new ArrayList<>(); |
| 292 | for (String id : conferenceableConnectionIds) { |
| 293 | if (mConnectionById.containsKey(id)) { |
| 294 | conferenceable.add(mConnectionById.get(id)); |
| 295 | } |
| 296 | } |
Santos Cordon | 7c7bc7f | 2014-07-28 18:15:48 -0700 | [diff] [blame] | 297 | |
Ihab Awad | 50e3506 | 2014-09-30 09:17:03 -0700 | [diff] [blame] | 298 | if (hasConnection(callId)) { |
| 299 | findConnectionForAction(callId, "setConferenceableConnections") |
| 300 | .setConferenceableConnections(conferenceable); |
| 301 | } else { |
| 302 | findConferenceForAction(callId, "setConferenceableConnections") |
| 303 | .setConferenceableConnections(conferenceable); |
| 304 | } |
Santos Cordon | 7c7bc7f | 2014-07-28 18:15:48 -0700 | [diff] [blame] | 305 | } |
Tyler Gunn | 4a57b9b | 2014-10-30 14:27:48 -0700 | [diff] [blame] | 306 | |
| 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 Kumar | 0736681 | 2015-03-24 16:42:31 -0700 | [diff] [blame] | 315 | |
| 316 | @Override |
| 317 | public void setCallSubstate(String callId, int callSubstate) { |
| 318 | findConnectionForAction(callId, "callSubstate") |
| 319 | .setCallSubstate(callSubstate); |
| 320 | } |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 321 | }; |
| 322 | |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 323 | private final ConnectionServiceAdapterServant mServant = |
| 324 | new ConnectionServiceAdapterServant(mServantDelegate); |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 325 | |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 326 | private final DeathRecipient mDeathRecipient = new DeathRecipient() { |
| 327 | @Override |
| 328 | public void binderDied() { |
| 329 | for (RemoteConnection c : mConnectionById.values()) { |
| 330 | c.setDestroyed(); |
| 331 | } |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 332 | for (RemoteConference c : mConferenceById.values()) { |
| 333 | c.setDestroyed(); |
| 334 | } |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 335 | mConnectionById.clear(); |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 336 | mConferenceById.clear(); |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 337 | mPendingConnections.clear(); |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 338 | mOutgoingConnectionServiceRpc.asBinder().unlinkToDeath(mDeathRecipient, 0); |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 339 | } |
| 340 | }; |
| 341 | |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 342 | private final IConnectionService mOutgoingConnectionServiceRpc; |
| 343 | private final ConnectionService mOurConnectionServiceImpl; |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 344 | private final Map<String, RemoteConnection> mConnectionById = new HashMap<>(); |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 345 | private final Map<String, RemoteConference> mConferenceById = new HashMap<>(); |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 346 | private final Set<RemoteConnection> mPendingConnections = new HashSet<>(); |
| 347 | |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 348 | RemoteConnectionService( |
| 349 | IConnectionService outgoingConnectionServiceRpc, |
| 350 | ConnectionService ourConnectionServiceImpl) throws RemoteException { |
| 351 | mOutgoingConnectionServiceRpc = outgoingConnectionServiceRpc; |
| 352 | mOutgoingConnectionServiceRpc.asBinder().linkToDeath(mDeathRecipient, 0); |
| 353 | mOurConnectionServiceImpl = ourConnectionServiceImpl; |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 354 | } |
| 355 | |
| 356 | @Override |
| 357 | public String toString() { |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 358 | return "[RemoteCS - " + mOutgoingConnectionServiceRpc.asBinder().toString() + "]"; |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 359 | } |
| 360 | |
Ihab Awad | f8b6988 | 2014-07-25 15:14:01 -0700 | [diff] [blame] | 361 | final RemoteConnection createRemoteConnection( |
| 362 | PhoneAccountHandle connectionManagerPhoneAccount, |
| 363 | ConnectionRequest request, |
| 364 | boolean isIncoming) { |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 365 | final String id = UUID.randomUUID().toString(); |
Ihab Awad | 8aecfed | 2014-08-08 17:06:11 -0700 | [diff] [blame] | 366 | final ConnectionRequest newRequest = new ConnectionRequest( |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 367 | request.getAccountHandle(), |
Nancy Chen | ea38cca | 2014-09-05 16:38:49 -0700 | [diff] [blame] | 368 | request.getAddress(), |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 369 | request.getExtras(), |
| 370 | request.getVideoState()); |
| 371 | try { |
Ihab Awad | 8aecfed | 2014-08-08 17:06:11 -0700 | [diff] [blame] | 372 | if (mConnectionById.isEmpty()) { |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 373 | mOutgoingConnectionServiceRpc.addConnectionServiceAdapter(mServant.getStub()); |
Ihab Awad | 8aecfed | 2014-08-08 17:06:11 -0700 | [diff] [blame] | 374 | } |
| 375 | RemoteConnection connection = |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 376 | new RemoteConnection(id, mOutgoingConnectionServiceRpc, newRequest); |
Ihab Awad | 8aecfed | 2014-08-08 17:06:11 -0700 | [diff] [blame] | 377 | mPendingConnections.add(connection); |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 378 | mConnectionById.put(id, connection); |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 379 | mOutgoingConnectionServiceRpc.createConnection( |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 380 | connectionManagerPhoneAccount, |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 381 | id, |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 382 | newRequest, |
Yorke Lee | c3cf982 | 2014-10-02 09:38:39 -0700 | [diff] [blame] | 383 | isIncoming, |
| 384 | false /* isUnknownCall */); |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 385 | connection.registerCallback(new RemoteConnection.Callback() { |
Ihab Awad | 8aecfed | 2014-08-08 17:06:11 -0700 | [diff] [blame] | 386 | @Override |
| 387 | public void onDestroyed(RemoteConnection connection) { |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 388 | mConnectionById.remove(id); |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 389 | maybeDisconnectAdapter(); |
Ihab Awad | 8aecfed | 2014-08-08 17:06:11 -0700 | [diff] [blame] | 390 | } |
| 391 | }); |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 392 | return connection; |
| 393 | } catch (RemoteException e) { |
Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame] | 394 | return RemoteConnection.failure( |
| 395 | new DisconnectCause(DisconnectCause.ERROR, e.toString())); |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 396 | } |
| 397 | } |
| 398 | |
Ihab Awad | 50e3506 | 2014-09-30 09:17:03 -0700 | [diff] [blame] | 399 | private boolean hasConnection(String callId) { |
mike dooley | 879142b | 2014-10-08 13:39:28 -0700 | [diff] [blame] | 400 | return mConnectionById.containsKey(callId); |
Ihab Awad | 50e3506 | 2014-09-30 09:17:03 -0700 | [diff] [blame] | 401 | } |
| 402 | |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 403 | private RemoteConnection findConnectionForAction( |
| 404 | String callId, String action) { |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 405 | 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 Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 410 | } |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 411 | |
| 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 Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 429 | } |