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