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