| 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 |
| 14 | * limitations under the License. |
| 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 | |
| Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 19 | import com.android.internal.telecom.IConnectionService; |
| 20 | import com.android.internal.telecom.IVideoCallback; |
| 21 | import com.android.internal.telecom.IVideoProvider; |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 22 | |
| Hall Liu | b64ac4c | 2017-02-06 10:49:48 -0800 | [diff] [blame] | 23 | import android.annotation.NonNull; |
| Santos Cordon | 6b7f955 | 2015-05-27 17:21:45 -0700 | [diff] [blame] | 24 | import android.annotation.Nullable; |
| Yorke Lee | 4af5935 | 2015-05-13 14:14:54 -0700 | [diff] [blame] | 25 | import android.annotation.SystemApi; |
| Tyler Gunn | 295f5d7 | 2015-06-04 11:08:54 -0700 | [diff] [blame] | 26 | import android.hardware.camera2.CameraManager; |
| Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 27 | import android.net.Uri; |
| Santos Cordon | 6b7f955 | 2015-05-27 17:21:45 -0700 | [diff] [blame] | 28 | import android.os.Bundle; |
| Andrew Lee | 011728f | 2015-04-23 15:47:06 -0700 | [diff] [blame] | 29 | import android.os.Handler; |
| Ihab Awad | a64627c | 2014-08-20 09:36:40 -0700 | [diff] [blame] | 30 | import android.os.IBinder; |
| Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 31 | import android.os.RemoteException; |
| Ihab Awad | a64627c | 2014-08-20 09:36:40 -0700 | [diff] [blame] | 32 | import android.view.Surface; |
| Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 33 | |
| Santos Cordon | 7c7bc7f | 2014-07-28 18:15:48 -0700 | [diff] [blame] | 34 | import java.util.ArrayList; |
| Sailesh Nepal | f4669df | 2014-08-14 17:43:13 -0700 | [diff] [blame] | 35 | import java.util.Collections; |
| Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 36 | import java.util.List; |
| Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 37 | import java.util.Set; |
| Sailesh Nepal | f4669df | 2014-08-14 17:43:13 -0700 | [diff] [blame] | 38 | import java.util.concurrent.ConcurrentHashMap; |
| Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 39 | |
| 40 | /** |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 41 | * A connection provided to a {@link ConnectionService} by another {@code ConnectionService} |
| 42 | * running in a different process. |
| 43 | * |
| 44 | * @see ConnectionService#createRemoteOutgoingConnection(PhoneAccountHandle, ConnectionRequest) |
| 45 | * @see ConnectionService#createRemoteIncomingConnection(PhoneAccountHandle, ConnectionRequest) |
| Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 46 | */ |
| 47 | public final class RemoteConnection { |
| Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 48 | |
| Santos Cordon | 895d4b8 | 2015-06-25 16:41:48 -0700 | [diff] [blame] | 49 | /** |
| 50 | * Callback base class for {@link RemoteConnection}. |
| 51 | */ |
| Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 52 | public static abstract class Callback { |
| Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 53 | /** |
| 54 | * Invoked when the state of this {@code RemoteConnection} has changed. See |
| 55 | * {@link #getState()}. |
| 56 | * |
| 57 | * @param connection The {@code RemoteConnection} invoking this method. |
| 58 | * @param state The new state of the {@code RemoteConnection}. |
| 59 | */ |
| Evan Charlton | bf11f98 | 2014-07-20 22:06:28 -0700 | [diff] [blame] | 60 | public void onStateChanged(RemoteConnection connection, int state) {} |
| Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 61 | |
| 62 | /** |
| Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 63 | * Invoked when this {@code RemoteConnection} is disconnected. |
| 64 | * |
| 65 | * @param connection The {@code RemoteConnection} invoking this method. |
| Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame] | 66 | * @param disconnectCause The ({@see DisconnectCause}) associated with this failed |
| 67 | * connection. |
| Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 68 | */ |
| 69 | public void onDisconnected( |
| 70 | RemoteConnection connection, |
| Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame] | 71 | DisconnectCause disconnectCause) {} |
| Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 72 | |
| 73 | /** |
| 74 | * Invoked when this {@code RemoteConnection} is requesting ringback. See |
| Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 75 | * {@link #isRingbackRequested()}. |
| Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 76 | * |
| 77 | * @param connection The {@code RemoteConnection} invoking this method. |
| 78 | * @param ringback Whether the {@code RemoteConnection} is requesting ringback. |
| 79 | */ |
| Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 80 | public void onRingbackRequested(RemoteConnection connection, boolean ringback) {} |
| Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 81 | |
| 82 | /** |
| 83 | * Indicates that the call capabilities of this {@code RemoteConnection} have changed. |
| Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 84 | * See {@link #getConnectionCapabilities()}. |
| Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 85 | * |
| 86 | * @param connection The {@code RemoteConnection} invoking this method. |
| Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 87 | * @param connectionCapabilities The new capabilities of the {@code RemoteConnection}. |
| Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 88 | */ |
| Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 89 | public void onConnectionCapabilitiesChanged( |
| 90 | RemoteConnection connection, |
| 91 | int connectionCapabilities) {} |
| Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 92 | |
| 93 | /** |
| Tyler Gunn | 720c664 | 2016-03-22 09:02:47 -0700 | [diff] [blame] | 94 | * Indicates that the call properties of this {@code RemoteConnection} have changed. |
| 95 | * See {@link #getConnectionProperties()}. |
| 96 | * |
| 97 | * @param connection The {@code RemoteConnection} invoking this method. |
| 98 | * @param connectionProperties The new properties of the {@code RemoteConnection}. |
| 99 | */ |
| 100 | public void onConnectionPropertiesChanged( |
| 101 | RemoteConnection connection, |
| 102 | int connectionProperties) {} |
| 103 | |
| 104 | /** |
| Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 105 | * Invoked when the post-dial sequence in the outgoing {@code Connection} has reached a |
| 106 | * pause character. This causes the post-dial signals to stop pending user confirmation. An |
| 107 | * implementation should present this choice to the user and invoke |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 108 | * {@link RemoteConnection#postDialContinue(boolean)} when the user makes the choice. |
| Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 109 | * |
| 110 | * @param connection The {@code RemoteConnection} invoking this method. |
| 111 | * @param remainingPostDialSequence The post-dial characters that remain to be sent. |
| 112 | */ |
| 113 | public void onPostDialWait(RemoteConnection connection, String remainingPostDialSequence) {} |
| 114 | |
| 115 | /** |
| Nancy Chen | 27d1c2d | 2014-12-15 16:12:50 -0800 | [diff] [blame] | 116 | * Invoked when the post-dial sequence in the outgoing {@code Connection} has processed |
| 117 | * a character. |
| 118 | * |
| 119 | * @param connection The {@code RemoteConnection} invoking this method. |
| 120 | * @param nextChar The character being processed. |
| 121 | */ |
| 122 | public void onPostDialChar(RemoteConnection connection, char nextChar) {} |
| 123 | |
| 124 | /** |
| Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 125 | * Indicates that the VOIP audio status of this {@code RemoteConnection} has changed. |
| Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 126 | * See {@link #isVoipAudioMode()}. |
| Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 127 | * |
| 128 | * @param connection The {@code RemoteConnection} invoking this method. |
| 129 | * @param isVoip Whether the new audio state of the {@code RemoteConnection} is VOIP. |
| 130 | */ |
| Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 131 | public void onVoipAudioChanged(RemoteConnection connection, boolean isVoip) {} |
| Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 132 | |
| 133 | /** |
| 134 | * Indicates that the status hints of this {@code RemoteConnection} have changed. See |
| 135 | * {@link #getStatusHints()} ()}. |
| 136 | * |
| 137 | * @param connection The {@code RemoteConnection} invoking this method. |
| 138 | * @param statusHints The new status hints of the {@code RemoteConnection}. |
| 139 | */ |
| Evan Charlton | bf11f98 | 2014-07-20 22:06:28 -0700 | [diff] [blame] | 140 | public void onStatusHintsChanged(RemoteConnection connection, StatusHints statusHints) {} |
| Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 141 | |
| 142 | /** |
| Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 143 | * Indicates that the address (e.g., phone number) of this {@code RemoteConnection} has |
| 144 | * changed. See {@link #getAddress()} and {@link #getAddressPresentation()}. |
| Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 145 | * |
| 146 | * @param connection The {@code RemoteConnection} invoking this method. |
| Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 147 | * @param address The new address of the {@code RemoteConnection}. |
| 148 | * @param presentation The presentation requirements for the address. |
| Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 149 | * See {@link TelecomManager} for valid values. |
| Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 150 | */ |
| Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 151 | public void onAddressChanged(RemoteConnection connection, Uri address, int presentation) {} |
| Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 152 | |
| 153 | /** |
| 154 | * Indicates that the caller display name of this {@code RemoteConnection} has changed. |
| 155 | * See {@link #getCallerDisplayName()} and {@link #getCallerDisplayNamePresentation()}. |
| 156 | * |
| 157 | * @param connection The {@code RemoteConnection} invoking this method. |
| 158 | * @param callerDisplayName The new caller display name of the {@code RemoteConnection}. |
| Nancy Chen | 9d568c0 | 2014-09-08 14:17:59 -0700 | [diff] [blame] | 159 | * @param presentation The presentation requirements for the handle. |
| Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 160 | * See {@link TelecomManager} for valid values. |
| Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 161 | */ |
| Evan Charlton | bf11f98 | 2014-07-20 22:06:28 -0700 | [diff] [blame] | 162 | public void onCallerDisplayNameChanged( |
| 163 | RemoteConnection connection, String callerDisplayName, int presentation) {} |
| Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 164 | |
| 165 | /** |
| 166 | * Indicates that the video state of this {@code RemoteConnection} has changed. |
| 167 | * See {@link #getVideoState()}. |
| 168 | * |
| 169 | * @param connection The {@code RemoteConnection} invoking this method. |
| 170 | * @param videoState The new video state of the {@code RemoteConnection}. |
| 171 | */ |
| Evan Charlton | bf11f98 | 2014-07-20 22:06:28 -0700 | [diff] [blame] | 172 | public void onVideoStateChanged(RemoteConnection connection, int videoState) {} |
| Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 173 | |
| 174 | /** |
| Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 175 | * Indicates that this {@code RemoteConnection} has been destroyed. No further requests |
| 176 | * should be made to the {@code RemoteConnection}, and references to it should be cleared. |
| 177 | * |
| 178 | * @param connection The {@code RemoteConnection} invoking this method. |
| 179 | */ |
| Evan Charlton | bf11f98 | 2014-07-20 22:06:28 -0700 | [diff] [blame] | 180 | public void onDestroyed(RemoteConnection connection) {} |
| Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 181 | |
| 182 | /** |
| 183 | * Indicates that the {@code RemoteConnection}s with which this {@code RemoteConnection} |
| 184 | * may be asked to create a conference has changed. |
| 185 | * |
| 186 | * @param connection The {@code RemoteConnection} invoking this method. |
| 187 | * @param conferenceableConnections The {@code RemoteConnection}s with which this |
| 188 | * {@code RemoteConnection} may be asked to create a conference. |
| 189 | */ |
| Santos Cordon | 7c7bc7f | 2014-07-28 18:15:48 -0700 | [diff] [blame] | 190 | public void onConferenceableConnectionsChanged( |
| Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 191 | RemoteConnection connection, |
| 192 | List<RemoteConnection> conferenceableConnections) {} |
| 193 | |
| 194 | /** |
| Ihab Awad | a64627c | 2014-08-20 09:36:40 -0700 | [diff] [blame] | 195 | * Indicates that the {@code VideoProvider} associated with this {@code RemoteConnection} |
| 196 | * has changed. |
| 197 | * |
| 198 | * @param connection The {@code RemoteConnection} invoking this method. |
| 199 | * @param videoProvider The new {@code VideoProvider} associated with this |
| 200 | * {@code RemoteConnection}. |
| Ihab Awad | a64627c | 2014-08-20 09:36:40 -0700 | [diff] [blame] | 201 | */ |
| 202 | public void onVideoProviderChanged( |
| 203 | RemoteConnection connection, VideoProvider videoProvider) {} |
| 204 | |
| 205 | /** |
| Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 206 | * Indicates that the {@code RemoteConference} that this {@code RemoteConnection} is a part |
| 207 | * of has changed. |
| 208 | * |
| 209 | * @param connection The {@code RemoteConnection} invoking this method. |
| 210 | * @param conference The {@code RemoteConference} of which this {@code RemoteConnection} is |
| 211 | * a part, which may be {@code null}. |
| 212 | */ |
| 213 | public void onConferenceChanged( |
| 214 | RemoteConnection connection, |
| 215 | RemoteConference conference) {} |
| Santos Cordon | 6b7f955 | 2015-05-27 17:21:45 -0700 | [diff] [blame] | 216 | |
| 217 | /** |
| Santos Cordon | 895d4b8 | 2015-06-25 16:41:48 -0700 | [diff] [blame] | 218 | * Handles changes to the {@code RemoteConnection} extras. |
| Santos Cordon | 6b7f955 | 2015-05-27 17:21:45 -0700 | [diff] [blame] | 219 | * |
| 220 | * @param connection The {@code RemoteConnection} invoking this method. |
| 221 | * @param extras The extras containing other information associated with the connection. |
| 222 | */ |
| 223 | public void onExtrasChanged(RemoteConnection connection, @Nullable Bundle extras) {} |
| Tyler Gunn | bd1eb1f | 2016-02-16 14:36:20 -0800 | [diff] [blame] | 224 | |
| 225 | /** |
| 226 | * Handles a connection event propagated to this {@link RemoteConnection}. |
| Tyler Gunn | 876dbfb | 2016-03-14 15:18:07 -0700 | [diff] [blame] | 227 | * <p> |
| 228 | * Connection events originate from {@link Connection#sendConnectionEvent(String, Bundle)}. |
| Tyler Gunn | bd1eb1f | 2016-02-16 14:36:20 -0800 | [diff] [blame] | 229 | * |
| 230 | * @param connection The {@code RemoteConnection} invoking this method. |
| 231 | * @param event The connection event. |
| Tyler Gunn | 876dbfb | 2016-03-14 15:18:07 -0700 | [diff] [blame] | 232 | * @param extras Extras associated with the event. |
| Tyler Gunn | bd1eb1f | 2016-02-16 14:36:20 -0800 | [diff] [blame] | 233 | */ |
| Tyler Gunn | 876dbfb | 2016-03-14 15:18:07 -0700 | [diff] [blame] | 234 | public void onConnectionEvent(RemoteConnection connection, String event, Bundle extras) {} |
| Hall Liu | b64ac4c | 2017-02-06 10:49:48 -0800 | [diff] [blame] | 235 | |
| 236 | /** |
| 237 | * Indicates that a RTT session was successfully established on this |
| 238 | * {@link RemoteConnection}. See {@link Connection#sendRttInitiationSuccess()}. |
| 239 | * @hide |
| 240 | * @param connection The {@code RemoteConnection} invoking this method. |
| 241 | */ |
| 242 | public void onRttInitiationSuccess(RemoteConnection connection) {} |
| 243 | |
| 244 | /** |
| 245 | * Indicates that a RTT session failed to be established on this |
| 246 | * {@link RemoteConnection}. See {@link Connection#sendRttInitiationFailure()}. |
| 247 | * @hide |
| 248 | * @param connection The {@code RemoteConnection} invoking this method. |
| 249 | * @param reason One of the reason codes defined in {@link Connection.RttModifyStatus}, |
| 250 | * with the exception of |
| 251 | * {@link Connection.RttModifyStatus#SESSION_MODIFY_REQUEST_SUCCESS}. |
| 252 | */ |
| 253 | public void onRttInitiationFailure(RemoteConnection connection, int reason) {} |
| 254 | |
| 255 | /** |
| 256 | * Indicates that an established RTT session was terminated remotely on this |
| 257 | * {@link RemoteConnection}. See {@link Connection#sendRttSessionRemotelyTerminated()} |
| 258 | * @hide |
| 259 | * @param connection The {@code RemoteConnection} invoking this method. |
| 260 | */ |
| 261 | public void onRttSessionRemotelyTerminated(RemoteConnection connection) {} |
| 262 | |
| 263 | /** |
| 264 | * Indicates that the remote user on this {@link RemoteConnection} has requested an upgrade |
| 265 | * to an RTT session. See {@link Connection#sendRemoteRttRequest()} |
| 266 | * @hide |
| 267 | * @param connection The {@code RemoteConnection} invoking this method. |
| 268 | */ |
| 269 | public void onRemoteRttRequest(RemoteConnection connection) {} |
| Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 270 | } |
| 271 | |
| Tyler Gunn | 295f5d7 | 2015-06-04 11:08:54 -0700 | [diff] [blame] | 272 | /** |
| 273 | * {@link RemoteConnection.VideoProvider} associated with a {@link RemoteConnection}. Used to |
| 274 | * receive video related events and control the video associated with a |
| 275 | * {@link RemoteConnection}. |
| 276 | * |
| 277 | * @see Connection.VideoProvider |
| 278 | */ |
| Ihab Awad | a64627c | 2014-08-20 09:36:40 -0700 | [diff] [blame] | 279 | public static class VideoProvider { |
| 280 | |
| Tyler Gunn | 295f5d7 | 2015-06-04 11:08:54 -0700 | [diff] [blame] | 281 | /** |
| 282 | * Callback class used by the {@link RemoteConnection.VideoProvider} to relay events from |
| 283 | * the {@link Connection.VideoProvider}. |
| 284 | */ |
| Tyler Gunn | a2df925 | 2015-05-29 10:05:46 -0700 | [diff] [blame] | 285 | public abstract static class Callback { |
| Tyler Gunn | 295f5d7 | 2015-06-04 11:08:54 -0700 | [diff] [blame] | 286 | /** |
| 287 | * Reports a session modification request received from the |
| 288 | * {@link Connection.VideoProvider} associated with a {@link RemoteConnection}. |
| 289 | * |
| 290 | * @param videoProvider The {@link RemoteConnection.VideoProvider} invoking this method. |
| 291 | * @param videoProfile The requested video call profile. |
| 292 | * @see InCallService.VideoCall.Callback#onSessionModifyRequestReceived(VideoProfile) |
| 293 | * @see Connection.VideoProvider#receiveSessionModifyRequest(VideoProfile) |
| 294 | */ |
| Tyler Gunn | a2df925 | 2015-05-29 10:05:46 -0700 | [diff] [blame] | 295 | public void onSessionModifyRequestReceived( |
| Ihab Awad | a64627c | 2014-08-20 09:36:40 -0700 | [diff] [blame] | 296 | VideoProvider videoProvider, |
| 297 | VideoProfile videoProfile) {} |
| 298 | |
| Tyler Gunn | 295f5d7 | 2015-06-04 11:08:54 -0700 | [diff] [blame] | 299 | /** |
| 300 | * Reports a session modification response received from the |
| 301 | * {@link Connection.VideoProvider} associated with a {@link RemoteConnection}. |
| 302 | * |
| 303 | * @param videoProvider The {@link RemoteConnection.VideoProvider} invoking this method. |
| 304 | * @param status Status of the session modify request. |
| 305 | * @param requestedProfile The original request which was sent to the peer device. |
| 306 | * @param responseProfile The actual profile changes made by the peer device. |
| 307 | * @see InCallService.VideoCall.Callback#onSessionModifyResponseReceived(int, |
| 308 | * VideoProfile, VideoProfile) |
| 309 | * @see Connection.VideoProvider#receiveSessionModifyResponse(int, VideoProfile, |
| 310 | * VideoProfile) |
| 311 | */ |
| Tyler Gunn | a2df925 | 2015-05-29 10:05:46 -0700 | [diff] [blame] | 312 | public void onSessionModifyResponseReceived( |
| Ihab Awad | a64627c | 2014-08-20 09:36:40 -0700 | [diff] [blame] | 313 | VideoProvider videoProvider, |
| 314 | int status, |
| 315 | VideoProfile requestedProfile, |
| 316 | VideoProfile responseProfile) {} |
| 317 | |
| Tyler Gunn | 295f5d7 | 2015-06-04 11:08:54 -0700 | [diff] [blame] | 318 | /** |
| 319 | * Reports a call session event received from the {@link Connection.VideoProvider} |
| 320 | * associated with a {@link RemoteConnection}. |
| 321 | * |
| 322 | * @param videoProvider The {@link RemoteConnection.VideoProvider} invoking this method. |
| 323 | * @param event The event. |
| 324 | * @see InCallService.VideoCall.Callback#onCallSessionEvent(int) |
| 325 | * @see Connection.VideoProvider#handleCallSessionEvent(int) |
| 326 | */ |
| Tyler Gunn | a2df925 | 2015-05-29 10:05:46 -0700 | [diff] [blame] | 327 | public void onCallSessionEvent(VideoProvider videoProvider, int event) {} |
| Ihab Awad | a64627c | 2014-08-20 09:36:40 -0700 | [diff] [blame] | 328 | |
| Tyler Gunn | 295f5d7 | 2015-06-04 11:08:54 -0700 | [diff] [blame] | 329 | /** |
| 330 | * Reports a change in the peer video dimensions received from the |
| 331 | * {@link Connection.VideoProvider} associated with a {@link RemoteConnection}. |
| 332 | * |
| 333 | * @param videoProvider The {@link RemoteConnection.VideoProvider} invoking this method. |
| 334 | * @param width The updated peer video width. |
| 335 | * @param height The updated peer video height. |
| 336 | * @see InCallService.VideoCall.Callback#onPeerDimensionsChanged(int, int) |
| 337 | * @see Connection.VideoProvider#changePeerDimensions(int, int) |
| 338 | */ |
| 339 | public void onPeerDimensionsChanged(VideoProvider videoProvider, int width, |
| 340 | int height) {} |
| Ihab Awad | a64627c | 2014-08-20 09:36:40 -0700 | [diff] [blame] | 341 | |
| Tyler Gunn | 295f5d7 | 2015-06-04 11:08:54 -0700 | [diff] [blame] | 342 | /** |
| 343 | * Reports a change in the data usage (in bytes) received from the |
| 344 | * {@link Connection.VideoProvider} associated with a {@link RemoteConnection}. |
| 345 | * |
| 346 | * @param videoProvider The {@link RemoteConnection.VideoProvider} invoking this method. |
| 347 | * @param dataUsage The updated data usage (in bytes). |
| 348 | * @see InCallService.VideoCall.Callback#onCallDataUsageChanged(long) |
| 349 | * @see Connection.VideoProvider#setCallDataUsage(long) |
| 350 | */ |
| Rekha Kumar | 0736681 | 2015-03-24 16:42:31 -0700 | [diff] [blame] | 351 | public void onCallDataUsageChanged(VideoProvider videoProvider, long dataUsage) {} |
| Ihab Awad | a64627c | 2014-08-20 09:36:40 -0700 | [diff] [blame] | 352 | |
| Tyler Gunn | 295f5d7 | 2015-06-04 11:08:54 -0700 | [diff] [blame] | 353 | /** |
| 354 | * Reports a change in the capabilities of the current camera, received from the |
| 355 | * {@link Connection.VideoProvider} associated with a {@link RemoteConnection}. |
| 356 | * |
| 357 | * @param videoProvider The {@link RemoteConnection.VideoProvider} invoking this method. |
| 358 | * @param cameraCapabilities The changed camera capabilities. |
| 359 | * @see InCallService.VideoCall.Callback#onCameraCapabilitiesChanged( |
| 360 | * VideoProfile.CameraCapabilities) |
| 361 | * @see Connection.VideoProvider#changeCameraCapabilities( |
| 362 | * VideoProfile.CameraCapabilities) |
| 363 | */ |
| Ihab Awad | a64627c | 2014-08-20 09:36:40 -0700 | [diff] [blame] | 364 | public void onCameraCapabilitiesChanged( |
| 365 | VideoProvider videoProvider, |
| Yorke Lee | 400470f | 2015-05-12 13:31:25 -0700 | [diff] [blame] | 366 | VideoProfile.CameraCapabilities cameraCapabilities) {} |
| Rekha Kumar | 0736681 | 2015-03-24 16:42:31 -0700 | [diff] [blame] | 367 | |
| Tyler Gunn | 295f5d7 | 2015-06-04 11:08:54 -0700 | [diff] [blame] | 368 | /** |
| 369 | * Reports a change in the video quality received from the |
| 370 | * {@link Connection.VideoProvider} associated with a {@link RemoteConnection}. |
| 371 | * |
| 372 | * @param videoProvider The {@link RemoteConnection.VideoProvider} invoking this method. |
| 373 | * @param videoQuality The updated peer video quality. |
| 374 | * @see InCallService.VideoCall.Callback#onVideoQualityChanged(int) |
| 375 | * @see Connection.VideoProvider#changeVideoQuality(int) |
| 376 | */ |
| Rekha Kumar | 0736681 | 2015-03-24 16:42:31 -0700 | [diff] [blame] | 377 | public void onVideoQualityChanged(VideoProvider videoProvider, int videoQuality) {} |
| Ihab Awad | a64627c | 2014-08-20 09:36:40 -0700 | [diff] [blame] | 378 | } |
| 379 | |
| 380 | private final IVideoCallback mVideoCallbackDelegate = new IVideoCallback() { |
| 381 | @Override |
| 382 | public void receiveSessionModifyRequest(VideoProfile videoProfile) { |
| Tyler Gunn | a2df925 | 2015-05-29 10:05:46 -0700 | [diff] [blame] | 383 | for (Callback l : mCallbacks) { |
| 384 | l.onSessionModifyRequestReceived(VideoProvider.this, videoProfile); |
| Ihab Awad | a64627c | 2014-08-20 09:36:40 -0700 | [diff] [blame] | 385 | } |
| 386 | } |
| 387 | |
| 388 | @Override |
| 389 | public void receiveSessionModifyResponse(int status, VideoProfile requestedProfile, |
| 390 | VideoProfile responseProfile) { |
| Tyler Gunn | a2df925 | 2015-05-29 10:05:46 -0700 | [diff] [blame] | 391 | for (Callback l : mCallbacks) { |
| 392 | l.onSessionModifyResponseReceived( |
| Ihab Awad | a64627c | 2014-08-20 09:36:40 -0700 | [diff] [blame] | 393 | VideoProvider.this, |
| 394 | status, |
| 395 | requestedProfile, |
| 396 | responseProfile); |
| 397 | } |
| 398 | } |
| 399 | |
| 400 | @Override |
| 401 | public void handleCallSessionEvent(int event) { |
| Tyler Gunn | a2df925 | 2015-05-29 10:05:46 -0700 | [diff] [blame] | 402 | for (Callback l : mCallbacks) { |
| 403 | l.onCallSessionEvent(VideoProvider.this, event); |
| Ihab Awad | a64627c | 2014-08-20 09:36:40 -0700 | [diff] [blame] | 404 | } |
| 405 | } |
| 406 | |
| 407 | @Override |
| 408 | public void changePeerDimensions(int width, int height) { |
| Tyler Gunn | a2df925 | 2015-05-29 10:05:46 -0700 | [diff] [blame] | 409 | for (Callback l : mCallbacks) { |
| Ihab Awad | a64627c | 2014-08-20 09:36:40 -0700 | [diff] [blame] | 410 | l.onPeerDimensionsChanged(VideoProvider.this, width, height); |
| 411 | } |
| 412 | } |
| 413 | |
| 414 | @Override |
| Rekha Kumar | 0736681 | 2015-03-24 16:42:31 -0700 | [diff] [blame] | 415 | public void changeCallDataUsage(long dataUsage) { |
| Tyler Gunn | a2df925 | 2015-05-29 10:05:46 -0700 | [diff] [blame] | 416 | for (Callback l : mCallbacks) { |
| Ihab Awad | a64627c | 2014-08-20 09:36:40 -0700 | [diff] [blame] | 417 | l.onCallDataUsageChanged(VideoProvider.this, dataUsage); |
| 418 | } |
| 419 | } |
| 420 | |
| 421 | @Override |
| Yorke Lee | 400470f | 2015-05-12 13:31:25 -0700 | [diff] [blame] | 422 | public void changeCameraCapabilities( |
| 423 | VideoProfile.CameraCapabilities cameraCapabilities) { |
| Tyler Gunn | a2df925 | 2015-05-29 10:05:46 -0700 | [diff] [blame] | 424 | for (Callback l : mCallbacks) { |
| Ihab Awad | a64627c | 2014-08-20 09:36:40 -0700 | [diff] [blame] | 425 | l.onCameraCapabilitiesChanged(VideoProvider.this, cameraCapabilities); |
| 426 | } |
| 427 | } |
| 428 | |
| 429 | @Override |
| Rekha Kumar | 0736681 | 2015-03-24 16:42:31 -0700 | [diff] [blame] | 430 | public void changeVideoQuality(int videoQuality) { |
| Tyler Gunn | a2df925 | 2015-05-29 10:05:46 -0700 | [diff] [blame] | 431 | for (Callback l : mCallbacks) { |
| Rekha Kumar | 0736681 | 2015-03-24 16:42:31 -0700 | [diff] [blame] | 432 | l.onVideoQualityChanged(VideoProvider.this, videoQuality); |
| 433 | } |
| 434 | } |
| 435 | |
| 436 | @Override |
| Ihab Awad | a64627c | 2014-08-20 09:36:40 -0700 | [diff] [blame] | 437 | public IBinder asBinder() { |
| 438 | return null; |
| 439 | } |
| 440 | }; |
| 441 | |
| 442 | private final VideoCallbackServant mVideoCallbackServant = |
| 443 | new VideoCallbackServant(mVideoCallbackDelegate); |
| 444 | |
| 445 | private final IVideoProvider mVideoProviderBinder; |
| 446 | |
| Tyler Gunn | bf9c6fd | 2016-11-09 10:19:23 -0800 | [diff] [blame] | 447 | private final String mCallingPackage; |
| 448 | |
| Tyler Gunn | 159f35c | 2017-03-02 09:28:37 -0800 | [diff] [blame] | 449 | private final int mTargetSdkVersion; |
| 450 | |
| Ihab Awad | a64627c | 2014-08-20 09:36:40 -0700 | [diff] [blame] | 451 | /** |
| 452 | * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is |
| 453 | * load factor before resizing, 1 means we only expect a single thread to |
| 454 | * access the map so make only a single shard |
| 455 | */ |
| Tyler Gunn | a2df925 | 2015-05-29 10:05:46 -0700 | [diff] [blame] | 456 | private final Set<Callback> mCallbacks = Collections.newSetFromMap( |
| 457 | new ConcurrentHashMap<Callback, Boolean>(8, 0.9f, 1)); |
| Ihab Awad | a64627c | 2014-08-20 09:36:40 -0700 | [diff] [blame] | 458 | |
| Tyler Gunn | 159f35c | 2017-03-02 09:28:37 -0800 | [diff] [blame] | 459 | VideoProvider(IVideoProvider videoProviderBinder, String callingPackage, |
| 460 | int targetSdkVersion) { |
| 461 | |
| Ihab Awad | a64627c | 2014-08-20 09:36:40 -0700 | [diff] [blame] | 462 | mVideoProviderBinder = videoProviderBinder; |
| Tyler Gunn | bf9c6fd | 2016-11-09 10:19:23 -0800 | [diff] [blame] | 463 | mCallingPackage = callingPackage; |
| Tyler Gunn | 159f35c | 2017-03-02 09:28:37 -0800 | [diff] [blame] | 464 | mTargetSdkVersion = targetSdkVersion; |
| Ihab Awad | a64627c | 2014-08-20 09:36:40 -0700 | [diff] [blame] | 465 | try { |
| Tyler Gunn | 7595842 | 2015-04-15 14:23:42 -0700 | [diff] [blame] | 466 | mVideoProviderBinder.addVideoCallback(mVideoCallbackServant.getStub().asBinder()); |
| Ihab Awad | a64627c | 2014-08-20 09:36:40 -0700 | [diff] [blame] | 467 | } catch (RemoteException e) { |
| 468 | } |
| 469 | } |
| 470 | |
| Tyler Gunn | 295f5d7 | 2015-06-04 11:08:54 -0700 | [diff] [blame] | 471 | /** |
| 472 | * Registers a callback to receive commands and state changes for video calls. |
| 473 | * |
| 474 | * @param l The video call callback. |
| 475 | */ |
| Tyler Gunn | a2df925 | 2015-05-29 10:05:46 -0700 | [diff] [blame] | 476 | public void registerCallback(Callback l) { |
| 477 | mCallbacks.add(l); |
| Ihab Awad | a64627c | 2014-08-20 09:36:40 -0700 | [diff] [blame] | 478 | } |
| 479 | |
| Tyler Gunn | 295f5d7 | 2015-06-04 11:08:54 -0700 | [diff] [blame] | 480 | /** |
| 481 | * Clears the video call callback set via {@link #registerCallback}. |
| 482 | * |
| 483 | * @param l The video call callback to clear. |
| 484 | */ |
| Tyler Gunn | a2df925 | 2015-05-29 10:05:46 -0700 | [diff] [blame] | 485 | public void unregisterCallback(Callback l) { |
| 486 | mCallbacks.remove(l); |
| Ihab Awad | a64627c | 2014-08-20 09:36:40 -0700 | [diff] [blame] | 487 | } |
| 488 | |
| Tyler Gunn | 295f5d7 | 2015-06-04 11:08:54 -0700 | [diff] [blame] | 489 | /** |
| 490 | * Sets the camera to be used for the outgoing video for the |
| 491 | * {@link RemoteConnection.VideoProvider}. |
| 492 | * |
| 493 | * @param cameraId The id of the camera (use ids as reported by |
| 494 | * {@link CameraManager#getCameraIdList()}). |
| 495 | * @see Connection.VideoProvider#onSetCamera(String) |
| 496 | */ |
| Ihab Awad | a64627c | 2014-08-20 09:36:40 -0700 | [diff] [blame] | 497 | public void setCamera(String cameraId) { |
| 498 | try { |
| Tyler Gunn | 159f35c | 2017-03-02 09:28:37 -0800 | [diff] [blame] | 499 | mVideoProviderBinder.setCamera(cameraId, mCallingPackage, mTargetSdkVersion); |
| Ihab Awad | a64627c | 2014-08-20 09:36:40 -0700 | [diff] [blame] | 500 | } catch (RemoteException e) { |
| 501 | } |
| 502 | } |
| 503 | |
| Tyler Gunn | 295f5d7 | 2015-06-04 11:08:54 -0700 | [diff] [blame] | 504 | /** |
| 505 | * Sets the surface to be used for displaying a preview of what the user's camera is |
| 506 | * currently capturing for the {@link RemoteConnection.VideoProvider}. |
| 507 | * |
| 508 | * @param surface The {@link Surface}. |
| 509 | * @see Connection.VideoProvider#onSetPreviewSurface(Surface) |
| 510 | */ |
| Ihab Awad | a64627c | 2014-08-20 09:36:40 -0700 | [diff] [blame] | 511 | public void setPreviewSurface(Surface surface) { |
| 512 | try { |
| 513 | mVideoProviderBinder.setPreviewSurface(surface); |
| 514 | } catch (RemoteException e) { |
| 515 | } |
| 516 | } |
| 517 | |
| Tyler Gunn | 295f5d7 | 2015-06-04 11:08:54 -0700 | [diff] [blame] | 518 | /** |
| 519 | * Sets the surface to be used for displaying the video received from the remote device for |
| 520 | * the {@link RemoteConnection.VideoProvider}. |
| 521 | * |
| 522 | * @param surface The {@link Surface}. |
| 523 | * @see Connection.VideoProvider#onSetDisplaySurface(Surface) |
| 524 | */ |
| Ihab Awad | a64627c | 2014-08-20 09:36:40 -0700 | [diff] [blame] | 525 | public void setDisplaySurface(Surface surface) { |
| 526 | try { |
| 527 | mVideoProviderBinder.setDisplaySurface(surface); |
| 528 | } catch (RemoteException e) { |
| 529 | } |
| 530 | } |
| 531 | |
| Tyler Gunn | 295f5d7 | 2015-06-04 11:08:54 -0700 | [diff] [blame] | 532 | /** |
| 533 | * Sets the device orientation, in degrees, for the {@link RemoteConnection.VideoProvider}. |
| 534 | * Assumes that a standard portrait orientation of the device is 0 degrees. |
| 535 | * |
| 536 | * @param rotation The device orientation, in degrees. |
| 537 | * @see Connection.VideoProvider#onSetDeviceOrientation(int) |
| 538 | */ |
| Ihab Awad | a64627c | 2014-08-20 09:36:40 -0700 | [diff] [blame] | 539 | public void setDeviceOrientation(int rotation) { |
| 540 | try { |
| 541 | mVideoProviderBinder.setDeviceOrientation(rotation); |
| 542 | } catch (RemoteException e) { |
| 543 | } |
| 544 | } |
| 545 | |
| Tyler Gunn | 295f5d7 | 2015-06-04 11:08:54 -0700 | [diff] [blame] | 546 | /** |
| 547 | * Sets camera zoom ratio for the {@link RemoteConnection.VideoProvider}. |
| 548 | * |
| 549 | * @param value The camera zoom ratio. |
| 550 | * @see Connection.VideoProvider#onSetZoom(float) |
| 551 | */ |
| Ihab Awad | a64627c | 2014-08-20 09:36:40 -0700 | [diff] [blame] | 552 | public void setZoom(float value) { |
| 553 | try { |
| 554 | mVideoProviderBinder.setZoom(value); |
| 555 | } catch (RemoteException e) { |
| 556 | } |
| 557 | } |
| 558 | |
| Tyler Gunn | 295f5d7 | 2015-06-04 11:08:54 -0700 | [diff] [blame] | 559 | /** |
| 560 | * Issues a request to modify the properties of the current video session for the |
| 561 | * {@link RemoteConnection.VideoProvider}. |
| 562 | * |
| 563 | * @param fromProfile The video profile prior to the request. |
| 564 | * @param toProfile The video profile with the requested changes made. |
| 565 | * @see Connection.VideoProvider#onSendSessionModifyRequest(VideoProfile, VideoProfile) |
| 566 | */ |
| Tyler Gunn | 4538216 | 2015-05-06 08:52:27 -0700 | [diff] [blame] | 567 | public void sendSessionModifyRequest(VideoProfile fromProfile, VideoProfile toProfile) { |
| Ihab Awad | a64627c | 2014-08-20 09:36:40 -0700 | [diff] [blame] | 568 | try { |
| Tyler Gunn | 4538216 | 2015-05-06 08:52:27 -0700 | [diff] [blame] | 569 | mVideoProviderBinder.sendSessionModifyRequest(fromProfile, toProfile); |
| Ihab Awad | a64627c | 2014-08-20 09:36:40 -0700 | [diff] [blame] | 570 | } catch (RemoteException e) { |
| 571 | } |
| 572 | } |
| 573 | |
| Tyler Gunn | 295f5d7 | 2015-06-04 11:08:54 -0700 | [diff] [blame] | 574 | /** |
| 575 | * Provides a response to a request to change the current call video session |
| 576 | * properties for the {@link RemoteConnection.VideoProvider}. |
| 577 | * |
| 578 | * @param responseProfile The response call video properties. |
| 579 | * @see Connection.VideoProvider#onSendSessionModifyResponse(VideoProfile) |
| 580 | */ |
| Ihab Awad | a64627c | 2014-08-20 09:36:40 -0700 | [diff] [blame] | 581 | public void sendSessionModifyResponse(VideoProfile responseProfile) { |
| 582 | try { |
| 583 | mVideoProviderBinder.sendSessionModifyResponse(responseProfile); |
| 584 | } catch (RemoteException e) { |
| 585 | } |
| 586 | } |
| 587 | |
| Tyler Gunn | 295f5d7 | 2015-06-04 11:08:54 -0700 | [diff] [blame] | 588 | /** |
| 589 | * Issues a request to retrieve the capabilities of the current camera for the |
| 590 | * {@link RemoteConnection.VideoProvider}. |
| 591 | * |
| 592 | * @see Connection.VideoProvider#onRequestCameraCapabilities() |
| 593 | */ |
| Ihab Awad | a64627c | 2014-08-20 09:36:40 -0700 | [diff] [blame] | 594 | public void requestCameraCapabilities() { |
| 595 | try { |
| 596 | mVideoProviderBinder.requestCameraCapabilities(); |
| 597 | } catch (RemoteException e) { |
| 598 | } |
| 599 | } |
| 600 | |
| Tyler Gunn | 295f5d7 | 2015-06-04 11:08:54 -0700 | [diff] [blame] | 601 | /** |
| 602 | * Issues a request to retrieve the data usage (in bytes) of the video portion of the |
| 603 | * {@link RemoteConnection} for the {@link RemoteConnection.VideoProvider}. |
| 604 | * |
| 605 | * @see Connection.VideoProvider#onRequestConnectionDataUsage() |
| 606 | */ |
| Ihab Awad | a64627c | 2014-08-20 09:36:40 -0700 | [diff] [blame] | 607 | public void requestCallDataUsage() { |
| 608 | try { |
| 609 | mVideoProviderBinder.requestCallDataUsage(); |
| 610 | } catch (RemoteException e) { |
| 611 | } |
| 612 | } |
| 613 | |
| Tyler Gunn | 295f5d7 | 2015-06-04 11:08:54 -0700 | [diff] [blame] | 614 | /** |
| 615 | * Sets the {@link Uri} of an image to be displayed to the peer device when the video signal |
| 616 | * is paused, for the {@link RemoteConnection.VideoProvider}. |
| 617 | * |
| 618 | * @see Connection.VideoProvider#onSetPauseImage(Uri) |
| 619 | */ |
| Yorke Lee | 32f2473 | 2015-05-12 16:18:03 -0700 | [diff] [blame] | 620 | public void setPauseImage(Uri uri) { |
| Ihab Awad | a64627c | 2014-08-20 09:36:40 -0700 | [diff] [blame] | 621 | try { |
| 622 | mVideoProviderBinder.setPauseImage(uri); |
| 623 | } catch (RemoteException e) { |
| 624 | } |
| 625 | } |
| 626 | } |
| 627 | |
| Evan Charlton | bf11f98 | 2014-07-20 22:06:28 -0700 | [diff] [blame] | 628 | private IConnectionService mConnectionService; |
| Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 629 | private final String mConnectionId; |
| Jay Shrauner | 229e382 | 2014-08-15 09:23:07 -0700 | [diff] [blame] | 630 | /** |
| 631 | * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is |
| 632 | * load factor before resizing, 1 means we only expect a single thread to |
| 633 | * access the map so make only a single shard |
| 634 | */ |
| Andrew Lee | 011728f | 2015-04-23 15:47:06 -0700 | [diff] [blame] | 635 | private final Set<CallbackRecord> mCallbackRecords = Collections.newSetFromMap( |
| 636 | new ConcurrentHashMap<CallbackRecord, Boolean>(8, 0.9f, 1)); |
| Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 637 | private final List<RemoteConnection> mConferenceableConnections = new ArrayList<>(); |
| 638 | private final List<RemoteConnection> mUnmodifiableconferenceableConnections = |
| 639 | Collections.unmodifiableList(mConferenceableConnections); |
| Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 640 | |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 641 | private int mState = Connection.STATE_NEW; |
| Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame] | 642 | private DisconnectCause mDisconnectCause; |
| Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 643 | private boolean mRingbackRequested; |
| Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 644 | private boolean mConnected; |
| Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 645 | private int mConnectionCapabilities; |
| Tyler Gunn | 720c664 | 2016-03-22 09:02:47 -0700 | [diff] [blame] | 646 | private int mConnectionProperties; |
| Tyler Gunn | aa07df8 | 2014-07-17 07:50:22 -0700 | [diff] [blame] | 647 | private int mVideoState; |
| Ihab Awad | a64627c | 2014-08-20 09:36:40 -0700 | [diff] [blame] | 648 | private VideoProvider mVideoProvider; |
| Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 649 | private boolean mIsVoipAudioMode; |
| Sailesh Nepal | e7ef59a | 2014-07-08 21:48:22 -0700 | [diff] [blame] | 650 | private StatusHints mStatusHints; |
| Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 651 | private Uri mAddress; |
| 652 | private int mAddressPresentation; |
| Sailesh Nepal | 6120386 | 2014-07-11 14:50:13 -0700 | [diff] [blame] | 653 | private String mCallerDisplayName; |
| 654 | private int mCallerDisplayNamePresentation; |
| Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 655 | private RemoteConference mConference; |
| Santos Cordon | 6b7f955 | 2015-05-27 17:21:45 -0700 | [diff] [blame] | 656 | private Bundle mExtras; |
| Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 657 | |
| 658 | /** |
| 659 | * @hide |
| 660 | */ |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 661 | RemoteConnection( |
| 662 | String id, |
| 663 | IConnectionService connectionService, |
| 664 | ConnectionRequest request) { |
| 665 | mConnectionId = id; |
| Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 666 | mConnectionService = connectionService; |
| Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 667 | mConnected = true; |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 668 | mState = Connection.STATE_INITIALIZING; |
| Evan Charlton | bf11f98 | 2014-07-20 22:06:28 -0700 | [diff] [blame] | 669 | } |
| 670 | |
| 671 | /** |
| Tyler Gunn | 4a57b9b | 2014-10-30 14:27:48 -0700 | [diff] [blame] | 672 | * @hide |
| 673 | */ |
| 674 | RemoteConnection(String callId, IConnectionService connectionService, |
| Tyler Gunn | 159f35c | 2017-03-02 09:28:37 -0800 | [diff] [blame] | 675 | ParcelableConnection connection, String callingPackage, int targetSdkVersion) { |
| Tyler Gunn | 4a57b9b | 2014-10-30 14:27:48 -0700 | [diff] [blame] | 676 | mConnectionId = callId; |
| 677 | mConnectionService = connectionService; |
| 678 | mConnected = true; |
| 679 | mState = connection.getState(); |
| 680 | mDisconnectCause = connection.getDisconnectCause(); |
| 681 | mRingbackRequested = connection.isRingbackRequested(); |
| Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 682 | mConnectionCapabilities = connection.getConnectionCapabilities(); |
| Tyler Gunn | 720c664 | 2016-03-22 09:02:47 -0700 | [diff] [blame] | 683 | mConnectionProperties = connection.getConnectionProperties(); |
| Tyler Gunn | 4a57b9b | 2014-10-30 14:27:48 -0700 | [diff] [blame] | 684 | mVideoState = connection.getVideoState(); |
| Tyler Gunn | 9c2c583 | 2016-09-16 15:08:50 -0700 | [diff] [blame] | 685 | IVideoProvider videoProvider = connection.getVideoProvider(); |
| 686 | if (videoProvider != null) { |
| Tyler Gunn | 159f35c | 2017-03-02 09:28:37 -0800 | [diff] [blame] | 687 | mVideoProvider = new RemoteConnection.VideoProvider(videoProvider, callingPackage, |
| 688 | targetSdkVersion); |
| Tyler Gunn | 9c2c583 | 2016-09-16 15:08:50 -0700 | [diff] [blame] | 689 | } else { |
| 690 | mVideoProvider = null; |
| 691 | } |
| Tyler Gunn | 4a57b9b | 2014-10-30 14:27:48 -0700 | [diff] [blame] | 692 | mIsVoipAudioMode = connection.getIsVoipAudioMode(); |
| 693 | mStatusHints = connection.getStatusHints(); |
| 694 | mAddress = connection.getHandle(); |
| 695 | mAddressPresentation = connection.getHandlePresentation(); |
| 696 | mCallerDisplayName = connection.getCallerDisplayName(); |
| 697 | mCallerDisplayNamePresentation = connection.getCallerDisplayNamePresentation(); |
| 698 | mConference = null; |
| Tyler Gunn | cd6ccfd | 2016-10-17 15:48:19 -0700 | [diff] [blame] | 699 | putExtras(connection.getExtras()); |
| 700 | |
| 701 | // Stash the original connection ID as it exists in the source ConnectionService. |
| 702 | // Telecom will use this to avoid adding duplicates later. |
| 703 | // See comments on Connection.EXTRA_ORIGINAL_CONNECTION_ID for more information. |
| 704 | Bundle newExtras = new Bundle(); |
| 705 | newExtras.putString(Connection.EXTRA_ORIGINAL_CONNECTION_ID, callId); |
| 706 | putExtras(newExtras); |
| Tyler Gunn | 4a57b9b | 2014-10-30 14:27:48 -0700 | [diff] [blame] | 707 | } |
| 708 | |
| 709 | /** |
| Evan Charlton | bf11f98 | 2014-07-20 22:06:28 -0700 | [diff] [blame] | 710 | * Create a RemoteConnection which is used for failed connections. Note that using it for any |
| 711 | * "real" purpose will almost certainly fail. Callers should note the failure and act |
| 712 | * accordingly (moving on to another RemoteConnection, for example) |
| 713 | * |
| Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame] | 714 | * @param disconnectCause The reason for the failed connection. |
| 715 | * @hide |
| Evan Charlton | bf11f98 | 2014-07-20 22:06:28 -0700 | [diff] [blame] | 716 | */ |
| Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame] | 717 | RemoteConnection(DisconnectCause disconnectCause) { |
| Tyler Gunn | 4a57b9b | 2014-10-30 14:27:48 -0700 | [diff] [blame] | 718 | mConnectionId = "NULL"; |
| Evan Charlton | bf11f98 | 2014-07-20 22:06:28 -0700 | [diff] [blame] | 719 | mConnected = false; |
| Ihab Awad | 6107bab | 2014-08-18 09:23:25 -0700 | [diff] [blame] | 720 | mState = Connection.STATE_DISCONNECTED; |
| Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame] | 721 | mDisconnectCause = disconnectCause; |
| Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 722 | } |
| 723 | |
| Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 724 | /** |
| Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 725 | * Adds a callback to this {@code RemoteConnection}. |
| Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 726 | * |
| Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 727 | * @param callback A {@code Callback}. |
| Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 728 | */ |
| Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 729 | public void registerCallback(Callback callback) { |
| Andrew Lee | 011728f | 2015-04-23 15:47:06 -0700 | [diff] [blame] | 730 | registerCallback(callback, new Handler()); |
| 731 | } |
| 732 | |
| 733 | /** |
| 734 | * Adds a callback to this {@code RemoteConnection}. |
| 735 | * |
| 736 | * @param callback A {@code Callback}. |
| 737 | * @param handler A {@code Handler} which command and status changes will be delivered to. |
| 738 | */ |
| 739 | public void registerCallback(Callback callback, Handler handler) { |
| 740 | unregisterCallback(callback); |
| 741 | if (callback != null && handler != null) { |
| 742 | mCallbackRecords.add(new CallbackRecord(callback, handler)); |
| 743 | } |
| Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 744 | } |
| 745 | |
| Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 746 | /** |
| Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 747 | * Removes a callback from this {@code RemoteConnection}. |
| Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 748 | * |
| Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 749 | * @param callback A {@code Callback}. |
| Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 750 | */ |
| Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 751 | public void unregisterCallback(Callback callback) { |
| 752 | if (callback != null) { |
| Andrew Lee | 011728f | 2015-04-23 15:47:06 -0700 | [diff] [blame] | 753 | for (CallbackRecord record : mCallbackRecords) { |
| 754 | if (record.getCallback() == callback) { |
| 755 | mCallbackRecords.remove(record); |
| 756 | break; |
| 757 | } |
| 758 | } |
| Jay Shrauner | 229e382 | 2014-08-15 09:23:07 -0700 | [diff] [blame] | 759 | } |
| Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 760 | } |
| 761 | |
| Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 762 | /** |
| Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 763 | * Obtains the state of this {@code RemoteConnection}. |
| 764 | * |
| 765 | * @return A state value, chosen from the {@code STATE_*} constants. |
| 766 | */ |
| Sailesh Nepal | ade3f25 | 2014-07-01 17:25:37 -0700 | [diff] [blame] | 767 | public int getState() { |
| 768 | return mState; |
| 769 | } |
| 770 | |
| Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 771 | /** |
| Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 772 | * Obtains the reason why this {@code RemoteConnection} may have been disconnected. |
| 773 | * |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 774 | * @return For a {@link Connection#STATE_DISCONNECTED} {@code RemoteConnection}, the |
| Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 775 | * disconnect cause expressed as a code chosen from among those declared in |
| 776 | * {@link DisconnectCause}. |
| Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 777 | */ |
| Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame] | 778 | public DisconnectCause getDisconnectCause() { |
| 779 | return mDisconnectCause; |
| Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 780 | } |
| 781 | |
| Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 782 | /** |
| Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 783 | * Obtains the capabilities of this {@code RemoteConnection}. |
| 784 | * |
| Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 785 | * @return A bitmask of the capabilities of the {@code RemoteConnection}, as defined in |
| Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 786 | * the {@code CAPABILITY_*} constants in class {@link Connection}. |
| Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 787 | */ |
| Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 788 | public int getConnectionCapabilities() { |
| 789 | return mConnectionCapabilities; |
| Sailesh Nepal | 1a7061b | 2014-07-09 21:03:20 -0700 | [diff] [blame] | 790 | } |
| 791 | |
| Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 792 | /** |
| Tyler Gunn | 720c664 | 2016-03-22 09:02:47 -0700 | [diff] [blame] | 793 | * Obtains the properties of this {@code RemoteConnection}. |
| 794 | * |
| 795 | * @return A bitmask of the properties of the {@code RemoteConnection}, as defined in the |
| 796 | * {@code PROPERTY_*} constants in class {@link Connection}. |
| 797 | */ |
| 798 | public int getConnectionProperties() { |
| 799 | return mConnectionProperties; |
| 800 | } |
| 801 | |
| 802 | /** |
| Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 803 | * Determines if the audio mode of this {@code RemoteConnection} is VOIP. |
| 804 | * |
| Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 805 | * @return {@code true} if the {@code RemoteConnection}'s current audio mode is VOIP. |
| 806 | */ |
| Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 807 | public boolean isVoipAudioMode() { |
| 808 | return mIsVoipAudioMode; |
| Sailesh Nepal | 33aaae4 | 2014-07-07 22:49:44 -0700 | [diff] [blame] | 809 | } |
| 810 | |
| Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 811 | /** |
| Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 812 | * Obtains status hints pertaining to this {@code RemoteConnection}. |
| 813 | * |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 814 | * @return The current {@link StatusHints} of this {@code RemoteConnection}, |
| Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 815 | * or {@code null} if none have been set. |
| Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 816 | */ |
| Sailesh Nepal | e7ef59a | 2014-07-08 21:48:22 -0700 | [diff] [blame] | 817 | public StatusHints getStatusHints() { |
| 818 | return mStatusHints; |
| 819 | } |
| 820 | |
| Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 821 | /** |
| Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 822 | * Obtains the address of this {@code RemoteConnection}. |
| 823 | * |
| 824 | * @return The address (e.g., phone number) to which the {@code RemoteConnection} |
| 825 | * is currently connected. |
| Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 826 | */ |
| Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 827 | public Uri getAddress() { |
| 828 | return mAddress; |
| Sailesh Nepal | 6120386 | 2014-07-11 14:50:13 -0700 | [diff] [blame] | 829 | } |
| 830 | |
| Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 831 | /** |
| Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 832 | * Obtains the presentation requirements for the address of this {@code RemoteConnection}. |
| 833 | * |
| 834 | * @return The presentation requirements for the address. See |
| 835 | * {@link TelecomManager} for valid values. |
| Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 836 | */ |
| Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 837 | public int getAddressPresentation() { |
| 838 | return mAddressPresentation; |
| Sailesh Nepal | 6120386 | 2014-07-11 14:50:13 -0700 | [diff] [blame] | 839 | } |
| 840 | |
| Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 841 | /** |
| Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 842 | * Obtains the display name for this {@code RemoteConnection}'s caller. |
| 843 | * |
| Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 844 | * @return The display name for the caller. |
| 845 | */ |
| Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 846 | public CharSequence getCallerDisplayName() { |
| Sailesh Nepal | 6120386 | 2014-07-11 14:50:13 -0700 | [diff] [blame] | 847 | return mCallerDisplayName; |
| 848 | } |
| 849 | |
| Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 850 | /** |
| Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 851 | * Obtains the presentation requirements for this {@code RemoteConnection}'s |
| 852 | * caller's display name. |
| 853 | * |
| Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 854 | * @return The presentation requirements for the caller display name. See |
| Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 855 | * {@link TelecomManager} for valid values. |
| Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 856 | */ |
| Sailesh Nepal | 6120386 | 2014-07-11 14:50:13 -0700 | [diff] [blame] | 857 | public int getCallerDisplayNamePresentation() { |
| 858 | return mCallerDisplayNamePresentation; |
| 859 | } |
| 860 | |
| Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 861 | /** |
| Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 862 | * Obtains the video state of this {@code RemoteConnection}. |
| 863 | * |
| Tyler Gunn | 87b73f3 | 2015-06-03 10:09:59 -0700 | [diff] [blame] | 864 | * @return The video state of the {@code RemoteConnection}. See {@link VideoProfile}. |
| Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 865 | */ |
| Tyler Gunn | aa07df8 | 2014-07-17 07:50:22 -0700 | [diff] [blame] | 866 | public int getVideoState() { |
| 867 | return mVideoState; |
| 868 | } |
| 869 | |
| Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 870 | /** |
| Rekha Kumar | 0736681 | 2015-03-24 16:42:31 -0700 | [diff] [blame] | 871 | * Obtains the video provider of this {@code RemoteConnection}. |
| Ihab Awad | a64627c | 2014-08-20 09:36:40 -0700 | [diff] [blame] | 872 | * @return The video provider associated with this {@code RemoteConnection}. |
| Ihab Awad | a64627c | 2014-08-20 09:36:40 -0700 | [diff] [blame] | 873 | */ |
| 874 | public final VideoProvider getVideoProvider() { |
| 875 | return mVideoProvider; |
| 876 | } |
| 877 | |
| 878 | /** |
| Santos Cordon | 6b7f955 | 2015-05-27 17:21:45 -0700 | [diff] [blame] | 879 | * Obtain the extras associated with this {@code RemoteConnection}. |
| 880 | * |
| 881 | * @return The extras for this connection. |
| 882 | */ |
| 883 | public final Bundle getExtras() { |
| 884 | return mExtras; |
| 885 | } |
| 886 | |
| 887 | /** |
| Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 888 | * Determines whether this {@code RemoteConnection} is requesting ringback. |
| 889 | * |
| Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 890 | * @return Whether the {@code RemoteConnection} is requesting that the framework play a |
| Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 891 | * ringback tone on its behalf. |
| Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 892 | */ |
| Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 893 | public boolean isRingbackRequested() { |
| Santos Cordon | 15d63c7 | 2015-06-02 15:08:26 -0700 | [diff] [blame] | 894 | return mRingbackRequested; |
| Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 895 | } |
| 896 | |
| 897 | /** |
| 898 | * Instructs this {@code RemoteConnection} to abort. |
| 899 | */ |
| Sailesh Nepal | 091768c | 2014-06-30 15:15:23 -0700 | [diff] [blame] | 900 | public void abort() { |
| 901 | try { |
| 902 | if (mConnected) { |
| Brad Ebinger | b32d4f8 | 2016-10-24 16:40:49 -0700 | [diff] [blame] | 903 | mConnectionService.abort(mConnectionId, null /*Session.Info*/); |
| Sailesh Nepal | 091768c | 2014-06-30 15:15:23 -0700 | [diff] [blame] | 904 | } |
| 905 | } catch (RemoteException ignored) { |
| 906 | } |
| 907 | } |
| 908 | |
| Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 909 | /** |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 910 | * Instructs this {@link Connection#STATE_RINGING} {@code RemoteConnection} to answer. |
| Tyler Gunn | be74de0 | 2014-08-29 14:51:48 -0700 | [diff] [blame] | 911 | */ |
| 912 | public void answer() { |
| 913 | try { |
| 914 | if (mConnected) { |
| Brad Ebinger | b32d4f8 | 2016-10-24 16:40:49 -0700 | [diff] [blame] | 915 | mConnectionService.answer(mConnectionId, null /*Session.Info*/); |
| Tyler Gunn | be74de0 | 2014-08-29 14:51:48 -0700 | [diff] [blame] | 916 | } |
| 917 | } catch (RemoteException ignored) { |
| 918 | } |
| 919 | } |
| 920 | |
| 921 | /** |
| 922 | * Instructs this {@link Connection#STATE_RINGING} {@code RemoteConnection} to answer. |
| Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 923 | * @param videoState The video state in which to answer the call. |
| Tyler Gunn | be74de0 | 2014-08-29 14:51:48 -0700 | [diff] [blame] | 924 | * @hide |
| Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 925 | */ |
| Andrew Lee | 8da4c3c | 2014-07-16 10:11:42 -0700 | [diff] [blame] | 926 | public void answer(int videoState) { |
| Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 927 | try { |
| 928 | if (mConnected) { |
| Brad Ebinger | b32d4f8 | 2016-10-24 16:40:49 -0700 | [diff] [blame] | 929 | mConnectionService.answerVideo(mConnectionId, videoState, null /*Session.Info*/); |
| Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 930 | } |
| 931 | } catch (RemoteException ignored) { |
| 932 | } |
| 933 | } |
| 934 | |
| Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 935 | /** |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 936 | * Instructs this {@link Connection#STATE_RINGING} {@code RemoteConnection} to reject. |
| Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 937 | */ |
| Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 938 | public void reject() { |
| 939 | try { |
| 940 | if (mConnected) { |
| Brad Ebinger | b32d4f8 | 2016-10-24 16:40:49 -0700 | [diff] [blame] | 941 | mConnectionService.reject(mConnectionId, null /*Session.Info*/); |
| Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 942 | } |
| 943 | } catch (RemoteException ignored) { |
| 944 | } |
| 945 | } |
| 946 | |
| Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 947 | /** |
| 948 | * Instructs this {@code RemoteConnection} to go on hold. |
| 949 | */ |
| Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 950 | public void hold() { |
| 951 | try { |
| 952 | if (mConnected) { |
| Brad Ebinger | b32d4f8 | 2016-10-24 16:40:49 -0700 | [diff] [blame] | 953 | mConnectionService.hold(mConnectionId, null /*Session.Info*/); |
| Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 954 | } |
| 955 | } catch (RemoteException ignored) { |
| 956 | } |
| 957 | } |
| 958 | |
| Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 959 | /** |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 960 | * Instructs this {@link Connection#STATE_HOLDING} call to release from hold. |
| Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 961 | */ |
| Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 962 | public void unhold() { |
| 963 | try { |
| 964 | if (mConnected) { |
| Brad Ebinger | b32d4f8 | 2016-10-24 16:40:49 -0700 | [diff] [blame] | 965 | mConnectionService.unhold(mConnectionId, null /*Session.Info*/); |
| Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 966 | } |
| 967 | } catch (RemoteException ignored) { |
| 968 | } |
| 969 | } |
| 970 | |
| Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 971 | /** |
| 972 | * Instructs this {@code RemoteConnection} to disconnect. |
| 973 | */ |
| Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 974 | public void disconnect() { |
| 975 | try { |
| 976 | if (mConnected) { |
| Brad Ebinger | b32d4f8 | 2016-10-24 16:40:49 -0700 | [diff] [blame] | 977 | mConnectionService.disconnect(mConnectionId, null /*Session.Info*/); |
| Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 978 | } |
| 979 | } catch (RemoteException ignored) { |
| 980 | } |
| 981 | } |
| 982 | |
| Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 983 | /** |
| 984 | * Instructs this {@code RemoteConnection} to play a dual-tone multi-frequency signaling |
| 985 | * (DTMF) tone. |
| 986 | * |
| 987 | * Any other currently playing DTMF tone in the specified call is immediately stopped. |
| 988 | * |
| 989 | * @param digit A character representing the DTMF digit for which to play the tone. This |
| 990 | * value must be one of {@code '0'} through {@code '9'}, {@code '*'} or {@code '#'}. |
| 991 | */ |
| 992 | public void playDtmfTone(char digit) { |
| Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 993 | try { |
| 994 | if (mConnected) { |
| Brad Ebinger | b32d4f8 | 2016-10-24 16:40:49 -0700 | [diff] [blame] | 995 | mConnectionService.playDtmfTone(mConnectionId, digit, null /*Session.Info*/); |
| Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 996 | } |
| 997 | } catch (RemoteException ignored) { |
| 998 | } |
| 999 | } |
| 1000 | |
| Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 1001 | /** |
| 1002 | * Instructs this {@code RemoteConnection} to stop any dual-tone multi-frequency signaling |
| 1003 | * (DTMF) tone currently playing. |
| 1004 | * |
| 1005 | * DTMF tones are played by calling {@link #playDtmfTone(char)}. If no DTMF tone is |
| 1006 | * currently playing, this method will do nothing. |
| 1007 | */ |
| 1008 | public void stopDtmfTone() { |
| Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 1009 | try { |
| 1010 | if (mConnected) { |
| Brad Ebinger | b32d4f8 | 2016-10-24 16:40:49 -0700 | [diff] [blame] | 1011 | mConnectionService.stopDtmfTone(mConnectionId, null /*Session.Info*/); |
| Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 1012 | } |
| 1013 | } catch (RemoteException ignored) { |
| 1014 | } |
| 1015 | } |
| 1016 | |
| Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 1017 | /** |
| 1018 | * Instructs this {@code RemoteConnection} to continue playing a post-dial DTMF string. |
| 1019 | * |
| 1020 | * A post-dial DTMF string is a string of digits following the first instance of either |
| Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 1021 | * {@link TelecomManager#DTMF_CHARACTER_WAIT} or {@link TelecomManager#DTMF_CHARACTER_PAUSE}. |
| Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 1022 | * These digits are immediately sent as DTMF tones to the recipient as soon as the |
| 1023 | * connection is made. |
| 1024 | * |
| Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 1025 | * If the DTMF string contains a {@link TelecomManager#DTMF_CHARACTER_PAUSE} symbol, this |
| Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 1026 | * {@code RemoteConnection} will temporarily pause playing the tones for a pre-defined period |
| 1027 | * of time. |
| 1028 | * |
| Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 1029 | * If the DTMF string contains a {@link TelecomManager#DTMF_CHARACTER_WAIT} symbol, this |
| Nancy Chen | 27d1c2d | 2014-12-15 16:12:50 -0800 | [diff] [blame] | 1030 | * {@code RemoteConnection} will pause playing the tones and notify callbacks via |
| Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 1031 | * {@link Callback#onPostDialWait(RemoteConnection, String)}. At this point, the in-call app |
| Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 1032 | * should display to the user an indication of this state and an affordance to continue |
| 1033 | * the postdial sequence. When the user decides to continue the postdial sequence, the in-call |
| 1034 | * app should invoke the {@link #postDialContinue(boolean)} method. |
| 1035 | * |
| 1036 | * @param proceed Whether or not to continue with the post-dial sequence. |
| 1037 | */ |
| Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 1038 | public void postDialContinue(boolean proceed) { |
| 1039 | try { |
| 1040 | if (mConnected) { |
| Brad Ebinger | b32d4f8 | 2016-10-24 16:40:49 -0700 | [diff] [blame] | 1041 | mConnectionService.onPostDialContinue(mConnectionId, proceed, |
| 1042 | null /*Session.Info*/); |
| Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 1043 | } |
| 1044 | } catch (RemoteException ignored) { |
| 1045 | } |
| 1046 | } |
| 1047 | |
| Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 1048 | /** |
| Tyler Gunn | 876dbfb | 2016-03-14 15:18:07 -0700 | [diff] [blame] | 1049 | * Instructs this {@link RemoteConnection} to pull itself to the local device. |
| 1050 | * <p> |
| 1051 | * See {@link Call#pullExternalCall()} for more information. |
| 1052 | */ |
| 1053 | public void pullExternalCall() { |
| 1054 | try { |
| 1055 | if (mConnected) { |
| Brad Ebinger | b32d4f8 | 2016-10-24 16:40:49 -0700 | [diff] [blame] | 1056 | mConnectionService.pullExternalCall(mConnectionId, null /*Session.Info*/); |
| Tyler Gunn | 876dbfb | 2016-03-14 15:18:07 -0700 | [diff] [blame] | 1057 | } |
| 1058 | } catch (RemoteException ignored) { |
| 1059 | } |
| 1060 | } |
| 1061 | |
| 1062 | /** |
| Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 1063 | * Set the audio state of this {@code RemoteConnection}. |
| 1064 | * |
| 1065 | * @param state The audio state of this {@code RemoteConnection}. |
| Yorke Lee | 4af5935 | 2015-05-13 14:14:54 -0700 | [diff] [blame] | 1066 | * @hide |
| 1067 | * @deprecated Use {@link #setCallAudioState(CallAudioState) instead. |
| Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 1068 | */ |
| Yorke Lee | 4af5935 | 2015-05-13 14:14:54 -0700 | [diff] [blame] | 1069 | @SystemApi |
| 1070 | @Deprecated |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 1071 | public void setAudioState(AudioState state) { |
| Yorke Lee | 4af5935 | 2015-05-13 14:14:54 -0700 | [diff] [blame] | 1072 | setCallAudioState(new CallAudioState(state)); |
| 1073 | } |
| 1074 | |
| 1075 | /** |
| 1076 | * Set the audio state of this {@code RemoteConnection}. |
| 1077 | * |
| 1078 | * @param state The audio state of this {@code RemoteConnection}. |
| 1079 | */ |
| 1080 | public void setCallAudioState(CallAudioState state) { |
| Sailesh Nepal | 091768c | 2014-06-30 15:15:23 -0700 | [diff] [blame] | 1081 | try { |
| 1082 | if (mConnected) { |
| Brad Ebinger | b32d4f8 | 2016-10-24 16:40:49 -0700 | [diff] [blame] | 1083 | mConnectionService.onCallAudioStateChanged(mConnectionId, state, |
| 1084 | null /*Session.Info*/); |
| Sailesh Nepal | 091768c | 2014-06-30 15:15:23 -0700 | [diff] [blame] | 1085 | } |
| 1086 | } catch (RemoteException ignored) { |
| 1087 | } |
| 1088 | } |
| 1089 | |
| Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 1090 | /** |
| Hall Liu | b64ac4c | 2017-02-06 10:49:48 -0800 | [diff] [blame] | 1091 | * Notifies this {@link RemoteConnection} that the user has requested an RTT session. |
| 1092 | * @param rttTextStream The object that should be used to send text to or receive text from |
| 1093 | * the in-call app. |
| 1094 | * @hide |
| 1095 | */ |
| 1096 | public void startRtt(@NonNull Connection.RttTextStream rttTextStream) { |
| 1097 | try { |
| 1098 | if (mConnected) { |
| 1099 | mConnectionService.startRtt(mConnectionId, rttTextStream.getFdFromInCall(), |
| 1100 | rttTextStream.getFdToInCall(), null /*Session.Info*/); |
| 1101 | } |
| 1102 | } catch (RemoteException ignored) { |
| 1103 | } |
| 1104 | } |
| 1105 | |
| 1106 | /** |
| 1107 | * Notifies this {@link RemoteConnection} that it should terminate any existing RTT |
| 1108 | * session. No response to Telecom is needed for this method. |
| 1109 | * @hide |
| 1110 | */ |
| 1111 | public void stopRtt() { |
| 1112 | try { |
| 1113 | if (mConnected) { |
| 1114 | mConnectionService.stopRtt(mConnectionId, null /*Session.Info*/); |
| 1115 | } |
| 1116 | } catch (RemoteException ignored) { |
| 1117 | } |
| 1118 | } |
| 1119 | |
| 1120 | /** |
| 1121 | * Notifies this {@link RemoteConnection} of a response to a previous remotely-initiated RTT |
| 1122 | * upgrade request sent via {@link Connection#sendRemoteRttRequest}. |
| 1123 | * Acceptance of the request is indicated by the supplied {@link RttTextStream} being non-null, |
| 1124 | * and rejection is indicated by {@code rttTextStream} being {@code null} |
| 1125 | * @hide |
| 1126 | * @param rttTextStream The object that should be used to send text to or receive text from |
| 1127 | * the in-call app. |
| 1128 | */ |
| 1129 | public void sendRttUpgradeResponse(@Nullable Connection.RttTextStream rttTextStream) { |
| 1130 | try { |
| 1131 | if (mConnected) { |
| 1132 | if (rttTextStream == null) { |
| 1133 | mConnectionService.respondToRttUpgradeRequest(mConnectionId, |
| 1134 | null, null, null /*Session.Info*/); |
| 1135 | } else { |
| 1136 | mConnectionService.respondToRttUpgradeRequest(mConnectionId, |
| 1137 | rttTextStream.getFdFromInCall(), rttTextStream.getFdToInCall(), |
| 1138 | null /*Session.Info*/); |
| 1139 | } |
| 1140 | } |
| 1141 | } catch (RemoteException ignored) { |
| 1142 | } |
| 1143 | } |
| 1144 | |
| 1145 | /** |
| Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 1146 | * Obtain the {@code RemoteConnection}s with which this {@code RemoteConnection} may be |
| 1147 | * successfully asked to create a conference with. |
| 1148 | * |
| 1149 | * @return The {@code RemoteConnection}s with which this {@code RemoteConnection} may be |
| 1150 | * merged into a {@link RemoteConference}. |
| 1151 | */ |
| 1152 | public List<RemoteConnection> getConferenceableConnections() { |
| 1153 | return mUnmodifiableconferenceableConnections; |
| 1154 | } |
| 1155 | |
| 1156 | /** |
| 1157 | * Obtain the {@code RemoteConference} that this {@code RemoteConnection} may be a part |
| 1158 | * of, or {@code null} if there is no such {@code RemoteConference}. |
| 1159 | * |
| 1160 | * @return A {@code RemoteConference} or {@code null}; |
| 1161 | */ |
| 1162 | public RemoteConference getConference() { |
| 1163 | return mConference; |
| 1164 | } |
| 1165 | |
| 1166 | /** {@hide} */ |
| 1167 | String getId() { |
| 1168 | return mConnectionId; |
| 1169 | } |
| 1170 | |
| 1171 | /** {@hide} */ |
| 1172 | IConnectionService getConnectionService() { |
| 1173 | return mConnectionService; |
| 1174 | } |
| 1175 | |
| 1176 | /** |
| Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 1177 | * @hide |
| 1178 | */ |
| Andrew Lee | 011728f | 2015-04-23 15:47:06 -0700 | [diff] [blame] | 1179 | void setState(final int state) { |
| Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 1180 | if (mState != state) { |
| 1181 | mState = state; |
| Andrew Lee | 011728f | 2015-04-23 15:47:06 -0700 | [diff] [blame] | 1182 | for (CallbackRecord record: mCallbackRecords) { |
| 1183 | final RemoteConnection connection = this; |
| 1184 | final Callback callback = record.getCallback(); |
| 1185 | record.getHandler().post(new Runnable() { |
| 1186 | @Override |
| 1187 | public void run() { |
| 1188 | callback.onStateChanged(connection, state); |
| 1189 | } |
| 1190 | }); |
| Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 1191 | } |
| 1192 | } |
| 1193 | } |
| 1194 | |
| 1195 | /** |
| 1196 | * @hide |
| 1197 | */ |
| Andrew Lee | 011728f | 2015-04-23 15:47:06 -0700 | [diff] [blame] | 1198 | void setDisconnected(final DisconnectCause disconnectCause) { |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 1199 | if (mState != Connection.STATE_DISCONNECTED) { |
| 1200 | mState = Connection.STATE_DISCONNECTED; |
| Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame] | 1201 | mDisconnectCause = disconnectCause; |
| Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 1202 | |
| Andrew Lee | 011728f | 2015-04-23 15:47:06 -0700 | [diff] [blame] | 1203 | for (CallbackRecord record : mCallbackRecords) { |
| 1204 | final RemoteConnection connection = this; |
| 1205 | final Callback callback = record.getCallback(); |
| 1206 | record.getHandler().post(new Runnable() { |
| 1207 | @Override |
| 1208 | public void run() { |
| 1209 | callback.onDisconnected(connection, disconnectCause); |
| 1210 | } |
| 1211 | }); |
| Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 1212 | } |
| 1213 | } |
| 1214 | } |
| 1215 | |
| 1216 | /** |
| 1217 | * @hide |
| 1218 | */ |
| Andrew Lee | 011728f | 2015-04-23 15:47:06 -0700 | [diff] [blame] | 1219 | void setRingbackRequested(final boolean ringback) { |
| Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 1220 | if (mRingbackRequested != ringback) { |
| 1221 | mRingbackRequested = ringback; |
| Andrew Lee | 011728f | 2015-04-23 15:47:06 -0700 | [diff] [blame] | 1222 | for (CallbackRecord record : mCallbackRecords) { |
| 1223 | final RemoteConnection connection = this; |
| 1224 | final Callback callback = record.getCallback(); |
| 1225 | record.getHandler().post(new Runnable() { |
| 1226 | @Override |
| 1227 | public void run() { |
| 1228 | callback.onRingbackRequested(connection, ringback); |
| 1229 | } |
| 1230 | }); |
| Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 1231 | } |
| 1232 | } |
| 1233 | } |
| 1234 | |
| 1235 | /** |
| 1236 | * @hide |
| 1237 | */ |
| Andrew Lee | 011728f | 2015-04-23 15:47:06 -0700 | [diff] [blame] | 1238 | void setConnectionCapabilities(final int connectionCapabilities) { |
| Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 1239 | mConnectionCapabilities = connectionCapabilities; |
| Andrew Lee | 011728f | 2015-04-23 15:47:06 -0700 | [diff] [blame] | 1240 | for (CallbackRecord record : mCallbackRecords) { |
| 1241 | final RemoteConnection connection = this; |
| 1242 | final Callback callback = record.getCallback(); |
| 1243 | record.getHandler().post(new Runnable() { |
| 1244 | @Override |
| 1245 | public void run() { |
| 1246 | callback.onConnectionCapabilitiesChanged(connection, connectionCapabilities); |
| 1247 | } |
| 1248 | }); |
| Sailesh Nepal | 1a7061b | 2014-07-09 21:03:20 -0700 | [diff] [blame] | 1249 | } |
| 1250 | } |
| 1251 | |
| 1252 | /** |
| 1253 | * @hide |
| 1254 | */ |
| Tyler Gunn | 720c664 | 2016-03-22 09:02:47 -0700 | [diff] [blame] | 1255 | void setConnectionProperties(final int connectionProperties) { |
| 1256 | mConnectionProperties = connectionProperties; |
| 1257 | for (CallbackRecord record : mCallbackRecords) { |
| 1258 | final RemoteConnection connection = this; |
| 1259 | final Callback callback = record.getCallback(); |
| 1260 | record.getHandler().post(new Runnable() { |
| 1261 | @Override |
| 1262 | public void run() { |
| 1263 | callback.onConnectionPropertiesChanged(connection, connectionProperties); |
| 1264 | } |
| 1265 | }); |
| 1266 | } |
| 1267 | } |
| 1268 | |
| 1269 | /** |
| 1270 | * @hide |
| 1271 | */ |
| Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 1272 | void setDestroyed() { |
| Andrew Lee | 011728f | 2015-04-23 15:47:06 -0700 | [diff] [blame] | 1273 | if (!mCallbackRecords.isEmpty()) { |
| Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 1274 | // Make sure that the callbacks are notified that the call is destroyed first. |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 1275 | if (mState != Connection.STATE_DISCONNECTED) { |
| Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame] | 1276 | setDisconnected( |
| 1277 | new DisconnectCause(DisconnectCause.ERROR, "Connection destroyed.")); |
| Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 1278 | } |
| 1279 | |
| Andrew Lee | 011728f | 2015-04-23 15:47:06 -0700 | [diff] [blame] | 1280 | for (CallbackRecord record : mCallbackRecords) { |
| 1281 | final RemoteConnection connection = this; |
| 1282 | final Callback callback = record.getCallback(); |
| 1283 | record.getHandler().post(new Runnable() { |
| 1284 | @Override |
| 1285 | public void run() { |
| 1286 | callback.onDestroyed(connection); |
| 1287 | } |
| 1288 | }); |
| Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 1289 | } |
| Andrew Lee | 011728f | 2015-04-23 15:47:06 -0700 | [diff] [blame] | 1290 | mCallbackRecords.clear(); |
| Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 1291 | |
| 1292 | mConnected = false; |
| 1293 | } |
| 1294 | } |
| 1295 | |
| 1296 | /** |
| 1297 | * @hide |
| 1298 | */ |
| Andrew Lee | 011728f | 2015-04-23 15:47:06 -0700 | [diff] [blame] | 1299 | void setPostDialWait(final String remainingDigits) { |
| 1300 | for (CallbackRecord record : mCallbackRecords) { |
| 1301 | final RemoteConnection connection = this; |
| 1302 | final Callback callback = record.getCallback(); |
| 1303 | record.getHandler().post(new Runnable() { |
| 1304 | @Override |
| 1305 | public void run() { |
| 1306 | callback.onPostDialWait(connection, remainingDigits); |
| 1307 | } |
| 1308 | }); |
| Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 1309 | } |
| 1310 | } |
| Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 1311 | |
| Tyler Gunn | aa07df8 | 2014-07-17 07:50:22 -0700 | [diff] [blame] | 1312 | /** |
| 1313 | * @hide |
| 1314 | */ |
| Andrew Lee | 011728f | 2015-04-23 15:47:06 -0700 | [diff] [blame] | 1315 | void onPostDialChar(final char nextChar) { |
| 1316 | for (CallbackRecord record : mCallbackRecords) { |
| 1317 | final RemoteConnection connection = this; |
| 1318 | final Callback callback = record.getCallback(); |
| 1319 | record.getHandler().post(new Runnable() { |
| 1320 | @Override |
| 1321 | public void run() { |
| Sailesh Nepal | 40451b3 | 2015-05-14 17:39:41 -0700 | [diff] [blame] | 1322 | callback.onPostDialChar(connection, nextChar); |
| Andrew Lee | 011728f | 2015-04-23 15:47:06 -0700 | [diff] [blame] | 1323 | } |
| 1324 | }); |
| Nancy Chen | 27d1c2d | 2014-12-15 16:12:50 -0800 | [diff] [blame] | 1325 | } |
| 1326 | } |
| 1327 | |
| 1328 | /** |
| 1329 | * @hide |
| 1330 | */ |
| Andrew Lee | 011728f | 2015-04-23 15:47:06 -0700 | [diff] [blame] | 1331 | void setVideoState(final int videoState) { |
| Tyler Gunn | aa07df8 | 2014-07-17 07:50:22 -0700 | [diff] [blame] | 1332 | mVideoState = videoState; |
| Andrew Lee | 011728f | 2015-04-23 15:47:06 -0700 | [diff] [blame] | 1333 | for (CallbackRecord record : mCallbackRecords) { |
| 1334 | final RemoteConnection connection = this; |
| 1335 | final Callback callback = record.getCallback(); |
| 1336 | record.getHandler().post(new Runnable() { |
| 1337 | @Override |
| 1338 | public void run() { |
| 1339 | callback.onVideoStateChanged(connection, videoState); |
| 1340 | } |
| 1341 | }); |
| Tyler Gunn | aa07df8 | 2014-07-17 07:50:22 -0700 | [diff] [blame] | 1342 | } |
| 1343 | } |
| 1344 | |
| Ihab Awad | a64627c | 2014-08-20 09:36:40 -0700 | [diff] [blame] | 1345 | /** |
| 1346 | * @hide |
| 1347 | */ |
| Andrew Lee | 011728f | 2015-04-23 15:47:06 -0700 | [diff] [blame] | 1348 | void setVideoProvider(final VideoProvider videoProvider) { |
| Ihab Awad | a64627c | 2014-08-20 09:36:40 -0700 | [diff] [blame] | 1349 | mVideoProvider = videoProvider; |
| Andrew Lee | 011728f | 2015-04-23 15:47:06 -0700 | [diff] [blame] | 1350 | for (CallbackRecord record : mCallbackRecords) { |
| 1351 | final RemoteConnection connection = this; |
| 1352 | final Callback callback = record.getCallback(); |
| 1353 | record.getHandler().post(new Runnable() { |
| 1354 | @Override |
| 1355 | public void run() { |
| 1356 | callback.onVideoProviderChanged(connection, videoProvider); |
| 1357 | } |
| 1358 | }); |
| Ihab Awad | a64627c | 2014-08-20 09:36:40 -0700 | [diff] [blame] | 1359 | } |
| 1360 | } |
| 1361 | |
| Sailesh Nepal | 33aaae4 | 2014-07-07 22:49:44 -0700 | [diff] [blame] | 1362 | /** @hide */ |
| Andrew Lee | 011728f | 2015-04-23 15:47:06 -0700 | [diff] [blame] | 1363 | void setIsVoipAudioMode(final boolean isVoip) { |
| Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 1364 | mIsVoipAudioMode = isVoip; |
| Andrew Lee | 011728f | 2015-04-23 15:47:06 -0700 | [diff] [blame] | 1365 | for (CallbackRecord record : mCallbackRecords) { |
| 1366 | final RemoteConnection connection = this; |
| 1367 | final Callback callback = record.getCallback(); |
| 1368 | record.getHandler().post(new Runnable() { |
| 1369 | @Override |
| 1370 | public void run() { |
| 1371 | callback.onVoipAudioChanged(connection, isVoip); |
| 1372 | } |
| 1373 | }); |
| Sailesh Nepal | 33aaae4 | 2014-07-07 22:49:44 -0700 | [diff] [blame] | 1374 | } |
| 1375 | } |
| Sailesh Nepal | e7ef59a | 2014-07-08 21:48:22 -0700 | [diff] [blame] | 1376 | |
| 1377 | /** @hide */ |
| Andrew Lee | 011728f | 2015-04-23 15:47:06 -0700 | [diff] [blame] | 1378 | void setStatusHints(final StatusHints statusHints) { |
| Sailesh Nepal | e7ef59a | 2014-07-08 21:48:22 -0700 | [diff] [blame] | 1379 | mStatusHints = statusHints; |
| Andrew Lee | 011728f | 2015-04-23 15:47:06 -0700 | [diff] [blame] | 1380 | for (CallbackRecord record : mCallbackRecords) { |
| 1381 | final RemoteConnection connection = this; |
| 1382 | final Callback callback = record.getCallback(); |
| 1383 | record.getHandler().post(new Runnable() { |
| 1384 | @Override |
| 1385 | public void run() { |
| 1386 | callback.onStatusHintsChanged(connection, statusHints); |
| 1387 | } |
| 1388 | }); |
| Sailesh Nepal | 6120386 | 2014-07-11 14:50:13 -0700 | [diff] [blame] | 1389 | } |
| 1390 | } |
| 1391 | |
| 1392 | /** @hide */ |
| Andrew Lee | 011728f | 2015-04-23 15:47:06 -0700 | [diff] [blame] | 1393 | void setAddress(final Uri address, final int presentation) { |
| Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 1394 | mAddress = address; |
| 1395 | mAddressPresentation = presentation; |
| Andrew Lee | 011728f | 2015-04-23 15:47:06 -0700 | [diff] [blame] | 1396 | for (CallbackRecord record : mCallbackRecords) { |
| 1397 | final RemoteConnection connection = this; |
| 1398 | final Callback callback = record.getCallback(); |
| 1399 | record.getHandler().post(new Runnable() { |
| 1400 | @Override |
| 1401 | public void run() { |
| 1402 | callback.onAddressChanged(connection, address, presentation); |
| 1403 | } |
| 1404 | }); |
| Sailesh Nepal | 6120386 | 2014-07-11 14:50:13 -0700 | [diff] [blame] | 1405 | } |
| 1406 | } |
| 1407 | |
| 1408 | /** @hide */ |
| Andrew Lee | 011728f | 2015-04-23 15:47:06 -0700 | [diff] [blame] | 1409 | void setCallerDisplayName(final String callerDisplayName, final int presentation) { |
| Sailesh Nepal | 6120386 | 2014-07-11 14:50:13 -0700 | [diff] [blame] | 1410 | mCallerDisplayName = callerDisplayName; |
| 1411 | mCallerDisplayNamePresentation = presentation; |
| Andrew Lee | 011728f | 2015-04-23 15:47:06 -0700 | [diff] [blame] | 1412 | for (CallbackRecord record : mCallbackRecords) { |
| 1413 | final RemoteConnection connection = this; |
| 1414 | final Callback callback = record.getCallback(); |
| 1415 | record.getHandler().post(new Runnable() { |
| 1416 | @Override |
| 1417 | public void run() { |
| 1418 | callback.onCallerDisplayNameChanged( |
| 1419 | connection, callerDisplayName, presentation); |
| 1420 | } |
| 1421 | }); |
| Sailesh Nepal | e7ef59a | 2014-07-08 21:48:22 -0700 | [diff] [blame] | 1422 | } |
| 1423 | } |
| Sailesh Nepal | 2ab88cc | 2014-07-18 14:49:18 -0700 | [diff] [blame] | 1424 | |
| 1425 | /** @hide */ |
| Andrew Lee | 011728f | 2015-04-23 15:47:06 -0700 | [diff] [blame] | 1426 | void setConferenceableConnections(final List<RemoteConnection> conferenceableConnections) { |
| Santos Cordon | 7c7bc7f | 2014-07-28 18:15:48 -0700 | [diff] [blame] | 1427 | mConferenceableConnections.clear(); |
| 1428 | mConferenceableConnections.addAll(conferenceableConnections); |
| Andrew Lee | 011728f | 2015-04-23 15:47:06 -0700 | [diff] [blame] | 1429 | for (CallbackRecord record : mCallbackRecords) { |
| 1430 | final RemoteConnection connection = this; |
| 1431 | final Callback callback = record.getCallback(); |
| 1432 | record.getHandler().post(new Runnable() { |
| 1433 | @Override |
| 1434 | public void run() { |
| 1435 | callback.onConferenceableConnectionsChanged( |
| 1436 | connection, mUnmodifiableconferenceableConnections); |
| 1437 | } |
| 1438 | }); |
| Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 1439 | } |
| 1440 | } |
| 1441 | |
| 1442 | /** @hide */ |
| Andrew Lee | 011728f | 2015-04-23 15:47:06 -0700 | [diff] [blame] | 1443 | void setConference(final RemoteConference conference) { |
| Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 1444 | if (mConference != conference) { |
| 1445 | mConference = conference; |
| Andrew Lee | 011728f | 2015-04-23 15:47:06 -0700 | [diff] [blame] | 1446 | for (CallbackRecord record : mCallbackRecords) { |
| 1447 | final RemoteConnection connection = this; |
| 1448 | final Callback callback = record.getCallback(); |
| 1449 | record.getHandler().post(new Runnable() { |
| 1450 | @Override |
| 1451 | public void run() { |
| 1452 | callback.onConferenceChanged(connection, conference); |
| 1453 | } |
| 1454 | }); |
| Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 1455 | } |
| Santos Cordon | 7c7bc7f | 2014-07-28 18:15:48 -0700 | [diff] [blame] | 1456 | } |
| 1457 | } |
| 1458 | |
| Santos Cordon | 6b7f955 | 2015-05-27 17:21:45 -0700 | [diff] [blame] | 1459 | /** @hide */ |
| Tyler Gunn | dee56a8 | 2016-03-23 16:06:34 -0700 | [diff] [blame] | 1460 | void putExtras(final Bundle extras) { |
| Tyler Gunn | cd6ccfd | 2016-10-17 15:48:19 -0700 | [diff] [blame] | 1461 | if (extras == null) { |
| 1462 | return; |
| 1463 | } |
| Tyler Gunn | dee56a8 | 2016-03-23 16:06:34 -0700 | [diff] [blame] | 1464 | if (mExtras == null) { |
| 1465 | mExtras = new Bundle(); |
| 1466 | } |
| 1467 | mExtras.putAll(extras); |
| 1468 | |
| 1469 | notifyExtrasChanged(); |
| 1470 | } |
| 1471 | |
| 1472 | /** @hide */ |
| 1473 | void removeExtras(List<String> keys) { |
| 1474 | if (mExtras == null || keys == null || keys.isEmpty()) { |
| 1475 | return; |
| 1476 | } |
| 1477 | for (String key : keys) { |
| 1478 | mExtras.remove(key); |
| 1479 | } |
| 1480 | |
| 1481 | notifyExtrasChanged(); |
| 1482 | } |
| 1483 | |
| 1484 | private void notifyExtrasChanged() { |
| Santos Cordon | 6b7f955 | 2015-05-27 17:21:45 -0700 | [diff] [blame] | 1485 | for (CallbackRecord record : mCallbackRecords) { |
| 1486 | final RemoteConnection connection = this; |
| 1487 | final Callback callback = record.getCallback(); |
| 1488 | record.getHandler().post(new Runnable() { |
| 1489 | @Override |
| 1490 | public void run() { |
| Tyler Gunn | dee56a8 | 2016-03-23 16:06:34 -0700 | [diff] [blame] | 1491 | callback.onExtrasChanged(connection, mExtras); |
| Santos Cordon | 6b7f955 | 2015-05-27 17:21:45 -0700 | [diff] [blame] | 1492 | } |
| 1493 | }); |
| 1494 | } |
| 1495 | } |
| 1496 | |
| Tyler Gunn | bd1eb1f | 2016-02-16 14:36:20 -0800 | [diff] [blame] | 1497 | /** @hide */ |
| Tyler Gunn | 876dbfb | 2016-03-14 15:18:07 -0700 | [diff] [blame] | 1498 | void onConnectionEvent(final String event, final Bundle extras) { |
| Tyler Gunn | bd1eb1f | 2016-02-16 14:36:20 -0800 | [diff] [blame] | 1499 | for (CallbackRecord record : mCallbackRecords) { |
| 1500 | final RemoteConnection connection = this; |
| 1501 | final Callback callback = record.getCallback(); |
| 1502 | record.getHandler().post(new Runnable() { |
| 1503 | @Override |
| 1504 | public void run() { |
| Tyler Gunn | 876dbfb | 2016-03-14 15:18:07 -0700 | [diff] [blame] | 1505 | callback.onConnectionEvent(connection, event, extras); |
| Tyler Gunn | bd1eb1f | 2016-02-16 14:36:20 -0800 | [diff] [blame] | 1506 | } |
| 1507 | }); |
| 1508 | } |
| 1509 | } |
| 1510 | |
| Hall Liu | b64ac4c | 2017-02-06 10:49:48 -0800 | [diff] [blame] | 1511 | /** @hide */ |
| 1512 | void onRttInitiationSuccess() { |
| 1513 | for (CallbackRecord record : mCallbackRecords) { |
| 1514 | final RemoteConnection connection = this; |
| 1515 | final Callback callback = record.getCallback(); |
| 1516 | record.getHandler().post( |
| 1517 | () -> callback.onRttInitiationSuccess(connection)); |
| 1518 | } |
| 1519 | } |
| 1520 | |
| 1521 | /** @hide */ |
| 1522 | void onRttInitiationFailure(int reason) { |
| 1523 | for (CallbackRecord record : mCallbackRecords) { |
| 1524 | final RemoteConnection connection = this; |
| 1525 | final Callback callback = record.getCallback(); |
| 1526 | record.getHandler().post( |
| 1527 | () -> callback.onRttInitiationFailure(connection, reason)); |
| 1528 | } |
| 1529 | } |
| 1530 | |
| 1531 | /** @hide */ |
| 1532 | void onRttSessionRemotelyTerminated() { |
| 1533 | for (CallbackRecord record : mCallbackRecords) { |
| 1534 | final RemoteConnection connection = this; |
| 1535 | final Callback callback = record.getCallback(); |
| 1536 | record.getHandler().post( |
| 1537 | () -> callback.onRttSessionRemotelyTerminated(connection)); |
| 1538 | } |
| 1539 | } |
| 1540 | |
| 1541 | /** @hide */ |
| 1542 | void onRemoteRttRequest() { |
| 1543 | for (CallbackRecord record : mCallbackRecords) { |
| 1544 | final RemoteConnection connection = this; |
| 1545 | final Callback callback = record.getCallback(); |
| 1546 | record.getHandler().post( |
| 1547 | () -> callback.onRemoteRttRequest(connection)); |
| 1548 | } |
| 1549 | } |
| 1550 | |
| 1551 | /** |
| Evan Charlton | bf11f98 | 2014-07-20 22:06:28 -0700 | [diff] [blame] | 1552 | /** |
| Ihab Awad | 6107bab | 2014-08-18 09:23:25 -0700 | [diff] [blame] | 1553 | * Create a RemoteConnection represents a failure, and which will be in |
| 1554 | * {@link Connection#STATE_DISCONNECTED}. Attempting to use it for anything will almost |
| 1555 | * certainly result in bad things happening. Do not do this. |
| Evan Charlton | bf11f98 | 2014-07-20 22:06:28 -0700 | [diff] [blame] | 1556 | * |
| 1557 | * @return a failed {@link RemoteConnection} |
| 1558 | * |
| 1559 | * @hide |
| Evan Charlton | bf11f98 | 2014-07-20 22:06:28 -0700 | [diff] [blame] | 1560 | */ |
| Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame] | 1561 | public static RemoteConnection failure(DisconnectCause disconnectCause) { |
| 1562 | return new RemoteConnection(disconnectCause); |
| Evan Charlton | bf11f98 | 2014-07-20 22:06:28 -0700 | [diff] [blame] | 1563 | } |
| Andrew Lee | 011728f | 2015-04-23 15:47:06 -0700 | [diff] [blame] | 1564 | |
| 1565 | private static final class CallbackRecord extends Callback { |
| 1566 | private final Callback mCallback; |
| 1567 | private final Handler mHandler; |
| 1568 | |
| 1569 | public CallbackRecord(Callback callback, Handler handler) { |
| 1570 | mCallback = callback; |
| 1571 | mHandler = handler; |
| 1572 | } |
| 1573 | |
| 1574 | public Callback getCallback() { |
| 1575 | return mCallback; |
| 1576 | } |
| 1577 | |
| 1578 | public Handler getHandler() { |
| 1579 | return mHandler; |
| 1580 | } |
| 1581 | } |
| Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 1582 | } |