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; |
Santos Cordon | 6b7f955 | 2015-05-27 17:21:45 -0700 | [diff] [blame] | 20 | import android.os.Bundle; |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 21 | import android.os.IBinder; |
Santos Cordon | e8dc4be | 2014-07-21 01:28:28 -0700 | [diff] [blame] | 22 | import android.os.IBinder.DeathRecipient; |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 23 | import android.os.RemoteException; |
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 | |
Tyler Gunn | 4a57b9b | 2014-10-30 14:27:48 -0700 | [diff] [blame] | 45 | // Note: Casting null to avoid ambiguous constructor reference. |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 46 | private static final RemoteConnection NULL_CONNECTION = |
Tyler Gunn | 4a57b9b | 2014-10-30 14:27:48 -0700 | [diff] [blame] | 47 | new RemoteConnection("NULL", null, (ConnectionRequest) null); |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 48 | |
| 49 | private static final RemoteConference NULL_CONFERENCE = |
| 50 | new RemoteConference("NULL", null); |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 51 | |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 52 | private final IConnectionServiceAdapter mServantDelegate = new IConnectionServiceAdapter() { |
Sailesh Nepal | 4803159 | 2014-07-18 14:21:23 -0700 | [diff] [blame] | 53 | @Override |
Ihab Awad | 6107bab | 2014-08-18 09:23:25 -0700 | [diff] [blame] | 54 | public void handleCreateConnectionComplete( |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 55 | String id, |
| 56 | ConnectionRequest request, |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 57 | ParcelableConnection parcel) { |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 58 | RemoteConnection connection = |
| 59 | findConnectionForAction(id, "handleCreateConnectionSuccessful"); |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 60 | if (connection != NULL_CONNECTION && mPendingConnections.contains(connection)) { |
| 61 | mPendingConnections.remove(connection); |
Ihab Awad | 6107bab | 2014-08-18 09:23:25 -0700 | [diff] [blame] | 62 | // Unconditionally initialize the connection ... |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 63 | connection.setConnectionCapabilities(parcel.getConnectionCapabilities()); |
Tyler Gunn | 720c664 | 2016-03-22 09:02:47 -0700 | [diff] [blame^] | 64 | connection.setConnectionProperties(parcel.getConnectionProperties()); |
Sailesh Nepal | 2d3ced7 | 2015-01-31 20:17:35 -0800 | [diff] [blame] | 65 | if (parcel.getHandle() != null |
| 66 | || parcel.getState() != Connection.STATE_DISCONNECTED) { |
| 67 | connection.setAddress(parcel.getHandle(), parcel.getHandlePresentation()); |
| 68 | } |
| 69 | if (parcel.getCallerDisplayName() != null |
| 70 | || parcel.getState() != Connection.STATE_DISCONNECTED) { |
| 71 | connection.setCallerDisplayName( |
| 72 | parcel.getCallerDisplayName(), |
| 73 | parcel.getCallerDisplayNamePresentation()); |
| 74 | } |
Sailesh Nepal | 70638f1 | 2014-09-09 21:49:14 -0700 | [diff] [blame] | 75 | // Set state after handle so that the client can identify the connection. |
Sailesh Nepal | c2a978d | 2014-09-20 18:23:05 -0700 | [diff] [blame] | 76 | if (parcel.getState() == Connection.STATE_DISCONNECTED) { |
| 77 | connection.setDisconnected(parcel.getDisconnectCause()); |
| 78 | } else { |
| 79 | connection.setState(parcel.getState()); |
| 80 | } |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 81 | List<RemoteConnection> conferenceable = new ArrayList<>(); |
| 82 | for (String confId : parcel.getConferenceableConnectionIds()) { |
| 83 | if (mConnectionById.containsKey(confId)) { |
| 84 | conferenceable.add(mConnectionById.get(confId)); |
| 85 | } |
| 86 | } |
| 87 | connection.setConferenceableConnections(conferenceable); |
Ihab Awad | a64627c | 2014-08-20 09:36:40 -0700 | [diff] [blame] | 88 | connection.setVideoState(parcel.getVideoState()); |
Ihab Awad | 6107bab | 2014-08-18 09:23:25 -0700 | [diff] [blame] | 89 | if (connection.getState() == Connection.STATE_DISCONNECTED) { |
| 90 | // ... then, if it was created in a disconnected state, that indicates |
| 91 | // failure on the providing end, so immediately mark it destroyed |
| 92 | connection.setDestroyed(); |
| 93 | } |
Sailesh Nepal | 4803159 | 2014-07-18 14:21:23 -0700 | [diff] [blame] | 94 | } |
| 95 | } |
Sailesh Nepal | 2ab88cc | 2014-07-18 14:49:18 -0700 | [diff] [blame] | 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 setActive(String callId) { |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 99 | if (mConnectionById.containsKey(callId)) { |
| 100 | findConnectionForAction(callId, "setActive") |
| 101 | .setState(Connection.STATE_ACTIVE); |
| 102 | } else { |
| 103 | findConferenceForAction(callId, "setActive") |
| 104 | .setState(Connection.STATE_ACTIVE); |
| 105 | } |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 106 | } |
| 107 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 108 | @Override |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 109 | public void setRinging(String callId) { |
| 110 | findConnectionForAction(callId, "setRinging") |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 111 | .setState(Connection.STATE_RINGING); |
Andrew Lee | 5ffbe8b | 2014-06-20 16:29:33 -0700 | [diff] [blame] | 112 | } |
| 113 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 114 | @Override |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 115 | public void setDialing(String callId) { |
| 116 | findConnectionForAction(callId, "setDialing") |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 117 | .setState(Connection.STATE_DIALING); |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 118 | } |
| 119 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 120 | @Override |
Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame] | 121 | public void setDisconnected(String callId, DisconnectCause disconnectCause) { |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 122 | if (mConnectionById.containsKey(callId)) { |
| 123 | findConnectionForAction(callId, "setDisconnected") |
Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame] | 124 | .setDisconnected(disconnectCause); |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 125 | } else { |
| 126 | findConferenceForAction(callId, "setDisconnected") |
Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame] | 127 | .setDisconnected(disconnectCause); |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 128 | } |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 129 | } |
| 130 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 131 | @Override |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 132 | public void setOnHold(String callId) { |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 133 | if (mConnectionById.containsKey(callId)) { |
| 134 | findConnectionForAction(callId, "setOnHold") |
| 135 | .setState(Connection.STATE_HOLDING); |
| 136 | } else { |
| 137 | findConferenceForAction(callId, "setOnHold") |
| 138 | .setState(Connection.STATE_HOLDING); |
| 139 | } |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 140 | } |
| 141 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 142 | @Override |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 143 | public void setRingbackRequested(String callId, boolean ringing) { |
| 144 | findConnectionForAction(callId, "setRingbackRequested") |
| 145 | .setRingbackRequested(ringing); |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 146 | } |
| 147 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 148 | @Override |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 149 | public void setConnectionCapabilities(String callId, int connectionCapabilities) { |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 150 | if (mConnectionById.containsKey(callId)) { |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 151 | findConnectionForAction(callId, "setConnectionCapabilities") |
| 152 | .setConnectionCapabilities(connectionCapabilities); |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 153 | } else { |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 154 | findConferenceForAction(callId, "setConnectionCapabilities") |
| 155 | .setConnectionCapabilities(connectionCapabilities); |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 156 | } |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 157 | } |
| 158 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 159 | @Override |
Tyler Gunn | 720c664 | 2016-03-22 09:02:47 -0700 | [diff] [blame^] | 160 | public void setConnectionProperties(String callId, int connectionProperties) { |
| 161 | if (mConnectionById.containsKey(callId)) { |
| 162 | findConnectionForAction(callId, "setConnectionProperties") |
| 163 | .setConnectionProperties(connectionProperties); |
| 164 | } else { |
| 165 | findConferenceForAction(callId, "setConnectionProperties") |
| 166 | .setConnectionProperties(connectionProperties); |
| 167 | } |
| 168 | } |
| 169 | |
| 170 | @Override |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 171 | public void setIsConferenced(String callId, String conferenceCallId) { |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 172 | // Note: callId should not be null; conferenceCallId may be null |
| 173 | RemoteConnection connection = |
| 174 | findConnectionForAction(callId, "setIsConferenced"); |
| 175 | if (connection != NULL_CONNECTION) { |
| 176 | if (conferenceCallId == null) { |
| 177 | // 'connection' is being split from its conference |
| 178 | if (connection.getConference() != null) { |
| 179 | connection.getConference().removeConnection(connection); |
| 180 | } |
| 181 | } else { |
| 182 | RemoteConference conference = |
| 183 | findConferenceForAction(conferenceCallId, "setIsConferenced"); |
| 184 | if (conference != NULL_CONFERENCE) { |
| 185 | conference.addConnection(connection); |
| 186 | } |
| 187 | } |
| 188 | } |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 189 | } |
| 190 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 191 | @Override |
Anthony Lee | 17455a3 | 2015-04-24 15:25:29 -0700 | [diff] [blame] | 192 | public void setConferenceMergeFailed(String callId) { |
| 193 | // Nothing to do here. |
| 194 | // The event has already been handled and there is no state to update |
| 195 | // in the underlying connection or conference objects |
| 196 | } |
| 197 | |
| 198 | @Override |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 199 | public void addConferenceCall( |
| 200 | final String callId, |
| 201 | ParcelableConference parcel) { |
| 202 | RemoteConference conference = new RemoteConference(callId, |
| 203 | mOutgoingConnectionServiceRpc); |
| 204 | |
| 205 | for (String id : parcel.getConnectionIds()) { |
| 206 | RemoteConnection c = mConnectionById.get(id); |
| 207 | if (c != null) { |
| 208 | conference.addConnection(c); |
| 209 | } |
| 210 | } |
| 211 | |
| 212 | if (conference.getConnections().size() == 0) { |
| 213 | // A conference was created, but none of its connections are ones that have been |
| 214 | // created by, and therefore being tracked by, this remote connection service. It |
| 215 | // is of no interest to us. |
| 216 | return; |
| 217 | } |
| 218 | |
| 219 | conference.setState(parcel.getState()); |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 220 | conference.setConnectionCapabilities(parcel.getConnectionCapabilities()); |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 221 | mConferenceById.put(callId, conference); |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 222 | conference.registerCallback(new RemoteConference.Callback() { |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 223 | @Override |
| 224 | public void onDestroyed(RemoteConference c) { |
| 225 | mConferenceById.remove(callId); |
| 226 | maybeDisconnectAdapter(); |
| 227 | } |
| 228 | }); |
| 229 | |
| 230 | mOurConnectionServiceImpl.addRemoteConference(conference); |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 231 | } |
| 232 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 233 | @Override |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 234 | public void removeCall(String callId) { |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 235 | if (mConnectionById.containsKey(callId)) { |
| 236 | findConnectionForAction(callId, "removeCall") |
| 237 | .setDestroyed(); |
| 238 | } else { |
| 239 | findConferenceForAction(callId, "removeCall") |
| 240 | .setDestroyed(); |
| 241 | } |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 242 | } |
| 243 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 244 | @Override |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 245 | public void onPostDialWait(String callId, String remaining) { |
| 246 | findConnectionForAction(callId, "onPostDialWait") |
| 247 | .setPostDialWait(remaining); |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 248 | } |
| 249 | |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 250 | @Override |
Nancy Chen | 27d1c2d | 2014-12-15 16:12:50 -0800 | [diff] [blame] | 251 | public void onPostDialChar(String callId, char nextChar) { |
| 252 | findConnectionForAction(callId, "onPostDialChar") |
| 253 | .onPostDialChar(nextChar); |
| 254 | } |
| 255 | |
| 256 | @Override |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 257 | public void queryRemoteConnectionServices(RemoteServiceCallback callback) { |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 258 | // Not supported from remote connection service. |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 259 | } |
Tyler Gunn | 8d83fa9 | 2014-07-01 11:31:21 -0700 | [diff] [blame] | 260 | |
Sailesh Nepal | 33aaae4 | 2014-07-07 22:49:44 -0700 | [diff] [blame] | 261 | @Override |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 262 | public void setVideoProvider(String callId, IVideoProvider videoProvider) { |
Sailesh Nepal | 11aeae5 | 2015-01-28 16:54:09 -0800 | [diff] [blame] | 263 | RemoteConnection.VideoProvider remoteVideoProvider = null; |
| 264 | if (videoProvider != null) { |
| 265 | remoteVideoProvider = new RemoteConnection.VideoProvider(videoProvider); |
| 266 | } |
Ihab Awad | a64627c | 2014-08-20 09:36:40 -0700 | [diff] [blame] | 267 | findConnectionForAction(callId, "setVideoProvider") |
Sailesh Nepal | 11aeae5 | 2015-01-28 16:54:09 -0800 | [diff] [blame] | 268 | .setVideoProvider(remoteVideoProvider); |
Tyler Gunn | aa07df8 | 2014-07-17 07:50:22 -0700 | [diff] [blame] | 269 | } |
| 270 | |
| 271 | @Override |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 272 | public void setVideoState(String callId, int videoState) { |
| 273 | findConnectionForAction(callId, "setVideoState") |
| 274 | .setVideoState(videoState); |
Sailesh Nepal | 33aaae4 | 2014-07-07 22:49:44 -0700 | [diff] [blame] | 275 | } |
Sailesh Nepal | e7ef59a | 2014-07-08 21:48:22 -0700 | [diff] [blame] | 276 | |
Sailesh Nepal | e7ef59a | 2014-07-08 21:48:22 -0700 | [diff] [blame] | 277 | @Override |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 278 | public void setIsVoipAudioMode(String callId, boolean isVoip) { |
| 279 | findConnectionForAction(callId, "setIsVoipAudioMode") |
| 280 | .setIsVoipAudioMode(isVoip); |
Sailesh Nepal | e7ef59a | 2014-07-08 21:48:22 -0700 | [diff] [blame] | 281 | } |
Sailesh Nepal | 6120386 | 2014-07-11 14:50:13 -0700 | [diff] [blame] | 282 | |
| 283 | @Override |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 284 | public void setStatusHints(String callId, StatusHints statusHints) { |
| 285 | findConnectionForAction(callId, "setStatusHints") |
| 286 | .setStatusHints(statusHints); |
Sailesh Nepal | 6120386 | 2014-07-11 14:50:13 -0700 | [diff] [blame] | 287 | } |
| 288 | |
| 289 | @Override |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 290 | public void setAddress(String callId, Uri address, int presentation) { |
| 291 | findConnectionForAction(callId, "setAddress") |
| 292 | .setAddress(address, presentation); |
Sailesh Nepal | 6120386 | 2014-07-11 14:50:13 -0700 | [diff] [blame] | 293 | } |
Sailesh Nepal | 2ab88cc | 2014-07-18 14:49:18 -0700 | [diff] [blame] | 294 | |
| 295 | @Override |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 296 | public void setCallerDisplayName(String callId, String callerDisplayName, |
| 297 | int presentation) { |
| 298 | findConnectionForAction(callId, "setCallerDisplayName") |
| 299 | .setCallerDisplayName(callerDisplayName, presentation); |
| 300 | } |
| 301 | |
| 302 | @Override |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 303 | public IBinder asBinder() { |
| 304 | throw new UnsupportedOperationException(); |
Sailesh Nepal | 2ab88cc | 2014-07-18 14:49:18 -0700 | [diff] [blame] | 305 | } |
Santos Cordon | 7c7bc7f | 2014-07-28 18:15:48 -0700 | [diff] [blame] | 306 | |
| 307 | @Override |
| 308 | public final void setConferenceableConnections( |
| 309 | String callId, List<String> conferenceableConnectionIds) { |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 310 | List<RemoteConnection> conferenceable = new ArrayList<>(); |
| 311 | for (String id : conferenceableConnectionIds) { |
| 312 | if (mConnectionById.containsKey(id)) { |
| 313 | conferenceable.add(mConnectionById.get(id)); |
| 314 | } |
| 315 | } |
Santos Cordon | 7c7bc7f | 2014-07-28 18:15:48 -0700 | [diff] [blame] | 316 | |
Ihab Awad | 50e3506 | 2014-09-30 09:17:03 -0700 | [diff] [blame] | 317 | if (hasConnection(callId)) { |
| 318 | findConnectionForAction(callId, "setConferenceableConnections") |
| 319 | .setConferenceableConnections(conferenceable); |
| 320 | } else { |
| 321 | findConferenceForAction(callId, "setConferenceableConnections") |
| 322 | .setConferenceableConnections(conferenceable); |
| 323 | } |
Santos Cordon | 7c7bc7f | 2014-07-28 18:15:48 -0700 | [diff] [blame] | 324 | } |
Tyler Gunn | 4a57b9b | 2014-10-30 14:27:48 -0700 | [diff] [blame] | 325 | |
| 326 | @Override |
| 327 | public void addExistingConnection(String callId, ParcelableConnection connection) { |
| 328 | // TODO: add contents of this method |
| 329 | RemoteConnection remoteConnction = new RemoteConnection(callId, |
| 330 | mOutgoingConnectionServiceRpc, connection); |
| 331 | |
| 332 | mOurConnectionServiceImpl.addRemoteExistingConnection(remoteConnction); |
| 333 | } |
Santos Cordon | 6b7f955 | 2015-05-27 17:21:45 -0700 | [diff] [blame] | 334 | |
| 335 | @Override |
Tyler Gunn | dee56a8 | 2016-03-23 16:06:34 -0700 | [diff] [blame] | 336 | public void putExtras(String callId, Bundle extras) { |
| 337 | if (hasConnection(callId)) { |
| 338 | findConnectionForAction(callId, "putExtras").putExtras(extras); |
Santos Cordon | 6b7f955 | 2015-05-27 17:21:45 -0700 | [diff] [blame] | 339 | } else { |
Tyler Gunn | dee56a8 | 2016-03-23 16:06:34 -0700 | [diff] [blame] | 340 | findConferenceForAction(callId, "putExtras").putExtras(extras); |
| 341 | } |
| 342 | } |
| 343 | |
| 344 | @Override |
| 345 | public void removeExtras(String callId, List<String> keys) { |
| 346 | if (hasConnection(callId)) { |
| 347 | findConnectionForAction(callId, "removeExtra").removeExtras(keys); |
| 348 | } else { |
| 349 | findConferenceForAction(callId, "removeExtra").removeExtras(keys); |
Santos Cordon | 6b7f955 | 2015-05-27 17:21:45 -0700 | [diff] [blame] | 350 | } |
| 351 | } |
Tyler Gunn | bd1eb1f | 2016-02-16 14:36:20 -0800 | [diff] [blame] | 352 | |
| 353 | @Override |
Tyler Gunn | 876dbfb | 2016-03-14 15:18:07 -0700 | [diff] [blame] | 354 | public void onConnectionEvent(String callId, String event, Bundle extras) { |
Tyler Gunn | bd1eb1f | 2016-02-16 14:36:20 -0800 | [diff] [blame] | 355 | if (mConnectionById.containsKey(callId)) { |
Tyler Gunn | 876dbfb | 2016-03-14 15:18:07 -0700 | [diff] [blame] | 356 | findConnectionForAction(callId, "onConnectionEvent").onConnectionEvent(event, |
| 357 | extras); |
Tyler Gunn | bd1eb1f | 2016-02-16 14:36:20 -0800 | [diff] [blame] | 358 | } |
| 359 | } |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 360 | }; |
| 361 | |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 362 | private final ConnectionServiceAdapterServant mServant = |
| 363 | new ConnectionServiceAdapterServant(mServantDelegate); |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 364 | |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 365 | private final DeathRecipient mDeathRecipient = new DeathRecipient() { |
| 366 | @Override |
| 367 | public void binderDied() { |
| 368 | for (RemoteConnection c : mConnectionById.values()) { |
| 369 | c.setDestroyed(); |
| 370 | } |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 371 | for (RemoteConference c : mConferenceById.values()) { |
| 372 | c.setDestroyed(); |
| 373 | } |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 374 | mConnectionById.clear(); |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 375 | mConferenceById.clear(); |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 376 | mPendingConnections.clear(); |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 377 | mOutgoingConnectionServiceRpc.asBinder().unlinkToDeath(mDeathRecipient, 0); |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 378 | } |
| 379 | }; |
| 380 | |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 381 | private final IConnectionService mOutgoingConnectionServiceRpc; |
| 382 | private final ConnectionService mOurConnectionServiceImpl; |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 383 | private final Map<String, RemoteConnection> mConnectionById = new HashMap<>(); |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 384 | private final Map<String, RemoteConference> mConferenceById = new HashMap<>(); |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 385 | private final Set<RemoteConnection> mPendingConnections = new HashSet<>(); |
| 386 | |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 387 | RemoteConnectionService( |
| 388 | IConnectionService outgoingConnectionServiceRpc, |
| 389 | ConnectionService ourConnectionServiceImpl) throws RemoteException { |
| 390 | mOutgoingConnectionServiceRpc = outgoingConnectionServiceRpc; |
| 391 | mOutgoingConnectionServiceRpc.asBinder().linkToDeath(mDeathRecipient, 0); |
| 392 | mOurConnectionServiceImpl = ourConnectionServiceImpl; |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 393 | } |
| 394 | |
| 395 | @Override |
| 396 | public String toString() { |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 397 | return "[RemoteCS - " + mOutgoingConnectionServiceRpc.asBinder().toString() + "]"; |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 398 | } |
| 399 | |
Ihab Awad | f8b6988 | 2014-07-25 15:14:01 -0700 | [diff] [blame] | 400 | final RemoteConnection createRemoteConnection( |
| 401 | PhoneAccountHandle connectionManagerPhoneAccount, |
| 402 | ConnectionRequest request, |
| 403 | boolean isIncoming) { |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 404 | final String id = UUID.randomUUID().toString(); |
Ihab Awad | 8aecfed | 2014-08-08 17:06:11 -0700 | [diff] [blame] | 405 | final ConnectionRequest newRequest = new ConnectionRequest( |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 406 | request.getAccountHandle(), |
Nancy Chen | ea38cca | 2014-09-05 16:38:49 -0700 | [diff] [blame] | 407 | request.getAddress(), |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 408 | request.getExtras(), |
| 409 | request.getVideoState()); |
| 410 | try { |
Ihab Awad | 8aecfed | 2014-08-08 17:06:11 -0700 | [diff] [blame] | 411 | if (mConnectionById.isEmpty()) { |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 412 | mOutgoingConnectionServiceRpc.addConnectionServiceAdapter(mServant.getStub()); |
Ihab Awad | 8aecfed | 2014-08-08 17:06:11 -0700 | [diff] [blame] | 413 | } |
| 414 | RemoteConnection connection = |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 415 | new RemoteConnection(id, mOutgoingConnectionServiceRpc, newRequest); |
Ihab Awad | 8aecfed | 2014-08-08 17:06:11 -0700 | [diff] [blame] | 416 | mPendingConnections.add(connection); |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 417 | mConnectionById.put(id, connection); |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 418 | mOutgoingConnectionServiceRpc.createConnection( |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 419 | connectionManagerPhoneAccount, |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 420 | id, |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 421 | newRequest, |
Yorke Lee | c3cf982 | 2014-10-02 09:38:39 -0700 | [diff] [blame] | 422 | isIncoming, |
| 423 | false /* isUnknownCall */); |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 424 | connection.registerCallback(new RemoteConnection.Callback() { |
Ihab Awad | 8aecfed | 2014-08-08 17:06:11 -0700 | [diff] [blame] | 425 | @Override |
| 426 | public void onDestroyed(RemoteConnection connection) { |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 427 | mConnectionById.remove(id); |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 428 | maybeDisconnectAdapter(); |
Ihab Awad | 8aecfed | 2014-08-08 17:06:11 -0700 | [diff] [blame] | 429 | } |
| 430 | }); |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 431 | return connection; |
| 432 | } catch (RemoteException e) { |
Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame] | 433 | return RemoteConnection.failure( |
| 434 | new DisconnectCause(DisconnectCause.ERROR, e.toString())); |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 435 | } |
| 436 | } |
| 437 | |
Ihab Awad | 50e3506 | 2014-09-30 09:17:03 -0700 | [diff] [blame] | 438 | private boolean hasConnection(String callId) { |
mike dooley | 879142b | 2014-10-08 13:39:28 -0700 | [diff] [blame] | 439 | return mConnectionById.containsKey(callId); |
Ihab Awad | 50e3506 | 2014-09-30 09:17:03 -0700 | [diff] [blame] | 440 | } |
| 441 | |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 442 | private RemoteConnection findConnectionForAction( |
| 443 | String callId, String action) { |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 444 | if (mConnectionById.containsKey(callId)) { |
| 445 | return mConnectionById.get(callId); |
| 446 | } |
| 447 | Log.w(this, "%s - Cannot find Connection %s", action, callId); |
| 448 | return NULL_CONNECTION; |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 449 | } |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 450 | |
| 451 | private RemoteConference findConferenceForAction( |
| 452 | String callId, String action) { |
| 453 | if (mConferenceById.containsKey(callId)) { |
| 454 | return mConferenceById.get(callId); |
| 455 | } |
| 456 | Log.w(this, "%s - Cannot find Conference %s", action, callId); |
| 457 | return NULL_CONFERENCE; |
| 458 | } |
| 459 | |
| 460 | private void maybeDisconnectAdapter() { |
| 461 | if (mConnectionById.isEmpty() && mConferenceById.isEmpty()) { |
| 462 | try { |
| 463 | mOutgoingConnectionServiceRpc.removeConnectionServiceAdapter(mServant.getStub()); |
| 464 | } catch (RemoteException e) { |
| 465 | } |
| 466 | } |
| 467 | } |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 468 | } |