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