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