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