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