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