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