Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -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; |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 18 | |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 19 | import com.android.internal.telecom.IVideoCallback; |
| 20 | import com.android.internal.telecom.IVideoProvider; |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 21 | |
Evan Charlton | 0e094d9 | 2014-11-08 15:49:16 -0800 | [diff] [blame] | 22 | import android.annotation.SystemApi; |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 23 | import android.net.Uri; |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 24 | import android.os.Handler; |
| 25 | import android.os.IBinder; |
| 26 | import android.os.Message; |
| 27 | import android.os.RemoteException; |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 28 | import android.view.Surface; |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 29 | |
Santos Cordon | b693998 | 2014-06-04 20:20:58 -0700 | [diff] [blame] | 30 | import java.util.ArrayList; |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 31 | import java.util.Collections; |
Santos Cordon | b693998 | 2014-06-04 20:20:58 -0700 | [diff] [blame] | 32 | import java.util.List; |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 33 | import java.util.Set; |
Jay Shrauner | 229e382 | 2014-08-15 09:23:07 -0700 | [diff] [blame] | 34 | import java.util.concurrent.ConcurrentHashMap; |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 35 | |
| 36 | /** |
| 37 | * Represents a connection to a remote endpoint that carries voice traffic. |
Ihab Awad | 6107bab | 2014-08-18 09:23:25 -0700 | [diff] [blame] | 38 | * <p> |
| 39 | * Implementations create a custom subclass of {@code Connection} and return it to the framework |
| 40 | * as the return value of |
| 41 | * {@link ConnectionService#onCreateIncomingConnection(PhoneAccountHandle, ConnectionRequest)} |
| 42 | * or |
| 43 | * {@link ConnectionService#onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}. |
| 44 | * Implementations are then responsible for updating the state of the {@code Connection}, and |
| 45 | * must call {@link #destroy()} to signal to the framework that the {@code Connection} is no |
| 46 | * longer used and associated resources may be recovered. |
Evan Charlton | 0e094d9 | 2014-11-08 15:49:16 -0800 | [diff] [blame] | 47 | * @hide |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 48 | */ |
Evan Charlton | 0e094d9 | 2014-11-08 15:49:16 -0800 | [diff] [blame] | 49 | @SystemApi |
Tyler Gunn | 6d76ca0 | 2014-11-17 15:49:51 -0800 | [diff] [blame] | 50 | public abstract class Connection implements IConferenceable { |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 51 | |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 52 | public static final int STATE_INITIALIZING = 0; |
| 53 | |
| 54 | public static final int STATE_NEW = 1; |
| 55 | |
| 56 | public static final int STATE_RINGING = 2; |
| 57 | |
| 58 | public static final int STATE_DIALING = 3; |
| 59 | |
| 60 | public static final int STATE_ACTIVE = 4; |
| 61 | |
| 62 | public static final int STATE_HOLDING = 5; |
| 63 | |
| 64 | public static final int STATE_DISCONNECTED = 6; |
| 65 | |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 66 | /** Connection can currently be put on hold or unheld. */ |
| 67 | public static final int CAPABILITY_HOLD = 0x00000001; |
| 68 | |
| 69 | /** Connection supports the hold feature. */ |
| 70 | public static final int CAPABILITY_SUPPORT_HOLD = 0x00000002; |
| 71 | |
| 72 | /** |
| 73 | * Connections within a conference can be merged. A {@link ConnectionService} has the option to |
| 74 | * add a {@link Conference} before the child {@link Connection}s are merged. This is how |
| 75 | * CDMA-based {@link Connection}s are implemented. For these unmerged {@link Conference}s, this |
| 76 | * capability allows a merge button to be shown while the conference is in the foreground |
| 77 | * of the in-call UI. |
| 78 | * <p> |
| 79 | * This is only intended for use by a {@link Conference}. |
| 80 | */ |
| 81 | public static final int CAPABILITY_MERGE_CONFERENCE = 0x00000004; |
| 82 | |
| 83 | /** |
| 84 | * Connections within a conference can be swapped between foreground and background. |
| 85 | * See {@link #CAPABILITY_MERGE_CONFERENCE} for additional information. |
| 86 | * <p> |
| 87 | * This is only intended for use by a {@link Conference}. |
| 88 | */ |
| 89 | public static final int CAPABILITY_SWAP_CONFERENCE = 0x00000008; |
| 90 | |
| 91 | /** |
| 92 | * @hide |
| 93 | */ |
| 94 | public static final int CAPABILITY_UNUSED = 0x00000010; |
| 95 | |
| 96 | /** Connection supports responding via text option. */ |
| 97 | public static final int CAPABILITY_RESPOND_VIA_TEXT = 0x00000020; |
| 98 | |
| 99 | /** Connection can be muted. */ |
| 100 | public static final int CAPABILITY_MUTE = 0x00000040; |
| 101 | |
| 102 | /** |
| 103 | * Connection supports conference management. This capability only applies to |
| 104 | * {@link Conference}s which can have {@link Connection}s as children. |
| 105 | */ |
| 106 | public static final int CAPABILITY_MANAGE_CONFERENCE = 0x00000080; |
| 107 | |
| 108 | /** |
Andrew Lee | 5e9e8bb | 2015-03-10 13:58:24 -0700 | [diff] [blame^] | 109 | * Local device supports receiving video. |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 110 | * @hide |
| 111 | */ |
Andrew Lee | 5e9e8bb | 2015-03-10 13:58:24 -0700 | [diff] [blame^] | 112 | public static final int CAPABILITY_SUPPORTS_VT_LOCAL_RX = 0x00000100; |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 113 | |
| 114 | /** |
Andrew Lee | 5e9e8bb | 2015-03-10 13:58:24 -0700 | [diff] [blame^] | 115 | * Local device supports transmitting video. |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 116 | * @hide |
| 117 | */ |
Andrew Lee | 5e9e8bb | 2015-03-10 13:58:24 -0700 | [diff] [blame^] | 118 | public static final int CAPABILITY_SUPPORTS_VT_LOCAL_TX = 0x00000200; |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 119 | |
| 120 | /** |
Andrew Lee | 5e9e8bb | 2015-03-10 13:58:24 -0700 | [diff] [blame^] | 121 | * Local device supports bidirectional video calling. |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 122 | * @hide |
| 123 | */ |
Andrew Lee | 5e9e8bb | 2015-03-10 13:58:24 -0700 | [diff] [blame^] | 124 | public static final int CAPABILITY_SUPPORTS_VT_LOCAL = |
| 125 | CAPABILITY_SUPPORTS_VT_LOCAL_RX | CAPABILITY_SUPPORTS_VT_LOCAL_TX; |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 126 | |
| 127 | /** |
Andrew Lee | 5e9e8bb | 2015-03-10 13:58:24 -0700 | [diff] [blame^] | 128 | * Remote device supports receiving video. |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 129 | * @hide |
| 130 | */ |
Andrew Lee | 5e9e8bb | 2015-03-10 13:58:24 -0700 | [diff] [blame^] | 131 | public static final int CAPABILITY_SUPPORTS_VT_REMOTE_RX = 0x00000400; |
| 132 | |
| 133 | /** |
| 134 | * Remote device supports transmitting video. |
| 135 | * @hide |
| 136 | */ |
| 137 | public static final int CAPABILITY_SUPPORTS_VT_REMOTE_TX = 0x00000800; |
| 138 | |
| 139 | /** |
| 140 | * Remote device supports bidirectional video calling. |
| 141 | * @hide |
| 142 | */ |
| 143 | public static final int CAPABILITY_SUPPORTS_VT_REMOTE = |
| 144 | CAPABILITY_SUPPORTS_VT_REMOTE_RX | CAPABILITY_SUPPORTS_VT_REMOTE_TX; |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 145 | |
| 146 | /** |
| 147 | * Connection is able to be separated from its parent {@code Conference}, if any. |
| 148 | */ |
| 149 | public static final int CAPABILITY_SEPARATE_FROM_CONFERENCE = 0x00001000; |
| 150 | |
| 151 | /** |
| 152 | * Connection is able to be individually disconnected when in a {@code Conference}. |
| 153 | */ |
| 154 | public static final int CAPABILITY_DISCONNECT_FROM_CONFERENCE = 0x00002000; |
| 155 | |
| 156 | /** |
| 157 | * Whether the call is a generic conference, where we do not know the precise state of |
| 158 | * participants in the conference (eg. on CDMA). |
| 159 | * |
| 160 | * @hide |
| 161 | */ |
| 162 | public static final int CAPABILITY_GENERIC_CONFERENCE = 0x00004000; |
| 163 | |
Andrew Lee | 5e9e8bb | 2015-03-10 13:58:24 -0700 | [diff] [blame^] | 164 | /** |
| 165 | * Connection is using high definition audio. |
| 166 | * @hide |
| 167 | */ |
| 168 | public static final int CAPABILITY_HIGH_DEF_AUDIO = 0x00008000; |
| 169 | |
| 170 | /** |
| 171 | * Connection is using WIFI. |
| 172 | * @hide |
| 173 | */ |
| 174 | public static final int CAPABILITY_WIFI = 0x000010000; |
| 175 | |
| 176 | //********************************************************************************************** |
| 177 | // Next CAPABILITY value: 0x00020000 |
| 178 | //********************************************************************************************** |
| 179 | |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 180 | // Flag controlling whether PII is emitted into the logs |
| 181 | private static final boolean PII_DEBUG = Log.isLoggable(android.util.Log.DEBUG); |
| 182 | |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 183 | /** |
| 184 | * Whether the given capabilities support the specified capability. |
| 185 | * |
| 186 | * @param capabilities A capability bit field. |
| 187 | * @param capability The capability to check capabilities for. |
| 188 | * @return Whether the specified capability is supported. |
| 189 | * @hide |
| 190 | */ |
| 191 | public static boolean can(int capabilities, int capability) { |
| 192 | return (capabilities & capability) != 0; |
| 193 | } |
| 194 | |
| 195 | /** |
| 196 | * Whether the capabilities of this {@code Connection} supports the specified capability. |
| 197 | * |
| 198 | * @param capability The capability to check capabilities for. |
| 199 | * @return Whether the specified capability is supported. |
| 200 | * @hide |
| 201 | */ |
| 202 | public boolean can(int capability) { |
| 203 | return can(mConnectionCapabilities, capability); |
| 204 | } |
| 205 | |
| 206 | /** |
| 207 | * Removes the specified capability from the set of capabilities of this {@code Connection}. |
| 208 | * |
| 209 | * @param capability The capability to remove from the set. |
| 210 | * @hide |
| 211 | */ |
| 212 | public void removeCapability(int capability) { |
| 213 | mConnectionCapabilities &= ~capability; |
| 214 | } |
| 215 | |
| 216 | /** |
| 217 | * Adds the specified capability to the set of capabilities of this {@code Connection}. |
| 218 | * |
| 219 | * @param capability The capability to add to the set. |
| 220 | * @hide |
| 221 | */ |
| 222 | public void addCapability(int capability) { |
| 223 | mConnectionCapabilities |= capability; |
| 224 | } |
| 225 | |
| 226 | |
| 227 | public static String capabilitiesToString(int capabilities) { |
| 228 | StringBuilder builder = new StringBuilder(); |
| 229 | builder.append("[Capabilities:"); |
| 230 | if (can(capabilities, CAPABILITY_HOLD)) { |
| 231 | builder.append(" CAPABILITY_HOLD"); |
| 232 | } |
| 233 | if (can(capabilities, CAPABILITY_SUPPORT_HOLD)) { |
| 234 | builder.append(" CAPABILITY_SUPPORT_HOLD"); |
| 235 | } |
| 236 | if (can(capabilities, CAPABILITY_MERGE_CONFERENCE)) { |
| 237 | builder.append(" CAPABILITY_MERGE_CONFERENCE"); |
| 238 | } |
| 239 | if (can(capabilities, CAPABILITY_SWAP_CONFERENCE)) { |
| 240 | builder.append(" CAPABILITY_SWAP_CONFERENCE"); |
| 241 | } |
| 242 | if (can(capabilities, CAPABILITY_RESPOND_VIA_TEXT)) { |
| 243 | builder.append(" CAPABILITY_RESPOND_VIA_TEXT"); |
| 244 | } |
| 245 | if (can(capabilities, CAPABILITY_MUTE)) { |
| 246 | builder.append(" CAPABILITY_MUTE"); |
| 247 | } |
| 248 | if (can(capabilities, CAPABILITY_MANAGE_CONFERENCE)) { |
| 249 | builder.append(" CAPABILITY_MANAGE_CONFERENCE"); |
| 250 | } |
Andrew Lee | 5e9e8bb | 2015-03-10 13:58:24 -0700 | [diff] [blame^] | 251 | if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_RX)) { |
| 252 | builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_RX"); |
| 253 | } |
| 254 | if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_TX)) { |
| 255 | builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_TX"); |
| 256 | } |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 257 | if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL)) { |
| 258 | builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL"); |
| 259 | } |
Andrew Lee | 5e9e8bb | 2015-03-10 13:58:24 -0700 | [diff] [blame^] | 260 | if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_RX)) { |
| 261 | builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_RX"); |
| 262 | } |
| 263 | if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_TX)) { |
| 264 | builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_TX"); |
| 265 | } |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 266 | if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE)) { |
| 267 | builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE"); |
| 268 | } |
Andrew Lee | 80fff3c | 2014-11-25 17:36:51 -0800 | [diff] [blame] | 269 | if (can(capabilities, CAPABILITY_HIGH_DEF_AUDIO)) { |
| 270 | builder.append(" CAPABILITY_HIGH_DEF_AUDIO"); |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 271 | } |
Andrew Lee | 1a8ae3e | 2015-02-02 13:42:38 -0800 | [diff] [blame] | 272 | if (can(capabilities, CAPABILITY_WIFI)) { |
| 273 | builder.append(" CAPABILITY_WIFI"); |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 274 | } |
| 275 | if (can(capabilities, CAPABILITY_GENERIC_CONFERENCE)) { |
| 276 | builder.append(" CAPABILITY_GENERIC_CONFERENCE"); |
| 277 | } |
| 278 | builder.append("]"); |
| 279 | return builder.toString(); |
| 280 | } |
| 281 | |
Sailesh Nepal | 091768c | 2014-06-30 15:15:23 -0700 | [diff] [blame] | 282 | /** @hide */ |
Sailesh Nepal | 6120386 | 2014-07-11 14:50:13 -0700 | [diff] [blame] | 283 | public abstract static class Listener { |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 284 | public void onStateChanged(Connection c, int state) {} |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 285 | public void onAddressChanged(Connection c, Uri newAddress, int presentation) {} |
Sailesh Nepal | 6120386 | 2014-07-11 14:50:13 -0700 | [diff] [blame] | 286 | public void onCallerDisplayNameChanged( |
| 287 | Connection c, String callerDisplayName, int presentation) {} |
Tyler Gunn | aa07df8 | 2014-07-17 07:50:22 -0700 | [diff] [blame] | 288 | public void onVideoStateChanged(Connection c, int videoState) {} |
Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame] | 289 | public void onDisconnected(Connection c, DisconnectCause disconnectCause) {} |
Sailesh Nepal | 091768c | 2014-06-30 15:15:23 -0700 | [diff] [blame] | 290 | public void onPostDialWait(Connection c, String remaining) {} |
Nancy Chen | 27d1c2d | 2014-12-15 16:12:50 -0800 | [diff] [blame] | 291 | public void onPostDialChar(Connection c, char nextChar) {} |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 292 | public void onRingbackRequested(Connection c, boolean ringback) {} |
Sailesh Nepal | 6120386 | 2014-07-11 14:50:13 -0700 | [diff] [blame] | 293 | public void onDestroyed(Connection c) {} |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 294 | public void onConnectionCapabilitiesChanged(Connection c, int capabilities) {} |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 295 | public void onVideoProviderChanged( |
| 296 | Connection c, VideoProvider videoProvider) {} |
Sailesh Nepal | 001bbbb | 2014-07-15 14:40:39 -0700 | [diff] [blame] | 297 | public void onAudioModeIsVoipChanged(Connection c, boolean isVoip) {} |
| 298 | public void onStatusHintsChanged(Connection c, StatusHints statusHints) {} |
Tyler Gunn | 6d76ca0 | 2014-11-17 15:49:51 -0800 | [diff] [blame] | 299 | public void onConferenceablesChanged( |
| 300 | Connection c, List<IConferenceable> conferenceables) {} |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 301 | public void onConferenceChanged(Connection c, Conference conference) {} |
Tyler Gunn | 3bffcf7 | 2014-10-28 13:51:27 -0700 | [diff] [blame] | 302 | /** @hide */ |
Tyler Gunn | ab4650c | 2014-11-06 20:06:23 -0800 | [diff] [blame] | 303 | public void onConferenceParticipantsChanged(Connection c, |
| 304 | List<ConferenceParticipant> participants) {} |
Tyler Gunn | 8a2b119 | 2015-01-29 11:47:24 -0800 | [diff] [blame] | 305 | public void onConferenceStarted() {} |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 306 | } |
| 307 | |
Tyler Gunn | 27d1e25 | 2014-08-21 16:38:40 -0700 | [diff] [blame] | 308 | /** @hide */ |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 309 | public static abstract class VideoProvider { |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 310 | |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 311 | /** |
| 312 | * Video is not being received (no protocol pause was issued). |
| 313 | */ |
| 314 | public static final int SESSION_EVENT_RX_PAUSE = 1; |
Evan Charlton | bf11f98 | 2014-07-20 22:06:28 -0700 | [diff] [blame] | 315 | |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 316 | /** |
| 317 | * Video reception has resumed after a SESSION_EVENT_RX_PAUSE. |
| 318 | */ |
| 319 | public static final int SESSION_EVENT_RX_RESUME = 2; |
| 320 | |
| 321 | /** |
| 322 | * Video transmission has begun. This occurs after a negotiated start of video transmission |
| 323 | * when the underlying protocol has actually begun transmitting video to the remote party. |
| 324 | */ |
| 325 | public static final int SESSION_EVENT_TX_START = 3; |
| 326 | |
| 327 | /** |
| 328 | * Video transmission has stopped. This occurs after a negotiated stop of video transmission |
| 329 | * when the underlying protocol has actually stopped transmitting video to the remote party. |
| 330 | */ |
| 331 | public static final int SESSION_EVENT_TX_STOP = 4; |
| 332 | |
| 333 | /** |
| 334 | * A camera failure has occurred for the selected camera. The In-Call UI can use this as a |
| 335 | * cue to inform the user the camera is not available. |
| 336 | */ |
| 337 | public static final int SESSION_EVENT_CAMERA_FAILURE = 5; |
| 338 | |
| 339 | /** |
| 340 | * Issued after {@code SESSION_EVENT_CAMERA_FAILURE} when the camera is once again ready for |
| 341 | * operation. The In-Call UI can use this as a cue to inform the user that the camera has |
| 342 | * become available again. |
| 343 | */ |
| 344 | public static final int SESSION_EVENT_CAMERA_READY = 6; |
| 345 | |
| 346 | /** |
| 347 | * Session modify request was successful. |
| 348 | */ |
| 349 | public static final int SESSION_MODIFY_REQUEST_SUCCESS = 1; |
| 350 | |
| 351 | /** |
| 352 | * Session modify request failed. |
| 353 | */ |
| 354 | public static final int SESSION_MODIFY_REQUEST_FAIL = 2; |
| 355 | |
| 356 | /** |
| 357 | * Session modify request ignored due to invalid parameters. |
| 358 | */ |
| 359 | public static final int SESSION_MODIFY_REQUEST_INVALID = 3; |
| 360 | |
Ihab Awad | a64627c | 2014-08-20 09:36:40 -0700 | [diff] [blame] | 361 | private static final int MSG_SET_VIDEO_CALLBACK = 1; |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 362 | private static final int MSG_SET_CAMERA = 2; |
| 363 | private static final int MSG_SET_PREVIEW_SURFACE = 3; |
| 364 | private static final int MSG_SET_DISPLAY_SURFACE = 4; |
| 365 | private static final int MSG_SET_DEVICE_ORIENTATION = 5; |
| 366 | private static final int MSG_SET_ZOOM = 6; |
| 367 | private static final int MSG_SEND_SESSION_MODIFY_REQUEST = 7; |
| 368 | private static final int MSG_SEND_SESSION_MODIFY_RESPONSE = 8; |
| 369 | private static final int MSG_REQUEST_CAMERA_CAPABILITIES = 9; |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 370 | private static final int MSG_REQUEST_CONNECTION_DATA_USAGE = 10; |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 371 | private static final int MSG_SET_PAUSE_IMAGE = 11; |
| 372 | |
| 373 | private final VideoProvider.VideoProviderHandler |
| 374 | mMessageHandler = new VideoProvider.VideoProviderHandler(); |
| 375 | private final VideoProvider.VideoProviderBinder mBinder; |
Ihab Awad | a64627c | 2014-08-20 09:36:40 -0700 | [diff] [blame] | 376 | private IVideoCallback mVideoCallback; |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 377 | |
| 378 | /** |
| 379 | * Default handler used to consolidate binder method calls onto a single thread. |
| 380 | */ |
| 381 | private final class VideoProviderHandler extends Handler { |
| 382 | @Override |
| 383 | public void handleMessage(Message msg) { |
| 384 | switch (msg.what) { |
Ihab Awad | a64627c | 2014-08-20 09:36:40 -0700 | [diff] [blame] | 385 | case MSG_SET_VIDEO_CALLBACK: |
| 386 | mVideoCallback = IVideoCallback.Stub.asInterface((IBinder) msg.obj); |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 387 | break; |
| 388 | case MSG_SET_CAMERA: |
| 389 | onSetCamera((String) msg.obj); |
| 390 | break; |
| 391 | case MSG_SET_PREVIEW_SURFACE: |
| 392 | onSetPreviewSurface((Surface) msg.obj); |
| 393 | break; |
| 394 | case MSG_SET_DISPLAY_SURFACE: |
| 395 | onSetDisplaySurface((Surface) msg.obj); |
| 396 | break; |
| 397 | case MSG_SET_DEVICE_ORIENTATION: |
| 398 | onSetDeviceOrientation(msg.arg1); |
| 399 | break; |
| 400 | case MSG_SET_ZOOM: |
| 401 | onSetZoom((Float) msg.obj); |
| 402 | break; |
| 403 | case MSG_SEND_SESSION_MODIFY_REQUEST: |
| 404 | onSendSessionModifyRequest((VideoProfile) msg.obj); |
| 405 | break; |
| 406 | case MSG_SEND_SESSION_MODIFY_RESPONSE: |
| 407 | onSendSessionModifyResponse((VideoProfile) msg.obj); |
| 408 | break; |
| 409 | case MSG_REQUEST_CAMERA_CAPABILITIES: |
| 410 | onRequestCameraCapabilities(); |
| 411 | break; |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 412 | case MSG_REQUEST_CONNECTION_DATA_USAGE: |
| 413 | onRequestConnectionDataUsage(); |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 414 | break; |
| 415 | case MSG_SET_PAUSE_IMAGE: |
| 416 | onSetPauseImage((String) msg.obj); |
| 417 | break; |
| 418 | default: |
| 419 | break; |
| 420 | } |
| 421 | } |
| 422 | } |
| 423 | |
| 424 | /** |
| 425 | * IVideoProvider stub implementation. |
| 426 | */ |
| 427 | private final class VideoProviderBinder extends IVideoProvider.Stub { |
Ihab Awad | a64627c | 2014-08-20 09:36:40 -0700 | [diff] [blame] | 428 | public void setVideoCallback(IBinder videoCallbackBinder) { |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 429 | mMessageHandler.obtainMessage( |
Ihab Awad | a64627c | 2014-08-20 09:36:40 -0700 | [diff] [blame] | 430 | MSG_SET_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget(); |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 431 | } |
| 432 | |
| 433 | public void setCamera(String cameraId) { |
| 434 | mMessageHandler.obtainMessage(MSG_SET_CAMERA, cameraId).sendToTarget(); |
| 435 | } |
| 436 | |
| 437 | public void setPreviewSurface(Surface surface) { |
| 438 | mMessageHandler.obtainMessage(MSG_SET_PREVIEW_SURFACE, surface).sendToTarget(); |
| 439 | } |
| 440 | |
| 441 | public void setDisplaySurface(Surface surface) { |
| 442 | mMessageHandler.obtainMessage(MSG_SET_DISPLAY_SURFACE, surface).sendToTarget(); |
| 443 | } |
| 444 | |
| 445 | public void setDeviceOrientation(int rotation) { |
| 446 | mMessageHandler.obtainMessage(MSG_SET_DEVICE_ORIENTATION, rotation).sendToTarget(); |
| 447 | } |
| 448 | |
| 449 | public void setZoom(float value) { |
| 450 | mMessageHandler.obtainMessage(MSG_SET_ZOOM, value).sendToTarget(); |
| 451 | } |
| 452 | |
| 453 | public void sendSessionModifyRequest(VideoProfile requestProfile) { |
| 454 | mMessageHandler.obtainMessage( |
| 455 | MSG_SEND_SESSION_MODIFY_REQUEST, requestProfile).sendToTarget(); |
| 456 | } |
| 457 | |
| 458 | public void sendSessionModifyResponse(VideoProfile responseProfile) { |
| 459 | mMessageHandler.obtainMessage( |
| 460 | MSG_SEND_SESSION_MODIFY_RESPONSE, responseProfile).sendToTarget(); |
| 461 | } |
| 462 | |
| 463 | public void requestCameraCapabilities() { |
| 464 | mMessageHandler.obtainMessage(MSG_REQUEST_CAMERA_CAPABILITIES).sendToTarget(); |
| 465 | } |
| 466 | |
| 467 | public void requestCallDataUsage() { |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 468 | mMessageHandler.obtainMessage(MSG_REQUEST_CONNECTION_DATA_USAGE).sendToTarget(); |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 469 | } |
| 470 | |
| 471 | public void setPauseImage(String uri) { |
| 472 | mMessageHandler.obtainMessage(MSG_SET_PAUSE_IMAGE, uri).sendToTarget(); |
| 473 | } |
| 474 | } |
| 475 | |
| 476 | public VideoProvider() { |
| 477 | mBinder = new VideoProvider.VideoProviderBinder(); |
| 478 | } |
| 479 | |
| 480 | /** |
| 481 | * Returns binder object which can be used across IPC methods. |
| 482 | * @hide |
| 483 | */ |
| 484 | public final IVideoProvider getInterface() { |
| 485 | return mBinder; |
| 486 | } |
| 487 | |
| 488 | /** |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 489 | * Sets the camera to be used for video recording in a video connection. |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 490 | * |
| 491 | * @param cameraId The id of the camera. |
| 492 | */ |
| 493 | public abstract void onSetCamera(String cameraId); |
| 494 | |
| 495 | /** |
| 496 | * Sets the surface to be used for displaying a preview of what the user's camera is |
| 497 | * currently capturing. When video transmission is enabled, this is the video signal which |
| 498 | * is sent to the remote device. |
| 499 | * |
| 500 | * @param surface The surface. |
| 501 | */ |
| 502 | public abstract void onSetPreviewSurface(Surface surface); |
| 503 | |
| 504 | /** |
| 505 | * Sets the surface to be used for displaying the video received from the remote device. |
| 506 | * |
| 507 | * @param surface The surface. |
| 508 | */ |
| 509 | public abstract void onSetDisplaySurface(Surface surface); |
| 510 | |
| 511 | /** |
| 512 | * Sets the device orientation, in degrees. Assumes that a standard portrait orientation of |
| 513 | * the device is 0 degrees. |
| 514 | * |
| 515 | * @param rotation The device orientation, in degrees. |
| 516 | */ |
| 517 | public abstract void onSetDeviceOrientation(int rotation); |
| 518 | |
| 519 | /** |
| 520 | * Sets camera zoom ratio. |
| 521 | * |
| 522 | * @param value The camera zoom ratio. |
| 523 | */ |
| 524 | public abstract void onSetZoom(float value); |
| 525 | |
| 526 | /** |
| 527 | * Issues a request to modify the properties of the current session. The request is |
| 528 | * sent to the remote device where it it handled by the In-Call UI. |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 529 | * Some examples of session modification requests: upgrade connection from audio to video, |
| 530 | * downgrade connection from video to audio, pause video. |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 531 | * |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 532 | * @param requestProfile The requested connection video properties. |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 533 | */ |
| 534 | public abstract void onSendSessionModifyRequest(VideoProfile requestProfile); |
| 535 | |
| 536 | /**te |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 537 | * Provides a response to a request to change the current connection session video |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 538 | * properties. |
| 539 | * This is in response to a request the InCall UI has received via the InCall UI. |
| 540 | * |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 541 | * @param responseProfile The response connection video properties. |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 542 | */ |
| 543 | public abstract void onSendSessionModifyResponse(VideoProfile responseProfile); |
| 544 | |
| 545 | /** |
| 546 | * Issues a request to the video provider to retrieve the camera capabilities. |
| 547 | * Camera capabilities are reported back to the caller via the In-Call UI. |
| 548 | */ |
| 549 | public abstract void onRequestCameraCapabilities(); |
| 550 | |
| 551 | /** |
| 552 | * Issues a request to the video telephony framework to retrieve the cumulative data usage |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 553 | * for the current connection. Data usage is reported back to the caller via the |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 554 | * InCall UI. |
| 555 | */ |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 556 | public abstract void onRequestConnectionDataUsage(); |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 557 | |
| 558 | /** |
| 559 | * Provides the video telephony framework with the URI of an image to be displayed to remote |
| 560 | * devices when the video signal is paused. |
| 561 | * |
| 562 | * @param uri URI of image to display. |
| 563 | */ |
| 564 | public abstract void onSetPauseImage(String uri); |
| 565 | |
| 566 | /** |
| 567 | * Invokes callback method defined in In-Call UI. |
| 568 | * |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 569 | * @param videoProfile The requested video connection profile. |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 570 | */ |
| 571 | public void receiveSessionModifyRequest(VideoProfile videoProfile) { |
Ihab Awad | a64627c | 2014-08-20 09:36:40 -0700 | [diff] [blame] | 572 | if (mVideoCallback != null) { |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 573 | try { |
Ihab Awad | a64627c | 2014-08-20 09:36:40 -0700 | [diff] [blame] | 574 | mVideoCallback.receiveSessionModifyRequest(videoProfile); |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 575 | } catch (RemoteException ignored) { |
| 576 | } |
| 577 | } |
| 578 | } |
| 579 | |
| 580 | /** |
| 581 | * Invokes callback method defined in In-Call UI. |
| 582 | * |
| 583 | * @param status Status of the session modify request. Valid values are |
| 584 | * {@link VideoProvider#SESSION_MODIFY_REQUEST_SUCCESS}, |
| 585 | * {@link VideoProvider#SESSION_MODIFY_REQUEST_FAIL}, |
| 586 | * {@link VideoProvider#SESSION_MODIFY_REQUEST_INVALID} |
| 587 | * @param requestedProfile The original request which was sent to the remote device. |
| 588 | * @param responseProfile The actual profile changes made by the remote device. |
| 589 | */ |
| 590 | public void receiveSessionModifyResponse(int status, |
| 591 | VideoProfile requestedProfile, VideoProfile responseProfile) { |
Ihab Awad | a64627c | 2014-08-20 09:36:40 -0700 | [diff] [blame] | 592 | if (mVideoCallback != null) { |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 593 | try { |
Ihab Awad | a64627c | 2014-08-20 09:36:40 -0700 | [diff] [blame] | 594 | mVideoCallback.receiveSessionModifyResponse( |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 595 | status, requestedProfile, responseProfile); |
| 596 | } catch (RemoteException ignored) { |
| 597 | } |
| 598 | } |
| 599 | } |
| 600 | |
| 601 | /** |
| 602 | * Invokes callback method defined in In-Call UI. |
| 603 | * |
| 604 | * Valid values are: {@link VideoProvider#SESSION_EVENT_RX_PAUSE}, |
| 605 | * {@link VideoProvider#SESSION_EVENT_RX_RESUME}, |
| 606 | * {@link VideoProvider#SESSION_EVENT_TX_START}, |
| 607 | * {@link VideoProvider#SESSION_EVENT_TX_STOP} |
| 608 | * |
| 609 | * @param event The event. |
| 610 | */ |
| 611 | public void handleCallSessionEvent(int event) { |
Ihab Awad | a64627c | 2014-08-20 09:36:40 -0700 | [diff] [blame] | 612 | if (mVideoCallback != null) { |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 613 | try { |
Ihab Awad | a64627c | 2014-08-20 09:36:40 -0700 | [diff] [blame] | 614 | mVideoCallback.handleCallSessionEvent(event); |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 615 | } catch (RemoteException ignored) { |
| 616 | } |
| 617 | } |
| 618 | } |
| 619 | |
| 620 | /** |
| 621 | * Invokes callback method defined in In-Call UI. |
| 622 | * |
| 623 | * @param width The updated peer video width. |
| 624 | * @param height The updated peer video height. |
| 625 | */ |
| 626 | public void changePeerDimensions(int width, int height) { |
Ihab Awad | a64627c | 2014-08-20 09:36:40 -0700 | [diff] [blame] | 627 | if (mVideoCallback != null) { |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 628 | try { |
Ihab Awad | a64627c | 2014-08-20 09:36:40 -0700 | [diff] [blame] | 629 | mVideoCallback.changePeerDimensions(width, height); |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 630 | } catch (RemoteException ignored) { |
| 631 | } |
| 632 | } |
| 633 | } |
| 634 | |
| 635 | /** |
| 636 | * Invokes callback method defined in In-Call UI. |
| 637 | * |
| 638 | * @param dataUsage The updated data usage. |
| 639 | */ |
| 640 | public void changeCallDataUsage(int dataUsage) { |
Ihab Awad | a64627c | 2014-08-20 09:36:40 -0700 | [diff] [blame] | 641 | if (mVideoCallback != null) { |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 642 | try { |
Ihab Awad | a64627c | 2014-08-20 09:36:40 -0700 | [diff] [blame] | 643 | mVideoCallback.changeCallDataUsage(dataUsage); |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 644 | } catch (RemoteException ignored) { |
| 645 | } |
| 646 | } |
| 647 | } |
| 648 | |
| 649 | /** |
| 650 | * Invokes callback method defined in In-Call UI. |
| 651 | * |
| 652 | * @param cameraCapabilities The changed camera capabilities. |
| 653 | */ |
| 654 | public void changeCameraCapabilities(CameraCapabilities cameraCapabilities) { |
Ihab Awad | a64627c | 2014-08-20 09:36:40 -0700 | [diff] [blame] | 655 | if (mVideoCallback != null) { |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 656 | try { |
Ihab Awad | a64627c | 2014-08-20 09:36:40 -0700 | [diff] [blame] | 657 | mVideoCallback.changeCameraCapabilities(cameraCapabilities); |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 658 | } catch (RemoteException ignored) { |
| 659 | } |
| 660 | } |
| 661 | } |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 662 | } |
| 663 | |
Santos Cordon | 7c7bc7f | 2014-07-28 18:15:48 -0700 | [diff] [blame] | 664 | private final Listener mConnectionDeathListener = new Listener() { |
| 665 | @Override |
| 666 | public void onDestroyed(Connection c) { |
Tyler Gunn | 6d76ca0 | 2014-11-17 15:49:51 -0800 | [diff] [blame] | 667 | if (mConferenceables.remove(c)) { |
| 668 | fireOnConferenceableConnectionsChanged(); |
| 669 | } |
| 670 | } |
| 671 | }; |
| 672 | |
| 673 | private final Conference.Listener mConferenceDeathListener = new Conference.Listener() { |
| 674 | @Override |
| 675 | public void onDestroyed(Conference c) { |
| 676 | if (mConferenceables.remove(c)) { |
Santos Cordon | 7c7bc7f | 2014-07-28 18:15:48 -0700 | [diff] [blame] | 677 | fireOnConferenceableConnectionsChanged(); |
| 678 | } |
| 679 | } |
| 680 | }; |
| 681 | |
Jay Shrauner | 229e382 | 2014-08-15 09:23:07 -0700 | [diff] [blame] | 682 | /** |
| 683 | * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is |
| 684 | * load factor before resizing, 1 means we only expect a single thread to |
| 685 | * access the map so make only a single shard |
| 686 | */ |
| 687 | private final Set<Listener> mListeners = Collections.newSetFromMap( |
| 688 | new ConcurrentHashMap<Listener, Boolean>(8, 0.9f, 1)); |
Tyler Gunn | 6d76ca0 | 2014-11-17 15:49:51 -0800 | [diff] [blame] | 689 | private final List<IConferenceable> mConferenceables = new ArrayList<>(); |
| 690 | private final List<IConferenceable> mUnmodifiableConferenceables = |
| 691 | Collections.unmodifiableList(mConferenceables); |
Santos Cordon | b693998 | 2014-06-04 20:20:58 -0700 | [diff] [blame] | 692 | |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 693 | private int mState = STATE_NEW; |
| 694 | private AudioState mAudioState; |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 695 | private Uri mAddress; |
| 696 | private int mAddressPresentation; |
Sailesh Nepal | 6120386 | 2014-07-11 14:50:13 -0700 | [diff] [blame] | 697 | private String mCallerDisplayName; |
| 698 | private int mCallerDisplayNamePresentation; |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 699 | private boolean mRingbackRequested = false; |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 700 | private int mConnectionCapabilities; |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 701 | private VideoProvider mVideoProvider; |
Sailesh Nepal | 33aaae4 | 2014-07-07 22:49:44 -0700 | [diff] [blame] | 702 | private boolean mAudioModeIsVoip; |
Sailesh Nepal | e7ef59a | 2014-07-08 21:48:22 -0700 | [diff] [blame] | 703 | private StatusHints mStatusHints; |
Tyler Gunn | aa07df8 | 2014-07-17 07:50:22 -0700 | [diff] [blame] | 704 | private int mVideoState; |
Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame] | 705 | private DisconnectCause mDisconnectCause; |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 706 | private Conference mConference; |
| 707 | private ConnectionService mConnectionService; |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 708 | |
| 709 | /** |
| 710 | * Create a new Connection. |
| 711 | */ |
Santos Cordon | f295110 | 2014-07-20 19:06:29 -0700 | [diff] [blame] | 712 | public Connection() {} |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 713 | |
| 714 | /** |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 715 | * @return The address (e.g., phone number) to which this Connection is currently communicating. |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 716 | */ |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 717 | public final Uri getAddress() { |
| 718 | return mAddress; |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 719 | } |
| 720 | |
| 721 | /** |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 722 | * @return The presentation requirements for the address. |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 723 | * See {@link TelecomManager} for valid values. |
Sailesh Nepal | 6120386 | 2014-07-11 14:50:13 -0700 | [diff] [blame] | 724 | */ |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 725 | public final int getAddressPresentation() { |
| 726 | return mAddressPresentation; |
Sailesh Nepal | 6120386 | 2014-07-11 14:50:13 -0700 | [diff] [blame] | 727 | } |
| 728 | |
| 729 | /** |
| 730 | * @return The caller display name (CNAP). |
| 731 | */ |
| 732 | public final String getCallerDisplayName() { |
| 733 | return mCallerDisplayName; |
| 734 | } |
| 735 | |
| 736 | /** |
Nancy Chen | 9d568c0 | 2014-09-08 14:17:59 -0700 | [diff] [blame] | 737 | * @return The presentation requirements for the handle. |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 738 | * See {@link TelecomManager} for valid values. |
Sailesh Nepal | 6120386 | 2014-07-11 14:50:13 -0700 | [diff] [blame] | 739 | */ |
| 740 | public final int getCallerDisplayNamePresentation() { |
| 741 | return mCallerDisplayNamePresentation; |
| 742 | } |
| 743 | |
| 744 | /** |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 745 | * @return The state of this Connection. |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 746 | */ |
| 747 | public final int getState() { |
| 748 | return mState; |
| 749 | } |
| 750 | |
| 751 | /** |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 752 | * Returns the video state of the connection. |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 753 | * Valid values: {@link VideoProfile.VideoState#AUDIO_ONLY}, |
| 754 | * {@link VideoProfile.VideoState#BIDIRECTIONAL}, |
| 755 | * {@link VideoProfile.VideoState#TX_ENABLED}, |
| 756 | * {@link VideoProfile.VideoState#RX_ENABLED}. |
Tyler Gunn | aa07df8 | 2014-07-17 07:50:22 -0700 | [diff] [blame] | 757 | * |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 758 | * @return The video state of the connection. |
Tyler Gunn | 27d1e25 | 2014-08-21 16:38:40 -0700 | [diff] [blame] | 759 | * @hide |
Tyler Gunn | aa07df8 | 2014-07-17 07:50:22 -0700 | [diff] [blame] | 760 | */ |
| 761 | public final int getVideoState() { |
| 762 | return mVideoState; |
| 763 | } |
| 764 | |
| 765 | /** |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 766 | * @return The audio state of the connection, describing how its audio is currently |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 767 | * being routed by the system. This is {@code null} if this Connection |
| 768 | * does not directly know about its audio state. |
| 769 | */ |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 770 | public final AudioState getAudioState() { |
| 771 | return mAudioState; |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 772 | } |
| 773 | |
| 774 | /** |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 775 | * @return The conference that this connection is a part of. Null if it is not part of any |
| 776 | * conference. |
| 777 | */ |
| 778 | public final Conference getConference() { |
| 779 | return mConference; |
| 780 | } |
| 781 | |
| 782 | /** |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 783 | * Returns whether this connection is requesting that the system play a ringback tone |
| 784 | * on its behalf. |
| 785 | */ |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 786 | public final boolean isRingbackRequested() { |
| 787 | return mRingbackRequested; |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 788 | } |
| 789 | |
| 790 | /** |
Sailesh Nepal | 33aaae4 | 2014-07-07 22:49:44 -0700 | [diff] [blame] | 791 | * @return True if the connection's audio mode is VOIP. |
| 792 | */ |
| 793 | public final boolean getAudioModeIsVoip() { |
| 794 | return mAudioModeIsVoip; |
| 795 | } |
| 796 | |
| 797 | /** |
Sailesh Nepal | e7ef59a | 2014-07-08 21:48:22 -0700 | [diff] [blame] | 798 | * @return The status hints for this connection. |
| 799 | */ |
| 800 | public final StatusHints getStatusHints() { |
| 801 | return mStatusHints; |
| 802 | } |
| 803 | |
| 804 | /** |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 805 | * Assign a listener to be notified of state changes. |
| 806 | * |
| 807 | * @param l A listener. |
| 808 | * @return This Connection. |
| 809 | * |
| 810 | * @hide |
| 811 | */ |
| 812 | public final Connection addConnectionListener(Listener l) { |
Santos Cordon | d34e571 | 2014-08-05 18:54:03 +0000 | [diff] [blame] | 813 | mListeners.add(l); |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 814 | return this; |
| 815 | } |
| 816 | |
| 817 | /** |
| 818 | * Remove a previously assigned listener that was being notified of state changes. |
| 819 | * |
| 820 | * @param l A Listener. |
| 821 | * @return This Connection. |
| 822 | * |
| 823 | * @hide |
| 824 | */ |
| 825 | public final Connection removeConnectionListener(Listener l) { |
Jay Shrauner | 229e382 | 2014-08-15 09:23:07 -0700 | [diff] [blame] | 826 | if (l != null) { |
| 827 | mListeners.remove(l); |
| 828 | } |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 829 | return this; |
| 830 | } |
| 831 | |
| 832 | /** |
Sailesh Nepal | cf7020b | 2014-08-20 10:07:19 -0700 | [diff] [blame] | 833 | * @return The {@link DisconnectCause} for this connection. |
Evan Charlton | bf11f98 | 2014-07-20 22:06:28 -0700 | [diff] [blame] | 834 | */ |
Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame] | 835 | public final DisconnectCause getDisconnectCause() { |
Sailesh Nepal | cf7020b | 2014-08-20 10:07:19 -0700 | [diff] [blame] | 836 | return mDisconnectCause; |
Evan Charlton | bf11f98 | 2014-07-20 22:06:28 -0700 | [diff] [blame] | 837 | } |
| 838 | |
| 839 | /** |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 840 | * Inform this Connection that the state of its audio output has been changed externally. |
| 841 | * |
| 842 | * @param state The new audio state. |
Sailesh Nepal | 400cc48 | 2014-06-26 12:04:00 -0700 | [diff] [blame] | 843 | * @hide |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 844 | */ |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 845 | final void setAudioState(AudioState state) { |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 846 | checkImmutable(); |
Ihab Awad | 60ac30b | 2014-05-20 22:32:12 -0700 | [diff] [blame] | 847 | Log.d(this, "setAudioState %s", state); |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 848 | mAudioState = state; |
Nancy Chen | 354b2bd | 2014-09-08 18:27:26 -0700 | [diff] [blame] | 849 | onAudioStateChanged(state); |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 850 | } |
| 851 | |
| 852 | /** |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 853 | * @param state An integer value of a {@code STATE_*} constant. |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 854 | * @return A string representation of the value. |
| 855 | */ |
| 856 | public static String stateToString(int state) { |
| 857 | switch (state) { |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 858 | case STATE_INITIALIZING: |
| 859 | return "STATE_INITIALIZING"; |
| 860 | case STATE_NEW: |
| 861 | return "STATE_NEW"; |
| 862 | case STATE_RINGING: |
| 863 | return "STATE_RINGING"; |
| 864 | case STATE_DIALING: |
| 865 | return "STATE_DIALING"; |
| 866 | case STATE_ACTIVE: |
| 867 | return "STATE_ACTIVE"; |
| 868 | case STATE_HOLDING: |
| 869 | return "STATE_HOLDING"; |
| 870 | case STATE_DISCONNECTED: |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 871 | return "DISCONNECTED"; |
| 872 | default: |
Ihab Awad | 60ac30b | 2014-05-20 22:32:12 -0700 | [diff] [blame] | 873 | Log.wtf(Connection.class, "Unknown state %d", state); |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 874 | return "UNKNOWN"; |
| 875 | } |
| 876 | } |
| 877 | |
| 878 | /** |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 879 | * Returns the connection's capabilities, as a bit mask of the {@code CAPABILITY_*} constants. |
Ihab Awad | 52a28f6 | 2014-06-18 10:26:34 -0700 | [diff] [blame] | 880 | */ |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 881 | public final int getConnectionCapabilities() { |
| 882 | return mConnectionCapabilities; |
Ihab Awad | 52a28f6 | 2014-06-18 10:26:34 -0700 | [diff] [blame] | 883 | } |
| 884 | |
Sailesh Nepal | ef77f0e | 2014-12-02 15:18:25 -0800 | [diff] [blame] | 885 | /** @hide */ |
| 886 | @SystemApi @Deprecated public final int getCallCapabilities() { |
| 887 | return getConnectionCapabilities(); |
| 888 | } |
| 889 | |
Ihab Awad | 52a28f6 | 2014-06-18 10:26:34 -0700 | [diff] [blame] | 890 | /** |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 891 | * Sets the value of the {@link #getAddress()} property. |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 892 | * |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 893 | * @param address The new address. |
| 894 | * @param presentation The presentation requirements for the address. |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 895 | * See {@link TelecomManager} for valid values. |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 896 | */ |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 897 | public final void setAddress(Uri address, int presentation) { |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 898 | checkImmutable(); |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 899 | Log.d(this, "setAddress %s", address); |
| 900 | mAddress = address; |
| 901 | mAddressPresentation = presentation; |
Santos Cordon | d34e571 | 2014-08-05 18:54:03 +0000 | [diff] [blame] | 902 | for (Listener l : mListeners) { |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 903 | l.onAddressChanged(this, address, presentation); |
Santos Cordon | d34e571 | 2014-08-05 18:54:03 +0000 | [diff] [blame] | 904 | } |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 905 | } |
| 906 | |
| 907 | /** |
Sailesh Nepal | 6120386 | 2014-07-11 14:50:13 -0700 | [diff] [blame] | 908 | * Sets the caller display name (CNAP). |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 909 | * |
Sailesh Nepal | 6120386 | 2014-07-11 14:50:13 -0700 | [diff] [blame] | 910 | * @param callerDisplayName The new display name. |
Nancy Chen | 9d568c0 | 2014-09-08 14:17:59 -0700 | [diff] [blame] | 911 | * @param presentation The presentation requirements for the handle. |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 912 | * See {@link TelecomManager} for valid values. |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 913 | */ |
Sailesh Nepal | 6120386 | 2014-07-11 14:50:13 -0700 | [diff] [blame] | 914 | public final void setCallerDisplayName(String callerDisplayName, int presentation) { |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 915 | checkImmutable(); |
Sailesh Nepal | 6120386 | 2014-07-11 14:50:13 -0700 | [diff] [blame] | 916 | Log.d(this, "setCallerDisplayName %s", callerDisplayName); |
Santos Cordon | d34e571 | 2014-08-05 18:54:03 +0000 | [diff] [blame] | 917 | mCallerDisplayName = callerDisplayName; |
| 918 | mCallerDisplayNamePresentation = presentation; |
| 919 | for (Listener l : mListeners) { |
| 920 | l.onCallerDisplayNameChanged(this, callerDisplayName, presentation); |
| 921 | } |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 922 | } |
| 923 | |
| 924 | /** |
Tyler Gunn | aa07df8 | 2014-07-17 07:50:22 -0700 | [diff] [blame] | 925 | * Set the video state for the connection. |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 926 | * Valid values: {@link VideoProfile.VideoState#AUDIO_ONLY}, |
| 927 | * {@link VideoProfile.VideoState#BIDIRECTIONAL}, |
| 928 | * {@link VideoProfile.VideoState#TX_ENABLED}, |
| 929 | * {@link VideoProfile.VideoState#RX_ENABLED}. |
Tyler Gunn | aa07df8 | 2014-07-17 07:50:22 -0700 | [diff] [blame] | 930 | * |
| 931 | * @param videoState The new video state. |
Tyler Gunn | 27d1e25 | 2014-08-21 16:38:40 -0700 | [diff] [blame] | 932 | * @hide |
Tyler Gunn | aa07df8 | 2014-07-17 07:50:22 -0700 | [diff] [blame] | 933 | */ |
| 934 | public final void setVideoState(int videoState) { |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 935 | checkImmutable(); |
Tyler Gunn | aa07df8 | 2014-07-17 07:50:22 -0700 | [diff] [blame] | 936 | Log.d(this, "setVideoState %d", videoState); |
Santos Cordon | d34e571 | 2014-08-05 18:54:03 +0000 | [diff] [blame] | 937 | mVideoState = videoState; |
| 938 | for (Listener l : mListeners) { |
| 939 | l.onVideoStateChanged(this, mVideoState); |
| 940 | } |
Tyler Gunn | aa07df8 | 2014-07-17 07:50:22 -0700 | [diff] [blame] | 941 | } |
| 942 | |
| 943 | /** |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 944 | * Sets state to active (e.g., an ongoing connection where two or more parties can actively |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 945 | * communicate). |
| 946 | */ |
Sailesh Nepal | 400cc48 | 2014-06-26 12:04:00 -0700 | [diff] [blame] | 947 | public final void setActive() { |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 948 | checkImmutable(); |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 949 | setRingbackRequested(false); |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 950 | setState(STATE_ACTIVE); |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 951 | } |
| 952 | |
| 953 | /** |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 954 | * Sets state to ringing (e.g., an inbound ringing connection). |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 955 | */ |
Sailesh Nepal | 400cc48 | 2014-06-26 12:04:00 -0700 | [diff] [blame] | 956 | public final void setRinging() { |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 957 | checkImmutable(); |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 958 | setState(STATE_RINGING); |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 959 | } |
| 960 | |
| 961 | /** |
Evan Charlton | bf11f98 | 2014-07-20 22:06:28 -0700 | [diff] [blame] | 962 | * Sets state to initializing (this Connection is not yet ready to be used). |
| 963 | */ |
| 964 | public final void setInitializing() { |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 965 | checkImmutable(); |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 966 | setState(STATE_INITIALIZING); |
Evan Charlton | bf11f98 | 2014-07-20 22:06:28 -0700 | [diff] [blame] | 967 | } |
| 968 | |
| 969 | /** |
| 970 | * Sets state to initialized (the Connection has been set up and is now ready to be used). |
| 971 | */ |
| 972 | public final void setInitialized() { |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 973 | checkImmutable(); |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 974 | setState(STATE_NEW); |
Evan Charlton | bf11f98 | 2014-07-20 22:06:28 -0700 | [diff] [blame] | 975 | } |
| 976 | |
| 977 | /** |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 978 | * Sets state to dialing (e.g., dialing an outbound connection). |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 979 | */ |
Sailesh Nepal | 400cc48 | 2014-06-26 12:04:00 -0700 | [diff] [blame] | 980 | public final void setDialing() { |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 981 | checkImmutable(); |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 982 | setState(STATE_DIALING); |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 983 | } |
| 984 | |
| 985 | /** |
| 986 | * Sets state to be on hold. |
| 987 | */ |
Sailesh Nepal | 400cc48 | 2014-06-26 12:04:00 -0700 | [diff] [blame] | 988 | public final void setOnHold() { |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 989 | checkImmutable(); |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 990 | setState(STATE_HOLDING); |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 991 | } |
| 992 | |
| 993 | /** |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 994 | * Sets the video connection provider. |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 995 | * @param videoProvider The video provider. |
Tyler Gunn | 27d1e25 | 2014-08-21 16:38:40 -0700 | [diff] [blame] | 996 | * @hide |
Andrew Lee | 5ffbe8b | 2014-06-20 16:29:33 -0700 | [diff] [blame] | 997 | */ |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 998 | public final void setVideoProvider(VideoProvider videoProvider) { |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 999 | checkImmutable(); |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 1000 | mVideoProvider = videoProvider; |
Santos Cordon | d34e571 | 2014-08-05 18:54:03 +0000 | [diff] [blame] | 1001 | for (Listener l : mListeners) { |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 1002 | l.onVideoProviderChanged(this, videoProvider); |
Santos Cordon | d34e571 | 2014-08-05 18:54:03 +0000 | [diff] [blame] | 1003 | } |
Andrew Lee | 5ffbe8b | 2014-06-20 16:29:33 -0700 | [diff] [blame] | 1004 | } |
| 1005 | |
Tyler Gunn | 27d1e25 | 2014-08-21 16:38:40 -0700 | [diff] [blame] | 1006 | /** @hide */ |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 1007 | public final VideoProvider getVideoProvider() { |
| 1008 | return mVideoProvider; |
Andrew Lee | a27a193 | 2014-07-09 17:07:13 -0700 | [diff] [blame] | 1009 | } |
| 1010 | |
Andrew Lee | 5ffbe8b | 2014-06-20 16:29:33 -0700 | [diff] [blame] | 1011 | /** |
Sailesh Nepal | 091768c | 2014-06-30 15:15:23 -0700 | [diff] [blame] | 1012 | * Sets state to disconnected. |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 1013 | * |
Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame] | 1014 | * @param disconnectCause The reason for the disconnection, as specified by |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 1015 | * {@link DisconnectCause}. |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 1016 | */ |
Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame] | 1017 | public final void setDisconnected(DisconnectCause disconnectCause) { |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 1018 | checkImmutable(); |
Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame] | 1019 | mDisconnectCause = disconnectCause; |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 1020 | setState(STATE_DISCONNECTED); |
mike dooley | f34519b | 2014-09-16 17:33:40 -0700 | [diff] [blame] | 1021 | Log.d(this, "Disconnected with cause %s", disconnectCause); |
Santos Cordon | d34e571 | 2014-08-05 18:54:03 +0000 | [diff] [blame] | 1022 | for (Listener l : mListeners) { |
Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame] | 1023 | l.onDisconnected(this, disconnectCause); |
Santos Cordon | d34e571 | 2014-08-05 18:54:03 +0000 | [diff] [blame] | 1024 | } |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 1025 | } |
| 1026 | |
| 1027 | /** |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 1028 | * Informs listeners that this {@code Connection} is in a post-dial wait state. This is done |
| 1029 | * when (a) the {@code Connection} is issuing a DTMF sequence; (b) it has encountered a "wait" |
| 1030 | * character; and (c) it wishes to inform the In-Call app that it is waiting for the end-user |
| 1031 | * to send an {@link #onPostDialContinue(boolean)} signal. |
| 1032 | * |
| 1033 | * @param remaining The DTMF character sequence remaining to be emitted once the |
| 1034 | * {@link #onPostDialContinue(boolean)} is received, including any "wait" characters |
| 1035 | * that remaining sequence may contain. |
Sailesh Nepal | 091768c | 2014-06-30 15:15:23 -0700 | [diff] [blame] | 1036 | */ |
| 1037 | public final void setPostDialWait(String remaining) { |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 1038 | checkImmutable(); |
Santos Cordon | d34e571 | 2014-08-05 18:54:03 +0000 | [diff] [blame] | 1039 | for (Listener l : mListeners) { |
| 1040 | l.onPostDialWait(this, remaining); |
| 1041 | } |
Sailesh Nepal | 091768c | 2014-06-30 15:15:23 -0700 | [diff] [blame] | 1042 | } |
| 1043 | |
| 1044 | /** |
Nancy Chen | 27d1c2d | 2014-12-15 16:12:50 -0800 | [diff] [blame] | 1045 | * Informs listeners that this {@code Connection} has processed a character in the post-dial |
| 1046 | * started state. This is done when (a) the {@code Connection} is issuing a DTMF sequence; |
| 1047 | * (b) it has encountered a "wait" character; and (c) it wishes to signal Telecom to play |
| 1048 | * the corresponding DTMF tone locally. |
| 1049 | * |
| 1050 | * @param nextChar The DTMF character that was just processed by the {@code Connection}. |
| 1051 | * |
| 1052 | * @hide |
| 1053 | */ |
| 1054 | public final void setNextPostDialWaitChar(char nextChar) { |
| 1055 | checkImmutable(); |
| 1056 | for (Listener l : mListeners) { |
| 1057 | l.onPostDialChar(this, nextChar); |
| 1058 | } |
| 1059 | } |
| 1060 | |
| 1061 | /** |
Ihab Awad | f835897 | 2014-05-28 16:46:42 -0700 | [diff] [blame] | 1062 | * Requests that the framework play a ringback tone. This is to be invoked by implementations |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 1063 | * that do not play a ringback tone themselves in the connection's audio stream. |
Ihab Awad | f835897 | 2014-05-28 16:46:42 -0700 | [diff] [blame] | 1064 | * |
| 1065 | * @param ringback Whether the ringback tone is to be played. |
| 1066 | */ |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 1067 | public final void setRingbackRequested(boolean ringback) { |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 1068 | checkImmutable(); |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 1069 | if (mRingbackRequested != ringback) { |
| 1070 | mRingbackRequested = ringback; |
Santos Cordon | d34e571 | 2014-08-05 18:54:03 +0000 | [diff] [blame] | 1071 | for (Listener l : mListeners) { |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 1072 | l.onRingbackRequested(this, ringback); |
Santos Cordon | d34e571 | 2014-08-05 18:54:03 +0000 | [diff] [blame] | 1073 | } |
| 1074 | } |
Ihab Awad | f835897 | 2014-05-28 16:46:42 -0700 | [diff] [blame] | 1075 | } |
| 1076 | |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 1077 | /** @hide */ |
Ihab Awad | de06133 | 2014-12-01 12:19:57 -0800 | [diff] [blame] | 1078 | @SystemApi @Deprecated public final void setCallCapabilities(int connectionCapabilities) { |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 1079 | setConnectionCapabilities(connectionCapabilities); |
| 1080 | } |
| 1081 | |
Ihab Awad | f835897 | 2014-05-28 16:46:42 -0700 | [diff] [blame] | 1082 | /** |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 1083 | * Sets the connection's capabilities as a bit mask of the {@code CAPABILITY_*} constants. |
Sailesh Nepal | 1a7061b | 2014-07-09 21:03:20 -0700 | [diff] [blame] | 1084 | * |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 1085 | * @param connectionCapabilities The new connection capabilities. |
Santos Cordon | b693998 | 2014-06-04 20:20:58 -0700 | [diff] [blame] | 1086 | */ |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 1087 | public final void setConnectionCapabilities(int connectionCapabilities) { |
| 1088 | checkImmutable(); |
| 1089 | if (mConnectionCapabilities != connectionCapabilities) { |
| 1090 | mConnectionCapabilities = connectionCapabilities; |
Santos Cordon | d34e571 | 2014-08-05 18:54:03 +0000 | [diff] [blame] | 1091 | for (Listener l : mListeners) { |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 1092 | l.onConnectionCapabilitiesChanged(this, mConnectionCapabilities); |
Santos Cordon | d34e571 | 2014-08-05 18:54:03 +0000 | [diff] [blame] | 1093 | } |
| 1094 | } |
Santos Cordon | b693998 | 2014-06-04 20:20:58 -0700 | [diff] [blame] | 1095 | } |
| 1096 | |
| 1097 | /** |
Santos Cordon | 7c7bc7f | 2014-07-28 18:15:48 -0700 | [diff] [blame] | 1098 | * Tears down the Connection object. |
Santos Cordon | b693998 | 2014-06-04 20:20:58 -0700 | [diff] [blame] | 1099 | */ |
Evan Charlton | 36a7134 | 2014-07-19 16:31:02 -0700 | [diff] [blame] | 1100 | public final void destroy() { |
Jay Shrauner | 229e382 | 2014-08-15 09:23:07 -0700 | [diff] [blame] | 1101 | for (Listener l : mListeners) { |
| 1102 | l.onDestroyed(this); |
Santos Cordon | d34e571 | 2014-08-05 18:54:03 +0000 | [diff] [blame] | 1103 | } |
Santos Cordon | b693998 | 2014-06-04 20:20:58 -0700 | [diff] [blame] | 1104 | } |
| 1105 | |
| 1106 | /** |
Sailesh Nepal | 33aaae4 | 2014-07-07 22:49:44 -0700 | [diff] [blame] | 1107 | * Requests that the framework use VOIP audio mode for this connection. |
| 1108 | * |
| 1109 | * @param isVoip True if the audio mode is VOIP. |
| 1110 | */ |
| 1111 | public final void setAudioModeIsVoip(boolean isVoip) { |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 1112 | checkImmutable(); |
Santos Cordon | d34e571 | 2014-08-05 18:54:03 +0000 | [diff] [blame] | 1113 | mAudioModeIsVoip = isVoip; |
| 1114 | for (Listener l : mListeners) { |
| 1115 | l.onAudioModeIsVoipChanged(this, isVoip); |
| 1116 | } |
Sailesh Nepal | 33aaae4 | 2014-07-07 22:49:44 -0700 | [diff] [blame] | 1117 | } |
| 1118 | |
| 1119 | /** |
Sailesh Nepal | e7ef59a | 2014-07-08 21:48:22 -0700 | [diff] [blame] | 1120 | * Sets the label and icon status to display in the in-call UI. |
| 1121 | * |
| 1122 | * @param statusHints The status label and icon to set. |
| 1123 | */ |
| 1124 | public final void setStatusHints(StatusHints statusHints) { |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 1125 | checkImmutable(); |
Santos Cordon | d34e571 | 2014-08-05 18:54:03 +0000 | [diff] [blame] | 1126 | mStatusHints = statusHints; |
| 1127 | for (Listener l : mListeners) { |
| 1128 | l.onStatusHintsChanged(this, statusHints); |
| 1129 | } |
Sailesh Nepal | e7ef59a | 2014-07-08 21:48:22 -0700 | [diff] [blame] | 1130 | } |
| 1131 | |
| 1132 | /** |
Santos Cordon | 7c7bc7f | 2014-07-28 18:15:48 -0700 | [diff] [blame] | 1133 | * Sets the connections with which this connection can be conferenced. |
| 1134 | * |
| 1135 | * @param conferenceableConnections The set of connections this connection can conference with. |
| 1136 | */ |
| 1137 | public final void setConferenceableConnections(List<Connection> conferenceableConnections) { |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 1138 | checkImmutable(); |
Santos Cordon | 7c7bc7f | 2014-07-28 18:15:48 -0700 | [diff] [blame] | 1139 | clearConferenceableList(); |
| 1140 | for (Connection c : conferenceableConnections) { |
| 1141 | // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a |
| 1142 | // small amount of items here. |
Tyler Gunn | 6d76ca0 | 2014-11-17 15:49:51 -0800 | [diff] [blame] | 1143 | if (!mConferenceables.contains(c)) { |
Santos Cordon | 7c7bc7f | 2014-07-28 18:15:48 -0700 | [diff] [blame] | 1144 | c.addConnectionListener(mConnectionDeathListener); |
Tyler Gunn | 6d76ca0 | 2014-11-17 15:49:51 -0800 | [diff] [blame] | 1145 | mConferenceables.add(c); |
Santos Cordon | 7c7bc7f | 2014-07-28 18:15:48 -0700 | [diff] [blame] | 1146 | } |
| 1147 | } |
| 1148 | fireOnConferenceableConnectionsChanged(); |
| 1149 | } |
| 1150 | |
| 1151 | /** |
Tyler Gunn | 6d76ca0 | 2014-11-17 15:49:51 -0800 | [diff] [blame] | 1152 | * Similar to {@link #setConferenceableConnections(java.util.List)}, sets a list of connections |
| 1153 | * or conferences with which this connection can be conferenced. |
| 1154 | * |
| 1155 | * @param conferenceables The conferenceables. |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 1156 | */ |
Tyler Gunn | 6d76ca0 | 2014-11-17 15:49:51 -0800 | [diff] [blame] | 1157 | public final void setConferenceables(List<IConferenceable> conferenceables) { |
| 1158 | clearConferenceableList(); |
| 1159 | for (IConferenceable c : conferenceables) { |
| 1160 | // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a |
| 1161 | // small amount of items here. |
| 1162 | if (!mConferenceables.contains(c)) { |
| 1163 | if (c instanceof Connection) { |
| 1164 | Connection connection = (Connection) c; |
| 1165 | connection.addConnectionListener(mConnectionDeathListener); |
| 1166 | } else if (c instanceof Conference) { |
| 1167 | Conference conference = (Conference) c; |
| 1168 | conference.addListener(mConferenceDeathListener); |
| 1169 | } |
| 1170 | mConferenceables.add(c); |
| 1171 | } |
| 1172 | } |
| 1173 | fireOnConferenceableConnectionsChanged(); |
| 1174 | } |
| 1175 | |
| 1176 | /** |
| 1177 | * Returns the connections or conferences with which this connection can be conferenced. |
| 1178 | */ |
| 1179 | public final List<IConferenceable> getConferenceables() { |
| 1180 | return mUnmodifiableConferenceables; |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 1181 | } |
| 1182 | |
Evan Charlton | 8635c57 | 2014-09-24 14:04:51 -0700 | [diff] [blame] | 1183 | /* |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 1184 | * @hide |
| 1185 | */ |
| 1186 | public final void setConnectionService(ConnectionService connectionService) { |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 1187 | checkImmutable(); |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 1188 | if (mConnectionService != null) { |
| 1189 | Log.e(this, new Exception(), "Trying to set ConnectionService on a connection " + |
| 1190 | "which is already associated with another ConnectionService."); |
| 1191 | } else { |
| 1192 | mConnectionService = connectionService; |
| 1193 | } |
| 1194 | } |
| 1195 | |
| 1196 | /** |
| 1197 | * @hide |
| 1198 | */ |
| 1199 | public final void unsetConnectionService(ConnectionService connectionService) { |
| 1200 | if (mConnectionService != connectionService) { |
| 1201 | Log.e(this, new Exception(), "Trying to remove ConnectionService from a Connection " + |
| 1202 | "that does not belong to the ConnectionService."); |
| 1203 | } else { |
| 1204 | mConnectionService = null; |
| 1205 | } |
| 1206 | } |
| 1207 | |
| 1208 | /** |
Santos Cordon | af1b296 | 2014-10-16 19:23:54 -0700 | [diff] [blame] | 1209 | * @hide |
| 1210 | */ |
| 1211 | public final ConnectionService getConnectionService() { |
| 1212 | return mConnectionService; |
| 1213 | } |
| 1214 | |
| 1215 | /** |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 1216 | * Sets the conference that this connection is a part of. This will fail if the connection is |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 1217 | * already part of a conference. {@link #resetConference} to un-set the conference first. |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 1218 | * |
| 1219 | * @param conference The conference. |
| 1220 | * @return {@code true} if the conference was successfully set. |
| 1221 | * @hide |
| 1222 | */ |
| 1223 | public final boolean setConference(Conference conference) { |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 1224 | checkImmutable(); |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 1225 | // We check to see if it is already part of another conference. |
Santos Cordon | 0159ac0 | 2014-08-21 14:28:11 -0700 | [diff] [blame] | 1226 | if (mConference == null) { |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 1227 | mConference = conference; |
Santos Cordon | 0159ac0 | 2014-08-21 14:28:11 -0700 | [diff] [blame] | 1228 | if (mConnectionService != null && mConnectionService.containsConference(conference)) { |
| 1229 | fireConferenceChanged(); |
| 1230 | } |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 1231 | return true; |
| 1232 | } |
| 1233 | return false; |
| 1234 | } |
| 1235 | |
| 1236 | /** |
| 1237 | * Resets the conference that this connection is a part of. |
| 1238 | * @hide |
| 1239 | */ |
| 1240 | public final void resetConference() { |
| 1241 | if (mConference != null) { |
Santos Cordon | 0159ac0 | 2014-08-21 14:28:11 -0700 | [diff] [blame] | 1242 | Log.d(this, "Conference reset"); |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 1243 | mConference = null; |
| 1244 | fireConferenceChanged(); |
| 1245 | } |
| 1246 | } |
| 1247 | |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 1248 | /** |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 1249 | * Notifies this Connection that the {@link #getAudioState()} property has a new value. |
Sailesh Nepal | 400cc48 | 2014-06-26 12:04:00 -0700 | [diff] [blame] | 1250 | * |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 1251 | * @param state The new connection audio state. |
Sailesh Nepal | 400cc48 | 2014-06-26 12:04:00 -0700 | [diff] [blame] | 1252 | */ |
Nancy Chen | 354b2bd | 2014-09-08 18:27:26 -0700 | [diff] [blame] | 1253 | public void onAudioStateChanged(AudioState state) {} |
Sailesh Nepal | 400cc48 | 2014-06-26 12:04:00 -0700 | [diff] [blame] | 1254 | |
| 1255 | /** |
Evan Charlton | bf11f98 | 2014-07-20 22:06:28 -0700 | [diff] [blame] | 1256 | * Notifies this Connection of an internal state change. This method is called after the |
| 1257 | * state is changed. |
Ihab Awad | f835897 | 2014-05-28 16:46:42 -0700 | [diff] [blame] | 1258 | * |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 1259 | * @param state The new state, one of the {@code STATE_*} constants. |
Ihab Awad | f835897 | 2014-05-28 16:46:42 -0700 | [diff] [blame] | 1260 | */ |
Nancy Chen | 354b2bd | 2014-09-08 18:27:26 -0700 | [diff] [blame] | 1261 | public void onStateChanged(int state) {} |
Ihab Awad | f835897 | 2014-05-28 16:46:42 -0700 | [diff] [blame] | 1262 | |
| 1263 | /** |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 1264 | * Notifies this Connection of a request to play a DTMF tone. |
| 1265 | * |
| 1266 | * @param c A DTMF character. |
| 1267 | */ |
Santos Cordon | f295110 | 2014-07-20 19:06:29 -0700 | [diff] [blame] | 1268 | public void onPlayDtmfTone(char c) {} |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 1269 | |
| 1270 | /** |
| 1271 | * Notifies this Connection of a request to stop any currently playing DTMF tones. |
| 1272 | */ |
Santos Cordon | f295110 | 2014-07-20 19:06:29 -0700 | [diff] [blame] | 1273 | public void onStopDtmfTone() {} |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 1274 | |
| 1275 | /** |
| 1276 | * Notifies this Connection of a request to disconnect. |
| 1277 | */ |
Santos Cordon | f295110 | 2014-07-20 19:06:29 -0700 | [diff] [blame] | 1278 | public void onDisconnect() {} |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 1279 | |
| 1280 | /** |
Tyler Gunn | 3b4b1dc | 2014-11-04 14:53:37 -0800 | [diff] [blame] | 1281 | * Notifies this Connection of a request to disconnect a participant of the conference managed |
| 1282 | * by the connection. |
| 1283 | * |
| 1284 | * @param endpoint the {@link Uri} of the participant to disconnect. |
| 1285 | * @hide |
| 1286 | */ |
| 1287 | public void onDisconnectConferenceParticipant(Uri endpoint) {} |
| 1288 | |
| 1289 | /** |
Santos Cordon | 7c7bc7f | 2014-07-28 18:15:48 -0700 | [diff] [blame] | 1290 | * Notifies this Connection of a request to separate from its parent conference. |
Santos Cordon | b693998 | 2014-06-04 20:20:58 -0700 | [diff] [blame] | 1291 | */ |
Santos Cordon | f295110 | 2014-07-20 19:06:29 -0700 | [diff] [blame] | 1292 | public void onSeparate() {} |
Santos Cordon | b693998 | 2014-06-04 20:20:58 -0700 | [diff] [blame] | 1293 | |
| 1294 | /** |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 1295 | * Notifies this Connection of a request to abort. |
| 1296 | */ |
Santos Cordon | f295110 | 2014-07-20 19:06:29 -0700 | [diff] [blame] | 1297 | public void onAbort() {} |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 1298 | |
| 1299 | /** |
| 1300 | * Notifies this Connection of a request to hold. |
| 1301 | */ |
Santos Cordon | f295110 | 2014-07-20 19:06:29 -0700 | [diff] [blame] | 1302 | public void onHold() {} |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 1303 | |
| 1304 | /** |
| 1305 | * Notifies this Connection of a request to exit a hold state. |
| 1306 | */ |
Santos Cordon | f295110 | 2014-07-20 19:06:29 -0700 | [diff] [blame] | 1307 | public void onUnhold() {} |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 1308 | |
| 1309 | /** |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 1310 | * Notifies this Connection, which is in {@link #STATE_RINGING}, of |
Santos Cordon | d34e571 | 2014-08-05 18:54:03 +0000 | [diff] [blame] | 1311 | * a request to accept. |
Andrew Lee | 8da4c3c | 2014-07-16 10:11:42 -0700 | [diff] [blame] | 1312 | * |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 1313 | * @param videoState The video state in which to answer the connection. |
Tyler Gunn | be74de0 | 2014-08-29 14:51:48 -0700 | [diff] [blame] | 1314 | * @hide |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 1315 | */ |
Santos Cordon | f295110 | 2014-07-20 19:06:29 -0700 | [diff] [blame] | 1316 | public void onAnswer(int videoState) {} |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 1317 | |
| 1318 | /** |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 1319 | * Notifies this Connection, which is in {@link #STATE_RINGING}, of |
Tyler Gunn | be74de0 | 2014-08-29 14:51:48 -0700 | [diff] [blame] | 1320 | * a request to accept. |
| 1321 | */ |
| 1322 | public void onAnswer() { |
| 1323 | onAnswer(VideoProfile.VideoState.AUDIO_ONLY); |
| 1324 | } |
| 1325 | |
| 1326 | /** |
| 1327 | * Notifies this Connection, which is in {@link #STATE_RINGING}, of |
Santos Cordon | d34e571 | 2014-08-05 18:54:03 +0000 | [diff] [blame] | 1328 | * a request to reject. |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 1329 | */ |
Santos Cordon | f295110 | 2014-07-20 19:06:29 -0700 | [diff] [blame] | 1330 | public void onReject() {} |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 1331 | |
Evan Charlton | 6dea4ac | 2014-06-03 14:07:13 -0700 | [diff] [blame] | 1332 | /** |
| 1333 | * Notifies this Connection whether the user wishes to proceed with the post-dial DTMF codes. |
| 1334 | */ |
Santos Cordon | f295110 | 2014-07-20 19:06:29 -0700 | [diff] [blame] | 1335 | public void onPostDialContinue(boolean proceed) {} |
Evan Charlton | 6dea4ac | 2014-06-03 14:07:13 -0700 | [diff] [blame] | 1336 | |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 1337 | static String toLogSafePhoneNumber(String number) { |
| 1338 | // For unknown number, log empty string. |
| 1339 | if (number == null) { |
| 1340 | return ""; |
| 1341 | } |
| 1342 | |
| 1343 | if (PII_DEBUG) { |
| 1344 | // When PII_DEBUG is true we emit PII. |
| 1345 | return number; |
| 1346 | } |
| 1347 | |
| 1348 | // Do exactly same thing as Uri#toSafeString() does, which will enable us to compare |
| 1349 | // sanitized phone numbers. |
| 1350 | StringBuilder builder = new StringBuilder(); |
| 1351 | for (int i = 0; i < number.length(); i++) { |
| 1352 | char c = number.charAt(i); |
| 1353 | if (c == '-' || c == '@' || c == '.') { |
| 1354 | builder.append(c); |
| 1355 | } else { |
| 1356 | builder.append('x'); |
| 1357 | } |
| 1358 | } |
| 1359 | return builder.toString(); |
| 1360 | } |
| 1361 | |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 1362 | private void setState(int state) { |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 1363 | checkImmutable(); |
Ihab Awad | 6107bab | 2014-08-18 09:23:25 -0700 | [diff] [blame] | 1364 | if (mState == STATE_DISCONNECTED && mState != state) { |
| 1365 | Log.d(this, "Connection already DISCONNECTED; cannot transition out of this state."); |
Evan Charlton | bf11f98 | 2014-07-20 22:06:28 -0700 | [diff] [blame] | 1366 | return; |
Sailesh Nepal | 400cc48 | 2014-06-26 12:04:00 -0700 | [diff] [blame] | 1367 | } |
Evan Charlton | bf11f98 | 2014-07-20 22:06:28 -0700 | [diff] [blame] | 1368 | if (mState != state) { |
| 1369 | Log.d(this, "setState: %s", stateToString(state)); |
| 1370 | mState = state; |
Nancy Chen | 354b2bd | 2014-09-08 18:27:26 -0700 | [diff] [blame] | 1371 | onStateChanged(state); |
Evan Charlton | bf11f98 | 2014-07-20 22:06:28 -0700 | [diff] [blame] | 1372 | for (Listener l : mListeners) { |
| 1373 | l.onStateChanged(this, state); |
| 1374 | } |
Evan Charlton | bf11f98 | 2014-07-20 22:06:28 -0700 | [diff] [blame] | 1375 | } |
| 1376 | } |
| 1377 | |
Sailesh Nepal | cf7020b | 2014-08-20 10:07:19 -0700 | [diff] [blame] | 1378 | private static class FailureSignalingConnection extends Connection { |
Ihab Awad | 90e34e3 | 2014-12-01 16:23:17 -0800 | [diff] [blame] | 1379 | private boolean mImmutable = false; |
Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame] | 1380 | public FailureSignalingConnection(DisconnectCause disconnectCause) { |
| 1381 | setDisconnected(disconnectCause); |
Ihab Awad | 90e34e3 | 2014-12-01 16:23:17 -0800 | [diff] [blame] | 1382 | mImmutable = true; |
Ihab Awad | 6107bab | 2014-08-18 09:23:25 -0700 | [diff] [blame] | 1383 | } |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 1384 | |
| 1385 | public void checkImmutable() { |
Ihab Awad | 90e34e3 | 2014-12-01 16:23:17 -0800 | [diff] [blame] | 1386 | if (mImmutable) { |
| 1387 | throw new UnsupportedOperationException("Connection is immutable"); |
| 1388 | } |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 1389 | } |
Ihab Awad | 6107bab | 2014-08-18 09:23:25 -0700 | [diff] [blame] | 1390 | } |
| 1391 | |
Evan Charlton | bf11f98 | 2014-07-20 22:06:28 -0700 | [diff] [blame] | 1392 | /** |
Ihab Awad | 6107bab | 2014-08-18 09:23:25 -0700 | [diff] [blame] | 1393 | * Return a {@code Connection} which represents a failed connection attempt. The returned |
Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame] | 1394 | * {@code Connection} will have a {@link android.telecom.DisconnectCause} and as specified, |
| 1395 | * and a {@link #getState()} of {@link #STATE_DISCONNECTED}. |
Ihab Awad | 6107bab | 2014-08-18 09:23:25 -0700 | [diff] [blame] | 1396 | * <p> |
| 1397 | * The returned {@code Connection} can be assumed to {@link #destroy()} itself when appropriate, |
| 1398 | * so users of this method need not maintain a reference to its return value to destroy it. |
Evan Charlton | bf11f98 | 2014-07-20 22:06:28 -0700 | [diff] [blame] | 1399 | * |
Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame] | 1400 | * @param disconnectCause The disconnect cause, ({@see android.telecomm.DisconnectCause}). |
Ihab Awad | 6107bab | 2014-08-18 09:23:25 -0700 | [diff] [blame] | 1401 | * @return A {@code Connection} which indicates failure. |
Evan Charlton | bf11f98 | 2014-07-20 22:06:28 -0700 | [diff] [blame] | 1402 | */ |
Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame] | 1403 | public static Connection createFailedConnection(DisconnectCause disconnectCause) { |
| 1404 | return new FailureSignalingConnection(disconnectCause); |
Evan Charlton | bf11f98 | 2014-07-20 22:06:28 -0700 | [diff] [blame] | 1405 | } |
| 1406 | |
Evan Charlton | bf11f98 | 2014-07-20 22:06:28 -0700 | [diff] [blame] | 1407 | /** |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 1408 | * Override to throw an {@link UnsupportedOperationException} if this {@code Connection} is |
| 1409 | * not intended to be mutated, e.g., if it is a marker for failure. Only for framework use; |
| 1410 | * this should never be un-@hide-den. |
| 1411 | * |
| 1412 | * @hide |
| 1413 | */ |
| 1414 | public void checkImmutable() {} |
| 1415 | |
| 1416 | /** |
Ihab Awad | 6107bab | 2014-08-18 09:23:25 -0700 | [diff] [blame] | 1417 | * Return a {@code Connection} which represents a canceled connection attempt. The returned |
| 1418 | * {@code Connection} will have state {@link #STATE_DISCONNECTED}, and cannot be moved out of |
| 1419 | * that state. This connection should not be used for anything, and no other |
| 1420 | * {@code Connection}s should be attempted. |
| 1421 | * <p> |
Ihab Awad | 6107bab | 2014-08-18 09:23:25 -0700 | [diff] [blame] | 1422 | * so users of this method need not maintain a reference to its return value to destroy it. |
Evan Charlton | bf11f98 | 2014-07-20 22:06:28 -0700 | [diff] [blame] | 1423 | * |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 1424 | * @return A {@code Connection} which indicates that the underlying connection should |
| 1425 | * be canceled. |
Evan Charlton | bf11f98 | 2014-07-20 22:06:28 -0700 | [diff] [blame] | 1426 | */ |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 1427 | public static Connection createCanceledConnection() { |
Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame] | 1428 | return new FailureSignalingConnection(new DisconnectCause(DisconnectCause.CANCELED)); |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 1429 | } |
Santos Cordon | 7c7bc7f | 2014-07-28 18:15:48 -0700 | [diff] [blame] | 1430 | |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 1431 | private final void fireOnConferenceableConnectionsChanged() { |
Santos Cordon | 7c7bc7f | 2014-07-28 18:15:48 -0700 | [diff] [blame] | 1432 | for (Listener l : mListeners) { |
Tyler Gunn | 6d76ca0 | 2014-11-17 15:49:51 -0800 | [diff] [blame] | 1433 | l.onConferenceablesChanged(this, getConferenceables()); |
Santos Cordon | 7c7bc7f | 2014-07-28 18:15:48 -0700 | [diff] [blame] | 1434 | } |
| 1435 | } |
| 1436 | |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 1437 | private final void fireConferenceChanged() { |
| 1438 | for (Listener l : mListeners) { |
| 1439 | l.onConferenceChanged(this, mConference); |
| 1440 | } |
| 1441 | } |
| 1442 | |
Santos Cordon | 7c7bc7f | 2014-07-28 18:15:48 -0700 | [diff] [blame] | 1443 | private final void clearConferenceableList() { |
Tyler Gunn | 6d76ca0 | 2014-11-17 15:49:51 -0800 | [diff] [blame] | 1444 | for (IConferenceable c : mConferenceables) { |
| 1445 | if (c instanceof Connection) { |
| 1446 | Connection connection = (Connection) c; |
| 1447 | connection.removeConnectionListener(mConnectionDeathListener); |
| 1448 | } else if (c instanceof Conference) { |
| 1449 | Conference conference = (Conference) c; |
| 1450 | conference.removeListener(mConferenceDeathListener); |
| 1451 | } |
Santos Cordon | 7c7bc7f | 2014-07-28 18:15:48 -0700 | [diff] [blame] | 1452 | } |
Tyler Gunn | 6d76ca0 | 2014-11-17 15:49:51 -0800 | [diff] [blame] | 1453 | mConferenceables.clear(); |
Santos Cordon | 7c7bc7f | 2014-07-28 18:15:48 -0700 | [diff] [blame] | 1454 | } |
Tyler Gunn | 3bffcf7 | 2014-10-28 13:51:27 -0700 | [diff] [blame] | 1455 | |
| 1456 | /** |
Tyler Gunn | ab4650c | 2014-11-06 20:06:23 -0800 | [diff] [blame] | 1457 | * Notifies listeners of a change to conference participant(s). |
Tyler Gunn | 3bffcf7 | 2014-10-28 13:51:27 -0700 | [diff] [blame] | 1458 | * |
Tyler Gunn | ab4650c | 2014-11-06 20:06:23 -0800 | [diff] [blame] | 1459 | * @param conferenceParticipants The participants. |
Tyler Gunn | 3bffcf7 | 2014-10-28 13:51:27 -0700 | [diff] [blame] | 1460 | * @hide |
| 1461 | */ |
Tyler Gunn | ab4650c | 2014-11-06 20:06:23 -0800 | [diff] [blame] | 1462 | protected final void updateConferenceParticipants( |
| 1463 | List<ConferenceParticipant> conferenceParticipants) { |
Tyler Gunn | 3bffcf7 | 2014-10-28 13:51:27 -0700 | [diff] [blame] | 1464 | for (Listener l : mListeners) { |
Tyler Gunn | ab4650c | 2014-11-06 20:06:23 -0800 | [diff] [blame] | 1465 | l.onConferenceParticipantsChanged(this, conferenceParticipants); |
Tyler Gunn | 3bffcf7 | 2014-10-28 13:51:27 -0700 | [diff] [blame] | 1466 | } |
| 1467 | } |
Tyler Gunn | 8a2b119 | 2015-01-29 11:47:24 -0800 | [diff] [blame] | 1468 | |
| 1469 | /** |
| 1470 | * Notifies listeners that a conference call has been started. |
| 1471 | */ |
| 1472 | protected void notifyConferenceStarted() { |
| 1473 | for (Listener l : mListeners) { |
| 1474 | l.onConferenceStarted(); |
| 1475 | } |
| 1476 | } |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 1477 | } |