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; |
Junho | edf3d82 | 2022-11-24 09:26:37 +0000 | [diff] [blame] | 24 | import android.os.ResultReceiver; |
Brad Ebinger | 4d75bee | 2016-10-28 12:29:55 -0700 | [diff] [blame] | 25 | import android.telecom.Logging.Session; |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 26 | |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 27 | import com.android.internal.telecom.IConnectionService; |
| 28 | import com.android.internal.telecom.IConnectionServiceAdapter; |
| 29 | import com.android.internal.telecom.IVideoProvider; |
| 30 | import com.android.internal.telecom.RemoteServiceCallback; |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 31 | |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 32 | import java.util.ArrayList; |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 33 | import java.util.HashMap; |
| 34 | import java.util.HashSet; |
Grace Jia | 9a09c67 | 2020-08-04 12:52:09 -0700 | [diff] [blame] | 35 | import java.util.List; |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 36 | import java.util.Map; |
| 37 | import java.util.Set; |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 38 | import java.util.UUID; |
| 39 | |
| 40 | /** |
| 41 | * 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] | 42 | * |
| 43 | * @hide |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 44 | */ |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 45 | final class RemoteConnectionService { |
Sailesh Nepal | 4803159 | 2014-07-18 14:21:23 -0700 | [diff] [blame] | 46 | |
Tyler Gunn | 4a57b9b | 2014-10-30 14:27:48 -0700 | [diff] [blame] | 47 | // Note: Casting null to avoid ambiguous constructor reference. |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 48 | private static final RemoteConnection NULL_CONNECTION = |
Tyler Gunn | 4a57b9b | 2014-10-30 14:27:48 -0700 | [diff] [blame] | 49 | new RemoteConnection("NULL", null, (ConnectionRequest) null); |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 50 | |
| 51 | private static final RemoteConference NULL_CONFERENCE = |
| 52 | new RemoteConference("NULL", null); |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 53 | |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 54 | private final IConnectionServiceAdapter mServantDelegate = new IConnectionServiceAdapter() { |
Sailesh Nepal | 4803159 | 2014-07-18 14:21:23 -0700 | [diff] [blame] | 55 | @Override |
Ihab Awad | 6107bab | 2014-08-18 09:23:25 -0700 | [diff] [blame] | 56 | public void handleCreateConnectionComplete( |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 57 | String id, |
| 58 | ConnectionRequest request, |
Brad Ebinger | 4d75bee | 2016-10-28 12:29:55 -0700 | [diff] [blame] | 59 | ParcelableConnection parcel, |
| 60 | Session.Info info) { |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 61 | RemoteConnection connection = |
| 62 | findConnectionForAction(id, "handleCreateConnectionSuccessful"); |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 63 | if (connection != NULL_CONNECTION && mPendingConnections.contains(connection)) { |
| 64 | mPendingConnections.remove(connection); |
Ihab Awad | 6107bab | 2014-08-18 09:23:25 -0700 | [diff] [blame] | 65 | // Unconditionally initialize the connection ... |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 66 | connection.setConnectionCapabilities(parcel.getConnectionCapabilities()); |
Tyler Gunn | 720c664 | 2016-03-22 09:02:47 -0700 | [diff] [blame] | 67 | connection.setConnectionProperties(parcel.getConnectionProperties()); |
Sailesh Nepal | 2d3ced7 | 2015-01-31 20:17:35 -0800 | [diff] [blame] | 68 | if (parcel.getHandle() != null |
| 69 | || parcel.getState() != Connection.STATE_DISCONNECTED) { |
| 70 | connection.setAddress(parcel.getHandle(), parcel.getHandlePresentation()); |
| 71 | } |
| 72 | if (parcel.getCallerDisplayName() != null |
| 73 | || parcel.getState() != Connection.STATE_DISCONNECTED) { |
| 74 | connection.setCallerDisplayName( |
| 75 | parcel.getCallerDisplayName(), |
| 76 | parcel.getCallerDisplayNamePresentation()); |
| 77 | } |
Sailesh Nepal | 70638f1 | 2014-09-09 21:49:14 -0700 | [diff] [blame] | 78 | // Set state after handle so that the client can identify the connection. |
Sailesh Nepal | c2a978d | 2014-09-20 18:23:05 -0700 | [diff] [blame] | 79 | if (parcel.getState() == Connection.STATE_DISCONNECTED) { |
| 80 | connection.setDisconnected(parcel.getDisconnectCause()); |
| 81 | } else { |
| 82 | connection.setState(parcel.getState()); |
| 83 | } |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 84 | List<RemoteConnection> conferenceable = new ArrayList<>(); |
| 85 | for (String confId : parcel.getConferenceableConnectionIds()) { |
| 86 | if (mConnectionById.containsKey(confId)) { |
| 87 | conferenceable.add(mConnectionById.get(confId)); |
| 88 | } |
| 89 | } |
| 90 | connection.setConferenceableConnections(conferenceable); |
Ihab Awad | a64627c | 2014-08-20 09:36:40 -0700 | [diff] [blame] | 91 | connection.setVideoState(parcel.getVideoState()); |
Ihab Awad | 6107bab | 2014-08-18 09:23:25 -0700 | [diff] [blame] | 92 | if (connection.getState() == Connection.STATE_DISCONNECTED) { |
| 93 | // ... then, if it was created in a disconnected state, that indicates |
| 94 | // failure on the providing end, so immediately mark it destroyed |
| 95 | connection.setDestroyed(); |
| 96 | } |
Tyler Gunn | 31f0e0b | 2018-02-13 08:39:45 -0800 | [diff] [blame] | 97 | connection.setStatusHints(parcel.getStatusHints()); |
| 98 | connection.setIsVoipAudioMode(parcel.getIsVoipAudioMode()); |
| 99 | connection.setRingbackRequested(parcel.isRingbackRequested()); |
| 100 | connection.putExtras(parcel.getExtras()); |
Sailesh Nepal | 4803159 | 2014-07-18 14:21:23 -0700 | [diff] [blame] | 101 | } |
| 102 | } |
Sailesh Nepal | 2ab88cc | 2014-07-18 14:49:18 -0700 | [diff] [blame] | 103 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 104 | @Override |
Ravi Paluri | 80aa214 | 2019-12-02 11:57:37 +0530 | [diff] [blame] | 105 | public void handleCreateConferenceComplete( |
| 106 | String id, |
| 107 | ConnectionRequest request, |
| 108 | ParcelableConference parcel, |
| 109 | Session.Info info) { |
| 110 | } |
| 111 | |
| 112 | @Override |
Brad Ebinger | 4d75bee | 2016-10-28 12:29:55 -0700 | [diff] [blame] | 113 | public void setActive(String callId, Session.Info sessionInfo) { |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 114 | if (mConnectionById.containsKey(callId)) { |
| 115 | findConnectionForAction(callId, "setActive") |
| 116 | .setState(Connection.STATE_ACTIVE); |
| 117 | } else { |
| 118 | findConferenceForAction(callId, "setActive") |
| 119 | .setState(Connection.STATE_ACTIVE); |
| 120 | } |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 121 | } |
| 122 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 123 | @Override |
Brad Ebinger | 4d75bee | 2016-10-28 12:29:55 -0700 | [diff] [blame] | 124 | public void setRinging(String callId, Session.Info sessionInfo) { |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 125 | findConnectionForAction(callId, "setRinging") |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 126 | .setState(Connection.STATE_RINGING); |
Andrew Lee | 5ffbe8b8 | 2014-06-20 16:29:33 -0700 | [diff] [blame] | 127 | } |
| 128 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 129 | @Override |
Brad Ebinger | 4d75bee | 2016-10-28 12:29:55 -0700 | [diff] [blame] | 130 | public void setDialing(String callId, Session.Info sessionInfo) { |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 131 | findConnectionForAction(callId, "setDialing") |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 132 | .setState(Connection.STATE_DIALING); |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 133 | } |
| 134 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 135 | @Override |
Brad Ebinger | 4d75bee | 2016-10-28 12:29:55 -0700 | [diff] [blame] | 136 | public void setPulling(String callId, Session.Info sessionInfo) { |
Tyler Gunn | c96b5e0 | 2016-07-07 22:53:57 -0700 | [diff] [blame] | 137 | findConnectionForAction(callId, "setPulling") |
| 138 | .setState(Connection.STATE_PULLING_CALL); |
| 139 | } |
| 140 | |
| 141 | @Override |
Brad Ebinger | 4d75bee | 2016-10-28 12:29:55 -0700 | [diff] [blame] | 142 | public void setDisconnected(String callId, DisconnectCause disconnectCause, |
| 143 | Session.Info sessionInfo) { |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 144 | if (mConnectionById.containsKey(callId)) { |
| 145 | findConnectionForAction(callId, "setDisconnected") |
Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame] | 146 | .setDisconnected(disconnectCause); |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 147 | } else { |
| 148 | findConferenceForAction(callId, "setDisconnected") |
Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame] | 149 | .setDisconnected(disconnectCause); |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 150 | } |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 151 | } |
| 152 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 153 | @Override |
Brad Ebinger | 4d75bee | 2016-10-28 12:29:55 -0700 | [diff] [blame] | 154 | public void setOnHold(String callId, Session.Info sessionInfo) { |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 155 | if (mConnectionById.containsKey(callId)) { |
| 156 | findConnectionForAction(callId, "setOnHold") |
| 157 | .setState(Connection.STATE_HOLDING); |
| 158 | } else { |
| 159 | findConferenceForAction(callId, "setOnHold") |
| 160 | .setState(Connection.STATE_HOLDING); |
| 161 | } |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 162 | } |
| 163 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 164 | @Override |
Brad Ebinger | 4d75bee | 2016-10-28 12:29:55 -0700 | [diff] [blame] | 165 | public void setRingbackRequested(String callId, boolean ringing, Session.Info sessionInfo) { |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 166 | findConnectionForAction(callId, "setRingbackRequested") |
| 167 | .setRingbackRequested(ringing); |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 168 | } |
| 169 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 170 | @Override |
Brad Ebinger | 4d75bee | 2016-10-28 12:29:55 -0700 | [diff] [blame] | 171 | public void setConnectionCapabilities(String callId, int connectionCapabilities, |
| 172 | Session.Info sessionInfo) { |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 173 | if (mConnectionById.containsKey(callId)) { |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 174 | findConnectionForAction(callId, "setConnectionCapabilities") |
| 175 | .setConnectionCapabilities(connectionCapabilities); |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 176 | } else { |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 177 | findConferenceForAction(callId, "setConnectionCapabilities") |
| 178 | .setConnectionCapabilities(connectionCapabilities); |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 179 | } |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 180 | } |
| 181 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 182 | @Override |
Brad Ebinger | 4d75bee | 2016-10-28 12:29:55 -0700 | [diff] [blame] | 183 | public void setConnectionProperties(String callId, int connectionProperties, |
| 184 | Session.Info sessionInfo) { |
Tyler Gunn | 720c664 | 2016-03-22 09:02:47 -0700 | [diff] [blame] | 185 | if (mConnectionById.containsKey(callId)) { |
| 186 | findConnectionForAction(callId, "setConnectionProperties") |
| 187 | .setConnectionProperties(connectionProperties); |
| 188 | } else { |
| 189 | findConferenceForAction(callId, "setConnectionProperties") |
| 190 | .setConnectionProperties(connectionProperties); |
| 191 | } |
| 192 | } |
| 193 | |
| 194 | @Override |
Brad Ebinger | 4d75bee | 2016-10-28 12:29:55 -0700 | [diff] [blame] | 195 | public void setIsConferenced(String callId, String conferenceCallId, |
| 196 | Session.Info sessionInfo) { |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 197 | // Note: callId should not be null; conferenceCallId may be null |
| 198 | RemoteConnection connection = |
| 199 | findConnectionForAction(callId, "setIsConferenced"); |
| 200 | if (connection != NULL_CONNECTION) { |
| 201 | if (conferenceCallId == null) { |
| 202 | // 'connection' is being split from its conference |
| 203 | if (connection.getConference() != null) { |
| 204 | connection.getConference().removeConnection(connection); |
| 205 | } |
| 206 | } else { |
| 207 | RemoteConference conference = |
| 208 | findConferenceForAction(conferenceCallId, "setIsConferenced"); |
| 209 | if (conference != NULL_CONFERENCE) { |
| 210 | conference.addConnection(connection); |
| 211 | } |
| 212 | } |
| 213 | } |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 214 | } |
| 215 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 216 | @Override |
Brad Ebinger | 4d75bee | 2016-10-28 12:29:55 -0700 | [diff] [blame] | 217 | public void setConferenceMergeFailed(String callId, Session.Info sessionInfo) { |
Anthony Lee | 17455a3 | 2015-04-24 15:25:29 -0700 | [diff] [blame] | 218 | // Nothing to do here. |
| 219 | // The event has already been handled and there is no state to update |
| 220 | // in the underlying connection or conference objects |
| 221 | } |
| 222 | |
| 223 | @Override |
Srikanth Chintala | fcb1501 | 2017-05-04 20:58:34 +0530 | [diff] [blame] | 224 | public void onPhoneAccountChanged(String callId, PhoneAccountHandle pHandle, |
| 225 | Session.Info sessionInfo) { |
| 226 | } |
| 227 | |
| 228 | @Override |
Pengquan Meng | 63d25a5 | 2017-11-21 18:01:13 -0800 | [diff] [blame] | 229 | public void onConnectionServiceFocusReleased(Session.Info sessionInfo) {} |
| 230 | |
| 231 | @Override |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 232 | public void addConferenceCall( |
Brad Ebinger | 4d75bee | 2016-10-28 12:29:55 -0700 | [diff] [blame] | 233 | final String callId, ParcelableConference parcel, Session.Info sessionInfo) { |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 234 | RemoteConference conference = new RemoteConference(callId, |
| 235 | mOutgoingConnectionServiceRpc); |
| 236 | |
| 237 | for (String id : parcel.getConnectionIds()) { |
| 238 | RemoteConnection c = mConnectionById.get(id); |
| 239 | if (c != null) { |
| 240 | conference.addConnection(c); |
| 241 | } |
| 242 | } |
Tyler Gunn | 2d4fcc1 | 2021-06-24 11:25:07 -0700 | [diff] [blame] | 243 | // We used to skip adding empty conferences; however in the world of IMS conference |
| 244 | // calls we need to add them to the remote connection service because they will always |
| 245 | // start with no participants. |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 246 | |
| 247 | conference.setState(parcel.getState()); |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 248 | conference.setConnectionCapabilities(parcel.getConnectionCapabilities()); |
Tyler Gunn | 04ce757 | 2016-08-15 10:56:12 -0700 | [diff] [blame] | 249 | conference.setConnectionProperties(parcel.getConnectionProperties()); |
Tyler Gunn | cd6ccfd | 2016-10-17 15:48:19 -0700 | [diff] [blame] | 250 | conference.putExtras(parcel.getExtras()); |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 251 | mConferenceById.put(callId, conference); |
Tyler Gunn | cd6ccfd | 2016-10-17 15:48:19 -0700 | [diff] [blame] | 252 | |
| 253 | // Stash the original connection ID as it exists in the source ConnectionService. |
| 254 | // Telecom will use this to avoid adding duplicates later. |
| 255 | // See comments on Connection.EXTRA_ORIGINAL_CONNECTION_ID for more information. |
| 256 | Bundle newExtras = new Bundle(); |
| 257 | newExtras.putString(Connection.EXTRA_ORIGINAL_CONNECTION_ID, callId); |
Tyler Gunn | c59fd0c | 2020-04-17 14:03:35 -0700 | [diff] [blame] | 258 | // Track the fact this request was relayed through the remote connection service. |
| 259 | newExtras.putParcelable(Connection.EXTRA_REMOTE_PHONE_ACCOUNT_HANDLE, |
| 260 | parcel.getPhoneAccount()); |
Tyler Gunn | cd6ccfd | 2016-10-17 15:48:19 -0700 | [diff] [blame] | 261 | conference.putExtras(newExtras); |
| 262 | |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 263 | conference.registerCallback(new RemoteConference.Callback() { |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 264 | @Override |
| 265 | public void onDestroyed(RemoteConference c) { |
| 266 | mConferenceById.remove(callId); |
| 267 | maybeDisconnectAdapter(); |
| 268 | } |
| 269 | }); |
| 270 | |
| 271 | mOurConnectionServiceImpl.addRemoteConference(conference); |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 272 | } |
| 273 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 274 | @Override |
Brad Ebinger | 4d75bee | 2016-10-28 12:29:55 -0700 | [diff] [blame] | 275 | public void removeCall(String callId, Session.Info sessionInfo) { |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 276 | if (mConnectionById.containsKey(callId)) { |
| 277 | findConnectionForAction(callId, "removeCall") |
| 278 | .setDestroyed(); |
| 279 | } else { |
| 280 | findConferenceForAction(callId, "removeCall") |
| 281 | .setDestroyed(); |
| 282 | } |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 283 | } |
| 284 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 285 | @Override |
Brad Ebinger | 4d75bee | 2016-10-28 12:29:55 -0700 | [diff] [blame] | 286 | public void onPostDialWait(String callId, String remaining, Session.Info sessionInfo) { |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 287 | findConnectionForAction(callId, "onPostDialWait") |
| 288 | .setPostDialWait(remaining); |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 289 | } |
| 290 | |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 291 | @Override |
Brad Ebinger | 4d75bee | 2016-10-28 12:29:55 -0700 | [diff] [blame] | 292 | public void onPostDialChar(String callId, char nextChar, Session.Info sessionInfo) { |
Nancy Chen | 27d1c2d | 2014-12-15 16:12:50 -0800 | [diff] [blame] | 293 | findConnectionForAction(callId, "onPostDialChar") |
| 294 | .onPostDialChar(nextChar); |
| 295 | } |
| 296 | |
| 297 | @Override |
Brad Ebinger | 4d75bee | 2016-10-28 12:29:55 -0700 | [diff] [blame] | 298 | public void queryRemoteConnectionServices(RemoteServiceCallback callback, |
Tyler Gunn | 4c69fb3 | 2019-05-17 10:49:16 -0700 | [diff] [blame] | 299 | String callingPackage, Session.Info sessionInfo) { |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 300 | // Not supported from remote connection service. |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 301 | } |
Tyler Gunn | 8d83fa9 | 2014-07-01 11:31:21 -0700 | [diff] [blame] | 302 | |
Sailesh Nepal | 33aaae4 | 2014-07-07 22:49:44 -0700 | [diff] [blame] | 303 | @Override |
Brad Ebinger | 4d75bee | 2016-10-28 12:29:55 -0700 | [diff] [blame] | 304 | public void setVideoProvider(String callId, IVideoProvider videoProvider, |
| 305 | Session.Info sessionInfo) { |
Tyler Gunn | bf9c6fd | 2016-11-09 10:19:23 -0800 | [diff] [blame] | 306 | |
| 307 | String callingPackage = mOurConnectionServiceImpl.getApplicationContext() |
| 308 | .getOpPackageName(); |
Tyler Gunn | 159f35c | 2017-03-02 09:28:37 -0800 | [diff] [blame] | 309 | int targetSdkVersion = mOurConnectionServiceImpl.getApplicationInfo().targetSdkVersion; |
Sailesh Nepal | 11aeae5 | 2015-01-28 16:54:09 -0800 | [diff] [blame] | 310 | RemoteConnection.VideoProvider remoteVideoProvider = null; |
| 311 | if (videoProvider != null) { |
Tyler Gunn | bf9c6fd | 2016-11-09 10:19:23 -0800 | [diff] [blame] | 312 | remoteVideoProvider = new RemoteConnection.VideoProvider(videoProvider, |
Tyler Gunn | 159f35c | 2017-03-02 09:28:37 -0800 | [diff] [blame] | 313 | callingPackage, targetSdkVersion); |
Sailesh Nepal | 11aeae5 | 2015-01-28 16:54:09 -0800 | [diff] [blame] | 314 | } |
Ihab Awad | a64627c | 2014-08-20 09:36:40 -0700 | [diff] [blame] | 315 | findConnectionForAction(callId, "setVideoProvider") |
Sailesh Nepal | 11aeae5 | 2015-01-28 16:54:09 -0800 | [diff] [blame] | 316 | .setVideoProvider(remoteVideoProvider); |
Tyler Gunn | aa07df8 | 2014-07-17 07:50:22 -0700 | [diff] [blame] | 317 | } |
| 318 | |
| 319 | @Override |
Brad Ebinger | 4d75bee | 2016-10-28 12:29:55 -0700 | [diff] [blame] | 320 | public void setVideoState(String callId, int videoState, Session.Info sessionInfo) { |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 321 | findConnectionForAction(callId, "setVideoState") |
| 322 | .setVideoState(videoState); |
Sailesh Nepal | 33aaae4 | 2014-07-07 22:49:44 -0700 | [diff] [blame] | 323 | } |
Sailesh Nepal | e7ef59a | 2014-07-08 21:48:22 -0700 | [diff] [blame] | 324 | |
Sailesh Nepal | e7ef59a | 2014-07-08 21:48:22 -0700 | [diff] [blame] | 325 | @Override |
Brad Ebinger | 4d75bee | 2016-10-28 12:29:55 -0700 | [diff] [blame] | 326 | public void setIsVoipAudioMode(String callId, boolean isVoip, Session.Info sessionInfo) { |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 327 | findConnectionForAction(callId, "setIsVoipAudioMode") |
| 328 | .setIsVoipAudioMode(isVoip); |
Sailesh Nepal | e7ef59a | 2014-07-08 21:48:22 -0700 | [diff] [blame] | 329 | } |
Sailesh Nepal | 6120386 | 2014-07-11 14:50:13 -0700 | [diff] [blame] | 330 | |
| 331 | @Override |
Brad Ebinger | 4d75bee | 2016-10-28 12:29:55 -0700 | [diff] [blame] | 332 | public void setStatusHints(String callId, StatusHints statusHints, |
| 333 | Session.Info sessionInfo) { |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 334 | findConnectionForAction(callId, "setStatusHints") |
| 335 | .setStatusHints(statusHints); |
Sailesh Nepal | 6120386 | 2014-07-11 14:50:13 -0700 | [diff] [blame] | 336 | } |
| 337 | |
| 338 | @Override |
Brad Ebinger | 4d75bee | 2016-10-28 12:29:55 -0700 | [diff] [blame] | 339 | public void setAddress(String callId, Uri address, int presentation, |
| 340 | Session.Info sessionInfo) { |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 341 | findConnectionForAction(callId, "setAddress") |
| 342 | .setAddress(address, presentation); |
Sailesh Nepal | 6120386 | 2014-07-11 14:50:13 -0700 | [diff] [blame] | 343 | } |
Sailesh Nepal | 2ab88cc | 2014-07-18 14:49:18 -0700 | [diff] [blame] | 344 | |
| 345 | @Override |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 346 | public void setCallerDisplayName(String callId, String callerDisplayName, |
Brad Ebinger | 4d75bee | 2016-10-28 12:29:55 -0700 | [diff] [blame] | 347 | int presentation, Session.Info sessionInfo) { |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 348 | findConnectionForAction(callId, "setCallerDisplayName") |
| 349 | .setCallerDisplayName(callerDisplayName, presentation); |
| 350 | } |
| 351 | |
| 352 | @Override |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 353 | public IBinder asBinder() { |
| 354 | throw new UnsupportedOperationException(); |
Sailesh Nepal | 2ab88cc | 2014-07-18 14:49:18 -0700 | [diff] [blame] | 355 | } |
Santos Cordon | 7c7bc7f | 2014-07-28 18:15:48 -0700 | [diff] [blame] | 356 | |
| 357 | @Override |
Brad Ebinger | 4d75bee | 2016-10-28 12:29:55 -0700 | [diff] [blame] | 358 | public final void setConferenceableConnections(String callId, |
| 359 | List<String> conferenceableConnectionIds, Session.Info sessionInfo) { |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 360 | List<RemoteConnection> conferenceable = new ArrayList<>(); |
| 361 | for (String id : conferenceableConnectionIds) { |
| 362 | if (mConnectionById.containsKey(id)) { |
| 363 | conferenceable.add(mConnectionById.get(id)); |
| 364 | } |
| 365 | } |
Santos Cordon | 7c7bc7f | 2014-07-28 18:15:48 -0700 | [diff] [blame] | 366 | |
Ihab Awad | 50e3506 | 2014-09-30 09:17:03 -0700 | [diff] [blame] | 367 | if (hasConnection(callId)) { |
| 368 | findConnectionForAction(callId, "setConferenceableConnections") |
| 369 | .setConferenceableConnections(conferenceable); |
| 370 | } else { |
| 371 | findConferenceForAction(callId, "setConferenceableConnections") |
| 372 | .setConferenceableConnections(conferenceable); |
| 373 | } |
Santos Cordon | 7c7bc7f | 2014-07-28 18:15:48 -0700 | [diff] [blame] | 374 | } |
Tyler Gunn | 4a57b9b | 2014-10-30 14:27:48 -0700 | [diff] [blame] | 375 | |
| 376 | @Override |
Brad Ebinger | 4d75bee | 2016-10-28 12:29:55 -0700 | [diff] [blame] | 377 | public void addExistingConnection(String callId, ParcelableConnection connection, |
| 378 | Session.Info sessionInfo) { |
Tyler Gunn | 2d4fcc1 | 2021-06-24 11:25:07 -0700 | [diff] [blame] | 379 | Log.i(RemoteConnectionService.this, "addExistingConnection: callId=%s, conn=%s", callId, |
| 380 | connection); |
Tyler Gunn | bf9c6fd | 2016-11-09 10:19:23 -0800 | [diff] [blame] | 381 | String callingPackage = mOurConnectionServiceImpl.getApplicationContext(). |
| 382 | getOpPackageName(); |
Tyler Gunn | 159f35c | 2017-03-02 09:28:37 -0800 | [diff] [blame] | 383 | int callingTargetSdkVersion = mOurConnectionServiceImpl.getApplicationInfo() |
| 384 | .targetSdkVersion; |
Tyler Gunn | cd6ccfd | 2016-10-17 15:48:19 -0700 | [diff] [blame] | 385 | RemoteConnection remoteConnection = new RemoteConnection(callId, |
Tyler Gunn | 159f35c | 2017-03-02 09:28:37 -0800 | [diff] [blame] | 386 | mOutgoingConnectionServiceRpc, connection, callingPackage, |
| 387 | callingTargetSdkVersion); |
Tyler Gunn | c59fd0c | 2020-04-17 14:03:35 -0700 | [diff] [blame] | 388 | // Track that it is via a remote connection. |
| 389 | Bundle newExtras = new Bundle(); |
| 390 | newExtras.putParcelable(Connection.EXTRA_REMOTE_PHONE_ACCOUNT_HANDLE, |
| 391 | connection.getPhoneAccount()); |
Tyler Gunn | 2d4fcc1 | 2021-06-24 11:25:07 -0700 | [diff] [blame] | 392 | if (connection.getParentCallId() != null) { |
| 393 | RemoteConference parentConf = mConferenceById.get(connection.getParentCallId()); |
| 394 | // If there is a parent being set, we need to stash the conference ID here. |
| 395 | // Telephony can add an existing connection while specifying a parent conference. |
| 396 | // There is no equivalent version of that operation as part of the remote connection |
| 397 | // API, so we will stash the pre-defined parent's ID in the extras. When the |
| 398 | // connectionmanager copies over the extras from the remote connection to the |
| 399 | // actual one, it'll get passed to Telecom so that it can make the association. |
| 400 | if (parentConf != null) { |
| 401 | newExtras.putString(Connection.EXTRA_ADD_TO_CONFERENCE_ID, parentConf.getId()); |
| 402 | Log.i(this, "addExistingConnection: stash parent of %s as %s", |
| 403 | connection.getParentCallId(), parentConf.getId()); |
| 404 | } |
| 405 | } |
Tyler Gunn | c59fd0c | 2020-04-17 14:03:35 -0700 | [diff] [blame] | 406 | remoteConnection.putExtras(newExtras); |
Tyler Gunn | cd6ccfd | 2016-10-17 15:48:19 -0700 | [diff] [blame] | 407 | mConnectionById.put(callId, remoteConnection); |
| 408 | remoteConnection.registerCallback(new RemoteConnection.Callback() { |
| 409 | @Override |
| 410 | public void onDestroyed(RemoteConnection connection) { |
| 411 | mConnectionById.remove(callId); |
| 412 | maybeDisconnectAdapter(); |
| 413 | } |
| 414 | }); |
| 415 | mOurConnectionServiceImpl.addRemoteExistingConnection(remoteConnection); |
Tyler Gunn | 4a57b9b | 2014-10-30 14:27:48 -0700 | [diff] [blame] | 416 | } |
Santos Cordon | 6b7f955 | 2015-05-27 17:21:45 -0700 | [diff] [blame] | 417 | |
| 418 | @Override |
Brad Ebinger | 4d75bee | 2016-10-28 12:29:55 -0700 | [diff] [blame] | 419 | public void putExtras(String callId, Bundle extras, Session.Info sessionInfo) { |
Tyler Gunn | dee56a8 | 2016-03-23 16:06:34 -0700 | [diff] [blame] | 420 | if (hasConnection(callId)) { |
| 421 | findConnectionForAction(callId, "putExtras").putExtras(extras); |
Santos Cordon | 6b7f955 | 2015-05-27 17:21:45 -0700 | [diff] [blame] | 422 | } else { |
Tyler Gunn | dee56a8 | 2016-03-23 16:06:34 -0700 | [diff] [blame] | 423 | findConferenceForAction(callId, "putExtras").putExtras(extras); |
| 424 | } |
| 425 | } |
| 426 | |
| 427 | @Override |
Brad Ebinger | 4d75bee | 2016-10-28 12:29:55 -0700 | [diff] [blame] | 428 | public void removeExtras(String callId, List<String> keys, Session.Info sessionInfo) { |
Tyler Gunn | dee56a8 | 2016-03-23 16:06:34 -0700 | [diff] [blame] | 429 | if (hasConnection(callId)) { |
| 430 | findConnectionForAction(callId, "removeExtra").removeExtras(keys); |
| 431 | } else { |
| 432 | findConferenceForAction(callId, "removeExtra").removeExtras(keys); |
Santos Cordon | 6b7f955 | 2015-05-27 17:21:45 -0700 | [diff] [blame] | 433 | } |
| 434 | } |
Tyler Gunn | bd1eb1f | 2016-02-16 14:36:20 -0800 | [diff] [blame] | 435 | |
| 436 | @Override |
Hall Liu | a98f58b5 | 2017-11-07 17:59:28 -0800 | [diff] [blame] | 437 | public void setAudioRoute(String callId, int audioRoute, String bluetoothAddress, |
| 438 | Session.Info sessionInfo) { |
Tyler Gunn | f503543 | 2017-01-09 09:43:12 -0800 | [diff] [blame] | 439 | if (hasConnection(callId)) { |
| 440 | // TODO(3pcalls): handle this for remote connections. |
| 441 | // Likely we don't want to do anything since it doesn't make sense for self-managed |
| 442 | // connections to go through a connection mgr. |
| 443 | } |
| 444 | } |
| 445 | |
| 446 | @Override |
Brad Ebinger | 4d75bee | 2016-10-28 12:29:55 -0700 | [diff] [blame] | 447 | public void onConnectionEvent(String callId, String event, Bundle extras, |
| 448 | Session.Info sessionInfo) { |
Tyler Gunn | bd1eb1f | 2016-02-16 14:36:20 -0800 | [diff] [blame] | 449 | if (mConnectionById.containsKey(callId)) { |
Tyler Gunn | 876dbfb | 2016-03-14 15:18:07 -0700 | [diff] [blame] | 450 | findConnectionForAction(callId, "onConnectionEvent").onConnectionEvent(event, |
| 451 | extras); |
Tyler Gunn | bd1eb1f | 2016-02-16 14:36:20 -0800 | [diff] [blame] | 452 | } |
| 453 | } |
Hall Liu | 57006aa | 2017-02-06 10:49:48 -0800 | [diff] [blame] | 454 | |
| 455 | @Override |
| 456 | public void onRttInitiationSuccess(String callId, Session.Info sessionInfo) |
| 457 | throws RemoteException { |
| 458 | if (hasConnection(callId)) { |
| 459 | findConnectionForAction(callId, "onRttInitiationSuccess") |
| 460 | .onRttInitiationSuccess(); |
| 461 | } else { |
| 462 | Log.w(this, "onRttInitiationSuccess called on a remote conference"); |
| 463 | } |
| 464 | } |
| 465 | |
| 466 | @Override |
| 467 | public void onRttInitiationFailure(String callId, int reason, Session.Info sessionInfo) |
| 468 | throws RemoteException { |
| 469 | if (hasConnection(callId)) { |
| 470 | findConnectionForAction(callId, "onRttInitiationFailure") |
| 471 | .onRttInitiationFailure(reason); |
| 472 | } else { |
| 473 | Log.w(this, "onRttInitiationFailure called on a remote conference"); |
| 474 | } |
| 475 | } |
| 476 | |
| 477 | @Override |
| 478 | public void onRttSessionRemotelyTerminated(String callId, Session.Info sessionInfo) |
| 479 | throws RemoteException { |
| 480 | if (hasConnection(callId)) { |
| 481 | findConnectionForAction(callId, "onRttSessionRemotelyTerminated") |
| 482 | .onRttSessionRemotelyTerminated(); |
| 483 | } else { |
| 484 | Log.w(this, "onRttSessionRemotelyTerminated called on a remote conference"); |
| 485 | } |
| 486 | } |
| 487 | |
| 488 | @Override |
| 489 | public void onRemoteRttRequest(String callId, Session.Info sessionInfo) |
| 490 | throws RemoteException { |
| 491 | if (hasConnection(callId)) { |
| 492 | findConnectionForAction(callId, "onRemoteRttRequest") |
| 493 | .onRemoteRttRequest(); |
| 494 | } else { |
| 495 | Log.w(this, "onRemoteRttRequest called on a remote conference"); |
| 496 | } |
| 497 | } |
Mengjun Leng | 2570774 | 2017-07-04 11:10:37 +0800 | [diff] [blame] | 498 | |
| 499 | @Override |
| 500 | public void resetConnectionTime(String callId, Session.Info sessionInfo) { |
| 501 | // Do nothing |
| 502 | } |
Tyler Gunn | 68a73a4 | 2018-10-03 15:38:57 -0700 | [diff] [blame] | 503 | |
| 504 | @Override |
| 505 | public void setConferenceState(String callId, boolean isConference, |
| 506 | Session.Info sessionInfo) { |
| 507 | // Do nothing |
| 508 | } |
Brad Ebinger | e0c12f4 | 2020-04-08 16:25:12 -0700 | [diff] [blame] | 509 | |
| 510 | @Override |
| 511 | public void setCallDirection(String callId, int direction, Session.Info sessionInfo) { |
| 512 | // Do nothing |
| 513 | } |
Junho | edf3d82 | 2022-11-24 09:26:37 +0000 | [diff] [blame] | 514 | |
| 515 | @Override |
| 516 | public void requestCallEndpointChange(String callId, CallEndpoint endpoint, |
| 517 | ResultReceiver callback, Session.Info sessionInfo) { |
| 518 | // Do nothing |
| 519 | } |
yongnamcha | 8ec5624 | 2022-11-28 06:23:02 +0000 | [diff] [blame] | 520 | |
| 521 | @Override |
| 522 | public void queryLocation(String callId, long timeoutMillis, String provider, |
| 523 | ResultReceiver callback, Session.Info sessionInfo) { |
| 524 | // Do nothing |
| 525 | } |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 526 | }; |
| 527 | |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 528 | private final ConnectionServiceAdapterServant mServant = |
| 529 | new ConnectionServiceAdapterServant(mServantDelegate); |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 530 | |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 531 | private final DeathRecipient mDeathRecipient = new DeathRecipient() { |
| 532 | @Override |
| 533 | public void binderDied() { |
| 534 | for (RemoteConnection c : mConnectionById.values()) { |
| 535 | c.setDestroyed(); |
| 536 | } |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 537 | for (RemoteConference c : mConferenceById.values()) { |
| 538 | c.setDestroyed(); |
| 539 | } |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 540 | mConnectionById.clear(); |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 541 | mConferenceById.clear(); |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 542 | mPendingConnections.clear(); |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 543 | mOutgoingConnectionServiceRpc.asBinder().unlinkToDeath(mDeathRecipient, 0); |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 544 | } |
| 545 | }; |
| 546 | |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 547 | private final IConnectionService mOutgoingConnectionServiceRpc; |
| 548 | private final ConnectionService mOurConnectionServiceImpl; |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 549 | private final Map<String, RemoteConnection> mConnectionById = new HashMap<>(); |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 550 | private final Map<String, RemoteConference> mConferenceById = new HashMap<>(); |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 551 | private final Set<RemoteConnection> mPendingConnections = new HashSet<>(); |
| 552 | |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 553 | RemoteConnectionService( |
| 554 | IConnectionService outgoingConnectionServiceRpc, |
| 555 | ConnectionService ourConnectionServiceImpl) throws RemoteException { |
| 556 | mOutgoingConnectionServiceRpc = outgoingConnectionServiceRpc; |
| 557 | mOutgoingConnectionServiceRpc.asBinder().linkToDeath(mDeathRecipient, 0); |
| 558 | mOurConnectionServiceImpl = ourConnectionServiceImpl; |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 559 | } |
| 560 | |
| 561 | @Override |
| 562 | public String toString() { |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 563 | return "[RemoteCS - " + mOutgoingConnectionServiceRpc.asBinder().toString() + "]"; |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 564 | } |
| 565 | |
Ihab Awad | f8b6988 | 2014-07-25 15:14:01 -0700 | [diff] [blame] | 566 | final RemoteConnection createRemoteConnection( |
| 567 | PhoneAccountHandle connectionManagerPhoneAccount, |
| 568 | ConnectionRequest request, |
| 569 | boolean isIncoming) { |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 570 | final String id = UUID.randomUUID().toString(); |
Tyler Gunn | c59fd0c | 2020-04-17 14:03:35 -0700 | [diff] [blame] | 571 | Bundle extras = new Bundle(); |
| 572 | if (request.getExtras() != null) { |
| 573 | extras.putAll(request.getExtras()); |
| 574 | } |
| 575 | // We will set the package name for the originator of the remote request; this lets the |
| 576 | // receiving ConnectionService know that the request originated from a remote connection |
| 577 | // service so that it can provide tracking information for Telecom. |
| 578 | extras.putString(Connection.EXTRA_REMOTE_CONNECTION_ORIGINATING_PACKAGE_NAME, |
| 579 | mOurConnectionServiceImpl.getApplicationContext().getOpPackageName()); |
| 580 | |
Hall Liu | 95d5587 | 2017-01-25 17:12:49 -0800 | [diff] [blame] | 581 | final ConnectionRequest newRequest = new ConnectionRequest.Builder() |
| 582 | .setAccountHandle(request.getAccountHandle()) |
| 583 | .setAddress(request.getAddress()) |
Tyler Gunn | c59fd0c | 2020-04-17 14:03:35 -0700 | [diff] [blame] | 584 | .setExtras(extras) |
Hall Liu | 95d5587 | 2017-01-25 17:12:49 -0800 | [diff] [blame] | 585 | .setVideoState(request.getVideoState()) |
| 586 | .setRttPipeFromInCall(request.getRttPipeFromInCall()) |
| 587 | .setRttPipeToInCall(request.getRttPipeToInCall()) |
| 588 | .build(); |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 589 | try { |
Ihab Awad | 8aecfed | 2014-08-08 17:06:11 -0700 | [diff] [blame] | 590 | if (mConnectionById.isEmpty()) { |
Brad Ebinger | b32d4f8 | 2016-10-24 16:40:49 -0700 | [diff] [blame] | 591 | mOutgoingConnectionServiceRpc.addConnectionServiceAdapter(mServant.getStub(), |
| 592 | null /*Session.Info*/); |
Ihab Awad | 8aecfed | 2014-08-08 17:06:11 -0700 | [diff] [blame] | 593 | } |
| 594 | RemoteConnection connection = |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 595 | new RemoteConnection(id, mOutgoingConnectionServiceRpc, newRequest); |
Ihab Awad | 8aecfed | 2014-08-08 17:06:11 -0700 | [diff] [blame] | 596 | mPendingConnections.add(connection); |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 597 | mConnectionById.put(id, connection); |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 598 | mOutgoingConnectionServiceRpc.createConnection( |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 599 | connectionManagerPhoneAccount, |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 600 | id, |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 601 | newRequest, |
Yorke Lee | c3cf982 | 2014-10-02 09:38:39 -0700 | [diff] [blame] | 602 | isIncoming, |
Brad Ebinger | b32d4f8 | 2016-10-24 16:40:49 -0700 | [diff] [blame] | 603 | false /* isUnknownCall */, |
| 604 | null /*Session.info*/); |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 605 | connection.registerCallback(new RemoteConnection.Callback() { |
Ihab Awad | 8aecfed | 2014-08-08 17:06:11 -0700 | [diff] [blame] | 606 | @Override |
| 607 | public void onDestroyed(RemoteConnection connection) { |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 608 | mConnectionById.remove(id); |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 609 | maybeDisconnectAdapter(); |
Ihab Awad | 8aecfed | 2014-08-08 17:06:11 -0700 | [diff] [blame] | 610 | } |
| 611 | }); |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 612 | return connection; |
| 613 | } catch (RemoteException e) { |
Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame] | 614 | return RemoteConnection.failure( |
| 615 | new DisconnectCause(DisconnectCause.ERROR, e.toString())); |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 616 | } |
| 617 | } |
| 618 | |
Grace Jia | 9a09c67 | 2020-08-04 12:52:09 -0700 | [diff] [blame] | 619 | RemoteConference createRemoteConference( |
| 620 | PhoneAccountHandle connectionManagerPhoneAccount, |
| 621 | ConnectionRequest request, |
| 622 | boolean isIncoming) { |
| 623 | final String id = UUID.randomUUID().toString(); |
| 624 | try { |
| 625 | if (mConferenceById.isEmpty()) { |
| 626 | mOutgoingConnectionServiceRpc.addConnectionServiceAdapter(mServant.getStub(), |
| 627 | null /*Session.Info*/); |
| 628 | } |
| 629 | RemoteConference conference = new RemoteConference(id, mOutgoingConnectionServiceRpc); |
| 630 | mOutgoingConnectionServiceRpc.createConference(connectionManagerPhoneAccount, |
| 631 | id, |
| 632 | request, |
| 633 | isIncoming, |
| 634 | false /* isUnknownCall */, |
| 635 | null /*Session.info*/); |
| 636 | conference.registerCallback(new RemoteConference.Callback() { |
| 637 | @Override |
| 638 | public void onDestroyed(RemoteConference conference) { |
| 639 | mConferenceById.remove(id); |
| 640 | maybeDisconnectAdapter(); |
| 641 | } |
| 642 | }); |
| 643 | conference.putExtras(request.getExtras()); |
| 644 | return conference; |
| 645 | } catch (RemoteException e) { |
| 646 | return RemoteConference.failure( |
| 647 | new DisconnectCause(DisconnectCause.ERROR, e.toString())); |
| 648 | } |
| 649 | } |
| 650 | |
Ihab Awad | 50e3506 | 2014-09-30 09:17:03 -0700 | [diff] [blame] | 651 | private boolean hasConnection(String callId) { |
mike dooley | 879142b | 2014-10-08 13:39:28 -0700 | [diff] [blame] | 652 | return mConnectionById.containsKey(callId); |
Ihab Awad | 50e3506 | 2014-09-30 09:17:03 -0700 | [diff] [blame] | 653 | } |
| 654 | |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 655 | private RemoteConnection findConnectionForAction( |
| 656 | String callId, String action) { |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 657 | if (mConnectionById.containsKey(callId)) { |
| 658 | return mConnectionById.get(callId); |
| 659 | } |
| 660 | Log.w(this, "%s - Cannot find Connection %s", action, callId); |
| 661 | return NULL_CONNECTION; |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 662 | } |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 663 | |
| 664 | private RemoteConference findConferenceForAction( |
| 665 | String callId, String action) { |
| 666 | if (mConferenceById.containsKey(callId)) { |
| 667 | return mConferenceById.get(callId); |
| 668 | } |
| 669 | Log.w(this, "%s - Cannot find Conference %s", action, callId); |
| 670 | return NULL_CONFERENCE; |
| 671 | } |
| 672 | |
| 673 | private void maybeDisconnectAdapter() { |
| 674 | if (mConnectionById.isEmpty() && mConferenceById.isEmpty()) { |
| 675 | try { |
Brad Ebinger | b32d4f8 | 2016-10-24 16:40:49 -0700 | [diff] [blame] | 676 | mOutgoingConnectionServiceRpc.removeConnectionServiceAdapter(mServant.getStub(), |
| 677 | null /*Session.info*/); |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 678 | } catch (RemoteException e) { |
| 679 | } |
| 680 | } |
| 681 | } |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 682 | } |