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