Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2013 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 | |
| 17 | package com.android.ims; |
| 18 | |
Uma Maheswari Ramalingam | ca45f58 | 2014-05-19 12:32:20 -0700 | [diff] [blame] | 19 | import com.android.internal.R; |
| 20 | |
Tyler Gunn | 1c46760 | 2014-11-04 14:51:52 -0800 | [diff] [blame] | 21 | import java.util.ArrayList; |
Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 22 | import java.util.Iterator; |
Tyler Gunn | 1c46760 | 2014-11-04 14:51:52 -0800 | [diff] [blame] | 23 | import java.util.List; |
Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 24 | import java.util.Map.Entry; |
| 25 | import java.util.Set; |
| 26 | |
| 27 | import android.content.Context; |
Tyler Gunn | 5965614 | 2014-10-28 13:52:11 -0700 | [diff] [blame] | 28 | import android.net.Uri; |
Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 29 | import android.os.Bundle; |
| 30 | import android.os.Message; |
Hall Liu | bd3f377 | 2017-03-22 15:38:23 -0700 | [diff] [blame] | 31 | import android.os.Parcel; |
Tyler Gunn | 5965614 | 2014-10-28 13:52:11 -0700 | [diff] [blame] | 32 | import android.telecom.ConferenceParticipant; |
Rekha Kumar | 5aec2e9 | 2015-03-24 11:00:34 -0700 | [diff] [blame] | 33 | import android.telecom.Connection; |
Shunta Sakai | fb688ca | 2016-12-06 20:32:07 +0900 | [diff] [blame] | 34 | import android.telephony.Rlog; |
Uma Maheswari Ramalingam | 95be7c6 | 2015-05-06 23:08:17 -0700 | [diff] [blame] | 35 | import java.util.Objects; |
Jack Yu | b42ff55 | 2016-06-22 13:20:52 -0700 | [diff] [blame] | 36 | import java.util.concurrent.atomic.AtomicInteger; |
Tyler Gunn | 1ac2485 | 2016-06-22 10:04:23 -0700 | [diff] [blame] | 37 | |
| 38 | import android.telephony.ServiceState; |
Brad Ebinger | 190ed93 | 2018-01-23 13:41:32 -0800 | [diff] [blame] | 39 | import android.telephony.ims.ImsCallProfile; |
| 40 | import android.telephony.ims.ImsConferenceState; |
| 41 | import android.telephony.ims.ImsReasonInfo; |
| 42 | import android.telephony.ims.ImsStreamMediaProfile; |
| 43 | import android.telephony.ims.ImsSuppServiceNotification; |
Tyler Gunn | 9bd5ca5 | 2014-12-02 09:21:01 -0800 | [diff] [blame] | 44 | import android.util.Log; |
Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 45 | |
Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 46 | import com.android.ims.internal.ICall; |
Brad Ebinger | 190ed93 | 2018-01-23 13:41:32 -0800 | [diff] [blame] | 47 | import android.telephony.ims.ImsCallSession; |
Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 48 | import com.android.ims.internal.ImsStreamMediaSession; |
Tyler Gunn | 938116f | 2014-10-27 09:15:23 -0700 | [diff] [blame] | 49 | import com.android.internal.annotations.VisibleForTesting; |
Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 50 | |
| 51 | /** |
| 52 | * Handles an IMS voice / video call over LTE. You can instantiate this class with |
| 53 | * {@link ImsManager}. |
| 54 | * |
| 55 | * @hide |
| 56 | */ |
| 57 | public class ImsCall implements ICall { |
Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 58 | // Mode of USSD message |
| 59 | public static final int USSD_MODE_NOTIFY = 0; |
| 60 | public static final int USSD_MODE_REQUEST = 1; |
| 61 | |
| 62 | private static final String TAG = "ImsCall"; |
Anthony Lee | 6804851 | 2015-03-18 15:04:18 -0700 | [diff] [blame] | 63 | |
| 64 | // This flag is meant to be used as a debugging tool to quickly see all logs |
| 65 | // regardless of the actual log level set on this component. |
Tyler Gunn | 6cb99be | 2014-12-02 14:16:30 -0800 | [diff] [blame] | 66 | private static final boolean FORCE_DEBUG = false; /* STOPSHIP if true */ |
Anthony Lee | 6804851 | 2015-03-18 15:04:18 -0700 | [diff] [blame] | 67 | |
| 68 | // We will log messages guarded by these flags at the info level. If logging is required |
| 69 | // to occur at (and only at) a particular log level, please use the logd, logv and loge |
| 70 | // functions as those will not be affected by the value of FORCE_DEBUG at all. |
| 71 | // Otherwise, anything guarded by these flags will be logged at the info level since that |
| 72 | // level allows those statements ot be logged by default which supports the workflow of |
| 73 | // setting FORCE_DEBUG and knowing these logs will show up regardless of the actual log |
| 74 | // level of this component. |
| 75 | private static final boolean DBG = FORCE_DEBUG || Log.isLoggable(TAG, Log.DEBUG); |
| 76 | private static final boolean VDBG = FORCE_DEBUG || Log.isLoggable(TAG, Log.VERBOSE); |
| 77 | // This is a special flag that is used only to highlight specific log around bringing |
| 78 | // up and tearing down conference calls. At times, these errors are transient and hard to |
| 79 | // reproduce so we need to capture this information the first time. |
| 80 | // TODO: Set this flag to FORCE_DEBUG once the new conference call logic gets more mileage |
| 81 | // across different IMS implementations. |
| 82 | private static final boolean CONF_DBG = true; |
Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 83 | |
Uma Maheswari Ramalingam | a1ed7b0 | 2015-05-20 14:26:42 -0700 | [diff] [blame] | 84 | private List<ConferenceParticipant> mConferenceParticipants; |
Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 85 | /** |
| 86 | * Listener for events relating to an IMS call, such as when a call is being |
Anthony Lee | c479f66 | 2015-02-11 17:04:35 -0800 | [diff] [blame] | 87 | * received ("on ringing") or a call is outgoing ("on calling"). |
Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 88 | * <p>Many of these events are also received by {@link ImsCallSession.Listener}.</p> |
| 89 | */ |
| 90 | public static class Listener { |
| 91 | /** |
| 92 | * Called when a request is sent out to initiate a new call |
| 93 | * and 1xx response is received from the network. |
| 94 | * The default implementation calls {@link #onCallStateChanged}. |
| 95 | * |
| 96 | * @param call the call object that carries out the IMS call |
| 97 | */ |
| 98 | public void onCallProgressing(ImsCall call) { |
| 99 | onCallStateChanged(call); |
| 100 | } |
| 101 | |
| 102 | /** |
| 103 | * Called when the call is established. |
| 104 | * The default implementation calls {@link #onCallStateChanged}. |
| 105 | * |
| 106 | * @param call the call object that carries out the IMS call |
| 107 | */ |
| 108 | public void onCallStarted(ImsCall call) { |
| 109 | onCallStateChanged(call); |
| 110 | } |
| 111 | |
| 112 | /** |
| 113 | * Called when the call setup is failed. |
| 114 | * The default implementation calls {@link #onCallError}. |
| 115 | * |
| 116 | * @param call the call object that carries out the IMS call |
| 117 | * @param reasonInfo detailed reason of the call setup failure |
| 118 | */ |
| 119 | public void onCallStartFailed(ImsCall call, ImsReasonInfo reasonInfo) { |
| 120 | onCallError(call, reasonInfo); |
| 121 | } |
| 122 | |
| 123 | /** |
| 124 | * Called when the call is terminated. |
| 125 | * The default implementation calls {@link #onCallStateChanged}. |
| 126 | * |
| 127 | * @param call the call object that carries out the IMS call |
| 128 | * @param reasonInfo detailed reason of the call termination |
| 129 | */ |
| 130 | public void onCallTerminated(ImsCall call, ImsReasonInfo reasonInfo) { |
| 131 | // Store the call termination reason |
| 132 | |
| 133 | onCallStateChanged(call); |
| 134 | } |
| 135 | |
| 136 | /** |
| 137 | * Called when the call is in hold. |
| 138 | * The default implementation calls {@link #onCallStateChanged}. |
| 139 | * |
| 140 | * @param call the call object that carries out the IMS call |
| 141 | */ |
| 142 | public void onCallHeld(ImsCall call) { |
| 143 | onCallStateChanged(call); |
| 144 | } |
| 145 | |
| 146 | /** |
| 147 | * Called when the call hold is failed. |
| 148 | * The default implementation calls {@link #onCallError}. |
| 149 | * |
| 150 | * @param call the call object that carries out the IMS call |
| 151 | * @param reasonInfo detailed reason of the call hold failure |
| 152 | */ |
| 153 | public void onCallHoldFailed(ImsCall call, ImsReasonInfo reasonInfo) { |
| 154 | onCallError(call, reasonInfo); |
| 155 | } |
| 156 | |
| 157 | /** |
| 158 | * Called when the call hold is received from the remote user. |
| 159 | * The default implementation calls {@link #onCallStateChanged}. |
| 160 | * |
| 161 | * @param call the call object that carries out the IMS call |
| 162 | */ |
| 163 | public void onCallHoldReceived(ImsCall call) { |
| 164 | onCallStateChanged(call); |
| 165 | } |
| 166 | |
| 167 | /** |
| 168 | * Called when the call is in call. |
| 169 | * The default implementation calls {@link #onCallStateChanged}. |
| 170 | * |
| 171 | * @param call the call object that carries out the IMS call |
| 172 | */ |
| 173 | public void onCallResumed(ImsCall call) { |
| 174 | onCallStateChanged(call); |
| 175 | } |
| 176 | |
| 177 | /** |
| 178 | * Called when the call resume is failed. |
| 179 | * The default implementation calls {@link #onCallError}. |
| 180 | * |
| 181 | * @param call the call object that carries out the IMS call |
| 182 | * @param reasonInfo detailed reason of the call resume failure |
| 183 | */ |
| 184 | public void onCallResumeFailed(ImsCall call, ImsReasonInfo reasonInfo) { |
| 185 | onCallError(call, reasonInfo); |
| 186 | } |
| 187 | |
| 188 | /** |
| 189 | * Called when the call resume is received from the remote user. |
| 190 | * The default implementation calls {@link #onCallStateChanged}. |
| 191 | * |
| 192 | * @param call the call object that carries out the IMS call |
| 193 | */ |
| 194 | public void onCallResumeReceived(ImsCall call) { |
| 195 | onCallStateChanged(call); |
| 196 | } |
| 197 | |
| 198 | /** |
| 199 | * Called when the call is in call. |
| 200 | * The default implementation calls {@link #onCallStateChanged}. |
| 201 | * |
Uma Maheswari Ramalingam | 95be7c6 | 2015-05-06 23:08:17 -0700 | [diff] [blame] | 202 | * @param call the call object that carries out the active IMS call |
| 203 | * @param peerCall the call object that carries out the held IMS call |
Tyler Gunn | 047d810 | 2015-01-30 15:21:11 -0800 | [diff] [blame] | 204 | * @param swapCalls {@code true} if the foreground and background calls should be swapped |
| 205 | * now that the merge has completed. |
Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 206 | */ |
Uma Maheswari Ramalingam | 95be7c6 | 2015-05-06 23:08:17 -0700 | [diff] [blame] | 207 | public void onCallMerged(ImsCall call, ImsCall peerCall, boolean swapCalls) { |
Anthony Lee | 7138269 | 2014-10-30 10:50:10 -0700 | [diff] [blame] | 208 | onCallStateChanged(call); |
Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 209 | } |
| 210 | |
| 211 | /** |
| 212 | * Called when the call merge is failed. |
| 213 | * The default implementation calls {@link #onCallError}. |
| 214 | * |
| 215 | * @param call the call object that carries out the IMS call |
| 216 | * @param reasonInfo detailed reason of the call merge failure |
| 217 | */ |
| 218 | public void onCallMergeFailed(ImsCall call, ImsReasonInfo reasonInfo) { |
| 219 | onCallError(call, reasonInfo); |
| 220 | } |
| 221 | |
| 222 | /** |
| 223 | * Called when the call is updated (except for hold/unhold). |
| 224 | * The default implementation calls {@link #onCallStateChanged}. |
| 225 | * |
| 226 | * @param call the call object that carries out the IMS call |
| 227 | */ |
| 228 | public void onCallUpdated(ImsCall call) { |
| 229 | onCallStateChanged(call); |
| 230 | } |
| 231 | |
| 232 | /** |
| 233 | * Called when the call update is failed. |
| 234 | * The default implementation calls {@link #onCallError}. |
| 235 | * |
| 236 | * @param call the call object that carries out the IMS call |
| 237 | * @param reasonInfo detailed reason of the call update failure |
| 238 | */ |
| 239 | public void onCallUpdateFailed(ImsCall call, ImsReasonInfo reasonInfo) { |
| 240 | onCallError(call, reasonInfo); |
| 241 | } |
| 242 | |
| 243 | /** |
| 244 | * Called when the call update is received from the remote user. |
| 245 | * |
| 246 | * @param call the call object that carries out the IMS call |
| 247 | */ |
| 248 | public void onCallUpdateReceived(ImsCall call) { |
| 249 | // no-op |
| 250 | } |
| 251 | |
| 252 | /** |
| 253 | * Called when the call is extended to the conference call. |
| 254 | * The default implementation calls {@link #onCallStateChanged}. |
| 255 | * |
| 256 | * @param call the call object that carries out the IMS call |
| 257 | * @param newCall the call object that is extended to the conference from the active call |
| 258 | */ |
| 259 | public void onCallConferenceExtended(ImsCall call, ImsCall newCall) { |
Anthony Lee | 7138269 | 2014-10-30 10:50:10 -0700 | [diff] [blame] | 260 | onCallStateChanged(call); |
Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 261 | } |
| 262 | |
| 263 | /** |
| 264 | * Called when the conference extension is failed. |
| 265 | * The default implementation calls {@link #onCallError}. |
| 266 | * |
| 267 | * @param call the call object that carries out the IMS call |
| 268 | * @param reasonInfo detailed reason of the conference extension failure |
| 269 | */ |
| 270 | public void onCallConferenceExtendFailed(ImsCall call, |
| 271 | ImsReasonInfo reasonInfo) { |
| 272 | onCallError(call, reasonInfo); |
| 273 | } |
| 274 | |
| 275 | /** |
| 276 | * Called when the conference extension is received from the remote user. |
| 277 | * |
| 278 | * @param call the call object that carries out the IMS call |
| 279 | * @param newCall the call object that is extended to the conference from the active call |
| 280 | */ |
| 281 | public void onCallConferenceExtendReceived(ImsCall call, ImsCall newCall) { |
Anthony Lee | 7138269 | 2014-10-30 10:50:10 -0700 | [diff] [blame] | 282 | onCallStateChanged(call); |
Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 283 | } |
| 284 | |
| 285 | /** |
| 286 | * Called when the invitation request of the participants is delivered to |
| 287 | * the conference server. |
| 288 | * |
| 289 | * @param call the call object that carries out the IMS call |
| 290 | */ |
| 291 | public void onCallInviteParticipantsRequestDelivered(ImsCall call) { |
| 292 | // no-op |
| 293 | } |
| 294 | |
| 295 | /** |
| 296 | * Called when the invitation request of the participants is failed. |
| 297 | * |
| 298 | * @param call the call object that carries out the IMS call |
| 299 | * @param reasonInfo detailed reason of the conference invitation failure |
| 300 | */ |
| 301 | public void onCallInviteParticipantsRequestFailed(ImsCall call, |
| 302 | ImsReasonInfo reasonInfo) { |
| 303 | // no-op |
| 304 | } |
| 305 | |
| 306 | /** |
| 307 | * Called when the removal request of the participants is delivered to |
| 308 | * the conference server. |
| 309 | * |
| 310 | * @param call the call object that carries out the IMS call |
| 311 | */ |
| 312 | public void onCallRemoveParticipantsRequestDelivered(ImsCall call) { |
| 313 | // no-op |
| 314 | } |
| 315 | |
| 316 | /** |
| 317 | * Called when the removal request of the participants is failed. |
| 318 | * |
| 319 | * @param call the call object that carries out the IMS call |
| 320 | * @param reasonInfo detailed reason of the conference removal failure |
| 321 | */ |
| 322 | public void onCallRemoveParticipantsRequestFailed(ImsCall call, |
| 323 | ImsReasonInfo reasonInfo) { |
| 324 | // no-op |
| 325 | } |
| 326 | |
| 327 | /** |
| 328 | * Called when the conference state is updated. |
| 329 | * |
| 330 | * @param call the call object that carries out the IMS call |
| 331 | * @param state state of the participant who is participated in the conference call |
| 332 | */ |
| 333 | public void onCallConferenceStateUpdated(ImsCall call, ImsConferenceState state) { |
| 334 | // no-op |
| 335 | } |
| 336 | |
| 337 | /** |
Tyler Gunn | 1c46760 | 2014-11-04 14:51:52 -0800 | [diff] [blame] | 338 | * Called when the state of IMS conference participant(s) has changed. |
Tyler Gunn | 5965614 | 2014-10-28 13:52:11 -0700 | [diff] [blame] | 339 | * |
| 340 | * @param call the call object that carries out the IMS call. |
Tyler Gunn | 1c46760 | 2014-11-04 14:51:52 -0800 | [diff] [blame] | 341 | * @param participants the participant(s) and their new state information. |
Tyler Gunn | 5965614 | 2014-10-28 13:52:11 -0700 | [diff] [blame] | 342 | */ |
Tyler Gunn | 1c46760 | 2014-11-04 14:51:52 -0800 | [diff] [blame] | 343 | public void onConferenceParticipantsStateChanged(ImsCall call, |
| 344 | List<ConferenceParticipant> participants) { |
Tyler Gunn | 5965614 | 2014-10-28 13:52:11 -0700 | [diff] [blame] | 345 | // no-op |
| 346 | } |
| 347 | |
| 348 | /** |
Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 349 | * Called when the USSD message is received from the network. |
| 350 | * |
| 351 | * @param mode mode of the USSD message (REQUEST / NOTIFY) |
| 352 | * @param ussdMessage USSD message |
| 353 | */ |
| 354 | public void onCallUssdMessageReceived(ImsCall call, |
| 355 | int mode, String ussdMessage) { |
| 356 | // no-op |
| 357 | } |
| 358 | |
| 359 | /** |
| 360 | * Called when an error occurs. The default implementation is no op. |
| 361 | * overridden. The default implementation is no op. Error events are |
| 362 | * not re-directed to this callback and are handled in {@link #onCallError}. |
| 363 | * |
| 364 | * @param call the call object that carries out the IMS call |
| 365 | * @param reasonInfo detailed reason of this error |
| 366 | * @see ImsReasonInfo |
| 367 | */ |
| 368 | public void onCallError(ImsCall call, ImsReasonInfo reasonInfo) { |
| 369 | // no-op |
| 370 | } |
| 371 | |
| 372 | /** |
| 373 | * Called when an event occurs and the corresponding callback is not |
| 374 | * overridden. The default implementation is no op. Error events are |
| 375 | * not re-directed to this callback and are handled in {@link #onCallError}. |
| 376 | * |
| 377 | * @param call the call object that carries out the IMS call |
| 378 | */ |
| 379 | public void onCallStateChanged(ImsCall call) { |
| 380 | // no-op |
| 381 | } |
| 382 | |
| 383 | /** |
Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 384 | * Called when the call moves the hold state to the conversation state. |
| 385 | * For example, when merging the active & hold call, the state of all the hold call |
| 386 | * will be changed from hold state to conversation state. |
| 387 | * This callback method can be invoked even though the application does not trigger |
| 388 | * any operations. |
| 389 | * |
| 390 | * @param call the call object that carries out the IMS call |
| 391 | * @param state the detailed state of call state changes; |
| 392 | * Refer to CALL_STATE_* in {@link ImsCall} |
| 393 | */ |
| 394 | public void onCallStateChanged(ImsCall call, int state) { |
| 395 | // no-op |
| 396 | } |
Pavel Zhamaitsiak | a6cae36 | 2014-12-10 17:31:33 -0800 | [diff] [blame] | 397 | |
| 398 | /** |
Shriram Ganesh | d3adfad | 2015-05-31 10:06:15 -0700 | [diff] [blame] | 399 | * Called when the call supp service is received |
| 400 | * The default implementation calls {@link #onCallStateChanged}. |
| 401 | * |
| 402 | * @param call the call object that carries out the IMS call |
| 403 | */ |
| 404 | public void onCallSuppServiceReceived(ImsCall call, |
| 405 | ImsSuppServiceNotification suppServiceInfo) { |
| 406 | } |
| 407 | |
| 408 | /** |
Pavel Zhamaitsiak | a6cae36 | 2014-12-10 17:31:33 -0800 | [diff] [blame] | 409 | * Called when TTY mode of remote party changed |
| 410 | * |
| 411 | * @param call the call object that carries out the IMS call |
| 412 | * @param mode TTY mode of remote party |
| 413 | */ |
| 414 | public void onCallSessionTtyModeReceived(ImsCall call, int mode) { |
| 415 | // no-op |
| 416 | } |
Rekha Kumar | 1463174 | 2015-02-04 10:47:00 -0800 | [diff] [blame] | 417 | |
| 418 | /** |
| 419 | * Called when handover occurs from one access technology to another. |
| 420 | * |
Anthony Lee | 6804851 | 2015-03-18 15:04:18 -0700 | [diff] [blame] | 421 | * @param imsCall ImsCall object |
Rekha Kumar | 1463174 | 2015-02-04 10:47:00 -0800 | [diff] [blame] | 422 | * @param srcAccessTech original access technology |
| 423 | * @param targetAccessTech new access technology |
| 424 | * @param reasonInfo |
| 425 | */ |
| 426 | public void onCallHandover(ImsCall imsCall, int srcAccessTech, int targetAccessTech, |
| 427 | ImsReasonInfo reasonInfo) { |
| 428 | } |
| 429 | |
| 430 | /** |
Hall Liu | bd3f377 | 2017-03-22 15:38:23 -0700 | [diff] [blame] | 431 | * Called when the remote party issues an RTT modify request |
| 432 | * |
| 433 | * @param imsCall ImsCall object |
| 434 | */ |
| 435 | public void onRttModifyRequestReceived(ImsCall imsCall) { |
| 436 | } |
| 437 | |
| 438 | /** |
| 439 | * Called when the remote party responds to a locally-issued RTT request. |
| 440 | * |
| 441 | * @param imsCall ImsCall object |
| 442 | * @param status The status of the request. See |
| 443 | * {@link Connection.RttModifyStatus} for possible values. |
| 444 | */ |
| 445 | public void onRttModifyResponseReceived(ImsCall imsCall, int status) { |
| 446 | } |
| 447 | |
| 448 | /** |
| 449 | * Called when the remote party has sent some characters via RTT |
| 450 | * |
| 451 | * @param imsCall ImsCall object |
| 452 | * @param message A string containing the transmitted characters. |
| 453 | */ |
| 454 | public void onRttMessageReceived(ImsCall imsCall, String message) { |
| 455 | } |
| 456 | |
| 457 | /** |
Rekha Kumar | 1463174 | 2015-02-04 10:47:00 -0800 | [diff] [blame] | 458 | * Called when handover from one access technology to another fails. |
| 459 | * |
Anthony Lee | 6804851 | 2015-03-18 15:04:18 -0700 | [diff] [blame] | 460 | * @param imsCall call that failed the handover. |
Rekha Kumar | 1463174 | 2015-02-04 10:47:00 -0800 | [diff] [blame] | 461 | * @param srcAccessTech original access technology |
| 462 | * @param targetAccessTech new access technology |
| 463 | * @param reasonInfo |
| 464 | */ |
| 465 | public void onCallHandoverFailed(ImsCall imsCall, int srcAccessTech, int targetAccessTech, |
| 466 | ImsReasonInfo reasonInfo) { |
| 467 | } |
Tyler Gunn | 2539409 | 2015-04-01 09:40:02 -0700 | [diff] [blame] | 468 | |
| 469 | /** |
| 470 | * Notifies of a change to the multiparty state for this {@code ImsCall}. |
| 471 | * |
| 472 | * @param imsCall The IMS call. |
| 473 | * @param isMultiParty {@code true} if the call became multiparty, {@code false} |
| 474 | * otherwise. |
| 475 | */ |
| 476 | public void onMultipartyStateChanged(ImsCall imsCall, boolean isMultiParty) { |
| 477 | } |
Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 478 | } |
| 479 | |
Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 480 | // List of update operation for IMS call control |
| 481 | private static final int UPDATE_NONE = 0; |
| 482 | private static final int UPDATE_HOLD = 1; |
| 483 | private static final int UPDATE_HOLD_MERGE = 2; |
| 484 | private static final int UPDATE_RESUME = 3; |
| 485 | private static final int UPDATE_MERGE = 4; |
| 486 | private static final int UPDATE_EXTEND_TO_CONFERENCE = 5; |
| 487 | private static final int UPDATE_UNSPECIFIED = 6; |
| 488 | |
| 489 | // For synchronization of private variables |
| 490 | private Object mLockObj = new Object(); |
| 491 | private Context mContext; |
| 492 | |
| 493 | // true if the call is established & in the conversation state |
| 494 | private boolean mInCall = false; |
| 495 | // true if the call is on hold |
| 496 | // If it is triggered by the local, mute the call. Otherwise, play local hold tone |
| 497 | // or network generated media. |
| 498 | private boolean mHold = false; |
| 499 | // true if the call is on mute |
| 500 | private boolean mMute = false; |
| 501 | // It contains the exclusive call update request. Refer to UPDATE_*. |
| 502 | private int mUpdateRequest = UPDATE_NONE; |
| 503 | |
| 504 | private ImsCall.Listener mListener = null; |
Tyler Gunn | 9bd5ca5 | 2014-12-02 09:21:01 -0800 | [diff] [blame] | 505 | |
| 506 | // When merging two calls together, the "peer" call that will merge into this call. |
| 507 | private ImsCall mMergePeer = null; |
| 508 | // When merging two calls together, the "host" call we are merging into. |
| 509 | private ImsCall mMergeHost = null; |
Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 510 | |
Uma Maheswari Ramalingam | 95be7c6 | 2015-05-06 23:08:17 -0700 | [diff] [blame] | 511 | // True if Conference request was initiated by |
| 512 | // Foreground Conference call else it will be false |
| 513 | private boolean mMergeRequestedByConference = false; |
Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 514 | // Wrapper call session to interworking the IMS service (server). |
| 515 | private ImsCallSession mSession = null; |
| 516 | // Call profile of the current session. |
| 517 | // It can be changed at anytime when the call is updated. |
| 518 | private ImsCallProfile mCallProfile = null; |
| 519 | // Call profile to be updated after the application's action (accept/reject) |
| 520 | // to the call update. After the application's action (accept/reject) is done, |
| 521 | // it will be set to null. |
| 522 | private ImsCallProfile mProposedCallProfile = null; |
| 523 | private ImsReasonInfo mLastReasonInfo = null; |
| 524 | |
| 525 | // Media session to control media (audio/video) operations for an IMS call |
| 526 | private ImsStreamMediaSession mMediaSession = null; |
| 527 | |
Anthony Lee | b8799fe | 2014-11-03 15:13:47 -0800 | [diff] [blame] | 528 | // The temporary ImsCallSession that could represent the merged call once |
| 529 | // we receive notification that the merge was successful. |
Anthony Lee | 7138269 | 2014-10-30 10:50:10 -0700 | [diff] [blame] | 530 | private ImsCallSession mTransientConferenceSession = null; |
Anthony Lee | b8799fe | 2014-11-03 15:13:47 -0800 | [diff] [blame] | 531 | // While a merge is progressing, we bury any session termination requests |
| 532 | // made on the original ImsCallSession until we have closure on the merge request |
| 533 | // If the request ultimately fails, we need to act on the termination request |
| 534 | // that we buried temporarily. We do this because we feel that timing issues could |
| 535 | // cause the termination request to occur just because the merge is succeeding. |
| 536 | private boolean mSessionEndDuringMerge = false; |
| 537 | // Just like mSessionEndDuringMerge, we need to keep track of the reason why the |
| 538 | // termination request was made on the original session in case we need to act |
| 539 | // on it in the case of a merge failure. |
| 540 | private ImsReasonInfo mSessionEndDuringMergeReasonInfo = null; |
Anthony Lee | c479f66 | 2015-02-11 17:04:35 -0800 | [diff] [blame] | 541 | // This flag is used to indicate if this ImsCall was merged into a conference |
| 542 | // or not. It is used primarily to determine if a disconnect sound should |
| 543 | // be heard when the call is terminated. |
Andrew Lee | 8ae5949 | 2014-11-17 17:03:02 -0800 | [diff] [blame] | 544 | private boolean mIsMerged = false; |
Anthony Lee | c479f66 | 2015-02-11 17:04:35 -0800 | [diff] [blame] | 545 | // If true, this flag means that this ImsCall is in the process of merging |
| 546 | // into a conference but it does not yet have closure on if it was |
| 547 | // actually added to the conference or not. false implies that it either |
| 548 | // is not part of a merging conference or already knows if it was |
| 549 | // successfully added. |
Tyler Gunn | 047d810 | 2015-01-30 15:21:11 -0800 | [diff] [blame] | 550 | private boolean mCallSessionMergePending = false; |
| 551 | |
Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 552 | /** |
Tyler Gunn | 95d563e | 2015-07-23 09:28:58 -0700 | [diff] [blame] | 553 | * If {@code true}, this flag indicates that a request to terminate the call was made by |
| 554 | * Telephony (could be from the user or some internal telephony logic) |
| 555 | * and that when we receive a {@link #processCallTerminated(ImsReasonInfo)} callback from the |
| 556 | * radio indicating that the call was terminated, we should override any burying of the |
| 557 | * termination due to an ongoing conference merge. |
| 558 | */ |
| 559 | private boolean mTerminationRequestPending = false; |
| 560 | |
| 561 | /** |
Tyler Gunn | 2539409 | 2015-04-01 09:40:02 -0700 | [diff] [blame] | 562 | * For multi-party IMS calls (e.g. conferences), determines if this {@link ImsCall} is the one |
| 563 | * hosting the call. This is used to distinguish between a situation where an {@link ImsCall} |
| 564 | * is {@link #isMultiparty()} because calls were merged on the device, and a situation where |
| 565 | * an {@link ImsCall} is {@link #isMultiparty()} because it is a member of a conference started |
| 566 | * on another device. |
| 567 | * <p> |
| 568 | * When {@code true}, this {@link ImsCall} is is the origin of the conference call. |
| 569 | * When {@code false}, this {@link ImsCall} is a member of a conference started on another |
| 570 | * device. |
| 571 | */ |
| 572 | private boolean mIsConferenceHost = false; |
| 573 | |
| 574 | /** |
Tyler Gunn | 1ac2485 | 2016-06-22 10:04:23 -0700 | [diff] [blame] | 575 | * Tracks whether this {@link ImsCall} has been a video call at any point in its lifetime. |
| 576 | * Some examples of calls which are/were video calls: |
| 577 | * 1. A call which has been a video call for its duration. |
| 578 | * 2. An audio call upgraded to video (and potentially downgraded to audio later). |
| 579 | * 3. A call answered as video which was downgraded to audio. |
| 580 | */ |
| 581 | private boolean mWasVideoCall = false; |
| 582 | |
| 583 | /** |
Jack Yu | b42ff55 | 2016-06-22 13:20:52 -0700 | [diff] [blame] | 584 | * Unique id generator used to generate call id. |
| 585 | */ |
| 586 | private static final AtomicInteger sUniqueIdGenerator = new AtomicInteger(); |
| 587 | |
| 588 | /** |
| 589 | * Unique identifier. |
| 590 | */ |
| 591 | public final int uniqueId; |
| 592 | |
| 593 | /** |
Tyler Gunn | afb53c8 | 2016-08-05 14:38:13 -0700 | [diff] [blame] | 594 | * The current ImsCallSessionListenerProxy. |
| 595 | */ |
| 596 | private ImsCallSessionListenerProxy mImsCallSessionListenerProxy; |
| 597 | |
| 598 | /** |
Tyler Gunn | 25a72fc | 2016-08-11 13:16:54 -0700 | [diff] [blame] | 599 | * When calling {@link #terminate(int, int)}, an override for the termination reason which the |
| 600 | * modem returns. |
| 601 | * |
| 602 | * Necessary because passing in an unexpected {@link ImsReasonInfo} reason code to |
| 603 | * {@link #terminate(int)} will cause the modem to ignore the terminate request. |
| 604 | */ |
| 605 | private int mOverrideReason = ImsReasonInfo.CODE_UNSPECIFIED; |
| 606 | |
| 607 | /** |
Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 608 | * Create an IMS call object. |
| 609 | * |
| 610 | * @param context the context for accessing system services |
| 611 | * @param profile the call profile to make/take a call |
| 612 | */ |
| 613 | public ImsCall(Context context, ImsCallProfile profile) { |
| 614 | mContext = context; |
Tyler Gunn | 1ac2485 | 2016-06-22 10:04:23 -0700 | [diff] [blame] | 615 | setCallProfile(profile); |
Jack Yu | b42ff55 | 2016-06-22 13:20:52 -0700 | [diff] [blame] | 616 | uniqueId = sUniqueIdGenerator.getAndIncrement(); |
Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 617 | } |
| 618 | |
| 619 | /** |
| 620 | * Closes this object. This object is not usable after being closed. |
| 621 | */ |
| 622 | @Override |
| 623 | public void close() { |
| 624 | synchronized(mLockObj) { |
Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 625 | if (mSession != null) { |
| 626 | mSession.close(); |
| 627 | mSession = null; |
Uma Maheswari Ramalingam | 95be7c6 | 2015-05-06 23:08:17 -0700 | [diff] [blame] | 628 | } else { |
| 629 | logi("close :: Cannot close Null call session!"); |
Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 630 | } |
| 631 | |
| 632 | mCallProfile = null; |
| 633 | mProposedCallProfile = null; |
| 634 | mLastReasonInfo = null; |
| 635 | mMediaSession = null; |
| 636 | } |
| 637 | } |
| 638 | |
| 639 | /** |
| 640 | * Checks if the call has a same remote user identity or not. |
| 641 | * |
| 642 | * @param userId the remote user identity |
| 643 | * @return true if the remote user identity is equal; otherwise, false |
| 644 | */ |
| 645 | @Override |
| 646 | public boolean checkIfRemoteUserIsSame(String userId) { |
| 647 | if (userId == null) { |
| 648 | return false; |
| 649 | } |
| 650 | |
| 651 | return userId.equals(mCallProfile.getCallExtra(ImsCallProfile.EXTRA_REMOTE_URI, "")); |
| 652 | } |
| 653 | |
| 654 | /** |
| 655 | * Checks if the call is equal or not. |
| 656 | * |
| 657 | * @param call the call to be compared |
| 658 | * @return true if the call is equal; otherwise, false |
| 659 | */ |
| 660 | @Override |
| 661 | public boolean equalsTo(ICall call) { |
| 662 | if (call == null) { |
| 663 | return false; |
| 664 | } |
| 665 | |
| 666 | if (call instanceof ImsCall) { |
Etan Cohen | 16b3b36 | 2014-10-24 11:10:58 -0700 | [diff] [blame] | 667 | return this.equals(call); |
Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 668 | } |
| 669 | |
| 670 | return false; |
| 671 | } |
| 672 | |
Anthony Lee | c479f66 | 2015-02-11 17:04:35 -0800 | [diff] [blame] | 673 | public static boolean isSessionAlive(ImsCallSession session) { |
| 674 | return session != null && session.isAlive(); |
| 675 | } |
| 676 | |
Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 677 | /** |
| 678 | * Gets the negotiated (local & remote) call profile. |
| 679 | * |
| 680 | * @return a {@link ImsCallProfile} object that has the negotiated call profile |
| 681 | */ |
| 682 | public ImsCallProfile getCallProfile() { |
| 683 | synchronized(mLockObj) { |
| 684 | return mCallProfile; |
| 685 | } |
| 686 | } |
| 687 | |
| 688 | /** |
Tyler Gunn | 1ac2485 | 2016-06-22 10:04:23 -0700 | [diff] [blame] | 689 | * Replaces the current call profile with a new one, tracking whethere this was previously a |
| 690 | * video call or not. |
| 691 | * |
| 692 | * @param profile The new call profile. |
| 693 | */ |
Tyler Gunn | cc0f78f | 2017-12-04 13:01:55 -0800 | [diff] [blame] | 694 | @VisibleForTesting |
| 695 | public void setCallProfile(ImsCallProfile profile) { |
Tyler Gunn | 1ac2485 | 2016-06-22 10:04:23 -0700 | [diff] [blame] | 696 | synchronized(mLockObj) { |
| 697 | mCallProfile = profile; |
| 698 | trackVideoStateHistory(mCallProfile); |
| 699 | } |
| 700 | } |
| 701 | |
| 702 | /** |
Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 703 | * Gets the local call profile (local capabilities). |
| 704 | * |
| 705 | * @return a {@link ImsCallProfile} object that has the local call profile |
| 706 | */ |
| 707 | public ImsCallProfile getLocalCallProfile() throws ImsException { |
| 708 | synchronized(mLockObj) { |
| 709 | if (mSession == null) { |
| 710 | throw new ImsException("No call session", |
| 711 | ImsReasonInfo.CODE_LOCAL_CALL_TERMINATED); |
| 712 | } |
| 713 | |
| 714 | try { |
| 715 | return mSession.getLocalCallProfile(); |
| 716 | } catch (Throwable t) { |
| 717 | loge("getLocalCallProfile :: ", t); |
| 718 | throw new ImsException("getLocalCallProfile()", t, 0); |
| 719 | } |
| 720 | } |
| 721 | } |
| 722 | |
| 723 | /** |
Shriram Ganesh | e871989 | 2014-10-13 18:28:34 -0700 | [diff] [blame] | 724 | * Gets the remote call profile (remote capabilities). |
| 725 | * |
| 726 | * @return a {@link ImsCallProfile} object that has the remote call profile |
| 727 | */ |
| 728 | public ImsCallProfile getRemoteCallProfile() throws ImsException { |
| 729 | synchronized(mLockObj) { |
| 730 | if (mSession == null) { |
| 731 | throw new ImsException("No call session", |
| 732 | ImsReasonInfo.CODE_LOCAL_CALL_TERMINATED); |
| 733 | } |
| 734 | |
| 735 | try { |
| 736 | return mSession.getRemoteCallProfile(); |
| 737 | } catch (Throwable t) { |
| 738 | loge("getRemoteCallProfile :: ", t); |
| 739 | throw new ImsException("getRemoteCallProfile()", t, 0); |
| 740 | } |
| 741 | } |
| 742 | } |
| 743 | |
| 744 | /** |
Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 745 | * Gets the call profile proposed by the local/remote user. |
| 746 | * |
| 747 | * @return a {@link ImsCallProfile} object that has the proposed call profile |
| 748 | */ |
| 749 | public ImsCallProfile getProposedCallProfile() { |
| 750 | synchronized(mLockObj) { |
| 751 | if (!isInCall()) { |
| 752 | return null; |
| 753 | } |
| 754 | |
| 755 | return mProposedCallProfile; |
| 756 | } |
| 757 | } |
| 758 | |
| 759 | /** |
Uma Maheswari Ramalingam | a1ed7b0 | 2015-05-20 14:26:42 -0700 | [diff] [blame] | 760 | * Gets the list of conference participants currently |
| 761 | * associated with this call. |
| 762 | * |
Tyler Gunn | 3a3d8eb | 2016-08-18 12:58:26 -0700 | [diff] [blame] | 763 | * @return Copy of the list of conference participants. |
Uma Maheswari Ramalingam | a1ed7b0 | 2015-05-20 14:26:42 -0700 | [diff] [blame] | 764 | */ |
| 765 | public List<ConferenceParticipant> getConferenceParticipants() { |
| 766 | synchronized(mLockObj) { |
| 767 | logi("getConferenceParticipants :: mConferenceParticipants" |
| 768 | + mConferenceParticipants); |
Tyler Gunn | 108a6b7 | 2016-08-23 21:05:25 -0700 | [diff] [blame] | 769 | if (mConferenceParticipants == null) { |
| 770 | return null; |
| 771 | } |
| 772 | if (mConferenceParticipants.isEmpty()) { |
| 773 | return new ArrayList<ConferenceParticipant>(0); |
| 774 | } |
Tyler Gunn | 3a3d8eb | 2016-08-18 12:58:26 -0700 | [diff] [blame] | 775 | return new ArrayList<ConferenceParticipant>(mConferenceParticipants); |
Uma Maheswari Ramalingam | a1ed7b0 | 2015-05-20 14:26:42 -0700 | [diff] [blame] | 776 | } |
| 777 | } |
| 778 | |
| 779 | /** |
Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 780 | * Gets the state of the {@link ImsCallSession} that carries this call. |
| 781 | * The value returned must be one of the states in {@link ImsCallSession#State}. |
| 782 | * |
| 783 | * @return the session state |
| 784 | */ |
| 785 | public int getState() { |
| 786 | synchronized(mLockObj) { |
| 787 | if (mSession == null) { |
| 788 | return ImsCallSession.State.IDLE; |
| 789 | } |
| 790 | |
| 791 | return mSession.getState(); |
| 792 | } |
| 793 | } |
| 794 | |
| 795 | /** |
| 796 | * Gets the {@link ImsCallSession} that carries this call. |
| 797 | * |
| 798 | * @return the session object that carries this call |
| 799 | * @hide |
| 800 | */ |
| 801 | public ImsCallSession getCallSession() { |
| 802 | synchronized(mLockObj) { |
| 803 | return mSession; |
| 804 | } |
| 805 | } |
| 806 | |
| 807 | /** |
| 808 | * Gets the {@link ImsStreamMediaSession} that handles the media operation of this call. |
| 809 | * Almost interface APIs are for the VT (Video Telephony). |
| 810 | * |
| 811 | * @return the media session object that handles the media operation of this call |
| 812 | * @hide |
| 813 | */ |
| 814 | public ImsStreamMediaSession getMediaSession() { |
| 815 | synchronized(mLockObj) { |
| 816 | return mMediaSession; |
| 817 | } |
| 818 | } |
| 819 | |
| 820 | /** |
| 821 | * Gets the specified property of this call. |
| 822 | * |
| 823 | * @param name key to get the extra call information defined in {@link ImsCallProfile} |
| 824 | * @return the extra call information as string |
| 825 | */ |
| 826 | public String getCallExtra(String name) throws ImsException { |
| 827 | // Lookup the cache |
| 828 | |
| 829 | synchronized(mLockObj) { |
| 830 | // If not found, try to get the property from the remote |
| 831 | if (mSession == null) { |
| 832 | throw new ImsException("No call session", |
| 833 | ImsReasonInfo.CODE_LOCAL_CALL_TERMINATED); |
| 834 | } |
| 835 | |
| 836 | try { |
| 837 | return mSession.getProperty(name); |
| 838 | } catch (Throwable t) { |
| 839 | loge("getCallExtra :: ", t); |
| 840 | throw new ImsException("getCallExtra()", t, 0); |
| 841 | } |
| 842 | } |
| 843 | } |
| 844 | |
| 845 | /** |
| 846 | * Gets the last reason information when the call is not established, cancelled or terminated. |
| 847 | * |
| 848 | * @return the last reason information |
| 849 | */ |
| 850 | public ImsReasonInfo getLastReasonInfo() { |
| 851 | synchronized(mLockObj) { |
| 852 | return mLastReasonInfo; |
| 853 | } |
| 854 | } |
| 855 | |
| 856 | /** |
| 857 | * Checks if the call has a pending update operation. |
| 858 | * |
| 859 | * @return true if the call has a pending update operation |
| 860 | */ |
| 861 | public boolean hasPendingUpdate() { |
| 862 | synchronized(mLockObj) { |
| 863 | return (mUpdateRequest != UPDATE_NONE); |
| 864 | } |
| 865 | } |
| 866 | |
| 867 | /** |
Tyler Gunn | 6c0b0d0 | 2015-07-01 16:39:43 -0700 | [diff] [blame] | 868 | * Checks if the call is pending a hold operation. |
| 869 | * |
| 870 | * @return true if the call is pending a hold operation. |
| 871 | */ |
| 872 | public boolean isPendingHold() { |
| 873 | synchronized(mLockObj) { |
| 874 | return (mUpdateRequest == UPDATE_HOLD); |
| 875 | } |
| 876 | } |
| 877 | |
| 878 | /** |
Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 879 | * Checks if the call is established. |
| 880 | * |
| 881 | * @return true if the call is established |
| 882 | */ |
| 883 | public boolean isInCall() { |
| 884 | synchronized(mLockObj) { |
| 885 | return mInCall; |
| 886 | } |
| 887 | } |
| 888 | |
| 889 | /** |
| 890 | * Checks if the call is muted. |
| 891 | * |
| 892 | * @return true if the call is muted |
| 893 | */ |
| 894 | public boolean isMuted() { |
| 895 | synchronized(mLockObj) { |
| 896 | return mMute; |
| 897 | } |
| 898 | } |
| 899 | |
| 900 | /** |
| 901 | * Checks if the call is on hold. |
| 902 | * |
| 903 | * @return true if the call is on hold |
| 904 | */ |
| 905 | public boolean isOnHold() { |
| 906 | synchronized(mLockObj) { |
| 907 | return mHold; |
| 908 | } |
| 909 | } |
| 910 | |
| 911 | /** |
Tyler Gunn | 725ad37 | 2014-10-22 11:28:47 -0700 | [diff] [blame] | 912 | * Determines if the call is a multiparty call. |
| 913 | * |
| 914 | * @return {@code True} if the call is a multiparty call. |
| 915 | */ |
| 916 | public boolean isMultiparty() { |
Etan Cohen | 16b3b36 | 2014-10-24 11:10:58 -0700 | [diff] [blame] | 917 | synchronized(mLockObj) { |
| 918 | if (mSession == null) { |
| 919 | return false; |
| 920 | } |
| 921 | |
Anthony Lee | 7138269 | 2014-10-30 10:50:10 -0700 | [diff] [blame] | 922 | return mSession.isMultiparty(); |
Etan Cohen | 16b3b36 | 2014-10-24 11:10:58 -0700 | [diff] [blame] | 923 | } |
Tyler Gunn | 725ad37 | 2014-10-22 11:28:47 -0700 | [diff] [blame] | 924 | } |
| 925 | |
| 926 | /** |
Tyler Gunn | 2539409 | 2015-04-01 09:40:02 -0700 | [diff] [blame] | 927 | * Where {@link #isMultiparty()} is {@code true}, determines if this {@link ImsCall} is the |
| 928 | * origin of the conference call (i.e. {@code #isConferenceHost()} is {@code true}), or if this |
| 929 | * {@link ImsCall} is a member of a conference hosted on another device. |
| 930 | * |
| 931 | * @return {@code true} if this call is the origin of the conference call it is a member of, |
| 932 | * {@code false} otherwise. |
| 933 | */ |
| 934 | public boolean isConferenceHost() { |
| 935 | synchronized(mLockObj) { |
| 936 | return isMultiparty() && mIsConferenceHost; |
| 937 | } |
| 938 | } |
| 939 | |
| 940 | /** |
Tyler Gunn | 9bd5ca5 | 2014-12-02 09:21:01 -0800 | [diff] [blame] | 941 | * Marks whether an IMS call is merged. This should be set {@code true} when the call merges |
| 942 | * into a conference. |
Andrew Lee | 8ae5949 | 2014-11-17 17:03:02 -0800 | [diff] [blame] | 943 | * |
| 944 | * @param isMerged Whether the call is merged. |
| 945 | */ |
| 946 | public void setIsMerged(boolean isMerged) { |
| 947 | mIsMerged = isMerged; |
| 948 | } |
| 949 | |
| 950 | /** |
Tyler Gunn | 9bd5ca5 | 2014-12-02 09:21:01 -0800 | [diff] [blame] | 951 | * @return {@code true} if the call recently merged into a conference call. |
Andrew Lee | 8ae5949 | 2014-11-17 17:03:02 -0800 | [diff] [blame] | 952 | */ |
| 953 | public boolean isMerged() { |
| 954 | return mIsMerged; |
| 955 | } |
| 956 | |
| 957 | /** |
Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 958 | * Sets the listener to listen to the IMS call events. |
| 959 | * The method calls {@link #setListener setListener(listener, false)}. |
| 960 | * |
| 961 | * @param listener to listen to the IMS call events of this object; null to remove listener |
| 962 | * @see #setListener(Listener, boolean) |
| 963 | */ |
| 964 | public void setListener(ImsCall.Listener listener) { |
| 965 | setListener(listener, false); |
| 966 | } |
| 967 | |
| 968 | /** |
| 969 | * Sets the listener to listen to the IMS call events. |
| 970 | * A {@link ImsCall} can only hold one listener at a time. Subsequent calls |
| 971 | * to this method override the previous listener. |
| 972 | * |
| 973 | * @param listener to listen to the IMS call events of this object; null to remove listener |
| 974 | * @param callbackImmediately set to true if the caller wants to be called |
| 975 | * back immediately on the current state |
| 976 | */ |
| 977 | public void setListener(ImsCall.Listener listener, boolean callbackImmediately) { |
| 978 | boolean inCall; |
| 979 | boolean onHold; |
| 980 | int state; |
| 981 | ImsReasonInfo lastReasonInfo; |
| 982 | |
| 983 | synchronized(mLockObj) { |
| 984 | mListener = listener; |
| 985 | |
| 986 | if ((listener == null) || !callbackImmediately) { |
| 987 | return; |
| 988 | } |
| 989 | |
| 990 | inCall = mInCall; |
| 991 | onHold = mHold; |
| 992 | state = getState(); |
| 993 | lastReasonInfo = mLastReasonInfo; |
| 994 | } |
| 995 | |
| 996 | try { |
| 997 | if (lastReasonInfo != null) { |
| 998 | listener.onCallError(this, lastReasonInfo); |
| 999 | } else if (inCall) { |
| 1000 | if (onHold) { |
| 1001 | listener.onCallHeld(this); |
| 1002 | } else { |
| 1003 | listener.onCallStarted(this); |
| 1004 | } |
| 1005 | } else { |
| 1006 | switch (state) { |
| 1007 | case ImsCallSession.State.ESTABLISHING: |
| 1008 | listener.onCallProgressing(this); |
| 1009 | break; |
| 1010 | case ImsCallSession.State.TERMINATED: |
| 1011 | listener.onCallTerminated(this, lastReasonInfo); |
| 1012 | break; |
| 1013 | default: |
| 1014 | // Ignore it. There is no action in the other state. |
| 1015 | break; |
| 1016 | } |
| 1017 | } |
| 1018 | } catch (Throwable t) { |
Anthony Lee | 6804851 | 2015-03-18 15:04:18 -0700 | [diff] [blame] | 1019 | loge("setListener() :: ", t); |
Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 1020 | } |
| 1021 | } |
| 1022 | |
| 1023 | /** |
| 1024 | * Mutes or unmutes the mic for the active call. |
| 1025 | * |
| 1026 | * @param muted true if the call is muted, false otherwise |
| 1027 | */ |
| 1028 | public void setMute(boolean muted) throws ImsException { |
| 1029 | synchronized(mLockObj) { |
| 1030 | if (mMute != muted) { |
Anthony Lee | 6804851 | 2015-03-18 15:04:18 -0700 | [diff] [blame] | 1031 | logi("setMute :: turning mute " + (muted ? "on" : "off")); |
Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 1032 | mMute = muted; |
| 1033 | |
| 1034 | try { |
| 1035 | mSession.setMute(muted); |
| 1036 | } catch (Throwable t) { |
| 1037 | loge("setMute :: ", t); |
| 1038 | throwImsException(t, 0); |
| 1039 | } |
| 1040 | } |
| 1041 | } |
| 1042 | } |
| 1043 | |
| 1044 | /** |
| 1045 | * Attaches an incoming call to this call object. |
| 1046 | * |
| 1047 | * @param session the session that receives the incoming call |
| 1048 | * @throws ImsException if the IMS service fails to attach this object to the session |
| 1049 | */ |
| 1050 | public void attachSession(ImsCallSession session) throws ImsException { |
Anthony Lee | 6804851 | 2015-03-18 15:04:18 -0700 | [diff] [blame] | 1051 | logi("attachSession :: session=" + session); |
Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 1052 | |
| 1053 | synchronized(mLockObj) { |
| 1054 | mSession = session; |
| 1055 | |
| 1056 | try { |
| 1057 | mSession.setListener(createCallSessionListener()); |
| 1058 | } catch (Throwable t) { |
| 1059 | loge("attachSession :: ", t); |
| 1060 | throwImsException(t, 0); |
| 1061 | } |
| 1062 | } |
| 1063 | } |
| 1064 | |
| 1065 | /** |
| 1066 | * Initiates an IMS call with the call profile which is provided |
| 1067 | * when creating a {@link ImsCall}. |
| 1068 | * |
| 1069 | * @param session the {@link ImsCallSession} for carrying out the call |
| 1070 | * @param callee callee information to initiate an IMS call |
| 1071 | * @throws ImsException if the IMS service fails to initiate the call |
| 1072 | */ |
| 1073 | public void start(ImsCallSession session, String callee) |
| 1074 | throws ImsException { |
fionaxu | 7b3107c | 2016-07-06 14:04:06 -0700 | [diff] [blame] | 1075 | logi("start(1) :: session=" + session); |
Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 1076 | |
| 1077 | synchronized(mLockObj) { |
| 1078 | mSession = session; |
| 1079 | |
| 1080 | try { |
| 1081 | session.setListener(createCallSessionListener()); |
| 1082 | session.start(callee, mCallProfile); |
| 1083 | } catch (Throwable t) { |
| 1084 | loge("start(1) :: ", t); |
| 1085 | throw new ImsException("start(1)", t, 0); |
| 1086 | } |
| 1087 | } |
| 1088 | } |
| 1089 | |
| 1090 | /** |
| 1091 | * Initiates an IMS conferenca call with the call profile which is provided |
| 1092 | * when creating a {@link ImsCall}. |
| 1093 | * |
| 1094 | * @param session the {@link ImsCallSession} for carrying out the call |
| 1095 | * @param participants participant list to initiate an IMS conference call |
| 1096 | * @throws ImsException if the IMS service fails to initiate the call |
| 1097 | */ |
| 1098 | public void start(ImsCallSession session, String[] participants) |
| 1099 | throws ImsException { |
fionaxu | 7b3107c | 2016-07-06 14:04:06 -0700 | [diff] [blame] | 1100 | logi("start(n) :: session=" + session); |
Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 1101 | |
| 1102 | synchronized(mLockObj) { |
| 1103 | mSession = session; |
| 1104 | |
| 1105 | try { |
| 1106 | session.setListener(createCallSessionListener()); |
| 1107 | session.start(participants, mCallProfile); |
| 1108 | } catch (Throwable t) { |
| 1109 | loge("start(n) :: ", t); |
| 1110 | throw new ImsException("start(n)", t, 0); |
| 1111 | } |
| 1112 | } |
| 1113 | } |
| 1114 | |
| 1115 | /** |
| 1116 | * Accepts a call. |
| 1117 | * |
| 1118 | * @see Listener#onCallStarted |
Tyler Gunn | d1edfd8 | 2014-07-18 13:44:18 -0700 | [diff] [blame] | 1119 | * |
| 1120 | * @param callType The call type the user agreed to for accepting the call. |
Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 1121 | * @throws ImsException if the IMS service fails to accept the call |
| 1122 | */ |
Tyler Gunn | d1edfd8 | 2014-07-18 13:44:18 -0700 | [diff] [blame] | 1123 | public void accept(int callType) throws ImsException { |
Tyler Gunn | d1edfd8 | 2014-07-18 13:44:18 -0700 | [diff] [blame] | 1124 | accept(callType, new ImsStreamMediaProfile()); |
Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 1125 | } |
| 1126 | |
| 1127 | /** |
| 1128 | * Accepts a call. |
| 1129 | * |
| 1130 | * @param callType call type to be answered in {@link ImsCallProfile} |
| 1131 | * @param profile a media profile to be answered (audio/audio & video, direction, ...) |
| 1132 | * @see Listener#onCallStarted |
| 1133 | * @throws ImsException if the IMS service fails to accept the call |
| 1134 | */ |
| 1135 | public void accept(int callType, ImsStreamMediaProfile profile) throws ImsException { |
Anthony Lee | 6804851 | 2015-03-18 15:04:18 -0700 | [diff] [blame] | 1136 | logi("accept :: callType=" + callType + ", profile=" + profile); |
Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 1137 | |
| 1138 | synchronized(mLockObj) { |
| 1139 | if (mSession == null) { |
| 1140 | throw new ImsException("No call to answer", |
| 1141 | ImsReasonInfo.CODE_LOCAL_CALL_TERMINATED); |
| 1142 | } |
| 1143 | |
| 1144 | try { |
| 1145 | mSession.accept(callType, profile); |
| 1146 | } catch (Throwable t) { |
| 1147 | loge("accept :: ", t); |
| 1148 | throw new ImsException("accept()", t, 0); |
| 1149 | } |
| 1150 | |
| 1151 | if (mInCall && (mProposedCallProfile != null)) { |
| 1152 | if (DBG) { |
Anthony Lee | 6804851 | 2015-03-18 15:04:18 -0700 | [diff] [blame] | 1153 | logi("accept :: call profile will be updated"); |
Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 1154 | } |
| 1155 | |
| 1156 | mCallProfile = mProposedCallProfile; |
Tyler Gunn | 1ac2485 | 2016-06-22 10:04:23 -0700 | [diff] [blame] | 1157 | trackVideoStateHistory(mCallProfile); |
Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 1158 | mProposedCallProfile = null; |
| 1159 | } |
| 1160 | |
| 1161 | // Other call update received |
| 1162 | if (mInCall && (mUpdateRequest == UPDATE_UNSPECIFIED)) { |
| 1163 | mUpdateRequest = UPDATE_NONE; |
| 1164 | } |
| 1165 | } |
| 1166 | } |
| 1167 | |
| 1168 | /** |
| 1169 | * Rejects a call. |
| 1170 | * |
| 1171 | * @param reason reason code to reject an incoming call |
| 1172 | * @see Listener#onCallStartFailed |
Anthony Lee | 6804851 | 2015-03-18 15:04:18 -0700 | [diff] [blame] | 1173 | * @throws ImsException if the IMS service fails to reject the call |
Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 1174 | */ |
| 1175 | public void reject(int reason) throws ImsException { |
Anthony Lee | 6804851 | 2015-03-18 15:04:18 -0700 | [diff] [blame] | 1176 | logi("reject :: reason=" + reason); |
Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 1177 | |
| 1178 | synchronized(mLockObj) { |
| 1179 | if (mSession != null) { |
| 1180 | mSession.reject(reason); |
| 1181 | } |
| 1182 | |
| 1183 | if (mInCall && (mProposedCallProfile != null)) { |
| 1184 | if (DBG) { |
Anthony Lee | 6804851 | 2015-03-18 15:04:18 -0700 | [diff] [blame] | 1185 | logi("reject :: call profile is not updated; destroy it..."); |
Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 1186 | } |
| 1187 | |
| 1188 | mProposedCallProfile = null; |
| 1189 | } |
| 1190 | |
| 1191 | // Other call update received |
| 1192 | if (mInCall && (mUpdateRequest == UPDATE_UNSPECIFIED)) { |
| 1193 | mUpdateRequest = UPDATE_NONE; |
| 1194 | } |
| 1195 | } |
| 1196 | } |
| 1197 | |
Tyler Gunn | 25a72fc | 2016-08-11 13:16:54 -0700 | [diff] [blame] | 1198 | public void terminate(int reason, int overrideReason) throws ImsException { |
| 1199 | logi("terminate :: reason=" + reason + " ; overrideReadon=" + overrideReason); |
| 1200 | mOverrideReason = overrideReason; |
| 1201 | terminate(reason); |
| 1202 | } |
| 1203 | |
Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 1204 | /** |
Tyler Gunn | 95d563e | 2015-07-23 09:28:58 -0700 | [diff] [blame] | 1205 | * Terminates an IMS call (e.g. user initiated). |
Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 1206 | * |
| 1207 | * @param reason reason code to terminate a call |
| 1208 | * @throws ImsException if the IMS service fails to terminate the call |
| 1209 | */ |
| 1210 | public void terminate(int reason) throws ImsException { |
Anthony Lee | 6804851 | 2015-03-18 15:04:18 -0700 | [diff] [blame] | 1211 | logi("terminate :: reason=" + reason); |
Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 1212 | |
| 1213 | synchronized(mLockObj) { |
| 1214 | mHold = false; |
| 1215 | mInCall = false; |
Tyler Gunn | 95d563e | 2015-07-23 09:28:58 -0700 | [diff] [blame] | 1216 | mTerminationRequestPending = true; |
Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 1217 | |
| 1218 | if (mSession != null) { |
Anthony Lee | c479f66 | 2015-02-11 17:04:35 -0800 | [diff] [blame] | 1219 | // TODO: Fix the fact that user invoked call terminations during |
| 1220 | // the process of establishing a conference call needs to be handled |
| 1221 | // as a special case. |
| 1222 | // Currently, any terminations (both invoked by the user or |
| 1223 | // by the network results in a callSessionTerminated() callback |
| 1224 | // from the network. When establishing a conference call we bury |
| 1225 | // these callbacks until we get closure on all participants of the |
| 1226 | // conference. In some situations, we will throw away the callback |
| 1227 | // (when the underlying session of the host of the new conference |
| 1228 | // is terminated) or will will unbury it when the conference has been |
| 1229 | // established, like when the peer of the new conference goes away |
| 1230 | // after the conference has been created. The UI relies on the callback |
| 1231 | // to reflect the fact that the call is gone. |
| 1232 | // So if a user decides to terminated a call while it is merging, it |
| 1233 | // could take a long time to reflect in the UI due to the conference |
| 1234 | // processing but we should probably cancel that and just terminate |
| 1235 | // the call immediately and clean up. This is not a huge issue right |
| 1236 | // now because we have not seen instances where establishing a |
| 1237 | // conference takes a long time (more than a second or two). |
Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 1238 | mSession.terminate(reason); |
| 1239 | } |
| 1240 | } |
| 1241 | } |
| 1242 | |
Uma Maheswari Ramalingam | d43b530 | 2014-08-29 14:13:17 -0700 | [diff] [blame] | 1243 | |
Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 1244 | /** |
| 1245 | * Puts a call on hold. When succeeds, {@link Listener#onCallHeld} is called. |
| 1246 | * |
| 1247 | * @see Listener#onCallHeld, Listener#onCallHoldFailed |
| 1248 | * @throws ImsException if the IMS service fails to hold the call |
| 1249 | */ |
| 1250 | public void hold() throws ImsException { |
Anthony Lee | 6804851 | 2015-03-18 15:04:18 -0700 | [diff] [blame] | 1251 | logi("hold :: "); |
Etan Cohen | 111eecc | 2014-09-10 17:18:12 -0700 | [diff] [blame] | 1252 | |
Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 1253 | if (isOnHold()) { |
| 1254 | if (DBG) { |
Anthony Lee | 6804851 | 2015-03-18 15:04:18 -0700 | [diff] [blame] | 1255 | logi("hold :: call is already on hold"); |
Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 1256 | } |
| 1257 | return; |
| 1258 | } |
| 1259 | |
| 1260 | synchronized(mLockObj) { |
| 1261 | if (mUpdateRequest != UPDATE_NONE) { |
Tyler Gunn | 9bd5ca5 | 2014-12-02 09:21:01 -0800 | [diff] [blame] | 1262 | loge("hold :: update is in progress; request=" + |
| 1263 | updateRequestToString(mUpdateRequest)); |
Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 1264 | throw new ImsException("Call update is in progress", |
| 1265 | ImsReasonInfo.CODE_LOCAL_ILLEGAL_STATE); |
| 1266 | } |
| 1267 | |
| 1268 | if (mSession == null) { |
Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 1269 | throw new ImsException("No call session", |
| 1270 | ImsReasonInfo.CODE_LOCAL_CALL_TERMINATED); |
| 1271 | } |
| 1272 | |
| 1273 | mSession.hold(createHoldMediaProfile()); |
Anthony Lee | 6804851 | 2015-03-18 15:04:18 -0700 | [diff] [blame] | 1274 | // FIXME: We should update the state on the callback because that is where |
| 1275 | // we can confirm that the hold request was successful or not. |
Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 1276 | mHold = true; |
| 1277 | mUpdateRequest = UPDATE_HOLD; |
| 1278 | } |
| 1279 | } |
| 1280 | |
| 1281 | /** |
| 1282 | * Continues a call that's on hold. When succeeds, {@link Listener#onCallResumed} is called. |
| 1283 | * |
| 1284 | * @see Listener#onCallResumed, Listener#onCallResumeFailed |
| 1285 | * @throws ImsException if the IMS service fails to resume the call |
| 1286 | */ |
| 1287 | public void resume() throws ImsException { |
Anthony Lee | 6804851 | 2015-03-18 15:04:18 -0700 | [diff] [blame] | 1288 | logi("resume :: "); |
Etan Cohen | 111eecc | 2014-09-10 17:18:12 -0700 | [diff] [blame] | 1289 | |
Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 1290 | if (!isOnHold()) { |
| 1291 | if (DBG) { |
Anthony Lee | 6804851 | 2015-03-18 15:04:18 -0700 | [diff] [blame] | 1292 | logi("resume :: call is not being held"); |
Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 1293 | } |
| 1294 | return; |
| 1295 | } |
| 1296 | |
| 1297 | synchronized(mLockObj) { |
| 1298 | if (mUpdateRequest != UPDATE_NONE) { |
Tyler Gunn | 9bd5ca5 | 2014-12-02 09:21:01 -0800 | [diff] [blame] | 1299 | loge("resume :: update is in progress; request=" + |
| 1300 | updateRequestToString(mUpdateRequest)); |
Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 1301 | throw new ImsException("Call update is in progress", |
| 1302 | ImsReasonInfo.CODE_LOCAL_ILLEGAL_STATE); |
| 1303 | } |
| 1304 | |
| 1305 | if (mSession == null) { |
| 1306 | loge("resume :: "); |
| 1307 | throw new ImsException("No call session", |
| 1308 | ImsReasonInfo.CODE_LOCAL_CALL_TERMINATED); |
| 1309 | } |
| 1310 | |
Anthony Lee | c479f66 | 2015-02-11 17:04:35 -0800 | [diff] [blame] | 1311 | // mHold is set to false in confirmation callback that the |
| 1312 | // ImsCall was resumed. |
Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 1313 | mUpdateRequest = UPDATE_RESUME; |
Anthony Lee | c479f66 | 2015-02-11 17:04:35 -0800 | [diff] [blame] | 1314 | mSession.resume(createResumeMediaProfile()); |
Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 1315 | } |
| 1316 | } |
| 1317 | |
| 1318 | /** |
| 1319 | * Merges the active & hold call. |
| 1320 | * |
| 1321 | * @see Listener#onCallMerged, Listener#onCallMergeFailed |
| 1322 | * @throws ImsException if the IMS service fails to merge the call |
| 1323 | */ |
Tyler Gunn | 047d810 | 2015-01-30 15:21:11 -0800 | [diff] [blame] | 1324 | private void merge() throws ImsException { |
Anthony Lee | 6804851 | 2015-03-18 15:04:18 -0700 | [diff] [blame] | 1325 | logi("merge :: "); |
Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 1326 | |
| 1327 | synchronized(mLockObj) { |
Tyler Gunn | c7ff7ee | 2017-09-06 14:38:37 -0700 | [diff] [blame] | 1328 | // If the host of the merge is in the midst of some other operation, we cannot merge. |
Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 1329 | if (mUpdateRequest != UPDATE_NONE) { |
Tyler Gunn | c7ff7ee | 2017-09-06 14:38:37 -0700 | [diff] [blame] | 1330 | setCallSessionMergePending(false); |
| 1331 | if (mMergePeer != null) { |
| 1332 | mMergePeer.setCallSessionMergePending(false); |
| 1333 | } |
Tyler Gunn | 9bd5ca5 | 2014-12-02 09:21:01 -0800 | [diff] [blame] | 1334 | loge("merge :: update is in progress; request=" + |
| 1335 | updateRequestToString(mUpdateRequest)); |
Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 1336 | throw new ImsException("Call update is in progress", |
| 1337 | ImsReasonInfo.CODE_LOCAL_ILLEGAL_STATE); |
| 1338 | } |
| 1339 | |
Tyler Gunn | c7ff7ee | 2017-09-06 14:38:37 -0700 | [diff] [blame] | 1340 | // The peer of the merge is in the midst of some other operation, we cannot merge. |
| 1341 | if (mMergePeer != null && mMergePeer.mUpdateRequest != UPDATE_NONE) { |
| 1342 | setCallSessionMergePending(false); |
| 1343 | mMergePeer.setCallSessionMergePending(false); |
| 1344 | loge("merge :: peer call update is in progress; request=" + |
| 1345 | updateRequestToString(mMergePeer.mUpdateRequest)); |
| 1346 | throw new ImsException("Peer call update is in progress", |
| 1347 | ImsReasonInfo.CODE_LOCAL_ILLEGAL_STATE); |
| 1348 | } |
| 1349 | |
Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 1350 | if (mSession == null) { |
Anthony Lee | c479f66 | 2015-02-11 17:04:35 -0800 | [diff] [blame] | 1351 | loge("merge :: no call session"); |
Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 1352 | throw new ImsException("No call session", |
| 1353 | ImsReasonInfo.CODE_LOCAL_CALL_TERMINATED); |
| 1354 | } |
| 1355 | |
Uma Maheswari Ramalingam | ca45f58 | 2014-05-19 12:32:20 -0700 | [diff] [blame] | 1356 | // if skipHoldBeforeMerge = true, IMS service implementation will |
| 1357 | // merge without explicitly holding the call. |
| 1358 | if (mHold || (mContext.getResources().getBoolean( |
| 1359 | com.android.internal.R.bool.skipHoldBeforeMerge))) { |
Anthony Lee | b8799fe | 2014-11-03 15:13:47 -0800 | [diff] [blame] | 1360 | |
Tyler Gunn | 9bd5ca5 | 2014-12-02 09:21:01 -0800 | [diff] [blame] | 1361 | if (mMergePeer != null && !mMergePeer.isMultiparty() && !isMultiparty()) { |
| 1362 | // We only set UPDATE_MERGE when we are adding the first |
| 1363 | // calls to the Conference. If there is already a conference |
Tyler Gunn | 047d810 | 2015-01-30 15:21:11 -0800 | [diff] [blame] | 1364 | // no special handling is needed. The existing conference |
Tyler Gunn | 9bd5ca5 | 2014-12-02 09:21:01 -0800 | [diff] [blame] | 1365 | // session will just go active and any other sessions will be terminated |
| 1366 | // if needed. There will be no merge failed callback. |
Tyler Gunn | 047d810 | 2015-01-30 15:21:11 -0800 | [diff] [blame] | 1367 | // Mark both the host and peer UPDATE_MERGE to ensure both are aware that a |
| 1368 | // merge is pending. |
Tyler Gunn | 9bd5ca5 | 2014-12-02 09:21:01 -0800 | [diff] [blame] | 1369 | mUpdateRequest = UPDATE_MERGE; |
Tyler Gunn | 047d810 | 2015-01-30 15:21:11 -0800 | [diff] [blame] | 1370 | mMergePeer.mUpdateRequest = UPDATE_MERGE; |
Anthony Lee | b8799fe | 2014-11-03 15:13:47 -0800 | [diff] [blame] | 1371 | } |
Tyler Gunn | 9bd5ca5 | 2014-12-02 09:21:01 -0800 | [diff] [blame] | 1372 | |
| 1373 | mSession.merge(); |
Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 1374 | } else { |
Anthony Lee | 7138269 | 2014-10-30 10:50:10 -0700 | [diff] [blame] | 1375 | // This code basically says, we need to explicitly hold before requesting a merge |
| 1376 | // when we get the callback that the hold was successful (or failed), we should |
| 1377 | // automatically request a merge. |
Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 1378 | mSession.hold(createHoldMediaProfile()); |
Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 1379 | mHold = true; |
| 1380 | mUpdateRequest = UPDATE_HOLD_MERGE; |
| 1381 | } |
| 1382 | } |
| 1383 | } |
| 1384 | |
| 1385 | /** |
| 1386 | * Merges the active & hold call. |
| 1387 | * |
| 1388 | * @param bgCall the background (holding) call |
| 1389 | * @see Listener#onCallMerged, Listener#onCallMergeFailed |
| 1390 | * @throws ImsException if the IMS service fails to merge the call |
| 1391 | */ |
| 1392 | public void merge(ImsCall bgCall) throws ImsException { |
Anthony Lee | 6804851 | 2015-03-18 15:04:18 -0700 | [diff] [blame] | 1393 | logi("merge(1) :: bgImsCall=" + bgCall); |
Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 1394 | |
| 1395 | if (bgCall == null) { |
| 1396 | throw new ImsException("No background call", |
| 1397 | ImsReasonInfo.CODE_LOCAL_ILLEGAL_ARGUMENT); |
| 1398 | } |
| 1399 | |
| 1400 | synchronized(mLockObj) { |
Tyler Gunn | 047d810 | 2015-01-30 15:21:11 -0800 | [diff] [blame] | 1401 | // Mark both sessions as pending merge. |
| 1402 | this.setCallSessionMergePending(true); |
| 1403 | bgCall.setCallSessionMergePending(true); |
| 1404 | |
Tyler Gunn | 87466c5 | 2014-12-08 09:56:17 -0800 | [diff] [blame] | 1405 | if ((!isMultiparty() && !bgCall.isMultiparty()) || isMultiparty()) { |
| 1406 | // If neither call is multiparty, the current call is the merge host and the bg call |
| 1407 | // is the merge peer (ie we're starting a new conference). |
| 1408 | // OR |
| 1409 | // If this call is multiparty, it is the merge host and the other call is the merge |
| 1410 | // peer. |
| 1411 | setMergePeer(bgCall); |
| 1412 | } else { |
| 1413 | // If the bg call is multiparty, it is the merge host. |
| 1414 | setMergeHost(bgCall); |
| 1415 | } |
Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 1416 | } |
Uma Maheswari Ramalingam | a1ed7b0 | 2015-05-20 14:26:42 -0700 | [diff] [blame] | 1417 | |
Uma Maheswari Ramalingam | 95be7c6 | 2015-05-06 23:08:17 -0700 | [diff] [blame] | 1418 | if (isMultiparty()) { |
| 1419 | mMergeRequestedByConference = true; |
| 1420 | } else { |
| 1421 | logi("merge : mMergeRequestedByConference not set"); |
| 1422 | } |
Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 1423 | merge(); |
| 1424 | } |
| 1425 | |
| 1426 | /** |
| 1427 | * Updates the current call's properties (ex. call mode change: video upgrade / downgrade). |
| 1428 | */ |
| 1429 | public void update(int callType, ImsStreamMediaProfile mediaProfile) throws ImsException { |
Anthony Lee | 6804851 | 2015-03-18 15:04:18 -0700 | [diff] [blame] | 1430 | logi("update :: callType=" + callType + ", mediaProfile=" + mediaProfile); |
Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 1431 | |
| 1432 | if (isOnHold()) { |
| 1433 | if (DBG) { |
Anthony Lee | 6804851 | 2015-03-18 15:04:18 -0700 | [diff] [blame] | 1434 | logi("update :: call is on hold"); |
Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 1435 | } |
| 1436 | throw new ImsException("Not in a call to update call", |
| 1437 | ImsReasonInfo.CODE_LOCAL_ILLEGAL_STATE); |
| 1438 | } |
| 1439 | |
| 1440 | synchronized(mLockObj) { |
| 1441 | if (mUpdateRequest != UPDATE_NONE) { |
| 1442 | if (DBG) { |
Anthony Lee | 6804851 | 2015-03-18 15:04:18 -0700 | [diff] [blame] | 1443 | logi("update :: update is in progress; request=" + |
Tyler Gunn | 9bd5ca5 | 2014-12-02 09:21:01 -0800 | [diff] [blame] | 1444 | updateRequestToString(mUpdateRequest)); |
Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 1445 | } |
| 1446 | throw new ImsException("Call update is in progress", |
| 1447 | ImsReasonInfo.CODE_LOCAL_ILLEGAL_STATE); |
| 1448 | } |
| 1449 | |
| 1450 | if (mSession == null) { |
| 1451 | loge("update :: "); |
| 1452 | throw new ImsException("No call session", |
| 1453 | ImsReasonInfo.CODE_LOCAL_CALL_TERMINATED); |
| 1454 | } |
| 1455 | |
| 1456 | mSession.update(callType, mediaProfile); |
| 1457 | mUpdateRequest = UPDATE_UNSPECIFIED; |
| 1458 | } |
| 1459 | } |
| 1460 | |
| 1461 | /** |
| 1462 | * Extends this call (1-to-1 call) to the conference call |
| 1463 | * inviting the specified participants to. |
| 1464 | * |
| 1465 | */ |
| 1466 | public void extendToConference(String[] participants) throws ImsException { |
Anthony Lee | 6804851 | 2015-03-18 15:04:18 -0700 | [diff] [blame] | 1467 | logi("extendToConference ::"); |
Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 1468 | |
| 1469 | if (isOnHold()) { |
| 1470 | if (DBG) { |
Anthony Lee | 6804851 | 2015-03-18 15:04:18 -0700 | [diff] [blame] | 1471 | logi("extendToConference :: call is on hold"); |
Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 1472 | } |
| 1473 | throw new ImsException("Not in a call to extend a call to conference", |
| 1474 | ImsReasonInfo.CODE_LOCAL_ILLEGAL_STATE); |
| 1475 | } |
| 1476 | |
| 1477 | synchronized(mLockObj) { |
| 1478 | if (mUpdateRequest != UPDATE_NONE) { |
Anthony Lee | 6804851 | 2015-03-18 15:04:18 -0700 | [diff] [blame] | 1479 | if (CONF_DBG) { |
| 1480 | logi("extendToConference :: update is in progress; request=" + |
Tyler Gunn | 9bd5ca5 | 2014-12-02 09:21:01 -0800 | [diff] [blame] | 1481 | updateRequestToString(mUpdateRequest)); |
Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 1482 | } |
| 1483 | throw new ImsException("Call update is in progress", |
| 1484 | ImsReasonInfo.CODE_LOCAL_ILLEGAL_STATE); |
| 1485 | } |
| 1486 | |
| 1487 | if (mSession == null) { |
| 1488 | loge("extendToConference :: "); |
| 1489 | throw new ImsException("No call session", |
| 1490 | ImsReasonInfo.CODE_LOCAL_CALL_TERMINATED); |
| 1491 | } |
| 1492 | |
| 1493 | mSession.extendToConference(participants); |
| 1494 | mUpdateRequest = UPDATE_EXTEND_TO_CONFERENCE; |
| 1495 | } |
| 1496 | } |
| 1497 | |
| 1498 | /** |
| 1499 | * Requests the conference server to invite an additional participants to the conference. |
| 1500 | * |
| 1501 | */ |
| 1502 | public void inviteParticipants(String[] participants) throws ImsException { |
Anthony Lee | 6804851 | 2015-03-18 15:04:18 -0700 | [diff] [blame] | 1503 | logi("inviteParticipants ::"); |
Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 1504 | |
| 1505 | synchronized(mLockObj) { |
| 1506 | if (mSession == null) { |
| 1507 | loge("inviteParticipants :: "); |
| 1508 | throw new ImsException("No call session", |
| 1509 | ImsReasonInfo.CODE_LOCAL_CALL_TERMINATED); |
| 1510 | } |
| 1511 | |
| 1512 | mSession.inviteParticipants(participants); |
| 1513 | } |
| 1514 | } |
| 1515 | |
| 1516 | /** |
| 1517 | * Requests the conference server to remove the specified participants from the conference. |
| 1518 | * |
| 1519 | */ |
| 1520 | public void removeParticipants(String[] participants) throws ImsException { |
Uma Maheswari Ramalingam | a1ed7b0 | 2015-05-20 14:26:42 -0700 | [diff] [blame] | 1521 | logi("removeParticipants :: session=" + mSession); |
Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 1522 | synchronized(mLockObj) { |
| 1523 | if (mSession == null) { |
| 1524 | loge("removeParticipants :: "); |
| 1525 | throw new ImsException("No call session", |
| 1526 | ImsReasonInfo.CODE_LOCAL_CALL_TERMINATED); |
| 1527 | } |
| 1528 | |
| 1529 | mSession.removeParticipants(participants); |
Uma Maheswari Ramalingam | a1ed7b0 | 2015-05-20 14:26:42 -0700 | [diff] [blame] | 1530 | |
Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 1531 | } |
| 1532 | } |
| 1533 | |
Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 1534 | /** |
| 1535 | * Sends a DTMF code. According to <a href="http://tools.ietf.org/html/rfc2833">RFC 2833</a>, |
| 1536 | * event 0 ~ 9 maps to decimal value 0 ~ 9, '*' to 10, '#' to 11, event 'A' ~ 'D' to 12 ~ 15, |
| 1537 | * and event flash to 16. Currently, event flash is not supported. |
| 1538 | * |
Libin.Tang@motorola.com | 2f92daf | 2014-08-23 18:08:31 -0500 | [diff] [blame] | 1539 | * @param c that represents the DTMF to send. '0' ~ '9', 'A' ~ 'D', '*', '#' are valid inputs. |
| 1540 | * @param result the result message to send when done. |
Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 1541 | */ |
Libin.Tang@motorola.com | 2f92daf | 2014-08-23 18:08:31 -0500 | [diff] [blame] | 1542 | public void sendDtmf(char c, Message result) { |
Anthony Lee | 6804851 | 2015-03-18 15:04:18 -0700 | [diff] [blame] | 1543 | logi("sendDtmf :: code=" + c); |
Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 1544 | |
| 1545 | synchronized(mLockObj) { |
| 1546 | if (mSession != null) { |
Andrew Lee | a4710d5 | 2014-12-09 14:51:53 -0800 | [diff] [blame] | 1547 | mSession.sendDtmf(c, result); |
Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 1548 | } |
| 1549 | } |
Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 1550 | } |
| 1551 | |
| 1552 | /** |
Uma Maheswari Ramalingam | a6fbae9 | 2014-12-05 16:40:46 -0800 | [diff] [blame] | 1553 | * Start a DTMF code. According to <a href="http://tools.ietf.org/html/rfc2833">RFC 2833</a>, |
| 1554 | * event 0 ~ 9 maps to decimal value 0 ~ 9, '*' to 10, '#' to 11, event 'A' ~ 'D' to 12 ~ 15, |
| 1555 | * and event flash to 16. Currently, event flash is not supported. |
| 1556 | * |
| 1557 | * @param c that represents the DTMF to send. '0' ~ '9', 'A' ~ 'D', '*', '#' are valid inputs. |
| 1558 | */ |
| 1559 | public void startDtmf(char c) { |
Anthony Lee | 6804851 | 2015-03-18 15:04:18 -0700 | [diff] [blame] | 1560 | logi("startDtmf :: code=" + c); |
Uma Maheswari Ramalingam | a6fbae9 | 2014-12-05 16:40:46 -0800 | [diff] [blame] | 1561 | |
| 1562 | synchronized(mLockObj) { |
| 1563 | if (mSession != null) { |
| 1564 | mSession.startDtmf(c); |
| 1565 | } |
| 1566 | } |
| 1567 | } |
| 1568 | |
| 1569 | /** |
| 1570 | * Stop a DTMF code. |
| 1571 | */ |
| 1572 | public void stopDtmf() { |
Anthony Lee | 6804851 | 2015-03-18 15:04:18 -0700 | [diff] [blame] | 1573 | logi("stopDtmf :: "); |
Uma Maheswari Ramalingam | a6fbae9 | 2014-12-05 16:40:46 -0800 | [diff] [blame] | 1574 | |
| 1575 | synchronized(mLockObj) { |
| 1576 | if (mSession != null) { |
| 1577 | mSession.stopDtmf(); |
| 1578 | } |
| 1579 | } |
| 1580 | } |
| 1581 | |
| 1582 | /** |
Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 1583 | * Sends an USSD message. |
| 1584 | * |
| 1585 | * @param ussdMessage USSD message to send |
| 1586 | */ |
| 1587 | public void sendUssd(String ussdMessage) throws ImsException { |
Anthony Lee | 6804851 | 2015-03-18 15:04:18 -0700 | [diff] [blame] | 1588 | logi("sendUssd :: ussdMessage=" + ussdMessage); |
Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 1589 | |
| 1590 | synchronized(mLockObj) { |
| 1591 | if (mSession == null) { |
| 1592 | loge("sendUssd :: "); |
| 1593 | throw new ImsException("No call session", |
| 1594 | ImsReasonInfo.CODE_LOCAL_CALL_TERMINATED); |
| 1595 | } |
| 1596 | |
| 1597 | mSession.sendUssd(ussdMessage); |
| 1598 | } |
| 1599 | } |
| 1600 | |
Hall Liu | bd3f377 | 2017-03-22 15:38:23 -0700 | [diff] [blame] | 1601 | public void sendRttMessage(String rttMessage) { |
| 1602 | synchronized(mLockObj) { |
| 1603 | if (mSession == null) { |
| 1604 | loge("sendRttMessage::no session"); |
| 1605 | } |
| 1606 | if (!mCallProfile.mMediaProfile.isRttCall()) { |
| 1607 | logi("sendRttMessage::Not an rtt call, ignoring"); |
| 1608 | return; |
| 1609 | } |
| 1610 | mSession.sendRttMessage(rttMessage); |
| 1611 | } |
| 1612 | } |
| 1613 | |
| 1614 | /** |
| 1615 | * Sends a user-requested RTT upgrade request. |
| 1616 | */ |
| 1617 | public void sendRttModifyRequest() { |
| 1618 | logi("sendRttModifyRequest"); |
| 1619 | |
| 1620 | synchronized(mLockObj) { |
| 1621 | if (mSession == null) { |
| 1622 | loge("sendRttModifyRequest::no session"); |
| 1623 | } |
| 1624 | if (mCallProfile.mMediaProfile.isRttCall()) { |
| 1625 | logi("sendRttModifyRequest::Already RTT call, ignoring."); |
| 1626 | return; |
| 1627 | } |
| 1628 | // Make a copy of the current ImsCallProfile and modify it to enable RTT |
| 1629 | Parcel p = Parcel.obtain(); |
| 1630 | mCallProfile.writeToParcel(p, 0); |
Hall Liu | b77d897 | 2018-01-22 19:15:05 -0800 | [diff] [blame^] | 1631 | p.setDataPosition(0); |
Hall Liu | bd3f377 | 2017-03-22 15:38:23 -0700 | [diff] [blame] | 1632 | ImsCallProfile requestedProfile = new ImsCallProfile(p); |
| 1633 | requestedProfile.mMediaProfile.setRttMode(ImsStreamMediaProfile.RTT_MODE_FULL); |
| 1634 | |
| 1635 | mSession.sendRttModifyRequest(requestedProfile); |
| 1636 | } |
| 1637 | } |
| 1638 | |
| 1639 | /** |
| 1640 | * Sends the user's response to a remotely-issued RTT upgrade request |
| 1641 | * |
| 1642 | * @param textStream A valid {@link Connection.RttTextStream} if the user |
| 1643 | * accepts, {@code null} if not. |
| 1644 | */ |
| 1645 | public void sendRttModifyResponse(boolean status) { |
| 1646 | logi("sendRttModifyResponse"); |
| 1647 | |
| 1648 | synchronized(mLockObj) { |
| 1649 | if (mSession == null) { |
| 1650 | loge("sendRttModifyResponse::no session"); |
| 1651 | } |
| 1652 | if (mCallProfile.mMediaProfile.isRttCall()) { |
| 1653 | logi("sendRttModifyResponse::Already RTT call, ignoring."); |
| 1654 | return; |
| 1655 | } |
| 1656 | mSession.sendRttModifyResponse(status); |
| 1657 | } |
| 1658 | } |
| 1659 | |
Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 1660 | private void clear(ImsReasonInfo lastReasonInfo) { |
| 1661 | mInCall = false; |
| 1662 | mHold = false; |
| 1663 | mUpdateRequest = UPDATE_NONE; |
| 1664 | mLastReasonInfo = lastReasonInfo; |
Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 1665 | } |
| 1666 | |
| 1667 | /** |
| 1668 | * Creates an IMS call session listener. |
| 1669 | */ |
| 1670 | private ImsCallSession.Listener createCallSessionListener() { |
Tyler Gunn | afb53c8 | 2016-08-05 14:38:13 -0700 | [diff] [blame] | 1671 | mImsCallSessionListenerProxy = new ImsCallSessionListenerProxy(); |
| 1672 | return mImsCallSessionListenerProxy; |
| 1673 | } |
| 1674 | |
| 1675 | /** |
| 1676 | * @return the current ImsCallSessionListenerProxy. NOTE: ONLY FOR USE WITH TESTING. |
| 1677 | */ |
| 1678 | @VisibleForTesting |
| 1679 | public ImsCallSessionListenerProxy getImsCallSessionListenerProxy() { |
| 1680 | return mImsCallSessionListenerProxy; |
Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 1681 | } |
| 1682 | |
| 1683 | private ImsCall createNewCall(ImsCallSession session, ImsCallProfile profile) { |
| 1684 | ImsCall call = new ImsCall(mContext, profile); |
| 1685 | |
| 1686 | try { |
| 1687 | call.attachSession(session); |
| 1688 | } catch (ImsException e) { |
| 1689 | if (call != null) { |
| 1690 | call.close(); |
| 1691 | call = null; |
| 1692 | } |
| 1693 | } |
| 1694 | |
| 1695 | // Do additional operations... |
| 1696 | |
| 1697 | return call; |
| 1698 | } |
| 1699 | |
| 1700 | private ImsStreamMediaProfile createHoldMediaProfile() { |
| 1701 | ImsStreamMediaProfile mediaProfile = new ImsStreamMediaProfile(); |
| 1702 | |
| 1703 | if (mCallProfile == null) { |
| 1704 | return mediaProfile; |
| 1705 | } |
| 1706 | |
| 1707 | mediaProfile.mAudioQuality = mCallProfile.mMediaProfile.mAudioQuality; |
| 1708 | mediaProfile.mVideoQuality = mCallProfile.mMediaProfile.mVideoQuality; |
| 1709 | mediaProfile.mAudioDirection = ImsStreamMediaProfile.DIRECTION_SEND; |
| 1710 | |
| 1711 | if (mediaProfile.mVideoQuality != ImsStreamMediaProfile.VIDEO_QUALITY_NONE) { |
| 1712 | mediaProfile.mVideoDirection = ImsStreamMediaProfile.DIRECTION_SEND; |
| 1713 | } |
| 1714 | |
| 1715 | return mediaProfile; |
| 1716 | } |
| 1717 | |
| 1718 | private ImsStreamMediaProfile createResumeMediaProfile() { |
| 1719 | ImsStreamMediaProfile mediaProfile = new ImsStreamMediaProfile(); |
| 1720 | |
| 1721 | if (mCallProfile == null) { |
| 1722 | return mediaProfile; |
| 1723 | } |
| 1724 | |
| 1725 | mediaProfile.mAudioQuality = mCallProfile.mMediaProfile.mAudioQuality; |
| 1726 | mediaProfile.mVideoQuality = mCallProfile.mMediaProfile.mVideoQuality; |
| 1727 | mediaProfile.mAudioDirection = ImsStreamMediaProfile.DIRECTION_SEND_RECEIVE; |
| 1728 | |
| 1729 | if (mediaProfile.mVideoQuality != ImsStreamMediaProfile.VIDEO_QUALITY_NONE) { |
| 1730 | mediaProfile.mVideoDirection = ImsStreamMediaProfile.DIRECTION_SEND_RECEIVE; |
| 1731 | } |
| 1732 | |
| 1733 | return mediaProfile; |
| 1734 | } |
| 1735 | |
| 1736 | private void enforceConversationMode() { |
| 1737 | if (mInCall) { |
| 1738 | mHold = false; |
| 1739 | mUpdateRequest = UPDATE_NONE; |
| 1740 | } |
| 1741 | } |
| 1742 | |
| 1743 | private void mergeInternal() { |
Anthony Lee | 6804851 | 2015-03-18 15:04:18 -0700 | [diff] [blame] | 1744 | if (CONF_DBG) { |
| 1745 | logi("mergeInternal :: "); |
Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 1746 | } |
| 1747 | |
| 1748 | mSession.merge(); |
| 1749 | mUpdateRequest = UPDATE_MERGE; |
| 1750 | } |
| 1751 | |
Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 1752 | private void notifyConferenceSessionTerminated(ImsReasonInfo reasonInfo) { |
Tyler Gunn | 9bd5ca5 | 2014-12-02 09:21:01 -0800 | [diff] [blame] | 1753 | ImsCall.Listener listener = mListener; |
Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 1754 | clear(reasonInfo); |
| 1755 | |
| 1756 | if (listener != null) { |
| 1757 | try { |
| 1758 | listener.onCallTerminated(this, reasonInfo); |
| 1759 | } catch (Throwable t) { |
| 1760 | loge("notifyConferenceSessionTerminated :: ", t); |
| 1761 | } |
| 1762 | } |
| 1763 | } |
| 1764 | |
| 1765 | private void notifyConferenceStateUpdated(ImsConferenceState state) { |
Tyler Gunn | 9e3452a | 2015-09-08 13:10:14 -0700 | [diff] [blame] | 1766 | if (state == null || state.mParticipants == null) { |
| 1767 | return; |
| 1768 | } |
| 1769 | |
Tyler Gunn | 1c46760 | 2014-11-04 14:51:52 -0800 | [diff] [blame] | 1770 | Set<Entry<String, Bundle>> participants = state.mParticipants.entrySet(); |
Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 1771 | |
Tyler Gunn | 1c46760 | 2014-11-04 14:51:52 -0800 | [diff] [blame] | 1772 | if (participants == null) { |
Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 1773 | return; |
| 1774 | } |
| 1775 | |
Tyler Gunn | 1c46760 | 2014-11-04 14:51:52 -0800 | [diff] [blame] | 1776 | Iterator<Entry<String, Bundle>> iterator = participants.iterator(); |
Uma Maheswari Ramalingam | a1ed7b0 | 2015-05-20 14:26:42 -0700 | [diff] [blame] | 1777 | mConferenceParticipants = new ArrayList<>(participants.size()); |
Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 1778 | while (iterator.hasNext()) { |
| 1779 | Entry<String, Bundle> entry = iterator.next(); |
| 1780 | |
| 1781 | String key = entry.getKey(); |
| 1782 | Bundle confInfo = entry.getValue(); |
| 1783 | String status = confInfo.getString(ImsConferenceState.STATUS); |
| 1784 | String user = confInfo.getString(ImsConferenceState.USER); |
Tyler Gunn | 5965614 | 2014-10-28 13:52:11 -0700 | [diff] [blame] | 1785 | String displayName = confInfo.getString(ImsConferenceState.DISPLAY_TEXT); |
Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 1786 | String endpoint = confInfo.getString(ImsConferenceState.ENDPOINT); |
| 1787 | |
Anthony Lee | 6804851 | 2015-03-18 15:04:18 -0700 | [diff] [blame] | 1788 | if (CONF_DBG) { |
Shunta Sakai | fb688ca | 2016-12-06 20:32:07 +0900 | [diff] [blame] | 1789 | logi("notifyConferenceStateUpdated :: key=" + Rlog.pii(TAG, key) + |
Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 1790 | ", status=" + status + |
Shunta Sakai | fb688ca | 2016-12-06 20:32:07 +0900 | [diff] [blame] | 1791 | ", user=" + Rlog.pii(TAG, user) + |
| 1792 | ", displayName= " + Rlog.pii(TAG, displayName) + |
Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 1793 | ", endpoint=" + endpoint); |
| 1794 | } |
| 1795 | |
Tyler Gunn | 9bd5ca5 | 2014-12-02 09:21:01 -0800 | [diff] [blame] | 1796 | Uri handle = Uri.parse(user); |
Uma Maheswari Ramalingam | a1ed7b0 | 2015-05-20 14:26:42 -0700 | [diff] [blame] | 1797 | if (endpoint == null) { |
| 1798 | endpoint = ""; |
| 1799 | } |
Tyler Gunn | 9bd5ca5 | 2014-12-02 09:21:01 -0800 | [diff] [blame] | 1800 | Uri endpointUri = Uri.parse(endpoint); |
| 1801 | int connectionState = ImsConferenceState.getConnectionStateForStatus(status); |
Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 1802 | |
Uma Maheswari Ramalingam | a1ed7b0 | 2015-05-20 14:26:42 -0700 | [diff] [blame] | 1803 | if (connectionState != Connection.STATE_DISCONNECTED) { |
| 1804 | ConferenceParticipant conferenceParticipant = new ConferenceParticipant(handle, |
| 1805 | displayName, endpointUri, connectionState); |
| 1806 | mConferenceParticipants.add(conferenceParticipant); |
| 1807 | } |
Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 1808 | } |
Tyler Gunn | 1c46760 | 2014-11-04 14:51:52 -0800 | [diff] [blame] | 1809 | |
Anju Mathapati | 0f10803 | 2015-10-09 15:34:28 -0700 | [diff] [blame] | 1810 | if (mConferenceParticipants != null && mListener != null) { |
Tyler Gunn | 1c46760 | 2014-11-04 14:51:52 -0800 | [diff] [blame] | 1811 | try { |
Uma Maheswari Ramalingam | a1ed7b0 | 2015-05-20 14:26:42 -0700 | [diff] [blame] | 1812 | mListener.onConferenceParticipantsStateChanged(this, mConferenceParticipants); |
Tyler Gunn | 1c46760 | 2014-11-04 14:51:52 -0800 | [diff] [blame] | 1813 | } catch (Throwable t) { |
| 1814 | loge("notifyConferenceStateUpdated :: ", t); |
| 1815 | } |
| 1816 | } |
Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 1817 | } |
| 1818 | |
Anthony Lee | b8799fe | 2014-11-03 15:13:47 -0800 | [diff] [blame] | 1819 | /** |
| 1820 | * Perform all cleanup and notification around the termination of a session. |
| 1821 | * Note that there are 2 distinct modes of operation. The first is when |
| 1822 | * we receive a session termination on the primary session when we are |
| 1823 | * in the processing of merging. The second is when we are not merging anything |
| 1824 | * and the call is terminated. |
| 1825 | * |
| 1826 | * @param reasonInfo The reason for the session termination |
| 1827 | */ |
| 1828 | private void processCallTerminated(ImsReasonInfo reasonInfo) { |
Tyler Gunn | 95d563e | 2015-07-23 09:28:58 -0700 | [diff] [blame] | 1829 | logi("processCallTerminated :: reason=" + reasonInfo + " userInitiated = " + |
| 1830 | mTerminationRequestPending); |
Anthony Lee | b8799fe | 2014-11-03 15:13:47 -0800 | [diff] [blame] | 1831 | |
| 1832 | ImsCall.Listener listener = null; |
Anthony Lee | b8799fe | 2014-11-03 15:13:47 -0800 | [diff] [blame] | 1833 | synchronized(ImsCall.this) { |
Tyler Gunn | 047d810 | 2015-01-30 15:21:11 -0800 | [diff] [blame] | 1834 | // If we are in the midst of establishing a conference, we will bury the termination |
Tyler Gunn | 95d563e | 2015-07-23 09:28:58 -0700 | [diff] [blame] | 1835 | // until the merge has completed. If necessary we can surface the termination at |
| 1836 | // this point. |
| 1837 | // We will also NOT bury the termination if a termination was initiated locally. |
| 1838 | if (isCallSessionMergePending() && !mTerminationRequestPending) { |
Anthony Lee | b8799fe | 2014-11-03 15:13:47 -0800 | [diff] [blame] | 1839 | // Since we are in the process of a merge, this trigger means something |
| 1840 | // else because it is probably due to the merge happening vs. the |
| 1841 | // session is really terminated. Let's flag this and revisit if |
| 1842 | // the merge() ends up failing because we will need to take action on the |
| 1843 | // mSession in that case since the termination was not due to the merge |
| 1844 | // succeeding. |
Anthony Lee | 6804851 | 2015-03-18 15:04:18 -0700 | [diff] [blame] | 1845 | if (CONF_DBG) { |
| 1846 | logi("processCallTerminated :: burying termination during ongoing merge."); |
Anthony Lee | b8799fe | 2014-11-03 15:13:47 -0800 | [diff] [blame] | 1847 | } |
| 1848 | mSessionEndDuringMerge = true; |
| 1849 | mSessionEndDuringMergeReasonInfo = reasonInfo; |
| 1850 | return; |
| 1851 | } |
| 1852 | |
Tyler Gunn | 9bd5ca5 | 2014-12-02 09:21:01 -0800 | [diff] [blame] | 1853 | // If we are terminating the conference call, notify using conference listeners. |
| 1854 | if (isMultiparty()) { |
Anthony Lee | b8799fe | 2014-11-03 15:13:47 -0800 | [diff] [blame] | 1855 | notifyConferenceSessionTerminated(reasonInfo); |
Tyler Gunn | 9bd5ca5 | 2014-12-02 09:21:01 -0800 | [diff] [blame] | 1856 | return; |
Anthony Lee | b8799fe | 2014-11-03 15:13:47 -0800 | [diff] [blame] | 1857 | } else { |
| 1858 | listener = mListener; |
| 1859 | clear(reasonInfo); |
| 1860 | } |
| 1861 | } |
| 1862 | |
| 1863 | if (listener != null) { |
| 1864 | try { |
| 1865 | listener.onCallTerminated(ImsCall.this, reasonInfo); |
| 1866 | } catch (Throwable t) { |
Anthony Lee | c479f66 | 2015-02-11 17:04:35 -0800 | [diff] [blame] | 1867 | loge("processCallTerminated :: ", t); |
Anthony Lee | b8799fe | 2014-11-03 15:13:47 -0800 | [diff] [blame] | 1868 | } |
| 1869 | } |
| 1870 | } |
Anthony Lee | 7138269 | 2014-10-30 10:50:10 -0700 | [diff] [blame] | 1871 | |
| 1872 | /** |
| 1873 | * This function determines if the ImsCallSession is our actual ImsCallSession or if is |
| 1874 | * the transient session used in the process of creating a conference. This function should only |
| 1875 | * be called within callbacks that are not directly related to conference merging but might |
| 1876 | * potentially still be called on the transient ImsCallSession sent to us from |
| 1877 | * callSessionMergeStarted() when we don't really care. In those situations, we probably don't |
| 1878 | * want to take any action so we need to know that we can return early. |
| 1879 | * |
| 1880 | * @param session - The {@link ImsCallSession} that the function needs to analyze |
| 1881 | * @return true if this is the transient {@link ImsCallSession}, false otherwise. |
| 1882 | */ |
| 1883 | private boolean isTransientConferenceSession(ImsCallSession session) { |
| 1884 | if (session != null && session != mSession && session == mTransientConferenceSession) { |
| 1885 | return true; |
| 1886 | } |
| 1887 | return false; |
| 1888 | } |
| 1889 | |
Anthony Lee | c479f66 | 2015-02-11 17:04:35 -0800 | [diff] [blame] | 1890 | private void setTransientSessionAsPrimary(ImsCallSession transientSession) { |
| 1891 | synchronized (ImsCall.this) { |
| 1892 | mSession.setListener(null); |
| 1893 | mSession = transientSession; |
| 1894 | mSession.setListener(createCallSessionListener()); |
| 1895 | } |
Tyler Gunn | 047d810 | 2015-01-30 15:21:11 -0800 | [diff] [blame] | 1896 | } |
| 1897 | |
Anju Mathapati | 818c09d | 2015-08-31 14:30:47 -0700 | [diff] [blame] | 1898 | private void markCallAsMerged(boolean playDisconnectTone) { |
| 1899 | if (!isSessionAlive(mSession)) { |
Uma Maheswari Ramalingam | 95be7c6 | 2015-05-06 23:08:17 -0700 | [diff] [blame] | 1900 | // If the peer is dead, let's not play a disconnect sound for it when we |
| 1901 | // unbury the termination callback. |
Anju Mathapati | 818c09d | 2015-08-31 14:30:47 -0700 | [diff] [blame] | 1902 | logi("markCallAsMerged"); |
| 1903 | setIsMerged(playDisconnectTone); |
| 1904 | mSessionEndDuringMerge = true; |
| 1905 | String reasonInfo; |
Jayachandran C | 96e2d85 | 2017-05-11 11:43:52 -0700 | [diff] [blame] | 1906 | int reasonCode = ImsReasonInfo.CODE_UNSPECIFIED; |
Anju Mathapati | 818c09d | 2015-08-31 14:30:47 -0700 | [diff] [blame] | 1907 | if (playDisconnectTone) { |
Jayachandran C | 96e2d85 | 2017-05-11 11:43:52 -0700 | [diff] [blame] | 1908 | reasonCode = ImsReasonInfo.CODE_USER_TERMINATED_BY_REMOTE; |
Anju Mathapati | 818c09d | 2015-08-31 14:30:47 -0700 | [diff] [blame] | 1909 | reasonInfo = "Call ended by network"; |
| 1910 | } else { |
Jayachandran C | 96e2d85 | 2017-05-11 11:43:52 -0700 | [diff] [blame] | 1911 | reasonCode = ImsReasonInfo.CODE_LOCAL_ENDED_BY_CONFERENCE_MERGE; |
Anju Mathapati | 818c09d | 2015-08-31 14:30:47 -0700 | [diff] [blame] | 1912 | reasonInfo = "Call ended during conference merge process."; |
| 1913 | } |
| 1914 | mSessionEndDuringMergeReasonInfo = new ImsReasonInfo( |
Jayachandran C | 96e2d85 | 2017-05-11 11:43:52 -0700 | [diff] [blame] | 1915 | reasonCode, 0, reasonInfo); |
Uma Maheswari Ramalingam | 95be7c6 | 2015-05-06 23:08:17 -0700 | [diff] [blame] | 1916 | } |
| 1917 | } |
| 1918 | |
Tyler Gunn | 047d810 | 2015-01-30 15:21:11 -0800 | [diff] [blame] | 1919 | /** |
Uma Maheswari Ramalingam | 95be7c6 | 2015-05-06 23:08:17 -0700 | [diff] [blame] | 1920 | * Checks if the merge was requested by foreground conference call |
| 1921 | * |
| 1922 | * @return true if the merge was requested by foreground conference call |
Anthony Lee | c479f66 | 2015-02-11 17:04:35 -0800 | [diff] [blame] | 1923 | */ |
Uma Maheswari Ramalingam | 95be7c6 | 2015-05-06 23:08:17 -0700 | [diff] [blame] | 1924 | public boolean isMergeRequestedByConf() { |
| 1925 | synchronized(mLockObj) { |
| 1926 | return mMergeRequestedByConference; |
| 1927 | } |
| 1928 | } |
| 1929 | |
| 1930 | /** |
| 1931 | * Resets the flag which indicates merge request was sent by |
| 1932 | * foreground conference call |
| 1933 | */ |
| 1934 | public void resetIsMergeRequestedByConf(boolean value) { |
| 1935 | synchronized(mLockObj) { |
| 1936 | mMergeRequestedByConference = value; |
| 1937 | } |
| 1938 | } |
| 1939 | |
| 1940 | /** |
| 1941 | * Returns current ImsCallSession |
| 1942 | * |
| 1943 | * @return current session |
| 1944 | */ |
| 1945 | public ImsCallSession getSession() { |
| 1946 | synchronized(mLockObj) { |
| 1947 | return mSession; |
Anthony Lee | c479f66 | 2015-02-11 17:04:35 -0800 | [diff] [blame] | 1948 | } |
| 1949 | } |
| 1950 | |
| 1951 | /** |
| 1952 | * We have detected that a initial conference call has been fully configured. The internal |
| 1953 | * state of both {@code ImsCall} objects need to be cleaned up to reflect the new state. |
| 1954 | * This function should only be called in the context of the merge host to simplify logic |
Anthony Lee | 7138269 | 2014-10-30 10:50:10 -0700 | [diff] [blame] | 1955 | * |
Anthony Lee | 7138269 | 2014-10-30 10:50:10 -0700 | [diff] [blame] | 1956 | */ |
Anthony Lee | b8799fe | 2014-11-03 15:13:47 -0800 | [diff] [blame] | 1957 | private void processMergeComplete() { |
Anthony Lee | 6804851 | 2015-03-18 15:04:18 -0700 | [diff] [blame] | 1958 | logi("processMergeComplete :: "); |
Anthony Lee | c479f66 | 2015-02-11 17:04:35 -0800 | [diff] [blame] | 1959 | |
| 1960 | // The logic simplifies if we can assume that this function is only called on |
| 1961 | // the merge host. |
| 1962 | if (!isMergeHost()) { |
| 1963 | loge("processMergeComplete :: We are not the merge host!"); |
| 1964 | return; |
Anthony Lee | b8799fe | 2014-11-03 15:13:47 -0800 | [diff] [blame] | 1965 | } |
| 1966 | |
Anthony Lee | 7138269 | 2014-10-30 10:50:10 -0700 | [diff] [blame] | 1967 | ImsCall.Listener listener; |
Tyler Gunn | 047d810 | 2015-01-30 15:21:11 -0800 | [diff] [blame] | 1968 | boolean swapRequired = false; |
Tyler Gunn | 047d810 | 2015-01-30 15:21:11 -0800 | [diff] [blame] | 1969 | |
Uma Maheswari Ramalingam | 95be7c6 | 2015-05-06 23:08:17 -0700 | [diff] [blame] | 1970 | ImsCall finalHostCall; |
| 1971 | ImsCall finalPeerCall; |
| 1972 | |
| 1973 | synchronized(ImsCall.this) { |
Anthony Lee | c479f66 | 2015-02-11 17:04:35 -0800 | [diff] [blame] | 1974 | if (isMultiparty()) { |
Anthony Lee | c479f66 | 2015-02-11 17:04:35 -0800 | [diff] [blame] | 1975 | setIsMerged(false); |
Uma Maheswari Ramalingam | 95be7c6 | 2015-05-06 23:08:17 -0700 | [diff] [blame] | 1976 | // if case handles Case 4 explained in callSessionMergeComplete |
| 1977 | // otherwise it is case 5 |
| 1978 | if (!mMergeRequestedByConference) { |
| 1979 | // single call in fg, conference call in bg. |
| 1980 | // Finally conf call becomes active after conference |
| 1981 | this.mHold = false; |
| 1982 | swapRequired = true; |
Tyler Gunn | 047d810 | 2015-01-30 15:21:11 -0800 | [diff] [blame] | 1983 | } |
Anju Mathapati | 818c09d | 2015-08-31 14:30:47 -0700 | [diff] [blame] | 1984 | mMergePeer.markCallAsMerged(false); |
Uma Maheswari Ramalingam | 95be7c6 | 2015-05-06 23:08:17 -0700 | [diff] [blame] | 1985 | finalHostCall = this; |
| 1986 | finalPeerCall = mMergePeer; |
Tyler Gunn | 047d810 | 2015-01-30 15:21:11 -0800 | [diff] [blame] | 1987 | } else { |
Anthony Lee | c479f66 | 2015-02-11 17:04:35 -0800 | [diff] [blame] | 1988 | // If we are here, we are not trying to merge a new call into an existing |
| 1989 | // conference. That means that there is a transient session on the merge |
| 1990 | // host that represents the future conference once all the parties |
| 1991 | // have been added to it. So make sure that it exists or else something |
| 1992 | // very wrong is going on. |
| 1993 | if (mTransientConferenceSession == null) { |
| 1994 | loge("processMergeComplete :: No transient session!"); |
| 1995 | return; |
Tyler Gunn | 047d810 | 2015-01-30 15:21:11 -0800 | [diff] [blame] | 1996 | } |
Anthony Lee | c479f66 | 2015-02-11 17:04:35 -0800 | [diff] [blame] | 1997 | if (mMergePeer == null) { |
| 1998 | loge("processMergeComplete :: No merge peer!"); |
| 1999 | return; |
Tyler Gunn | 047d810 | 2015-01-30 15:21:11 -0800 | [diff] [blame] | 2000 | } |
Tyler Gunn | 047d810 | 2015-01-30 15:21:11 -0800 | [diff] [blame] | 2001 | |
Anthony Lee | c479f66 | 2015-02-11 17:04:35 -0800 | [diff] [blame] | 2002 | // Since we are the host, we have the transient session attached to us. Let's detach |
| 2003 | // it and figure out where we need to set it for the final conference configuration. |
| 2004 | ImsCallSession transientConferenceSession = mTransientConferenceSession; |
| 2005 | mTransientConferenceSession = null; |
| 2006 | |
| 2007 | // Clear the listener for this transient session, we'll create a new listener |
| 2008 | // when it is attached to the final ImsCall that it should live on. |
| 2009 | transientConferenceSession.setListener(null); |
| 2010 | |
| 2011 | // Determine which call the transient session should be moved to. If the current |
| 2012 | // call session is still alive and the merge peer's session is not, we have a |
| 2013 | // situation where the current call failed to merge into the conference but the |
| 2014 | // merge peer did merge in to the conference. In this type of scenario the current |
| 2015 | // call will continue as a single party call, yet the background call will become |
| 2016 | // the conference. |
| 2017 | |
Uma Maheswari Ramalingam | 95be7c6 | 2015-05-06 23:08:17 -0700 | [diff] [blame] | 2018 | // handles Case 3 explained in callSessionMergeComplete |
Anthony Lee | c479f66 | 2015-02-11 17:04:35 -0800 | [diff] [blame] | 2019 | if (isSessionAlive(mSession) && !isSessionAlive(mMergePeer.getCallSession())) { |
| 2020 | // I'm the host but we are moving the transient session to the peer since its |
| 2021 | // session was disconnected and my session is still alive. This signifies that |
| 2022 | // their session was properly added to the conference but mine was not because |
| 2023 | // it is probably in the held state as opposed to part of the final conference. |
| 2024 | // In this case, we need to set isMerged to false on both calls so the |
| 2025 | // disconnect sound is called when either call disconnects. |
| 2026 | // Note that this case is only valid if this is an initial conference being |
| 2027 | // brought up. |
Uma Maheswari Ramalingam | 95be7c6 | 2015-05-06 23:08:17 -0700 | [diff] [blame] | 2028 | mMergePeer.mHold = false; |
| 2029 | this.mHold = true; |
Anju Mathapati | d0fb664 | 2015-07-22 13:55:57 -0700 | [diff] [blame] | 2030 | if (mConferenceParticipants != null && !mConferenceParticipants.isEmpty()) { |
| 2031 | mMergePeer.mConferenceParticipants = mConferenceParticipants; |
| 2032 | } |
| 2033 | // At this point both host & peer will have participant information. |
| 2034 | // Peer will transition to host & the participant information |
| 2035 | // from that will be used |
| 2036 | // HostCall that failed to merge will remain as a single call with |
| 2037 | // mConferenceParticipants, which should not be used. |
| 2038 | // Expectation is that if this call becomes part of a conference call in future, |
| 2039 | // mConferenceParticipants will be overriten with new CEP that is received. |
Anthony Lee | c479f66 | 2015-02-11 17:04:35 -0800 | [diff] [blame] | 2040 | finalHostCall = mMergePeer; |
| 2041 | finalPeerCall = this; |
| 2042 | swapRequired = true; |
| 2043 | setIsMerged(false); |
| 2044 | mMergePeer.setIsMerged(false); |
Anthony Lee | 6804851 | 2015-03-18 15:04:18 -0700 | [diff] [blame] | 2045 | if (CONF_DBG) { |
| 2046 | logi("processMergeComplete :: transient will transfer to merge peer"); |
Tyler Gunn | 047d810 | 2015-01-30 15:21:11 -0800 | [diff] [blame] | 2047 | } |
Anthony Lee | 6804851 | 2015-03-18 15:04:18 -0700 | [diff] [blame] | 2048 | } else if (!isSessionAlive(mSession) && |
| 2049 | isSessionAlive(mMergePeer.getCallSession())) { |
Uma Maheswari Ramalingam | 95be7c6 | 2015-05-06 23:08:17 -0700 | [diff] [blame] | 2050 | // Handles case 2 explained in callSessionMergeComplete |
Anthony Lee | c479f66 | 2015-02-11 17:04:35 -0800 | [diff] [blame] | 2051 | // The transient session stays with us and the disconnect sound should be played |
| 2052 | // when the merge peer eventually disconnects since it was not actually added to |
| 2053 | // the conference and is probably sitting in the held state. |
| 2054 | finalHostCall = this; |
| 2055 | finalPeerCall = mMergePeer; |
| 2056 | swapRequired = false; |
| 2057 | setIsMerged(false); |
| 2058 | mMergePeer.setIsMerged(false); // Play the disconnect sound |
Anthony Lee | 6804851 | 2015-03-18 15:04:18 -0700 | [diff] [blame] | 2059 | if (CONF_DBG) { |
| 2060 | logi("processMergeComplete :: transient will stay with the merge host"); |
Tyler Gunn | 047d810 | 2015-01-30 15:21:11 -0800 | [diff] [blame] | 2061 | } |
Anthony Lee | c479f66 | 2015-02-11 17:04:35 -0800 | [diff] [blame] | 2062 | } else { |
Uma Maheswari Ramalingam | 95be7c6 | 2015-05-06 23:08:17 -0700 | [diff] [blame] | 2063 | // Handles case 1 explained in callSessionMergeComplete |
Anthony Lee | c479f66 | 2015-02-11 17:04:35 -0800 | [diff] [blame] | 2064 | // The transient session stays with us and the disconnect sound should not be |
| 2065 | // played when we ripple up the disconnect for the merge peer because it was |
| 2066 | // only disconnected to be added to the conference. |
| 2067 | finalHostCall = this; |
| 2068 | finalPeerCall = mMergePeer; |
Anju Mathapati | 818c09d | 2015-08-31 14:30:47 -0700 | [diff] [blame] | 2069 | mMergePeer.markCallAsMerged(false); |
Anthony Lee | c479f66 | 2015-02-11 17:04:35 -0800 | [diff] [blame] | 2070 | swapRequired = false; |
| 2071 | setIsMerged(false); |
| 2072 | mMergePeer.setIsMerged(true); |
Anthony Lee | 6804851 | 2015-03-18 15:04:18 -0700 | [diff] [blame] | 2073 | if (CONF_DBG) { |
| 2074 | logi("processMergeComplete :: transient will stay with us (I'm the host)."); |
Anthony Lee | c479f66 | 2015-02-11 17:04:35 -0800 | [diff] [blame] | 2075 | } |
Tyler Gunn | 047d810 | 2015-01-30 15:21:11 -0800 | [diff] [blame] | 2076 | } |
Anthony Lee | c479f66 | 2015-02-11 17:04:35 -0800 | [diff] [blame] | 2077 | |
Anthony Lee | 6804851 | 2015-03-18 15:04:18 -0700 | [diff] [blame] | 2078 | if (CONF_DBG) { |
| 2079 | logi("processMergeComplete :: call=" + finalHostCall + " is the final host"); |
Anthony Lee | c479f66 | 2015-02-11 17:04:35 -0800 | [diff] [blame] | 2080 | } |
| 2081 | |
| 2082 | // Add the transient session to the ImsCall that ended up being the host for the |
| 2083 | // conference. |
| 2084 | finalHostCall.setTransientSessionAsPrimary(transientConferenceSession); |
Tyler Gunn | 047d810 | 2015-01-30 15:21:11 -0800 | [diff] [blame] | 2085 | } |
| 2086 | |
Anthony Lee | c479f66 | 2015-02-11 17:04:35 -0800 | [diff] [blame] | 2087 | listener = finalHostCall.mListener; |
Tyler Gunn | 047d810 | 2015-01-30 15:21:11 -0800 | [diff] [blame] | 2088 | |
Anju Mathapati | 1c10888 | 2015-11-17 18:59:24 +0530 | [diff] [blame] | 2089 | updateCallProfile(finalPeerCall); |
| 2090 | updateCallProfile(finalHostCall); |
| 2091 | |
Anthony Lee | c479f66 | 2015-02-11 17:04:35 -0800 | [diff] [blame] | 2092 | // Clear all the merge related flags. |
| 2093 | clearMergeInfo(); |
| 2094 | |
| 2095 | // For the final peer...let's bubble up any possible disconnects that we had |
| 2096 | // during the merge process |
| 2097 | finalPeerCall.notifySessionTerminatedDuringMerge(); |
| 2098 | // For the final host, let's just bury the disconnects that we my have received |
| 2099 | // during the merge process since we are now the host of the conference call. |
| 2100 | finalHostCall.clearSessionTerminationFlags(); |
Tyler Gunn | 2539409 | 2015-04-01 09:40:02 -0700 | [diff] [blame] | 2101 | |
| 2102 | // Keep track of the fact that merge host is the origin of a conference call in |
| 2103 | // progress. This is important so that we can later determine if a multiparty ImsCall |
| 2104 | // is multiparty because it was the origin of a conference call, or because it is a |
| 2105 | // member of a conference on another device. |
| 2106 | finalHostCall.mIsConferenceHost = true; |
Anthony Lee | 7138269 | 2014-10-30 10:50:10 -0700 | [diff] [blame] | 2107 | } |
| 2108 | if (listener != null) { |
| 2109 | try { |
Uma Maheswari Ramalingam | 95be7c6 | 2015-05-06 23:08:17 -0700 | [diff] [blame] | 2110 | // finalPeerCall will have the participant that was not merged and |
| 2111 | // it will be held state |
| 2112 | // if peer was merged successfully, finalPeerCall will be null |
| 2113 | listener.onCallMerged(finalHostCall, finalPeerCall, swapRequired); |
Anthony Lee | 7138269 | 2014-10-30 10:50:10 -0700 | [diff] [blame] | 2114 | } catch (Throwable t) { |
Anthony Lee | b8799fe | 2014-11-03 15:13:47 -0800 | [diff] [blame] | 2115 | loge("processMergeComplete :: ", t); |
Anthony Lee | 7138269 | 2014-10-30 10:50:10 -0700 | [diff] [blame] | 2116 | } |
Tyler Gunn | 6c0b0d0 | 2015-07-01 16:39:43 -0700 | [diff] [blame] | 2117 | if (mConferenceParticipants != null && !mConferenceParticipants.isEmpty()) { |
Uma Maheswari Ramalingam | a1ed7b0 | 2015-05-20 14:26:42 -0700 | [diff] [blame] | 2118 | try { |
Anju Mathapati | d0fb664 | 2015-07-22 13:55:57 -0700 | [diff] [blame] | 2119 | listener.onConferenceParticipantsStateChanged(finalHostCall, |
| 2120 | mConferenceParticipants); |
Uma Maheswari Ramalingam | a1ed7b0 | 2015-05-20 14:26:42 -0700 | [diff] [blame] | 2121 | } catch (Throwable t) { |
| 2122 | loge("processMergeComplete :: ", t); |
| 2123 | } |
| 2124 | } |
Anthony Lee | 7138269 | 2014-10-30 10:50:10 -0700 | [diff] [blame] | 2125 | } |
Anthony Lee | 7138269 | 2014-10-30 10:50:10 -0700 | [diff] [blame] | 2126 | return; |
| 2127 | } |
| 2128 | |
Anju Mathapati | 1c10888 | 2015-11-17 18:59:24 +0530 | [diff] [blame] | 2129 | private static void updateCallProfile(ImsCall call) { |
| 2130 | if (call != null) { |
| 2131 | call.updateCallProfile(); |
| 2132 | } |
| 2133 | } |
| 2134 | |
| 2135 | private void updateCallProfile() { |
| 2136 | synchronized (mLockObj) { |
| 2137 | if (mSession != null) { |
Tyler Gunn | 1ac2485 | 2016-06-22 10:04:23 -0700 | [diff] [blame] | 2138 | setCallProfile(mSession.getCallProfile()); |
Anju Mathapati | 1c10888 | 2015-11-17 18:59:24 +0530 | [diff] [blame] | 2139 | } |
| 2140 | } |
| 2141 | } |
| 2142 | |
Anthony Lee | 7138269 | 2014-10-30 10:50:10 -0700 | [diff] [blame] | 2143 | /** |
Tyler Gunn | 047d810 | 2015-01-30 15:21:11 -0800 | [diff] [blame] | 2144 | * Handles the case where the session has ended during a merge by reporting the termination |
| 2145 | * reason to listeners. |
| 2146 | */ |
| 2147 | private void notifySessionTerminatedDuringMerge() { |
| 2148 | ImsCall.Listener listener; |
| 2149 | boolean notifyFailure = false; |
| 2150 | ImsReasonInfo notifyFailureReasonInfo = null; |
| 2151 | |
| 2152 | synchronized(ImsCall.this) { |
| 2153 | listener = mListener; |
| 2154 | if (mSessionEndDuringMerge) { |
| 2155 | // Set some local variables that will send out a notification about a |
| 2156 | // previously buried termination callback for our primary session now that |
| 2157 | // we know that this is not due to the conference call merging successfully. |
Anthony Lee | 6804851 | 2015-03-18 15:04:18 -0700 | [diff] [blame] | 2158 | if (CONF_DBG) { |
| 2159 | logi("notifySessionTerminatedDuringMerge ::reporting terminate during merge"); |
Tyler Gunn | 047d810 | 2015-01-30 15:21:11 -0800 | [diff] [blame] | 2160 | } |
| 2161 | notifyFailure = true; |
| 2162 | notifyFailureReasonInfo = mSessionEndDuringMergeReasonInfo; |
| 2163 | } |
Anthony Lee | c479f66 | 2015-02-11 17:04:35 -0800 | [diff] [blame] | 2164 | clearSessionTerminationFlags(); |
Tyler Gunn | 047d810 | 2015-01-30 15:21:11 -0800 | [diff] [blame] | 2165 | } |
| 2166 | |
| 2167 | if (listener != null && notifyFailure) { |
| 2168 | try { |
| 2169 | processCallTerminated(notifyFailureReasonInfo); |
| 2170 | } catch (Throwable t) { |
| 2171 | loge("notifySessionTerminatedDuringMerge :: ", t); |
| 2172 | } |
| 2173 | } |
| 2174 | } |
| 2175 | |
Anthony Lee | c479f66 | 2015-02-11 17:04:35 -0800 | [diff] [blame] | 2176 | private void clearSessionTerminationFlags() { |
| 2177 | mSessionEndDuringMerge = false; |
| 2178 | mSessionEndDuringMergeReasonInfo = null; |
| 2179 | } |
| 2180 | |
Uma Maheswari Ramalingam | a1ed7b0 | 2015-05-20 14:26:42 -0700 | [diff] [blame] | 2181 | /** |
Anthony Lee | 7138269 | 2014-10-30 10:50:10 -0700 | [diff] [blame] | 2182 | * We received a callback from ImsCallSession that a merge failed. Clean up all |
Anthony Lee | c479f66 | 2015-02-11 17:04:35 -0800 | [diff] [blame] | 2183 | * internal state to represent this state change. The calling function is a callback |
| 2184 | * and should have been called on the session that was in the foreground |
| 2185 | * when merge() was originally called. It is assumed that this function will be called |
| 2186 | * on the merge host. |
Anthony Lee | 7138269 | 2014-10-30 10:50:10 -0700 | [diff] [blame] | 2187 | * |
Anthony Lee | 7138269 | 2014-10-30 10:50:10 -0700 | [diff] [blame] | 2188 | * @param reasonInfo The {@link ImsReasonInfo} why the merge failed. |
| 2189 | */ |
Anthony Lee | b8799fe | 2014-11-03 15:13:47 -0800 | [diff] [blame] | 2190 | private void processMergeFailed(ImsReasonInfo reasonInfo) { |
Anthony Lee | 6804851 | 2015-03-18 15:04:18 -0700 | [diff] [blame] | 2191 | logi("processMergeFailed :: reason=" + reasonInfo); |
Tyler Gunn | 047d810 | 2015-01-30 15:21:11 -0800 | [diff] [blame] | 2192 | |
| 2193 | ImsCall.Listener listener; |
Anthony Lee | 7138269 | 2014-10-30 10:50:10 -0700 | [diff] [blame] | 2194 | synchronized(ImsCall.this) { |
Anthony Lee | c479f66 | 2015-02-11 17:04:35 -0800 | [diff] [blame] | 2195 | // The logic simplifies if we can assume that this function is only called on |
| 2196 | // the merge host. |
| 2197 | if (!isMergeHost()) { |
| 2198 | loge("processMergeFailed :: We are not the merge host!"); |
| 2199 | return; |
| 2200 | } |
| 2201 | |
Anthony Lee | 61d41c1 | 2015-04-02 09:40:01 -0700 | [diff] [blame] | 2202 | // Try to clean up the transient session if it exists. |
| 2203 | if (mTransientConferenceSession != null) { |
Anthony Lee | 7138269 | 2014-10-30 10:50:10 -0700 | [diff] [blame] | 2204 | mTransientConferenceSession.setListener(null); |
| 2205 | mTransientConferenceSession = null; |
| 2206 | } |
Tyler Gunn | 047d810 | 2015-01-30 15:21:11 -0800 | [diff] [blame] | 2207 | |
Anthony Lee | c479f66 | 2015-02-11 17:04:35 -0800 | [diff] [blame] | 2208 | listener = mListener; |
| 2209 | |
Anthony Lee | 61d41c1 | 2015-04-02 09:40:01 -0700 | [diff] [blame] | 2210 | // Ensure the calls being conferenced into the conference has isMerged = false. |
Anthony Lee | c479f66 | 2015-02-11 17:04:35 -0800 | [diff] [blame] | 2211 | // Ensure any terminations are surfaced from this session. |
Anju Mathapati | 818c09d | 2015-08-31 14:30:47 -0700 | [diff] [blame] | 2212 | markCallAsMerged(true); |
| 2213 | setCallSessionMergePending(false); |
Anthony Lee | c479f66 | 2015-02-11 17:04:35 -0800 | [diff] [blame] | 2214 | notifySessionTerminatedDuringMerge(); |
Anthony Lee | 61d41c1 | 2015-04-02 09:40:01 -0700 | [diff] [blame] | 2215 | |
Anju Mathapati | 818c09d | 2015-08-31 14:30:47 -0700 | [diff] [blame] | 2216 | // Perform the same cleanup on the merge peer if it exists. |
Anthony Lee | 61d41c1 | 2015-04-02 09:40:01 -0700 | [diff] [blame] | 2217 | if (mMergePeer != null) { |
Anju Mathapati | 818c09d | 2015-08-31 14:30:47 -0700 | [diff] [blame] | 2218 | mMergePeer.markCallAsMerged(true); |
| 2219 | mMergePeer.setCallSessionMergePending(false); |
Anthony Lee | 61d41c1 | 2015-04-02 09:40:01 -0700 | [diff] [blame] | 2220 | mMergePeer.notifySessionTerminatedDuringMerge(); |
| 2221 | } else { |
| 2222 | loge("processMergeFailed :: No merge peer!"); |
| 2223 | } |
Anthony Lee | c479f66 | 2015-02-11 17:04:35 -0800 | [diff] [blame] | 2224 | |
| 2225 | // Clear all the various flags around coordinating this merge. |
| 2226 | clearMergeInfo(); |
Anthony Lee | 7138269 | 2014-10-30 10:50:10 -0700 | [diff] [blame] | 2227 | } |
| 2228 | if (listener != null) { |
| 2229 | try { |
| 2230 | listener.onCallMergeFailed(ImsCall.this, reasonInfo); |
| 2231 | } catch (Throwable t) { |
Anthony Lee | b8799fe | 2014-11-03 15:13:47 -0800 | [diff] [blame] | 2232 | loge("processMergeFailed :: ", t); |
Anthony Lee | 7138269 | 2014-10-30 10:50:10 -0700 | [diff] [blame] | 2233 | } |
| 2234 | } |
Anthony Lee | c479f66 | 2015-02-11 17:04:35 -0800 | [diff] [blame] | 2235 | |
Anthony Lee | 7138269 | 2014-10-30 10:50:10 -0700 | [diff] [blame] | 2236 | return; |
| 2237 | } |
| 2238 | |
Tyler Gunn | afb53c8 | 2016-08-05 14:38:13 -0700 | [diff] [blame] | 2239 | @VisibleForTesting |
| 2240 | public class ImsCallSessionListenerProxy extends ImsCallSession.Listener { |
Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 2241 | @Override |
Anthony Lee | 7138269 | 2014-10-30 10:50:10 -0700 | [diff] [blame] | 2242 | public void callSessionProgressing(ImsCallSession session, ImsStreamMediaProfile profile) { |
Anthony Lee | 6804851 | 2015-03-18 15:04:18 -0700 | [diff] [blame] | 2243 | logi("callSessionProgressing :: session=" + session + " profile=" + profile); |
| 2244 | |
Anthony Lee | 7138269 | 2014-10-30 10:50:10 -0700 | [diff] [blame] | 2245 | if (isTransientConferenceSession(session)) { |
Anthony Lee | c479f66 | 2015-02-11 17:04:35 -0800 | [diff] [blame] | 2246 | // If it is a transient (conference) session, there is no action for this signal. |
Anthony Lee | 6804851 | 2015-03-18 15:04:18 -0700 | [diff] [blame] | 2247 | logi("callSessionProgressing :: not supported for transient conference session=" + |
Anthony Lee | b8799fe | 2014-11-03 15:13:47 -0800 | [diff] [blame] | 2248 | session); |
Anthony Lee | 7138269 | 2014-10-30 10:50:10 -0700 | [diff] [blame] | 2249 | return; |
| 2250 | } |
| 2251 | |
Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 2252 | ImsCall.Listener listener; |
| 2253 | |
| 2254 | synchronized(ImsCall.this) { |
| 2255 | listener = mListener; |
| 2256 | mCallProfile.mMediaProfile.copyFrom(profile); |
| 2257 | } |
| 2258 | |
| 2259 | if (listener != null) { |
| 2260 | try { |
| 2261 | listener.onCallProgressing(ImsCall.this); |
| 2262 | } catch (Throwable t) { |
| 2263 | loge("callSessionProgressing :: ", t); |
| 2264 | } |
| 2265 | } |
| 2266 | } |
| 2267 | |
| 2268 | @Override |
Anthony Lee | 7138269 | 2014-10-30 10:50:10 -0700 | [diff] [blame] | 2269 | public void callSessionStarted(ImsCallSession session, ImsCallProfile profile) { |
Anthony Lee | 6804851 | 2015-03-18 15:04:18 -0700 | [diff] [blame] | 2270 | logi("callSessionStarted :: session=" + session + " profile=" + profile); |
Anthony Lee | c479f66 | 2015-02-11 17:04:35 -0800 | [diff] [blame] | 2271 | |
| 2272 | if (!isTransientConferenceSession(session)) { |
| 2273 | // In the case that we are in the middle of a merge (either host or peer), we have |
| 2274 | // closure as far as this call's primary session is concerned. If we are not |
| 2275 | // merging...its a NOOP. |
| 2276 | setCallSessionMergePending(false); |
| 2277 | } else { |
Anthony Lee | 6804851 | 2015-03-18 15:04:18 -0700 | [diff] [blame] | 2278 | logi("callSessionStarted :: on transient session=" + session); |
Anthony Lee | c479f66 | 2015-02-11 17:04:35 -0800 | [diff] [blame] | 2279 | return; |
Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 2280 | } |
| 2281 | |
Anthony Lee | c479f66 | 2015-02-11 17:04:35 -0800 | [diff] [blame] | 2282 | if (isTransientConferenceSession(session)) { |
| 2283 | // No further processing is needed if this is the transient session. |
Anthony Lee | b8799fe | 2014-11-03 15:13:47 -0800 | [diff] [blame] | 2284 | return; |
| 2285 | } |
| 2286 | |
Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 2287 | ImsCall.Listener listener; |
| 2288 | |
| 2289 | synchronized(ImsCall.this) { |
| 2290 | listener = mListener; |
Tyler Gunn | 1ac2485 | 2016-06-22 10:04:23 -0700 | [diff] [blame] | 2291 | setCallProfile(profile); |
Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 2292 | } |
| 2293 | |
| 2294 | if (listener != null) { |
| 2295 | try { |
| 2296 | listener.onCallStarted(ImsCall.this); |
| 2297 | } catch (Throwable t) { |
| 2298 | loge("callSessionStarted :: ", t); |
| 2299 | } |
| 2300 | } |
| 2301 | } |
| 2302 | |
| 2303 | @Override |
Anthony Lee | 7138269 | 2014-10-30 10:50:10 -0700 | [diff] [blame] | 2304 | public void callSessionStartFailed(ImsCallSession session, ImsReasonInfo reasonInfo) { |
Anthony Lee | 6804851 | 2015-03-18 15:04:18 -0700 | [diff] [blame] | 2305 | loge("callSessionStartFailed :: session=" + session + " reasonInfo=" + reasonInfo); |
| 2306 | |
Anthony Lee | 7138269 | 2014-10-30 10:50:10 -0700 | [diff] [blame] | 2307 | if (isTransientConferenceSession(session)) { |
Anthony Lee | c479f66 | 2015-02-11 17:04:35 -0800 | [diff] [blame] | 2308 | // We should not get this callback for a transient session. |
Anthony Lee | 6804851 | 2015-03-18 15:04:18 -0700 | [diff] [blame] | 2309 | logi("callSessionStartFailed :: not supported for transient conference session=" + |
Anthony Lee | b8799fe | 2014-11-03 15:13:47 -0800 | [diff] [blame] | 2310 | session); |
Anthony Lee | 7138269 | 2014-10-30 10:50:10 -0700 | [diff] [blame] | 2311 | return; |
| 2312 | } |
| 2313 | |
Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 2314 | ImsCall.Listener listener; |
| 2315 | |
| 2316 | synchronized(ImsCall.this) { |
| 2317 | listener = mListener; |
| 2318 | mLastReasonInfo = reasonInfo; |
| 2319 | } |
| 2320 | |
| 2321 | if (listener != null) { |
| 2322 | try { |
| 2323 | listener.onCallStartFailed(ImsCall.this, reasonInfo); |
| 2324 | } catch (Throwable t) { |
| 2325 | loge("callSessionStarted :: ", t); |
| 2326 | } |
| 2327 | } |
| 2328 | } |
| 2329 | |
| 2330 | @Override |
Anthony Lee | 7138269 | 2014-10-30 10:50:10 -0700 | [diff] [blame] | 2331 | public void callSessionTerminated(ImsCallSession session, ImsReasonInfo reasonInfo) { |
Anthony Lee | 6804851 | 2015-03-18 15:04:18 -0700 | [diff] [blame] | 2332 | logi("callSessionTerminated :: session=" + session + " reasonInfo=" + reasonInfo); |
| 2333 | |
Anthony Lee | c479f66 | 2015-02-11 17:04:35 -0800 | [diff] [blame] | 2334 | if (isTransientConferenceSession(session)) { |
Anthony Lee | 6804851 | 2015-03-18 15:04:18 -0700 | [diff] [blame] | 2335 | logi("callSessionTerminated :: on transient session=" + session); |
Anthony Lee | c479f66 | 2015-02-11 17:04:35 -0800 | [diff] [blame] | 2336 | // This is bad, it should be treated much a callSessionMergeFailed since the |
| 2337 | // transient session only exists when in the process of a merge and the |
| 2338 | // termination of this session is effectively the end of the merge. |
| 2339 | processMergeFailed(reasonInfo); |
Anthony Lee | 7138269 | 2014-10-30 10:50:10 -0700 | [diff] [blame] | 2340 | return; |
| 2341 | } |
| 2342 | |
Tyler Gunn | 25a72fc | 2016-08-11 13:16:54 -0700 | [diff] [blame] | 2343 | if (mOverrideReason != ImsReasonInfo.CODE_UNSPECIFIED) { |
| 2344 | logi("callSessionTerminated :: overrideReasonInfo=" + mOverrideReason); |
| 2345 | reasonInfo = new ImsReasonInfo(mOverrideReason, reasonInfo.getExtraCode(), |
| 2346 | reasonInfo.getExtraMessage()); |
| 2347 | } |
| 2348 | |
Anthony Lee | c479f66 | 2015-02-11 17:04:35 -0800 | [diff] [blame] | 2349 | // Process the termination first. If we are in the midst of establishing a conference |
| 2350 | // call, we may bury this callback until we are done. If there so no conference |
| 2351 | // call, the code after this function will be a NOOP. |
| 2352 | processCallTerminated(reasonInfo); |
| 2353 | |
Tyler Gunn | 047d810 | 2015-01-30 15:21:11 -0800 | [diff] [blame] | 2354 | // If session has terminated, it is no longer pending merge. |
| 2355 | setCallSessionMergePending(false); |
| 2356 | |
Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 2357 | } |
| 2358 | |
| 2359 | @Override |
Anthony Lee | 7138269 | 2014-10-30 10:50:10 -0700 | [diff] [blame] | 2360 | public void callSessionHeld(ImsCallSession session, ImsCallProfile profile) { |
Anthony Lee | 6804851 | 2015-03-18 15:04:18 -0700 | [diff] [blame] | 2361 | logi("callSessionHeld :: session=" + session + "profile=" + profile); |
Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 2362 | ImsCall.Listener listener; |
| 2363 | |
| 2364 | synchronized(ImsCall.this) { |
Tyler Gunn | 047d810 | 2015-01-30 15:21:11 -0800 | [diff] [blame] | 2365 | // If the session was held, it is no longer pending a merge -- this means it could |
| 2366 | // not be merged into the conference and was held instead. |
| 2367 | setCallSessionMergePending(false); |
| 2368 | |
Tyler Gunn | 1ac2485 | 2016-06-22 10:04:23 -0700 | [diff] [blame] | 2369 | setCallProfile(profile); |
Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 2370 | |
| 2371 | if (mUpdateRequest == UPDATE_HOLD_MERGE) { |
Anthony Lee | c479f66 | 2015-02-11 17:04:35 -0800 | [diff] [blame] | 2372 | // This hold request was made to set the stage for a merge. |
Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 2373 | mergeInternal(); |
| 2374 | return; |
| 2375 | } |
| 2376 | |
| 2377 | mUpdateRequest = UPDATE_NONE; |
| 2378 | listener = mListener; |
| 2379 | } |
| 2380 | |
| 2381 | if (listener != null) { |
| 2382 | try { |
| 2383 | listener.onCallHeld(ImsCall.this); |
| 2384 | } catch (Throwable t) { |
| 2385 | loge("callSessionHeld :: ", t); |
| 2386 | } |
| 2387 | } |
| 2388 | } |
| 2389 | |
| 2390 | @Override |
Anthony Lee | 7138269 | 2014-10-30 10:50:10 -0700 | [diff] [blame] | 2391 | public void callSessionHoldFailed(ImsCallSession session, ImsReasonInfo reasonInfo) { |
Anthony Lee | 6804851 | 2015-03-18 15:04:18 -0700 | [diff] [blame] | 2392 | loge("callSessionHoldFailed :: session" + session + "reasonInfo=" + reasonInfo); |
| 2393 | |
Anthony Lee | 7138269 | 2014-10-30 10:50:10 -0700 | [diff] [blame] | 2394 | if (isTransientConferenceSession(session)) { |
Anthony Lee | c479f66 | 2015-02-11 17:04:35 -0800 | [diff] [blame] | 2395 | // We should not get this callback for a transient session. |
Anthony Lee | 6804851 | 2015-03-18 15:04:18 -0700 | [diff] [blame] | 2396 | logi("callSessionHoldFailed :: not supported for transient conference session=" + |
Anthony Lee | b8799fe | 2014-11-03 15:13:47 -0800 | [diff] [blame] | 2397 | session); |
Anthony Lee | 7138269 | 2014-10-30 10:50:10 -0700 | [diff] [blame] | 2398 | return; |
| 2399 | } |
| 2400 | |
Shriram Ganesh | d3adfad | 2015-05-31 10:06:15 -0700 | [diff] [blame] | 2401 | logi("callSessionHoldFailed :: session=" + session + |
| 2402 | ", reasonInfo=" + reasonInfo); |
| 2403 | |
| 2404 | synchronized (mLockObj) { |
Uma Maheswari Ramalingam | a1ed7b0 | 2015-05-20 14:26:42 -0700 | [diff] [blame] | 2405 | mHold = false; |
| 2406 | } |
| 2407 | |
Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 2408 | boolean isHoldForMerge = false; |
| 2409 | ImsCall.Listener listener; |
| 2410 | |
| 2411 | synchronized(ImsCall.this) { |
| 2412 | if (mUpdateRequest == UPDATE_HOLD_MERGE) { |
| 2413 | isHoldForMerge = true; |
| 2414 | } |
| 2415 | |
| 2416 | mUpdateRequest = UPDATE_NONE; |
| 2417 | listener = mListener; |
| 2418 | } |
| 2419 | |
Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 2420 | if (listener != null) { |
| 2421 | try { |
| 2422 | listener.onCallHoldFailed(ImsCall.this, reasonInfo); |
| 2423 | } catch (Throwable t) { |
| 2424 | loge("callSessionHoldFailed :: ", t); |
| 2425 | } |
| 2426 | } |
| 2427 | } |
| 2428 | |
Tyler Gunn | cc0f78f | 2017-12-04 13:01:55 -0800 | [diff] [blame] | 2429 | /** |
| 2430 | * Indicates that an {@link ImsCallSession} has been remotely held. This can be due to the |
| 2431 | * remote party holding the current call, or swapping between calls. |
| 2432 | * @param session the session which was held. |
| 2433 | * @param profile the profile for the held call. |
| 2434 | */ |
Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 2435 | @Override |
Anthony Lee | 7138269 | 2014-10-30 10:50:10 -0700 | [diff] [blame] | 2436 | public void callSessionHoldReceived(ImsCallSession session, ImsCallProfile profile) { |
Anthony Lee | 6804851 | 2015-03-18 15:04:18 -0700 | [diff] [blame] | 2437 | logi("callSessionHoldReceived :: session=" + session + "profile=" + profile); |
| 2438 | |
Anthony Lee | 7138269 | 2014-10-30 10:50:10 -0700 | [diff] [blame] | 2439 | if (isTransientConferenceSession(session)) { |
Anthony Lee | c479f66 | 2015-02-11 17:04:35 -0800 | [diff] [blame] | 2440 | // We should not get this callback for a transient session. |
Anthony Lee | 6804851 | 2015-03-18 15:04:18 -0700 | [diff] [blame] | 2441 | logi("callSessionHoldReceived :: not supported for transient conference session=" + |
Anthony Lee | b8799fe | 2014-11-03 15:13:47 -0800 | [diff] [blame] | 2442 | session); |
Anthony Lee | 7138269 | 2014-10-30 10:50:10 -0700 | [diff] [blame] | 2443 | return; |
| 2444 | } |
| 2445 | |
Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 2446 | ImsCall.Listener listener; |
| 2447 | |
| 2448 | synchronized(ImsCall.this) { |
| 2449 | listener = mListener; |
Tyler Gunn | 1ac2485 | 2016-06-22 10:04:23 -0700 | [diff] [blame] | 2450 | setCallProfile(profile); |
Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 2451 | } |
| 2452 | |
| 2453 | if (listener != null) { |
| 2454 | try { |
| 2455 | listener.onCallHoldReceived(ImsCall.this); |
| 2456 | } catch (Throwable t) { |
| 2457 | loge("callSessionHoldReceived :: ", t); |
| 2458 | } |
| 2459 | } |
| 2460 | } |
| 2461 | |
Tyler Gunn | cc0f78f | 2017-12-04 13:01:55 -0800 | [diff] [blame] | 2462 | /** |
| 2463 | * Indicates that an {@link ImsCallSession} has been remotely resumed. This can be due to |
| 2464 | * the remote party un-holding the current call, or swapping back to this call. |
| 2465 | * @param session the session which was resumed. |
| 2466 | * @param profile the profile for the held call. |
| 2467 | */ |
Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 2468 | @Override |
Anthony Lee | 7138269 | 2014-10-30 10:50:10 -0700 | [diff] [blame] | 2469 | public void callSessionResumed(ImsCallSession session, ImsCallProfile profile) { |
Anthony Lee | 6804851 | 2015-03-18 15:04:18 -0700 | [diff] [blame] | 2470 | logi("callSessionResumed :: session=" + session + "profile=" + profile); |
| 2471 | |
Anthony Lee | 7138269 | 2014-10-30 10:50:10 -0700 | [diff] [blame] | 2472 | if (isTransientConferenceSession(session)) { |
Anthony Lee | 6804851 | 2015-03-18 15:04:18 -0700 | [diff] [blame] | 2473 | logi("callSessionResumed :: not supported for transient conference session=" + |
Anthony Lee | b8799fe | 2014-11-03 15:13:47 -0800 | [diff] [blame] | 2474 | session); |
Anthony Lee | 7138269 | 2014-10-30 10:50:10 -0700 | [diff] [blame] | 2475 | return; |
| 2476 | } |
| 2477 | |
Anthony Lee | c479f66 | 2015-02-11 17:04:35 -0800 | [diff] [blame] | 2478 | // If this call was pending a merge, it is not anymore. This is the case when we |
| 2479 | // are merging in a new call into an existing conference. |
| 2480 | setCallSessionMergePending(false); |
Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 2481 | |
Anthony Lee | c479f66 | 2015-02-11 17:04:35 -0800 | [diff] [blame] | 2482 | // TOOD: When we are merging a new call into an existing conference we are waiting |
| 2483 | // for 2 triggers to let us know that the conference has been established, the first |
| 2484 | // is a termination for the new calls (since it is added to the conference) the second |
| 2485 | // would be a resume on the existing conference. If the resume comes first, then |
| 2486 | // we will make the onCallResumed() callback and its unclear how this will behave if |
| 2487 | // the termination has not come yet. |
| 2488 | |
| 2489 | ImsCall.Listener listener; |
Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 2490 | synchronized(ImsCall.this) { |
| 2491 | listener = mListener; |
Tyler Gunn | 1ac2485 | 2016-06-22 10:04:23 -0700 | [diff] [blame] | 2492 | setCallProfile(profile); |
Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 2493 | mUpdateRequest = UPDATE_NONE; |
Uma Maheswari Ramalingam | 095839a | 2014-12-03 14:47:15 -0800 | [diff] [blame] | 2494 | mHold = false; |
Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 2495 | } |
| 2496 | |
| 2497 | if (listener != null) { |
| 2498 | try { |
| 2499 | listener.onCallResumed(ImsCall.this); |
| 2500 | } catch (Throwable t) { |
| 2501 | loge("callSessionResumed :: ", t); |
| 2502 | } |
| 2503 | } |
| 2504 | } |
| 2505 | |
| 2506 | @Override |
Anthony Lee | 7138269 | 2014-10-30 10:50:10 -0700 | [diff] [blame] | 2507 | public void callSessionResumeFailed(ImsCallSession session, ImsReasonInfo reasonInfo) { |
Anthony Lee | 6804851 | 2015-03-18 15:04:18 -0700 | [diff] [blame] | 2508 | loge("callSessionResumeFailed :: session=" + session + "reasonInfo=" + reasonInfo); |
| 2509 | |
Anthony Lee | 7138269 | 2014-10-30 10:50:10 -0700 | [diff] [blame] | 2510 | if (isTransientConferenceSession(session)) { |
Anthony Lee | 6804851 | 2015-03-18 15:04:18 -0700 | [diff] [blame] | 2511 | logi("callSessionResumeFailed :: not supported for transient conference session=" + |
Anthony Lee | b8799fe | 2014-11-03 15:13:47 -0800 | [diff] [blame] | 2512 | session); |
Anthony Lee | 7138269 | 2014-10-30 10:50:10 -0700 | [diff] [blame] | 2513 | return; |
| 2514 | } |
| 2515 | |
Uma Maheswari Ramalingam | a1ed7b0 | 2015-05-20 14:26:42 -0700 | [diff] [blame] | 2516 | synchronized(mLockObj) { |
| 2517 | mHold = true; |
| 2518 | } |
| 2519 | |
Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 2520 | ImsCall.Listener listener; |
| 2521 | |
| 2522 | synchronized(ImsCall.this) { |
| 2523 | listener = mListener; |
| 2524 | mUpdateRequest = UPDATE_NONE; |
| 2525 | } |
| 2526 | |
| 2527 | if (listener != null) { |
| 2528 | try { |
| 2529 | listener.onCallResumeFailed(ImsCall.this, reasonInfo); |
| 2530 | } catch (Throwable t) { |
| 2531 | loge("callSessionResumeFailed :: ", t); |
| 2532 | } |
| 2533 | } |
| 2534 | } |
| 2535 | |
| 2536 | @Override |
Anthony Lee | 7138269 | 2014-10-30 10:50:10 -0700 | [diff] [blame] | 2537 | public void callSessionResumeReceived(ImsCallSession session, ImsCallProfile profile) { |
Anthony Lee | 6804851 | 2015-03-18 15:04:18 -0700 | [diff] [blame] | 2538 | logi("callSessionResumeReceived :: session=" + session + "profile=" + profile); |
| 2539 | |
Anthony Lee | 7138269 | 2014-10-30 10:50:10 -0700 | [diff] [blame] | 2540 | if (isTransientConferenceSession(session)) { |
Anthony Lee | 6804851 | 2015-03-18 15:04:18 -0700 | [diff] [blame] | 2541 | logi("callSessionResumeReceived :: not supported for transient conference session=" + |
Anthony Lee | b8799fe | 2014-11-03 15:13:47 -0800 | [diff] [blame] | 2542 | session); |
Anthony Lee | 7138269 | 2014-10-30 10:50:10 -0700 | [diff] [blame] | 2543 | return; |
| 2544 | } |
| 2545 | |
Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 2546 | ImsCall.Listener listener; |
| 2547 | |
| 2548 | synchronized(ImsCall.this) { |
| 2549 | listener = mListener; |
Tyler Gunn | 1ac2485 | 2016-06-22 10:04:23 -0700 | [diff] [blame] | 2550 | setCallProfile(profile); |
Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 2551 | } |
| 2552 | |
| 2553 | if (listener != null) { |
| 2554 | try { |
| 2555 | listener.onCallResumeReceived(ImsCall.this); |
| 2556 | } catch (Throwable t) { |
| 2557 | loge("callSessionResumeReceived :: ", t); |
| 2558 | } |
| 2559 | } |
| 2560 | } |
| 2561 | |
| 2562 | @Override |
Tyler Gunn | 3f2b0aa | 2014-10-24 10:02:19 -0700 | [diff] [blame] | 2563 | public void callSessionMergeStarted(ImsCallSession session, |
Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 2564 | ImsCallSession newSession, ImsCallProfile profile) { |
Anthony Lee | 6804851 | 2015-03-18 15:04:18 -0700 | [diff] [blame] | 2565 | logi("callSessionMergeStarted :: session=" + session + " newSession=" + newSession + |
| 2566 | ", profile=" + profile); |
Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 2567 | |
Anthony Lee | 7138269 | 2014-10-30 10:50:10 -0700 | [diff] [blame] | 2568 | return; |
Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 2569 | } |
| 2570 | |
Uma Maheswari Ramalingam | 95be7c6 | 2015-05-06 23:08:17 -0700 | [diff] [blame] | 2571 | /* |
| 2572 | * This method check if session exists as a session on the current |
| 2573 | * ImsCall or its counterpart if it is in the process of a conference |
| 2574 | */ |
| 2575 | private boolean doesCallSessionExistsInMerge(ImsCallSession cs) { |
| 2576 | String callId = cs.getCallId(); |
| 2577 | return ((isMergeHost() && Objects.equals(mMergePeer.mSession.getCallId(), callId)) || |
| 2578 | (isMergePeer() && Objects.equals(mMergeHost.mSession.getCallId(), callId)) || |
| 2579 | Objects.equals(mSession.getCallId(), callId)); |
| 2580 | } |
| 2581 | |
| 2582 | /** |
| 2583 | * We received a callback from ImsCallSession that merge completed. |
Anju Mathapati | d9ed874 | 2015-07-17 14:54:10 -0700 | [diff] [blame] | 2584 | * @param newSession - this session can have 2 values based on the below scenarios |
Uma Maheswari Ramalingam | 95be7c6 | 2015-05-06 23:08:17 -0700 | [diff] [blame] | 2585 | * |
| 2586 | * Conference Scenarios : |
| 2587 | * Case 1 - 3 way success case |
| 2588 | * Case 2 - 3 way success case but held call fails to merge |
| 2589 | * Case 3 - 3 way success case but active call fails to merge |
| 2590 | * case 4 - 4 way success case, where merge is initiated on the foreground single-party |
| 2591 | * call and the conference (mergeHost) is the background call. |
| 2592 | * case 5 - 4 way success case, where merge is initiated on the foreground conference |
| 2593 | * call (mergeHost) and the single party call is in the background. |
| 2594 | * |
| 2595 | * Conference Result: |
Anju Mathapati | d9ed874 | 2015-07-17 14:54:10 -0700 | [diff] [blame] | 2596 | * session : new session after conference |
| 2597 | * newSession = new session for case 1, 2, 3. |
| 2598 | * Should be considered as mTransientConferencession |
| 2599 | * newSession = Active conference session for case 5 will be null |
| 2600 | * mergehost was foreground call |
| 2601 | * mTransientConferencession will be null |
| 2602 | * newSession = Active conference session for case 4 will be null |
| 2603 | * mergeHost was background call |
| 2604 | * mTransientConferencession will be null |
Uma Maheswari Ramalingam | 95be7c6 | 2015-05-06 23:08:17 -0700 | [diff] [blame] | 2605 | */ |
Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 2606 | @Override |
Anju Mathapati | d9ed874 | 2015-07-17 14:54:10 -0700 | [diff] [blame] | 2607 | public void callSessionMergeComplete(ImsCallSession newSession) { |
| 2608 | logi("callSessionMergeComplete :: newSession =" + newSession); |
Uma Maheswari Ramalingam | 95be7c6 | 2015-05-06 23:08:17 -0700 | [diff] [blame] | 2609 | if (!isMergeHost()) { |
| 2610 | // Handles case 4 |
| 2611 | mMergeHost.processMergeComplete(); |
| 2612 | } else { |
Anju Mathapati | d9ed874 | 2015-07-17 14:54:10 -0700 | [diff] [blame] | 2613 | // Handles case 1, 2, 3 |
| 2614 | if (newSession != null) { |
| 2615 | mTransientConferenceSession = doesCallSessionExistsInMerge(newSession) ? |
| 2616 | null: newSession; |
| 2617 | } |
| 2618 | // Handles case 5 |
Uma Maheswari Ramalingam | 95be7c6 | 2015-05-06 23:08:17 -0700 | [diff] [blame] | 2619 | processMergeComplete(); |
| 2620 | } |
Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 2621 | } |
| 2622 | |
| 2623 | @Override |
Anthony Lee | 7138269 | 2014-10-30 10:50:10 -0700 | [diff] [blame] | 2624 | public void callSessionMergeFailed(ImsCallSession session, ImsReasonInfo reasonInfo) { |
Anthony Lee | 6804851 | 2015-03-18 15:04:18 -0700 | [diff] [blame] | 2625 | loge("callSessionMergeFailed :: session=" + session + "reasonInfo=" + reasonInfo); |
Anthony Lee | c479f66 | 2015-02-11 17:04:35 -0800 | [diff] [blame] | 2626 | |
| 2627 | // Its possible that there could be threading issues with the other thread handling |
| 2628 | // the other call. This could affect our state. |
| 2629 | synchronized (ImsCall.this) { |
Anthony Lee | c479f66 | 2015-02-11 17:04:35 -0800 | [diff] [blame] | 2630 | // Let's tell our parent ImsCall that the merge has failed and we need to clean |
| 2631 | // up any temporary, transient state. Note this only gets called for an initial |
| 2632 | // conference. If a merge into an existing conference fails, the two sessions will |
| 2633 | // just go back to their original state (ACTIVE or HELD). |
| 2634 | if (isMergeHost()) { |
| 2635 | processMergeFailed(reasonInfo); |
| 2636 | } else if (mMergeHost != null) { |
| 2637 | mMergeHost.processMergeFailed(reasonInfo); |
| 2638 | } else { |
| 2639 | loge("callSessionMergeFailed :: No merge host for this conference!"); |
| 2640 | } |
Anthony Lee | 7138269 | 2014-10-30 10:50:10 -0700 | [diff] [blame] | 2641 | } |
Anthony Lee | 7138269 | 2014-10-30 10:50:10 -0700 | [diff] [blame] | 2642 | } |
| 2643 | |
| 2644 | @Override |
| 2645 | public void callSessionUpdated(ImsCallSession session, ImsCallProfile profile) { |
Anthony Lee | 6804851 | 2015-03-18 15:04:18 -0700 | [diff] [blame] | 2646 | logi("callSessionUpdated :: session=" + session + " profile=" + profile); |
| 2647 | |
Anthony Lee | 7138269 | 2014-10-30 10:50:10 -0700 | [diff] [blame] | 2648 | if (isTransientConferenceSession(session)) { |
Anthony Lee | 6804851 | 2015-03-18 15:04:18 -0700 | [diff] [blame] | 2649 | logi("callSessionUpdated :: not supported for transient conference session=" + |
Anthony Lee | b8799fe | 2014-11-03 15:13:47 -0800 | [diff] [blame] | 2650 | session); |
Anthony Lee | 7138269 | 2014-10-30 10:50:10 -0700 | [diff] [blame] | 2651 | return; |
| 2652 | } |
| 2653 | |
Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 2654 | ImsCall.Listener listener; |
| 2655 | |
| 2656 | synchronized(ImsCall.this) { |
| 2657 | listener = mListener; |
Tyler Gunn | 1ac2485 | 2016-06-22 10:04:23 -0700 | [diff] [blame] | 2658 | setCallProfile(profile); |
Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 2659 | } |
| 2660 | |
| 2661 | if (listener != null) { |
| 2662 | try { |
| 2663 | listener.onCallUpdated(ImsCall.this); |
| 2664 | } catch (Throwable t) { |
| 2665 | loge("callSessionUpdated :: ", t); |
| 2666 | } |
| 2667 | } |
| 2668 | } |
| 2669 | |
| 2670 | @Override |
Anthony Lee | 7138269 | 2014-10-30 10:50:10 -0700 | [diff] [blame] | 2671 | public void callSessionUpdateFailed(ImsCallSession session, ImsReasonInfo reasonInfo) { |
Anthony Lee | 6804851 | 2015-03-18 15:04:18 -0700 | [diff] [blame] | 2672 | loge("callSessionUpdateFailed :: session=" + session + " reasonInfo=" + reasonInfo); |
| 2673 | |
Anthony Lee | 7138269 | 2014-10-30 10:50:10 -0700 | [diff] [blame] | 2674 | if (isTransientConferenceSession(session)) { |
Anthony Lee | 6804851 | 2015-03-18 15:04:18 -0700 | [diff] [blame] | 2675 | logi("callSessionUpdateFailed :: not supported for transient conference session=" + |
Anthony Lee | b8799fe | 2014-11-03 15:13:47 -0800 | [diff] [blame] | 2676 | session); |
Anthony Lee | 7138269 | 2014-10-30 10:50:10 -0700 | [diff] [blame] | 2677 | return; |
| 2678 | } |
| 2679 | |
Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 2680 | ImsCall.Listener listener; |
| 2681 | |
| 2682 | synchronized(ImsCall.this) { |
| 2683 | listener = mListener; |
| 2684 | mUpdateRequest = UPDATE_NONE; |
| 2685 | } |
| 2686 | |
| 2687 | if (listener != null) { |
| 2688 | try { |
| 2689 | listener.onCallUpdateFailed(ImsCall.this, reasonInfo); |
| 2690 | } catch (Throwable t) { |
| 2691 | loge("callSessionUpdateFailed :: ", t); |
| 2692 | } |
| 2693 | } |
| 2694 | } |
| 2695 | |
| 2696 | @Override |
Anthony Lee | 7138269 | 2014-10-30 10:50:10 -0700 | [diff] [blame] | 2697 | public void callSessionUpdateReceived(ImsCallSession session, ImsCallProfile profile) { |
Anthony Lee | 6804851 | 2015-03-18 15:04:18 -0700 | [diff] [blame] | 2698 | logi("callSessionUpdateReceived :: session=" + session + " profile=" + profile); |
| 2699 | |
Anthony Lee | 7138269 | 2014-10-30 10:50:10 -0700 | [diff] [blame] | 2700 | if (isTransientConferenceSession(session)) { |
Anthony Lee | 6804851 | 2015-03-18 15:04:18 -0700 | [diff] [blame] | 2701 | logi("callSessionUpdateReceived :: not supported for transient conference " + |
Anthony Lee | b8799fe | 2014-11-03 15:13:47 -0800 | [diff] [blame] | 2702 | "session=" + session); |
Anthony Lee | 7138269 | 2014-10-30 10:50:10 -0700 | [diff] [blame] | 2703 | return; |
| 2704 | } |
| 2705 | |
Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 2706 | ImsCall.Listener listener; |
| 2707 | |
| 2708 | synchronized(ImsCall.this) { |
| 2709 | listener = mListener; |
| 2710 | mProposedCallProfile = profile; |
| 2711 | mUpdateRequest = UPDATE_UNSPECIFIED; |
| 2712 | } |
| 2713 | |
| 2714 | if (listener != null) { |
| 2715 | try { |
| 2716 | listener.onCallUpdateReceived(ImsCall.this); |
| 2717 | } catch (Throwable t) { |
| 2718 | loge("callSessionUpdateReceived :: ", t); |
| 2719 | } |
| 2720 | } |
| 2721 | } |
| 2722 | |
| 2723 | @Override |
Anthony Lee | 7138269 | 2014-10-30 10:50:10 -0700 | [diff] [blame] | 2724 | public void callSessionConferenceExtended(ImsCallSession session, ImsCallSession newSession, |
| 2725 | ImsCallProfile profile) { |
Anthony Lee | 6804851 | 2015-03-18 15:04:18 -0700 | [diff] [blame] | 2726 | logi("callSessionConferenceExtended :: session=" + session + " newSession=" + |
| 2727 | newSession + ", profile=" + profile); |
| 2728 | |
Anthony Lee | 7138269 | 2014-10-30 10:50:10 -0700 | [diff] [blame] | 2729 | if (isTransientConferenceSession(session)) { |
Anthony Lee | 6804851 | 2015-03-18 15:04:18 -0700 | [diff] [blame] | 2730 | logi("callSessionConferenceExtended :: not supported for transient conference " + |
Anthony Lee | b8799fe | 2014-11-03 15:13:47 -0800 | [diff] [blame] | 2731 | "session=" + session); |
Anthony Lee | 7138269 | 2014-10-30 10:50:10 -0700 | [diff] [blame] | 2732 | return; |
| 2733 | } |
| 2734 | |
Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 2735 | ImsCall newCall = createNewCall(newSession, profile); |
| 2736 | |
| 2737 | if (newCall == null) { |
| 2738 | callSessionConferenceExtendFailed(session, new ImsReasonInfo()); |
| 2739 | return; |
| 2740 | } |
| 2741 | |
| 2742 | ImsCall.Listener listener; |
| 2743 | |
| 2744 | synchronized(ImsCall.this) { |
| 2745 | listener = mListener; |
| 2746 | mUpdateRequest = UPDATE_NONE; |
| 2747 | } |
| 2748 | |
| 2749 | if (listener != null) { |
| 2750 | try { |
| 2751 | listener.onCallConferenceExtended(ImsCall.this, newCall); |
| 2752 | } catch (Throwable t) { |
| 2753 | loge("callSessionConferenceExtended :: ", t); |
| 2754 | } |
| 2755 | } |
| 2756 | } |
| 2757 | |
| 2758 | @Override |
| 2759 | public void callSessionConferenceExtendFailed(ImsCallSession session, |
| 2760 | ImsReasonInfo reasonInfo) { |
Anthony Lee | 6804851 | 2015-03-18 15:04:18 -0700 | [diff] [blame] | 2761 | loge("callSessionConferenceExtendFailed :: reasonInfo=" + reasonInfo); |
| 2762 | |
Anthony Lee | 7138269 | 2014-10-30 10:50:10 -0700 | [diff] [blame] | 2763 | if (isTransientConferenceSession(session)) { |
Anthony Lee | 6804851 | 2015-03-18 15:04:18 -0700 | [diff] [blame] | 2764 | logi("callSessionConferenceExtendFailed :: not supported for transient " + |
Anthony Lee | b8799fe | 2014-11-03 15:13:47 -0800 | [diff] [blame] | 2765 | "conference session=" + session); |
Anthony Lee | 7138269 | 2014-10-30 10:50:10 -0700 | [diff] [blame] | 2766 | return; |
| 2767 | } |
| 2768 | |
Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 2769 | ImsCall.Listener listener; |
| 2770 | |
| 2771 | synchronized(ImsCall.this) { |
| 2772 | listener = mListener; |
| 2773 | mUpdateRequest = UPDATE_NONE; |
| 2774 | } |
| 2775 | |
| 2776 | if (listener != null) { |
| 2777 | try { |
| 2778 | listener.onCallConferenceExtendFailed(ImsCall.this, reasonInfo); |
| 2779 | } catch (Throwable t) { |
| 2780 | loge("callSessionConferenceExtendFailed :: ", t); |
| 2781 | } |
| 2782 | } |
| 2783 | } |
| 2784 | |
| 2785 | @Override |
| 2786 | public void callSessionConferenceExtendReceived(ImsCallSession session, |
| 2787 | ImsCallSession newSession, ImsCallProfile profile) { |
Anthony Lee | 6804851 | 2015-03-18 15:04:18 -0700 | [diff] [blame] | 2788 | logi("callSessionConferenceExtendReceived :: newSession=" + newSession + |
| 2789 | ", profile=" + profile); |
| 2790 | |
Anthony Lee | 7138269 | 2014-10-30 10:50:10 -0700 | [diff] [blame] | 2791 | if (isTransientConferenceSession(session)) { |
Anthony Lee | 6804851 | 2015-03-18 15:04:18 -0700 | [diff] [blame] | 2792 | logi("callSessionConferenceExtendReceived :: not supported for transient " + |
Tyler Gunn | 9bd5ca5 | 2014-12-02 09:21:01 -0800 | [diff] [blame] | 2793 | "conference session" + session); |
Anthony Lee | 7138269 | 2014-10-30 10:50:10 -0700 | [diff] [blame] | 2794 | return; |
| 2795 | } |
| 2796 | |
Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 2797 | ImsCall newCall = createNewCall(newSession, profile); |
| 2798 | |
| 2799 | if (newCall == null) { |
| 2800 | // Should all the calls be terminated...??? |
| 2801 | return; |
| 2802 | } |
| 2803 | |
| 2804 | ImsCall.Listener listener; |
| 2805 | |
| 2806 | synchronized(ImsCall.this) { |
| 2807 | listener = mListener; |
| 2808 | } |
| 2809 | |
| 2810 | if (listener != null) { |
| 2811 | try { |
| 2812 | listener.onCallConferenceExtendReceived(ImsCall.this, newCall); |
| 2813 | } catch (Throwable t) { |
| 2814 | loge("callSessionConferenceExtendReceived :: ", t); |
| 2815 | } |
| 2816 | } |
| 2817 | } |
| 2818 | |
| 2819 | @Override |
| 2820 | public void callSessionInviteParticipantsRequestDelivered(ImsCallSession session) { |
Anthony Lee | 6804851 | 2015-03-18 15:04:18 -0700 | [diff] [blame] | 2821 | logi("callSessionInviteParticipantsRequestDelivered ::"); |
| 2822 | |
Anthony Lee | 7138269 | 2014-10-30 10:50:10 -0700 | [diff] [blame] | 2823 | if (isTransientConferenceSession(session)) { |
Anthony Lee | 6804851 | 2015-03-18 15:04:18 -0700 | [diff] [blame] | 2824 | logi("callSessionInviteParticipantsRequestDelivered :: not supported for " + |
Anthony Lee | 7138269 | 2014-10-30 10:50:10 -0700 | [diff] [blame] | 2825 | "conference session=" + session); |
| 2826 | return; |
| 2827 | } |
| 2828 | |
Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 2829 | ImsCall.Listener listener; |
| 2830 | |
| 2831 | synchronized(ImsCall.this) { |
| 2832 | listener = mListener; |
| 2833 | } |
| 2834 | |
| 2835 | if (listener != null) { |
| 2836 | try { |
| 2837 | listener.onCallInviteParticipantsRequestDelivered(ImsCall.this); |
| 2838 | } catch (Throwable t) { |
| 2839 | loge("callSessionInviteParticipantsRequestDelivered :: ", t); |
| 2840 | } |
| 2841 | } |
| 2842 | } |
| 2843 | |
| 2844 | @Override |
| 2845 | public void callSessionInviteParticipantsRequestFailed(ImsCallSession session, |
| 2846 | ImsReasonInfo reasonInfo) { |
Anthony Lee | 6804851 | 2015-03-18 15:04:18 -0700 | [diff] [blame] | 2847 | loge("callSessionInviteParticipantsRequestFailed :: reasonInfo=" + reasonInfo); |
| 2848 | |
Anthony Lee | 7138269 | 2014-10-30 10:50:10 -0700 | [diff] [blame] | 2849 | if (isTransientConferenceSession(session)) { |
Anthony Lee | 6804851 | 2015-03-18 15:04:18 -0700 | [diff] [blame] | 2850 | logi("callSessionInviteParticipantsRequestFailed :: not supported for " + |
Anthony Lee | 7138269 | 2014-10-30 10:50:10 -0700 | [diff] [blame] | 2851 | "conference session=" + session); |
| 2852 | return; |
| 2853 | } |
| 2854 | |
Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 2855 | ImsCall.Listener listener; |
| 2856 | |
| 2857 | synchronized(ImsCall.this) { |
| 2858 | listener = mListener; |
| 2859 | } |
| 2860 | |
| 2861 | if (listener != null) { |
| 2862 | try { |
| 2863 | listener.onCallInviteParticipantsRequestFailed(ImsCall.this, reasonInfo); |
| 2864 | } catch (Throwable t) { |
| 2865 | loge("callSessionInviteParticipantsRequestFailed :: ", t); |
| 2866 | } |
| 2867 | } |
| 2868 | } |
| 2869 | |
| 2870 | @Override |
| 2871 | public void callSessionRemoveParticipantsRequestDelivered(ImsCallSession session) { |
Anthony Lee | 6804851 | 2015-03-18 15:04:18 -0700 | [diff] [blame] | 2872 | logi("callSessionRemoveParticipantsRequestDelivered ::"); |
| 2873 | |
Anthony Lee | 7138269 | 2014-10-30 10:50:10 -0700 | [diff] [blame] | 2874 | if (isTransientConferenceSession(session)) { |
Anthony Lee | 6804851 | 2015-03-18 15:04:18 -0700 | [diff] [blame] | 2875 | logi("callSessionRemoveParticipantsRequestDelivered :: not supported for " + |
Anthony Lee | 7138269 | 2014-10-30 10:50:10 -0700 | [diff] [blame] | 2876 | "conference session=" + session); |
| 2877 | return; |
| 2878 | } |
| 2879 | |
Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 2880 | ImsCall.Listener listener; |
| 2881 | |
| 2882 | synchronized(ImsCall.this) { |
| 2883 | listener = mListener; |
| 2884 | } |
| 2885 | |
| 2886 | if (listener != null) { |
| 2887 | try { |
| 2888 | listener.onCallRemoveParticipantsRequestDelivered(ImsCall.this); |
| 2889 | } catch (Throwable t) { |
| 2890 | loge("callSessionRemoveParticipantsRequestDelivered :: ", t); |
| 2891 | } |
| 2892 | } |
| 2893 | } |
| 2894 | |
| 2895 | @Override |
| 2896 | public void callSessionRemoveParticipantsRequestFailed(ImsCallSession session, |
| 2897 | ImsReasonInfo reasonInfo) { |
Anthony Lee | 6804851 | 2015-03-18 15:04:18 -0700 | [diff] [blame] | 2898 | loge("callSessionRemoveParticipantsRequestFailed :: reasonInfo=" + reasonInfo); |
| 2899 | |
Anthony Lee | 7138269 | 2014-10-30 10:50:10 -0700 | [diff] [blame] | 2900 | if (isTransientConferenceSession(session)) { |
Anthony Lee | 6804851 | 2015-03-18 15:04:18 -0700 | [diff] [blame] | 2901 | logi("callSessionRemoveParticipantsRequestFailed :: not supported for " + |
Tyler Gunn | 9bd5ca5 | 2014-12-02 09:21:01 -0800 | [diff] [blame] | 2902 | "conference session=" + session); |
Anthony Lee | 7138269 | 2014-10-30 10:50:10 -0700 | [diff] [blame] | 2903 | return; |
| 2904 | } |
| 2905 | |
Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 2906 | ImsCall.Listener listener; |
| 2907 | |
| 2908 | synchronized(ImsCall.this) { |
| 2909 | listener = mListener; |
| 2910 | } |
| 2911 | |
| 2912 | if (listener != null) { |
| 2913 | try { |
| 2914 | listener.onCallRemoveParticipantsRequestFailed(ImsCall.this, reasonInfo); |
| 2915 | } catch (Throwable t) { |
| 2916 | loge("callSessionRemoveParticipantsRequestFailed :: ", t); |
| 2917 | } |
| 2918 | } |
| 2919 | } |
| 2920 | |
| 2921 | @Override |
| 2922 | public void callSessionConferenceStateUpdated(ImsCallSession session, |
| 2923 | ImsConferenceState state) { |
Anthony Lee | 6804851 | 2015-03-18 15:04:18 -0700 | [diff] [blame] | 2924 | logi("callSessionConferenceStateUpdated :: state=" + state); |
| 2925 | |
Tyler Gunn | 938116f | 2014-10-27 09:15:23 -0700 | [diff] [blame] | 2926 | conferenceStateUpdated(state); |
Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 2927 | } |
| 2928 | |
| 2929 | @Override |
Anthony Lee | 7138269 | 2014-10-30 10:50:10 -0700 | [diff] [blame] | 2930 | public void callSessionUssdMessageReceived(ImsCallSession session, int mode, |
| 2931 | String ussdMessage) { |
Anthony Lee | 6804851 | 2015-03-18 15:04:18 -0700 | [diff] [blame] | 2932 | logi("callSessionUssdMessageReceived :: mode=" + mode + ", ussdMessage=" + |
| 2933 | ussdMessage); |
| 2934 | |
Anthony Lee | 7138269 | 2014-10-30 10:50:10 -0700 | [diff] [blame] | 2935 | if (isTransientConferenceSession(session)) { |
Anthony Lee | 6804851 | 2015-03-18 15:04:18 -0700 | [diff] [blame] | 2936 | logi("callSessionUssdMessageReceived :: not supported for transient " + |
Anthony Lee | b8799fe | 2014-11-03 15:13:47 -0800 | [diff] [blame] | 2937 | "conference session=" + session); |
Anthony Lee | 7138269 | 2014-10-30 10:50:10 -0700 | [diff] [blame] | 2938 | return; |
| 2939 | } |
| 2940 | |
Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 2941 | ImsCall.Listener listener; |
| 2942 | |
| 2943 | synchronized(ImsCall.this) { |
| 2944 | listener = mListener; |
| 2945 | } |
| 2946 | |
| 2947 | if (listener != null) { |
| 2948 | try { |
| 2949 | listener.onCallUssdMessageReceived(ImsCall.this, mode, ussdMessage); |
| 2950 | } catch (Throwable t) { |
| 2951 | loge("callSessionUssdMessageReceived :: ", t); |
| 2952 | } |
| 2953 | } |
| 2954 | } |
Pavel Zhamaitsiak | 987bab8 | 2014-11-16 15:29:09 -0800 | [diff] [blame] | 2955 | |
| 2956 | @Override |
| 2957 | public void callSessionTtyModeReceived(ImsCallSession session, int mode) { |
Anthony Lee | 6804851 | 2015-03-18 15:04:18 -0700 | [diff] [blame] | 2958 | logi("callSessionTtyModeReceived :: mode=" + mode); |
Pavel Zhamaitsiak | 987bab8 | 2014-11-16 15:29:09 -0800 | [diff] [blame] | 2959 | |
Pavel Zhamaitsiak | a6cae36 | 2014-12-10 17:31:33 -0800 | [diff] [blame] | 2960 | ImsCall.Listener listener; |
| 2961 | |
| 2962 | synchronized(ImsCall.this) { |
| 2963 | listener = mListener; |
| 2964 | } |
| 2965 | |
| 2966 | if (listener != null) { |
| 2967 | try { |
| 2968 | listener.onCallSessionTtyModeReceived(ImsCall.this, mode); |
| 2969 | } catch (Throwable t) { |
| 2970 | loge("callSessionTtyModeReceived :: ", t); |
Pavel Zhamaitsiak | 987bab8 | 2014-11-16 15:29:09 -0800 | [diff] [blame] | 2971 | } |
| 2972 | } |
| 2973 | } |
Rekha Kumar | 1463174 | 2015-02-04 10:47:00 -0800 | [diff] [blame] | 2974 | |
Tyler Gunn | 2539409 | 2015-04-01 09:40:02 -0700 | [diff] [blame] | 2975 | /** |
| 2976 | * Notifies of a change to the multiparty state for this {@code ImsCallSession}. |
| 2977 | * |
| 2978 | * @param session The call session. |
| 2979 | * @param isMultiParty {@code true} if the session became multiparty, {@code false} |
| 2980 | * otherwise. |
| 2981 | */ |
| 2982 | @Override |
| 2983 | public void callSessionMultipartyStateChanged(ImsCallSession session, |
| 2984 | boolean isMultiParty) { |
| 2985 | if (VDBG) { |
Pavel Zhamaitsiak | 691a1cc | 2015-04-09 10:14:55 -0700 | [diff] [blame] | 2986 | logi("callSessionMultipartyStateChanged isMultiParty: " + (isMultiParty ? "Y" |
Tyler Gunn | 2539409 | 2015-04-01 09:40:02 -0700 | [diff] [blame] | 2987 | : "N")); |
| 2988 | } |
| 2989 | |
| 2990 | ImsCall.Listener listener; |
| 2991 | |
| 2992 | synchronized(ImsCall.this) { |
| 2993 | listener = mListener; |
| 2994 | } |
| 2995 | |
| 2996 | if (listener != null) { |
| 2997 | try { |
| 2998 | listener.onMultipartyStateChanged(ImsCall.this, isMultiParty); |
| 2999 | } catch (Throwable t) { |
| 3000 | loge("callSessionMultipartyStateChanged :: ", t); |
| 3001 | } |
| 3002 | } |
| 3003 | } |
| 3004 | |
Rekha Kumar | 1463174 | 2015-02-04 10:47:00 -0800 | [diff] [blame] | 3005 | public void callSessionHandover(ImsCallSession session, int srcAccessTech, |
| 3006 | int targetAccessTech, ImsReasonInfo reasonInfo) { |
Anthony Lee | 6804851 | 2015-03-18 15:04:18 -0700 | [diff] [blame] | 3007 | logi("callSessionHandover :: session=" + session + ", srcAccessTech=" + |
| 3008 | srcAccessTech + ", targetAccessTech=" + targetAccessTech + ", reasonInfo=" + |
| 3009 | reasonInfo); |
Rekha Kumar | 1463174 | 2015-02-04 10:47:00 -0800 | [diff] [blame] | 3010 | |
| 3011 | ImsCall.Listener listener; |
| 3012 | |
| 3013 | synchronized(ImsCall.this) { |
| 3014 | listener = mListener; |
| 3015 | } |
| 3016 | |
| 3017 | if (listener != null) { |
| 3018 | try { |
| 3019 | listener.onCallHandover(ImsCall.this, srcAccessTech, targetAccessTech, |
| 3020 | reasonInfo); |
| 3021 | } catch (Throwable t) { |
| 3022 | loge("callSessionHandover :: ", t); |
| 3023 | } |
| 3024 | } |
| 3025 | } |
| 3026 | |
| 3027 | @Override |
| 3028 | public void callSessionHandoverFailed(ImsCallSession session, int srcAccessTech, |
| 3029 | int targetAccessTech, ImsReasonInfo reasonInfo) { |
Anthony Lee | 6804851 | 2015-03-18 15:04:18 -0700 | [diff] [blame] | 3030 | loge("callSessionHandoverFailed :: session=" + session + ", srcAccessTech=" + |
| 3031 | srcAccessTech + ", targetAccessTech=" + targetAccessTech + ", reasonInfo=" + |
| 3032 | reasonInfo); |
Rekha Kumar | 1463174 | 2015-02-04 10:47:00 -0800 | [diff] [blame] | 3033 | |
| 3034 | ImsCall.Listener listener; |
| 3035 | |
| 3036 | synchronized(ImsCall.this) { |
| 3037 | listener = mListener; |
| 3038 | } |
| 3039 | |
| 3040 | if (listener != null) { |
| 3041 | try { |
| 3042 | listener.onCallHandoverFailed(ImsCall.this, srcAccessTech, targetAccessTech, |
| 3043 | reasonInfo); |
| 3044 | } catch (Throwable t) { |
| 3045 | loge("callSessionHandoverFailed :: ", t); |
| 3046 | } |
| 3047 | } |
| 3048 | } |
Shriram Ganesh | d3adfad | 2015-05-31 10:06:15 -0700 | [diff] [blame] | 3049 | |
| 3050 | @Override |
| 3051 | public void callSessionSuppServiceReceived(ImsCallSession session, |
| 3052 | ImsSuppServiceNotification suppServiceInfo ) { |
| 3053 | if (isTransientConferenceSession(session)) { |
| 3054 | logi("callSessionSuppServiceReceived :: not supported for transient conference" |
| 3055 | + " session=" + session); |
| 3056 | return; |
| 3057 | } |
| 3058 | |
| 3059 | logi("callSessionSuppServiceReceived :: session=" + session + |
| 3060 | ", suppServiceInfo" + suppServiceInfo); |
| 3061 | |
| 3062 | ImsCall.Listener listener; |
| 3063 | |
| 3064 | synchronized(ImsCall.this) { |
| 3065 | listener = mListener; |
| 3066 | } |
| 3067 | |
| 3068 | if (listener != null) { |
| 3069 | try { |
| 3070 | listener.onCallSuppServiceReceived(ImsCall.this, suppServiceInfo); |
| 3071 | } catch (Throwable t) { |
| 3072 | loge("callSessionSuppServiceReceived :: ", t); |
| 3073 | } |
| 3074 | } |
| 3075 | } |
Hall Liu | bd3f377 | 2017-03-22 15:38:23 -0700 | [diff] [blame] | 3076 | |
| 3077 | @Override |
| 3078 | public void callSessionRttModifyRequestReceived(ImsCallSession session, |
| 3079 | ImsCallProfile callProfile) { |
| 3080 | ImsCall.Listener listener; |
Hall Liu | b77d897 | 2018-01-22 19:15:05 -0800 | [diff] [blame^] | 3081 | logi("callSessionRttModifyRequestReceived"); |
Hall Liu | bd3f377 | 2017-03-22 15:38:23 -0700 | [diff] [blame] | 3082 | |
| 3083 | synchronized(ImsCall.this) { |
| 3084 | listener = mListener; |
| 3085 | } |
| 3086 | |
| 3087 | if (!callProfile.mMediaProfile.isRttCall()) { |
| 3088 | logi("callSessionRttModifyRequestReceived:: ignoring request, requested profile " + |
| 3089 | "is not RTT."); |
| 3090 | return; |
| 3091 | } |
| 3092 | |
| 3093 | if (listener != null) { |
| 3094 | try { |
| 3095 | listener.onRttModifyRequestReceived(ImsCall.this); |
| 3096 | } catch (Throwable t) { |
| 3097 | loge("callSessionRttModifyRequestReceived:: ", t); |
| 3098 | } |
| 3099 | } |
| 3100 | } |
| 3101 | |
| 3102 | @Override |
| 3103 | public void callSessionRttModifyResponseReceived(int status) { |
| 3104 | ImsCall.Listener listener; |
| 3105 | |
Hall Liu | b77d897 | 2018-01-22 19:15:05 -0800 | [diff] [blame^] | 3106 | logi("callSessionRttModifyResponseReceived"); |
Hall Liu | bd3f377 | 2017-03-22 15:38:23 -0700 | [diff] [blame] | 3107 | synchronized(ImsCall.this) { |
| 3108 | listener = mListener; |
| 3109 | } |
| 3110 | |
| 3111 | if (listener != null) { |
| 3112 | try { |
| 3113 | listener.onRttModifyResponseReceived(ImsCall.this, status); |
| 3114 | } catch (Throwable t) { |
| 3115 | loge("callSessionRttModifyResponseReceived:: ", t); |
| 3116 | } |
| 3117 | } |
| 3118 | } |
| 3119 | |
| 3120 | @Override |
| 3121 | public void callSessionRttMessageReceived(String rttMessage) { |
| 3122 | ImsCall.Listener listener; |
| 3123 | |
| 3124 | synchronized(ImsCall.this) { |
| 3125 | listener = mListener; |
| 3126 | } |
| 3127 | |
| 3128 | if (listener != null) { |
| 3129 | try { |
| 3130 | listener.onRttMessageReceived(ImsCall.this, rttMessage); |
| 3131 | } catch (Throwable t) { |
| 3132 | loge("callSessionRttModifyResponseReceived:: ", t); |
| 3133 | } |
| 3134 | } |
| 3135 | } |
Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 3136 | } |
Tyler Gunn | 938116f | 2014-10-27 09:15:23 -0700 | [diff] [blame] | 3137 | |
| 3138 | /** |
| 3139 | * Report a new conference state to the current {@link ImsCall} and inform listeners of the |
| 3140 | * change. Marked as {@code VisibleForTesting} so that the |
| 3141 | * {@code com.android.internal.telephony.TelephonyTester} class can inject a test conference |
| 3142 | * event package into a regular ongoing IMS call. |
| 3143 | * |
| 3144 | * @param state The {@link ImsConferenceState}. |
| 3145 | */ |
| 3146 | @VisibleForTesting |
| 3147 | public void conferenceStateUpdated(ImsConferenceState state) { |
| 3148 | Listener listener; |
| 3149 | |
| 3150 | synchronized(this) { |
| 3151 | notifyConferenceStateUpdated(state); |
| 3152 | listener = mListener; |
| 3153 | } |
| 3154 | |
| 3155 | if (listener != null) { |
| 3156 | try { |
| 3157 | listener.onCallConferenceStateUpdated(this, state); |
| 3158 | } catch (Throwable t) { |
| 3159 | loge("callSessionConferenceStateUpdated :: ", t); |
| 3160 | } |
| 3161 | } |
| 3162 | } |
Tyler Gunn | 168c634 | 2014-11-18 08:40:49 -0800 | [diff] [blame] | 3163 | |
| 3164 | /** |
| 3165 | * Provides a human-readable string representation of an update request. |
| 3166 | * |
| 3167 | * @param updateRequest The update request. |
| 3168 | * @return The string representation. |
| 3169 | */ |
| 3170 | private String updateRequestToString(int updateRequest) { |
| 3171 | switch (updateRequest) { |
| 3172 | case UPDATE_NONE: |
| 3173 | return "NONE"; |
| 3174 | case UPDATE_HOLD: |
| 3175 | return "HOLD"; |
| 3176 | case UPDATE_HOLD_MERGE: |
| 3177 | return "HOLD_MERGE"; |
| 3178 | case UPDATE_RESUME: |
| 3179 | return "RESUME"; |
| 3180 | case UPDATE_MERGE: |
| 3181 | return "MERGE"; |
| 3182 | case UPDATE_EXTEND_TO_CONFERENCE: |
| 3183 | return "EXTEND_TO_CONFERENCE"; |
| 3184 | case UPDATE_UNSPECIFIED: |
| 3185 | return "UNSPECIFIED"; |
| 3186 | default: |
| 3187 | return "UNKNOWN"; |
| 3188 | } |
| 3189 | } |
| 3190 | |
| 3191 | /** |
Tyler Gunn | 9bd5ca5 | 2014-12-02 09:21:01 -0800 | [diff] [blame] | 3192 | * Clears the merge peer for this call, ensuring that the peer's connection to this call is also |
| 3193 | * severed at the same time. |
| 3194 | */ |
Anthony Lee | c479f66 | 2015-02-11 17:04:35 -0800 | [diff] [blame] | 3195 | private void clearMergeInfo() { |
Anthony Lee | 6804851 | 2015-03-18 15:04:18 -0700 | [diff] [blame] | 3196 | if (CONF_DBG) { |
| 3197 | logi("clearMergeInfo :: clearing all merge info"); |
Anthony Lee | c479f66 | 2015-02-11 17:04:35 -0800 | [diff] [blame] | 3198 | } |
Tyler Gunn | 047d810 | 2015-01-30 15:21:11 -0800 | [diff] [blame] | 3199 | |
Anthony Lee | c479f66 | 2015-02-11 17:04:35 -0800 | [diff] [blame] | 3200 | // First clear out the merge partner then clear ourselves out. |
Tyler Gunn | 9bd5ca5 | 2014-12-02 09:21:01 -0800 | [diff] [blame] | 3201 | if (mMergeHost != null) { |
| 3202 | mMergeHost.mMergePeer = null; |
Libin.Tang@motorola.com | 165aed5 | 2015-02-05 22:12:09 -0600 | [diff] [blame] | 3203 | mMergeHost.mUpdateRequest = UPDATE_NONE; |
Anthony Lee | c479f66 | 2015-02-11 17:04:35 -0800 | [diff] [blame] | 3204 | mMergeHost.mCallSessionMergePending = false; |
Tyler Gunn | 9bd5ca5 | 2014-12-02 09:21:01 -0800 | [diff] [blame] | 3205 | } |
Tyler Gunn | 9bd5ca5 | 2014-12-02 09:21:01 -0800 | [diff] [blame] | 3206 | if (mMergePeer != null) { |
| 3207 | mMergePeer.mMergeHost = null; |
Libin.Tang@motorola.com | 165aed5 | 2015-02-05 22:12:09 -0600 | [diff] [blame] | 3208 | mMergePeer.mUpdateRequest = UPDATE_NONE; |
Anthony Lee | c479f66 | 2015-02-11 17:04:35 -0800 | [diff] [blame] | 3209 | mMergePeer.mCallSessionMergePending = false; |
Tyler Gunn | 9bd5ca5 | 2014-12-02 09:21:01 -0800 | [diff] [blame] | 3210 | } |
Anthony Lee | c479f66 | 2015-02-11 17:04:35 -0800 | [diff] [blame] | 3211 | mMergeHost = null; |
| 3212 | mMergePeer = null; |
| 3213 | mUpdateRequest = UPDATE_NONE; |
| 3214 | mCallSessionMergePending = false; |
Tyler Gunn | 9bd5ca5 | 2014-12-02 09:21:01 -0800 | [diff] [blame] | 3215 | } |
| 3216 | |
| 3217 | /** |
| 3218 | * Sets the merge peer for the current call. The merge peer is the background call that will be |
| 3219 | * merged into this call. On the merge peer, sets the merge host to be this call. |
| 3220 | * |
| 3221 | * @param mergePeer The peer call to be merged into this one. |
| 3222 | */ |
| 3223 | private void setMergePeer(ImsCall mergePeer) { |
| 3224 | mMergePeer = mergePeer; |
| 3225 | mMergeHost = null; |
| 3226 | |
| 3227 | mergePeer.mMergeHost = ImsCall.this; |
| 3228 | mergePeer.mMergePeer = null; |
| 3229 | } |
| 3230 | |
| 3231 | /** |
| 3232 | * Sets the merge hody for the current call. The merge host is the foreground call this call |
| 3233 | * will be merged into. On the merge host, sets the merge peer to be this call. |
| 3234 | * |
| 3235 | * @param mergeHost The merge host this call will be merged into. |
| 3236 | */ |
| 3237 | public void setMergeHost(ImsCall mergeHost) { |
| 3238 | mMergeHost = mergeHost; |
| 3239 | mMergePeer = null; |
| 3240 | |
| 3241 | mergeHost.mMergeHost = null; |
| 3242 | mergeHost.mMergePeer = ImsCall.this; |
| 3243 | } |
| 3244 | |
| 3245 | /** |
| 3246 | * Determines if the current call is in the process of merging with another call or conference. |
| 3247 | * |
| 3248 | * @return {@code true} if in the process of merging. |
| 3249 | */ |
| 3250 | private boolean isMerging() { |
| 3251 | return mMergePeer != null || mMergeHost != null; |
| 3252 | } |
| 3253 | |
| 3254 | /** |
| 3255 | * Determines if the current call is the host of the merge. |
| 3256 | * |
| 3257 | * @return {@code true} if the call is the merge host. |
| 3258 | */ |
| 3259 | private boolean isMergeHost() { |
| 3260 | return mMergePeer != null && mMergeHost == null; |
| 3261 | } |
| 3262 | |
| 3263 | /** |
| 3264 | * Determines if the current call is the peer of the merge. |
| 3265 | * |
| 3266 | * @return {@code true} if the call is the merge peer. |
| 3267 | */ |
| 3268 | private boolean isMergePeer() { |
| 3269 | return mMergePeer == null && mMergeHost != null; |
| 3270 | } |
| 3271 | |
| 3272 | /** |
Tyler Gunn | 047d810 | 2015-01-30 15:21:11 -0800 | [diff] [blame] | 3273 | * Determines if the call session is pending merge into a conference or not. |
| 3274 | * |
| 3275 | * @return {@code true} if a merge into a conference is pending, {@code false} otherwise. |
| 3276 | */ |
Tyler Gunn | 083efaa | 2017-06-20 15:50:32 -0700 | [diff] [blame] | 3277 | public boolean isCallSessionMergePending() { |
Tyler Gunn | 047d810 | 2015-01-30 15:21:11 -0800 | [diff] [blame] | 3278 | return mCallSessionMergePending; |
| 3279 | } |
| 3280 | |
| 3281 | /** |
| 3282 | * Sets flag indicating whether the call session is pending merge into a conference or not. |
| 3283 | * |
| 3284 | * @param callSessionMergePending {@code true} if a merge into the conference is pending, |
| 3285 | * {@code false} otherwise. |
| 3286 | */ |
| 3287 | private void setCallSessionMergePending(boolean callSessionMergePending) { |
| 3288 | mCallSessionMergePending = callSessionMergePending; |
| 3289 | } |
| 3290 | |
| 3291 | /** |
| 3292 | * Determines if there is a conference merge in process. If there is a merge in process, |
| 3293 | * determines if both the merge host and peer sessions have completed the merge process. This |
| 3294 | * means that we have received terminate or hold signals for the sessions, indicating that they |
| 3295 | * are no longer in the process of being merged into the conference. |
| 3296 | * <p> |
Anthony Lee | c479f66 | 2015-02-11 17:04:35 -0800 | [diff] [blame] | 3297 | * The sessions are considered to have merged if: both calls still have merge peer/host |
| 3298 | * relationships configured, both sessions are not waiting to be merged into the conference, |
| 3299 | * and the transient conference session is alive in the case of an initial conference. |
Tyler Gunn | 047d810 | 2015-01-30 15:21:11 -0800 | [diff] [blame] | 3300 | * |
| 3301 | * @return {@code true} where the host and peer sessions have finished merging into the |
| 3302 | * conference, {@code false} if the merge has not yet completed, and {@code false} if there |
| 3303 | * is no conference merge in progress. |
| 3304 | */ |
Anthony Lee | c479f66 | 2015-02-11 17:04:35 -0800 | [diff] [blame] | 3305 | private boolean shouldProcessConferenceResult() { |
| 3306 | boolean areMergeTriggersDone = false; |
Tyler Gunn | 047d810 | 2015-01-30 15:21:11 -0800 | [diff] [blame] | 3307 | |
Anthony Lee | c479f66 | 2015-02-11 17:04:35 -0800 | [diff] [blame] | 3308 | synchronized (ImsCall.this) { |
| 3309 | // if there is a merge going on, then the merge host/peer relationships should have been |
| 3310 | // set up. This works for both the initial conference or merging a call into an |
| 3311 | // existing conference. |
| 3312 | if (!isMergeHost() && !isMergePeer()) { |
Anthony Lee | 6804851 | 2015-03-18 15:04:18 -0700 | [diff] [blame] | 3313 | if (CONF_DBG) { |
| 3314 | loge("shouldProcessConferenceResult :: no merge in progress"); |
Anthony Lee | c479f66 | 2015-02-11 17:04:35 -0800 | [diff] [blame] | 3315 | } |
| 3316 | return false; |
| 3317 | } |
| 3318 | |
| 3319 | // There is a merge in progress, so check the sessions to ensure: |
| 3320 | // 1. Both calls have completed being merged (or failing to merge) into the conference. |
| 3321 | // 2. The transient conference session is alive. |
| 3322 | if (isMergeHost()) { |
Anthony Lee | 6804851 | 2015-03-18 15:04:18 -0700 | [diff] [blame] | 3323 | if (CONF_DBG) { |
| 3324 | logi("shouldProcessConferenceResult :: We are a merge host"); |
| 3325 | logi("shouldProcessConferenceResult :: Here is the merge peer=" + mMergePeer); |
Anthony Lee | c479f66 | 2015-02-11 17:04:35 -0800 | [diff] [blame] | 3326 | } |
| 3327 | areMergeTriggersDone = !isCallSessionMergePending() && |
| 3328 | !mMergePeer.isCallSessionMergePending(); |
| 3329 | if (!isMultiparty()) { |
| 3330 | // Only check the transient session when there is no existing conference |
| 3331 | areMergeTriggersDone &= isSessionAlive(mTransientConferenceSession); |
| 3332 | } |
| 3333 | } else if (isMergePeer()) { |
Anthony Lee | 6804851 | 2015-03-18 15:04:18 -0700 | [diff] [blame] | 3334 | if (CONF_DBG) { |
| 3335 | logi("shouldProcessConferenceResult :: We are a merge peer"); |
| 3336 | logi("shouldProcessConferenceResult :: Here is the merge host=" + mMergeHost); |
Anthony Lee | c479f66 | 2015-02-11 17:04:35 -0800 | [diff] [blame] | 3337 | } |
| 3338 | areMergeTriggersDone = !isCallSessionMergePending() && |
| 3339 | !mMergeHost.isCallSessionMergePending(); |
| 3340 | if (!mMergeHost.isMultiparty()) { |
| 3341 | // Only check the transient session when there is no existing conference |
| 3342 | areMergeTriggersDone &= isSessionAlive(mMergeHost.mTransientConferenceSession); |
| 3343 | } else { |
| 3344 | // This else block is a special case for Verizon to handle these steps |
| 3345 | // 1. Establish a conference call. |
| 3346 | // 2. Add a new call (conference in in BG) |
| 3347 | // 3. Swap (conference active on FG) |
| 3348 | // 4. Merge |
| 3349 | // What happens here is that the BG call gets a terminated callback |
| 3350 | // because it was added to the conference. I've seen where |
| 3351 | // the FG gets no callback at all because its already active. |
| 3352 | // So if we continue to wait for it to set its isCallSessionMerging |
| 3353 | // flag to false...we'll be waiting forever. |
| 3354 | areMergeTriggersDone = !isCallSessionMergePending(); |
| 3355 | } |
| 3356 | } else { |
| 3357 | // Realistically this shouldn't happen, but best to be safe. |
| 3358 | loge("shouldProcessConferenceResult : merge in progress but call is neither" + |
Anthony Lee | 6804851 | 2015-03-18 15:04:18 -0700 | [diff] [blame] | 3359 | " host nor peer."); |
Anthony Lee | c479f66 | 2015-02-11 17:04:35 -0800 | [diff] [blame] | 3360 | } |
Anthony Lee | 6804851 | 2015-03-18 15:04:18 -0700 | [diff] [blame] | 3361 | if (CONF_DBG) { |
| 3362 | logi("shouldProcessConferenceResult :: returning:" + |
Anthony Lee | c479f66 | 2015-02-11 17:04:35 -0800 | [diff] [blame] | 3363 | (areMergeTriggersDone ? "true" : "false")); |
| 3364 | } |
Tyler Gunn | 047d810 | 2015-01-30 15:21:11 -0800 | [diff] [blame] | 3365 | } |
Anthony Lee | c479f66 | 2015-02-11 17:04:35 -0800 | [diff] [blame] | 3366 | return areMergeTriggersDone; |
Tyler Gunn | 047d810 | 2015-01-30 15:21:11 -0800 | [diff] [blame] | 3367 | } |
| 3368 | |
| 3369 | /** |
Tyler Gunn | 168c634 | 2014-11-18 08:40:49 -0800 | [diff] [blame] | 3370 | * Provides a string representation of the {@link ImsCall}. Primarily intended for use in log |
| 3371 | * statements. |
| 3372 | * |
| 3373 | * @return String representation of call. |
| 3374 | */ |
| 3375 | @Override |
| 3376 | public String toString() { |
| 3377 | StringBuilder sb = new StringBuilder(); |
| 3378 | sb.append("[ImsCall objId:"); |
| 3379 | sb.append(System.identityHashCode(this)); |
Tyler Gunn | 9bd5ca5 | 2014-12-02 09:21:01 -0800 | [diff] [blame] | 3380 | sb.append(" onHold:"); |
| 3381 | sb.append(isOnHold() ? "Y" : "N"); |
| 3382 | sb.append(" mute:"); |
| 3383 | sb.append(isMuted() ? "Y" : "N"); |
Pavel Zhamaitsiak | 50b03e9 | 2016-02-29 14:47:39 -0800 | [diff] [blame] | 3384 | if (mCallProfile != null) { |
Jack Yu | 9f71a24 | 2016-08-08 11:59:18 -0700 | [diff] [blame] | 3385 | sb.append(" mCallProfile:" + mCallProfile); |
Pavel Zhamaitsiak | 50b03e9 | 2016-02-29 14:47:39 -0800 | [diff] [blame] | 3386 | sb.append(" tech:"); |
| 3387 | sb.append(mCallProfile.getCallExtra(ImsCallProfile.EXTRA_CALL_RAT_TYPE)); |
| 3388 | } |
Tyler Gunn | 168c634 | 2014-11-18 08:40:49 -0800 | [diff] [blame] | 3389 | sb.append(" updateRequest:"); |
| 3390 | sb.append(updateRequestToString(mUpdateRequest)); |
Tyler Gunn | 87466c5 | 2014-12-08 09:56:17 -0800 | [diff] [blame] | 3391 | sb.append(" merging:"); |
| 3392 | sb.append(isMerging() ? "Y" : "N"); |
| 3393 | if (isMerging()) { |
| 3394 | if (isMergePeer()) { |
| 3395 | sb.append("P"); |
| 3396 | } else { |
| 3397 | sb.append("H"); |
| 3398 | } |
| 3399 | } |
Anthony Lee | c479f66 | 2015-02-11 17:04:35 -0800 | [diff] [blame] | 3400 | sb.append(" merge action pending:"); |
| 3401 | sb.append(isCallSessionMergePending() ? "Y" : "N"); |
Tyler Gunn | 87466c5 | 2014-12-08 09:56:17 -0800 | [diff] [blame] | 3402 | sb.append(" merged:"); |
| 3403 | sb.append(isMerged() ? "Y" : "N"); |
Tyler Gunn | 9bd5ca5 | 2014-12-02 09:21:01 -0800 | [diff] [blame] | 3404 | sb.append(" multiParty:"); |
| 3405 | sb.append(isMultiparty() ? "Y" : "N"); |
Tyler Gunn | 2539409 | 2015-04-01 09:40:02 -0700 | [diff] [blame] | 3406 | sb.append(" confHost:"); |
| 3407 | sb.append(isConferenceHost() ? "Y" : "N"); |
Anthony Lee | c479f66 | 2015-02-11 17:04:35 -0800 | [diff] [blame] | 3408 | sb.append(" buried term:"); |
| 3409 | sb.append(mSessionEndDuringMerge ? "Y" : "N"); |
Jack Yu | 9f71a24 | 2016-08-08 11:59:18 -0700 | [diff] [blame] | 3410 | sb.append(" isVideo: "); |
| 3411 | sb.append(isVideoCall() ? "Y" : "N"); |
Tyler Gunn | 1ac2485 | 2016-06-22 10:04:23 -0700 | [diff] [blame] | 3412 | sb.append(" wasVideo: "); |
| 3413 | sb.append(mWasVideoCall ? "Y" : "N"); |
Jack Yu | 9f71a24 | 2016-08-08 11:59:18 -0700 | [diff] [blame] | 3414 | sb.append(" isWifi: "); |
| 3415 | sb.append(isWifiCall() ? "Y" : "N"); |
Tyler Gunn | 9bd5ca5 | 2014-12-02 09:21:01 -0800 | [diff] [blame] | 3416 | sb.append(" session:"); |
| 3417 | sb.append(mSession); |
Tyler Gunn | 168c634 | 2014-11-18 08:40:49 -0800 | [diff] [blame] | 3418 | sb.append(" transientSession:"); |
| 3419 | sb.append(mTransientConferenceSession); |
| 3420 | sb.append("]"); |
| 3421 | return sb.toString(); |
| 3422 | } |
Anthony Lee | 6804851 | 2015-03-18 15:04:18 -0700 | [diff] [blame] | 3423 | |
| 3424 | private void throwImsException(Throwable t, int code) throws ImsException { |
| 3425 | if (t instanceof ImsException) { |
| 3426 | throw (ImsException) t; |
| 3427 | } else { |
| 3428 | throw new ImsException(String.valueOf(code), t, code); |
| 3429 | } |
| 3430 | } |
| 3431 | |
| 3432 | /** |
| 3433 | * Append the ImsCall information to the provided string. Usefull for as a logging helper. |
| 3434 | * @param s The original string |
| 3435 | * @return The original string with {@code ImsCall} information appended to it. |
| 3436 | */ |
| 3437 | private String appendImsCallInfoToString(String s) { |
| 3438 | StringBuilder sb = new StringBuilder(); |
| 3439 | sb.append(s); |
| 3440 | sb.append(" ImsCall="); |
| 3441 | sb.append(ImsCall.this); |
| 3442 | return sb.toString(); |
| 3443 | } |
| 3444 | |
| 3445 | /** |
Tyler Gunn | 1ac2485 | 2016-06-22 10:04:23 -0700 | [diff] [blame] | 3446 | * Updates {@link #mWasVideoCall} based on the current {@link ImsCallProfile} for the call. |
| 3447 | * |
| 3448 | * @param profile The current {@link ImsCallProfile} for the call. |
| 3449 | */ |
| 3450 | private void trackVideoStateHistory(ImsCallProfile profile) { |
| 3451 | mWasVideoCall = mWasVideoCall || profile.isVideoCall(); |
| 3452 | } |
| 3453 | |
| 3454 | /** |
| 3455 | * @return {@code true} if this call was a video call at some point in its life span, |
| 3456 | * {@code false} otherwise. |
| 3457 | */ |
| 3458 | public boolean wasVideoCall() { |
| 3459 | return mWasVideoCall; |
| 3460 | } |
| 3461 | |
| 3462 | /** |
| 3463 | * @return {@code true} if this call is a video call, {@code false} otherwise. |
| 3464 | */ |
| 3465 | public boolean isVideoCall() { |
| 3466 | synchronized(mLockObj) { |
| 3467 | return mCallProfile != null && mCallProfile.isVideoCall(); |
| 3468 | } |
| 3469 | } |
| 3470 | |
| 3471 | /** |
| 3472 | * Determines if the current call radio access technology is over WIFI. |
| 3473 | * Note: This depends on the RIL exposing the {@link ImsCallProfile#EXTRA_CALL_RAT_TYPE} extra. |
| 3474 | * This method is primarily intended to be used when checking if answering an incoming audio |
| 3475 | * call should cause a wifi video call to drop (e.g. |
| 3476 | * {@link android.telephony.CarrierConfigManager# |
| 3477 | * KEY_DROP_VIDEO_CALL_WHEN_ANSWERING_AUDIO_CALL_BOOL} is set). |
| 3478 | * |
| 3479 | * @return {@code true} if the call is over WIFI, {@code false} otherwise. |
| 3480 | */ |
| 3481 | public boolean isWifiCall() { |
| 3482 | synchronized(mLockObj) { |
| 3483 | if (mCallProfile == null) { |
| 3484 | return false; |
| 3485 | } |
Tyler Gunn | 730752a | 2017-08-17 15:55:53 -0700 | [diff] [blame] | 3486 | int radioTechnology = getRadioTechnology(); |
| 3487 | return radioTechnology == ServiceState.RIL_RADIO_TECHNOLOGY_IWLAN; |
| 3488 | } |
| 3489 | } |
| 3490 | |
| 3491 | /** |
| 3492 | * Determines the radio access technology for the {@link ImsCall}. |
| 3493 | * @return The {@link ServiceState} {@code RIL_RADIO_TECHNOLOGY_*} code in use. |
| 3494 | */ |
| 3495 | public int getRadioTechnology() { |
| 3496 | synchronized(mLockObj) { |
| 3497 | if (mCallProfile == null) { |
| 3498 | return ServiceState.RIL_RADIO_TECHNOLOGY_UNKNOWN; |
| 3499 | } |
Tyler Gunn | 1ac2485 | 2016-06-22 10:04:23 -0700 | [diff] [blame] | 3500 | String callType = mCallProfile.getCallExtra(ImsCallProfile.EXTRA_CALL_RAT_TYPE); |
Tyler Gunn | 8ae5fbb | 2016-07-13 17:24:04 -0700 | [diff] [blame] | 3501 | if (callType == null || callType.isEmpty()) { |
| 3502 | callType = mCallProfile.getCallExtra(ImsCallProfile.EXTRA_CALL_RAT_TYPE_ALT); |
| 3503 | } |
Tyler Gunn | 1ac2485 | 2016-06-22 10:04:23 -0700 | [diff] [blame] | 3504 | |
| 3505 | // The RIL (sadly) sends us the EXTRA_CALL_RAT_TYPE as a string extra, rather than an |
| 3506 | // integer extra, so we need to parse it. |
| 3507 | int radioTechnology = ServiceState.RIL_RADIO_TECHNOLOGY_UNKNOWN; |
| 3508 | try { |
| 3509 | radioTechnology = Integer.parseInt(callType); |
| 3510 | } catch (NumberFormatException nfe) { |
| 3511 | radioTechnology = ServiceState.RIL_RADIO_TECHNOLOGY_UNKNOWN; |
| 3512 | } |
| 3513 | |
Tyler Gunn | 730752a | 2017-08-17 15:55:53 -0700 | [diff] [blame] | 3514 | return radioTechnology; |
Tyler Gunn | 1ac2485 | 2016-06-22 10:04:23 -0700 | [diff] [blame] | 3515 | } |
| 3516 | } |
| 3517 | |
| 3518 | /** |
Anthony Lee | 6804851 | 2015-03-18 15:04:18 -0700 | [diff] [blame] | 3519 | * Log a string to the radio buffer at the info level. |
| 3520 | * @param s The message to log |
| 3521 | */ |
| 3522 | private void logi(String s) { |
| 3523 | Log.i(TAG, appendImsCallInfoToString(s)); |
| 3524 | } |
| 3525 | |
| 3526 | /** |
| 3527 | * Log a string to the radio buffer at the debug level. |
| 3528 | * @param s The message to log |
| 3529 | */ |
| 3530 | private void logd(String s) { |
| 3531 | Log.d(TAG, appendImsCallInfoToString(s)); |
| 3532 | } |
| 3533 | |
| 3534 | /** |
| 3535 | * Log a string to the radio buffer at the verbose level. |
| 3536 | * @param s The message to log |
| 3537 | */ |
| 3538 | private void logv(String s) { |
| 3539 | Log.v(TAG, appendImsCallInfoToString(s)); |
| 3540 | } |
| 3541 | |
| 3542 | /** |
| 3543 | * Log a string to the radio buffer at the error level. |
| 3544 | * @param s The message to log |
| 3545 | */ |
| 3546 | private void loge(String s) { |
| 3547 | Log.e(TAG, appendImsCallInfoToString(s)); |
| 3548 | } |
| 3549 | |
| 3550 | /** |
| 3551 | * Log a string to the radio buffer at the error level with a throwable |
| 3552 | * @param s The message to log |
| 3553 | * @param t The associated throwable |
| 3554 | */ |
| 3555 | private void loge(String s, Throwable t) { |
| 3556 | Log.e(TAG, appendImsCallInfoToString(s), t); |
| 3557 | } |
Wink Saville | ef36ef6 | 2014-06-11 08:39:38 -0700 | [diff] [blame] | 3558 | } |