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 | } |
Tyler Gunn | 31f0e0b | 2018-02-13 08:39:45 -0800 | [diff] [blame] | 96 | connection.setStatusHints(parcel.getStatusHints()); |
| 97 | connection.setIsVoipAudioMode(parcel.getIsVoipAudioMode()); |
| 98 | connection.setRingbackRequested(parcel.isRingbackRequested()); |
| 99 | connection.putExtras(parcel.getExtras()); |
Sailesh Nepal | 4803159 | 2014-07-18 14:21:23 -0700 | [diff] [blame] | 100 | } |
| 101 | } |
Sailesh Nepal | 2ab88cc | 2014-07-18 14:49:18 -0700 | [diff] [blame] | 102 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 103 | @Override |
Brad Ebinger | 4d75bee | 2016-10-28 12:29:55 -0700 | [diff] [blame] | 104 | public void setActive(String callId, Session.Info sessionInfo) { |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 105 | if (mConnectionById.containsKey(callId)) { |
| 106 | findConnectionForAction(callId, "setActive") |
| 107 | .setState(Connection.STATE_ACTIVE); |
| 108 | } else { |
| 109 | findConferenceForAction(callId, "setActive") |
| 110 | .setState(Connection.STATE_ACTIVE); |
| 111 | } |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 112 | } |
| 113 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 114 | @Override |
Brad Ebinger | 4d75bee | 2016-10-28 12:29:55 -0700 | [diff] [blame] | 115 | public void setRinging(String callId, Session.Info sessionInfo) { |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 116 | findConnectionForAction(callId, "setRinging") |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 117 | .setState(Connection.STATE_RINGING); |
Andrew Lee | 5ffbe8b | 2014-06-20 16:29:33 -0700 | [diff] [blame] | 118 | } |
| 119 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 120 | @Override |
Brad Ebinger | 4d75bee | 2016-10-28 12:29:55 -0700 | [diff] [blame] | 121 | public void setDialing(String callId, Session.Info sessionInfo) { |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 122 | findConnectionForAction(callId, "setDialing") |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 123 | .setState(Connection.STATE_DIALING); |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 124 | } |
| 125 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 126 | @Override |
Brad Ebinger | 4d75bee | 2016-10-28 12:29:55 -0700 | [diff] [blame] | 127 | public void setPulling(String callId, Session.Info sessionInfo) { |
Tyler Gunn | c96b5e0 | 2016-07-07 22:53:57 -0700 | [diff] [blame] | 128 | findConnectionForAction(callId, "setPulling") |
| 129 | .setState(Connection.STATE_PULLING_CALL); |
| 130 | } |
| 131 | |
| 132 | @Override |
Brad Ebinger | 4d75bee | 2016-10-28 12:29:55 -0700 | [diff] [blame] | 133 | public void setDisconnected(String callId, DisconnectCause disconnectCause, |
| 134 | Session.Info sessionInfo) { |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 135 | if (mConnectionById.containsKey(callId)) { |
| 136 | findConnectionForAction(callId, "setDisconnected") |
Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame] | 137 | .setDisconnected(disconnectCause); |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 138 | } else { |
| 139 | findConferenceForAction(callId, "setDisconnected") |
Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame] | 140 | .setDisconnected(disconnectCause); |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 141 | } |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 142 | } |
| 143 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 144 | @Override |
Brad Ebinger | 4d75bee | 2016-10-28 12:29:55 -0700 | [diff] [blame] | 145 | public void setOnHold(String callId, Session.Info sessionInfo) { |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 146 | if (mConnectionById.containsKey(callId)) { |
| 147 | findConnectionForAction(callId, "setOnHold") |
| 148 | .setState(Connection.STATE_HOLDING); |
| 149 | } else { |
| 150 | findConferenceForAction(callId, "setOnHold") |
| 151 | .setState(Connection.STATE_HOLDING); |
| 152 | } |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 153 | } |
| 154 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 155 | @Override |
Brad Ebinger | 4d75bee | 2016-10-28 12:29:55 -0700 | [diff] [blame] | 156 | public void setRingbackRequested(String callId, boolean ringing, Session.Info sessionInfo) { |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 157 | findConnectionForAction(callId, "setRingbackRequested") |
| 158 | .setRingbackRequested(ringing); |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 159 | } |
| 160 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 161 | @Override |
Brad Ebinger | 4d75bee | 2016-10-28 12:29:55 -0700 | [diff] [blame] | 162 | public void setConnectionCapabilities(String callId, int connectionCapabilities, |
| 163 | Session.Info sessionInfo) { |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 164 | if (mConnectionById.containsKey(callId)) { |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 165 | findConnectionForAction(callId, "setConnectionCapabilities") |
| 166 | .setConnectionCapabilities(connectionCapabilities); |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 167 | } else { |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 168 | findConferenceForAction(callId, "setConnectionCapabilities") |
| 169 | .setConnectionCapabilities(connectionCapabilities); |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 170 | } |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 171 | } |
| 172 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 173 | @Override |
Brad Ebinger | 4d75bee | 2016-10-28 12:29:55 -0700 | [diff] [blame] | 174 | public void setConnectionProperties(String callId, int connectionProperties, |
| 175 | Session.Info sessionInfo) { |
Tyler Gunn | 720c664 | 2016-03-22 09:02:47 -0700 | [diff] [blame] | 176 | if (mConnectionById.containsKey(callId)) { |
| 177 | findConnectionForAction(callId, "setConnectionProperties") |
| 178 | .setConnectionProperties(connectionProperties); |
| 179 | } else { |
| 180 | findConferenceForAction(callId, "setConnectionProperties") |
| 181 | .setConnectionProperties(connectionProperties); |
| 182 | } |
| 183 | } |
| 184 | |
| 185 | @Override |
Brad Ebinger | 4d75bee | 2016-10-28 12:29:55 -0700 | [diff] [blame] | 186 | public void setIsConferenced(String callId, String conferenceCallId, |
| 187 | Session.Info sessionInfo) { |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 188 | // Note: callId should not be null; conferenceCallId may be null |
| 189 | RemoteConnection connection = |
| 190 | findConnectionForAction(callId, "setIsConferenced"); |
| 191 | if (connection != NULL_CONNECTION) { |
| 192 | if (conferenceCallId == null) { |
| 193 | // 'connection' is being split from its conference |
| 194 | if (connection.getConference() != null) { |
| 195 | connection.getConference().removeConnection(connection); |
| 196 | } |
| 197 | } else { |
| 198 | RemoteConference conference = |
| 199 | findConferenceForAction(conferenceCallId, "setIsConferenced"); |
| 200 | if (conference != NULL_CONFERENCE) { |
| 201 | conference.addConnection(connection); |
| 202 | } |
| 203 | } |
| 204 | } |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 205 | } |
| 206 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 207 | @Override |
Brad Ebinger | 4d75bee | 2016-10-28 12:29:55 -0700 | [diff] [blame] | 208 | public void setConferenceMergeFailed(String callId, Session.Info sessionInfo) { |
Anthony Lee | 17455a3 | 2015-04-24 15:25:29 -0700 | [diff] [blame] | 209 | // Nothing to do here. |
| 210 | // The event has already been handled and there is no state to update |
| 211 | // in the underlying connection or conference objects |
| 212 | } |
| 213 | |
| 214 | @Override |
Srikanth Chintala | fcb1501 | 2017-05-04 20:58:34 +0530 | [diff] [blame] | 215 | public void onPhoneAccountChanged(String callId, PhoneAccountHandle pHandle, |
| 216 | Session.Info sessionInfo) { |
| 217 | } |
| 218 | |
| 219 | @Override |
Pengquan Meng | 63d25a5 | 2017-11-21 18:01:13 -0800 | [diff] [blame] | 220 | public void onConnectionServiceFocusReleased(Session.Info sessionInfo) {} |
| 221 | |
| 222 | @Override |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 223 | public void addConferenceCall( |
Brad Ebinger | 4d75bee | 2016-10-28 12:29:55 -0700 | [diff] [blame] | 224 | final String callId, ParcelableConference parcel, Session.Info sessionInfo) { |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 225 | RemoteConference conference = new RemoteConference(callId, |
| 226 | mOutgoingConnectionServiceRpc); |
| 227 | |
| 228 | for (String id : parcel.getConnectionIds()) { |
| 229 | RemoteConnection c = mConnectionById.get(id); |
| 230 | if (c != null) { |
| 231 | conference.addConnection(c); |
| 232 | } |
| 233 | } |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 234 | if (conference.getConnections().size() == 0) { |
| 235 | // A conference was created, but none of its connections are ones that have been |
| 236 | // created by, and therefore being tracked by, this remote connection service. It |
| 237 | // is of no interest to us. |
Tyler Gunn | cd6ccfd | 2016-10-17 15:48:19 -0700 | [diff] [blame] | 238 | Log.d(this, "addConferenceCall - skipping"); |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 239 | return; |
| 240 | } |
| 241 | |
| 242 | conference.setState(parcel.getState()); |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 243 | conference.setConnectionCapabilities(parcel.getConnectionCapabilities()); |
Tyler Gunn | 04ce757 | 2016-08-15 10:56:12 -0700 | [diff] [blame] | 244 | conference.setConnectionProperties(parcel.getConnectionProperties()); |
Tyler Gunn | cd6ccfd | 2016-10-17 15:48:19 -0700 | [diff] [blame] | 245 | conference.putExtras(parcel.getExtras()); |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 246 | mConferenceById.put(callId, conference); |
Tyler Gunn | cd6ccfd | 2016-10-17 15:48:19 -0700 | [diff] [blame] | 247 | |
| 248 | // Stash the original connection ID as it exists in the source ConnectionService. |
| 249 | // Telecom will use this to avoid adding duplicates later. |
| 250 | // See comments on Connection.EXTRA_ORIGINAL_CONNECTION_ID for more information. |
| 251 | Bundle newExtras = new Bundle(); |
| 252 | newExtras.putString(Connection.EXTRA_ORIGINAL_CONNECTION_ID, callId); |
| 253 | conference.putExtras(newExtras); |
| 254 | |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 255 | conference.registerCallback(new RemoteConference.Callback() { |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 256 | @Override |
| 257 | public void onDestroyed(RemoteConference c) { |
| 258 | mConferenceById.remove(callId); |
| 259 | maybeDisconnectAdapter(); |
| 260 | } |
| 261 | }); |
| 262 | |
| 263 | mOurConnectionServiceImpl.addRemoteConference(conference); |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 264 | } |
| 265 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 266 | @Override |
Brad Ebinger | 4d75bee | 2016-10-28 12:29:55 -0700 | [diff] [blame] | 267 | public void removeCall(String callId, Session.Info sessionInfo) { |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 268 | if (mConnectionById.containsKey(callId)) { |
| 269 | findConnectionForAction(callId, "removeCall") |
| 270 | .setDestroyed(); |
| 271 | } else { |
| 272 | findConferenceForAction(callId, "removeCall") |
| 273 | .setDestroyed(); |
| 274 | } |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 275 | } |
| 276 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 277 | @Override |
Brad Ebinger | 4d75bee | 2016-10-28 12:29:55 -0700 | [diff] [blame] | 278 | public void onPostDialWait(String callId, String remaining, Session.Info sessionInfo) { |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 279 | findConnectionForAction(callId, "onPostDialWait") |
| 280 | .setPostDialWait(remaining); |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 281 | } |
| 282 | |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 283 | @Override |
Brad Ebinger | 4d75bee | 2016-10-28 12:29:55 -0700 | [diff] [blame] | 284 | public void onPostDialChar(String callId, char nextChar, Session.Info sessionInfo) { |
Nancy Chen | 27d1c2d | 2014-12-15 16:12:50 -0800 | [diff] [blame] | 285 | findConnectionForAction(callId, "onPostDialChar") |
| 286 | .onPostDialChar(nextChar); |
| 287 | } |
| 288 | |
| 289 | @Override |
Brad Ebinger | 4d75bee | 2016-10-28 12:29:55 -0700 | [diff] [blame] | 290 | public void queryRemoteConnectionServices(RemoteServiceCallback callback, |
| 291 | Session.Info sessionInfo) { |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 292 | // Not supported from remote connection service. |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 293 | } |
Tyler Gunn | 8d83fa9 | 2014-07-01 11:31:21 -0700 | [diff] [blame] | 294 | |
Sailesh Nepal | 33aaae4 | 2014-07-07 22:49:44 -0700 | [diff] [blame] | 295 | @Override |
Brad Ebinger | 4d75bee | 2016-10-28 12:29:55 -0700 | [diff] [blame] | 296 | public void setVideoProvider(String callId, IVideoProvider videoProvider, |
| 297 | Session.Info sessionInfo) { |
Tyler Gunn | bf9c6fd | 2016-11-09 10:19:23 -0800 | [diff] [blame] | 298 | |
| 299 | String callingPackage = mOurConnectionServiceImpl.getApplicationContext() |
| 300 | .getOpPackageName(); |
Tyler Gunn | 159f35c | 2017-03-02 09:28:37 -0800 | [diff] [blame] | 301 | int targetSdkVersion = mOurConnectionServiceImpl.getApplicationInfo().targetSdkVersion; |
Sailesh Nepal | 11aeae5 | 2015-01-28 16:54:09 -0800 | [diff] [blame] | 302 | RemoteConnection.VideoProvider remoteVideoProvider = null; |
| 303 | if (videoProvider != null) { |
Tyler Gunn | bf9c6fd | 2016-11-09 10:19:23 -0800 | [diff] [blame] | 304 | remoteVideoProvider = new RemoteConnection.VideoProvider(videoProvider, |
Tyler Gunn | 159f35c | 2017-03-02 09:28:37 -0800 | [diff] [blame] | 305 | callingPackage, targetSdkVersion); |
Sailesh Nepal | 11aeae5 | 2015-01-28 16:54:09 -0800 | [diff] [blame] | 306 | } |
Ihab Awad | a64627c | 2014-08-20 09:36:40 -0700 | [diff] [blame] | 307 | findConnectionForAction(callId, "setVideoProvider") |
Sailesh Nepal | 11aeae5 | 2015-01-28 16:54:09 -0800 | [diff] [blame] | 308 | .setVideoProvider(remoteVideoProvider); |
Tyler Gunn | aa07df8 | 2014-07-17 07:50:22 -0700 | [diff] [blame] | 309 | } |
| 310 | |
| 311 | @Override |
Brad Ebinger | 4d75bee | 2016-10-28 12:29:55 -0700 | [diff] [blame] | 312 | public void setVideoState(String callId, int videoState, Session.Info sessionInfo) { |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 313 | findConnectionForAction(callId, "setVideoState") |
| 314 | .setVideoState(videoState); |
Sailesh Nepal | 33aaae4 | 2014-07-07 22:49:44 -0700 | [diff] [blame] | 315 | } |
Sailesh Nepal | e7ef59a | 2014-07-08 21:48:22 -0700 | [diff] [blame] | 316 | |
Sailesh Nepal | e7ef59a | 2014-07-08 21:48:22 -0700 | [diff] [blame] | 317 | @Override |
Brad Ebinger | 4d75bee | 2016-10-28 12:29:55 -0700 | [diff] [blame] | 318 | public void setIsVoipAudioMode(String callId, boolean isVoip, Session.Info sessionInfo) { |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 319 | findConnectionForAction(callId, "setIsVoipAudioMode") |
| 320 | .setIsVoipAudioMode(isVoip); |
Sailesh Nepal | e7ef59a | 2014-07-08 21:48:22 -0700 | [diff] [blame] | 321 | } |
Sailesh Nepal | 6120386 | 2014-07-11 14:50:13 -0700 | [diff] [blame] | 322 | |
| 323 | @Override |
Brad Ebinger | 4d75bee | 2016-10-28 12:29:55 -0700 | [diff] [blame] | 324 | public void setStatusHints(String callId, StatusHints statusHints, |
| 325 | Session.Info sessionInfo) { |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 326 | findConnectionForAction(callId, "setStatusHints") |
| 327 | .setStatusHints(statusHints); |
Sailesh Nepal | 6120386 | 2014-07-11 14:50:13 -0700 | [diff] [blame] | 328 | } |
| 329 | |
| 330 | @Override |
Brad Ebinger | 4d75bee | 2016-10-28 12:29:55 -0700 | [diff] [blame] | 331 | public void setAddress(String callId, Uri address, int presentation, |
| 332 | Session.Info sessionInfo) { |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 333 | findConnectionForAction(callId, "setAddress") |
| 334 | .setAddress(address, presentation); |
Sailesh Nepal | 6120386 | 2014-07-11 14:50:13 -0700 | [diff] [blame] | 335 | } |
Sailesh Nepal | 2ab88cc | 2014-07-18 14:49:18 -0700 | [diff] [blame] | 336 | |
| 337 | @Override |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 338 | public void setCallerDisplayName(String callId, String callerDisplayName, |
Brad Ebinger | 4d75bee | 2016-10-28 12:29:55 -0700 | [diff] [blame] | 339 | int presentation, Session.Info sessionInfo) { |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 340 | findConnectionForAction(callId, "setCallerDisplayName") |
| 341 | .setCallerDisplayName(callerDisplayName, presentation); |
| 342 | } |
| 343 | |
| 344 | @Override |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 345 | public IBinder asBinder() { |
| 346 | throw new UnsupportedOperationException(); |
Sailesh Nepal | 2ab88cc | 2014-07-18 14:49:18 -0700 | [diff] [blame] | 347 | } |
Santos Cordon | 7c7bc7f | 2014-07-28 18:15:48 -0700 | [diff] [blame] | 348 | |
| 349 | @Override |
Brad Ebinger | 4d75bee | 2016-10-28 12:29:55 -0700 | [diff] [blame] | 350 | public final void setConferenceableConnections(String callId, |
| 351 | List<String> conferenceableConnectionIds, Session.Info sessionInfo) { |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 352 | List<RemoteConnection> conferenceable = new ArrayList<>(); |
| 353 | for (String id : conferenceableConnectionIds) { |
| 354 | if (mConnectionById.containsKey(id)) { |
| 355 | conferenceable.add(mConnectionById.get(id)); |
| 356 | } |
| 357 | } |
Santos Cordon | 7c7bc7f | 2014-07-28 18:15:48 -0700 | [diff] [blame] | 358 | |
Ihab Awad | 50e3506 | 2014-09-30 09:17:03 -0700 | [diff] [blame] | 359 | if (hasConnection(callId)) { |
| 360 | findConnectionForAction(callId, "setConferenceableConnections") |
| 361 | .setConferenceableConnections(conferenceable); |
| 362 | } else { |
| 363 | findConferenceForAction(callId, "setConferenceableConnections") |
| 364 | .setConferenceableConnections(conferenceable); |
| 365 | } |
Santos Cordon | 7c7bc7f | 2014-07-28 18:15:48 -0700 | [diff] [blame] | 366 | } |
Tyler Gunn | 4a57b9b | 2014-10-30 14:27:48 -0700 | [diff] [blame] | 367 | |
| 368 | @Override |
Brad Ebinger | 4d75bee | 2016-10-28 12:29:55 -0700 | [diff] [blame] | 369 | public void addExistingConnection(String callId, ParcelableConnection connection, |
| 370 | Session.Info sessionInfo) { |
Tyler Gunn | bf9c6fd | 2016-11-09 10:19:23 -0800 | [diff] [blame] | 371 | String callingPackage = mOurConnectionServiceImpl.getApplicationContext(). |
| 372 | getOpPackageName(); |
Tyler Gunn | 159f35c | 2017-03-02 09:28:37 -0800 | [diff] [blame] | 373 | int callingTargetSdkVersion = mOurConnectionServiceImpl.getApplicationInfo() |
| 374 | .targetSdkVersion; |
Tyler Gunn | cd6ccfd | 2016-10-17 15:48:19 -0700 | [diff] [blame] | 375 | RemoteConnection remoteConnection = new RemoteConnection(callId, |
Tyler Gunn | 159f35c | 2017-03-02 09:28:37 -0800 | [diff] [blame] | 376 | mOutgoingConnectionServiceRpc, connection, callingPackage, |
| 377 | callingTargetSdkVersion); |
Tyler Gunn | cd6ccfd | 2016-10-17 15:48:19 -0700 | [diff] [blame] | 378 | mConnectionById.put(callId, remoteConnection); |
| 379 | remoteConnection.registerCallback(new RemoteConnection.Callback() { |
| 380 | @Override |
| 381 | public void onDestroyed(RemoteConnection connection) { |
| 382 | mConnectionById.remove(callId); |
| 383 | maybeDisconnectAdapter(); |
| 384 | } |
| 385 | }); |
| 386 | mOurConnectionServiceImpl.addRemoteExistingConnection(remoteConnection); |
Tyler Gunn | 4a57b9b | 2014-10-30 14:27:48 -0700 | [diff] [blame] | 387 | } |
Santos Cordon | 6b7f955 | 2015-05-27 17:21:45 -0700 | [diff] [blame] | 388 | |
| 389 | @Override |
Brad Ebinger | 4d75bee | 2016-10-28 12:29:55 -0700 | [diff] [blame] | 390 | public void putExtras(String callId, Bundle extras, Session.Info sessionInfo) { |
Tyler Gunn | dee56a8 | 2016-03-23 16:06:34 -0700 | [diff] [blame] | 391 | if (hasConnection(callId)) { |
| 392 | findConnectionForAction(callId, "putExtras").putExtras(extras); |
Santos Cordon | 6b7f955 | 2015-05-27 17:21:45 -0700 | [diff] [blame] | 393 | } else { |
Tyler Gunn | dee56a8 | 2016-03-23 16:06:34 -0700 | [diff] [blame] | 394 | findConferenceForAction(callId, "putExtras").putExtras(extras); |
| 395 | } |
| 396 | } |
| 397 | |
| 398 | @Override |
Brad Ebinger | 4d75bee | 2016-10-28 12:29:55 -0700 | [diff] [blame] | 399 | public void removeExtras(String callId, List<String> keys, Session.Info sessionInfo) { |
Tyler Gunn | dee56a8 | 2016-03-23 16:06:34 -0700 | [diff] [blame] | 400 | if (hasConnection(callId)) { |
| 401 | findConnectionForAction(callId, "removeExtra").removeExtras(keys); |
| 402 | } else { |
| 403 | findConferenceForAction(callId, "removeExtra").removeExtras(keys); |
Santos Cordon | 6b7f955 | 2015-05-27 17:21:45 -0700 | [diff] [blame] | 404 | } |
| 405 | } |
Tyler Gunn | bd1eb1f | 2016-02-16 14:36:20 -0800 | [diff] [blame] | 406 | |
| 407 | @Override |
Hall Liu | a98f58b | 2017-11-07 17:59:28 -0800 | [diff] [blame] | 408 | public void setAudioRoute(String callId, int audioRoute, String bluetoothAddress, |
| 409 | Session.Info sessionInfo) { |
Tyler Gunn | f503543 | 2017-01-09 09:43:12 -0800 | [diff] [blame] | 410 | if (hasConnection(callId)) { |
| 411 | // TODO(3pcalls): handle this for remote connections. |
| 412 | // Likely we don't want to do anything since it doesn't make sense for self-managed |
| 413 | // connections to go through a connection mgr. |
| 414 | } |
| 415 | } |
| 416 | |
| 417 | @Override |
Brad Ebinger | 4d75bee | 2016-10-28 12:29:55 -0700 | [diff] [blame] | 418 | public void onConnectionEvent(String callId, String event, Bundle extras, |
| 419 | Session.Info sessionInfo) { |
Tyler Gunn | bd1eb1f | 2016-02-16 14:36:20 -0800 | [diff] [blame] | 420 | if (mConnectionById.containsKey(callId)) { |
Tyler Gunn | 876dbfb | 2016-03-14 15:18:07 -0700 | [diff] [blame] | 421 | findConnectionForAction(callId, "onConnectionEvent").onConnectionEvent(event, |
| 422 | extras); |
Tyler Gunn | bd1eb1f | 2016-02-16 14:36:20 -0800 | [diff] [blame] | 423 | } |
| 424 | } |
Hall Liu | 57006aa | 2017-02-06 10:49:48 -0800 | [diff] [blame] | 425 | |
| 426 | @Override |
| 427 | public void onRttInitiationSuccess(String callId, Session.Info sessionInfo) |
| 428 | throws RemoteException { |
| 429 | if (hasConnection(callId)) { |
| 430 | findConnectionForAction(callId, "onRttInitiationSuccess") |
| 431 | .onRttInitiationSuccess(); |
| 432 | } else { |
| 433 | Log.w(this, "onRttInitiationSuccess called on a remote conference"); |
| 434 | } |
| 435 | } |
| 436 | |
| 437 | @Override |
| 438 | public void onRttInitiationFailure(String callId, int reason, Session.Info sessionInfo) |
| 439 | throws RemoteException { |
| 440 | if (hasConnection(callId)) { |
| 441 | findConnectionForAction(callId, "onRttInitiationFailure") |
| 442 | .onRttInitiationFailure(reason); |
| 443 | } else { |
| 444 | Log.w(this, "onRttInitiationFailure called on a remote conference"); |
| 445 | } |
| 446 | } |
| 447 | |
| 448 | @Override |
| 449 | public void onRttSessionRemotelyTerminated(String callId, Session.Info sessionInfo) |
| 450 | throws RemoteException { |
| 451 | if (hasConnection(callId)) { |
| 452 | findConnectionForAction(callId, "onRttSessionRemotelyTerminated") |
| 453 | .onRttSessionRemotelyTerminated(); |
| 454 | } else { |
| 455 | Log.w(this, "onRttSessionRemotelyTerminated called on a remote conference"); |
| 456 | } |
| 457 | } |
| 458 | |
| 459 | @Override |
| 460 | public void onRemoteRttRequest(String callId, Session.Info sessionInfo) |
| 461 | throws RemoteException { |
| 462 | if (hasConnection(callId)) { |
| 463 | findConnectionForAction(callId, "onRemoteRttRequest") |
| 464 | .onRemoteRttRequest(); |
| 465 | } else { |
| 466 | Log.w(this, "onRemoteRttRequest called on a remote conference"); |
| 467 | } |
| 468 | } |
Mengjun Leng | 2570774 | 2017-07-04 11:10:37 +0800 | [diff] [blame] | 469 | |
| 470 | @Override |
| 471 | public void resetConnectionTime(String callId, Session.Info sessionInfo) { |
| 472 | // Do nothing |
| 473 | } |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 474 | }; |
| 475 | |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 476 | private final ConnectionServiceAdapterServant mServant = |
| 477 | new ConnectionServiceAdapterServant(mServantDelegate); |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 478 | |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 479 | private final DeathRecipient mDeathRecipient = new DeathRecipient() { |
| 480 | @Override |
| 481 | public void binderDied() { |
| 482 | for (RemoteConnection c : mConnectionById.values()) { |
| 483 | c.setDestroyed(); |
| 484 | } |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 485 | for (RemoteConference c : mConferenceById.values()) { |
| 486 | c.setDestroyed(); |
| 487 | } |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 488 | mConnectionById.clear(); |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 489 | mConferenceById.clear(); |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 490 | mPendingConnections.clear(); |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 491 | mOutgoingConnectionServiceRpc.asBinder().unlinkToDeath(mDeathRecipient, 0); |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 492 | } |
| 493 | }; |
| 494 | |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 495 | private final IConnectionService mOutgoingConnectionServiceRpc; |
| 496 | private final ConnectionService mOurConnectionServiceImpl; |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 497 | private final Map<String, RemoteConnection> mConnectionById = new HashMap<>(); |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 498 | private final Map<String, RemoteConference> mConferenceById = new HashMap<>(); |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 499 | private final Set<RemoteConnection> mPendingConnections = new HashSet<>(); |
| 500 | |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 501 | RemoteConnectionService( |
| 502 | IConnectionService outgoingConnectionServiceRpc, |
| 503 | ConnectionService ourConnectionServiceImpl) throws RemoteException { |
| 504 | mOutgoingConnectionServiceRpc = outgoingConnectionServiceRpc; |
| 505 | mOutgoingConnectionServiceRpc.asBinder().linkToDeath(mDeathRecipient, 0); |
| 506 | mOurConnectionServiceImpl = ourConnectionServiceImpl; |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 507 | } |
| 508 | |
| 509 | @Override |
| 510 | public String toString() { |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 511 | return "[RemoteCS - " + mOutgoingConnectionServiceRpc.asBinder().toString() + "]"; |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 512 | } |
| 513 | |
Ihab Awad | f8b6988 | 2014-07-25 15:14:01 -0700 | [diff] [blame] | 514 | final RemoteConnection createRemoteConnection( |
| 515 | PhoneAccountHandle connectionManagerPhoneAccount, |
| 516 | ConnectionRequest request, |
| 517 | boolean isIncoming) { |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 518 | final String id = UUID.randomUUID().toString(); |
Hall Liu | 95d5587 | 2017-01-25 17:12:49 -0800 | [diff] [blame] | 519 | final ConnectionRequest newRequest = new ConnectionRequest.Builder() |
| 520 | .setAccountHandle(request.getAccountHandle()) |
| 521 | .setAddress(request.getAddress()) |
| 522 | .setExtras(request.getExtras()) |
| 523 | .setVideoState(request.getVideoState()) |
| 524 | .setRttPipeFromInCall(request.getRttPipeFromInCall()) |
| 525 | .setRttPipeToInCall(request.getRttPipeToInCall()) |
| 526 | .build(); |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 527 | try { |
Ihab Awad | 8aecfed | 2014-08-08 17:06:11 -0700 | [diff] [blame] | 528 | if (mConnectionById.isEmpty()) { |
Brad Ebinger | b32d4f8 | 2016-10-24 16:40:49 -0700 | [diff] [blame] | 529 | mOutgoingConnectionServiceRpc.addConnectionServiceAdapter(mServant.getStub(), |
| 530 | null /*Session.Info*/); |
Ihab Awad | 8aecfed | 2014-08-08 17:06:11 -0700 | [diff] [blame] | 531 | } |
| 532 | RemoteConnection connection = |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 533 | new RemoteConnection(id, mOutgoingConnectionServiceRpc, newRequest); |
Ihab Awad | 8aecfed | 2014-08-08 17:06:11 -0700 | [diff] [blame] | 534 | mPendingConnections.add(connection); |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 535 | mConnectionById.put(id, connection); |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 536 | mOutgoingConnectionServiceRpc.createConnection( |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 537 | connectionManagerPhoneAccount, |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 538 | id, |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 539 | newRequest, |
Yorke Lee | c3cf982 | 2014-10-02 09:38:39 -0700 | [diff] [blame] | 540 | isIncoming, |
Brad Ebinger | b32d4f8 | 2016-10-24 16:40:49 -0700 | [diff] [blame] | 541 | false /* isUnknownCall */, |
| 542 | null /*Session.info*/); |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 543 | connection.registerCallback(new RemoteConnection.Callback() { |
Ihab Awad | 8aecfed | 2014-08-08 17:06:11 -0700 | [diff] [blame] | 544 | @Override |
| 545 | public void onDestroyed(RemoteConnection connection) { |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 546 | mConnectionById.remove(id); |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 547 | maybeDisconnectAdapter(); |
Ihab Awad | 8aecfed | 2014-08-08 17:06:11 -0700 | [diff] [blame] | 548 | } |
| 549 | }); |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 550 | return connection; |
| 551 | } catch (RemoteException e) { |
Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame] | 552 | return RemoteConnection.failure( |
| 553 | new DisconnectCause(DisconnectCause.ERROR, e.toString())); |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 554 | } |
| 555 | } |
| 556 | |
Ihab Awad | 50e3506 | 2014-09-30 09:17:03 -0700 | [diff] [blame] | 557 | private boolean hasConnection(String callId) { |
mike dooley | 879142b | 2014-10-08 13:39:28 -0700 | [diff] [blame] | 558 | return mConnectionById.containsKey(callId); |
Ihab Awad | 50e3506 | 2014-09-30 09:17:03 -0700 | [diff] [blame] | 559 | } |
| 560 | |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 561 | private RemoteConnection findConnectionForAction( |
| 562 | String callId, String action) { |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 563 | if (mConnectionById.containsKey(callId)) { |
| 564 | return mConnectionById.get(callId); |
| 565 | } |
| 566 | Log.w(this, "%s - Cannot find Connection %s", action, callId); |
| 567 | return NULL_CONNECTION; |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 568 | } |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 569 | |
| 570 | private RemoteConference findConferenceForAction( |
| 571 | String callId, String action) { |
| 572 | if (mConferenceById.containsKey(callId)) { |
| 573 | return mConferenceById.get(callId); |
| 574 | } |
| 575 | Log.w(this, "%s - Cannot find Conference %s", action, callId); |
| 576 | return NULL_CONFERENCE; |
| 577 | } |
| 578 | |
| 579 | private void maybeDisconnectAdapter() { |
| 580 | if (mConnectionById.isEmpty() && mConferenceById.isEmpty()) { |
| 581 | try { |
Brad Ebinger | b32d4f8 | 2016-10-24 16:40:49 -0700 | [diff] [blame] | 582 | mOutgoingConnectionServiceRpc.removeConnectionServiceAdapter(mServant.getStub(), |
| 583 | null /*Session.info*/); |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 584 | } catch (RemoteException e) { |
| 585 | } |
| 586 | } |
| 587 | } |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 588 | } |