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