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