Ejemplo n.º 1
0
  void switchWaitingOrHoldingAndActive() throws CallStateException {
    if (DBG) log("switchWaitingOrHoldingAndActive");

    if (mRingingCall.getState() == ImsPhoneCall.State.INCOMING) {
      throw new CallStateException("cannot be in the incoming state");
    }

    if (mForegroundCall.getState() == ImsPhoneCall.State.ACTIVE) {
      ImsCall imsCall = mForegroundCall.getImsCall();
      if (imsCall == null) {
        throw new CallStateException("no ims call");
      }

      // Swap the ImsCalls pointed to by the foreground and background ImsPhoneCalls.
      // If hold or resume later fails, we will swap them back.
      mSwitchingFgAndBgCalls = true;
      mCallExpectedToResume = mBackgroundCall.getImsCall();
      mForegroundCall.switchWith(mBackgroundCall);

      // Hold the foreground call; once the foreground call is held, the background call will
      // be resumed.
      try {
        imsCall.hold();
      } catch (ImsException e) {
        mForegroundCall.switchWith(mBackgroundCall);
        throw new CallStateException(e.getMessage());
      }
    } else if (mBackgroundCall.getState() == ImsPhoneCall.State.HOLDING) {
      resumeWaitingOrHolding();
    }
  }