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