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