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 | } |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 222 | if (conference.getConnections().size() == 0) { |
| 223 | // A conference was created, but none of its connections are ones that have been |
| 224 | // created by, and therefore being tracked by, this remote connection service. It |
| 225 | // is of no interest to us. |
Tyler Gunn | 2282bb9 | 2016-10-17 15:48:19 -0700 | [diff] [blame] | 226 | Log.d(this, "addConferenceCall - skipping"); |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 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()); |
Tyler Gunn | 2282bb9 | 2016-10-17 15:48:19 -0700 | [diff] [blame] | 233 | conference.putExtras(parcel.getExtras()); |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 234 | mConferenceById.put(callId, conference); |
Tyler Gunn | 2282bb9 | 2016-10-17 15:48:19 -0700 | [diff] [blame] | 235 | |
| 236 | // Stash the original connection ID as it exists in the source ConnectionService. |
| 237 | // Telecom will use this to avoid adding duplicates later. |
| 238 | // See comments on Connection.EXTRA_ORIGINAL_CONNECTION_ID for more information. |
| 239 | Bundle newExtras = new Bundle(); |
| 240 | newExtras.putString(Connection.EXTRA_ORIGINAL_CONNECTION_ID, callId); |
| 241 | conference.putExtras(newExtras); |
| 242 | |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 243 | conference.registerCallback(new RemoteConference.Callback() { |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 244 | @Override |
| 245 | public void onDestroyed(RemoteConference c) { |
| 246 | mConferenceById.remove(callId); |
| 247 | maybeDisconnectAdapter(); |
| 248 | } |
| 249 | }); |
| 250 | |
| 251 | mOurConnectionServiceImpl.addRemoteConference(conference); |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 252 | } |
| 253 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 254 | @Override |
Brad Ebinger | 4d75bee | 2016-10-28 12:29:55 -0700 | [diff] [blame] | 255 | public void removeCall(String callId, Session.Info sessionInfo) { |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 256 | if (mConnectionById.containsKey(callId)) { |
| 257 | findConnectionForAction(callId, "removeCall") |
| 258 | .setDestroyed(); |
| 259 | } else { |
| 260 | findConferenceForAction(callId, "removeCall") |
| 261 | .setDestroyed(); |
| 262 | } |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 263 | } |
| 264 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 265 | @Override |
Brad Ebinger | 4d75bee | 2016-10-28 12:29:55 -0700 | [diff] [blame] | 266 | public void onPostDialWait(String callId, String remaining, Session.Info sessionInfo) { |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 267 | findConnectionForAction(callId, "onPostDialWait") |
| 268 | .setPostDialWait(remaining); |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 269 | } |
| 270 | |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 271 | @Override |
Brad Ebinger | 4d75bee | 2016-10-28 12:29:55 -0700 | [diff] [blame] | 272 | public void onPostDialChar(String callId, char nextChar, Session.Info sessionInfo) { |
Nancy Chen | 27d1c2d | 2014-12-15 16:12:50 -0800 | [diff] [blame] | 273 | findConnectionForAction(callId, "onPostDialChar") |
| 274 | .onPostDialChar(nextChar); |
| 275 | } |
| 276 | |
| 277 | @Override |
Brad Ebinger | 4d75bee | 2016-10-28 12:29:55 -0700 | [diff] [blame] | 278 | public void queryRemoteConnectionServices(RemoteServiceCallback callback, |
| 279 | Session.Info sessionInfo) { |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 280 | // Not supported from remote connection service. |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 281 | } |
Tyler Gunn | 8d83fa9 | 2014-07-01 11:31:21 -0700 | [diff] [blame] | 282 | |
Sailesh Nepal | 33aaae4 | 2014-07-07 22:49:44 -0700 | [diff] [blame] | 283 | @Override |
Brad Ebinger | 4d75bee | 2016-10-28 12:29:55 -0700 | [diff] [blame] | 284 | public void setVideoProvider(String callId, IVideoProvider videoProvider, |
| 285 | Session.Info sessionInfo) { |
Sailesh Nepal | 11aeae5 | 2015-01-28 16:54:09 -0800 | [diff] [blame] | 286 | RemoteConnection.VideoProvider remoteVideoProvider = null; |
| 287 | if (videoProvider != null) { |
| 288 | remoteVideoProvider = new RemoteConnection.VideoProvider(videoProvider); |
| 289 | } |
Ihab Awad | a64627c | 2014-08-20 09:36:40 -0700 | [diff] [blame] | 290 | findConnectionForAction(callId, "setVideoProvider") |
Sailesh Nepal | 11aeae5 | 2015-01-28 16:54:09 -0800 | [diff] [blame] | 291 | .setVideoProvider(remoteVideoProvider); |
Tyler Gunn | aa07df8 | 2014-07-17 07:50:22 -0700 | [diff] [blame] | 292 | } |
| 293 | |
| 294 | @Override |
Brad Ebinger | 4d75bee | 2016-10-28 12:29:55 -0700 | [diff] [blame] | 295 | public void setVideoState(String callId, int videoState, Session.Info sessionInfo) { |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 296 | findConnectionForAction(callId, "setVideoState") |
| 297 | .setVideoState(videoState); |
Sailesh Nepal | 33aaae4 | 2014-07-07 22:49:44 -0700 | [diff] [blame] | 298 | } |
Sailesh Nepal | e7ef59a | 2014-07-08 21:48:22 -0700 | [diff] [blame] | 299 | |
Sailesh Nepal | e7ef59a | 2014-07-08 21:48:22 -0700 | [diff] [blame] | 300 | @Override |
Brad Ebinger | 4d75bee | 2016-10-28 12:29:55 -0700 | [diff] [blame] | 301 | public void setIsVoipAudioMode(String callId, boolean isVoip, Session.Info sessionInfo) { |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 302 | findConnectionForAction(callId, "setIsVoipAudioMode") |
| 303 | .setIsVoipAudioMode(isVoip); |
Sailesh Nepal | e7ef59a | 2014-07-08 21:48:22 -0700 | [diff] [blame] | 304 | } |
Sailesh Nepal | 6120386 | 2014-07-11 14:50:13 -0700 | [diff] [blame] | 305 | |
| 306 | @Override |
Brad Ebinger | 4d75bee | 2016-10-28 12:29:55 -0700 | [diff] [blame] | 307 | public void setStatusHints(String callId, StatusHints statusHints, |
| 308 | Session.Info sessionInfo) { |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 309 | findConnectionForAction(callId, "setStatusHints") |
| 310 | .setStatusHints(statusHints); |
Sailesh Nepal | 6120386 | 2014-07-11 14:50:13 -0700 | [diff] [blame] | 311 | } |
| 312 | |
| 313 | @Override |
Brad Ebinger | 4d75bee | 2016-10-28 12:29:55 -0700 | [diff] [blame] | 314 | public void setAddress(String callId, Uri address, int presentation, |
| 315 | Session.Info sessionInfo) { |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 316 | findConnectionForAction(callId, "setAddress") |
| 317 | .setAddress(address, presentation); |
Sailesh Nepal | 6120386 | 2014-07-11 14:50:13 -0700 | [diff] [blame] | 318 | } |
Sailesh Nepal | 2ab88cc | 2014-07-18 14:49:18 -0700 | [diff] [blame] | 319 | |
| 320 | @Override |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 321 | public void setCallerDisplayName(String callId, String callerDisplayName, |
Brad Ebinger | 4d75bee | 2016-10-28 12:29:55 -0700 | [diff] [blame] | 322 | int presentation, Session.Info sessionInfo) { |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 323 | findConnectionForAction(callId, "setCallerDisplayName") |
| 324 | .setCallerDisplayName(callerDisplayName, presentation); |
| 325 | } |
| 326 | |
| 327 | @Override |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 328 | public IBinder asBinder() { |
| 329 | throw new UnsupportedOperationException(); |
Sailesh Nepal | 2ab88cc | 2014-07-18 14:49:18 -0700 | [diff] [blame] | 330 | } |
Santos Cordon | 7c7bc7f | 2014-07-28 18:15:48 -0700 | [diff] [blame] | 331 | |
| 332 | @Override |
Brad Ebinger | 4d75bee | 2016-10-28 12:29:55 -0700 | [diff] [blame] | 333 | public final void setConferenceableConnections(String callId, |
| 334 | List<String> conferenceableConnectionIds, Session.Info sessionInfo) { |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 335 | List<RemoteConnection> conferenceable = new ArrayList<>(); |
| 336 | for (String id : conferenceableConnectionIds) { |
| 337 | if (mConnectionById.containsKey(id)) { |
| 338 | conferenceable.add(mConnectionById.get(id)); |
| 339 | } |
| 340 | } |
Santos Cordon | 7c7bc7f | 2014-07-28 18:15:48 -0700 | [diff] [blame] | 341 | |
Ihab Awad | 50e3506 | 2014-09-30 09:17:03 -0700 | [diff] [blame] | 342 | if (hasConnection(callId)) { |
| 343 | findConnectionForAction(callId, "setConferenceableConnections") |
| 344 | .setConferenceableConnections(conferenceable); |
| 345 | } else { |
| 346 | findConferenceForAction(callId, "setConferenceableConnections") |
| 347 | .setConferenceableConnections(conferenceable); |
| 348 | } |
Santos Cordon | 7c7bc7f | 2014-07-28 18:15:48 -0700 | [diff] [blame] | 349 | } |
Tyler Gunn | 4a57b9b | 2014-10-30 14:27:48 -0700 | [diff] [blame] | 350 | |
| 351 | @Override |
Brad Ebinger | 4d75bee | 2016-10-28 12:29:55 -0700 | [diff] [blame] | 352 | public void addExistingConnection(String callId, ParcelableConnection connection, |
| 353 | Session.Info sessionInfo) { |
Tyler Gunn | 2282bb9 | 2016-10-17 15:48:19 -0700 | [diff] [blame] | 354 | RemoteConnection remoteConnection = new RemoteConnection(callId, |
Tyler Gunn | 4a57b9b | 2014-10-30 14:27:48 -0700 | [diff] [blame] | 355 | mOutgoingConnectionServiceRpc, connection); |
Tyler Gunn | 2282bb9 | 2016-10-17 15:48:19 -0700 | [diff] [blame] | 356 | mConnectionById.put(callId, remoteConnection); |
| 357 | remoteConnection.registerCallback(new RemoteConnection.Callback() { |
| 358 | @Override |
| 359 | public void onDestroyed(RemoteConnection connection) { |
| 360 | mConnectionById.remove(callId); |
| 361 | maybeDisconnectAdapter(); |
| 362 | } |
| 363 | }); |
| 364 | mOurConnectionServiceImpl.addRemoteExistingConnection(remoteConnection); |
Tyler Gunn | 4a57b9b | 2014-10-30 14:27:48 -0700 | [diff] [blame] | 365 | } |
Santos Cordon | 6b7f955 | 2015-05-27 17:21:45 -0700 | [diff] [blame] | 366 | |
| 367 | @Override |
Brad Ebinger | 4d75bee | 2016-10-28 12:29:55 -0700 | [diff] [blame] | 368 | public void putExtras(String callId, Bundle extras, Session.Info sessionInfo) { |
Tyler Gunn | dee56a8 | 2016-03-23 16:06:34 -0700 | [diff] [blame] | 369 | if (hasConnection(callId)) { |
| 370 | findConnectionForAction(callId, "putExtras").putExtras(extras); |
Santos Cordon | 6b7f955 | 2015-05-27 17:21:45 -0700 | [diff] [blame] | 371 | } else { |
Tyler Gunn | dee56a8 | 2016-03-23 16:06:34 -0700 | [diff] [blame] | 372 | findConferenceForAction(callId, "putExtras").putExtras(extras); |
| 373 | } |
| 374 | } |
| 375 | |
| 376 | @Override |
Brad Ebinger | 4d75bee | 2016-10-28 12:29:55 -0700 | [diff] [blame] | 377 | public void removeExtras(String callId, List<String> keys, Session.Info sessionInfo) { |
Tyler Gunn | dee56a8 | 2016-03-23 16:06:34 -0700 | [diff] [blame] | 378 | if (hasConnection(callId)) { |
| 379 | findConnectionForAction(callId, "removeExtra").removeExtras(keys); |
| 380 | } else { |
| 381 | findConferenceForAction(callId, "removeExtra").removeExtras(keys); |
Santos Cordon | 6b7f955 | 2015-05-27 17:21:45 -0700 | [diff] [blame] | 382 | } |
| 383 | } |
Tyler Gunn | bd1eb1f | 2016-02-16 14:36:20 -0800 | [diff] [blame] | 384 | |
| 385 | @Override |
Brad Ebinger | 4d75bee | 2016-10-28 12:29:55 -0700 | [diff] [blame] | 386 | public void onConnectionEvent(String callId, String event, Bundle extras, |
| 387 | Session.Info sessionInfo) { |
Tyler Gunn | bd1eb1f | 2016-02-16 14:36:20 -0800 | [diff] [blame] | 388 | if (mConnectionById.containsKey(callId)) { |
Tyler Gunn | 876dbfb | 2016-03-14 15:18:07 -0700 | [diff] [blame] | 389 | findConnectionForAction(callId, "onConnectionEvent").onConnectionEvent(event, |
| 390 | extras); |
Tyler Gunn | bd1eb1f | 2016-02-16 14:36:20 -0800 | [diff] [blame] | 391 | } |
| 392 | } |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 393 | }; |
| 394 | |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 395 | private final ConnectionServiceAdapterServant mServant = |
| 396 | new ConnectionServiceAdapterServant(mServantDelegate); |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 397 | |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 398 | private final DeathRecipient mDeathRecipient = new DeathRecipient() { |
| 399 | @Override |
| 400 | public void binderDied() { |
| 401 | for (RemoteConnection c : mConnectionById.values()) { |
| 402 | c.setDestroyed(); |
| 403 | } |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 404 | for (RemoteConference c : mConferenceById.values()) { |
| 405 | c.setDestroyed(); |
| 406 | } |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 407 | mConnectionById.clear(); |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 408 | mConferenceById.clear(); |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 409 | mPendingConnections.clear(); |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 410 | mOutgoingConnectionServiceRpc.asBinder().unlinkToDeath(mDeathRecipient, 0); |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 411 | } |
| 412 | }; |
| 413 | |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 414 | private final IConnectionService mOutgoingConnectionServiceRpc; |
| 415 | private final ConnectionService mOurConnectionServiceImpl; |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 416 | private final Map<String, RemoteConnection> mConnectionById = new HashMap<>(); |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 417 | private final Map<String, RemoteConference> mConferenceById = new HashMap<>(); |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 418 | private final Set<RemoteConnection> mPendingConnections = new HashSet<>(); |
| 419 | |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 420 | RemoteConnectionService( |
| 421 | IConnectionService outgoingConnectionServiceRpc, |
| 422 | ConnectionService ourConnectionServiceImpl) throws RemoteException { |
| 423 | mOutgoingConnectionServiceRpc = outgoingConnectionServiceRpc; |
| 424 | mOutgoingConnectionServiceRpc.asBinder().linkToDeath(mDeathRecipient, 0); |
| 425 | mOurConnectionServiceImpl = ourConnectionServiceImpl; |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 426 | } |
| 427 | |
| 428 | @Override |
| 429 | public String toString() { |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 430 | return "[RemoteCS - " + mOutgoingConnectionServiceRpc.asBinder().toString() + "]"; |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 431 | } |
| 432 | |
Ihab Awad | f8b6988 | 2014-07-25 15:14:01 -0700 | [diff] [blame] | 433 | final RemoteConnection createRemoteConnection( |
| 434 | PhoneAccountHandle connectionManagerPhoneAccount, |
| 435 | ConnectionRequest request, |
| 436 | boolean isIncoming) { |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 437 | final String id = UUID.randomUUID().toString(); |
Ihab Awad | 8aecfed | 2014-08-08 17:06:11 -0700 | [diff] [blame] | 438 | final ConnectionRequest newRequest = new ConnectionRequest( |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 439 | request.getAccountHandle(), |
Nancy Chen | ea38cca | 2014-09-05 16:38:49 -0700 | [diff] [blame] | 440 | request.getAddress(), |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 441 | request.getExtras(), |
| 442 | request.getVideoState()); |
| 443 | try { |
Ihab Awad | 8aecfed | 2014-08-08 17:06:11 -0700 | [diff] [blame] | 444 | if (mConnectionById.isEmpty()) { |
Brad Ebinger | b32d4f8 | 2016-10-24 16:40:49 -0700 | [diff] [blame] | 445 | mOutgoingConnectionServiceRpc.addConnectionServiceAdapter(mServant.getStub(), |
| 446 | null /*Session.Info*/); |
Ihab Awad | 8aecfed | 2014-08-08 17:06:11 -0700 | [diff] [blame] | 447 | } |
| 448 | RemoteConnection connection = |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 449 | new RemoteConnection(id, mOutgoingConnectionServiceRpc, newRequest); |
Ihab Awad | 8aecfed | 2014-08-08 17:06:11 -0700 | [diff] [blame] | 450 | mPendingConnections.add(connection); |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 451 | mConnectionById.put(id, connection); |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 452 | mOutgoingConnectionServiceRpc.createConnection( |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 453 | connectionManagerPhoneAccount, |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 454 | id, |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 455 | newRequest, |
Yorke Lee | c3cf982 | 2014-10-02 09:38:39 -0700 | [diff] [blame] | 456 | isIncoming, |
Brad Ebinger | b32d4f8 | 2016-10-24 16:40:49 -0700 | [diff] [blame] | 457 | false /* isUnknownCall */, |
| 458 | null /*Session.info*/); |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 459 | connection.registerCallback(new RemoteConnection.Callback() { |
Ihab Awad | 8aecfed | 2014-08-08 17:06:11 -0700 | [diff] [blame] | 460 | @Override |
| 461 | public void onDestroyed(RemoteConnection connection) { |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 462 | mConnectionById.remove(id); |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 463 | maybeDisconnectAdapter(); |
Ihab Awad | 8aecfed | 2014-08-08 17:06:11 -0700 | [diff] [blame] | 464 | } |
| 465 | }); |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 466 | return connection; |
| 467 | } catch (RemoteException e) { |
Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame] | 468 | return RemoteConnection.failure( |
| 469 | new DisconnectCause(DisconnectCause.ERROR, e.toString())); |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 470 | } |
| 471 | } |
| 472 | |
Ihab Awad | 50e3506 | 2014-09-30 09:17:03 -0700 | [diff] [blame] | 473 | private boolean hasConnection(String callId) { |
mike dooley | 879142b | 2014-10-08 13:39:28 -0700 | [diff] [blame] | 474 | return mConnectionById.containsKey(callId); |
Ihab Awad | 50e3506 | 2014-09-30 09:17:03 -0700 | [diff] [blame] | 475 | } |
| 476 | |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 477 | private RemoteConnection findConnectionForAction( |
| 478 | String callId, String action) { |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 479 | if (mConnectionById.containsKey(callId)) { |
| 480 | return mConnectionById.get(callId); |
| 481 | } |
| 482 | Log.w(this, "%s - Cannot find Connection %s", action, callId); |
| 483 | return NULL_CONNECTION; |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 484 | } |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 485 | |
| 486 | private RemoteConference findConferenceForAction( |
| 487 | String callId, String action) { |
| 488 | if (mConferenceById.containsKey(callId)) { |
| 489 | return mConferenceById.get(callId); |
| 490 | } |
| 491 | Log.w(this, "%s - Cannot find Conference %s", action, callId); |
| 492 | return NULL_CONFERENCE; |
| 493 | } |
| 494 | |
| 495 | private void maybeDisconnectAdapter() { |
| 496 | if (mConnectionById.isEmpty() && mConferenceById.isEmpty()) { |
| 497 | try { |
Brad Ebinger | b32d4f8 | 2016-10-24 16:40:49 -0700 | [diff] [blame] | 498 | mOutgoingConnectionServiceRpc.removeConnectionServiceAdapter(mServant.getStub(), |
| 499 | null /*Session.info*/); |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 500 | } catch (RemoteException e) { |
| 501 | } |
| 502 | } |
| 503 | } |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 504 | } |