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