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