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