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