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