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