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