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