public static boolean canHangupActiveAndAnswerWaiting(CallManager cm) {
    boolean retval = false;

    Call fgCall = cm.getActiveFgCall();
    Call bgCall = cm.getFirstActiveBgCall();
    Call rgCall = cm.getFirstActiveRingingCall();

    final boolean isFgActive = fgCall.getState() == Call.State.ACTIVE;
    final boolean isBgIdle = bgCall.getState() == Call.State.IDLE;
    final boolean isRgWaiting = rgCall.getState() == Call.State.WAITING;

    if (isFgActive && isBgIdle && isRgWaiting) {
      if (fgCall.getPhone() == rgCall.getPhone() && !rgCall.getLatestConnection().isVideo()) {
        retval = true;
      }
    }

    return retval;
  }
  public static boolean canECT(CallManager cm) {
    boolean retval = false;

    final boolean hasActiveFgCall = cm.hasActiveFgCall();
    final boolean hasActiveBgCall = cm.hasActiveBgCall();
    final boolean hasActiveRingingCall = cm.hasActiveRingingCall();

    Call fgCall = null;
    Call bgCall = null;

    DualTalkUtils dt = DualTalkUtils.getInstance();
    if (DualTalkUtils.isSupportDualTalk() && dt != null && dt.isDualTalkMultipleHoldCase()) {
      fgCall = dt.getActiveFgCall();
      bgCall = dt.getFirstActiveBgCall();
    } else {
      fgCall = cm.getActiveFgCall();
      bgCall = cm.getFirstActiveBgCall();
    }

    if (hasActiveRingingCall) {
      retval = false;
      return retval;
    }

    if (hasActiveFgCall && hasActiveBgCall) {
      final boolean isFgSipPhone =
          fgCall.getPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_SIP;
      final boolean isBgSipPhone =
          bgCall.getPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_SIP;
      if (!isFgSipPhone && !isBgSipPhone && (fgCall.getPhone() == bgCall.getPhone())) {
        retval = true;
      }
    }

    return retval;
  }
  /**
   * Brings up the "Respond via SMS" popup for an incoming call.
   *
   * @param ringingCall the current incoming call
   */
  public void showRespondViaSmsPopup(Call ringingCall) {
    if (DBG) log("showRespondViaSmsPopup()...");

    ListView lv = new ListView(mInCallScreen);

    // Refresh the array of "canned responses".
    // TODO: don't do this here in the UI thread!  (This lookup is very
    // cheap, but it's still a StrictMode violation.  See the TODO comment
    // following loadCannedResponses() for more info.)
    mCannedResponses = loadCannedResponses();

    // Build the list: start with the canned responses, but manually add
    // "Custom message..." as the last choice.
    int numPopupItems = mCannedResponses.length + 1;
    String[] popupItems = Arrays.copyOf(mCannedResponses, numPopupItems);
    popupItems[numPopupItems - 1] =
        mInCallScreen.getResources().getString(R.string.respond_via_sms_custom_message);

    ArrayAdapter<String> adapter =
        new ArrayAdapter<String>(
            mInCallScreen, android.R.layout.simple_list_item_1, android.R.id.text1, popupItems);
    lv.setAdapter(adapter);

    // Create a RespondViaSmsItemClickListener instance to handle item
    // clicks from the popup.
    // (Note we create a fresh instance for each incoming call, and
    // stash away the call's phone number, since we can't necessarily
    // assume this call will still be ringing when the user finally
    // chooses a response.)

    Connection c = ringingCall.getLatestConnection();
    Phone p = ringingCall.getPhone();
    if (VDBG) log("- connection: " + c);

    if (c == null || p == null) {
      // Uh oh -- the "ringingCall" doesn't have any connections any more.
      // (In other words, it's no longer ringing.)  This is rare, but can
      // happen if the caller hangs up right at the exact moment the user
      // selects the "Respond via SMS" option.
      // There's nothing to do here (since the incoming call is gone),
      // so just bail out.
      Log.i(TAG, "showRespondViaSmsPopup: null connection; bailing out...");
      return;
    }

    // TODO: at this point we probably should re-check c.getAddress()
    // and c.getNumberPresentation() for validity.  (i.e. recheck the
    // same cases in InCallTouchUi.showIncomingCallWidget() where we
    // should have disallowed the "respond via SMS" feature in the
    // first place.)

    String phoneNumber = c.getAddress();
    int subscription = p.getSubscription();
    if (VDBG) log("- phoneNumber: " + phoneNumber);
    lv.setOnItemClickListener(new RespondViaSmsItemClickListener(phoneNumber, subscription));

    AlertDialog.Builder builder =
        new AlertDialog.Builder(mInCallScreen)
            .setCancelable(true)
            .setOnCancelListener(new RespondViaSmsCancelListener())
            .setView(lv);
    mPopup = builder.create();
    mPopup.show();
  }
 public PhoneBase getPhoneFromConnection() {
   return (PhoneBase) (parent.getPhone());
 }