ImsPhoneCallTracker.java revision 276bc50374a46461b334fef28fdf07b536d96c71
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 17package com.android.internal.telephony.imsphone; 18 19import java.io.FileDescriptor; 20import java.io.PrintWriter; 21import java.util.ArrayList; 22import java.util.List; 23 24import android.app.PendingIntent; 25import android.content.BroadcastReceiver; 26import android.content.Context; 27import android.content.Intent; 28import android.content.IntentFilter; 29import android.content.SharedPreferences; 30import android.os.AsyncResult; 31import android.os.Handler; 32import android.os.Message; 33import android.os.Registrant; 34import android.os.RegistrantList; 35import android.os.RemoteException; 36import android.os.SystemProperties; 37import android.provider.Settings; 38import android.preference.PreferenceManager; 39import android.telecom.ConferenceParticipant; 40import android.telecom.VideoProfile; 41import android.telephony.DisconnectCause; 42import android.telephony.PhoneNumberUtils; 43import android.telephony.Rlog; 44import android.telephony.ServiceState; 45 46import com.android.ims.ImsCall; 47import com.android.ims.ImsCallProfile; 48import com.android.ims.ImsConfig; 49import com.android.ims.ImsConnectionStateListener; 50import com.android.ims.ImsEcbm; 51import com.android.ims.ImsException; 52import com.android.ims.ImsManager; 53import com.android.ims.ImsReasonInfo; 54import com.android.ims.ImsServiceClass; 55import com.android.ims.ImsUtInterface; 56import com.android.ims.internal.IImsVideoCallProvider; 57import com.android.ims.internal.ImsVideoCallProviderWrapper; 58import com.android.internal.telephony.Call; 59import com.android.internal.telephony.CallStateException; 60import com.android.internal.telephony.CallTracker; 61import com.android.internal.telephony.CommandException; 62import com.android.internal.telephony.CommandsInterface; 63import com.android.internal.telephony.Connection; 64import com.android.internal.telephony.Phone; 65import com.android.internal.telephony.PhoneBase; 66import com.android.internal.telephony.PhoneConstants; 67import com.android.internal.telephony.TelephonyProperties; 68 69/** 70 * {@hide} 71 */ 72public final class ImsPhoneCallTracker extends CallTracker { 73 static final String LOG_TAG = "ImsPhoneCallTracker"; 74 75 private static final boolean DBG = true; 76 77 private boolean mIsVolteEnabled = false; 78 private boolean mIsVtEnabled = false; 79 80 private BroadcastReceiver mReceiver = new BroadcastReceiver() { 81 @Override 82 public void onReceive(Context context, Intent intent) { 83 if (intent.getAction().equals(ImsManager.ACTION_IMS_INCOMING_CALL)) { 84 if (DBG) log("onReceive : incoming call intent"); 85 86 if (mImsManager == null) return; 87 88 if (mServiceId < 0) return; 89 90 try { 91 // Network initiated USSD will be treated by mImsUssdListener 92 boolean isUssd = intent.getBooleanExtra(ImsManager.EXTRA_USSD, false); 93 if (isUssd) { 94 if (DBG) log("onReceive : USSD"); 95 mUssdSession = mImsManager.takeCall(mServiceId, intent, mImsUssdListener); 96 if (mUssdSession != null) { 97 mUssdSession.accept(ImsCallProfile.CALL_TYPE_VOICE); 98 } 99 return; 100 } 101 102 // Normal MT call 103 ImsCall imsCall = mImsManager.takeCall(mServiceId, intent, mImsCallListener); 104 ImsPhoneConnection conn = new ImsPhoneConnection(mPhone.getContext(), imsCall, 105 ImsPhoneCallTracker.this, mRingingCall); 106 addConnection(conn); 107 108 IImsVideoCallProvider imsVideoCallProvider = 109 imsCall.getCallSession().getVideoCallProvider(); 110 if (imsVideoCallProvider != null) { 111 ImsVideoCallProviderWrapper imsVideoCallProviderWrapper = 112 new ImsVideoCallProviderWrapper(imsVideoCallProvider); 113 conn.setVideoProvider(imsVideoCallProviderWrapper); 114 } 115 116 if ((mForegroundCall.getState() != ImsPhoneCall.State.IDLE) || 117 (mBackgroundCall.getState() != ImsPhoneCall.State.IDLE)) { 118 conn.update(imsCall, ImsPhoneCall.State.WAITING); 119 } 120 121 mPhone.notifyNewRingingConnection(conn); 122 mPhone.notifyIncomingRing(); 123 124 updatePhoneState(); 125 mPhone.notifyPreciseCallStateChanged(); 126 } catch (ImsException e) { 127 loge("onReceive : exception " + e); 128 } catch (RemoteException e) { 129 } 130 } 131 } 132 }; 133 134 //***** Constants 135 136 static final int MAX_CONNECTIONS = 7; 137 static final int MAX_CONNECTIONS_PER_CALL = 5; 138 139 private static final int EVENT_HANGUP_PENDINGMO = 18; 140 private static final int EVENT_RESUME_BACKGROUND = 19; 141 private static final int EVENT_DIAL_PENDINGMO = 20; 142 143 private static final int TIMEOUT_HANGUP_PENDINGMO = 500; 144 145 //***** Instance Variables 146 private ArrayList<ImsPhoneConnection> mConnections = new ArrayList<ImsPhoneConnection>(); 147 private RegistrantList mVoiceCallEndedRegistrants = new RegistrantList(); 148 private RegistrantList mVoiceCallStartedRegistrants = new RegistrantList(); 149 150 ImsPhoneCall mRingingCall = new ImsPhoneCall(this); 151 ImsPhoneCall mForegroundCall = new ImsPhoneCall(this); 152 ImsPhoneCall mBackgroundCall = new ImsPhoneCall(this); 153 ImsPhoneCall mHandoverCall = new ImsPhoneCall(this); 154 155 private ImsPhoneConnection mPendingMO; 156 private int mClirMode = CommandsInterface.CLIR_DEFAULT; 157 private Object mSyncHold = new Object(); 158 159 private ImsCall mUssdSession = null; 160 private Message mPendingUssd = null; 161 162 ImsPhone mPhone; 163 164 private boolean mDesiredMute = false; // false = mute off 165 private boolean mOnHoldToneStarted = false; 166 167 PhoneConstants.State mState = PhoneConstants.State.IDLE; 168 169 private ImsManager mImsManager; 170 private int mServiceId = -1; 171 172 private Call.SrvccState mSrvccState = Call.SrvccState.NONE; 173 174 private boolean mIsInEmergencyCall = false; 175 176 private int pendingCallClirMode; 177 private int pendingCallVideoState; 178 private boolean pendingCallInEcm = false; 179 private boolean mSwitchingFgAndBgCalls = false; 180 private ImsCall mCallExpectedToResume = null; 181 182 //***** Events 183 184 185 //***** Constructors 186 187 ImsPhoneCallTracker(ImsPhone phone) { 188 this.mPhone = phone; 189 190 IntentFilter intentfilter = new IntentFilter(); 191 intentfilter.addAction(ImsManager.ACTION_IMS_INCOMING_CALL); 192 mPhone.getContext().registerReceiver(mReceiver, intentfilter); 193 194 Thread t = new Thread() { 195 public void run() { 196 getImsService(); 197 } 198 }; 199 t.start(); 200 } 201 202 private PendingIntent createIncomingCallPendingIntent() { 203 Intent intent = new Intent(ImsManager.ACTION_IMS_INCOMING_CALL); 204 intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND); 205 return PendingIntent.getBroadcast(mPhone.getContext(), 0, intent, 206 PendingIntent.FLAG_UPDATE_CURRENT); 207 } 208 209 private void getImsService() { 210 if (DBG) log("getImsService"); 211 mImsManager = ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId()); 212 try { 213 mServiceId = mImsManager.open(ImsServiceClass.MMTEL, 214 createIncomingCallPendingIntent(), 215 mImsConnectionStateListener); 216 217 // Get the ECBM interface and set IMSPhone's listener object for notifications 218 getEcbmInterface().setEcbmStateListener(mPhone.mImsEcbmStateListener); 219 if (mPhone.isInEcm()) { 220 // Call exit ECBM which will invoke onECBMExited 221 mPhone.exitEmergencyCallbackMode(); 222 } 223 int mPreferredTtyMode = Settings.Secure.getInt( 224 mPhone.getContext().getContentResolver(), 225 Settings.Secure.PREFERRED_TTY_MODE, 226 Phone.TTY_MODE_OFF); 227 mImsManager.setUiTTYMode(mServiceId, mPreferredTtyMode, null); 228 229 } catch (ImsException e) { 230 loge("getImsService: " + e); 231 //Leave mImsManager as null, then CallStateException will be thrown when dialing 232 mImsManager = null; 233 } 234 } 235 236 public void dispose() { 237 if (DBG) log("dispose"); 238 mRingingCall.dispose(); 239 mBackgroundCall.dispose(); 240 mForegroundCall.dispose(); 241 mHandoverCall.dispose(); 242 243 clearDisconnected(); 244 mPhone.getContext().unregisterReceiver(mReceiver); 245 } 246 247 @Override 248 protected void finalize() { 249 log("ImsPhoneCallTracker finalized"); 250 } 251 252 //***** Instance Methods 253 254 //***** Public Methods 255 @Override 256 public void registerForVoiceCallStarted(Handler h, int what, Object obj) { 257 Registrant r = new Registrant(h, what, obj); 258 mVoiceCallStartedRegistrants.add(r); 259 } 260 261 @Override 262 public void unregisterForVoiceCallStarted(Handler h) { 263 mVoiceCallStartedRegistrants.remove(h); 264 } 265 266 @Override 267 public void registerForVoiceCallEnded(Handler h, int what, Object obj) { 268 Registrant r = new Registrant(h, what, obj); 269 mVoiceCallEndedRegistrants.add(r); 270 } 271 272 @Override 273 public void unregisterForVoiceCallEnded(Handler h) { 274 mVoiceCallEndedRegistrants.remove(h); 275 } 276 277 Connection 278 dial(String dialString, int videoState) throws CallStateException { 279 SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(mPhone.getContext()); 280 int oirMode = sp.getInt(PhoneBase.CLIR_KEY, CommandsInterface.CLIR_DEFAULT); 281 return dial(dialString, oirMode, videoState); 282 } 283 284 /** 285 * oirMode is one of the CLIR_ constants 286 */ 287 synchronized Connection 288 dial(String dialString, int clirMode, int videoState) throws CallStateException { 289 boolean isPhoneInEcmMode = SystemProperties.getBoolean( 290 TelephonyProperties.PROPERTY_INECM_MODE, false); 291 boolean isEmergencyNumber = PhoneNumberUtils.isEmergencyNumber(dialString); 292 293 if (DBG) log("dial clirMode=" + clirMode); 294 295 // note that this triggers call state changed notif 296 clearDisconnected(); 297 298 if (mImsManager == null) { 299 throw new CallStateException("service not available"); 300 } 301 302 if (!canDial()) { 303 throw new CallStateException("cannot dial in current state"); 304 } 305 306 if (isPhoneInEcmMode && isEmergencyNumber) { 307 handleEcmTimer(ImsPhone.CANCEL_ECM_TIMER); 308 } 309 310 boolean holdBeforeDial = false; 311 312 // The new call must be assigned to the foreground call. 313 // That call must be idle, so place anything that's 314 // there on hold 315 if (mForegroundCall.getState() == ImsPhoneCall.State.ACTIVE) { 316 if (mBackgroundCall.getState() != ImsPhoneCall.State.IDLE) { 317 //we should have failed in !canDial() above before we get here 318 throw new CallStateException("cannot dial in current state"); 319 } 320 // foreground call is empty for the newly dialed connection 321 holdBeforeDial = true; 322 switchWaitingOrHoldingAndActive(); 323 } 324 325 ImsPhoneCall.State fgState = ImsPhoneCall.State.IDLE; 326 ImsPhoneCall.State bgState = ImsPhoneCall.State.IDLE; 327 328 mClirMode = clirMode; 329 330 synchronized (mSyncHold) { 331 if (holdBeforeDial) { 332 fgState = mForegroundCall.getState(); 333 bgState = mBackgroundCall.getState(); 334 335 //holding foreground call failed 336 if (fgState == ImsPhoneCall.State.ACTIVE) { 337 throw new CallStateException("cannot dial in current state"); 338 } 339 340 //holding foreground call succeeded 341 if (bgState == ImsPhoneCall.State.HOLDING) { 342 holdBeforeDial = false; 343 } 344 } 345 346 mPendingMO = new ImsPhoneConnection(mPhone.getContext(), 347 checkForTestEmergencyNumber(dialString), this, mForegroundCall); 348 } 349 addConnection(mPendingMO); 350 351 if (!holdBeforeDial) { 352 if ((!isPhoneInEcmMode) || (isPhoneInEcmMode && isEmergencyNumber)) { 353 dialInternal(mPendingMO, clirMode, videoState); 354 } else { 355 try { 356 getEcbmInterface().exitEmergencyCallbackMode(); 357 } catch (ImsException e) { 358 e.printStackTrace(); 359 throw new CallStateException("service not available"); 360 } 361 mPhone.setOnEcbModeExitResponse(this, EVENT_EXIT_ECM_RESPONSE_CDMA, null); 362 pendingCallClirMode = clirMode; 363 pendingCallVideoState = videoState; 364 pendingCallInEcm = true; 365 } 366 } 367 368 updatePhoneState(); 369 mPhone.notifyPreciseCallStateChanged(); 370 371 return mPendingMO; 372 } 373 374 private void handleEcmTimer(int action) { 375 mPhone.handleTimerInEmergencyCallbackMode(action); 376 switch (action) { 377 case ImsPhone.CANCEL_ECM_TIMER: 378 break; 379 case ImsPhone.RESTART_ECM_TIMER: 380 break; 381 default: 382 log("handleEcmTimer, unsupported action " + action); 383 } 384 } 385 386 private void dialInternal(ImsPhoneConnection conn, int clirMode, int videoState) { 387 if (conn == null) { 388 return; 389 } 390 391 if (conn.getAddress()== null || conn.getAddress().length() == 0 392 || conn.getAddress().indexOf(PhoneNumberUtils.WILD) >= 0) { 393 // Phone number is invalid 394 conn.setDisconnectCause(DisconnectCause.INVALID_NUMBER); 395 sendEmptyMessageDelayed(EVENT_HANGUP_PENDINGMO, TIMEOUT_HANGUP_PENDINGMO); 396 return; 397 } 398 399 // Always unmute when initiating a new call 400 setMute(false); 401 int serviceType = PhoneNumberUtils.isEmergencyNumber(conn.getAddress()) ? 402 ImsCallProfile.SERVICE_TYPE_EMERGENCY : ImsCallProfile.SERVICE_TYPE_NORMAL; 403 int callType = ImsCallProfile.getCallTypeFromVideoState(videoState); 404 //TODO(vt): Is this sufficient? At what point do we know the video state of the call? 405 conn.setVideoState(videoState); 406 407 try { 408 String[] callees = new String[] { conn.getAddress() }; 409 ImsCallProfile profile = mImsManager.createCallProfile(mServiceId, 410 serviceType, callType); 411 profile.setCallExtraInt(ImsCallProfile.EXTRA_OIR, clirMode); 412 413 ImsCall imsCall = mImsManager.makeCall(mServiceId, profile, 414 callees, mImsCallListener); 415 conn.setImsCall(imsCall); 416 417 IImsVideoCallProvider imsVideoCallProvider = 418 imsCall.getCallSession().getVideoCallProvider(); 419 if (imsVideoCallProvider != null) { 420 ImsVideoCallProviderWrapper imsVideoCallProviderWrapper = 421 new ImsVideoCallProviderWrapper(imsVideoCallProvider); 422 conn.setVideoProvider(imsVideoCallProviderWrapper); 423 } 424 } catch (ImsException e) { 425 loge("dialInternal : " + e); 426 conn.setDisconnectCause(DisconnectCause.ERROR_UNSPECIFIED); 427 sendEmptyMessageDelayed(EVENT_HANGUP_PENDINGMO, TIMEOUT_HANGUP_PENDINGMO); 428 } catch (RemoteException e) { 429 } 430 } 431 432 /** 433 * Accepts a call with the specified video state. The video state is the video state that the 434 * user has agreed upon in the InCall UI. 435 * 436 * @param videoState The video State 437 * @throws CallStateException 438 */ 439 void acceptCall (int videoState) throws CallStateException { 440 if (DBG) log("acceptCall"); 441 442 if (mForegroundCall.getState().isAlive() 443 && mBackgroundCall.getState().isAlive()) { 444 throw new CallStateException("cannot accept call"); 445 } 446 447 if ((mRingingCall.getState() == ImsPhoneCall.State.WAITING) 448 && mForegroundCall.getState().isAlive()) { 449 setMute(false); 450 switchWaitingOrHoldingAndActive(); 451 } else if (mRingingCall.getState().isRinging()) { 452 if (DBG) log("acceptCall: incoming..."); 453 // Always unmute when answering a new call 454 setMute(false); 455 try { 456 ImsCall imsCall = mRingingCall.getImsCall(); 457 if (imsCall != null) { 458 imsCall.accept(ImsCallProfile.getCallTypeFromVideoState(videoState)); 459 } else { 460 throw new CallStateException("no valid ims call"); 461 } 462 } catch (ImsException e) { 463 throw new CallStateException("cannot accept call"); 464 } 465 } else { 466 throw new CallStateException("phone not ringing"); 467 } 468 } 469 470 void 471 rejectCall () throws CallStateException { 472 if (DBG) log("rejectCall"); 473 474 if (mRingingCall.getState().isRinging()) { 475 hangup(mRingingCall); 476 } else { 477 throw new CallStateException("phone not ringing"); 478 } 479 } 480 481 void 482 switchWaitingOrHoldingAndActive() throws CallStateException { 483 if (DBG) log("switchWaitingOrHoldingAndActive"); 484 485 if (mRingingCall.getState() == ImsPhoneCall.State.INCOMING) { 486 throw new CallStateException("cannot be in the incoming state"); 487 } 488 489 if (mForegroundCall.getState() == ImsPhoneCall.State.ACTIVE) { 490 ImsCall imsCall = mForegroundCall.getImsCall(); 491 if (imsCall == null) { 492 throw new CallStateException("no ims call"); 493 } 494 495 // Swap the ImsCalls pointed to by the foreground and background ImsPhoneCalls. 496 // If hold or resume later fails, we will swap them back. 497 mSwitchingFgAndBgCalls = true; 498 mCallExpectedToResume = mBackgroundCall.getImsCall(); 499 mForegroundCall.switchWith(mBackgroundCall); 500 501 // Hold the foreground call; once the foreground call is held, the background call will 502 // be resumed. 503 try { 504 imsCall.hold(); 505 } catch (ImsException e) { 506 mForegroundCall.switchWith(mBackgroundCall); 507 throw new CallStateException(e.getMessage()); 508 } 509 } else if (mBackgroundCall.getState() == ImsPhoneCall.State.HOLDING) { 510 resumeWaitingOrHolding(); 511 } 512 } 513 514 void 515 conference() { 516 if (DBG) log("conference"); 517 518 ImsCall fgImsCall = mForegroundCall.getImsCall(); 519 if (fgImsCall == null) { 520 log("conference no foreground ims call"); 521 return; 522 } 523 524 ImsCall bgImsCall = mBackgroundCall.getImsCall(); 525 if (bgImsCall == null) { 526 log("conference no background ims call"); 527 return; 528 } 529 530 try { 531 fgImsCall.merge(bgImsCall); 532 } catch (ImsException e) { 533 log("conference " + e.getMessage()); 534 } 535 } 536 537 void 538 explicitCallTransfer() { 539 //TODO : implement 540 } 541 542 void 543 clearDisconnected() { 544 if (DBG) log("clearDisconnected"); 545 546 internalClearDisconnected(); 547 548 updatePhoneState(); 549 mPhone.notifyPreciseCallStateChanged(); 550 } 551 552 boolean 553 canConference() { 554 return mForegroundCall.getState() == ImsPhoneCall.State.ACTIVE 555 && mBackgroundCall.getState() == ImsPhoneCall.State.HOLDING 556 && !mBackgroundCall.isFull() 557 && !mForegroundCall.isFull(); 558 } 559 560 boolean 561 canDial() { 562 boolean ret; 563 int serviceState = mPhone.getServiceState().getState(); 564 String disableCall = SystemProperties.get( 565 TelephonyProperties.PROPERTY_DISABLE_CALL, "false"); 566 567 ret = (serviceState != ServiceState.STATE_POWER_OFF) 568 && mPendingMO == null 569 && !mRingingCall.isRinging() 570 && !disableCall.equals("true") 571 && (!mForegroundCall.getState().isAlive() 572 || !mBackgroundCall.getState().isAlive()); 573 574 return ret; 575 } 576 577 boolean 578 canTransfer() { 579 return mForegroundCall.getState() == ImsPhoneCall.State.ACTIVE 580 && mBackgroundCall.getState() == ImsPhoneCall.State.HOLDING; 581 } 582 583 //***** Private Instance Methods 584 585 private void 586 internalClearDisconnected() { 587 mRingingCall.clearDisconnected(); 588 mForegroundCall.clearDisconnected(); 589 mBackgroundCall.clearDisconnected(); 590 mHandoverCall.clearDisconnected(); 591 } 592 593 private void 594 updatePhoneState() { 595 PhoneConstants.State oldState = mState; 596 597 if (mRingingCall.isRinging()) { 598 mState = PhoneConstants.State.RINGING; 599 } else if (mPendingMO != null || 600 !(mForegroundCall.isIdle() && mBackgroundCall.isIdle())) { 601 mState = PhoneConstants.State.OFFHOOK; 602 } else { 603 mState = PhoneConstants.State.IDLE; 604 } 605 606 if (mState == PhoneConstants.State.IDLE && oldState != mState) { 607 mVoiceCallEndedRegistrants.notifyRegistrants( 608 new AsyncResult(null, null, null)); 609 } else if (oldState == PhoneConstants.State.IDLE && oldState != mState) { 610 mVoiceCallStartedRegistrants.notifyRegistrants ( 611 new AsyncResult(null, null, null)); 612 } 613 614 if (DBG) log("updatePhoneState oldState=" + oldState + ", newState=" + mState); 615 616 if (mState != oldState) { 617 mPhone.notifyPhoneStateChanged(); 618 } 619 } 620 621 private void 622 handleRadioNotAvailable() { 623 // handlePollCalls will clear out its 624 // call list when it gets the CommandException 625 // error result from this 626 pollCallsWhenSafe(); 627 } 628 629 private void 630 dumpState() { 631 List l; 632 633 log("Phone State:" + mState); 634 635 log("Ringing call: " + mRingingCall.toString()); 636 637 l = mRingingCall.getConnections(); 638 for (int i = 0, s = l.size(); i < s; i++) { 639 log(l.get(i).toString()); 640 } 641 642 log("Foreground call: " + mForegroundCall.toString()); 643 644 l = mForegroundCall.getConnections(); 645 for (int i = 0, s = l.size(); i < s; i++) { 646 log(l.get(i).toString()); 647 } 648 649 log("Background call: " + mBackgroundCall.toString()); 650 651 l = mBackgroundCall.getConnections(); 652 for (int i = 0, s = l.size(); i < s; i++) { 653 log(l.get(i).toString()); 654 } 655 656 } 657 658 //***** Called from ImsPhone 659 660 void setUiTTYMode(int uiTtyMode, Message onComplete) { 661 try { 662 mImsManager.setUiTTYMode(mServiceId, uiTtyMode, onComplete); 663 } catch (ImsException e) { 664 loge("setTTYMode : " + e); 665 mPhone.sendErrorResponse(onComplete, e); 666 } 667 } 668 669 /*package*/ void 670 setMute(boolean mute) { 671 mDesiredMute = mute; 672 mForegroundCall.setMute(mute); 673 } 674 675 /*package*/ boolean 676 getMute() { 677 return mDesiredMute; 678 } 679 680 /*package*/ void 681 sendDtmf(char c) { 682 if (DBG) log("sendDtmf"); 683 684 ImsCall imscall = mForegroundCall.getImsCall(); 685 if (imscall != null) { 686 imscall.sendDtmf(c); 687 } 688 } 689 690 //***** Called from ImsPhoneConnection 691 692 /*package*/ void 693 hangup (ImsPhoneConnection conn) throws CallStateException { 694 if (DBG) log("hangup connection"); 695 696 if (conn.getOwner() != this) { 697 throw new CallStateException ("ImsPhoneConnection " + conn 698 + "does not belong to ImsPhoneCallTracker " + this); 699 } 700 701 hangup(conn.getCall()); 702 } 703 704 //***** Called from ImsPhoneCall 705 706 /* package */ void 707 hangup (ImsPhoneCall call) throws CallStateException { 708 if (DBG) log("hangup call"); 709 710 if (call.getConnections().size() == 0) { 711 throw new CallStateException("no connections"); 712 } 713 714 ImsCall imsCall = call.getImsCall(); 715 boolean rejectCall = false; 716 717 if (call == mRingingCall) { 718 if (Phone.DEBUG_PHONE) log("(ringing) hangup incoming"); 719 rejectCall = true; 720 } else if (call == mForegroundCall) { 721 if (call.isDialingOrAlerting()) { 722 if (Phone.DEBUG_PHONE) { 723 log("(foregnd) hangup dialing or alerting..."); 724 } 725 } else { 726 if (Phone.DEBUG_PHONE) { 727 log("(foregnd) hangup foreground"); 728 } 729 //held call will be resumed by onCallTerminated 730 } 731 } else if (call == mBackgroundCall) { 732 if (Phone.DEBUG_PHONE) { 733 log("(backgnd) hangup waiting or background"); 734 } 735 } else { 736 throw new CallStateException ("ImsPhoneCall " + call + 737 "does not belong to ImsPhoneCallTracker " + this); 738 } 739 740 call.onHangupLocal(); 741 742 try { 743 if (imsCall != null) { 744 if (rejectCall) imsCall.reject(ImsReasonInfo.CODE_USER_DECLINE); 745 else imsCall.terminate(ImsReasonInfo.CODE_USER_TERMINATED); 746 } else if (mPendingMO != null && call == mForegroundCall) { 747 // is holding a foreground call 748 mPendingMO.update(null, ImsPhoneCall.State.DISCONNECTED); 749 mPendingMO.onDisconnect(); 750 removeConnection(mPendingMO); 751 mPendingMO = null; 752 updatePhoneState(); 753 removeMessages(EVENT_DIAL_PENDINGMO); 754 } 755 } catch (ImsException e) { 756 throw new CallStateException(e.getMessage()); 757 } 758 759 mPhone.notifyPreciseCallStateChanged(); 760 } 761 762 /* package */ 763 void resumeWaitingOrHolding() throws CallStateException { 764 if (DBG) log("resumeWaitingOrHolding"); 765 766 try { 767 if (mForegroundCall.getState().isAlive()) { 768 //resume foreground call after holding background call 769 //they were switched before holding 770 ImsCall imsCall = mForegroundCall.getImsCall(); 771 if (imsCall != null) imsCall.resume(); 772 } else if (mRingingCall.getState() == ImsPhoneCall.State.WAITING) { 773 //accept waiting call after holding background call 774 ImsCall imsCall = mRingingCall.getImsCall(); 775 if (imsCall != null) imsCall.accept(ImsCallProfile.CALL_TYPE_VOICE); 776 } else { 777 //Just resume background call. 778 //To distinguish resuming call with swapping calls 779 //we do not switch calls.here 780 //ImsPhoneConnection.update will chnage the parent when completed 781 ImsCall imsCall = mBackgroundCall.getImsCall(); 782 if (imsCall != null) imsCall.resume(); 783 } 784 } catch (ImsException e) { 785 throw new CallStateException(e.getMessage()); 786 } 787 } 788 789 /* package */ 790 void sendUSSD (String ussdString, Message response) { 791 if (DBG) log("sendUSSD"); 792 793 try { 794 if (mUssdSession != null) { 795 mUssdSession.sendUssd(ussdString); 796 AsyncResult.forMessage(response, null, null); 797 response.sendToTarget(); 798 return; 799 } 800 801 String[] callees = new String[] { ussdString }; 802 ImsCallProfile profile = mImsManager.createCallProfile(mServiceId, 803 ImsCallProfile.SERVICE_TYPE_NORMAL, ImsCallProfile.CALL_TYPE_VOICE); 804 profile.setCallExtraInt(ImsCallProfile.EXTRA_DIALSTRING, 805 ImsCallProfile.DIALSTRING_USSD); 806 807 mUssdSession = mImsManager.makeCall(mServiceId, profile, 808 callees, mImsUssdListener); 809 } catch (ImsException e) { 810 loge("sendUSSD : " + e); 811 mPhone.sendErrorResponse(response, e); 812 } 813 } 814 815 /* package */ 816 void cancelUSSD() { 817 if (mUssdSession == null) return; 818 819 try { 820 mUssdSession.terminate(ImsReasonInfo.CODE_USER_TERMINATED); 821 } catch (ImsException e) { 822 } 823 824 } 825 826 private synchronized ImsPhoneConnection findConnection(ImsCall imsCall) { 827 for (ImsPhoneConnection conn : mConnections) { 828 if (conn.getImsCall() == imsCall) { 829 return conn; 830 } 831 } 832 return null; 833 } 834 835 private synchronized void removeConnection(ImsPhoneConnection conn) { 836 mConnections.remove(conn); 837 } 838 839 private synchronized void addConnection(ImsPhoneConnection conn) { 840 mConnections.add(conn); 841 } 842 843 private void processCallStateChange(ImsCall imsCall, ImsPhoneCall.State state, int cause) { 844 if (DBG) log("processCallStateChange " + imsCall + " state=" + state + " cause=" + cause); 845 846 if (imsCall == null) return; 847 848 boolean changed = false; 849 ImsPhoneConnection conn = findConnection(imsCall); 850 851 if (conn == null) { 852 // TODO : what should be done? 853 return; 854 } 855 856 changed = conn.update(imsCall, state); 857 858 if (state == ImsPhoneCall.State.DISCONNECTED) { 859 changed = conn.onDisconnect(cause) || changed; 860 removeConnection(conn); 861 } 862 863 if (changed) { 864 if (conn.getCall() == mHandoverCall) return; 865 updatePhoneState(); 866 mPhone.notifyPreciseCallStateChanged(); 867 } 868 } 869 870 private int getDisconnectCauseFromReasonInfo(ImsReasonInfo reasonInfo) { 871 int cause = DisconnectCause.ERROR_UNSPECIFIED; 872 873 //int type = reasonInfo.getReasonType(); 874 int code = reasonInfo.getCode(); 875 switch (code) { 876 case ImsReasonInfo.CODE_SIP_BAD_ADDRESS: 877 case ImsReasonInfo.CODE_SIP_NOT_REACHABLE: 878 return DisconnectCause.NUMBER_UNREACHABLE; 879 880 case ImsReasonInfo.CODE_SIP_BUSY: 881 return DisconnectCause.BUSY; 882 883 case ImsReasonInfo.CODE_USER_TERMINATED: 884 return DisconnectCause.LOCAL; 885 886 case ImsReasonInfo.CODE_LOCAL_CALL_DECLINE: 887 return DisconnectCause.INCOMING_REJECTED; 888 889 case ImsReasonInfo.CODE_USER_TERMINATED_BY_REMOTE: 890 return DisconnectCause.NORMAL; 891 892 case ImsReasonInfo.CODE_SIP_REDIRECTED: 893 case ImsReasonInfo.CODE_SIP_BAD_REQUEST: 894 case ImsReasonInfo.CODE_SIP_FORBIDDEN: 895 case ImsReasonInfo.CODE_SIP_NOT_ACCEPTABLE: 896 case ImsReasonInfo.CODE_SIP_USER_REJECTED: 897 case ImsReasonInfo.CODE_SIP_GLOBAL_ERROR: 898 return DisconnectCause.SERVER_ERROR; 899 900 case ImsReasonInfo.CODE_SIP_SERVICE_UNAVAILABLE: 901 case ImsReasonInfo.CODE_SIP_NOT_FOUND: 902 case ImsReasonInfo.CODE_SIP_SERVER_ERROR: 903 return DisconnectCause.SERVER_UNREACHABLE; 904 905 case ImsReasonInfo.CODE_LOCAL_NETWORK_ROAMING: 906 case ImsReasonInfo.CODE_LOCAL_NETWORK_IP_CHANGED: 907 case ImsReasonInfo.CODE_LOCAL_IMS_SERVICE_DOWN: 908 case ImsReasonInfo.CODE_LOCAL_SERVICE_UNAVAILABLE: 909 case ImsReasonInfo.CODE_LOCAL_NOT_REGISTERED: 910 case ImsReasonInfo.CODE_LOCAL_NETWORK_NO_LTE_COVERAGE: 911 case ImsReasonInfo.CODE_LOCAL_NETWORK_NO_SERVICE: 912 case ImsReasonInfo.CODE_LOCAL_CALL_VCC_ON_PROGRESSING: 913 return DisconnectCause.OUT_OF_SERVICE; 914 915 case ImsReasonInfo.CODE_SIP_REQUEST_TIMEOUT: 916 case ImsReasonInfo.CODE_TIMEOUT_1XX_WAITING: 917 case ImsReasonInfo.CODE_TIMEOUT_NO_ANSWER: 918 case ImsReasonInfo.CODE_TIMEOUT_NO_ANSWER_CALL_UPDATE: 919 return DisconnectCause.TIMED_OUT; 920 921 case ImsReasonInfo.CODE_LOCAL_LOW_BATTERY: 922 case ImsReasonInfo.CODE_LOCAL_POWER_OFF: 923 return DisconnectCause.POWER_OFF; 924 925 default: 926 } 927 928 return cause; 929 } 930 931 /** 932 * Listen to the IMS call state change 933 */ 934 private ImsCall.Listener mImsCallListener = new ImsCall.Listener() { 935 @Override 936 public void onCallProgressing(ImsCall imsCall) { 937 if (DBG) log("onCallProgressing"); 938 939 mPendingMO = null; 940 processCallStateChange(imsCall, ImsPhoneCall.State.ALERTING, 941 DisconnectCause.NOT_DISCONNECTED); 942 } 943 944 @Override 945 public void onCallStarted(ImsCall imsCall) { 946 if (DBG) log("onCallStarted"); 947 948 mPendingMO = null; 949 processCallStateChange(imsCall, ImsPhoneCall.State.ACTIVE, 950 DisconnectCause.NOT_DISCONNECTED); 951 } 952 953 /** 954 * onCallStartFailed will be invoked when: 955 * case 1) Dialing fails 956 * case 2) Ringing call is disconnected by local or remote user 957 */ 958 @Override 959 public void onCallStartFailed(ImsCall imsCall, ImsReasonInfo reasonInfo) { 960 if (DBG) log("onCallStartFailed reasonCode=" + reasonInfo.getCode()); 961 962 if (mPendingMO != null) { 963 // To initiate dialing circuit-switched call 964 if (reasonInfo.getCode() == ImsReasonInfo.CODE_LOCAL_CALL_CS_RETRY_REQUIRED 965 && mBackgroundCall.getState() == ImsPhoneCall.State.IDLE 966 && mRingingCall.getState() == ImsPhoneCall.State.IDLE) { 967 mForegroundCall.detach(mPendingMO); 968 removeConnection(mPendingMO); 969 mPendingMO.finalize(); 970 mPendingMO = null; 971 mPhone.initiateSilentRedial(); 972 return; 973 } 974 mPendingMO = null; 975 } 976 } 977 978 @Override 979 public void onCallTerminated(ImsCall imsCall, ImsReasonInfo reasonInfo) { 980 if (DBG) log("onCallTerminated reasonCode=" + reasonInfo.getCode()); 981 982 ImsPhoneCall.State oldState = mForegroundCall.getState(); 983 int cause = getDisconnectCauseFromReasonInfo(reasonInfo); 984 ImsPhoneConnection conn = findConnection(imsCall); 985 if (DBG) log("cause = " + cause + " conn = " + conn); 986 987 if (conn != null && conn.isIncoming() && conn.getConnectTime() == 0) { 988 // Missed 989 if (cause == DisconnectCause.NORMAL) { 990 cause = DisconnectCause.INCOMING_MISSED; 991 } 992 if (DBG) log("Incoming connection of 0 connect time detected - translated cause = " 993 + cause); 994 995 } 996 997 if (cause == DisconnectCause.NORMAL && conn != null && conn.getImsCall().isMerged()) { 998 // Call was terminated while it is merged instead of a remote disconnect. 999 cause = DisconnectCause.IMS_MERGED_SUCCESSFULLY; 1000 } 1001 1002 processCallStateChange(imsCall, ImsPhoneCall.State.DISCONNECTED, cause); 1003 } 1004 1005 @Override 1006 public void onCallHeld(ImsCall imsCall) { 1007 if (DBG) log("onCallHeld"); 1008 1009 synchronized (mSyncHold) { 1010 ImsPhoneCall.State oldState = mBackgroundCall.getState(); 1011 processCallStateChange(imsCall, ImsPhoneCall.State.HOLDING, 1012 DisconnectCause.NOT_DISCONNECTED); 1013 if (oldState == ImsPhoneCall.State.ACTIVE) { 1014 // Note: This case comes up when we have just held a call in response to a 1015 // switchWaitingOrHoldingAndActive. We now need to resume the background call. 1016 // The EVENT_RESUME_BACKGROUND causes resumeWaitingOrHolding to be called. 1017 if ((mForegroundCall.getState() == ImsPhoneCall.State.HOLDING) 1018 || (mRingingCall.getState() == ImsPhoneCall.State.WAITING)) { 1019 1020 sendEmptyMessage(EVENT_RESUME_BACKGROUND); 1021 } else { 1022 //when multiple connections belong to background call, 1023 //only the first callback reaches here 1024 //otherwise the oldState is already HOLDING 1025 if (mPendingMO != null) { 1026 sendEmptyMessage(EVENT_DIAL_PENDINGMO); 1027 } 1028 } 1029 } 1030 } 1031 } 1032 1033 @Override 1034 public void onCallHoldFailed(ImsCall imsCall, ImsReasonInfo reasonInfo) { 1035 if (DBG) log("onCallHoldFailed reasonCode=" + reasonInfo.getCode()); 1036 1037 synchronized (mSyncHold) { 1038 ImsPhoneCall.State bgState = mBackgroundCall.getState(); 1039 if (reasonInfo.getCode() == ImsReasonInfo.CODE_LOCAL_CALL_TERMINATED) { 1040 // disconnected while processing hold 1041 if (mPendingMO != null) { 1042 sendEmptyMessage(EVENT_DIAL_PENDINGMO); 1043 } 1044 } else if (bgState == ImsPhoneCall.State.ACTIVE) { 1045 mForegroundCall.switchWith(mBackgroundCall); 1046 1047 if (mPendingMO != null) { 1048 mPendingMO.setDisconnectCause(DisconnectCause.ERROR_UNSPECIFIED); 1049 sendEmptyMessageDelayed(EVENT_HANGUP_PENDINGMO, TIMEOUT_HANGUP_PENDINGMO); 1050 } 1051 } 1052 } 1053 } 1054 1055 @Override 1056 public void onCallResumed(ImsCall imsCall) { 1057 if (DBG) log("onCallResumed"); 1058 1059 // If we are the in midst of swapping FG and BG calls and the call we end up resuming 1060 // is not the one we expected, we likely had a resume failure and we need to swap the 1061 // FG and BG calls back. 1062 if (mSwitchingFgAndBgCalls && imsCall != mCallExpectedToResume) { 1063 mForegroundCall.switchWith(mBackgroundCall); 1064 mSwitchingFgAndBgCalls = false; 1065 mCallExpectedToResume = null; 1066 } 1067 processCallStateChange(imsCall, ImsPhoneCall.State.ACTIVE, 1068 DisconnectCause.NOT_DISCONNECTED); 1069 } 1070 1071 @Override 1072 public void onCallResumeFailed(ImsCall imsCall, ImsReasonInfo reasonInfo) { 1073 // TODO : What should be done? 1074 // If we are in the midst of swapping the FG and BG calls and we got a resume fail, we 1075 // need to swap back the FG and BG calls. 1076 if (mSwitchingFgAndBgCalls && imsCall == mCallExpectedToResume) { 1077 mForegroundCall.switchWith(mBackgroundCall); 1078 mCallExpectedToResume = null; 1079 mSwitchingFgAndBgCalls = false; 1080 } 1081 mPhone.notifySuppServiceFailed(Phone.SuppService.RESUME); 1082 } 1083 1084 @Override 1085 public void onCallResumeReceived(ImsCall imsCall) { 1086 if (DBG) log("onCallResumeReceived"); 1087 1088 if (mOnHoldToneStarted) { 1089 mPhone.stopOnHoldTone(); 1090 mOnHoldToneStarted = false; 1091 } 1092 } 1093 1094 @Override 1095 public void onCallHoldReceived(ImsCall imsCall) { 1096 if (DBG) log("onCallHoldReceived"); 1097 1098 ImsPhoneConnection conn = findConnection(imsCall); 1099 if (conn != null && conn.getState() == ImsPhoneCall.State.ACTIVE) { 1100 if (!mOnHoldToneStarted && ImsPhoneCall.isLocalTone(imsCall)) { 1101 mPhone.startOnHoldTone(); 1102 mOnHoldToneStarted = true; 1103 } 1104 } 1105 } 1106 1107 @Override 1108 public void onCallMerged(ImsCall call) { 1109 if (DBG) log("onCallMerged"); 1110 1111 mForegroundCall.merge(mBackgroundCall, mForegroundCall.getState()); 1112 updatePhoneState(); 1113 mPhone.notifyPreciseCallStateChanged(); 1114 } 1115 1116 @Override 1117 public void onCallMergeFailed(ImsCall call, ImsReasonInfo reasonInfo) { 1118 if (DBG) log("onCallMergeFailed reasonInfo=" + reasonInfo); 1119 mPhone.notifySuppServiceFailed(Phone.SuppService.CONFERENCE); 1120 } 1121 1122 /** 1123 * Called when the state of IMS conference participant(s) has changed. 1124 * 1125 * @param call the call object that carries out the IMS call. 1126 * @param participants the participant(s) and their new state information. 1127 */ 1128 @Override 1129 public void onConferenceParticipantsStateChanged(ImsCall call, 1130 List<ConferenceParticipant> participants) { 1131 if (DBG) log("onConferenceParticipantsStateChanged"); 1132 1133 ImsPhoneConnection conn = findConnection(call); 1134 if (conn != null) { 1135 conn.updateConferenceParticipants(participants); 1136 } 1137 } 1138 }; 1139 1140 /** 1141 * Listen to the IMS call state change 1142 */ 1143 private ImsCall.Listener mImsUssdListener = new ImsCall.Listener() { 1144 @Override 1145 public void onCallStarted(ImsCall imsCall) { 1146 if (DBG) log("mImsUssdListener onCallStarted"); 1147 1148 if (imsCall == mUssdSession) { 1149 if (mPendingUssd != null) { 1150 AsyncResult.forMessage(mPendingUssd); 1151 mPendingUssd.sendToTarget(); 1152 mPendingUssd = null; 1153 } 1154 } 1155 } 1156 1157 @Override 1158 public void onCallStartFailed(ImsCall imsCall, ImsReasonInfo reasonInfo) { 1159 if (DBG) log("mImsUssdListener onCallStartFailed reasonCode=" + reasonInfo.getCode()); 1160 1161 onCallTerminated(imsCall, reasonInfo); 1162 } 1163 1164 @Override 1165 public void onCallTerminated(ImsCall imsCall, ImsReasonInfo reasonInfo) { 1166 if (DBG) log("mImsUssdListener onCallTerminated reasonCode=" + reasonInfo.getCode()); 1167 1168 if (imsCall == mUssdSession) { 1169 mUssdSession = null; 1170 if (mPendingUssd != null) { 1171 CommandException ex = 1172 new CommandException(CommandException.Error.GENERIC_FAILURE); 1173 AsyncResult.forMessage(mPendingUssd, null, ex); 1174 mPendingUssd.sendToTarget(); 1175 mPendingUssd = null; 1176 } 1177 } 1178 imsCall.close(); 1179 } 1180 1181 @Override 1182 public void onCallUssdMessageReceived(ImsCall call, 1183 int mode, String ussdMessage) { 1184 if (DBG) log("mImsUssdListener onCallUssdMessageReceived mode=" + mode); 1185 1186 int ussdMode = -1; 1187 1188 switch(mode) { 1189 case ImsCall.USSD_MODE_REQUEST: 1190 ussdMode = CommandsInterface.USSD_MODE_REQUEST; 1191 break; 1192 1193 case ImsCall.USSD_MODE_NOTIFY: 1194 ussdMode = CommandsInterface.USSD_MODE_NOTIFY; 1195 break; 1196 } 1197 1198 mPhone.onIncomingUSSD(ussdMode, ussdMessage); 1199 } 1200 }; 1201 1202 /** 1203 * Listen to the IMS service state change 1204 * 1205 */ 1206 private ImsConnectionStateListener mImsConnectionStateListener = 1207 new ImsConnectionStateListener() { 1208 @Override 1209 public void onImsConnected() { 1210 if (DBG) log("onImsConnected"); 1211 mPhone.setServiceState(ServiceState.STATE_IN_SERVICE); 1212 } 1213 1214 @Override 1215 public void onImsDisconnected() { 1216 if (DBG) log("onImsDisconnected"); 1217 mPhone.setServiceState(ServiceState.STATE_OUT_OF_SERVICE); 1218 } 1219 1220 @Override 1221 public void onImsResumed() { 1222 if (DBG) log("onImsResumed"); 1223 mPhone.setServiceState(ServiceState.STATE_IN_SERVICE); 1224 } 1225 1226 @Override 1227 public void onImsSuspended() { 1228 if (DBG) log("onImsSuspended"); 1229 mPhone.setServiceState(ServiceState.STATE_OUT_OF_SERVICE); 1230 } 1231 1232 @Override 1233 public void onFeatureCapabilityChanged(int serviceClass, 1234 int[] enabledFeatures, int[] disabledFeatures) { 1235 if (serviceClass == ImsServiceClass.MMTEL) { 1236 if (enabledFeatures[ImsConfig.FeatureConstants.FEATURE_TYPE_VOICE_OVER_LTE] == 1237 ImsConfig.FeatureConstants.FEATURE_TYPE_VOICE_OVER_LTE) { 1238 mIsVolteEnabled = true; 1239 } 1240 if (enabledFeatures[ImsConfig.FeatureConstants.FEATURE_TYPE_VIDEO_OVER_LTE] == 1241 ImsConfig.FeatureConstants.FEATURE_TYPE_VIDEO_OVER_LTE) { 1242 mIsVtEnabled = true; 1243 } 1244 if (disabledFeatures[ImsConfig.FeatureConstants.FEATURE_TYPE_VOICE_OVER_LTE] == 1245 ImsConfig.FeatureConstants.FEATURE_TYPE_VOICE_OVER_LTE) { 1246 mIsVolteEnabled = false; 1247 } 1248 if (disabledFeatures[ImsConfig.FeatureConstants.FEATURE_TYPE_VIDEO_OVER_LTE] == 1249 ImsConfig.FeatureConstants.FEATURE_TYPE_VIDEO_OVER_LTE) { 1250 mIsVtEnabled = false; 1251 } 1252 } 1253 if (DBG) log("onFeatureCapabilityChanged, mIsVolteEnabled = " + mIsVolteEnabled 1254 + " mIsVtEnabled = " + mIsVtEnabled); 1255 } 1256 }; 1257 1258 /* package */ 1259 ImsUtInterface getUtInterface() throws ImsException { 1260 if (mImsManager == null) { 1261 throw new ImsException("no ims manager", ImsReasonInfo.CODE_UNSPECIFIED); 1262 } 1263 1264 ImsUtInterface ut = mImsManager.getSupplementaryServiceConfiguration(mServiceId); 1265 return ut; 1266 } 1267 1268 /* package */ 1269 void notifySrvccState(Call.SrvccState state) { 1270 if (DBG) log("notifySrvccState state=" + state); 1271 1272 mSrvccState = state; 1273 1274 if (mSrvccState == Call.SrvccState.COMPLETED) { 1275 if (mForegroundCall.getConnections().size() > 0) { 1276 mHandoverCall.switchWith(mForegroundCall); 1277 } else if (mBackgroundCall.getConnections().size() > 0) { 1278 mHandoverCall.switchWith(mBackgroundCall); 1279 } 1280 1281 // release wake lock hold 1282 ImsPhoneConnection con = mHandoverCall.getHandoverConnection(); 1283 if (con != null) { 1284 con.releaseWakeLock(); 1285 } 1286 } 1287 } 1288 1289 //****** Overridden from Handler 1290 1291 @Override 1292 public void 1293 handleMessage (Message msg) { 1294 AsyncResult ar; 1295 if (DBG) log("handleMessage what=" + msg.what); 1296 1297 switch (msg.what) { 1298 case EVENT_HANGUP_PENDINGMO: 1299 if (mPendingMO != null) { 1300 mPendingMO.onDisconnect(); 1301 removeConnection(mPendingMO); 1302 mPendingMO = null; 1303 } 1304 1305 updatePhoneState(); 1306 mPhone.notifyPreciseCallStateChanged(); 1307 break; 1308 case EVENT_RESUME_BACKGROUND: 1309 try { 1310 resumeWaitingOrHolding(); 1311 } catch (CallStateException e) { 1312 if (Phone.DEBUG_PHONE) { 1313 loge("handleMessage EVENT_RESUME_BACKGROUND exception=" + e); 1314 } 1315 } 1316 break; 1317 case EVENT_DIAL_PENDINGMO: 1318 dialInternal(mPendingMO, mClirMode, VideoProfile.VideoState.AUDIO_ONLY); 1319 break; 1320 1321 case EVENT_EXIT_ECM_RESPONSE_CDMA: 1322 // no matter the result, we still do the same here 1323 if (pendingCallInEcm) { 1324 dialInternal(mPendingMO, pendingCallClirMode, pendingCallVideoState); 1325 pendingCallInEcm = false; 1326 } 1327 mPhone.unsetOnEcbModeExitResponse(this); 1328 break; 1329 } 1330 } 1331 1332 @Override 1333 protected void log(String msg) { 1334 Rlog.d(LOG_TAG, "[ImsPhoneCallTracker] " + msg); 1335 } 1336 1337 protected void loge(String msg) { 1338 Rlog.e(LOG_TAG, "[ImsPhoneCallTracker] " + msg); 1339 } 1340 1341 @Override 1342 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { 1343 pw.println("ImsPhoneCallTracker extends:"); 1344 super.dump(fd, pw, args); 1345 pw.println(" mVoiceCallEndedRegistrants=" + mVoiceCallEndedRegistrants); 1346 pw.println(" mVoiceCallStartedRegistrants=" + mVoiceCallStartedRegistrants); 1347 pw.println(" mRingingCall=" + mRingingCall); 1348 pw.println(" mForegroundCall=" + mForegroundCall); 1349 pw.println(" mBackgroundCall=" + mBackgroundCall); 1350 pw.println(" mHandoverCall=" + mHandoverCall); 1351 pw.println(" mPendingMO=" + mPendingMO); 1352 //pw.println(" mHangupPendingMO=" + mHangupPendingMO); 1353 pw.println(" mPhone=" + mPhone); 1354 pw.println(" mDesiredMute=" + mDesiredMute); 1355 pw.println(" mState=" + mState); 1356 } 1357 1358 @Override 1359 protected void handlePollCalls(AsyncResult ar) { 1360 } 1361 1362 /* package */ 1363 ImsEcbm getEcbmInterface() throws ImsException { 1364 if (mImsManager == null) { 1365 throw new ImsException("no ims manager", ImsReasonInfo.CODE_UNSPECIFIED); 1366 } 1367 1368 ImsEcbm ecbm = mImsManager.getEcbmInterface(mServiceId); 1369 return ecbm; 1370 } 1371 1372 public boolean isInEmergencyCall() { 1373 return mIsInEmergencyCall; 1374 } 1375 1376 public boolean isVolteEnabled() { 1377 return mIsVolteEnabled; 1378 } 1379 1380 public boolean isVtEnabled() { 1381 return mIsVtEnabled; 1382 } 1383} 1384