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