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